From 31f755960f571ac982e42dd03d1e466b9e751cc1 Mon Sep 17 00:00:00 2001 From: dotCooCoo Date: Tue, 1 Dec 2026 07:14:51 -0800 Subject: [PATCH] Color Effects: screen print marks check type lines without the target weight The canvas-edge check padded every mark by the target stroke weight, so a line of type that fit inside the canvas could be refused. Only the stroked targets are padded now; each line of type is checked by its layout box and its glyphs' ink, underline and strikethrough bars included. --- crates/engine/src/cmd/addons/color/screen_marks.rs | 13 ++++++++++--- .../src/cmd/addons/color/screen_marks/tests.rs | 10 ++++++++++ 2 files changed, 20 insertions(+), 3 deletions(-) diff --git a/crates/engine/src/cmd/addons/color/screen_marks.rs b/crates/engine/src/cmd/addons/color/screen_marks.rs index ceba23ec7d..f4a02d4fdf 100644 --- a/crates/engine/src/cmd/addons/color/screen_marks.rs +++ b/crates/engine/src/cmd/addons/color/screen_marks.rs @@ -321,9 +321,16 @@ fn screen_marks(s: &mut Session, p: &Value) -> Result { let st = s.doc()?; let layer = marks_layer(&st.doc).map(|l| (l.id, l.children().cloned().unwrap_or_default())); let drawn: Vec = boards.iter().map(|(r, board)| marks.group(*r, *board, &mut || NodeId(0))).collect(); - let reach = marks.weight; - let beyond = |b: Rect| [b.x0 - reach, b.y0 - reach, b.x1 + reach, b.y1 + reach].iter().any(|v| !v.is_finite() || v.abs() > MAX_COORD); - if drawn.iter().any(|g| g.geometric_bounds().is_some_and(beyond)) { + // Only the stroked targets reach past their paths by the target weight. The lines of type have + // no stroke; their glyphs' ink, underline and strikethrough bars included, is checked as well. + let past = |b: Rect, reach: f64| [b.x0 - reach, b.y0 - reach, b.x1 + reach, b.y1 + reach].iter().any(|v| !v.is_finite() || v.abs() > MAX_COORD); + let beyond = |n: &Node| match &n.kind { + NodeKind::Text(t) => { + n.geometric_bounds().is_some_and(|b| past(b, 0.0)) || t.ink().flatten().is_some_and(|ink| past(t.xf.transform_rect_bbox(ink), 0.0)) + } + _ => n.geometric_bounds().is_some_and(|b| past(b, marks.weight)), + }; + if drawn.iter().any(|g| g.children().is_some_and(|kids| kids.iter().any(|k| beyond(k)))) { return Err(bad(C, format!("the marks would reach past the edge of the canvas (±{MAX_COORD} pt)"))); } if let Some((layer, kids)) = &layer { diff --git a/crates/engine/src/cmd/addons/color/screen_marks/tests.rs b/crates/engine/src/cmd/addons/color/screen_marks/tests.rs index 7d356efd46..eed2fdf0f8 100644 --- a/crates/engine/src/cmd/addons/color/screen_marks/tests.rs +++ b/crates/engine/src/cmd/addons/color/screen_marks/tests.rs @@ -181,6 +181,16 @@ fn marks_past_the_canvas_edge_are_refused() { run(&mut s, json!({"artboard": 1, "positions": ["right"]})); } +#[test] +fn the_target_weight_does_not_pad_lines_of_type_at_the_canvas_edge() { + let mut s = session(); + // The artboard ends 10 pt inside the canvas edge. + s.execute("artboard.new", &json!({"x": 3999090, "y": 0, "width": 900, "height": 100})).unwrap(); + let p = json!({"artboard": 1, "positions": [], "info": true, "textAlign": "right", "inset": 0, "weight": 20}); + let r = run(&mut s, p); + assert_eq!(lines(&node(&s, r["ids"][0].as_u64().unwrap())).len(), 1); +} + #[test] fn every_artboard_gets_its_group_and_one_artboard_rerun_keeps_the_others() { let mut s = session();