mirror of
https://github.com/storytold/vectorcraft.git
synced 2026-11-27 16:59:43 +01:00
Merge pull request #9008 from dotCooCoo/fix/dynamic-text-leading-line-gap
Dynamic Text: a leading change on area type with Block on moves its Line Gap
This commit is contained in:
11 files changed
+589
-35
No files matched your search
@@ -20,7 +20,7 @@ use vectorcraft_text::edit;
|
||||
use super::super::menucmds::whole_or;
|
||||
use super::super::object::choice;
|
||||
use super::super::textedit::{CharChange, text_mut, text_ref, type_ranges};
|
||||
use super::super::typecmd::refresh_bounds;
|
||||
use super::super::typecmd::{refresh_bounds, refresh_with_given_leading};
|
||||
use super::super::typemenu::{bake_dynamic_text, text_ids};
|
||||
use super::super::{CommandSpec, bad, cmd, has_selection, number_or, switch_or, targets};
|
||||
use crate::{EngineError, Result, Session};
|
||||
@@ -170,7 +170,11 @@ fn text_tweaker(s: &mut Session, p: &Value) -> Result<Value> {
|
||||
for (id, changes) in &plans {
|
||||
let t = text_mut(d, *id).ok_or(EngineError::NoNode(*id))?;
|
||||
t.runs = tweak(std::mem::take(&mut t.runs), changes);
|
||||
refresh_bounds(t);
|
||||
// With Block on, the first changed character's leading goes to the frame's line gap.
|
||||
match changes.first().filter(|_| key == "leading") {
|
||||
Some(&(at, _)) => refresh_with_given_leading(t, at),
|
||||
None => refresh_bounds(t),
|
||||
}
|
||||
}
|
||||
Ok(())
|
||||
})?;
|
||||
|
||||
@@ -40,7 +40,7 @@ pub fn specs() -> Vec<CommandSpec> {
|
||||
"Character",
|
||||
[],
|
||||
None,
|
||||
"{id? (default: the one selected type object), start?: byte, end?: byte (default: all text), story?: bool = false (all the text of every frame of the threaded story `id` is a frame of, in one undo step; no `start` or `end`), font?, style?, size?: pt 0.1..1296 (outside it: an error), leading?: pt|\"auto\", tracking?, kerning?: 1/1000 em|\"auto\"|\"optical\" (the space after each character), kerningBefore?: 1/1000 em -1000..10000 (the space before a character that starts a line by itself: the first character of the text, of a paragraph or after a forced line break; no effect elsewhere; 0 by default), baselineShift?: pt, hScale?: %, vScale?: %, rotation?: deg counter-clockwise (0: upright), fill?: colour|\"none\", stroke?: colour|\"none\" (#rrggbbaa and #rgba are refused in both), keepModel?: bool (fill and stroke, as paint.setFill), strokeWidth?: pt, strokeOptions?: {weight?, cap?, join?, miterLimit?, align?, dash?, dashOffset?, alignDashes?} (as stroke.set: the character stroke), underline?, strikethrough?, allCaps?: bool, smallCaps?: bool, position?: \"normal\"|\"superscript\"|\"subscript\" (sizes from Document Setup), features?: [\"dlig\", \"-liga\", \"salt=2\", …] (swsh, ss01–ss20, salt, titl, pnum, lnum, sups, subs, numr, dnom and aalt take the font's alternate number as `tag=N`, N 0–65535: \"salt=2\" draws the second alternate of each glyph that has one, \"salt\" is \"salt=1\", \"-salt\" and \"salt=0\" are off; \"hkna\" is H or V Style, kana in the font's forms for the writing direction, shaped as `vkna` in vertical type, and \"ital\" is Roman Italics, half-width alphanumerics in the font's italic forms, both on or off only; the range is shaped with its word, so a letter's alternate keeps it joined to its neighbours), featureChanges?: [\"tnum\", \"-onum\", \"salt=2\", …] (OpenType features turned on, or with - off, on top of each character's own, a value replacing the feature's last one; its other features are kept), charAlign?: \"romanBaseline\"|\"emBoxTop\"|\"emBoxCenter\"|\"emBoxBottom\"|\"icfTop\"|\"icfBottom\", proportionalMetrics?: bool (full-width glyphs on the font's proportional widths: `palt` in horizontal type, `vpal` in vertical type), tateChuYoko?: bool (Character panel menu › Tate-chu-yoko, with Show East Asian Options: in vertical type those characters stand side by side across one em of the column; kept on the characters and ignored in horizontal type), tcyUpDown?, tcyLeftRight?: pt -1296..1296 (Character panel menu › Tate-chu-yoko Settings: in vertical type a block of tate-chu-yoko characters moves up by a positive Up/Down and down by a negative one, right by a positive Left/Right and left by a negative one, as one piece with the values of its first character; on a vertical path a positive Up/Down moves it toward the path's start and a positive Left/Right to the path's left; 0 by default; automatic digit blocks and horizontal type do not move; neither turns tateChuYoko on), warichu?: bool (Character panel menu › Warichu, with Show East Asian Options: the characters are set at warichuScale percent of their size and stacked on warichuLines lines inside their line, one above the other in horizontal type and side by side in vertical type, the first line above or to the right; a stretch of them is one block with the settings of its first character that stays whole on one line and may run past its end; type on a path sets them at their own size), warichuLines?: 1..6 (default 2), warichuGap?: pt 0..100 (the space between the lines, default 0), warichuScale?: % 10..100 (default 50), warichuAlign?: \"auto\"|\"left\"|\"center\"|\"right\"|\"justifyLeft\"|\"justifyCenter\"|\"justifyRight\"|\"justifyAll\" (Warichu Settings: how the lines line up along the block, which is as long as its longest line; the justify values spread every line but the last, which is set left, centered or right, or spread with justifyAll; auto, the default, sets them as justifyLeft; left and right are top and bottom in vertical type; none of them turns warichu on), akiLeft?, akiRight?: 1/1000 em 0..1000 (Character panel › Insert Aki Left and Right, with Show East Asian Options: space before and after each character in reading order, on its left and right in left-to-right type, on its right and left in right-to-left type, above and below it in vertical type; a ligature or a letter with its marks takes the values of its first character; line wrapping counts it, alignment keeps it at a line's ends and justification does not stretch or narrow it; 0 by default; a value that is not a number or is outside the range is refused, naming the key), tsume?: % 0..100 (Character panel › Tsume, with Show East Asian Options: the share of the blank space on each side of each character's ink, inside its own width, that is taken away, the glyph keeping its shape; 100 sets the ink edge to edge; a color glyph's ink is its color art or bitmap; a character without ink, such as a space, keeps its width; a ligature or a
Line truncated
|
||||
"{id? (default: the one selected type object), start?: byte, end?: byte (default: all text), story?: bool = false (all the text of every frame of the threaded story `id` is a frame of, in one undo step; no `start` or `end`), font?, style?, size?: pt 0.1..1296 (outside it: an error), leading?: pt|\"auto\" (on area type with Dynamic Text (Block) on, a leading change sets the frame's line gap to the new leading less the size of the first character changed, within -1296..1296 pt, as text.setStyle), keepLineGap?: bool = false (as text.setStyle), tracking?, kerning?: 1/1000 em|\"auto\"|\"optical\" (the space after each character), kerningBefore?: 1/1000 em -1000..10000 (the space before a character that starts a line by itself: the first character of the text, of a paragraph or after a forced line break; no effect elsewhere; 0 by default), baselineShift?: pt, hScale?: %, vScale?: %, rotation?: deg counter-clockwise (0: upright), fill?: colour|\"none\", stroke?: colour|\"none\" (#rrggbbaa and #rgba are refused in both), keepModel?: bool (fill and stroke, as paint.setFill), strokeWidth?: pt, strokeOptions?: {weight?, cap?, join?, miterLimit?, align?, dash?, dashOffset?, alignDashes?} (as stroke.set: the character stroke), underline?, strikethrough?, allCaps?: bool, smallCaps?: bool, position?: \"normal\"|\"superscript\"|\"subscript\" (sizes from Document Setup), features?: [\"dlig\", \"-liga\", \"salt=2\", …] (swsh, ss01–ss20, salt, titl, pnum, lnum, sups, subs, numr, dnom and aalt take the font's alternate number as `tag=N`, N 0–65535: \"salt=2\" draws the second alternate of each glyph that has one, \"salt\" is \"salt=1\", \"-salt\" and \"salt=0\" are off; \"hkna\" is H or V Style, kana in the font's forms for the writing direction, shaped as `vkna` in vertical type, and \"ital\" is Roman Italics, half-width alphanumerics in the font's italic forms, both on or off only; the range is shaped with its word, so a letter's alternate keeps it joined to its neighbours), featureChanges?: [\"tnum\", \"-onum\", \"salt=2\", …] (OpenType features turned on, or with - off, on top of each character's own, a value replacing the feature's last one; its other features are kept), charAlign?: \"romanBaseline\"|\"emBoxTop\"|\"emBoxCenter\"|\"emBoxBottom\"|\"icfTop\"|\"icfBottom\", proportionalMetrics?: bool (full-width glyphs on the font's proportional widths: `palt` in horizontal type, `vpal` in vertical type), tateChuYoko?: bool (Character panel menu › Tate-chu-yoko, with Show East Asian Options: in vertical type those characters stand side by side across one em of the column; kept on the characters and ignored in horizontal type), tcyUpDown?, tcyLeftRight?: pt -1296..1296 (Character panel menu › Tate-chu-yoko Settings: in vertical type a block of tate-chu-yoko characters moves up by a positive Up/Down and down by a negative one, right by a positive Left/Right and left by a negative one, as one piece with the values of its first character; on a vertical path a positive Up/Down moves it toward the path's start and a positive Left/Right to the path's left; 0 by default; automatic digit blocks and horizontal type do not move; neither turns tateChuYoko on), warichu?: bool (Character panel menu › Warichu, with Show East Asian Options: the characters are set at warichuScale percent of their size and stacked on warichuLines lines inside their line, one above the other in horizontal type and side by side in vertical type, the first line above or to the right; a stretch of them is one block with the settings of its first character that stays whole on one line and may run past its end; type on a path sets them at their own size), warichuLines?: 1..6 (default 2), warichuGap?: pt 0..100 (the space between the lines, default 0), warichuScale?: % 10..100 (default 50), warichuAlign?: \"auto\"|\"left\"|\"center\"|\"right\"|\"justifyLeft\"|\"justifyCenter\"|\"justifyRight\"|\"justifyAll\" (Warichu Settings: how the lines line up along the block, which is as long as its longest line; the justify values spread every line but the last, which is set left, centered or right, or spread with justifyAll; auto, the default, sets them as justifyLeft; left and right are top and bottom in vertical type; none of them turns warichu on), akiLeft?, akiRight?: 1/1000 em 0..1000 (Character panel › Insert Aki Left and Right, with Show East Asian Options: space before and after each character in reading order, on its left and right in left-to-right type, on its right and left in right-to-left type, above and below it in vertical type; a ligature or a letter with its marks takes the values of its first character; line wrapping counts it, alignment keeps it at a line's ends and justification does not stretch or narrow it; 0 by default; a value that is not a number or is outside the range is refused, naming the key), tsume?: % 0..100 (Character panel › Tsume, with Show East Asian Options: the share of the blank space on each side of each c
Line truncated
|
||||
has_doc,
|
||||
set_range_style
|
||||
),
|
||||
@@ -103,7 +103,7 @@ pub fn specs() -> Vec<CommandSpec> {
|
||||
"Step Type",
|
||||
[],
|
||||
None,
|
||||
"{attribute: \"size\"|\"leading\"|\"tracking\"|\"kerning\"|\"baselineShift\", by?: steps (1; negative steps down), id?, start?: byte, end?: byte, ids?: [id…] (instead of id)} step type by the Preferences › Type increments (size and leading: typeSizeIncrement, pt; tracking and kerning: trackingIncrement, 1/1000 em; baseline shift: baselineShiftIncrement, pt), what the Type tool's Alt+arrows do (Cmd/Ctrl too: five steps; horizontal: ←/→ kerning at the caret or tracking of the selection, ↑/↓ leading, Shift+↑/↓ baseline shift; vertical: ↓/↑ with or without Shift kerning or tracking, ←/→ leading, Shift+→/← baseline shift; mixed selected text objects use the horizontal mapping). The range of `id`, else the type objects in `ids`, else the text the Type tool has selected (at a caret: kerning steps the space after the character before it, or at the start of a line (of the text, a paragraph, or after a forced line break) the space before the character after it (kerningBefore, as text.setRangeStyle), and nothing at an empty line's start; leading its paragraph), else every selected type object → {ids}",
|
||||
"{attribute: \"size\"|\"leading\"|\"tracking\"|\"kerning\"|\"baselineShift\", by?: steps (1; negative steps down), id?, start?: byte, end?: byte, ids?: [id…] (instead of id)} step type by the Preferences › Type increments (size and leading: typeSizeIncrement, pt; tracking and kerning: trackingIncrement, 1/1000 em; baseline shift: baselineShiftIncrement, pt), what the Type tool's Alt+arrows do (Cmd/Ctrl too: five steps; horizontal: ←/→ kerning at the caret or tracking of the selection, ↑/↓ leading, Shift+↑/↓ baseline shift; vertical: ↓/↑ with or without Shift kerning or tracking, ←/→ leading, Shift+→/← baseline shift; mixed selected text objects use the horizontal mapping). The range of `id`, else the type objects in `ids`, else the text the Type tool has selected (at a caret: kerning steps the space after the character before it, or at the start of a line (of the text, a paragraph, or after a forced line break) the space before the character after it (kerningBefore, as text.setRangeStyle), and nothing at an empty line's start; leading its paragraph), else every selected type object. On area type with Dynamic Text (Block) on, a leading change sets the frame's line gap to the new leading less the size of the first character changed, within -1296..1296 pt, as text.setStyle → {ids}",
|
||||
has_doc,
|
||||
type_step
|
||||
),
|
||||
@@ -1213,6 +1213,7 @@ fn set_range_style(s: &mut Session, p: &Value) -> Result<Value> {
|
||||
},
|
||||
};
|
||||
let story = switch_or(p, "story", false, C)?;
|
||||
let keep_line_gap = switch_or(p, "keepLineGap", false, C)?;
|
||||
if story && ["start", "end"].iter().any(|k| p.get(*k).is_some_and(|v| !v.is_null())) {
|
||||
return Err(bad(C, "`story` styles the whole story: give no `start` or `end`"));
|
||||
}
|
||||
@@ -1256,7 +1257,11 @@ fn set_range_style(s: &mut Session, p: &Value) -> Result<Value> {
|
||||
let styled = if a == b { t.runs.clone() } else { unprotected_runs(&t.runs, a, b, &kept) };
|
||||
set.extend(styled.iter().flat_map(super::fonts::run_fonts));
|
||||
}
|
||||
refresh_bounds(t);
|
||||
// With Block on, the leading goes to the frame's line gap.
|
||||
match change.leading.filter(|_| !keep_line_gap).and_then(|l| super::typecmd::styled_start(t, a, b).map(|at| (at, l))) {
|
||||
Some((at, l)) => super::typecmd::refresh_with_leading(t, at, l),
|
||||
None => refresh_bounds(t),
|
||||
}
|
||||
n = if *f == id { t.runs.len() } else { n };
|
||||
}
|
||||
Ok(n)
|
||||
@@ -2077,7 +2082,11 @@ fn type_step(s: &mut Session, p: &Value) -> Result<Value> {
|
||||
}
|
||||
}
|
||||
edit::replace_range_styled(&mut t.runs, a, b, &runs);
|
||||
refresh_bounds(t);
|
||||
// With Block on, the step goes to the frame's line gap.
|
||||
match runs.first().filter(|_| matches!(step, Step::Leading)) {
|
||||
Some(first) => super::typecmd::refresh_with_leading(t, a, first.style.leading),
|
||||
None => refresh_bounds(t),
|
||||
}
|
||||
}
|
||||
Ok(())
|
||||
})?;
|
||||
|
||||
@@ -500,13 +500,33 @@ fn update_users(d: &mut Document, kind: Kind, name: &str, old: &Map<String, Valu
|
||||
};
|
||||
each_text_mut(d, &mut |t| {
|
||||
let mut changed = false;
|
||||
// The first character whose leading the new definition changed.
|
||||
let mut leading_at = None;
|
||||
// Substitute the old definition only for leading generated by Block.
|
||||
let block = t.dynamic_text && matches!(t.kind, vectorcraft_doc::TextKind::Area { .. });
|
||||
let block_metrics = super::typecmd::block_fit_metrics(t).map(|(points, gap, _)| (gap / points, super::typecmd::BLOCK_SIZES.0 / points));
|
||||
let old_leading = old
|
||||
.get("leading")
|
||||
.filter(|_| block && old.get("leading") != new.get("leading"))
|
||||
.and_then(|v| serde_json::from_value::<Option<f64>>(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
|
||||
.filter(|_| block_metrics.is_some_and(|(gap, minimum)| r.style.leading == Some((r.style.size + gap).max(minimum))))
|
||||
{
|
||||
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;
|
||||
if r.style.leading != was && leading_at.is_none() {
|
||||
leading_at = Some(off);
|
||||
}
|
||||
}
|
||||
off += r.text.len();
|
||||
}
|
||||
}
|
||||
Kind::Para => {
|
||||
@@ -519,7 +539,11 @@ fn update_users(d: &mut Document, kind: Kind, name: &str, old: &Map<String, Valu
|
||||
}
|
||||
}
|
||||
if changed {
|
||||
refresh_bounds(t);
|
||||
// With Block on, a leading the new definition gives goes to the frame's line gap.
|
||||
match leading_at {
|
||||
Some(at) => super::typecmd::refresh_with_given_leading(t, at),
|
||||
None => refresh_bounds(t),
|
||||
}
|
||||
}
|
||||
Ok(())
|
||||
})
|
||||
@@ -857,6 +881,8 @@ fn apply(s: &mut Session, p: &Value, kind: Kind) -> Result<Value> {
|
||||
let attrs = kind.attrs(d, &name).ok_or_else(|| bad(&c, format!("no style `{name}`")))?;
|
||||
let normal = kind.attrs(d, kind.normal()).unwrap_or_default();
|
||||
let clear = bool_or(p, "clearOverrides", false);
|
||||
// The style sets a leading, or clearing overrides gives the text Normal's.
|
||||
let sets_leading = kind == Kind::Char && (attrs.contains_key("leading") || (clear && normal.contains_key("leading")));
|
||||
let style_name = (name != kind.normal()).then(|| name.clone());
|
||||
// A Type tool range or whole text objects.
|
||||
let text_range = super::typecmd::TextRange::parse(p, &c)?;
|
||||
@@ -883,6 +909,8 @@ fn apply(s: &mut Session, p: &Value, kind: Kind) -> Result<Value> {
|
||||
s.edit_named("Apply {name}", &name, name == kind.normal(), |d, _| {
|
||||
for id in &ids {
|
||||
let Some(t) = text_mut(d, *id) else { continue };
|
||||
// The first character given the style's leading.
|
||||
let mut leading_at = None;
|
||||
match kind {
|
||||
Kind::Char => {
|
||||
let len = vectorcraft_text::edit::runs_len(&t.runs);
|
||||
@@ -903,6 +931,7 @@ fn apply(s: &mut Session, p: &Value, kind: Kind) -> Result<Value> {
|
||||
if let Some(e) = err {
|
||||
return Err(e);
|
||||
}
|
||||
leading_at = sets_leading.then(|| super::typecmd::styled_start(t, a.min(b), a.max(b))).flatten();
|
||||
}
|
||||
Kind::Para => {
|
||||
let mut v = t.paragraph_styles();
|
||||
@@ -916,7 +945,11 @@ fn apply(s: &mut Session, p: &Value, kind: Kind) -> Result<Value> {
|
||||
t.set_paragraph_styles(v);
|
||||
}
|
||||
}
|
||||
refresh_bounds(t);
|
||||
// With Block on, a leading the style sets goes to the frame's line gap.
|
||||
match leading_at {
|
||||
Some(at) => super::typecmd::refresh_with_given_leading(t, at),
|
||||
None => refresh_bounds(t),
|
||||
}
|
||||
}
|
||||
Ok(())
|
||||
})?;
|
||||
|
||||
@@ -95,7 +95,7 @@ pub fn specs() -> Vec<CommandSpec> {
|
||||
"Area Type Options…",
|
||||
["Type"],
|
||||
None,
|
||||
"{ids?|id?, width?: pt, height?: pt, rows?, columns?, gutter?: pt (between rows and columns), rowGutter?: pt|null (between rows when it differs from gutter, which is then between columns; gutter given alone sets both; the reply gives the rows' gutter either way), inset?: pt, firstBaseline?: ascent|capHeight|xHeight|leading|emBoxHeight|fixed (emBoxHeight: the top of the first line's ideographic em box, the largest on the line, touches the top of the type area inside the inset), firstBaselineMin?: pt (the least distance from that top to the first baseline; with fixed, the distance), verticalAlign?: top|center|bottom|justify, flow?: columns|rows (Text Flow: down each column's rows, then across, the default; or across each row's columns, then down), fit?: none|autoHeight|shrinkText|block, fitMinPercent?: 10..100, wordGap?: % 0..1000, lineGap?: pt -1296..1296, …the keys of its own reply (it can be passed back; the values it only reports are ignored)} set the selected area type's options (each frame takes the options given over its own and keeps the rest; fit resolves against each frame's own; options that change nothing add no undo step); width and height size the type area from its top-left corner, along the type's own axes, and the text reflows at its size (with fit autoHeight, Auto Size, the frame's height follows the text after every edit and height is ignored; setting the height by hand turns it off); fit shrinkText scales overflowing text down (size, leading, baseline shift) by the largest factor down to fitMinPercent % (default 50) that makes it fit; fit block is Dynamic Text's Block, as type.dynamicText sets it (in place of Auto Size and Shrink Text to Fit; threaded frames are refused; another fit turns it off, keeping the sizes it wrote), and wordGap and lineGap set its gaps (kept while Block is off; out of range is an error) (none given: query) → the first object's options, plus wordGap and lineGap, overflow (the text doesn't fit its frame) and fitScale (Shrink Text's factor, 1 unshrunk)",
|
||||
"{ids?|id?, width?: pt, height?: pt, rows?, columns?, gutter?: pt (between rows and columns), rowGutter?: pt|null (between rows when it differs from gutter, which is then between columns; gutter given alone sets both; the reply gives the rows' gutter either way), inset?: pt, firstBaseline?: ascent|capHeight|xHeight|leading|emBoxHeight|fixed (emBoxHeight: the top of the first line's ideographic em box, the largest on the line, touches the top of the type area inside the inset), firstBaselineMin?: pt (the least distance from that top to the first baseline; with fixed, the distance), verticalAlign?: top|center|bottom|justify, flow?: columns|rows (Text Flow: down each column's rows, then across, the default; or across each row's columns, then down), fit?: none|autoHeight|shrinkText|block, fitMinPercent?: 10..100, wordGap?: % 0..1000, lineGap?: pt -1296..1296, …the keys of its own reply (it can be passed back; the values it only reports are ignored)} set the selected area type's options (each frame takes the options given over its own and keeps the rest; fit resolves against each frame's own; options that change nothing add no undo step); width and height size the type area from its top-left corner, along the type's own axes, and the text reflows at its size (with fit autoHeight, Auto Size, the frame's height follows the text after every edit and height is ignored; setting the height by hand turns it off); fit shrinkText scales overflowing text down (size, leading, baseline shift) by the largest factor down to fitMinPercent % (default 50) that makes it fit; fit block is Dynamic Text's Block, as type.dynamicText sets it (in place of Auto Size and Shrink Text to Fit; threaded frames are refused; another fit turns it off, keeping the sizes it wrote), and wordGap and lineGap set its gaps (kept while Block is off; out of range is an error; a leading change on the text also sets lineGap, as type.dynamicText says) (none given: query) → the first object's options, plus wordGap and lineGap, overflow (the text doesn't fit its frame) and fitScale (Shrink Text's factor, 1 unshrunk)",
|
||||
has_selection,
|
||||
area_options
|
||||
),
|
||||
@@ -140,7 +140,7 @@ pub fn specs() -> Vec<CommandSpec> {
|
||||
"Character",
|
||||
[],
|
||||
None,
|
||||
"{ids?|id?, font?, style? (font alone: the style is kept when the new family has it, else its closest), size?: pt 0.1..1296 (outside it: an error), leading?: pt|\"auto\", tracking?: 1/1000 em, justify?: \"auto\" (the start of each paragraph's direction)|\"left\"|\"center\"|\"right\"|\"justifyAll\", fill?: colour|\"none\", stroke?: colour|\"none\" (characters without a stroke weight get 1 pt; #rrggbbaa and #rgba are refused in both), keepModel?: bool (fill and stroke, as paint.setFill), strokeWidth?: pt (the character stroke's weight, in document points as stroke.set), features?: [\"dlig\", \"-liga\", \"salt=2\", …] OpenType (swsh, ss01–ss20, salt, titl, pnum, lnum, sups, subs, numr, dnom and aalt take the font's alternate number as `tag=N`, N 0–65535: \"salt=2\" draws the second alternate of each glyph that has one, \"salt\" is \"salt=1\", \"-salt\" and \"salt=0\" are off; \"hkna\" is H or V Style, kana in the font's forms for the writing direction, shaped as `vkna` in vertical type, and \"ital\" is Roman Italics, half-width alphanumerics in the font's italic forms, both on or off only), featureChanges?: [\"tnum\", \"-onum\", \"salt=2\", …] (OpenType features turned on, or with - off, on top of each character's own, a value replacing the feature's last one; its other features are kept), start?: byte, end?: byte} (size/leading are document points after object scaling; with a range: the character attributes style that range and justify the paragraphs it touches; without: all the text; no undo step when no character, paragraph or graph label style changes) → {ids, overflow?: [id…] (area type and type on a path whose text no longer fits; left out when all fits), warning?: text (the font or style set isn't available: its type is drawn in the fallback font or the family's closest style)}",
|
||||
"{ids?|id?, font?, style? (font alone: the style is kept when the new family has it, else its closest), size?: pt 0.1..1296 (outside it: an error), leading?: pt|\"auto\", keepLineGap?: bool = false (true: Dynamic Text (Block) keeps the frame's line gap, as Reset Panel does), tracking?: 1/1000 em, justify?: \"auto\" (the start of each paragraph's direction)|\"left\"|\"center\"|\"right\"|\"justifyAll\", fill?: colour|\"none\", stroke?: colour|\"none\" (characters without a stroke weight get 1 pt; #rrggbbaa and #rgba are refused in both), keepModel?: bool (fill and stroke, as paint.setFill), strokeWidth?: pt (the character stroke's weight, in document points as stroke.set), features?: [\"dlig\", \"-liga\", \"salt=2\", …] OpenType (swsh, ss01–ss20, salt, titl, pnum, lnum, sups, subs, numr, dnom and aalt take the font's alternate number as `tag=N`, N 0–65535: \"salt=2\" draws the second alternate of each glyph that has one, \"salt\" is \"salt=1\", \"-salt\" and \"salt=0\" are off; \"hkna\" is H or V Style, kana in the font's forms for the writing direction, shaped as `vkna` in vertical type, and \"ital\" is Roman Italics, half-width alphanumerics in the font's italic forms, both on or off only), featureChanges?: [\"tnum\", \"-onum\", \"salt=2\", …] (OpenType features turned on, or with - off, on top of each character's own, a value replacing the feature's last one; its other features are kept), start?: byte, end?: byte} (size/leading are document points after object scaling; on area type with Dynamic Text (Block) on, a leading change sets the frame's line gap (text.areaOptions lineGap) to the new leading less the size of the first character changed, within -1296..1296 pt, so every line spreads or tightens by the change, unless keepLineGap is true; with a range: the character attributes style that range and justify the paragraphs it touches; without: all the text; no undo step when no character, paragraph or graph label style changes) → {ids, overflow?: [id…] (area type and type on a path whose text no longer fits; left out when all fits), warning?: text (the font or style set isn't available: its type is drawn in the fallback font or the family's closest style)}",
|
||||
has_doc,
|
||||
set_style
|
||||
),
|
||||
@@ -335,6 +335,11 @@ pub(crate) fn refresh_bounds(t: &mut TextObject) {
|
||||
// Edits that changed the paragraph count keep one paragraph style per paragraph.
|
||||
t.normalize_paras();
|
||||
block::block_fit(t);
|
||||
refresh_fitted(t);
|
||||
}
|
||||
|
||||
/// The part of [`refresh_bounds`] after Block has fitted the lines.
|
||||
fn refresh_fitted(t: &mut TextObject) {
|
||||
auto_height(t);
|
||||
let lay = vectorcraft_text::layout(vectorcraft_text::FontDb::global(), t);
|
||||
t.cached_bounds = Some(lay.bounds);
|
||||
@@ -342,6 +347,36 @@ pub(crate) fn refresh_bounds(t: &mut TextObject) {
|
||||
t.cached_ink = Some((lay.bounds, vectorcraft_render::effects::preview::laid_out_ink(&lay, t)));
|
||||
}
|
||||
|
||||
/// [`refresh_bounds`] after a change that set the leading of the character at `at` to `leading`
|
||||
/// (in text space; None: Auto): on area type with Block on the change goes to the frame's line gap
|
||||
/// ([`block::leading_to_line_gap`]), and the lines are fitted again only when the gap changed.
|
||||
pub(crate) fn refresh_with_leading(t: &mut TextObject, at: usize, leading: Option<f64>) {
|
||||
if block::leading_to_line_gap(t, at, leading) {
|
||||
refresh_fitted(t);
|
||||
} else {
|
||||
refresh_bounds(t);
|
||||
}
|
||||
}
|
||||
|
||||
/// The first character a style change over `a..b` of `t` reaches, with both ends on character
|
||||
/// boundaries as [`vectorcraft_text::edit::style_range`] sets them; None when the range styles no
|
||||
/// character (empty, or inside one character, in text that is not empty).
|
||||
pub(crate) fn styled_start(t: &TextObject, a: usize, b: usize) -> Option<usize> {
|
||||
let plain = t.plain_text();
|
||||
let (a, b) = (vectorcraft_text::edit::floor_char(&plain, a), vectorcraft_text::edit::floor_char(&plain, b));
|
||||
(a != b || plain.is_empty()).then_some(a.min(b))
|
||||
}
|
||||
|
||||
/// [`refresh_with_leading`] with the leading the character at `at` was just given (a character
|
||||
/// 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);
|
||||
} else {
|
||||
refresh_bounds(t);
|
||||
}
|
||||
}
|
||||
|
||||
/// [`refresh_bounds`] for a document that is opening: the first frame takes the layout
|
||||
/// ([`vectorcraft_text::take_kept_layout`]) instead of laying the object out again.
|
||||
pub(crate) fn refresh_bounds_for_first_frame(t: &mut TextObject) {
|
||||
@@ -955,6 +990,7 @@ fn set_style(s: &mut Session, p: &Value) -> Result<Value> {
|
||||
{
|
||||
return Err(bad(C, "nothing to change"));
|
||||
}
|
||||
let keep_line_gap = switch_or(p, "keepLineGap", false, C)?;
|
||||
let range = TextRange::parse(p, C)?;
|
||||
let ids = text_targets(s, p, C)?;
|
||||
let protect = s.prefs.missing_glyph_protection && (font.is_some() || style.is_some());
|
||||
@@ -1032,7 +1068,14 @@ fn set_style(s: &mut Session, p: &Value) -> Result<Value> {
|
||||
let span = para_span(range, t);
|
||||
t.edit_paras(span, |pa| pa.justify = j);
|
||||
}
|
||||
refresh_bounds(t);
|
||||
// With Block on, the leading goes to the frame's line gap; an empty range styles nothing.
|
||||
let changed = leading.filter(|_| !keep_line_gap).and_then(|l| {
|
||||
range.map_or(Some(0), |r| Some(r.bytes(t)).filter(|(a, b)| a < b).and_then(|(a, b)| styled_start(t, a, b))).map(|at| (at, l))
|
||||
});
|
||||
match changed {
|
||||
Some((at, l)) => refresh_with_leading(t, at, l),
|
||||
None => refresh_bounds(t),
|
||||
}
|
||||
}
|
||||
// Graph labels keep a change made to all of their text through the graph being drawn again (sizes as given,
|
||||
// not in a scaled label's own units).
|
||||
@@ -1478,6 +1521,8 @@ fn set_path_handle(s: &mut Session, p: &Value) -> Result<Value> {
|
||||
#[cfg(test)]
|
||||
mod area_tests;
|
||||
mod block;
|
||||
pub(super) use block::SIZES as BLOCK_SIZES;
|
||||
pub(super) use block::fit_metrics as block_fit_metrics;
|
||||
pub(crate) use block::needed_room;
|
||||
#[cfg(test)]
|
||||
mod block_tests;
|
||||
|
||||
@@ -2,11 +2,11 @@
|
||||
//! typed is set to the frame's width by changing its font size, after every edit
|
||||
//! ([`super::refresh_bounds`]).
|
||||
|
||||
use vectorcraft_doc::{TextKind, TextObject, TextRun};
|
||||
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.
|
||||
@@ -56,6 +56,19 @@ pub(crate) fn size_at(runs: &[TextRun], byte: usize) -> f64 {
|
||||
vectorcraft_text::edit::style_at(runs, byte).size
|
||||
}
|
||||
|
||||
/// The run that holds the character at `byte` (not the one before it), else the last run.
|
||||
fn run_at(runs: &[TextRun], byte: usize) -> Option<&TextRun> {
|
||||
let mut off = 0;
|
||||
for r in runs {
|
||||
let end = off + r.text.len();
|
||||
if (off..end).contains(&byte) {
|
||||
return Some(r);
|
||||
}
|
||||
off = end;
|
||||
}
|
||||
runs.last()
|
||||
}
|
||||
|
||||
/// The stored size of each line's first character, in one pass over the runs.
|
||||
fn first_sizes(runs: &[TextRun], lines: &[TypedLine]) -> Vec<f64> {
|
||||
let mut out = Vec::with_capacity(lines.len());
|
||||
@@ -122,6 +135,71 @@ pub(crate) fn needed_room(t: &TextObject) -> Option<(f64, usize, usize)> {
|
||||
.reduce(|a, b| if b.0 > a.0 { b } else { a })
|
||||
}
|
||||
|
||||
/// Whether every character's leading is the one Block gives it: its size plus the frame's line
|
||||
/// gap (in text space, at least the least size), as [`block_fit`] sets it.
|
||||
fn block_leadings(t: &TextObject, points: f64) -> bool {
|
||||
let gap = t.area.block_gaps().1 / points;
|
||||
let min_leading = SIZES.0 / points;
|
||||
t.runs.iter().all(|r| r.style.leading == Some((r.style.size + gap).max(min_leading)))
|
||||
}
|
||||
|
||||
/// A leading change on area type with Block on ([`TextObject::dynamic_text`]), called after the
|
||||
/// change is applied to the characters: Block sets each character's leading to its size plus the
|
||||
/// frame's line gap, so the change goes to the line gap instead. The lines are fitted, so the
|
||||
/// character at `at` has the size Block gives it (a size set by the same change included); the gap
|
||||
/// is then the leading `leading` gives that character (in text space; None: Auto) less its size, in
|
||||
/// document points and kept within [`vectorcraft_doc::AreaOptions::LINE_GAP`]. That moves the gap
|
||||
/// by the change to the character's leading, so every line spreads or tightens by the same amount.
|
||||
/// A new gap moves the lines, which in a shaped frame changes the room each one has and so the size
|
||||
/// Block gives the character, so the lines are fitted again and the gap worked out again from the
|
||||
/// new size, at most [`BLOCK_PASSES`] times. True when the lines are fitted for the final gap, so the
|
||||
/// caller lays the text out without fitting it again. Point type, type on a path and area type with
|
||||
/// Block off are left as they are.
|
||||
pub(crate) fn leading_to_line_gap(t: &mut TextObject, at: usize, leading: Option<f64>) -> bool {
|
||||
if !t.dynamic_text || !matches!(t.kind, TextKind::Area { .. }) {
|
||||
return false;
|
||||
}
|
||||
let Some(points) = t.style_scale().map(|s| s.points).filter(|p| p.is_finite() && *p > 1e-12) else { return false };
|
||||
t.normalize_paras();
|
||||
let para = t.plain_text().get(..at).map_or(0, |s| s.bytes().filter(|&c| c == b'\n').count());
|
||||
for _ in 0..BLOCK_PASSES {
|
||||
block_fit(t);
|
||||
// A frame Block could not fit leaves the characters as they were.
|
||||
if !block_leadings(t, points) {
|
||||
return false;
|
||||
}
|
||||
let Some(run) = run_at(&t.runs, at) else { return true };
|
||||
let size = run.style.size;
|
||||
let new = match leading {
|
||||
Some(l) => l,
|
||||
None => {
|
||||
// Auto leading as the layout sets it: the paragraph's Auto Leading share of the em size
|
||||
// the font height reference gives the character. An inline graphic keeps its size.
|
||||
let em = if run.inline.is_some() { size } else { vectorcraft_text::FontDb::global().em_size(&run.style, t.vertical) };
|
||||
t.para_at(para).effective_leading(&CharStyle { size: em, leading: None, ..run.style.clone() })
|
||||
}
|
||||
};
|
||||
let gap = (new - size) * points;
|
||||
if !gap.is_finite() {
|
||||
return true;
|
||||
}
|
||||
let (lo, hi) = vectorcraft_doc::AreaOptions::LINE_GAP;
|
||||
let next = gap.clamp(lo, hi);
|
||||
if (next - t.area.line_gap).abs() <= 1e-9 {
|
||||
return true;
|
||||
}
|
||||
t.area.line_gap = next;
|
||||
}
|
||||
false
|
||||
}
|
||||
|
||||
/// [`leading_to_line_gap`] with the leading the character at `at` was just given (a character
|
||||
/// 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)
|
||||
}
|
||||
|
||||
/// The size a line set at `size` points and `width` wide takes to fill `avail`, its width growing
|
||||
/// by `slope` a point of size (`width / size` when the whole line follows its size): rounded down
|
||||
/// to tenths and kept within [`SIZES`]. A line that fits and would not fit a tenth larger keeps its
|
||||
@@ -140,6 +218,21 @@ fn tenths(points: f64) -> f64 {
|
||||
((points * 10.0 + 1e-6).floor() / 10.0).clamp(SIZES.0, SIZES.1)
|
||||
}
|
||||
|
||||
pub(crate) fn fit_metrics(t: &TextObject) -> Option<(f64, f64, f64)> {
|
||||
if !t.dynamic_text {
|
||||
return None;
|
||||
}
|
||||
let TextKind::Area { frame } = &t.kind else { return None };
|
||||
let (_, line_gap) = t.area.block_gaps();
|
||||
let b = frame.bounds().filter(|b| [b.x0, b.y0, b.x1, b.y1].iter().all(|v| v.is_finite()))?;
|
||||
let points = t.style_scale().map(|s| s.points).filter(|p| p.is_finite() && *p > 1e-12)?;
|
||||
let a = &t.area;
|
||||
let (along, cells, gutter) = if t.vertical { (b.height(), a.rows, a.row_gutter.unwrap_or(a.gutter)) } else { (b.width(), a.columns, a.gutter) };
|
||||
let cells = cells.max(1) as f64;
|
||||
let cell = (along - 2.0 * a.inset.max(0.0) - gutter.max(0.0) * (cells - 1.0)) / cells;
|
||||
(cell.is_finite() && cell > 1e-9).then_some((points, line_gap, cell))
|
||||
}
|
||||
|
||||
/// Fit area type with Dynamic Text (Block) on: with the word gap as every paragraph's Desired word
|
||||
/// spacing ([`TextObject::layout_justification`]; the paragraphs keep their own values), each line
|
||||
/// as typed gets the size (its first character's, in steps of 0.1 pt within 0.1 to
|
||||
@@ -150,24 +243,9 @@ fn tenths(points: f64) -> f64 {
|
||||
/// has no size. A line that still wraps at its first fit is made smaller, in at most
|
||||
/// [`BLOCK_PASSES`] more passes. True when the text changed.
|
||||
pub(crate) fn block_fit(t: &mut TextObject) -> bool {
|
||||
if !t.dynamic_text {
|
||||
return false;
|
||||
}
|
||||
let TextKind::Area { frame } = &t.kind else { return false };
|
||||
let (_, line_gap) = t.area.block_gaps();
|
||||
let Some(b) = frame.bounds().filter(|b| [b.x0, b.y0, b.x1, b.y1].iter().all(|v| v.is_finite())) else { return false };
|
||||
let Some(points) = t.style_scale().map(|s| s.points).filter(|p| p.is_finite() && *p > 1e-12) else { return false };
|
||||
let Some((points, line_gap, cell)) = fit_metrics(t) else { return false };
|
||||
let before = t.runs.clone();
|
||||
|
||||
// The room along a line in one cell of the frame, before indents.
|
||||
let a = &t.area;
|
||||
let (along, cells, gutter) = if t.vertical { (b.height(), a.rows, a.row_gutter.unwrap_or(a.gutter)) } else { (b.width(), a.columns, a.gutter) };
|
||||
let cells = cells.max(1) as f64;
|
||||
let cell = (along - 2.0 * a.inset.max(0.0) - gutter.max(0.0) * (cells - 1.0)) / cells;
|
||||
if !(cell.is_finite() && cell > 1e-9) {
|
||||
return t.runs != before;
|
||||
}
|
||||
|
||||
let db = vectorcraft_text::FontDb::global();
|
||||
let text = t.plain_text();
|
||||
let lines = typed_lines(&text);
|
||||
|
||||
@@ -31,6 +31,29 @@ fn undo_len(s: &Session) -> usize {
|
||||
s.doc().unwrap().history.undo.len()
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn editing_a_character_style_keeps_manual_leading_when_block_has_no_room() {
|
||||
for command in ["charStyle.setAttrs", "charStyle.edit"] {
|
||||
for manual_leading in [42.0, 12.0] {
|
||||
let mut s = session();
|
||||
let id = area(&mut s, 50.0, 400.0, "Inset");
|
||||
s.execute("text.areaOptions", &json!({"inset": 30})).unwrap();
|
||||
s.execute("charStyle.new", &json!({"name": "Body", "attrs": {"leading": 30}})).unwrap();
|
||||
s.execute("charStyle.apply", &json!({"name": "Body", "id": id})).unwrap();
|
||||
s.execute("text.setStyle", &json!({"ids": [id], "leading": manual_leading})).unwrap();
|
||||
s.execute("type.dynamicText", &json!({"ids": [id], "on": true})).unwrap();
|
||||
assert_eq!(text(&s, id).runs[0].style.leading, Some(manual_leading));
|
||||
let params = if command == "charStyle.edit" {
|
||||
json!({"name": "Body", "to": "Body", "attrs": {"leading": 60}})
|
||||
} else {
|
||||
json!({"name": "Body", "attrs": {"leading": 60}})
|
||||
};
|
||||
s.execute(command, ¶ms).unwrap();
|
||||
assert_eq!(text(&s, id).runs[0].style.leading, Some(manual_leading), "{command}: {manual_leading}");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// The size of the character at `byte`.
|
||||
fn size_at(t: &TextObject, byte: usize) -> f64 {
|
||||
super::block::size_at(&t.runs, byte)
|
||||
@@ -672,6 +695,109 @@ fn point_type_with_nothing_to_fit_is_left_as_it_is() {
|
||||
assert!(!vectorcraft_text::layout(vectorcraft_text::FontDb::global(), &t).overflow);
|
||||
}
|
||||
|
||||
/// The distances between the baselines of `t`'s lines.
|
||||
fn baseline_steps(t: &TextObject) -> Vec<f64> {
|
||||
let lay = vectorcraft_text::layout(vectorcraft_text::FontDb::global(), t);
|
||||
lay.lines.windows(2).map(|w| w[1].baseline - w[0].baseline).collect()
|
||||
}
|
||||
|
||||
/// Block owns each character's leading (its size plus the line gap): a leading change from
|
||||
/// `text.setStyle`, `text.setRangeStyle` or `type.step` on area type with Block on changes the
|
||||
/// line gap by the difference from the first character's leading, in one undo step, and sticks.
|
||||
#[test]
|
||||
fn a_leading_change_with_block_on_moves_the_line_gap() {
|
||||
let mut s = session();
|
||||
let id = area(&mut s, 300.0, 400.0, "BIG\na much longer second line\nmid one");
|
||||
s.execute("type.dynamicText", &json!({"on": true})).unwrap();
|
||||
let t = text(&s, id);
|
||||
let (first, second) = (t.runs[0].style.size, size_at(&t, 4));
|
||||
let steps = baseline_steps(&t);
|
||||
let n = undo_len(&s);
|
||||
|
||||
// The whole object: the first character's leading becomes the leading given.
|
||||
s.execute("text.setStyle", &json!({"ids": [id], "leading": first + 6.0})).unwrap();
|
||||
assert_eq!(undo_len(&s), n + 1, "one undo step");
|
||||
let t = text(&s, id);
|
||||
assert!((t.area.line_gap - 6.0).abs() < 1e-9, "line gap {}", t.area.line_gap);
|
||||
assert!(t.runs.iter().all(|r| r.style.leading.is_some_and(|l| (l - r.style.size - 6.0).abs() < 1e-9)), "{:?}", t.runs);
|
||||
assert_block(&t);
|
||||
let wider = baseline_steps(&t);
|
||||
assert!(wider.iter().zip(&steps).all(|(w, s)| (w - s - 6.0).abs() < 1e-6), "every line spreads: {steps:?} -> {wider:?}");
|
||||
s.execute("edit.undo", &json!({})).unwrap();
|
||||
assert_eq!(text(&s, id).area.line_gap, 0.0);
|
||||
|
||||
// A range: measured from the leading of its first character.
|
||||
s.execute("text.setRangeStyle", &json!({"id": id, "start": 4, "end": 10, "leading": second - 3.0})).unwrap();
|
||||
let t = text(&s, id);
|
||||
assert!((t.area.line_gap + 3.0).abs() < 1e-9, "line gap {}", t.area.line_gap);
|
||||
assert!(baseline_steps(&t).iter().zip(&steps).all(|(w, s)| w < s), "every line tightens");
|
||||
|
||||
// Alt+Up/Down steps by the Size/Leading increment.
|
||||
let inc = s.prefs.type_size_increment;
|
||||
s.execute("type.step", &json!({"attribute": "leading", "by": 1, "id": id, "start": 0, "end": 3})).unwrap();
|
||||
assert!((text(&s, id).area.line_gap - (inc - 3.0)).abs() < 1e-9);
|
||||
|
||||
// Auto: the first character's Auto leading, 120% of its size.
|
||||
s.execute("text.setStyle", &json!({"ids": [id], "leading": "auto"})).unwrap();
|
||||
let t = text(&s, id);
|
||||
assert!((t.area.line_gap - t.runs[0].style.size * 0.2).abs() < 1e-6, "line gap {}", t.area.line_gap);
|
||||
|
||||
// The leading the first character already has changes nothing.
|
||||
let n = undo_len(&s);
|
||||
let lead = text(&s, id).runs[0].style.leading.unwrap();
|
||||
s.execute("text.setStyle", &json!({"ids": [id], "leading": lead})).unwrap();
|
||||
assert_eq!(undo_len(&s), n, "no undo step");
|
||||
|
||||
// The gap stays within its range.
|
||||
s.execute("text.setStyle", &json!({"ids": [id], "leading": 5000})).unwrap();
|
||||
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();
|
||||
let lead = text(&s, id).runs[0].style.leading.unwrap();
|
||||
assert!((lead - 1.0).abs() < 1e-6, "leading {lead}");
|
||||
s.execute("text.areaOptions", &json!({"lineGap": 0})).unwrap();
|
||||
// A size set with the leading: the gap follows the size Block gives the first character, on an
|
||||
// empty line (whose size Block keeps) too.
|
||||
s.execute("text.setStyle", &json!({"ids": [id], "size": 20, "leading": 50})).unwrap();
|
||||
let lead = text(&s, id).runs[0].style.leading.unwrap();
|
||||
assert!((lead - 50.0).abs() < 1e-6, "leading {lead}");
|
||||
s.execute("text.setText", &json!({"text": "\nwords"})).unwrap();
|
||||
s.execute("text.setStyle", &json!({"ids": [id], "size": 20, "leading": 30})).unwrap();
|
||||
let t = text(&s, id);
|
||||
assert_eq!(size_at(&t, 0), 20.0, "the empty line keeps the size set");
|
||||
assert!((t.runs[0].style.leading.unwrap() - 30.0).abs() < 1e-6, "{:?}", t.runs[0].style);
|
||||
s.execute("text.setText", &json!({"text": "BIG\na much longer second line\nmid one"})).unwrap();
|
||||
s.execute("text.areaOptions", &json!({"lineGap": 0})).unwrap();
|
||||
|
||||
// Scaled type: the leading given and the line gap are in document points.
|
||||
s.execute("object.scale", &json!({"sx": 200, "sy": 200})).unwrap();
|
||||
let points = text(&s, id).style_scale().unwrap().points;
|
||||
s.execute("text.setStyle", &json!({"ids": [id], "leading": 150})).unwrap();
|
||||
let t = text(&s, id);
|
||||
let (size, lead) = (t.runs[0].style.size * points, t.runs[0].style.leading.unwrap() * points);
|
||||
assert!((lead - 150.0).abs() < 1e-6, "leading {lead}");
|
||||
assert!((t.area.line_gap - (150.0 - size)).abs() < 1e-6, "line gap {} for size {size}", t.area.line_gap);
|
||||
}
|
||||
|
||||
/// Without Block (point type, and area type with Block off) a leading change sets the
|
||||
/// characters' leading and leaves the line gap.
|
||||
#[test]
|
||||
fn a_leading_change_without_block_sets_the_leading() {
|
||||
let mut s = session();
|
||||
let id = area(&mut s, 300.0, 400.0, "one\ntwo");
|
||||
s.execute("text.areaOptions", &json!({"lineGap": 5})).unwrap();
|
||||
s.execute("text.setStyle", &json!({"ids": [id], "leading": 30})).unwrap();
|
||||
let t = text(&s, id);
|
||||
assert_eq!(t.area.line_gap, 5.0);
|
||||
assert!(t.runs.iter().all(|r| r.style.leading == Some(30.0)));
|
||||
let id = point(&mut s, "one\ntwo", json!({}));
|
||||
s.execute("type.step", &json!({"attribute": "leading", "by": 1, "id": id, "start": 0, "end": 3})).unwrap();
|
||||
let t = text(&s, id);
|
||||
assert_eq!(t.area.line_gap, 0.0);
|
||||
assert_eq!(t.runs[0].style.leading, Some(12.0 * 1.2 + s.prefs.type_size_increment));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn long_text_fits_in_a_bounded_number_of_layouts() {
|
||||
let mut s = session();
|
||||
@@ -698,3 +824,155 @@ fn long_text_fits_in_a_bounded_number_of_layouts() {
|
||||
let bound = 2 * (2 + 2 * super::block::BLOCK_PASSES as u64) + 8;
|
||||
assert!(used <= bound, "point type: {used} layouts");
|
||||
}
|
||||
|
||||
/// Area type with Block on, its lines at different sizes, and a line gap of 0.
|
||||
fn block_text(s: &mut Session) -> u64 {
|
||||
let id = area(s, 300.0, 400.0, "BIG\na much longer second line\nmid one");
|
||||
s.execute("type.dynamicText", &json!({"on": true})).unwrap();
|
||||
assert_eq!(text(s, id).area.line_gap, 0.0);
|
||||
id
|
||||
}
|
||||
|
||||
/// The leading of the one-byte character at `byte` (`style_at` reads the character before a run
|
||||
/// end, so it is asked for the end of the character).
|
||||
fn leading_at(t: &TextObject, byte: usize) -> Option<f64> {
|
||||
vectorcraft_text::edit::style_at(&t.runs, byte + 1).leading
|
||||
}
|
||||
|
||||
/// `text.setRangeStyle {leading}` on a range of Block text moves the line gap by the change to
|
||||
/// the leading of the range's first character, and the range keeps the leading given.
|
||||
#[test]
|
||||
fn a_range_leading_change_with_block_on_moves_the_line_gap() {
|
||||
let mut s = session();
|
||||
let id = block_text(&mut s);
|
||||
let second = vectorcraft_text::edit::style_at(&text(&s, id).runs, 5).size;
|
||||
s.execute("text.setRangeStyle", &json!({"id": id, "start": 4, "end": 10, "leading": second + 5.0})).unwrap();
|
||||
let t = text(&s, id);
|
||||
assert!((t.area.line_gap - 5.0).abs() < 1e-9, "line gap {}", t.area.line_gap);
|
||||
assert!(leading_at(&t, 4).is_some_and(|l| (l - second - 5.0).abs() < 1e-9), "{:?}", leading_at(&t, 4));
|
||||
assert!(t.runs.iter().all(|r| r.style.leading.is_some_and(|l| (l - r.style.size - 5.0).abs() < 1e-9)), "every line spreads");
|
||||
// Reset Panel's form: the leading is set and Block keeps the line gap.
|
||||
s.execute("text.setRangeStyle", &json!({"id": id, "start": 4, "end": 10, "leading": "auto", "keepLineGap": true})).unwrap();
|
||||
assert!((text(&s, id).area.line_gap - 5.0).abs() < 1e-9);
|
||||
s.execute("text.setStyle", &json!({"ids": [id], "leading": "auto", "keepLineGap": true})).unwrap();
|
||||
assert!((text(&s, id).area.line_gap - 5.0).abs() < 1e-9);
|
||||
assert!(s.execute("text.setStyle", &json!({"ids": [id], "leading": 30, "keepLineGap": 1})).is_err(), "keepLineGap takes a bool");
|
||||
}
|
||||
|
||||
/// A range inside one character styles nothing, so it leaves the line gap.
|
||||
#[test]
|
||||
fn a_leading_on_a_range_inside_one_character_leaves_the_line_gap() {
|
||||
let mut s = session();
|
||||
let id = area(&mut s, 300.0, 400.0, "\u{e9}t\u{e9}\nsecond line");
|
||||
s.execute("type.dynamicText", &json!({"on": true})).unwrap();
|
||||
s.execute("charStyle.new", &json!({"name": "Loose", "attrs": {"leading": 50}})).unwrap();
|
||||
let gap = text(&s, id).area.line_gap;
|
||||
let range = json!({"start": 0, "end": 1});
|
||||
let mut setstyle = json!({"ids": [id], "leading": 50});
|
||||
let mut setrange = json!({"id": id, "leading": 50});
|
||||
let mut apply = json!({"name": "Loose", "id": id});
|
||||
for p in [&mut setstyle, &mut setrange, &mut apply] {
|
||||
p.as_object_mut().unwrap().extend(range.as_object().unwrap().clone());
|
||||
}
|
||||
for (c, p) in [("text.setStyle", setstyle), ("text.setRangeStyle", setrange), ("charStyle.apply", apply)] {
|
||||
s.execute(c, &p).unwrap_or_else(|e| panic!("{c}: {e}"));
|
||||
assert_eq!(text(&s, id).area.line_gap, gap, "{c}");
|
||||
}
|
||||
}
|
||||
|
||||
/// `type.step {attribute: "leading"}` (Alt+Up/Down) on Block text moves the line gap by the step.
|
||||
#[test]
|
||||
fn a_leading_step_with_block_on_moves_the_line_gap() {
|
||||
let mut s = session();
|
||||
let id = block_text(&mut s);
|
||||
let inc = s.prefs.type_size_increment;
|
||||
s.execute("type.step", &json!({"attribute": "leading", "by": -1, "id": id, "start": 0, "end": 3})).unwrap();
|
||||
let t = text(&s, id);
|
||||
assert!((t.area.line_gap + inc).abs() < 1e-9, "line gap {}", t.area.line_gap);
|
||||
assert!(leading_at(&t, 0).is_some_and(|l| (l - t.runs[0].style.size + inc).abs() < 1e-9));
|
||||
}
|
||||
|
||||
/// A character style edited to set a leading while Block text uses it moves the line gap; a style
|
||||
/// without a leading leaves the gap.
|
||||
#[test]
|
||||
fn a_character_style_edited_to_a_leading_with_block_on_moves_the_line_gap() {
|
||||
let mut s = session();
|
||||
let id = block_text(&mut s);
|
||||
s.execute("charStyle.new", &json!({"name": "Plain", "attrs": {"tracking": 0}})).unwrap();
|
||||
s.execute("charStyle.apply", &json!({"name": "Plain", "id": id})).unwrap();
|
||||
assert_eq!(text(&s, id).area.line_gap, 0.0, "no leading in the style");
|
||||
s.execute("charStyle.edit", &json!({"name": "Plain", "to": "Plain", "attrs": {"tracking": 0, "leading": 60}})).unwrap();
|
||||
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.
|
||||
#[test]
|
||||
fn a_character_style_leading_applied_with_block_on_moves_the_line_gap() {
|
||||
let mut s = session();
|
||||
let id = block_text(&mut s);
|
||||
s.execute("charStyle.new", &json!({"name": "Loose", "attrs": {"leading": 50}})).unwrap();
|
||||
s.execute("charStyle.apply", &json!({"name": "Loose", "id": id})).unwrap();
|
||||
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();
|
||||
s.execute("charStyle.new", &json!({"name": "Plain", "attrs": {"tracking": 0}})).unwrap();
|
||||
s.execute("text.areaOptions", &json!({"lineGap": 0})).unwrap();
|
||||
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;
|
||||
/// 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();
|
||||
let id = block_text(&mut s);
|
||||
s.execute("addon.type.textTweaker", &json!({"attribute": "leading", "from": 40, "to": 45, "ids": [id]})).unwrap();
|
||||
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 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_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_eq!(t.area.line_gap, gap);
|
||||
assert_spread(&t);
|
||||
}
|
||||
@@ -84,7 +84,7 @@ pub fn specs() -> Vec<CommandSpec> {
|
||||
"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, 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
|
||||
),
|
||||
|
||||
@@ -1620,8 +1620,9 @@ fn fractional_widths_on(app: &VectorcraftApp) -> bool {
|
||||
/// line gap, 50%, Auto alignment), Insert Aki Left and Right 0, Tsume 0, the Default character direction,
|
||||
/// Kashidas on, the Default digits, Adjust Horizontal and Vertical Diacritic Position 0 and the Em Box
|
||||
/// font height reference, whether or not Show East Asian
|
||||
/// Options, Show Indic Options and Show Font Height Options are on. Inside an undo group that is
|
||||
/// already open, the reset is part of that group's step.
|
||||
/// Options, Show Indic Options and Show Font Height Options are on. Area type with Dynamic Text
|
||||
/// (Block) on keeps its frame's Line Gap. Inside an undo group that is already open, the reset is
|
||||
/// part of that group's step.
|
||||
fn reset_panel(app: &mut VectorcraftApp) {
|
||||
// Typing in progress stays an undo step of its own.
|
||||
end_typing(app);
|
||||
@@ -1630,7 +1631,8 @@ fn reset_panel(app: &mut VectorcraftApp) {
|
||||
app.session.begin_named_undo_group(Some("Reset Panel".into()));
|
||||
}
|
||||
let d = CharStyle::default();
|
||||
style(app, json!({"tracking": 0, "leading": "auto"}));
|
||||
// Dynamic Text's Line Gap is the frame's, so the reset leaves it as it is.
|
||||
style(app, json!({"tracking": 0, "leading": "auto", "keepLineGap": true}));
|
||||
format(
|
||||
app,
|
||||
json!({
|
||||
|
||||
@@ -232,6 +232,92 @@ fn leading_follows_the_paragraphs_the_type_tool_selection_covers() {
|
||||
}
|
||||
}
|
||||
|
||||
/// Selected area type of two equal lines with Dynamic Text (Block) on and a Line Gap of 7 pt.
|
||||
fn block_app() -> (VectorcraftApp, NodeId) {
|
||||
let mut app = VectorcraftApp::new(Session::new(), Default::default());
|
||||
app.run("file.new", json!({"width": 600, "height": 400})).unwrap();
|
||||
let id =
|
||||
app.run("text.create", json!({"x": 20, "y": 20, "size": 12, "area": {"width": 300, "height": 2000}, "text": "Hello\nHello"})).unwrap()["id"]
|
||||
.as_u64()
|
||||
.unwrap();
|
||||
app.run("select.set", json!({"ids": [id]})).unwrap();
|
||||
app.run("type.dynamicText", json!({"on": true, "lineGap": 7})).unwrap();
|
||||
let leading = shared_leading(&app).expect("both lines share a leading");
|
||||
assert!((leading - block_text(&app, NodeId(id)).runs[0].style.size - 7.0).abs() < 1e-9);
|
||||
(app, NodeId(id))
|
||||
}
|
||||
|
||||
fn block_text(app: &VectorcraftApp, id: NodeId) -> vectorcraft_doc::TextObject {
|
||||
match &app.session.active().unwrap().doc.node(id).unwrap().kind {
|
||||
NodeKind::Text(t) => (**t).clone(),
|
||||
_ => panic!("text"),
|
||||
}
|
||||
}
|
||||
|
||||
fn pick_leading(panel: &mut crate::tests::panel_harness::Panel, entry: &str) {
|
||||
panel.focus("Leading");
|
||||
panel.key(egui::Key::ArrowDown, egui::Modifiers::ALT);
|
||||
panel.click_role(entry, craft::ui::contract::Role::LIST_BOX_OPTION);
|
||||
}
|
||||
|
||||
/// Area type with Dynamic Text (Block) on: a leading typed into the Leading field moves the
|
||||
/// frame's Line Gap, so the field then shows the leading typed and the lines are spaced by it.
|
||||
#[test]
|
||||
fn leading_typed_with_block_on_moves_the_line_gap() {
|
||||
use crate::tests::panel_harness::Panel;
|
||||
let (app, id) = block_app();
|
||||
let size = block_text(&app, id).runs[0].style.size;
|
||||
let mut panel = Panel::new(app, show);
|
||||
panel.type_into("Leading", "200");
|
||||
let app = panel.app();
|
||||
let t = block_text(&app, id);
|
||||
assert!((t.area.line_gap - (200.0 - size)).abs() < 1e-6, "line gap {} for size {size}", t.area.line_gap);
|
||||
assert!(shared_leading(&app).is_some_and(|l| (l - 200.0).abs() < 1e-6), "the field shows {:?}", shared_leading(&app));
|
||||
let lay = vectorcraft_text::layout(vectorcraft_text::FontDb::global(), &t);
|
||||
assert!((lay.lines[1].baseline - lay.lines[0].baseline - 200.0).abs() < 1e-6, "the lines are 200 pt apart");
|
||||
}
|
||||
|
||||
/// The Properties panel's Leading field does the same on Block text.
|
||||
#[test]
|
||||
fn leading_typed_in_properties_with_block_on_moves_the_line_gap() {
|
||||
use crate::tests::panel_harness::Panel;
|
||||
let (app, id) = block_app();
|
||||
let size = block_text(&app, id).runs[0].style.size;
|
||||
let mut panel = Panel::new(app, super::super::properties::show);
|
||||
panel.type_into("Leading", "150");
|
||||
let t = block_text(&panel.app(), id);
|
||||
assert!((t.area.line_gap - (150.0 - size)).abs() < 1e-6, "line gap {} for size {size}", t.area.line_gap);
|
||||
}
|
||||
|
||||
/// A pick from the Leading field's list on Block text: a preset, then Auto, each moves the Line Gap.
|
||||
#[test]
|
||||
fn leading_picked_from_the_list_with_block_on_moves_the_line_gap() {
|
||||
use crate::tests::panel_harness::Panel;
|
||||
let (app, id) = block_app();
|
||||
let size = block_text(&app, id).runs[0].style.size;
|
||||
let preset = vectorcraft_doc::Unit::Points.format(72.0);
|
||||
let mut panel = Panel::new(app, show);
|
||||
pick_leading(&mut panel, &preset);
|
||||
let gap = block_text(&panel.app(), id).area.line_gap;
|
||||
assert!((gap - (72.0 - size)).abs() < 1e-6, "{preset}: line gap {gap} for size {size}");
|
||||
pick_leading(&mut panel, tl!("Auto"));
|
||||
let gap = block_text(&panel.app(), id).area.line_gap;
|
||||
assert!(gap > 0.0 && gap < size * 0.5, "Auto: line gap {gap} for size {size}");
|
||||
}
|
||||
|
||||
/// Reset Panel resets the leading to Auto and leaves Block's Line Gap, which belongs to the frame.
|
||||
#[test]
|
||||
fn reset_panel_with_block_on_keeps_the_line_gap() {
|
||||
let (mut app, id) = block_app();
|
||||
app.run("text.setFormat", json!({"baselineShift": 3})).unwrap();
|
||||
let reset = CommandRef::with_params("ui.character.reset", json!({}));
|
||||
assert!(listed(&app).contains(&reset), "the panel menu lists Reset Panel");
|
||||
fire(&mut app, &reset);
|
||||
let t = block_text(&app, id);
|
||||
assert_eq!(t.area.line_gap, 7.0);
|
||||
assert_eq!(t.runs[0].style.baseline_shift, 0.0, "the reset ran");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn scaled_range_fields_follow_the_type_tool_selection() {
|
||||
let mut app = VectorcraftApp::new(Session::new(), Default::default());
|
||||
|
||||
+17
@@ -12165,6 +12165,23 @@ lines. The rest are VectorCraft's own rules:
|
||||
Maximum word spacing moves out to `wordGap` when `wordGap` lies outside it. The paragraphs keep their own
|
||||
Justification… values, which apply again when Block is off. Each character's leading is its size plus `lineGap`. A
|
||||
gap given with no area type in the selection, and no point type that it turns into area type, is an error.
|
||||
- A leading change on the frame's text sets `lineGap` to the new leading less the size of the first character changed,
|
||||
within -1,296 to 1,296 pt, in the change's own undo step. That covers `text.setStyle {leading}` and
|
||||
`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, 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. If Block cannot fit a frame, editing a character style keeps each run's
|
||||
manual leading override. When Block can fit the frame, its generated leading follows the edited style.
|
||||
- The sizes are written into the characters, so every export and the Character panel see them. After every edit to
|
||||
the text or the frame (typing, `text.editRange`, character and paragraph changes, `text.areaOptions {width}`, a
|
||||
frame resize) the lines are fitted again, in the edit's own undo step. The lines are then measured again, in at
|
||||
|
||||
@@ -36,6 +36,8 @@
|
||||
|
||||
History panel row context menus (2026-11-20, G12): Right-clicking any state offers New Document from State, Step to This State, and Clear History. Creating a document uses the clicked snapshot without stepping the source document; Step to This State uses undo/redo and is disabled on the current row; Clear History removes undo and redo steps without changing artwork and is disabled when history is empty. Headless tests in `crates/ui-egui/src/panels/history.rs` cover opening an earlier row menu, snapshot creation, backward/forward jumps, and clearing history. The snapshot chosen when the menu opens is retained while it stays open; pending tool edits are settled before resolving that snapshot to its new row; a discarded snapshot reports that it is unavailable instead of acting on a neighboring row. Jumps settle pending typing before counting undo/redo steps. Shift+F10 opens the focused row menu; Escape dismisses it and restores row focus. Switching documents dismisses the menu before it can act on another document. Headless tests cover these keyboard and document-switch paths. The list and menu use shared Craft UI controls. Scores and estimates unchanged.
|
||||
|
||||
Character-style edits keep manual leading overrides when Dynamic Text's Block cannot fit the frame. When Block can fit the frame, its generated leading follows the edited style. A regression in `crates/engine/src/cmd/typecmd/block_tests.rs` covers a frame whose inset leaves no room.
|
||||
|
||||
Script appearance and geometry setters reject objects on locked artboards. Assigning the current opacity remains allowed when it changes no graph styling. Position, size and stacking-order setters also reject objects excluded by selection filtering, including locked guide paths. `crates/engine/src/tests/script_dom.rs` covers refused edits, unchanged documents and undo history, and editing a guide after unlocking it.
|
||||
|
||||
Variables panel row context menus (2026-11-20, G12): Right-click highlights the clicked variable without changing the canvas selection and offers Select Bound Object, Variable Options…, Unbind Variable, the four Make Dynamic actions, and Delete Variable. Shift+F10 opens the same menu for the focused row; Escape dismisses it. Row actions target that variable; dynamic actions use the canvas selection. Lock and selection checks disable unavailable actions. Headless pointer/accessibility tests cover opening the menu, highlighting, bound-object selection, deletion in one undo step and restoration, and disabled actions. Scores and estimates unchanged.
|
||||
@@ -1873,7 +1875,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, 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, limited to -1,296 to 1,296 pt, 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.
|
||||
@@ -3055,7 +3057,7 @@ A VectorCraft addition, not a feature of the reference app, so no area score mov
|
||||
|
||||
## Type Tools add-on: Text Tweaker (2026-11-03)
|
||||
|
||||
A VectorCraft addition, not a feature of the reference app, so no area score moves. Object › Plug-ins › Type Tools › Text Tweaker… gives one character attribute (size, baseline shift, character rotation, horizontal or vertical scale, tracking, leading or stroke weight) to the selected characters letter by letter, from a start value to an end value along a straight ramp, an ease in and out, a bow, a spike or at random with a seed, while the text stays live and editable (#4924). Values are set as the Character panel sets them, in its units and ranges, so scaled type takes the sizes shown; spaces and line breaks are skipped unless asked for, each type object gets its own ramp, the range is the Type tool's selection or all the text of the selected type objects, and the run is one undo step from a dialog with Preview. Tests: `cmd::addons::typetools::tests` in `vectorcraft-engine` (each shape, each attribute, skipped spaces, ranges, one ramp per object, seeded random values, scaled type, one undo step, bad params refused), `addons::typetools::tests` in `vectorcraft-ui-egui` (the submenu, the dialog, Preview and Cancel, OK) and `command_sweep`. Commands: `docs/mcp.md` › Type Tools add-on.
|
||||
A VectorCraft addition, not a feature of the reference app, so no area score moves. Object › Plug-ins › Type Tools › Text Tweaker… gives one character attribute (size, baseline shift, character rotation, horizontal or vertical scale, tracking, leading or stroke weight) to the selected characters letter by letter, from a start value to an end value along a straight ramp, an ease in and out, a bow, a spike or at random with a seed, while the text stays live and editable (#4924). With Block enabled, a leading ramp sets Line Gap from the first changed character instead of varying leading across the text. Values are set as the Character panel sets them, in its units and ranges, so scaled type takes the sizes shown; spaces and line breaks are skipped unless asked for, each type object gets its own ramp, the range is the Type tool's selection or all the text of the selected type objects, and the run is one undo step from a dialog with Preview. Tests: `cmd::addons::typetools::tests` in `vectorcraft-engine` (each shape, each attribute, skipped spaces, ranges, one ramp per object, seeded random values, scaled type, one undo step, bad params refused), `addons::typetools::tests` in `vectorcraft-ui-egui` (the submenu, the dialog, Preview and Cancel, OK) and `command_sweep`. Commands: `docs/mcp.md` › Type Tools add-on.
|
||||
|
||||
## Type Tools add-on: Release Type on a Path (2026-11-05)
|
||||
|
||||
|
||||
Reference in new issue
Block a user