From c3905aee4f76baa94dc9d0b463437e5380eab9dc Mon Sep 17 00:00:00 2001 From: dotCooCoo Date: Sat, 21 Nov 2026 02:50:05 -0800 Subject: [PATCH] Dynamic Text: a style's new leading applies to Block text, the Eyedropper keeps Line Gap Block gives every character its size plus the frame's Line Gap, so on Block text a character's leading is never an override. A character style edited to a new leading now applies it there even when Block has given its users other leadings than the old definition's, for example after a Line Gap change or a refit, and the Line Gap moves. The Eyedropper copies a whole character style, so the leading it copies is no longer treated as a leading change: Line Gap stays, and Block gives the characters their size plus the gap, as before this branch. The tests now check that every character's leading is its size plus the new gap for each path, and the docs say that Text Tweaker's ramp sets the gap from its first character and does not vary the leading. --- crates/engine/src/cmd/appearance.rs | 14 +------ crates/engine/src/cmd/textstyles.rs | 10 +++++ crates/engine/src/cmd/typecmd.rs | 2 +- crates/engine/src/cmd/typecmd/block.rs | 4 +- crates/engine/src/cmd/typecmd/block_tests.rs | 39 ++++++++++++++++---- crates/engine/src/cmd/typemenu.rs | 2 +- docs/mcp.md | 16 ++++---- docs/target-app-parity.md | 2 +- 8 files changed, 57 insertions(+), 32 deletions(-) diff --git a/crates/engine/src/cmd/appearance.rs b/crates/engine/src/cmd/appearance.rs index d1d6194639..3b23d62634 100644 --- a/crates/engine/src/cmd/appearance.rs +++ b/crates/engine/src/cmd/appearance.rs @@ -2003,12 +2003,7 @@ fn copy_from(s: &mut Session, p: &Value) -> Result { if let Some((_, para)) = picked.text.as_ref().filter(|_| attrs.paragraph) { t.edit_paras(Some(t.paragraphs_in(start, end)), |p| *p = para.clone()); } - // With Block on, the copied leading goes to the frame's line gap. - if characters.contains_key(&id) && start < end { - super::typecmd::refresh_with_given_leading(t, start); - } else { - super::typecmd::refresh_bounds(t); - } + super::typecmd::refresh_bounds(t); } check_text_bounds(d)?; let labels = super::graph::capture_label_text(d, &whole, kept_text, kept_para)?; @@ -2270,12 +2265,7 @@ impl Picked { t.set_all_paras(para.clone()); } if text.is_some() && (a.character || a.paragraph) { - // With Block on, the copied leading goes to the frame's line gap. - if character.is_some() { - super::typecmd::refresh_with_given_leading(t, 0); - } else { - super::typecmd::refresh_bounds(t); - } + super::typecmd::refresh_bounds(t); } return; } diff --git a/crates/engine/src/cmd/textstyles.rs b/crates/engine/src/cmd/textstyles.rs index a804984ff6..426410b661 100644 --- a/crates/engine/src/cmd/textstyles.rs +++ b/crates/engine/src/cmd/textstyles.rs @@ -502,11 +502,21 @@ fn update_users(d: &mut Document, kind: Kind, name: &str, old: &Map>(v.clone()).ok()); match kind { Kind::Char => { let mut off = 0; for r in &mut t.runs { if r.style.style_name == target { + if let Some(l) = old_leading { + r.style.leading = l; + } let was = r.style.leading; r.style = font_change(&r.style, restyle(&r.style, char_attrs, old, new, &base), new); changed = true; diff --git a/crates/engine/src/cmd/typecmd.rs b/crates/engine/src/cmd/typecmd.rs index ea5a416165..240fb37c1f 100644 --- a/crates/engine/src/cmd/typecmd.rs +++ b/crates/engine/src/cmd/typecmd.rs @@ -359,7 +359,7 @@ pub(crate) fn refresh_with_leading(t: &mut TextObject, at: usize, leading: Optio } /// [`refresh_with_leading`] with the leading the character at `at` was just given (a character -/// style, the Eyedropper, Text Tweaker). +/// style, Text Tweaker). pub(crate) fn refresh_with_given_leading(t: &mut TextObject, at: usize) { if block::given_leading_to_line_gap(t, at) { refresh_fitted(t); diff --git a/crates/engine/src/cmd/typecmd/block.rs b/crates/engine/src/cmd/typecmd/block.rs index 8a567f127c..c3a54ca84f 100644 --- a/crates/engine/src/cmd/typecmd/block.rs +++ b/crates/engine/src/cmd/typecmd/block.rs @@ -6,7 +6,7 @@ use vectorcraft_doc::{CharStyle, TextKind, TextObject, TextRun}; /// The font size range a line's first character is fitted within, in document points (the /// Character panel's). -const SIZES: (f64, f64) = (0.1, 1296.0); +pub(crate) const SIZES: (f64, f64) = (0.1, 1296.0); /// Most passes a refit runs to correct lines that still wrap after the first fit; each pass measures /// the lines and runs at most one more area layout. @@ -194,7 +194,7 @@ pub(crate) fn leading_to_line_gap(t: &mut TextObject, at: usize, leading: Option } /// [`leading_to_line_gap`] with the leading the character at `at` was just given (a character -/// style, the Eyedropper, Text Tweaker), read before Block sets it again. +/// style, Text Tweaker), read before Block sets it again. pub(crate) fn given_leading_to_line_gap(t: &mut TextObject, at: usize) -> bool { let Some(leading) = run_at(&t.runs, at).map(|r| r.style.leading) else { return false }; leading_to_line_gap(t, at, leading) diff --git a/crates/engine/src/cmd/typecmd/block_tests.rs b/crates/engine/src/cmd/typecmd/block_tests.rs index 911f5abfd1..84d52e2cb1 100644 --- a/crates/engine/src/cmd/typecmd/block_tests.rs +++ b/crates/engine/src/cmd/typecmd/block_tests.rs @@ -727,7 +727,7 @@ fn a_leading_change_with_block_on_moves_the_line_gap() { // The gap stays within its range. s.execute("text.setStyle", &json!({"ids": [id], "leading": 5000})).unwrap(); - assert_eq!(text(&s, id).area.line_gap, 1296.0); + assert_eq!(text(&s, id).area.line_gap, vectorcraft_doc::AreaOptions::LINE_GAP.1); // From a gap that holds every leading at its least, the leading given still applies. s.execute("text.areaOptions", &json!({"lineGap": -1296})).unwrap(); s.execute("text.setStyle", &json!({"ids": [id], "leading": 1})).unwrap(); @@ -861,6 +861,25 @@ fn a_character_style_edited_to_a_leading_with_block_on_moves_the_line_gap() { let t = text(&s, id); assert!((t.area.line_gap - (60.0 - t.runs[0].style.size)).abs() < 1e-6, "edit: line gap {}", t.area.line_gap); assert!(leading_at(&t, 0).is_some_and(|l| (l - 60.0).abs() < 1e-6)); + assert_spread(&t); + + // Once Block has given the characters other leadings than the style's (a new line gap here), a + // new leading in the style still applies: Block's leadings are not overrides. + s.execute("text.areaOptions", &json!({"lineGap": 0})).unwrap(); + let gap = text(&s, id).area.line_gap; + s.execute("charStyle.edit", &json!({"name": "Plain", "to": "Plain", "attrs": {"tracking": 0, "leading": 70}})).unwrap(); + let t = text(&s, id); + assert!(t.area.line_gap != gap, "the line gap moved"); + assert!(leading_at(&t, 0).is_some_and(|l| (l - 70.0).abs() < 1e-6), "{:?}", leading_at(&t, 0)); + assert_spread(&t); +} + +/// Every character's leading is its size plus the frame's line gap (at least the least size), so +/// every line spread or tightened by the same amount. +fn assert_spread(t: &TextObject) { + let gap = t.area.line_gap; + let least = super::block::SIZES.0; + assert!(t.runs.iter().all(|r| r.style.leading.is_some_and(|l| (l - (r.style.size + gap).max(least)).abs() < 1e-6)), "{:?}", t.runs); } /// A character style that sets a leading, applied to Block text, moves the line gap. @@ -873,6 +892,7 @@ fn a_character_style_leading_applied_with_block_on_moves_the_line_gap() { let t = text(&s, id); assert!((t.area.line_gap - (50.0 - t.runs[0].style.size)).abs() < 1e-6, "apply: line gap {}", t.area.line_gap); assert!(leading_at(&t, 0).is_some_and(|l| (l - 50.0).abs() < 1e-6)); + assert_spread(&t); // Clearing overrides gives the text the leading of the Normal style. s.execute("charStyle.setAttrs", &json!({"name": "[Normal Character Style]", "attrs": {"leading": 44}})).unwrap(); @@ -881,9 +901,12 @@ fn a_character_style_leading_applied_with_block_on_moves_the_line_gap() { s.execute("charStyle.apply", &json!({"name": "Plain", "id": id, "clearOverrides": true})).unwrap(); let t = text(&s, id); assert!(leading_at(&t, 0).is_some_and(|l| (l - 44.0).abs() < 1e-6), "clear: {:?}", leading_at(&t, 0)); + assert!((t.area.line_gap - (44.0 - t.runs[0].style.size)).abs() < 1e-6, "clear: line gap {}", t.area.line_gap); + assert_spread(&t); } -/// Text Tweaker's leading ramp on Block text moves the line gap to its first character's value. +/// Text Tweaker's leading ramp on Block text moves the line gap to its first character's value; +/// Block then gives every other character its size plus that gap. #[test] fn a_text_tweaker_leading_with_block_on_moves_the_line_gap() { let mut s = session(); @@ -892,18 +915,20 @@ fn a_text_tweaker_leading_with_block_on_moves_the_line_gap() { let t = text(&s, id); assert!((t.area.line_gap - (40.0 - t.runs[0].style.size)).abs() < 1e-6, "line gap {}", t.area.line_gap); assert!(leading_at(&t, 0).is_some_and(|l| (l - 40.0).abs() < 1e-6)); + assert_spread(&t); } -/// The Eyedropper copying a leading onto Block text moves the line gap, so the first character -/// takes the copied leading. +/// The Eyedropper copies a whole character style, so the leading it copies onto Block text is not +/// a leading change: the line gap stays, and Block gives every character its size plus the gap. #[test] -fn an_eyedropper_leading_with_block_on_moves_the_line_gap() { +fn an_eyedropper_copy_onto_block_text_keeps_the_line_gap() { let mut s = session(); let source = point(&mut s, "source", json!({})); s.execute("text.setStyle", &json!({"ids": [source], "leading": 33})).unwrap(); let id = block_text(&mut s); + let gap = text(&s, id).area.line_gap; s.execute("appearance.copyFrom", &json!({"source": source, "ids": [id]})).unwrap(); let t = text(&s, id); - assert!(t.area.line_gap != 0.0, "the line gap moved"); - assert!(leading_at(&t, 0).is_some_and(|l| (l - 33.0).abs() < 1e-6), "{:?}", leading_at(&t, 0)); + assert_eq!(t.area.line_gap, gap); + assert_spread(&t); } diff --git a/crates/engine/src/cmd/typemenu.rs b/crates/engine/src/cmd/typemenu.rs index 5f61bbae81..70aa0ee07c 100644 --- a/crates/engine/src/cmd/typemenu.rs +++ b/crates/engine/src/cmd/typemenu.rs @@ -84,7 +84,7 @@ pub fn specs() -> Vec { "Dynamic Text", ["Type"], None, - "{ids?|id?, on?: bool, wordGap?: % of a word space 0..1000 (100), lineGap?: pt -1296..1296 (0)} turn Dynamic Text on or off for the selected type on a path and area type, or turn it on for point type (on omitted: the opposite of the first object's setting, point type counting as off, or on when a gap is given). On type on a path, the layout scales the text by one factor (every character's size, leading and baseline shift; Type on a Path Options › Spacing stays) so that it fills the span between its start and end brackets, larger or smaller, and fits it again after every edit to the text, the path or the brackets; the first character's size moves in steps of 0.1 pt within 0.1 to 1,296 pt, and at 0.1 pt text that still runs past the end bracket overflows. The stored sizes keep their proportions. On area type it is Block: each line as typed (each paragraph, and each forced line break in one; lines are not broken again) is set to the frame's width, less the inset, the gutters and the paragraph's indents, by changing its font size only: its first character's size, in steps of 0.1 pt within 0.1 to 1,296 pt, the line's other characters keeping their proportions to it, with baseline shifts following. Every character's leading is its size plus lineGap (a leading change on the text, from text.setStyle, text.setRangeStyle, type.step, a character style, the Eyedropper or Text Tweaker, sets lineGap to the new leading less the size of the first character changed), and the layout sets every paragraph with wordGap as its Desired word spacing, its Minimum or Maximum moving out to wordGap when wordGap lies outside it (the paragraphs keep their own Justification… values, which apply again when Block is off; the gaps are area type's, and are kept while Block is off; a gap with no area type in the selection, and no point type it turns into area type, is an error). The sizes are written into the characters and fitted again after every edit to the text or the frame, in the same undo step; at a size limit a line can be narrower than the frame or wrap. An empty line keeps its size. Block replaces Auto Size and Shrink Text to Fit (Area Type Options › Block is the same setting). Off, the text keeps the sizes it was drawn at. Turning it on turns point type into area type with Block on, with the default Area Type Options but the gaps (options kept from an earlier frame do not carry over): the frame is as wide (along the lines) as the widest line as typed with its paragraph's indents, so that line keeps its size and sits where it was (by its own alignment), the other lines are set to that width (when negative indents take more than that line's width, the frame is as wide as the line, and Block makes it larger), and the frame then grows in depth (down, or to the left for vertical type) to hold every fitted line, around any Text Wrap objects above it; the gaps apply to it as to area type. Point type with no line to fit (empty, or only spaces and breaks) is left as it is, and so is point type when it is turned off; a selection holding type in a thread is refused (threading type turns Dynamic Text off, keeping its drawn sizes). When nothing changes, no undo step is recorded → {on, ids, fitScale (the first object's factor; 1 when off and for area type), wordGap?, lineGap? (the first area type's; left out without area type)}", + "{ids?|id?, on?: bool, wordGap?: % of a word space 0..1000 (100), lineGap?: pt -1296..1296 (0)} turn Dynamic Text on or off for the selected type on a path and area type, or turn it on for point type (on omitted: the opposite of the first object's setting, point type counting as off, or on when a gap is given). On type on a path, the layout scales the text by one factor (every character's size, leading and baseline shift; Type on a Path Options › Spacing stays) so that it fills the span between its start and end brackets, larger or smaller, and fits it again after every edit to the text, the path or the brackets; the first character's size moves in steps of 0.1 pt within 0.1 to 1,296 pt, and at 0.1 pt text that still runs past the end bracket overflows. The stored sizes keep their proportions. On area type it is Block: each line as typed (each paragraph, and each forced line break in one; lines are not broken again) is set to the frame's width, less the inset, the gutters and the paragraph's indents, by changing its font size only: its first character's size, in steps of 0.1 pt within 0.1 to 1,296 pt, the line's other characters keeping their proportions to it, with baseline shifts following. Every character's leading is its size plus lineGap (a leading change on the text, from text.setStyle, text.setRangeStyle, type.step, a character style or Text Tweaker, sets lineGap to the new leading less the size of the first character changed), and the layout sets every paragraph with wordGap as its Desired word spacing, its Minimum or Maximum moving out to wordGap when wordGap lies outside it (the paragraphs keep their own Justification… values, which apply again when Block is off; the gaps are area type's, and are kept while Block is off; a gap with no area type in the selection, and no point type it turns into area type, is an error). The sizes are written into the characters and fitted again after every edit to the text or the frame, in the same undo step; at a size limit a line can be narrower than the frame or wrap. An empty line keeps its size. Block replaces Auto Size and Shrink Text to Fit (Area Type Options › Block is the same setting). Off, the text keeps the sizes it was drawn at. Turning it on turns point type into area type with Block on, with the default Area Type Options but the gaps (options kept from an earlier frame do not carry over): the frame is as wide (along the lines) as the widest line as typed with its paragraph's indents, so that line keeps its size and sits where it was (by its own alignment), the other lines are set to that width (when negative indents take more than that line's width, the frame is as wide as the line, and Block makes it larger), and the frame then grows in depth (down, or to the left for vertical type) to hold every fitted line, around any Text Wrap objects above it; the gaps apply to it as to area type. Point type with no line to fit (empty, or only spaces and breaks) is left as it is, and so is point type when it is turned off; a selection holding type in a thread is refused (threading type turns Dynamic Text off, keeping its drawn sizes). When nothing changes, no undo step is recorded → {on, ids, fitScale (the first object's factor; 1 when off and for area type), wordGap?, lineGap? (the first area type's; left out without area type)}", has_dynamic_type, dynamic_text ), diff --git a/docs/mcp.md b/docs/mcp.md index 7a1373b938..2c579a9856 100644 --- a/docs/mcp.md +++ b/docs/mcp.md @@ -11329,14 +11329,14 @@ lines. The rest are VectorCraft's own rules: `text.setRangeStyle {leading}` (the Character panel's and the Properties panel's Leading field and its list), `type.step {attribute: "leading"}` (the Type tool's Alt+arrow leading steps), `charStyle.apply` with a style that sets a leading (or with `clearOverrides` when the Normal style sets one), `charStyle.edit` and `charStyle.setAttrs` when - the new definition gives its users another leading, `appearance.copyFrom` copying character attributes (the - Eyedropper) and `addon.type.textTweaker {attribute: "leading"}` (from its first changed character). `"auto"` takes - the first character's Auto leading. Every line then spreads or tightens by the change to that character's leading. - In a shaped frame where the moved lines take another size, the gap is worked out again from the new size, up to four - times, and the leading set can then differ by the last change in that size. Area Type Options and the Properties - panel show the new Line Gap. When the changed characters share one size and the gap is within its range, the Leading - field shows the leading set. Otherwise each character takes its own size plus the gap, and the field is blank where - those differ. + the new definition gives its users another leading, and `addon.type.textTweaker {attribute: "leading"}`. Text + Tweaker's ramp sets the gap from its first changed character, and every other character then takes its size plus + that gap, so the ramp does not vary the leading. `"auto"` takes the first character's Auto leading. Every line then + spreads or tightens by the change to that character's leading. The Eyedropper (`appearance.copyFrom`) copies a whole + character style, so it leaves `lineGap` as it is. In a shaped frame where the moved lines take another size, the gap + is worked out again from the new size, up to four times, and the leading set can then differ by the last change in + that size. When the changed characters share one size and the gap is within its range, the Leading field shows the + leading set. Otherwise each character takes its own size plus the gap, and the field is blank where those differ. `keepLineGap: true` on `text.setStyle` and `text.setRangeStyle` leaves `lineGap` as it is, and the Character panel's Reset Panel sends it, so a reset to Auto leading keeps the frame's Line Gap. Point type, type on a path and area type with Block off keep their own leading. diff --git a/docs/target-app-parity.md b/docs/target-app-parity.md index 19083cb60f..d17a4d3b25 100644 --- a/docs/target-app-parity.md +++ b/docs/target-app-parity.md @@ -1795,7 +1795,7 @@ Moved from the ROADMAP's "Shipped so far" on 2026-10-10. Update it when a featur Type › Type on a Path › Center on Top and Center on Bottom (`type.pathCenter.top`, `type.pathCenter.bottom`, also on the Contextual Task Bar for type on a closed path) slide type on a closed path so the middle of its span lands on the path's topmost or bottommost point as drawn, keep the span's length, and set the first paragraph to Center unless it is Center or Justify Center. This is VectorCraft's own behavior (`crates/geom/src/arc.rs`, `crates/engine/src/tests/pathtype.rs`). Type on a Path Options › Align to Path (option names as in [Create type on a path](https://helpx.adobe.com/illustrator/desktop/design-with-text/edit-format-text/create-type-on-a-path.html)) moves each character by its own font, size and vertical scale: Ascender runs the top of the font's em box along the path (the ideographic em box that its `BASE` table, its typographic or `hhea` box or its ideographs give, else an em box centered on the cap height), Descender runs the bottom of the font's bounding box along it, and Center runs a line at half the height of the top of the font's H above the baseline along it. In vertical type, Ascender and Descender move the characters half an em, and Center leaves them on the path. These distances are VectorCraft's own values (`tests::on_path_align_runs_each_glyph_by_its_own_metrics`, `tests::on_path_align_finds_the_em_box_of_each_kind_of_face`, `tests::on_path_align_in_vertical_type_moves_half_an_em`). Type › Dynamic Text (`type.dynamicText`, also on the Contextual Task Bar for type on a path) sizes type on a path to fill the span between its start and end brackets and fits it again after each edit to the text or a bracket ([Dynamic Text overview](https://helpx.adobe.com/photoshop/desktop/text-typography/work-with-dynamic-text/dynamic-text-overview.html), [start and end points](https://helpx.adobe.com/photoshop/desktop/text-typography/work-with-dynamic-text/reposition-start-and-end-points.html)). VectorCraft's own rules: reshaping or scaling the path fits the text again; one factor scales every size, leading and baseline shift; the first character's size moves in 0.1 pt steps within 0.1 to 1,296 pt; turning it off, threading the type or Release Type on a Path keeps the drawn sizes; SVG, EPS, legacy `.ai` and the editing data write the drawn sizes (`crates/text/src/tests/fit.rs`, `crates/engine/src/tests/dynamic_text.rs`). - Dynamic Text on area type is Block (Type › Dynamic Text, the Contextual Task Bar, Area Type Options › Block, the Properties panel's Dynamic Text checkbox with Word Gap and Line Gap; [Dynamic Text overview](https://helpx.adobe.com/photoshop/desktop/text-typography/work-with-dynamic-text/dynamic-text-overview.html)): each line as typed is set to the frame's width by its font size, again after every edit to the text or the frame. VectorCraft's own rules: lines are not broken again, the first character's size moves in 0.1 pt steps within 0.1 to 1,296 pt, Word Gap (0 to 1,000 %, default 100) is the Desired word spacing and Line Gap (-1,296 to 1,296 pt, default 0) is added to each size for the leading, a leading change (the Character and Properties panels, the Type tool's Alt+arrow leading steps, a character style, the Eyedropper, Text Tweaker) sets Line Gap to the new leading less the size of the first character changed, Reset Panel keeps Line Gap, the sizes are written into the characters, threaded frames cannot use it, and Convert To Point Type turns it off, keeping the sizes (`crates/engine/src/cmd/typecmd/block_tests.rs`). + Dynamic Text on area type is Block (Type › Dynamic Text, the Contextual Task Bar, Area Type Options › Block, the Properties panel's Dynamic Text checkbox with Word Gap and Line Gap; [Dynamic Text overview](https://helpx.adobe.com/photoshop/desktop/text-typography/work-with-dynamic-text/dynamic-text-overview.html)): each line as typed is set to the frame's width by its font size, again after every edit to the text or the frame. VectorCraft's own rules: lines are not broken again, the first character's size moves in 0.1 pt steps within 0.1 to 1,296 pt, Word Gap (0 to 1,000 %, default 100) is the Desired word spacing and Line Gap (-1,296 to 1,296 pt, default 0) is added to each size for the leading, a leading change (the Character and Properties panels, the Type tool's Alt+arrow leading steps, a character style, Text Tweaker) sets Line Gap to the new leading less the size of the first character changed, Reset Panel keeps Line Gap, the sizes are written into the characters, threaded frames cannot use it, and Convert To Point Type turns it off, keeping the sizes (`crates/engine/src/cmd/typecmd/block_tests.rs`). Dynamic Text on point type (Type › Dynamic Text, the Contextual Task Bar; [Adjust formatting and resize text](https://helpx.adobe.com/photoshop/desktop/text-typography/work-with-dynamic-text/adjust-formatting-and-resize-text-with-dynamic-text.html) applies it to existing text) turns it into area type with Block on. VectorCraft's own rules: the frame is as wide as the widest line with its indents, so that line keeps its size and place across the page, and it grows in depth to hold every fitted line (`crates/engine/src/cmd/typecmd/block_tests.rs`). Type › Dynamic Text Presets › Circle, Arch and Bow (`type.dynamicTextPreset`) put point type or type on a path on a circular, upward-curving or downward-curving path with Dynamic Text on, with the text's position against the path (above, center, below) and its direction ([Dynamic Text overview](https://helpx.adobe.com/photoshop/desktop/text-typography/work-with-dynamic-text/dynamic-text-overview.html)). VectorCraft's own rules: the circle is as wide as the text and the text starts at its bottom; Arch and Bow are a 120° arc whose chord is as wide as the text; above, center and below are Align to Path's Descender, Center and Ascender (`crates/engine/src/tests/dynamic_text.rs`). The frames of threaded text share one Optical Margin Alignment setting: turning it on or off in one frame sets it in every frame, threading frames gives the thread its first frame's setting, and frames taken out of a thread keep it.