DesignCraft: An open-source page and layout design editor written by scratch in pure Rust
Inline objects paint under their frame's text
Claudeafc6d31764ec
diff --git a/ROADMAP.md b/ROADMAP.mdindex 9bd0274ef..a26f9e84b 100644--- a/ROADMAP.md+++ b/ROADMAP.md@@ -348,6 +348,7 @@ list) · [roadmap.md](docs/roadmap.md) (milestones, plan) · [parity-checklist.mNewest first.+- **2026-10-17** · Inline and anchored objects paint under their frame's text, on screen and in PDF, as InDesign draws them: a picture whose frame reaches into the next line (a negative Y offset) no longer hides the top of that line. No readiness percentage change.- **2026-10-16** · Threading: the loaded text cursor threads into a text frame inside a group (it hit the group and showed it could not thread); a plain click still selects the group (#1075). Gap 27 closed. No readiness percentage change.- **2026-10-16** · Greek text hyphenates. The patterns were never compiled in, so Greek set unhyphenated however narrow the column; `"Greek"`, `"Greek: Greece"`, `el` and `el-GR` all resolve now and ανθρωπος breaks αν-θρω-πος. They are the monotonic patterns (hyph-el-monoton, Dimitrios Filippou, under MIT), which is what polytonic text hyphenates by too. Five of InDesign's ~40 hyphenation languages. No readiness percentage change.- **2026-10-16** · A swatch applied to a placed greyscale or bitmap image colours it, as in InDesign: IDML's `<Image FillColor>` is read and written, greyscale pixels become a tint of the swatch on opaque white and a bitmap's white lets the frame show through, on screen and in PDF (spot swatches print on their plate). Colour images keep their colours. Applying the swatch from the Swatches panel comes next. No readiness percentage change.diff --git a/crates/pdf/src/export.rs b/crates/pdf/src/export.rsindex 3afe22015..54f252b25 100644--- a/crates/pdf/src/export.rs+++ b/crates/pdf/src/export.rs@@ -965,7 +965,8 @@ impl Exporter<'_> {if frame_art {s.end_tagged();}- // Content.+ // Content. A text frame's anchored objects are drawn under its text when it can be.+ let mut drawn = false;match &it.content {Content::Graphic(g) => {let g = &if it.media.is_some() { it.drawn_graphic(&self.doc.assets).unwrap_or_else(|| g.clone()) } else { g.clone() };@@ -996,7 +997,7 @@ impl Exporter<'_> {s.push_transform(&tf(local));}self.text_area = (local.determinant().abs() > 1e-12).then(|| local.inverse().transform_rect_bbox(it.inner_bounds()));- self.frame_text(s, &cs, ft, text);+ drawn = self.frame_text(s, &cs, ft, text, Some((xf * local, page)));self.text_area = None;if local != Affine::IDENTITY {s.pop();@@ -1021,7 +1022,9 @@ impl Exporter<'_> {for _ in 0..pushes {s.pop();}- if let Content::Text(tfr) = &it.content {+ if let Content::Text(tfr) = &it.content+ && !drawn+ {let cs = self.cache.get(doc, tfr.story, page);if let Some(ft) = cs.frame(it.id) {self.frame_objects(s, ft, xf * doc.text_local(it), page);@@ -1031,7 +1034,7 @@ impl Exporter<'_> {/// Draw embedded page items after restoring the surface, retaining spread-space/// transforms for page culling (also for anonymous note and cell stories).- fn frame_objects(&mut self, s: &mut Surface, ft: &designcraft_compose::FrameText, xf: Affine, page: Option<usize>) {+ pub(crate) fn frame_objects(&mut self, s: &mut Surface, ft: &designcraft_compose::FrameText, xf: Affine, page: Option<usize>) {let mut pending = vec![(ft, xf)];while let Some((frame, transform)) = pending.pop() {for object in &frame.objects {diff --git a/crates/pdf/src/tests.rs b/crates/pdf/src/tests.rsindex ed6a1ac1f..f72903cbf 100644--- a/crates/pdf/src/tests.rs+++ b/crates/pdf/src/tests.rs@@ -819,3 +819,24 @@ fn a_swatch_colours_a_greyscale_image() {let (s, _) = export(&rgb, Some("PANTONE Test"));assert!(!s.contains("PANTONE#20Test"), "a colour image keeps its colours");}++/// An inline object is painted under its frame's text, as InDesign draws it: a picture whose+/// frame reaches down into the next line (a negative Y offset) doesn't hide that line.+#[test]+fn inline_objects_are_painted_under_the_text() {+ use designcraft_doc::{AnchorPosition, AnchoredObject};+ let mut d = doc_with_text("A\nWWWW");+ let sid = *d.stories.keys().next().unwrap();+ let mut item = Item::new(+ ItemId(d.alloc()),+ d.default_layer(),+ designcraft_doc::Shape::Rectangle,+ designcraft_geom::shapes::rectangle(Rect::new(0.0, 0.0, 200.0, 30.0)),+ );+ item.fill = Fill::swatch(designcraft_color::swatch::BLACK);+ d.story_mut(sid).unwrap().insert_object(1, AnchoredObject::new(item, AnchorPosition::Inline { y_offset: -20.0 }));+ let order = paint_order(&export_pdf(&d, &Cache::new(), &PdfOptions::default()).unwrap());+ let first_text = order.iter().position(|(op, _)| op.ends_with("text")).unwrap();+ let the_box = order.iter().position(|(op, _)| op == "fill path").unwrap();+ assert!(the_box < first_text, "{order:?}");+}diff --git a/crates/pdf/src/text.rs b/crates/pdf/src/text.rsindex 300a47d93..f059bb605 100644--- a/crates/pdf/src/text.rs+++ b/crates/pdf/src/text.rs@@ -233,7 +233,17 @@ impl Exporter<'_> {}}- pub(crate) fn frame_text(&mut self, s: &mut Surface, cs: &ComposedStory, ft: &FrameText, story: &str) {+ /// The frame's text. With `objects` (the frame text space → page transform and the page),+ /// the frame's anchored objects are drawn too, over its paragraph shading and under its text;+ /// returns whether they were.+ pub(crate) fn frame_text(+ &mut self,+ s: &mut Surface,+ cs: &ComposedStory,+ ft: &FrameText,+ story: &str,+ objects: Option<(Affine, Option<usize>)>,+ ) -> bool {// Paragraph shading and rules under the text.self.as_artifact(s, |me, s| {for d in ft.decos.iter().filter(|d| !d.nonprinting) {@@ -248,6 +258,17 @@ impl Exporter<'_> {me.tables(s, ft);}});+ // Anchored objects under the text (as InDesign draws them): a picture whose frame reaches+ // into the next line doesn't hide that line. Objects keep their page-space transforms.+ let drawn = match objects {+ Some((xf, page)) if xf.determinant().abs() > 1e-12 => {+ s.push_transform(&tf(xf.inverse()));+ self.frame_objects(s, ft, xf, page);+ s.pop();+ true+ }+ _ => false,+ };// All underlines precede all glyph runs, including ink overlapping from another run.let underlines = text_rules(cs, ft, true);if !underlines.is_empty() {@@ -295,12 +316,13 @@ impl Exporter<'_> {if let Some(nft) = n.text.frames.first() {s.push_transform(&tf(Affine::translate(n.origin.to_vec2())));let area = std::mem::replace(&mut me.text_area, lines_area(nft));- me.frame_text(s, &n.text, nft, &n.source);+ me.frame_text(s, &n.text, nft, &n.source, None);me.text_area = area;s.pop();}}});+ drawn}/// Table fragments: cell fills, cell text (real text), edges and the border.@@ -325,7 +347,7 @@ impl Exporter<'_> {} else if let Some(cft) = c.text.frames.first() {s.push_transform(&tf(Affine::translate(c.origin.to_vec2())));let area = std::mem::replace(&mut self.text_area, lines_area(cft));- self.frame_text(s, &c.text, cft, &c.source);+ self.frame_text(s, &c.text, cft, &c.source, None);self.text_area = area;s.pop();}diff --git a/crates/render/src/lib.rs b/crates/render/src/lib.rsindex c42d8c897..86ae9c65b 100644--- a/crates/render/src/lib.rs+++ b/crates/render/src/lib.rs@@ -1503,6 +1503,32 @@ mod tests {assert!(image_size(corrupt).is_none());}+ /// An inline object is painted under its frame's text, as InDesign draws it: a picture+ /// whose frame reaches down into the next line (a negative Y offset) doesn't hide that line.+ #[test]+ fn inline_objects_are_painted_under_the_text() {+ use designcraft_doc::{AnchorPosition, AnchoredObject, ItemId, Shape, SpreadRef};+ let mut d = Document::new(&NewDocument::default());+ let (fid, sid) =+ d.add_text_frame(SpreadRef::Doc(0), Rect::new(20.0, 20.0, 300.0, 300.0), d.default_layer(), "A\nWWWW", ParaFormat::default()).unwrap();+ let mut item =+ Item::new(ItemId(d.alloc()), d.default_layer(), Shape::Rectangle, designcraft_geom::shapes::rectangle(Rect::new(0.0, 0.0, 250.0, 60.0)));+ item.fill = Fill::swatch(designcraft_color::swatch::PAPER);+ d.story_mut(sid).unwrap().insert_object(1, AnchoredObject::new(item, AnchorPosition::Inline { y_offset: -40.0 }));+ let cache = Cache::new();+ let cs = cache.get(&d, sid, None);+ let (ft, obj) = (&cs.frames[0], &cs.frames[0].objects[0]);+ let l = ft.lines.iter().find(|l| l.range.start > 1).unwrap();+ // The second line lies inside the white box.+ assert!(obj.origin.y + obj.size.1 > l.baseline && obj.origin.y < l.baseline - l.ascent, "{:?} {}", obj.origin, l.baseline);+ let m = d.text_xf(d.item(fid).unwrap());+ let image = Renderer::new().render_page(&d, &cache, 0, 1.0, false, &RenderOptions::default()).unwrap();+ let (a, b) = (m * designcraft_geom::Point::new(l.x0, l.baseline - l.ascent), m * designcraft_geom::Point::new(l.end_x, l.baseline));+ let dark =+ (a.y as u32..b.y as u32).flat_map(|y| (a.x as u32..b.x as u32).map(move |x| (x, y))).filter(|&(x, y)| image.pixel(x, y)[0] < 100).count();+ assert!(dark > 20, "the line's glyphs show over the box: {dark} dark pixels");+ }+#[test]fn footnote_vector_objects_are_painted() {use designcraft_doc::{AnchorPosition, AnchoredObject, ItemId, Shape, SpreadRef};diff --git a/crates/render/src/text.rs b/crates/render/src/text.rsindex 70f31b4f6..a40e666ab 100644--- a/crates/render/src/text.rs+++ b/crates/render/src/text.rs@@ -267,6 +267,11 @@ impl Renderer {if !ft.tables.is_empty() {self.draw_tables(ctx, f, ft, xf);}+ // Anchored objects ride on their lines, under the frame's text (as InDesign draws them):+ // a picture whose frame reaches into the next line doesn't hide that line.+ for o in &ft.objects {+ self.draw_item(ctx, f, &o.object.item, xf * Affine::translate(o.origin.to_vec2()), ShownOn::Own);+ }// Text in fonts that aren't installed: pink behind the glyphs (screen only).if f.opts.highlight_missing_fonts && cs.styles.iter().any(|s| s.missing_font) {ctx.set_transform(m);@@ -448,10 +453,6 @@ impl Renderer {self.draw_text(ctx, f, &n.text, nft, xf * Affine::translate(n.origin.to_vec2()));}}- // Anchored objects ride on their lines.- for o in &ft.objects {- self.draw_item(ctx, f, &o.object.item, xf * Affine::translate(o.origin.to_vec2()), ShownOn::Own);- }}}