Type Tools: Create Font Sheet's artboard guard covers every artboard deletion

Cut Artboard, Delete Empty Artboards and Artwork Cleanup's Empty Artboards
now return the guard's error, with nothing changed, when they would delete
the artboard an open Create Font Sheet dialog uses, as Delete Artboard
already did. `families` with any `filter`, an empty one included, is an
error. docs/mcp.md says that `null` is the same as an omitted parameter for
`addon.type.fontSheet`, and the progress line says labels are optional.
This commit is contained in:
dotCooCoo committed 2026-11-30 03:07:02 -08:00
1 parent fa87375177
commit e58c1f2a07
7 files changed
+65 -15

No files matched your search

+8 -1
View File
@@ -64,7 +64,7 @@ pub fn specs() -> Vec<CommandSpec> {
"Fix All Issues",
["Object", "Plug-ins", "Artwork Cleanup"],
None,
"{scope?: \"selection\"|\"document\", kinds?: [kind…] (default: all; see addon.cleanup.check)} fix the issues addon.cleanup.check finds, in up to three rounds while a round still finds some (a fix can leave issues for another kind), as one undo step: what is empty, unpainted, invisible, duplicated or off the artboards goes, anchors merge, snap or go, tiny handles retract, paths close and needless groups, compound paths and clipping groups give way to their contents → {scope, total, fixed: {kind: count}}",
"{scope?: \"selection\"|\"document\", kinds?: [kind…] (default: all; see addon.cleanup.check)} fix the issues addon.cleanup.check finds, in up to three rounds while a round still finds some (a fix can leave issues for another kind), as one undo step: what is empty, unpainted, invisible, duplicated or off the artboards goes, anchors merge, snap or go, tiny handles retract, paths close and needless groups, compound paths and clipping groups give way to their contents. An error, with nothing fixed, when the fixes would delete the artboard an open Create Font Sheet dialog uses → {scope, total, fixed: {kind: count}}",
has_doc,
fix
),
@@ -260,6 +260,13 @@ fn fix(s: &mut Session, p: &Value) -> Result<Value> {
}
// With nothing to fix, the document and its undo history stay as they are.
if total > 0 {
if let Some(guard) = &s.artboard_deletion_guard {
let st = s.doc()?;
let protected = |doc: &Document| doc.artboards.iter().any(|a| a.id == guard.artboard);
if (st.uid, st.reverts) == guard.document && protected(&st.doc) && !protected(&d) {
return Err(EngineError::Other(guard.message.clone()));
}
}
sel.prune(&d);
s.edit("Fix Issues", |doc, selection| {
*doc = d;
@@ -36,7 +36,7 @@ pub fn specs() -> Vec<CommandSpec> {
"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), 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)} 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?}",
has_doc,
font_sheet
)]
@@ -91,7 +91,7 @@ fn families(p: &Value, db: &FontDb) -> Result<Vec<String>> {
}
return Ok(found);
}
Some(_) if filter.is_some() => return Err(bad(COMMAND, "give `families` or `filter`, not both")),
Some(_) if p.get("filter").is_some_and(|f| !f.is_null()) => return Err(bad(COMMAND, "give `families` or `filter`, not both")),
Some(Value::Array(a)) => a,
Some(_) => return Err(bad(COMMAND, "`families` must be a list of font family names")),
};
@@ -168,6 +168,8 @@ fn bad_params_are_refused_without_a_change() {
json!({"families": ["No Such Family Anywhere"]}),
json!({"families": [""]}),
json!({"families": ["Inter"], "filter": "Inter"}),
json!({"families": ["Inter"], "filter": ""}),
json!({"families": ["Inter"], "filter": " "}),
json!({"labels": "yes"}),
json!({"allStyles": 1}),
json!({"newArtboards": "no"}),
@@ -375,6 +377,30 @@ fn an_artboard_deletion_guard_checks_the_document_and_artboard_ids() {
assert_eq!(s.doc().unwrap().doc.artboards.len(), 1, "a reverted drawing is not protected");
}
/// Cut Artboard, Delete Empty Artboards and Artwork Cleanup's Empty Artboards keep the guarded artboard too.
#[test]
fn an_artboard_deletion_guard_covers_every_command_that_deletes_artboards() {
let mut s = Session::new();
s.execute("file.new", &json!({"artboards": 3})).unwrap();
let state = s.doc().unwrap();
let document = (state.uid, state.reverts);
let artboard = state.doc.artboards[1].id;
s.artboard_deletion_guard = Some(crate::ArtboardDeletionGuard { document, artboard, message: "The artboard is in use.".into() });
let before = (s.doc().unwrap().doc.clone(), steps(&s));
for (command, params) in [
("artboard.cut", json!({"index": 1})),
("artboard.deleteEmpty", json!({})),
("addon.cleanup.fix", json!({"kinds": ["emptyArtboards"], "scope": "document"})),
] {
let error = s.execute(command, &params).unwrap_err();
assert_eq!(error.to_string(), "The artboard is in use.", "{command}");
assert_eq!(s.doc().unwrap().doc, before.0, "{command}");
assert_eq!(steps(&s), before.1, "{command}");
}
s.execute("artboard.cut", &json!({"index": 2})).unwrap();
assert_eq!(s.doc().unwrap().doc.artboards.len(), 2, "another artboard is cut");
}
#[test]
fn it_needs_a_document() {
let mut s = Session::new();
+17 -8
View File
@@ -147,7 +147,7 @@ pub fn specs() -> Vec<CommandSpec> {
"Delete Artboard",
["Window", "Artboards"],
None,
"{index | indices: [index…]} delete artboards (with their guides) in one step; one is always left, and a locked one is an error",
"{index | indices: [index…]} delete artboards (with their guides) in one step; one is always left, and a locked one, or the one an open Create Font Sheet dialog uses, is an error",
has_doc,
artboard_delete
),
@@ -156,7 +156,7 @@ pub fn specs() -> Vec<CommandSpec> {
"Delete Empty Artboards",
["Window", "Artboards"],
None,
"{} delete every artboard with no artwork on it (no object, hidden, locked and template art included, whose visual bounds meet or touch it, clip groups and clipping layers by their members inside the clip; guides don't count), with its guides, in one step; locked artboards stay; when every artboard is empty and none is locked, artboard 1 stays (with a locked one left, artboard 1 can go) → {deleted: [index…]} (the indices before deleting)",
"{} delete every artboard with no artwork on it (no object, hidden, locked and template art included, whose visual bounds meet or touch it, clip groups and clipping layers by their members inside the clip; guides don't count), with its guides, in one step; locked artboards stay; when every artboard is empty and none is locked, artboard 1 stays (with a locked one left, artboard 1 can go); an error, with nothing deleted, when one of them is the artboard an open Create Font Sheet dialog uses → {deleted: [index…]} (the indices before deleting)",
has_empty_artboards,
artboard_delete_empty
),
@@ -1155,17 +1155,25 @@ fn artboard_new(s: &mut Session, p: &Value) -> Result<Value> {
fn artboard_delete(s: &mut Session, p: &Value) -> Result<Value> {
let indices = super::panelcmds::artboard_indices(&s.doc()?.doc, p, "artboard.delete")?;
if let Some(guard) = &s.artboard_deletion_guard {
let state = s.doc()?;
if (state.uid, state.reverts) == guard.document && indices.iter().any(|&index| state.doc.artboards[index].id == guard.artboard) {
return Err(EngineError::Other(guard.message.clone()));
}
}
refuse_guarded(s, &indices)?;
super::panelcmds::refuse_locked(&s.doc()?.doc, &indices)?;
s.edit("Delete Artboard", |d, sel| remove_artboards(d, sel, &indices))?;
ok()
}
/// The session's artboard deletion guard's message when deleting artboards `indices` of the
/// active document would delete the artboard it protects.
pub(crate) fn refuse_guarded(s: &Session, indices: &[usize]) -> Result<()> {
let Some(guard) = &s.artboard_deletion_guard else { return Ok(()) };
let state = s.doc()?;
if (state.uid, state.reverts) == guard.document
&& indices.iter().any(|&index| state.doc.artboards.get(index).is_some_and(|a| a.id == guard.artboard))
{
return Err(EngineError::Other(guard.message.clone()));
}
Ok(())
}
/// Delete artboards `indices` (sorted, each once) of `d` with their guides; at least one must be
/// left. The other artboards keep their order, no later artboard takes a deleted one's id, and
/// `sel` forgets the deleted guides. One walk over the artboards and one over the ruler guides,
@@ -1242,6 +1250,7 @@ fn artboard_delete_empty(s: &mut Session, _: &Value) -> Result<Value> {
if indices.is_empty() {
return Err(EngineError::Other("no empty artboards to delete".into()));
}
refuse_guarded(s, &indices)?;
s.edit("Delete Empty Artboards", |d, sel| remove_artboards(d, sel, &indices))?;
Ok(json!({ "deleted": indices }))
}
+2 -1
View File
@@ -38,7 +38,7 @@ pub fn specs() -> Vec<CommandSpec> {
"Cut Artboard",
[],
None,
"{index? | indices?, selectedArtboards?, art?, lockedAndHidden?} put the artboards and the art fully inside each on the clipboard (leaving oversized or overhanging art on the canvas and off the clipboard), then delete the artboards and that art in one undo step (one artboard is always left: the cut fails when it names every artboard, or a locked one; art also on another locked artboard stays, and is left off the clipboard, unless lockedAndHidden); edit.cut runs this while the Artboard tool is chosen → {copied: objects}",
"{index? | indices?, selectedArtboards?, art?, lockedAndHidden?} put the artboards and the art fully inside each on the clipboard (leaving oversized or overhanging art on the canvas and off the clipboard), then delete the artboards and that art in one undo step (one artboard is always left: the cut fails when it names every artboard, a locked one, or the one an open Create Font Sheet dialog uses; art also on another locked artboard stays, and is left off the clipboard, unless lockedAndHidden); edit.cut runs this while the Artboard tool is chosen → {copied: objects}",
has_doc,
|s, p| {
boards_and_art_noted(s, p, "artboard.cut")?;
@@ -366,6 +366,7 @@ pub(crate) fn artboard_copy(s: &mut Session, p: &Value, cut: bool) -> Result<Val
return Err(EngineError::Other("a document needs at least one artboard".into()));
}
if cut {
super::layer::refuse_guarded(s, &indices)?;
refuse_locked(&st.doc, &indices)?;
}
let art = st.doc.paint_order(arts.into_iter().flat_map(|(_, a)| a));
+9 -2
View File
@@ -16551,7 +16551,9 @@ envelopes, graphs, symbols), are left out.
- `addon.cleanup.check {scope?, kinds?}` changes nothing and lists `findings`: for each kind found, its `count`, the
`ids` of the objects it is on (at most 1,000) and, for empty artboards, their indexes.
- `addon.cleanup.show {kind, scope?}` selects the objects with that issue.
- `addon.cleanup.fix {scope?, kinds?}` fixes the issues as one undo step and reports how many of each kind it fixed.
- `addon.cleanup.fix {scope?, kinds?}` fixes the issues as one undo step and reports how many of each kind it fixed. When the fixes would delete the
artboard an open Create Font Sheet… dialog uses, it returns an error and fixes nothing; close the dialog or leave
`emptyArtboards` out of `kinds`.
The kinds run in a fixed order, so art removed by one kind can leave a group that a later kind unwraps, and they
run again (three rounds at most) while a round still fixes something.
@@ -18059,7 +18061,7 @@ the fonts can be compared on the artboard or printed.
| `text` | one line of sample text, at most 1000 characters, without line or paragraph breaks or other control characters (`The quick brown fox jumps over the lazy dog`) |
| `size` | the sample's size, pt 1…1296 (12) |
| `filter` | only the families whose name contains this text, in any case; empty: every family |
| `families` | instead of `filter`: these family names, in this order; each must be available and named once |
| `families` | instead of `filter`: these family names, in this order; each must be available and named once. Giving both is an error, even with an empty `filter` |
| `allStyles` | false; true: one entry for each style of each family |
| `labels` | true; false: the sample alone |
| `columns` | whole number 1…50 (2) |
@@ -18067,6 +18069,11 @@ the fonts can be compared on the artboard or printed.
| `margin` | pt 0…1000, inside each page (36) |
| `newArtboards` | true; false: the pages after the first get no artboards |
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
Artboard, Delete Empty Artboards and Artwork Cleanup's Empty Artboards return an error and change nothing when they
would delete the artboard the dialog opened on; 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
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
+1 -1
View File
@@ -3176,7 +3176,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, as point type flowed down columns on the active artboard and on new artboards of the same size to its right when the artboard is full. 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. 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 and on new artboards of the same size to its right when the artboard is full. 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. 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)