From b2a1e86fe912ea480787d52b63d5b722d031fb85 Mon Sep 17 00:00:00 2001 From: dotCooCoo Date: Mon, 16 Nov 2026 09:27:38 -0800 Subject: [PATCH] Print: a link button keeps Custom Scale W and H equal The Print dialog's General section (and the print preset editor) gets a link button after Scale W and H. While it is on, typing either percentage sets the other, and turning it on sets H to W. It is on for new settings, dimmed with the fields unless Scaling is Custom or a tiling choice, toggled with a click, Space or Enter, and screen readers hear its name and on or off state. W and H now take 1 to 1000 %. The link is saved as scale.linked with the other print settings, in the document and in print presets. A scale saved without it reads as unlinked, so earlier settings print as they did. print.setup, print.preview, file.print and print.presets.save apply the same rules: one percentage sets the other while linked, a different width and height without a linked key turn the link off, and with linked: true (or linked: null over a linked scale) they are an error. --- crates/engine/src/cmd/print.rs | 29 +++- crates/engine/src/tests/print.rs | 53 ++++++++ crates/pdf/src/print/settings.rs | 12 +- crates/pdf/src/tests/print.rs | 22 ++++ crates/ui-egui/src/dialogs/print.rs | 92 ++++++++++++- crates/ui-egui/src/dialogs/tests_print.rs | 154 ++++++++++++++++++++++ docs/mcp.md | 11 +- docs/target-app-parity.md | 1 + 8 files changed, 369 insertions(+), 5 deletions(-) diff --git a/crates/engine/src/cmd/print.rs b/crates/engine/src/cmd/print.rs index bc3c90f321..504a67d644 100644 --- a/crates/engine/src/cmd/print.rs +++ b/crates/engine/src/cmd/print.rs @@ -23,7 +23,7 @@ pub fn specs() -> Vec { "Print Setup", [], None, - "{preset?: name ([Default] or a saved print preset, any case: print.presets.list; its settings replace the document's, as choosing it in the Print dialog does), settings?: {copies: 1 (1–999), collate: true, reverse, artboards: all|range|ignore (all the art as one page), range: \"1-3, 5\" (1-based, with artboards: range), skipBlank (leave out artboards with no art that prints), media: letter|legal|tabloid|a3|a4|a5|a6|b4|b5|b4 (jis)|b5 (jis)|b6 (jis)|japanese postcard|japanese double postcard|japanese envelope #3|japanese envelope #4|kaku #2|kaku #3|yonroku-ban|custom (a paper is named by its id or its dialog label, any case and spacing, so `B5 (JIS)` works; b4 and b5 stay the ISO 216 sizes, 250 × 353 and 176 × 250 mm, and the JIS sizes are b4 (jis) 257 × 364 mm, b5 (jis) 182 × 257 mm and b6 (jis) 128 × 182 mm), width, height (custom paper, 72–14400 pt), orientation: portrait|landscape|portraitFlipped|landscapeFlipped, autoRotate: true (turn the paper to each artboard; orientation ignored), transverse (the page a quarter turn on the paper), printLayers: visiblePrintable|visible|all (template layers never print), placement: {origin: topLeft|top|topRight|left|center|right|bottomLeft|bottom|bottomRight (the point of the printed area, the artboard with its bleed and marks, on the same point of the imageable area), x, y (pt, right and down)}, scaling: none|fit|custom|tileFull|tileImageable, scale: {width: 100, height: 100} (% with custom and tiling), overlap: 0 (pt between tiles), tileRange: \"\" (1-based tiles across then down; empty: all), copiesPerSheet: false (not with tiling: as many copies of each artboard, with its bleed and marks, as fit the imageable area, across then down, not turned; the placement places the grid; an artboard that doesn't fit prints one copy per sheet, with a warning), gutter: 0 (pt between copies, 0–720), margin: 0 (pt the device can't print around the paper: the imageable area is inside it), marks: {trim, registration, colorBars, pageInfo, kind: roman|japanese, weight: 0.25, offset: 6} (as document.exportPdf, at the paper's scale; page information adds the tile and the ink), bleed: {useDocument: true (the document's bleed, document.setup), top, bottom, left, right} (pt), output: {mode: composite|separations (one gray page per ink that prints), emulsion: up|down (down mirrors), image: positive|negative, spotsToProcess, overprintBlack: false (separations: solid 100% K or 100% gray fills, strokes and characters, to within half a percent, overprint in the printed copy, gradients when every stop is (every point of a freeform one); rich, RGB, spot-linked and lighter blacks knock out; composite ignores it), inks: [{name: \"Cyan\"|…|a spot swatch, print: true, frequency (lpi, default 60), angle (screen angle, degrees counter-clockwise as PostScript setscreen takes it; default C 15, M 75, Y 0, K 45, spots 45)}]}, graphics: {autoFlatness: true, flatness: 1 (0.2–100), fonts: none|subset|complete}, color: {intent: perceptual|relativeColorimetric|saturation|absoluteColorimetric, preserveNumbers: true (CMYK colors keep their values), profile: \"\" (the printer profile, an RGB or CMYK one: composite PDF colors are converted to it with the intent, separations separate with a CMYK one; empty: as they are)}, advanced: {printAsBitmap (composite pages print as one image each, at the document's raster effects resolution, or lower for a page larger than 64 Mpx or 32,768 px a side), overprints: preserve|discard|simulate (composite output; preserve writes them to overprint (/OP), simulate prints them as Overprint Preview shows them; separations always keep them), flattenerPreset: \"\" (a flattener preset, built-in or saved: transparency is flattened before printing; empty: it prints live; PostScript defaults to medium)}, tileOrigin: {placed: false, x, y} (where the Print Tiling tool put the pages: print.tiling.set)}} store the print settings with the document, over the ones it has or the preset's (null keeps a value), as one undo step; no settings or preset → {settings} (the current ones, defaults if never set up)", + "{preset?: name ([Default] or a saved print preset, any case: print.presets.list; its settings replace the document's, as choosing it in the Print dialog does), settings?: {copies: 1 (1–999), collate: true, reverse, artboards: all|range|ignore (all the art as one page), range: \"1-3, 5\" (1-based, with artboards: range), skipBlank (leave out artboards with no art that prints), media: letter|legal|tabloid|a3|a4|a5|a6|b4|b5|b4 (jis)|b5 (jis)|b6 (jis)|japanese postcard|japanese double postcard|japanese envelope #3|japanese envelope #4|kaku #2|kaku #3|yonroku-ban|custom (a paper is named by its id or its dialog label, any case and spacing, so `B5 (JIS)` works; b4 and b5 stay the ISO 216 sizes, 250 × 353 and 176 × 250 mm, and the JIS sizes are b4 (jis) 257 × 364 mm, b5 (jis) 182 × 257 mm and b6 (jis) 128 × 182 mm), width, height (custom paper, 72–14400 pt), orientation: portrait|landscape|portraitFlipped|landscapeFlipped, autoRotate: true (turn the paper to each artboard; orientation ignored), transverse (the page a quarter turn on the paper), printLayers: visiblePrintable|visible|all (template layers never print), placement: {origin: topLeft|top|topRight|left|center|right|bottomLeft|bottom|bottomRight (the point of the printed area, the artboard with its bleed and marks, on the same point of the imageable area), x, y (pt, right and down)}, scaling: none|fit|custom|tileFull|tileImageable, scale: {width: 100, height: 100 (1–1000 % with custom and tiling), linked: true (width and height stay equal: give one and the other follows, and turning it on sets the height to the width; a different width and height without linked turn it off, and with linked: true, or linked: null over a linked scale, are an error; a saved scale without linked reads it as false)}, overlap: 0 (pt between tiles), tileRange: \"\" (1-based tiles across then down; empty: all), copiesPerSheet: false (not with tiling: as many copies of each artboard, with its bleed and marks, as fit the imageable area, across then down, not turned; the placement places the grid; an artboard that doesn't fit prints one copy per sheet, with a warning), gutter: 0 (pt between copies, 0–720), margin: 0 (pt the device can't print around the paper: the imageable area is inside it), marks: {trim, registration, colorBars, pageInfo, kind: roman|japanese, weight: 0.25, offset: 6} (as document.exportPdf, at the paper's scale; page information adds the tile and the ink), bleed: {useDocument: true (the document's bleed, document.setup), top, bottom, left, right} (pt), output: {mode: composite|separations (one gray page per ink that prints), emulsion: up|down (down mirrors), image: positive|negative, spotsToProcess, overprintBlack: false (separations: solid 100% K or 100% gray fills, strokes and characters, to within half a percent, overprint in the printed copy, gradients when every stop is (every point of a freeform one); rich, RGB, spot-linked and lighter blacks knock out; composite ignores it), inks: [{name: \"Cyan\"|…|a spot swatch, print: true, frequency (lpi, default 60), angle (screen angle, degrees counter-clockwise as PostScript setscreen takes it; default C 15, M 75, Y 0, K 45, spots 45)}]}, graphics: {autoFlatness: true, flatness: 1 (0.2–100), fonts: none|subset|complete}, color: {intent: perceptual|relativeColorimetric|saturation|absoluteColorimetric, preserveNumbers: true (CMYK colors keep their values), profile: \"\" (the printer profile, an RGB or CMYK one: composite PDF colors are converted to it with the intent, separations separate with a CMYK one; empty: as they are)}, advanced: {printAsBitmap (composite pages print as one image each, at the document's raster effects resolution, or lower for a page larger than 64 Mpx or 32,768 px a side), overprints: preserve|discard|simulate (composite output; preserve writes them to overprint (/OP), simulate prints them as Overprint Preview shows them; separations always keep them), flattenerPreset: \"\" (a flattener preset, built-in or saved: transparency is flattened before printing; empty: it prints live; PostScript defaults to medium)}, tileOrigin: {placed: false, x, y} (where the Print Tiling tool put the pages: print.tiling.set)}} store the print settings with the document, over the ones it has or the preset's (null keeps a value), as one undo step; no settings or preset → {settings} (the current ones, defaults if never set up)", has_doc, setup ), @@ -82,11 +82,38 @@ pub(crate) fn settings_over(cmd: &str, mut v: Value, p: &Value) -> Result merge(&mut v, over), Some(_) => return Err(bad(cmd, "settings must be an object")), } + link_scale(cmd, &mut v, p.get("settings").and_then(|s| s.get("scale")).filter(|s| s.is_object()))?; let set = PrintSettings::deserialize(&v).map_err(|e| bad(cmd, format!("print settings: {e}")))?; set.check().map_err(|e| pdf_error(cmd, e))?; Ok(set) } +/// Keep the custom scale's width and height equal in the merged settings `v` while `scale.linked` +/// is on, after `over` (the request's `scale`) was merged in: the one side the request gives sets +/// the other, and otherwise the height takes the width (as turning the link on does). A request +/// that gives a different width and height without a `linked` key turns the link off; with +/// `linked: true`, or with `linked: null` over a linked scale, it is refused. +fn link_scale(cmd: &str, v: &mut Value, over: Option<&Value>) -> Result<()> { + let given = |k: &str| over.and_then(|o| o.get(k)).filter(|x| !x.is_null()); + let (width, height) = (given("width").cloned(), given("height").cloned()); + let apart = matches!((&width, &height), (Some(w), Some(h)) if w.as_f64() != h.as_f64()); + let Some(scale) = v.get_mut("scale").and_then(Value::as_object_mut) else { return Ok(()) }; + if apart && over.and_then(|o| o.get("linked")).is_none() { + scale.insert("linked".into(), Value::Bool(false)); + } + if scale.get("linked") != Some(&Value::Bool(true)) { + return Ok(()); + } + if apart { + return Err(bad(cmd, "scale: give one percentage, or the same width and height, while scale.linked is on (linked: false scales them apart)")); + } + let (from, to) = if width.is_none() && height.is_some() { ("height", "width") } else { ("width", "height") }; + if let Some(value) = scale.get(from).cloned() { + scale.insert(to.into(), value); + } + Ok(()) +} + pub(crate) fn to_json(set: &PrintSettings) -> Result { serde_json::to_value(set).map_err(|e| EngineError::Other(e.to_string())) } diff --git a/crates/engine/src/tests/print.rs b/crates/engine/src/tests/print.rs index 88ee16c384..e2ea85d54f 100644 --- a/crates/engine/src/tests/print.rs +++ b/crates/engine/src/tests/print.rs @@ -69,6 +69,59 @@ fn overprint_black_is_saved_with_the_setup_and_in_presets() { assert_eq!(changed, ["output.overprintBlack"]); } +#[test] +fn the_scale_link_keeps_width_and_height_equal() { + let (mut s, _) = session(); + let scale = |s: &mut Session, p: Value| s.execute("print.setup", &json!({ "settings": p })).unwrap()["settings"]["scale"].clone(); + assert_eq!(scale(&mut s, json!({})), json!({"width": 100.0, "height": 100.0, "linked": true}), "on for a new job"); + // Linked, one percentage sets the other, whichever it is. + assert_eq!(scale(&mut s, json!({"scaling": "custom", "scale": {"width": 40}})), json!({"width": 40.0, "height": 40.0, "linked": true})); + assert_eq!(scale(&mut s, json!({"scale": {"height": 250}})), json!({"width": 250.0, "height": 250.0, "linked": true})); + assert_eq!(scale(&mut s, json!({"scale": {"width": 60, "height": 60.0}})), json!({"width": 60.0, "height": 60.0, "linked": true})); + // Two different percentages with linked: true are refused and keep what was saved. + let apart = s.execute("print.setup", &json!({"settings": {"scale": {"width": 50, "height": 200, "linked": true}}})); + assert!(matches!(apart, Err(EngineError::BadParams { .. })), "{apart:?}"); + assert!(s.execute("print.preview", &json!({"settings": {"scale": {"width": 50, "height": 200, "linked": true}}})).is_err()); + // `linked: null` keeps the saved link, as null keeps any saved setting. + let kept = s.execute("print.setup", &json!({"settings": {"scale": {"width": 50, "height": 200, "linked": null}}})); + assert!(matches!(kept, Err(EngineError::BadParams { .. })), "{kept:?}"); + assert_eq!(scale(&mut s, json!({}))["width"], 60.0); + // Without linked, two different percentages turn the link off and print as given. + assert_eq!(scale(&mut s, json!({"scale": {"width": 50, "height": 200}})), json!({"width": 50.0, "height": 200.0, "linked": false})); + assert_eq!(s.execute("print.preview", &json!({})).unwrap()["sheets"][0]["scale"], json!([50.0, 200.0])); + // Unlinked, each changes alone; turning the link on sets the height to the width. + assert_eq!(scale(&mut s, json!({"scale": {"height": 120}})), json!({"width": 50.0, "height": 120.0, "linked": false})); + assert_eq!(scale(&mut s, json!({"scale": {"linked": true}})), json!({"width": 50.0, "height": 50.0, "linked": true})); + assert_eq!(s.execute("print.preview", &json!({})).unwrap()["sheets"][0]["scale"], json!([50.0, 50.0])); + // Kept in the native file and in print presets. + let doc = &s.doc().unwrap().doc; + let back = vectorcraft_format::load(&vectorcraft_format::save(doc, false)).unwrap(); + assert_eq!(back.print_setup.as_ref().map(|p| p["scale"].clone()), Some(json!({"width": 50.0, "height": 50.0, "linked": true}))); + s.execute("print.presets.save", &json!({"name": "Apart", "settings": {"scaling": "custom", "scale": {"width": 30, "height": 90}}})).unwrap(); + let preset = s.prefs.print_presets.iter().find(|p| p.name == "Apart").map(|p| p.settings.scale.clone()); + assert_eq!(preset.map(|p| (p.width, p.height, p.linked)), Some((30.0, 90.0, false))); + assert_eq!(scale(&mut s, json!({}))["linked"], true, "saving a preset leaves the document's settings"); + let v = s.execute("print.setup", &json!({"preset": "Apart"})).unwrap(); + assert_eq!(v["settings"]["scale"], json!({"width": 30.0, "height": 90.0, "linked": false})); +} + +#[test] +fn a_scale_saved_without_the_link_keeps_its_width_and_height() { + let (mut s, _) = session(); + // Settings saved before the link had no `linked`: they print as they did, unlinked. + let mut old = serde_json::to_value(vectorcraft_pdf::PrintSettings::default()).unwrap(); + old["scaling"] = json!("custom"); + old["scale"] = json!({"width": 50, "height": 200}); + let mut doc = (*s.doc().unwrap().doc).clone(); + doc.print_setup = Some(old); + s.doc_mut().unwrap().doc = std::sync::Arc::new(doc); + let pv = s.execute("print.preview", &json!({})).unwrap(); + assert_eq!(pv["sheets"][0]["scale"], json!([50.0, 200.0])); + assert_eq!(pv["settings"]["scale"]["linked"], false); + // One percentage changes alone until the link is turned on. + assert_eq!(s.execute("print.preview", &json!({"settings": {"scale": {"width": 80}}})).unwrap()["sheets"][0]["scale"], json!([80.0, 200.0])); +} + #[test] fn print_writes_the_saved_setup_with_overrides() { let (mut s, _) = session(); diff --git a/crates/pdf/src/print/settings.rs b/crates/pdf/src/print/settings.rs index aeb9005501..15e029a13a 100644 --- a/crates/pdf/src/print/settings.rs +++ b/crates/pdf/src/print/settings.rs @@ -420,11 +420,15 @@ pub struct Placement { pub struct PrintScale { pub width: f64, pub height: f64, + /// The link between the width and the height: on, both are the same percentage. On for new + /// settings; a saved scale without it reads as off, so its width and height stay as saved. + #[serde(default)] + pub linked: bool, } impl Default for PrintScale { fn default() -> Self { - Self { width: 100.0, height: 100.0 } + Self { width: 100.0, height: 100.0, linked: true } } } @@ -585,6 +589,12 @@ impl PrintSettings { within("placement.y", self.placement.y, -14_400.0, 14_400.0, " pt")?; within("scale.width", self.scale.width, 1.0, 1000.0, "%")?; within("scale.height", self.scale.height, 1.0, 1000.0, "%")?; + if self.scale.linked && self.scale.width != self.scale.height { + return Err(PdfError::BadSetting(format!( + "scale: width ({}%) and height ({}%) must be equal while scale.linked is on", + self.scale.width, self.scale.height + ))); + } within("overlap", self.overlap, 0.0, 720.0, " pt")?; within("gutter", self.gutter, 0.0, 720.0, " pt")?; within("margin", self.margin, 0.0, 144.0, " pt")?; diff --git a/crates/pdf/src/tests/print.rs b/crates/pdf/src/tests/print.rs index 52dc3dac48..4463517c68 100644 --- a/crates/pdf/src/tests/print.rs +++ b/crates/pdf/src/tests/print.rs @@ -105,6 +105,28 @@ fn defaults_and_json() { assert_eq!(Media::A4.size().map(|(w, h)| (w.round(), h.round())), Some((595.0, 842.0))); } +#[test] +fn the_scale_link_is_on_for_new_settings_and_off_for_a_saved_scale_without_it() { + let s = PrintSettings::default(); + assert!(s.scale.linked, "new settings keep W and H equal"); + assert_eq!(serde_json::to_value(&s).unwrap()["scale"], json!({"width": 100.0, "height": 100.0, "linked": true})); + // Settings without a scale are new settings; a scale saved before the link reads as unlinked, + // so its width and height print as they did. + assert!(settings(json!({"copies": 2})).scale.linked); + let old = settings(json!({"scaling": "custom", "scale": {"width": 50, "height": 200}})); + assert_eq!((old.scale.width, old.scale.height, old.scale.linked), (50.0, 200.0, false)); + assert!(old.check().is_ok()); + // Linked, the two must be equal; the range still holds for both. + let apart = settings(json!({"scale": {"width": 50, "height": 200, "linked": true}})); + assert!(matches!(apart.check(), Err(PdfError::BadSetting(_)))); + for bad in + [json!({"width": 0, "height": 0, "linked": true}), json!({"width": 1001, "height": 1001, "linked": true}), json!({"width": -5, "height": 50})] + { + assert!(matches!(settings(json!({ "scale": bad })).check(), Err(PdfError::BadSetting(_))), "{bad}"); + } + assert!(settings(json!({"scale": {"width": 1000, "height": 1000, "linked": true}})).check().is_ok()); +} + #[test] fn japanese_paper_sizes() { // The Japanese papers: JIS B4, B5 and B6 are the sizes Japanese printing uses (JIS X 6310), diff --git a/crates/ui-egui/src/dialogs/print.rs b/crates/ui-egui/src/dialogs/print.rs index 9c68539120..017e669d9c 100644 --- a/crates/ui-egui/src/dialogs/print.rs +++ b/crates/ui-egui/src/dialogs/print.rs @@ -69,6 +69,11 @@ pub(super) fn defaults(kind: &str) -> Option<&'static Value> { /// Set when the Print Tiling tool placed the pages (`tileOrigin`): the placement is ignored. const PLACED: &str = "tileOrigin.placed"; +/// The link between Scale W and H. +const SCALE_LINKED: &str = "scale.linked"; +/// Scale W and H as [`link_scale`] last left them, to tell which one changed since. +const SCALE_SEEN: &str = "__scaleSeen"; + /// The fields that aren't print settings. const NOT_SETTINGS: [&str; 5] = ["printer", "toFile", "discard", "preset", "name"]; @@ -97,6 +102,7 @@ pub fn open(app: &mut VectorcraftApp) -> Result { let preset = app.session.prefs.print_presets.iter().find(|p| p.settings == saved).map_or(DEFAULT_PRESET, |p| p.name.as_str()); fields.insert("preset".into(), json!(preset)); fields.insert(LOADED.into(), json!(preset)); + see_scale(&mut fields); app.ui.dialog = Some(Dialog { kind: KIND.into(), fields }); Ok(Value::Null) } @@ -118,6 +124,7 @@ fn sync_preset(app: &VectorcraftApp, d: &mut Dialog) -> Result<(), String> { d.fields.insert(LOADED.into(), json!(name)); let set = app.session.print_preset_settings(&name).ok_or_else(|| format!("no print preset named `{name}`"))?; d.fields.extend(fields_of(&set)?); + see_scale(&mut d.fields); Ok(()) } @@ -148,6 +155,7 @@ pub fn open_preset(app: &mut VectorcraftApp, params: &Value) -> Result Result Result { + let mut d = d.clone(); + link_scale(&mut d); + let d = &d; let (name, editing) = (d.str("name"), d.str(EDITING)); let p = if editing.is_empty() { if app.session.print_preset_settings(&name).is_some() { @@ -188,6 +199,7 @@ fn confirm(app: &mut VectorcraftApp, d: &Dialog) -> Result { // Done's flag holds for this press only: the dialog may stay open. let done = d.fields.remove("discard").is_some_and(|v| v == true); let synced = sync_preset(app, &mut d); + link_scale(&mut d); app.ui.dialog = Some(d.clone()); synced?; // While Save Preset… asks for a name, OK (and Enter) saves the preset instead. @@ -217,6 +229,7 @@ fn body(app: &mut VectorcraftApp, ui: &mut egui::Ui, d: &mut Dialog) -> bool { if let Err(e) = sync_preset(app, d) { app.status(e); } + link_scale(d); if d.kind == PRESET_KIND { row_with(ui, tl!("Preset name:"), TOP_LABEL_WIDTH, |ui| { form::text_edit(ui, d, "name", 288.0); @@ -577,6 +590,75 @@ fn whole(ui: &mut egui::Ui, d: &mut Dialog, path: &str, range: std::ops::RangeIn }); } +/// A Scale percentage at `path`, 1–1000 %: the value typed, once one was. +fn percent(ui: &mut egui::Ui, d: &mut Dialog, path: &str, enabled: bool) -> Option { + let v = get(d, path).as_f64().unwrap_or(100.0); + let typed = ui.add_enabled_ui(enabled, |ui| widgets::range_field(ui, path, v, 1.0..=1000.0, "%", 3, 64.0)).inner; + if let Some(x) = typed { + set(d, path, json!(x)); + } + typed +} + +/// The link after Scale W and H: on, either field sets both, and turning it on sets H to W. With +/// the keyboard on it, Space or Enter toggles it unless it is dimmed. +fn scale_link(ui: &mut egui::Ui, d: &mut Dialog, linked: bool) { + const NAME: &str = "Constrain Width and Height Proportions"; + let size = crate::panels::transform::CONSTRAIN_LINK_SIZE; + let (_, at) = ui.allocate_exact_size(egui::Vec2::splat(size), egui::Sense::click()); + let enabled = ui.is_enabled(); + let keyed = enabled + && at.has_focus() + && ui.input_mut(|i| i.consume_key(egui::Modifiers::NONE, egui::Key::Space) | i.consume_key(egui::Modifiers::NONE, egui::Key::Enter)); + let resp = widgets::paint_icon_button(ui, at, if linked { "link" } else { "link-2-off" }, NAME, linked); + // Off is a state too: screen readers hear the link as off, not as a plain button. + resp.widget_info(|| egui::WidgetInfo::selected(egui::Role::Button, enabled, linked, tl!(NAME))); + if resp.clicked() || keyed { + set(d, SCALE_LINKED, json!(!linked)); + link_scale(d); + } +} + +/// While the Scale link is on, keep H equal to W: the field that changed since the last call (a +/// field typed in, or `ui.dialog.set`) gives its value to the other, and when neither changed H +/// takes W, as turning the link on does. As `print.setup` reads a `scale`: one set with W and H +/// apart and without a `linked` key turns the link off, one that leaves out W, H or `linked` (or +/// gives `null`) keeps it as it was, and one that changes both W and H apart while linked is left +/// as it is (and stays changed on later calls), for confirming to refuse. +fn link_scale(d: &mut Dialog) { + let seen = d.fields.get(SCALE_SEEN).cloned().unwrap_or_default(); + if let Some(Value::Object(s)) = d.fields.get_mut("scale") { + let num = |s: &serde_json::Map, k: &str| s.get(k).and_then(Value::as_f64); + let stated = |s: &serde_json::Map, k: &str| s.get(k).is_some_and(|v| !v.is_null()); + if s.get("linked").is_none() && num(s, "width").zip(num(s, "height")).is_some_and(|(w, h)| w != h) { + s.insert("linked".into(), json!(false)); + } + for (i, k) in ["width", "height", "linked"].into_iter().enumerate() { + if !stated(s, k) && !seen[i].is_null() { + s.insert(k.into(), seen[i].clone()); + } + } + } + let (w, h) = (get(d, "scale.width").clone(), get(d, "scale.height").clone()); + if get(d, SCALE_LINKED).as_bool() == Some(true) && w.as_f64() != h.as_f64() { + let (w_kept, h_kept) = (seen[0].as_f64() == w.as_f64(), seen[1].as_f64() == h.as_f64()); + if (w_kept && !h_kept) || w.as_f64().is_none() { + set(d, "scale.width", h); + } else if h_kept || seen.is_null() { + set(d, "scale.height", w); + } else { + return; + } + } + see_scale(&mut d.fields); +} + +/// Remember Scale W, H and the link as the fields hold them, for [`link_scale`]. +fn see_scale(fields: &mut serde_json::Map) { + let s = fields.get("scale").cloned().unwrap_or_default(); + fields.insert(SCALE_SEEN.into(), json!([s["width"], s["height"], s["linked"]])); +} + fn general(app: &VectorcraftApp, ui: &mut egui::Ui, d: &mut Dialog) { let unit = app.session.general_unit(); row(ui, tl!("Copies:"), |ui| { @@ -662,10 +744,16 @@ fn general(app: &VectorcraftApp, ui: &mut egui::Ui, d: &mut Dialog) { }); row(ui, tl!("Scale:"), |ui| { let on = scaling == PrintScaling::Custom || tiles; + let linked = get(d, SCALE_LINKED).as_bool() == Some(true); ui.label(tl!("W:")); - number(ui, d, "scale.width", "%", on); + if let Some(w) = percent(ui, d, "scale.width", on).filter(|_| linked) { + set(d, "scale.height", json!(w)); + } ui.label(tl!("H:")); - number(ui, d, "scale.height", "%", on); + if let Some(h) = percent(ui, d, "scale.height", on).filter(|_| linked) { + set(d, "scale.width", json!(h)); + } + ui.add_enabled_ui(on, |ui| scale_link(ui, d, linked)); }); row(ui, tl!("Overlap:"), |ui| length(ui, d, "overlap", unit, tiles)); row(ui, tl!("Tile Range:"), |ui| text(ui, d, "tileRange", tiles)); diff --git a/crates/ui-egui/src/dialogs/tests_print.rs b/crates/ui-egui/src/dialogs/tests_print.rs index 3bf847d0e7..f1baabc1b9 100644 --- a/crates/ui-egui/src/dialogs/tests_print.rs +++ b/crates/ui-egui/src/dialogs/tests_print.rs @@ -286,3 +286,157 @@ fn the_control_channel_fills_and_confirms_the_dialog() { assert_eq!(app.session.active().unwrap().doc.print_setup.as_ref().unwrap()["copies"], 5); assert_eq!(jobs.borrow().len(), 1); } + +/// Frames of the dialog layer with the accessibility tree on. +struct Screen { + ctx: egui::Context, + time: f64, +} + +impl Screen { + fn new() -> Self { + let ctx = egui::Context::default(); + ctx.enable_accesskit(); + theme::install_fonts(&ctx); + Self { ctx, time: 0.0 } + } + + fn run(&mut self, app: &mut VectorcraftApp, events: Vec) -> egui::FullOutput { + self.time += 0.1; + let screen = egui::Rect::from_min_size(egui::Pos2::ZERO, egui::vec2(1280.0, 900.0)); + let input = egui::RawInput { events, time: Some(self.time), screen_rect: Some(screen), ..Default::default() }; + let mut out = self.ctx.run_ui(input, |ui| super::show(app, ui.ctx())); + out.textures_delta.clear(); + out + } + + /// The Scale link as screen readers find it: its node, whether it is on, and whether it is dimmed. + fn link(&mut self, app: &mut VectorcraftApp) -> (egui::accesskit::NodeId, Option, bool) { + self.run(app, vec![]); + let out = self.run(app, vec![]); + let nodes = &out.platform_output.accesskit_update.as_ref().expect("an accessibility tree").nodes; + let link = + nodes.iter().find(|(_, n)| n.label() == Some("Constrain Width and Height Proportions") && n.role() == egui::accesskit::Role::Button); + let (id, node) = link.expect("the Scale link"); + (*id, node.toggled(), node.is_disabled()) + } +} + +/// Scale W and H of the open dialog, and its link. +fn scale(app: &mut VectorcraftApp) -> (f64, f64, bool) { + let s = &dialog(app).fields["scale"]; + (s["width"].as_f64().unwrap_or(f64::NAN), s["height"].as_f64().unwrap_or(f64::NAN), s["linked"] == true) +} + +#[test] +fn the_scale_link_keeps_scale_width_and_height_equal() { + use egui::accesskit::{Action, ActionRequest, Toggled, TreeId}; + let (mut app, _) = app(); + app.run("file.print", json!({})).unwrap(); + let mut screen = Screen::new(); + // On for a new job, and dimmed with the fields until a scaling uses them. + let (link, on, dimmed) = screen.link(&mut app); + assert_eq!((on, dimmed), (Some(Toggled::True), true)); + set(&mut app, "scaling", json!("custom")); + assert!(!screen.link(&mut app).2, "Custom scales by W and H"); + // Linked, a new W sets H, and a new H sets W. + dialog(&mut app).fields["scale"]["width"] = json!(40); + screen.run(&mut app, vec![]); + assert_eq!(scale(&mut app), (40.0, 40.0, true)); + dialog(&mut app).fields["scale"]["height"] = json!(250); + screen.run(&mut app, vec![]); + assert_eq!(scale(&mut app), (250.0, 250.0, true)); + // A click turns it off: screen readers hear it off, and each field changes alone. + let request = |action| egui::Event::AccessKitActionRequest(ActionRequest { action, target_node: link, target_tree: TreeId::ROOT, data: None }); + screen.run(&mut app, vec![request(Action::Click)]); + assert_eq!(screen.link(&mut app).1, Some(Toggled::False)); + dialog(&mut app).fields["scale"]["width"] = json!(50); + screen.run(&mut app, vec![]); + assert_eq!(scale(&mut app), (50.0, 250.0, false)); + // Space on the focused link turns it on and sets H to W; Enter turns it off again. + let key = |key| egui::Event::Key { key, physical_key: None, pressed: true, repeat: false, modifiers: egui::Modifiers::NONE }; + screen.run(&mut app, vec![request(Action::Focus)]); + screen.run(&mut app, vec![key(egui::Key::Space)]); + assert_eq!(scale(&mut app), (50.0, 50.0, true)); + assert_eq!(screen.link(&mut app).1, Some(Toggled::True)); + screen.run(&mut app, vec![request(Action::Focus)]); + screen.run(&mut app, vec![key(egui::Key::Enter)]); + assert_eq!(scale(&mut app), (50.0, 50.0, false)); + // Done keeps the link with the document's settings, and the next Print opens with it. + dialog(&mut app).fields["scale"]["height"] = json!(75); + set(&mut app, "discard", json!(true)); + super::confirm(&mut app).unwrap(); + let saved = app.session.active().unwrap().doc.print_setup.clone().unwrap(); + assert_eq!(saved["scale"], json!({"width": 50.0, "height": 75.0, "linked": false})); + app.run("file.print", json!({})).unwrap(); + assert_eq!(scale(&mut app), (50.0, 75.0, false)); +} + +#[test] +fn a_print_preset_keeps_the_scale_link() { + let (mut app, _) = app(); + app.run("print.presets.save", json!({"name": "Apart", "settings": {"scaling": "custom", "scale": {"width": 30, "height": 90}}})).unwrap(); + app.run("file.print", json!({})).unwrap(); + assert_eq!(scale(&mut app), (100.0, 100.0, true)); + // Choosing the preset loads its unlinked W and H as they are. + set(&mut app, "preset", json!("Apart")); + frame(&mut app); + assert_eq!(scale(&mut app), (30.0, 90.0, false)); + // A scale set without the link and with W and H apart turns it off, as print.setup reads it. + set(&mut app, "preset", json!("[Default]")); + frame(&mut app); + assert_eq!(scale(&mut app), (100.0, 100.0, true)); + set(&mut app, "scale", json!({"width": 20, "height": 60})); + frame(&mut app); + assert_eq!(scale(&mut app), (20.0, 60.0, false)); + // `linked: null` keeps the link as it was, off here. + set(&mut app, "scale", json!({"width": 30, "height": 70, "linked": null})); + frame(&mut app); + assert_eq!(dialog(&mut app).fields["scale"], json!({"width": 30, "height": 70, "linked": false})); +} + +#[test] +fn a_scale_set_through_the_dialog_keeps_the_percentage_it_changes() { + let (mut app, _) = app(); + app.run("file.print", json!({})).unwrap(); + // A new H with the link on, set before any frame: W follows it, and Done saves both. + set(&mut app, "scale", json!({"width": 100, "height": 250, "linked": true})); + set(&mut app, "discard", json!(true)); + super::confirm(&mut app).unwrap(); + let saved = app.session.active().unwrap().doc.print_setup.clone().unwrap(); + assert_eq!(saved["scale"], json!({"width": 250.0, "height": 250.0, "linked": true})); + // A scale that gives only W keeps the link and H as they were, so H follows W. + app.run("file.print", json!({})).unwrap(); + set(&mut app, "scale", json!({"width": 40})); + frame(&mut app); + assert_eq!(scale(&mut app), (40.0, 40.0, true)); + // A new W and H apart with `linked: null` keep the link on: they stay as set, and confirming + // refuses them, as print.setup does, and saves nothing. + set(&mut app, "scale", json!({"width": 50, "height": 200, "linked": null})); + frame(&mut app); + frame(&mut app); + assert_eq!(scale(&mut app), (50.0, 200.0, true)); + set(&mut app, "discard", json!(true)); + assert!(super::confirm(&mut app).is_err()); + let saved = app.session.active().unwrap().doc.print_setup.clone().unwrap(); + assert_eq!(saved["scale"], json!({"width": 250.0, "height": 250.0, "linked": true})); +} + +#[test] +fn the_dimmed_scale_link_ignores_the_keyboard() { + use egui::accesskit::{Action, ActionRequest, TreeId}; + let (mut app, _) = app(); + app.run("file.print", json!({})).unwrap(); + let mut screen = Screen::new(); + set(&mut app, "scaling", json!("custom")); + let (link, _, _) = screen.link(&mut app); + let focus = + egui::Event::AccessKitActionRequest(ActionRequest { action: Action::Focus, target_node: link, target_tree: TreeId::ROOT, data: None }); + let space = egui::Event::Key { key: egui::Key::Space, physical_key: None, pressed: true, repeat: false, modifiers: egui::Modifiers::NONE }; + screen.run(&mut app, vec![focus]); + // Scaling None dims the link while it has the keyboard: Space leaves it as it was. + set(&mut app, "scaling", json!("none")); + screen.run(&mut app, vec![space]); + screen.run(&mut app, vec![]); + assert_eq!(scale(&mut app), (100.0, 100.0, true)); +} diff --git a/docs/mcp.md b/docs/mcp.md index d3a5350b4e..08da97320a 100644 --- a/docs/mcp.md +++ b/docs/mcp.md @@ -8547,7 +8547,16 @@ documents every field: `orientation`, `autoRotate` (on by default: the paper turns to each artboard), `transverse`; `printLayers: visiblePrintable|visible|all` (template layers never print); `placement: {origin, x, y}` places the printed area (artboard, bleed and marks) on the imageable area (the paper inside `margin`); `scaling: none|fit|custom|tileFull| - tileImageable` with `scale: {width, height}` (%), `overlap` and `tileRange` (tiles numbered across then down). + tileImageable` with `scale: {width, height, linked}` (1–1000 %), `overlap` and `tileRange` (tiles numbered across + then down). +- `scale.linked` keeps the custom scale's width and height equal, as the link by Custom's width and height does on + [the help page](https://helpx.adobe.com/illustrator/desktop/save-and-export/export-files-to-different-formats/print-documents-in-illustrator.html), + where turning it off scales the two apart. The rest is VectorCraft's own rule. New settings have it on, and a saved + `scale` without `linked` reads it as false, so settings and presets saved before it print as they did. While it is + on, a request that gives one percentage sets the other, turning it on sets the height to the width, and a width and + height that differ are an error. A request that gives a different width and height without `linked` turns it off; + `linked: null` keeps the saved link, as `null` does for every setting. The Print dialog shows it as the link button after Scale W and H, dimmed with them unless Scaling is Custom or a + tiling choice. - Copies per sheet: with `copiesPerSheet: true` (off by default; not with tiling) each sheet holds as many copies of the artboard as fit the imageable area, each with its bleed and marks, across then down, `gutter` pt apart (0–720, default 0). The copies are not turned, and the placement places the whole grid. An artboard that doesn't fit prints diff --git a/docs/target-app-parity.md b/docs/target-app-parity.md index ab6548a2d0..bcddb0e8bc 100644 --- a/docs/target-app-parity.md +++ b/docs/target-app-parity.md @@ -1982,6 +1982,7 @@ Moved from the ROADMAP's "Shipped so far" on 2026-10-10. Update it when a featur - Separations Preview shows placed and embedded raster images on the visible plates, as it shows vector art (#4153): an RGB image's pixels are separated into process inks with the proof setup's intent, a CMYK image shows its own inks, a hidden plate's ink leaves the image, and with one plate visible the image shows that plate's ink as a grey. Raster images carry no spot ink, so a spot plate shown alone shows them as paper; a colorized image shows its color's plates. Emoji and other bitmap glyphs follow the same rule. The plate-filtered pixels and their reduced-size copies are kept apart from the image's own pixels, for each set of visible plates, proof setup and color settings, and with the preview off nothing changes. Evidence: `tests::colorize::separations_preview_shows_an_rgb_images_process_inks`, `separations_preview_shows_a_cmyk_images_own_inks`, `separations_preview_keeps_an_images_pixels_per_plate_set`. Print preview fidelity remains the open gap, so scores and hours are unchanged. - Desktop print transport uses `craft-print` for CUPS and modern Windows. Sheet composition, copies, separations and colour management remain in VectorCraft. The Print dialog's Media list also carries the Japanese papers — JIS B4 257 × 364 mm, JIS B5 182 × 257 mm and JIS B6 128 × 182 mm beside the ISO B4/B5 (250 × 353 and 176 × 250 mm, kept so settings and presets saved before them keep their paper), and はがき 100 × 148 mm, 往復はがき 148 × 200 mm, 封筒 長形3号 120 × 235 mm, 長形4号 90 × 225 mm, 角形2号 240 × 332 mm, 角形3号 216 × 277 mm and 四六判 127 × 188 mm; the JSON id or the dialog label names a paper, any case and spacing (`B5 (JIS)` or `b5jis`) (`crates/pdf/src/print/settings.rs`, `crates/pdf/src/tests/print.rs`). The print-preview and physical-device fidelity gaps remain, so print scores and hours are unchanged. - The Print dialog's Output section has Overprint Black under Convert All Spot Colors to Process, off by default and available with Separations ([Print color separations](https://helpx.adobe.com/illustrator/using/printing-color-separations.html) lists it among the separation options): black art then leaves the inks under it on the other plates (`print.setup {settings: {output: {overprintBlack: true}}}`, kept with the document and in print presets). Solid 100% K or 100% gray fills, strokes and characters (to within half a percent, as Edit › Edit Colors › Overprint Black counts them), and gradients whose every stop (every color point of a freeform gradient) is, overprint; rich, RGB, Lab, spot-linked and lighter blacks knock out, and only the printed copy is marked. These limits are VectorCraft's own rules. Characters set to overprint now also leave the inks below them on printed PDF plates, a type object's own fill in a PDF is drawn with its blending mode, and Edit › Edit Colors › Overprint Black counts a gradient with a stop linked to a spot swatch as a spot black, as it counts a solid one, and a freeform gradient by the color points it draws from. Evidence: `print::overprint_black_keeps_the_inks_under_solid_black_on_separations`, `print::overprint_black_keeps_the_cyan_under_near_and_freeform_blacks_on_postscript_plates`, `print::overprinting_type_leaves_the_inks_below_on_separations`, `print::a_type_objects_own_black_fill_overprints_on_separations`, `tests::print::overprint_black_is_saved_with_the_setup_and_in_presets`, `overprint::tests::a_gradient_with_a_spot_linked_stop_is_black_only_with_spot`, `overprint::tests::a_freeform_gradient_is_black_when_every_point_is`. Print scores and hours are unchanged. + - The Print dialog's General section (and the print preset editor) has a link button after Scale W and H, as the Custom scale has one on [the help page](https://helpx.adobe.com/illustrator/desktop/save-and-export/export-files-to-different-formats/print-documents-in-illustrator.html), where turning it off scales the width and height apart. While it is on, typing either percentage sets the other, and turning it on sets H to W. It is on for new settings, dimmed with the fields unless Scaling is Custom or a tiling choice, toggled with a click, Space or Enter, and named with its on or off state for screen readers. W and H take 1–1000% in the fields. The link is kept with the document's print settings and in print presets (`print.setup {settings: {scale: {linked}}}`); settings saved without it read it as off, so they print as before. Its default, the tiling choices and the agent rules are VectorCraft's own. Evidence: `print::the_scale_link_is_on_for_new_settings_and_off_for_a_saved_scale_without_it`, `tests::print::the_scale_link_keeps_width_and_height_equal`, `tests::print::a_scale_saved_without_the_link_keeps_its_width_and_height`, `dialogs::tests_print::the_scale_link_keeps_scale_width_and_height_equal`, `dialogs::tests_print::a_print_preset_keeps_the_scale_link`. Print scores and hours are unchanged. - A PDF, PDF-compatible `.ai` or `.ait` opened from its pages or its editing copy opens with the File Info that its XMP packet and its document information dictionary give: the title (`dc:title`, its `x-default` item first, else Info `Title`), the author, description, keywords, copyright status, notice and URL, and the created and modified dates, the XMP packet's value where both give one (`crates/pdf/src/tests/file_info.rs`, `crates/engine/src/tests/fileinfo.rs`). An SVG opens with the title of its root ``. The title is File Info's alone (`DocMetadata::title`): the document's name stays the file's name with its extension, a file that gives no title leaves File Info with that name, and exports (PDF, SVG, PNG, EPS, `.ai`) and native saves carry it; changing the title in File Info sets the document's name as before (#3626). - PDF export and PDF-compatible `.ai` and `.ait` saves write the document's File Info created date as the file's creation date, or the time of writing when the document has none, and the time of writing as its modification date; the page information mark still prints the time of writing (`crates/engine/src/tests/fileinfo.rs`, `crates/pdf/src/tests.rs`, `crates/pdf/src/tests/marks.rs`). - PDF export and PDF-compatible `.ai` and `.ait` saves write File Info's copyright notice, URL and status to the XMP packet (`dc:rights`, `xmpRights:WebStatement`, `xmpRights:Marked`), so a PDF or `.ai` opened from its pages keeps them (`crates/pdf/src/tests/file_info.rs`, `crates/engine/src/tests/fileinfo.rs`).