PhotoCraft: An open-source, photo editor written by scratch in pure Rust
Integration: hide area type that reaches the shape's narrow bottom (#6230)
David Mann13733ba3a9a0
diff --git a/crates/text/src/layout.rs b/crates/text/src/layout.rsindex 9164cbaa9..bf42fdc31 100644--- a/crates/text/src/layout.rs+++ b/crates/text/src/layout.rs@@ -1200,7 +1200,8 @@ struct Need {////// A span too narrow for the word that would start it (the narrow top of an ellipse) is left/// empty and the word goes to the first later span that holds it, as Photoshop does. A word no-/// later span holds overflows its span, as in a text box. Parley doesn't report a line's+/// later span holds but another span of the shape would means the shape is full: it and the rest are+/// hidden. Only a word no span holds overflows its span. Parley doesn't report a line's/// trailing whitespace while breaking, so overflowing lines are found after a pass and the/// paragraph broken again; `budget` (shared by the paragraph's calls) bounds the passes.///@@ -1219,13 +1220,12 @@ fn break_area() -> (Vec<Slot>, bool) {let inset = indents.0 + indents.1;let mut rows = AreaRows { area, m, min_width, next: from, rows: Vec::new(), done: false };+ // Every row of the shape from its top, whatever paragraph came before (found lazily).+ let mut shape_rows = AreaRows { area, m, min_width, next: area.bounds[1], rows: Vec::new(), done: false };let mut needs: Vec<Need> = Vec::new();loop {let (slots, overflow) = break_area_pass(layout, &mut rows, inset, scale, &needs);budget.set(budget.get().saturating_sub(1));- if budget.get() == 0 {- return (slots, overflow);- }// Each line's text start and scaled width without its trailing whitespace.let lines: Vec<(usize, f32)> = layout.lines()@@ -1234,6 +1234,20 @@ fn break_area((l.text_range().start, (lm.advance - lm.trailing_whitespace) * scale)}).collect();+ // A line still wider than its span that some span of the shape would hold: the shape ran+ // out of room for it (the narrow bottom of a full bubble). It and the rest are hidden, as+ // overflow; only a word no span holds overflows its span.+ let mut ran_out = |slots: Vec<Slot>, overflow: bool| match lines+ .iter()+ .zip(&slots)+ .position(|(&(_, width), s)| width > s.width + 0.5 && shape_rows.first_fit(0, 0, width, inset).is_some())+ {+ Some(li) => (slots.into_iter().take(li).collect(), true),+ None => (slots, overflow),+ };+ if budget.get() == 0 {+ return ran_out(slots, overflow);+ }// A line that now starts elsewhere (an earlier line changed) no longer needs its span.let kept = needs.len();needs.retain(|n| lines.get(n.line).is_some_and(|l| l.0 == n.start));@@ -1247,10 +1261,11 @@ fn break_area(break;}}- match new {- Some(n) => needs.push(n),- None => return (slots, overflow),+ if let Some(n) = new {+ needs.push(n);+ continue;}+ return ran_out(slots, overflow);}}diff --git a/crates/text/src/tests.rs b/crates/text/src/tests.rsindex bfa833a3a..24b2d9cfc 100644--- a/crates/text/src/tests.rs+++ b/crates/text/src/tests.rs@@ -2160,6 +2160,39 @@ fn area_overflow_is_hidden() {assert_lines_inside(&l, &path);}+/// A long word that reaches the narrow bottom of a full bubble is hidden with the rest, not+/// drawn past the outline: the wide middle rows would hold it, so the shape just ran out.+#[test]+fn area_overflow_at_the_narrow_bottom_is_hidden() {+ let mut e = TextEngine::new();+ let words = "Unfortunately the misunderstanding between representatives continued indefinitely. ";+ for (w, h, size) in [(260.0, 160.0, 12.0), (180.0, 140.0, 14.0), (150.0, 220.0, 12.0)] {+ let mut t = point(&words.repeat(8), size);+ let path = area_ellipse(0.0, 0.0, w, h);+ t.shape = TextShape::Area { path: path.clone() };+ let l = e.layout(&t, 72.0);+ assert!(!l.lines.is_empty());+ assert!(l.lines.last().unwrap().range.end < t.text.len(), "the rest is hidden");+ assert_lines_inside(&l, &path);+ }+}++/// The same in a later paragraph: its own rows start below the wide top of the shape, but the+/// shape would still hold the word there, so it is hidden rather than drawn past the outline.+#[test]+fn area_overflow_in_a_later_paragraph_is_hidden() {+ let mut e = TextEngine::new();+ // A funnel: 300 px wide at the top, a point at the bottom.+ let path = area_poly(&[(0.0, 0.0), (300.0, 0.0), (150.0, 300.0)]);+ for n in (10..120).step_by(5) {+ let text = format!("{}\nmisunderstanding and more", "cat ".repeat(n));+ let mut t = point(&text, 12.0);+ t.shape = TextShape::Area { path: path.clone() };+ let l = e.layout(&t, 72.0);+ assert_lines_inside(&l, &path);+ }+}+#[test]fn area_lines_center_in_their_span() {let mut e = TextEngine::new();@@ -2254,7 +2287,7 @@ fn area_word_wider_than_every_span_overflows_instead_of_hiding_the_text() {t.shape = TextShape::Area { path };let l = e.layout(&t, 72.0);let first = l.lines.first().expect("the text is shown");- // The word overflows its 40 px span, as in a text box, on the first row.+ // The word overflows its 40 px span on the first row (box text would break it, #6694).assert!(first.x1 - first.x0 > 40.0 && first.x1 - first.x0 < 200.0, "{first:?}");assert!(first.x0 >= -0.5, "{first:?}");// Nothing is hidden.diff --git a/docs/scorecard.md b/docs/scorecard.mdindex f524872be..1ff5e0507 100644--- a/docs/scorecard.md+++ b/docs/scorecard.md@@ -222,7 +222,7 @@ Unread: `general.color_picker`, `general.animated_zoom`, `general.zoom_resizes_w| TYPE-218-7 | Warp Text dialog previews live and opens with the layer's current warp | missing | [#218](https://github.com/storytold/photocraft/issues/218) | view_cmds.rs:834 always seeds arc, bend 50 || TYPE-218-8 | Text editing: select all, double/triple/quadruple-click selection, paste, with tests | done | [#218](https://github.com/storytold/photocraft/issues/218) | Like Photoshop, 2 clicks select the word, 3 the laid-out line (a column in vertical type), 4 the paragraph up to the hard return, 5 all text, and the next quick click starts over (#3493; type_tool.rs next_click_count, click_selection, multi_click). Tested through real canvas clicks in point, paragraph and vertical type, with paste replacing the selection and Cmd+A selecting all (type_tool_tests.rs multi_click_selects_word_line_paragraph_and_all_in_point_text, multi_click_separates_wrapped_lines_from_paragraphs, click_counts_cycle_and_restart, click_selection_without_layout_and_on_hostile_input, multi_click_without_a_session_does_nothing) || TYPE-218-9 | Distort/Perspective/Warp on live type as in Photoshop (was: offer 'Rasterize and continue?'; Photoshop doesn't prompt) | done | [#218](https://github.com/storytold/photocraft/issues/218) | Photoshop 2026 prompts for none of these: Edit › Transform › Warp on live type stays enabled with no rasterize prompt and offers only the warp styles (the mesh can't be dragged), so the type stays editable; Distort, Perspective and the split warps are greyed. PhotoCraft does the same: Warp on type commits the layer's Warp Text in one step (transform_tool.rs enter_type_warp, warp_cmds.rs warp_type_layer, #3004; warp_on_type_takes_a_style_and_keeps_the_type_editable), Distort/Perspective greyed (enable_rules.rs, #2701) |-| TYPE-218-10 | Area type: Type tool click inside a closed path or shape wraps text inside it, holes and dents included, PSD round trip | partial | [#218](https://github.com/storytold/photocraft/issues/218) | TextShape::Area (doc text.rs) laid out line by line into the spans the path leaves (text area.rs, layout.rs break_area), type.fillPath (engine type_area_cmds.rs), released to box text by type.detachFromPath, area/path cursors and click-to-place (ui-egui type_tool.rs path_target), .pcraft round trip. Missing: PSD area type (saves as paragraph text over the path's bounds, with an export warning); mixed type sizes in one area paragraph space at its largest line; area type takes paths of at most 4096 anchors: beyond that a Type tool click makes point text (the pointer shows the plain I-beam), and type.fillPath refuses the path with "the path has too many anchor points" (type.attachToPath still takes a subpath of up to 100,000 anchors); a word too wide for every span in the shape overflows its span the way box text does |+| TYPE-218-10 | Area type: Type tool click inside a closed path or shape wraps text inside it, holes and dents included, PSD round trip | partial | [#218](https://github.com/storytold/photocraft/issues/218) | TextShape::Area (doc text.rs) laid out line by line into the spans the path leaves (text area.rs, layout.rs break_area), type.fillPath (engine type_area_cmds.rs), released to box text by type.detachFromPath, area/path cursors and click-to-place (ui-egui type_tool.rs path_target), .pcraft round trip. Missing: PSD area type (saves as paragraph text over the path's bounds, with an export warning); mixed type sizes in one area paragraph space at its largest line; area type takes paths of at most 4096 anchors: beyond that a Type tool click makes point text (the pointer shows the plain I-beam), and type.fillPath refuses the path with "the path has too many anchor points" (type.attachToPath still takes a subpath of up to 100,000 anchors); a word too wide for every span in the shape overflows its span (box text breaks it at the edge, #6694); the first line starts about 0.24 em lower than in a text box of the same size; Photoshop area type in a PSD opens as box text; the area path has no handles to edit it after the type is placed |## Automationdiff --git a/scorecard/type.toml b/scorecard/type.tomlindex ef3701b41..5703affff 100644--- a/scorecard/type.toml+++ b/scorecard/type.toml@@ -72,4 +72,4 @@ id = "TYPE-218-10"target = "Area type: Type tool click inside a closed path or shape wraps text inside it, holes and dents included, PSD round trip"status = "partial"issue = 218-note = "TextShape::Area (doc text.rs) laid out line by line into the spans the path leaves (text area.rs, layout.rs break_area), type.fillPath (engine type_area_cmds.rs), released to box text by type.detachFromPath, area/path cursors and click-to-place (ui-egui type_tool.rs path_target), .pcraft round trip. Missing: PSD area type (saves as paragraph text over the path's bounds, with an export warning); mixed type sizes in one area paragraph space at its largest line; area type takes paths of at most 4096 anchors: beyond that a Type tool click makes point text (the pointer shows the plain I-beam), and type.fillPath refuses the path with \"the path has too many anchor points\" (type.attachToPath still takes a subpath of up to 100,000 anchors); a word too wide for every span in the shape overflows its span the way box text does"+note = "TextShape::Area (doc text.rs) laid out line by line into the spans the path leaves (text area.rs, layout.rs break_area), type.fillPath (engine type_area_cmds.rs), released to box text by type.detachFromPath, area/path cursors and click-to-place (ui-egui type_tool.rs path_target), .pcraft round trip. Missing: PSD area type (saves as paragraph text over the path's bounds, with an export warning); mixed type sizes in one area paragraph space at its largest line; area type takes paths of at most 4096 anchors: beyond that a Type tool click makes point text (the pointer shows the plain I-beam), and type.fillPath refuses the path with \"the path has too many anchor points\" (type.attachToPath still takes a subpath of up to 100,000 anchors); a word too wide for every span in the shape overflows its span (box text breaks it at the edge, #6694); the first line starts about 0.24 em lower than in a text box of the same size; Photoshop area type in a PSD opens as box text; the area path has no handles to edit it after the type is placed"