diff --git a/crates/engine/src/cmd/addons/typetools/font_sheet.rs b/crates/engine/src/cmd/addons/typetools/font_sheet.rs index 14c4f46edf..46ae534764 100644 --- a/crates/engine/src/cmd/addons/typetools/font_sheet.rs +++ b/crates/engine/src/cmd/addons/typetools/font_sheet.rs @@ -11,6 +11,7 @@ use vectorcraft_geom::{Affine, Point, Rect, Shape}; use vectorcraft_text::{FontDb, FontMatch}; use super::super::super::create::{new_type_para, new_type_style}; +use super::super::super::panelcmds::artboard_at; use super::super::super::typecmd::refresh_bounds; use super::super::super::{CommandSpec, bad, cmd, has_doc, switch_or}; use crate::{Result, Session}; @@ -36,7 +37,7 @@ pub fn specs() -> Vec { "Create Font Sheet", ["Object", "Plug-ins", "Type Tools"], None, - "{text?: one line of sample text of at most 1000 characters without line or paragraph breaks or other control characters (\"The quick brown fox jumps over the lazy dog\"), size?: pt 1..1296 (12), filter?: text (only the families whose name contains it, in any case; empty: every family), families?: [family name…] (instead of filter: these families, in this order; each must be available and named once; an error with any filter, an empty one included), allStyles?: false (true: one entry for each style of each family; false: the family's Regular, else its closest style), labels?: true (each entry starts with a line naming its font, at the sample's size up to 9 pt, in the document's normal type font), columns?: 1..50 (2), gap?: pt 0..1000 (12, between entries and between columns), margin?: pt 0..1000 (36, inside each page), newArtboards?: true (false: the pages after the first are laid out in the same places without artboards)} set the sample text once in every family the font menus list (the bundled, added and installed fonts), as point type labeled with the font's name, flowed down the columns of the active artboard (inset by `margin`) and on to new artboards of the same size to the right of the rightmost artboard when it fills, as one group named Font Sheet in the current layer (else the topmost layer shown and unlocked), in one undo step; the group is selected. Each row is as tall as the tallest laid-out entry. A sample wider than its column runs on past it. A family whose font can't be loaded, or with allStyles a style that can't, or a composite font with a part setting the sample whose font or style can't, is left out, listed in `skipped` and named in `warning`. An error, with nothing changed, when no font matches, when there are more than 5000 entries, when no font loads, or when the margin, gap and columns leave no room for an entry → {id, count, skipped: [family, or family and style…], artboards: [index…] (the artboards added), warning?}", + "{text?: one line of sample text of at most 1000 characters without line or paragraph breaks or other control characters (\"The quick brown fox jumps over the lazy dog\"), size?: pt 1..1296 (12), filter?: text (only the families whose name contains it, in any case; empty: every family), families?: [family name…] (instead of filter: these families, in this order; each must be available and named once; an error with any filter, an empty one included), allStyles?: false (true: one entry for each style of each family; false: the family's Regular, else its closest style), labels?: true (each entry starts with a line naming its font, at the sample's size up to 9 pt, in the document's normal type font), columns?: 1..50 (2), gap?: pt 0..1000 (12, between entries and between columns), margin?: pt 0..1000 (36, inside each page), newArtboards?: true (false: the pages after the first are laid out in the same places without artboards), artboard?: n (0-based; the artboard the first page is; default: the active one), activeArtboard?: n (the journal records that default here, for a replay; `artboard` goes ahead of it)} set the sample text once in every family the font menus list (the bundled, added and installed fonts), as point type labeled with the font's name, every line aligned left (right-to-left samples too), flowed down the columns of the active artboard, or artboard `artboard` (inset by `margin`) and on to new artboards of the same size to the right of the rightmost artboard when it fills, as one group named Font Sheet in the current layer (else the topmost layer shown and unlocked), in one undo step; the group is selected. Each row is as tall as the tallest laid-out entry. A sample wider than its column runs on past it. A family whose font can't be loaded, or with allStyles a style that can't, or a composite font with a part setting the sample whose font or style can't, is left out, listed in `skipped` and named in `warning`. An error, with nothing changed, when no font matches, when there are more than 5000 entries, when no font loads, or when the margin, gap and columns leave no room for an entry → {id, count, skipped: [family, or family and style…], artboards: [index…] (the artboards added), warning?}", has_doc, font_sheet )] @@ -160,9 +161,22 @@ fn font_sheet_in(s: &mut Session, p: &Value, db: &FontDb) -> Result { } let label = size.min(LABEL_SIZE); + // The artboard named, else `activeArtboard` (a replay of the journal), else the view's active + // one, which the journal entry then records as `activeArtboard` so a replay uses the same artboard. + let named = artboard_at(&s.doc()?.doc, p, "artboard", C)?; + let active = match named.or(artboard_at(&s.doc()?.doc, p, "activeArtboard", C)?) { + Some(i) => i, + None => { + let st = s.doc()?; + let i = active_artboard(st); + if i < st.doc.artboards.len() { + s.note_journal("activeArtboard", json!(i)); + } + i + } + }; let st = s.doc()?; let d = &st.doc; - let active = active_artboard(st); let template = d.artboards.get(active).cloned(); let page = template.as_ref().map_or(LETTER, |a| a.rect); let right = d.artboards.iter().map(|a| a.rect.x1).fold(page.x1, f64::max); @@ -286,7 +300,8 @@ fn font_sheet_in(s: &mut Session, p: &Value, db: &FontDb) -> Result { fn laid_out(first: TextRun, more: Option, system_layout: bool) -> TextObject { let mut t = TextObject::point(Point::ZERO, "", first.style.clone()); t.runs = std::iter::once(first).chain(more).collect(); - t.para = new_type_para(); + // Every paragraph is aligned left, right-to-left ones too, so each starts at the column's edge. + t.para = vectorcraft_doc::ParaStyle { justify: vectorcraft_doc::Justify::Left, ..new_type_para() }; t.system_layout = system_layout; t.normalize_paras(); let layout = vectorcraft_text::layout(FontDb::global(), &t); diff --git a/crates/engine/src/cmd/addons/typetools/font_sheet/tests.rs b/crates/engine/src/cmd/addons/typetools/font_sheet/tests.rs index a64d79c7a2..e52a1e8ce0 100644 --- a/crates/engine/src/cmd/addons/typetools/font_sheet/tests.rs +++ b/crates/engine/src/cmd/addons/typetools/font_sheet/tests.rs @@ -139,6 +139,58 @@ fn columns_share_the_room_inside_the_margin() { assert_eq!(r["artboards"], json!([])); } +/// The journal records the active artboard, so a replay in a new session lays the sheet out on the +/// same one; an action leaves it out, and a named artboard goes ahead of it. +#[test] +fn the_journal_records_the_artboard_the_sheet_was_laid_out_on() { + let mut s = session(); + s.execute("artboard.new", &json!({"x": 700, "y": 0, "width": 300, "height": 300})).unwrap(); + let second = s.doc().unwrap().doc.artboards[1].clone(); + s.doc_mut().unwrap().active_artboard = Some(second.id); + let start = s.journal.len(); + let params = json!({"families": ["Inter"], "margin": 10}); + let r = s.execute(COMMAND, ¶ms).unwrap(); + let e = entries(&group(&s, &r)); + assert!((origin(&e[0].1).0 - second.rect.x0 - 10.0).abs() < 1e-9, "on the active artboard"); + let (id, recorded) = s.journal.last().unwrap().clone(); + assert_eq!((id.as_str(), &recorded["activeArtboard"]), (COMMAND, &json!(1))); + assert_eq!(s.journal_for_action(start)[0].1.get("activeArtboard"), None, "an action uses the artboard active when it plays"); + + // A replay in a session whose view has no active artboard uses the recorded one. + let mut fresh = session(); + fresh.execute("artboard.new", &json!({"x": 700, "y": 0, "width": 300, "height": 300})).unwrap(); + let r = fresh.replay(COMMAND, &recorded).unwrap(); + let e = entries(&group(&fresh, &r)); + assert!((origin(&e[0].1).0 - second.rect.x0 - 10.0).abs() < 1e-9, "the replay lays it out on the recorded artboard"); + // A named artboard goes ahead of the recorded one. + let r = fresh.execute(COMMAND, &json!({"families": ["Inter"], "margin": 10, "artboard": 0, "activeArtboard": 1})).unwrap(); + let e = entries(&group(&fresh, &r)); + let first = fresh.doc().unwrap().doc.artboards[0].rect; + assert!((origin(&e[0].1).0 - first.x0 - 10.0).abs() < 1e-9); + assert!(fresh.execute(COMMAND, &json!({"families": ["Inter"], "artboard": 5})).is_err(), "no such artboard"); +} + +/// A right-to-left sample starts at its column's left edge like any other, so it stays inside its column. +#[test] +fn a_right_to_left_sample_stays_inside_its_column() { + let mut s = session(); + let rtl = "\u{5e9}\u{5dc}\u{5d5}\u{5dd}"; + let board = s.doc().unwrap().doc.artboards[0].rect; + // Alone, and under a left-to-right label: each line starts at the column's left edge. + for labels in [false, true] { + let r = s.execute(COMMAND, &json!({"families": BUNDLED, "columns": 3, "margin": 50, "gap": 12, "labels": labels, "text": rtl})).unwrap(); + for (name, t) in &entries(&group(&s, &r)) { + let x = origin(t).0; + assert!((x - board.x0 - 50.0).abs() < 1e-9, "{name}: {x}"); + let layout = vectorcraft_text::layout(FontDb::global(), t); + for line in &layout.lines { + let left = x + line.x0; + assert!(left > board.x0 + 50.0 - 1e-6, "{name}, labels {labels}: a line starts at {left}, left of the column's edge"); + } + } + } +} + #[test] fn bad_params_are_refused_without_a_change() { let mut s = session(); diff --git a/crates/engine/src/command_sets.rs b/crates/engine/src/command_sets.rs index 228d23a0f0..9b2b0ad033 100644 --- a/crates/engine/src/command_sets.rs +++ b/crates/engine/src/command_sets.rs @@ -37,7 +37,7 @@ pub const DRAWS_SHAPE: [&str; 5] = ["shape.rectangle", "shape.ellipse", "shape.p /// Artboard tool had selected for its commands and for Paste in Place, in Front and in Back; the artboards and art Cut and Copy took with that /// tool chosen; the view's center the app passes to Edit Symbol); an action leaves them out /// ([`Session::journal_for_action`]). -const REPLAY_ONLY: [(&str, &str); 37] = [ +const REPLAY_ONLY: [(&str, &str); 38] = [ ("edit.copy", "artboard"), ("edit.cut", "artboard"), ("file.new", "created"), @@ -67,6 +67,7 @@ const REPLAY_ONLY: [(&str, &str); 37] = [ ("artboard.distribute", "activeArtboard"), ("artboard.distributeSpacing", "selectedArtboards"), ("artboard.distributeSpacing", "activeArtboard"), + ("addon.type.fontSheet", "activeArtboard"), ("edit.copy", "selectedArtboards"), ("edit.copy", "art"), ("edit.cut", "selectedArtboards"), diff --git a/docs/mcp.md b/docs/mcp.md index a14d344869..8ccd65f7c5 100644 --- a/docs/mcp.md +++ b/docs/mcp.md @@ -18252,8 +18252,9 @@ the fonts can be compared on the artboard or printed. after its font. With `labels` on, an entry starts with a line naming its font in the document's normal type font, at the sample's size up to 9 pt, and the sample follows on the next line. With `allStyles` each style of a family gets its own entry, labeled with the family and style; otherwise the family's Regular is used, else its closest style. -- **Layout:** the entries flow down the columns of the active artboard, inside `margin`, with `gap` between entries - and between columns. A sample wider than its column runs on past it. When the artboard is full, the sheet continues +- **Layout:** the entries flow down the columns of the active artboard (or the one `artboard` names), inside `margin`, with `gap` between entries + and between columns. Every line is aligned left, right-to-left samples too, so each starts at its column's left + edge. A sample wider than its column runs on past it. When the artboard is full, the sheet continues on new artboards of the same size to the right of the rightmost artboard, 20 pt apart; with `newArtboards` off the later pages are laid out in the same places without artboards. A document without artboards lays the sheet out on a 612 × 792 pt page at the origin and adds no artboards. @@ -18280,6 +18281,8 @@ the fonts can be compared on the artboard or printed. | `gap` | pt 0…1000, between entries and between columns (12) | | `margin` | pt 0…1000, inside each page (36) | | `newArtboards` | true; false: the pages after the first get no artboards | +| `artboard` | 0-based index of the artboard the first page is laid out on (the active artboard) | +| `activeArtboard` | the journal records the active artboard here when `artboard` is left out, so a replay uses the same artboard; `artboard` goes ahead of it, and an action leaves it out | In `addon.type.fontSheet`, a parameter given as `null` is the same as one left out and takes its default; any other value of the wrong type or out of range is an error. While the Create Font Sheet… dialog is open, Delete Artboard, Cut @@ -18288,7 +18291,7 @@ would delete the artboard the dialog opened on, and so does a running script's ` that does not catch the error ends with it); close the dialog first. → `{id, count, skipped: [family, or family and style…], artboards: [index…] (the artboards added), warning?}`. Create Font Sheet… opens a dialog -(`ui.menuDialog {command}`) whose fields are the command's parameters except `families`, with Preview, which starts +(`ui.menuDialog {command}`) whose fields are the command's parameters except `families`, `artboard` and `activeArtboard` (it lays the sheet out on the artboard that was active when it opened), with Preview, which starts off: switched on, it sets the whole sheet again after each change. OK is off while the sample text is empty. Plug-ins can't call the command, since the sheet lists the installed fonts as `text.fontList` does. diff --git a/docs/target-app-parity.md b/docs/target-app-parity.md index ef28729815..0e5b2852b3 100644 --- a/docs/target-app-parity.md +++ b/docs/target-app-parity.md @@ -3186,7 +3186,7 @@ A VectorCraft addition, not a feature of the reference app (it has no command fo ## Type Tools add-on: Create Font Sheet (2026-11-29) -A VectorCraft addition, so no area score moves. Object › Plug-ins › Type Tools › Create Font Sheet… sets a line of sample text once in each font family the font menus list, or in the families whose name contains a filter, each entry labeled with its font's name unless labels are switched off, as point type flowed down columns on the active artboard. When the artboard is full, Add Artboards When Full (on by default) adds new artboards of the same size to its right for the rest; with it off, the rest is laid out in the same places to the right without artboards. Every Style gives each style of a family its own entry; families whose font can't be loaded, and composite fonts whose part setting the sample can't, are left out and listed. Each row is as tall as the tallest laid-out entry, so a composite font that enlarges the sample does not overlap. The sheet is one selected group made in one undo step, from a dialog whose Preview starts off (`addon.type.fontSheet`); its preview and OK set the sheet on the artboard active in the view when it opens, and while it is open, Delete Artboard, Cut Artboard, Delete Empty Artboards and Artwork Cleanup's Empty Artboards return an error when they would delete that artboard, also when a running script calls them through `vc.run`. Tests: `cmd::addons::typetools::font_sheet::tests` in `vectorcraft-engine` (labels, columns and margins, new artboards and none, the filter, every style, fonts and styles that don't load, composite fonts' row heights and missing parts, undo, a locked layer, bad params refused), `addons::typetools::font_sheet::tests` (including the artboard active when the dialog opens) and the Create Font Sheet row of `add_on_dialogs_preview_cancel_and_run_their_command` in `vectorcraft-ui-egui`. Commands: `docs/mcp.md` › Type Tools add-on › Create Font Sheet. +A VectorCraft addition, so no area score moves. Object › Plug-ins › Type Tools › Create Font Sheet… sets a line of sample text once in each font family the font menus list, or in the families whose name contains a filter, each entry labeled with its font's name unless labels are switched off, as point type flowed down columns on the active artboard (or the one `artboard` names; the journal records the active one, so a replay uses the same artboard). Every line is aligned left, right-to-left samples too, so each starts at its column's left edge. When the artboard is full, Add Artboards When Full (on by default) adds new artboards of the same size to its right for the rest; with it off, the rest is laid out in the same places to the right without artboards. Every Style gives each style of a family its own entry; families whose font can't be loaded, and composite fonts whose part setting the sample can't, are left out and listed. Each row is as tall as the tallest laid-out entry, so a composite font that enlarges the sample does not overlap. The sheet is one selected group made in one undo step, from a dialog whose Preview starts off (`addon.type.fontSheet`); its preview and OK set the sheet on the artboard active in the view when it opens, and while it is open, Delete Artboard, Cut Artboard, Delete Empty Artboards and Artwork Cleanup's Empty Artboards return an error when they would delete that artboard, also when a running script calls them through `vc.run`. Tests: `cmd::addons::typetools::font_sheet::tests` in `vectorcraft-engine` (labels, columns and margins, new artboards and none, the filter, every style, fonts and styles that don't load, composite fonts' row heights and missing parts, undo, a locked layer, bad params refused), `addons::typetools::font_sheet::tests` (including the artboard active when the dialog opens) and the Create Font Sheet row of `add_on_dialogs_preview_cancel_and_run_their_command` in `vectorcraft-ui-egui`. Commands: `docs/mcp.md` › Type Tools add-on › Create Font Sheet. ## Unit Converter add-on (2026-11-14)