From 8b781a6eed651302ef8c22a7411c0f548156b714 Mon Sep 17 00:00:00 2001 From: skylartaylor Date: Tue, 24 Nov 2026 14:53:49 +0100 Subject: [PATCH 1/5] Render: test that moving a group damages its text's descenders below the frame A text frame fitted to its text ends on its last baseline, so its descenders paint below it. Moved inside a group, with the canvas's composition cache, that ink is outside the damage and stays behind as a trail (#3193). --- crates/render/src/damage.rs | 37 ++++++++++++++++++++++++++++++++++++- 1 file changed, 36 insertions(+), 1 deletion(-) diff --git a/crates/render/src/damage.rs b/crates/render/src/damage.rs index 979780ada..48873e806 100644 --- a/crates/render/src/damage.rs +++ b/crates/render/src/damage.rs @@ -495,9 +495,44 @@ mod tests { assert!(changed.iter().any(|p| p.x < 70.0), "the child's stroke paints its scaled width"); } + /// Text in a group paints its descenders below its frame, as a lone frame's do, and moving the + /// group damages them where they were and where they are (#3193). The canvas passes its + /// composition cache, which finds the text unchanged by the move, so only the group's own + /// area covers its text. + #[test] + fn moving_a_group_damages_its_text_below_the_frame() { + let mut d = Document::new(&NewDocument { pages: 1, ..Default::default() }); + let lid = d.default_layer(); + let text = "gjpqy gjpqy"; + let (f, sid) = d.add_text_frame(SpreadRef::Doc(0), Rect::new(100.0, 200.0, 450.0, 400.0), lid, text, ParaFormat::default()).unwrap(); + d.story_mut(sid).unwrap().format_chars(0..text.len(), |c| c.over.size = Some(48.0)); + // Fit Frame to Content: the frame ends at the baseline, the descenders below it. + let baseline = designcraft_compose::Cache::new().get(&d, sid, None).frame(f).unwrap().lines[0].baseline; + let bottom = baseline + 1.0; + d.item_mut(f).unwrap().path = designcraft_geom::shapes::rectangle(Rect::new(100.0, 200.0, 450.0, bottom)); + let i = d.spreads[0].items.iter().position(|it| it.id == f).unwrap(); + let frame = Arc::make_mut(&mut d.spreads[0]).items.remove(i); + let gid = ItemId(d.alloc()); + let mut group = Item::new(gid, lid, designcraft_doc::Shape::Group, Default::default()); + group.content = designcraft_doc::Content::Group { items: vec![frame] }; + d.insert_item(SpreadRef::Doc(0), group, None).unwrap(); + // The canvas has composed the version it shows. + let cache = designcraft_compose::Cache::new(); + let _ = cache.get(&d, sid, None); + let old = d.clone(); + d.item_mut(gid).unwrap().xf = designcraft_geom::Affine::translate((0.0, -80.0)); + let dmg = damage_with(&old, &d, Some(&cache)).expect("bounded damage"); + let changed = changed_pixels_in(&old, &d, &dmg); + assert!(changed.iter().any(|p| p.y > bottom), "the descenders paint below the frame"); + } + /// The pixels a page render changes from `old` to `new`, each checked to lie in the damage. fn changed_pixels_in_damage(old: &Document, new: &Document) -> Vec { - let dmg = damage(old, new).expect("bounded damage"); + changed_pixels_in(old, new, &damage(old, new).expect("bounded damage")) + } + + /// The pixels a page render changes from `old` to `new`, each checked to lie in `dmg`. + fn changed_pixels_in(old: &Document, new: &Document, dmg: &[(SpreadRef, Rect)]) -> Vec { let cache = designcraft_compose::Cache::new(); let mut r = crate::Renderer::new(); r.threads = 0; From 0dec15234d16733b81da347bc856c0a1fb8a8d28 Mon Sep 17 00:00:00 2001 From: skylartaylor Date: Tue, 24 Nov 2026 14:54:03 +0100 Subject: [PATCH 2/5] Canvas: moving a group repaints its text's descenders below the frame A moved item's damage pads a text frame by its glyphs' overhang only when the item itself is the frame. A text frame inside a group got its box and stroke alone, and with the composition cache a move damages no frames of its unchanged text, so descenders below a frame fitted to its text left trails. A group's children now get the same overhang, through their transforms. Fixes #3193 --- crates/render/src/damage.rs | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/crates/render/src/damage.rs b/crates/render/src/damage.rs index 48873e806..87aea273c 100644 --- a/crates/render/src/damage.rs +++ b/crates/render/src/damage.rs @@ -174,24 +174,29 @@ fn item_area(it: &Item) -> Option { // and feathers stay inside the shape. let scale = max_scale(it.xf)?; let stroke = it.stroke.extent().max(0.0) * scale; - let pad = stroke + 2.0 + if it.is_text_frame() { 24.0 } else { 0.0 } + crate::fx::outset_scaled(it, scale); + let pad = stroke + 2.0 + if it.is_text_frame() { GLYPH_OVERHANG } else { 0.0 } + crate::fx::outset_scaled(it, scale); if !pad.is_finite() { return None; } Some(painted_bounds(it)?.inflate(pad, pad)) } +/// How far a text frame's glyphs paint past its text box: descenders below a frame fitted to its +/// last baseline, italics, swashes and big initials. +const GLYPH_OVERHANG: f64 = 24.0; + /// An item's bounds, grown to its text: text is composed in the box around the frame's path in /// the frame's own coordinates, which a sheared then rotated frame turns past its path's bounds. -/// Its children's bounds include their strokes. None when a child's transform is not finite. +/// Its children's bounds include their strokes and, for text frames, their glyphs' overhang. None +/// when a child's transform is not finite. fn painted_bounds(it: &Item) -> Option { let mut b = it.bounds(); if it.is_text_frame() { b = b.union(it.xf.transform_rect_bbox(it.inner_bounds())); } for c in it.children() { - let stroke = c.stroke.extent().max(0.0) * max_scale(c.xf)?; - b = b.union(it.xf.transform_rect_bbox(painted_bounds(c)?.inflate(stroke, stroke))); + let pad = (c.stroke.extent().max(0.0) + if c.is_text_frame() { GLYPH_OVERHANG } else { 0.0 }) * max_scale(c.xf)?; + b = b.union(it.xf.transform_rect_bbox(painted_bounds(c)?.inflate(pad, pad))); } Some(b) } From 284b2eb6bdef27d450efae63b839d07312f751ed Mon Sep 17 00:00:00 2001 From: "autocraft-bot[bot]" <354215646+autocraft-bot[bot]@users.noreply.github.com> Date: Wed, 25 Nov 2026 01:10:07 +0000 Subject: [PATCH 3/5] Apply review fixes - crates/render/src/damage.rs --- crates/render/src/damage.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/crates/render/src/damage.rs b/crates/render/src/damage.rs index 87aea273c..1c576192d 100644 --- a/crates/render/src/damage.rs +++ b/crates/render/src/damage.rs @@ -174,7 +174,7 @@ fn item_area(it: &Item) -> Option { // and feathers stay inside the shape. let scale = max_scale(it.xf)?; let stroke = it.stroke.extent().max(0.0) * scale; - let pad = stroke + 2.0 + if it.is_text_frame() { GLYPH_OVERHANG } else { 0.0 } + crate::fx::outset_scaled(it, scale); + let pad = stroke + 2.0 + if it.is_text_frame() { GLYPH_OVERHANG * scale } else { 0.0 } + crate::fx::outset_scaled(it, scale); if !pad.is_finite() { return None; } From e6fbf5931ca9873fb304493296db46063c74b0a1 Mon Sep 17 00:00:00 2001 From: "autocraft-bot[bot]" <354215646+autocraft-bot[bot]@users.noreply.github.com> Date: Thu, 26 Nov 2026 22:40:46 +0000 Subject: [PATCH 4/5] Apply review fixes - crates/render/src/damage.rs --- crates/render/src/damage.rs | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/crates/render/src/damage.rs b/crates/render/src/damage.rs index 1c576192d..e926cc627 100644 --- a/crates/render/src/damage.rs +++ b/crates/render/src/damage.rs @@ -205,9 +205,11 @@ fn painted_bounds(it: &Item) -> Option { fn frame_area(d: &Document, f: ItemId) -> Option<(SpreadRef, Rect)> { let loc = d.find(f)?; let it = d.item_at(&loc)?; - let b = d.parent_xf(&loc).transform_rect_bbox(painted_bounds(it)?); + let pxf = d.parent_xf(&loc); + let b = pxf.transform_rect_bbox(painted_bounds(it)?); // Overhang of italics, swashes and big initials, and anchored objects pinned to lines. - Some((loc.spread, b.inflate(24.0 + 0.1 * b.width().max(b.height()), 24.0))) + let glyph = GLYPH_OVERHANG * max_scale(pxf * it.xf)?.max(1.0); + Some((loc.spread, b.inflate(glyph + 0.1 * b.width().max(b.height()), glyph))) } #[cfg(test)] From a9f9cbaeb43064c6df7324f9e252d3758cee35b4 Mon Sep 17 00:00:00 2001 From: skylartaylor Date: Fri, 27 Nov 2026 00:59:57 +0100 Subject: [PATCH 5/5] Damage: a turned text frame's glyphs get room in its group --- crates/render/src/damage.rs | 32 +++++++++++++++++++++++++++++--- 1 file changed, 29 insertions(+), 3 deletions(-) diff --git a/crates/render/src/damage.rs b/crates/render/src/damage.rs index e926cc627..0d650ff8b 100644 --- a/crates/render/src/damage.rs +++ b/crates/render/src/damage.rs @@ -174,7 +174,7 @@ fn item_area(it: &Item) -> Option { // and feathers stay inside the shape. let scale = max_scale(it.xf)?; let stroke = it.stroke.extent().max(0.0) * scale; - let pad = stroke + 2.0 + if it.is_text_frame() { GLYPH_OVERHANG * scale } else { 0.0 } + crate::fx::outset_scaled(it, scale); + let pad = stroke + 2.0 + crate::fx::outset_scaled(it, scale); if !pad.is_finite() { return None; } @@ -192,10 +192,12 @@ const GLYPH_OVERHANG: f64 = 24.0; fn painted_bounds(it: &Item) -> Option { let mut b = it.bounds(); if it.is_text_frame() { - b = b.union(it.xf.transform_rect_bbox(it.inner_bounds())); + // The allowance applies in the frame's own axes: a turned frame's ink reaches past its + // turned box's bounding box, which a pad applied after the transform would miss. + b = b.union(it.xf.transform_rect_bbox(it.inner_bounds().inflate(GLYPH_OVERHANG, GLYPH_OVERHANG))); } for c in it.children() { - let pad = (c.stroke.extent().max(0.0) + if c.is_text_frame() { GLYPH_OVERHANG } else { 0.0 }) * max_scale(c.xf)?; + let pad = c.stroke.extent().max(0.0) * max_scale(c.xf)?; b = b.union(it.xf.transform_rect_bbox(painted_bounds(c)?.inflate(pad, pad))); } Some(b) @@ -506,6 +508,30 @@ mod tests { /// group damages them where they were and where they are (#3193). The canvas passes its /// composition cache, which finds the text unchanged by the move, so only the group's own /// area covers its text. + /// A turned text frame inside a group reaches the glyph allowance at its box's corners, which + /// the turn swings outside a pad applied after the child's transform. + #[test] + fn a_turned_text_frame_in_a_group_damages_its_glyph_allowance_corners() { + use designcraft_geom::{Affine, Point}; + let mut d = Document::new(&NewDocument { pages: 1, ..Default::default() }); + let lid = d.default_layer(); + let (f, _) = d.add_text_frame(SpreadRef::Doc(0), Rect::new(100.0, 200.0, 450.0, 400.0), lid, "gjpqy", ParaFormat::default()).unwrap(); + let turned = Affine::translate((150.0, 60.0)) * Affine::rotate(45f64.to_radians()); + d.item_mut(f).unwrap().xf = turned; + let inner = d.item(f).unwrap().inner_bounds(); + let ink = turned.transform_rect_bbox(inner.inflate(GLYPH_OVERHANG, GLYPH_OVERHANG)); + let i = d.spreads[0].items.iter().position(|it| it.id == f).unwrap(); + let frame = Arc::make_mut(&mut d.spreads[0]).items.remove(i); + let gid = ItemId(d.alloc()); + let mut group = Item::new(gid, lid, designcraft_doc::Shape::Group, Default::default()); + group.content = designcraft_doc::Content::Group { items: vec![frame] }; + d.insert_item(SpreadRef::Doc(0), group, None).unwrap(); + let area = item_area(d.item(gid).unwrap()).expect("a group has a damaging area"); + for p in [Point::new(ink.x0, ink.y0), Point::new(ink.x1, ink.y0), Point::new(ink.x0, ink.y1), Point::new(ink.x1, ink.y1)] { + assert!(area.contains(p), "the group's damage misses the glyph allowance at {p:?}"); + } + } + #[test] fn moving_a_group_damages_its_text_below_the_frame() { let mut d = Document::new(&NewDocument { pages: 1, ..Default::default() });