Skip to content

DesignCraft: An open-source page and layout design editor written by scratch in pure Rust

Merge parent-margins: Layout: parent pages pass margins and guides to their pages

aiongga5b8d99164ea
diff --cc ROADMAP.md
index 9076d5400,04b59336d..bc61812ff
--- a/ROADMAP.md
+++ b/ROADMAP.md
@@@ -129,20 -129,7 +129,21 @@@ list) · [roadmap.md](docs/roadmap.md)
Newest first.
+- **2026-10-11** · Japanese captions now cover print ranges, imported style handling and table
+ row/column movement, including row-height distribution. Existing translation and RTL helpers
+ handle the display; command IDs, stored option values and user-defined style names are unchanged.
+- **2026-10-11** · Moving a sheared and rotated text frame no longer leaves trails of text behind: canvas repaints cover the frame's whole text box, not just its outline. No readiness percentage change.
+- **2026-10-11** · Live corners: the yellow widget on a selected rectangle frame shows corner
+ diamonds; dragging one rounds the corners, Alt-click steps the corner shape (#186).
+- **2026-10-11** · Optical kerning (#181): pairs are spaced from their outlines (ink gap per band,
+ pulled towards the font's stem gap, bounded) instead of silently using the font's kern pairs.
+- **2026-10-11** · New Document laid out like InDesign's (#325): Recent, Saved, Print, Web and
+ Mobile preset tabs beside the preset's details; saved document presets live in the engine
+ (`file.savePreset`, `file.deletePreset`, `file.new {preset}`); `file.new` takes intent, units,
+ start page and per-edge bleed and slug.
+- **2026-10-11** · macOS: fonts that font services and managers activate (Adobe Fonts,
+ RightFont) are listed, read from the files CoreText has available (#261, #327).
+ - **2026-10-11:** Document pages take their parent page's margins and columns (left or right parent page by side) and follow its changes unless they have their own; parent ruler guides draw and snap on the pages based on it. IDML import marks a page margin preference that differs from its parent as the page's own. No readiness percentage change.
- **2026-10-10 (UI.4–UI.5):** Panel tabs can move into other groups, split the dock, float, resize and return to their saved locations through shared docking transactions. Layouts persist in custom workspaces; UI and control commands share the same validated action path. Shared pane geometry and widget-state theme application retain all five palettes and local fonts. Split panes send keyboard input only to the focused canvas and scope contextual toolbar IDs per pane. No readiness percentage change.
- **2026-10-10** · Version 0.6.0; releases add a Linux riscv64 tar.gz (cross-compiled, CLI
smoke-tested under QEMU).
diff --cc crates/doc/src/build.rs
index 690a8ad9b,27f668349..7e920e05a
--- a/crates/doc/src/build.rs
+++ b/crates/doc/src/build.rs
@@@ -560,11 -549,70 +564,69 @@@ impl Document
/// Parent page (spread index, page index) to show behind document page `abs`.
pub fn parent_page_for(&self, abs: usize) -> Option<(usize, usize)> {
- let page = self.page(abs)?;
+ self.parent_page_of(self.page(abs)?)
+ }
+
+ /// Parent page (spread index, page index) applied to `page`: the page on its side of its
+ /// parent spread.
+ pub fn parent_page_of(&self, page: &Page) -> Option<(usize, usize)> {
let pi = self.parent_index(page.parent?)?;
- let ps = &self.parents[pi];
// A parent spread can come without pages from a file.
- Some((pi, ps.parent_page_for_side(page.side)?))
- let idx = self.parents.get(pi)?.parent_page_index(page.side)?;
- Some((pi, idx))
++ Some((pi, self.parents.get(pi)?.parent_page_for_side(page.side)?))
+ }
+
+ /// The parent page applied to `page`.
+ pub fn parent_page(&self, page: &Page) -> Option<&Page> {
+ let (pi, qi) = self.parent_page_of(page)?;
+ self.parents.get(pi)?.pages.get(qi)
+ }
+
+ /// Ruler guides `page` shows from its parent page, moved from the parent page's place in its
+ /// spread to `page`'s place in its own. They stay stored on the parent page.
+ pub fn parent_guides<'a>(&'a self, page: &Page) -> impl Iterator<Item = Guide> + 'a {
+ let src = self.parent_page(page);
+ let dx = src.map_or(0.0, |q| page.x - q.x);
+ src.into_iter().flat_map(|q| q.guides.iter()).map(move |g| {
+ let mut g = g.clone();
+ if g.orientation == Orientation::Vertical {
+ g.position += dx;
+ }
+ g
+ })
+ }
+
+ /// Give every document page without local margins its parent page's margins and columns.
+ pub fn sync_parent_margins(&mut self) {
+ for si in 0..self.spreads.len() {
+ for pi in 0..self.spreads[si].pages.len() {
+ let Some(page) = self.spreads[si].pages.get(pi) else { continue };
+ if page.local_margins {
+ continue;
+ }
+ let Some(src) = self.parent_page(page).filter(|q| !q.same_margins(page)).map(|q| (q.margins, q.columns.clone())) else {
+ continue;
+ };
+ if let Some(page) = Arc::make_mut(&mut self.spreads[si]).pages.get_mut(pi) {
+ (page.margins, page.columns) = src;
+ }
+ }
+ }
+ }
+
+ /// Mark document pages whose margins or columns differ from their parent page's as local, so
+ /// that a later sync keeps them (documents saved before pages tracked local margins).
+ pub fn mark_differing_margins_local(&mut self) {
+ for si in 0..self.spreads.len() {
+ for pi in 0..self.spreads[si].pages.len() {
+ let Some(page) = self.spreads[si].pages.get(pi) else { continue };
+ if page.local_margins || self.parent_page(page).is_none_or(|q| q.same_margins(page)) {
+ continue;
+ }
+ if let Some(page) = Arc::make_mut(&mut self.spreads[si]).pages.get_mut(pi) {
+ page.local_margins = true;
+ }
+ }
+ }
}
}
@@@ -598,19 -646,19 +660,32 @@@ mod tests
assert_eq!(d.parent_page_for(1), None);
}
+ /// A single-sided page applying a two-page parent shows the parent's first page.
+ #[test]
+ fn single_sided_page_shows_first_parent_page() {
+ let mut d = Document::new(&NewDocument { pages: 2, facing_pages: false, ..Default::default() });
+ let extra = d.parents[0].pages[0].clone();
+ Arc::make_mut(&mut d.parents[0]).pages.push(extra);
+ assert_eq!(d.parents[0].pages.len(), 2);
+ assert_eq!(d.parent_page_for(0), Some((0, 0)));
+ assert_eq!(d.parent_page_for(1), Some((0, 0)));
+ Arc::make_mut(&mut d.parents[0]).pages.clear();
+ assert_eq!(d.parent_page_for(0), None);
+ }
+
+ /// Files saved before pages tracked local margins: pages that differ from their parent keep
+ /// their margins; the rest follow the parent.
+ #[test]
+ fn differing_margins_from_older_files_stay_local() {
+ let mut d = Document::new(&NewDocument { pages: 2, ..Default::default() });
+ Arc::make_mut(&mut d.spreads[1]).pages[0].margins = Margins::uniform(90.0);
+ d.mark_differing_margins_local();
+ Arc::make_mut(&mut d.parents[0]).pages.iter_mut().for_each(|p| p.margins = Margins::uniform(12.0));
+ d.sync_parent_margins();
+ assert_eq!(d.page(0).map(|p| (p.margins.top, p.local_margins)), Some((12.0, false)));
+ assert_eq!(d.page(1).map(|p| (p.margins.top, p.local_margins)), Some((90.0, true)));
+ }
+
#[test]
fn non_facing_one_page_per_spread() {
let d = Document::new(&NewDocument { pages: 3, facing_pages: false, ..Default::default() });
diff --cc crates/engine/src/cmd/layout.rs
index e53dfd676,aa478d46c..4e69230a2
--- a/crates/engine/src/cmd/layout.rs
+++ b/crates/engine/src/cmd/layout.rs
@@@ -1156,64 -954,56 +1188,118 @@@ mod adjust_tests
}
}
+#[cfg(test)]
+mod spread_rotation_input_tests {
+ use serde_json::json;
+
+ #[test]
+ fn quarter_turns_work_and_other_angles_are_rejected_without_mutation() {
+ let mut s = crate::Session::new();
+ s.execute("file.new", &json!({})).unwrap();
+ let rotation = |s: &crate::Session| s.doc().unwrap().doc.spreads[0].pages[0].view_rotation;
+ for bad in [json!(45), json!(-45), json!(91), json!("90"), json!(0.5)] {
+ assert!(s.execute("layout.rotateSpreadView", &json!({"angle": bad})).is_err(), "{bad}");
+ assert_eq!(rotation(&s), 0, "invalid input must not change the view");
+ }
+ s.execute("layout.rotateSpreadView", &json!({"angle": 90})).unwrap();
+ assert_eq!(rotation(&s), 1);
+ s.execute("layout.rotateSpreadView", &json!({"angle": -90})).unwrap();
+ assert_eq!(rotation(&s), 0);
+ s.execute("layout.rotateSpreadView", &json!({"angle": 180})).unwrap();
+ assert_eq!(rotation(&s), 2);
+ s.execute("layout.rotateSpreadView", &json!({"angle": 0})).unwrap();
+ assert_eq!(rotation(&s), 0, "zero resets the spread view");
+ }
+}
+
+#[cfg(test)]
+mod layer_options_tests {
+ use serde_json::json;
+
+ #[test]
+ fn layer_set_sets_every_field_and_rejects_bad_names() {
+ let mut s = crate::Session::new();
+ s.execute("file.new", &json!({})).unwrap();
+ let first = s.doc().unwrap().doc.layers[0].id.0;
+ let id = s.execute("layer.new", &json!({"name": "Art"})).unwrap()["id"].as_u64().unwrap();
+ let all = json!({"id": id, "name": " Artwork ", "color": "Gold", "visible": false, "locked": true, "printable": false,
+ "showGuides": false, "suppressWrapWhenHidden": true});
+ s.execute("layer.set", &all).unwrap();
+ let l = s.doc().unwrap().doc.layer(designcraft_doc::LayerId(id)).cloned().unwrap();
+ assert_eq!(l.name, "Artwork");
+ assert_eq!(l.color, [255, 153, 0]);
+ assert!(!l.visible && l.locked && !l.printable && !l.show_guides && l.suppress_wrap_when_hidden);
+ s.execute("edit.undo", &json!({})).unwrap();
+ assert_eq!(s.doc().unwrap().doc.layer(designcraft_doc::LayerId(id)).unwrap().name, "Art", "one undo step");
+ let first_name = s.doc().unwrap().doc.layers.iter().find(|l| l.id.0 == first).unwrap().name.clone();
+ let before = s.doc().unwrap().doc.layers.clone();
+ for p in [
+ json!({"id": id, "name": ""}),
+ json!({"id": id, "name": " "}),
+ json!({"id": id, "name": first_name}),
+ json!({"id": id, "name": "Fine", "color": "Plaid"}),
+ json!({"id": id, "color": [300, 0, 0]}),
+ json!({"id": id, "visible": "yes"}),
+ json!({"id": 999_999, "name": "Ghost"}),
+ ] {
+ assert!(s.execute("layer.set", &p).is_err(), "{p}");
+ }
+ assert_eq!(s.doc().unwrap().doc.layers, before);
+ // Keeping its own name is fine.
+ s.execute("layer.set", &json!({"id": id, "name": "Art", "color": [1, 2, 3]})).unwrap();
+ }
+}
++
+ #[cfg(test)]
+ mod parent_margin_tests {
+ use designcraft_doc::{Document, Margins};
+ use serde_json::json;
+
+ use crate::Session;
+
+ fn margins(d: &Document) -> Vec<(Margins, u32, bool)> {
+ (0..d.page_count()).filter_map(|i| d.page(i)).map(|p| (p.margins, p.columns.count, p.local_margins)).collect()
+ }
+
+ #[test]
+ fn pages_follow_their_parent_pages_margins_unless_set_locally() {
+ let mut s = Session::new();
+ // Facing: [1] [2 3]; page 3 gets its own margins.
+ s.execute("file.new", &json!({"pages": 3})).unwrap();
+ s.execute("layout.marginsAndColumns", &json!({"pages": [2], "margins": 100})).unwrap();
+ // A's left page: only the left document page follows.
+ let left = json!({"top": 10, "bottom": 20, "inside": 30, "outside": 40});
+ s.execute("layout.marginsAndColumns", &json!({"parent": "A", "pages": [0], "margins": left, "columns": 2})).unwrap();
+ let l = Margins { top: 10.0, bottom: 20.0, inside: 30.0, outside: 40.0 };
+ let m = margins(&s.doc().unwrap().doc);
+ assert_eq!(m, vec![(Margins::uniform(36.0), 1, false), (l, 2, false), (Margins::uniform(100.0), 1, true)]);
+ // A's right page: page 1 follows, page 3 keeps its own.
+ s.execute("layout.marginsAndColumns", &json!({"parent": "A-Parent", "pages": [1], "margins": 50})).unwrap();
+ let m = margins(&s.doc().unwrap().doc);
+ assert_eq!(m, vec![(Margins::uniform(50.0), 1, false), (l, 2, false), (Margins::uniform(100.0), 1, true)]);
+ // A page inserted after page 1 pushes page 2 to the right: it takes the right parent page's.
+ s.execute("layout.pages.insert", &json!({"after": 0, "count": 1, "parent": "A"})).unwrap();
+ let m = margins(&s.doc().unwrap().doc);
+ assert_eq!(m[1], (l, 2, false), "the new left page");
+ assert_eq!(m[2], (Margins::uniform(50.0), 1, false), "old page 2, now a right page");
+ assert_eq!(m[3], (Margins::uniform(100.0), 1, true));
+ assert!(s.execute("layout.marginsAndColumns", &json!({"parent": "Z", "margins": 10})).is_err());
+ }
+
+ #[test]
+ fn parent_guides_show_on_pages_but_stay_on_the_parent() {
+ let mut s = Session::new();
+ s.execute("file.new", &json!({"pages": 2})).unwrap();
+ // A vertical guide 100 pt into A's right page (x = 612 in the parent spread).
+ s.execute("guide.add", &json!({"spread": {"kind": "parent", "index": 0}, "page": 1, "orientation": "vertical", "position": 712})).unwrap();
+ let d = &s.doc().unwrap().doc;
+ let right = d.page(0).unwrap();
+ let shown: Vec<f64> = d.parent_guides(right).map(|g| g.position).collect();
+ assert_eq!(shown, vec![100.0], "moved to the document page's place");
+ assert_eq!(d.parent_guides(d.page(1).unwrap()).count(), 0, "the left page shows A's left page's guides");
+ // Not the document page's own: not listed, moved or deleted from there.
+ assert_eq!(s.execute("guide.list", &json!({"spread": 0})).unwrap(), json!([]));
+ assert!(s.execute("guide.move", &json!({"spread": 0, "page": 0, "index": 0, "position": 50})).is_err());
+ assert!(s.execute("guide.delete", &json!({"spread": 0, "page": 0, "index": 0})).is_err());
+ }
+ }
diff --cc crates/engine/src/tests_idml.rs
index 6d7c7bf5c,cf3cbc418..5c3364d6d
--- a/crates/engine/src/tests_idml.rs
+++ b/crates/engine/src/tests_idml.rs
@@@ -338,164 -252,21 +338,183 @@@ fn named_lists_round_trip_through_idml(
assert_eq!(st.paras[0].para.start_at, Some(Some(5)));
}
+#[test]
+fn type_para_sets_a_drop_cap_that_survives_idml() {
+ let mut s = Session::new();
+ s.execute("file.new", &json!({})).unwrap();
+ s.execute("style.character.create", &json!({"name": "Initial", "chars": {"fontStyle": "Bold"}})).unwrap();
+ let text = "Once upon a time there was a paragraph long enough to run beside its drop cap for a few lines and then some more.";
+ let r = s.execute("frame.create", &json!({"rect": [72, 72, 300, 400], "content": "text", "text": text})).unwrap();
+ let sid = r["story"].as_u64().unwrap();
+ s.execute("text.select", &json!({"story": sid, "anchor": 3, "focus": 3})).unwrap();
+ s.execute("type.para", &json!({"attrs": {"dropCapLines": 3, "dropCapChars": 1, "dropCapStyle": "Initial", "dropCapAlignLeft": false}})).unwrap();
+ let d = s.doc().unwrap().doc.clone();
+ let cs = designcraft_compose::compose_story(&d, designcraft_doc::StoryId(sid), &Default::default());
+ let lines = &cs.frames[0].lines;
+ let dc = &lines[0].glyphs[0];
+ assert_eq!(dc.byte, 0);
+ assert!((lines[0].baseline + dc.y - lines[2].baseline).abs() < 1e-6, "on line 3's baseline");
+ assert!(lines[0].drop_cap.is_some_and(|b| b.end == 1));
+ let p = &d.story(designcraft_doc::StoryId(sid)).unwrap().paras[0].para;
+ assert_eq!((p.drop_cap_lines, p.drop_cap_chars, p.drop_cap_style.as_deref()), (Some(3), Some(1), Some("Initial")));
+ let back = designcraft_idml::import_idml(&designcraft_idml::export_idml(&d)).unwrap();
+ let p = &back.stories.values().find(|st| st.text.starts_with("Once")).unwrap().paras[0].para;
+ assert_eq!((p.drop_cap_lines, p.drop_cap_chars, p.drop_cap_align_left), (Some(3), Some(1), Some(false)));
+ // The drop cap's character style goes through IDML as a leading Dropcap nested style.
+ assert_eq!(p.drop_cap_style.as_deref(), Some("Initial"));
+ assert_eq!(p.nested_styles, Some(vec![designcraft_doc::NestedStyle::drop_cap("Initial")]));
+}
+
+/// IDML says which page of a placed PDF shows and which box its graphic spans, so InDesign opens
+/// it at the same size and position; importing it back gives the same page, crop and geometry.
+#[test]
+fn placed_pdf_page_and_crop_round_trip_through_idml() {
+ let mut s = Session::new();
+ s.execute("file.new", &json!({"pages": 2})).unwrap();
+ s.execute("layout.documentSetup", &json!({"bleed": 9})).unwrap();
+ let b64 = s.execute("file.exportPdf", &json!({"bleed": true})).unwrap()["base64"].as_str().unwrap().to_string();
+ let mut t = Session::new();
+ t.execute("file.new", &json!({})).unwrap();
+ // Page 2, cropped to its trim box: the frame is smaller than the page with its bleed.
+ let place = json!({"base64": b64, "name": "a.pdf", "pdfPage": 2, "pdfCrop": "trim", "width": 315, "x": 20, "y": 30});
+ let r = t.execute("file.place", &place).unwrap();
+ let d = t.doc().unwrap().doc.clone();
+ let item = d.item(ItemId(r["id"].as_u64().unwrap())).unwrap();
+ let (bounds, g) = (item.bounds(), item.graphic().unwrap().clone());
+ assert_eq!(d.assets[&g.asset].page, 1);
+ assert_eq!(d.assets[&g.asset].pdf_crop, designcraft_doc::PdfCrop::Trim);
+
+ let bytes = designcraft_idml::export_idml(&d);
+ let mut zip = zip::ZipArchive::new(std::io::Cursor::new(bytes.as_slice())).unwrap();
+ let mut spreads = String::new();
+ for i in 0..zip.len() {
+ let mut f = zip.by_index(i).unwrap();
+ if f.name().starts_with("Spreads/") {
+ std::io::Read::read_to_string(&mut f, &mut spreads).unwrap();
+ }
+ }
+ let attr = spreads.split("<PDFAttribute ").nth(1).and_then(|a| a.split("/>").next()).expect("a PDFAttribute");
+ assert!(attr.contains(r#"PageNumber="2""#) && attr.contains(r#"PDFCrop="CropTrim""#), "{attr}");
+ assert!(spreads.contains(r#"<GraphicBounds Left="0" Top="0" Right="612" Bottom="792"/>"#), "the trim box");
+
+ let back = crate::cmd::interchange::import(&bytes, None).unwrap();
+ let bi = back.spreads.iter().flat_map(|sp| sp.items.iter()).find(|i| i.graphic().is_some()).unwrap();
+ let bg = bi.graphic().unwrap();
+ let ba = &back.assets[&bg.asset];
+ assert_eq!((ba.page, ba.pdf_crop), (1, designcraft_doc::PdfCrop::Trim));
+ let (want, got) = (d.assets[&g.asset].shown_box().unwrap(), ba.shown_box().expect("the trim box found on the page"));
+ assert!(want.iter().zip(got).all(|(a, b)| (a - b).abs() < 1e-9), "{got:?} vs {want:?}");
+ let bb = bi.bounds();
+ assert!([bb.x0 - bounds.x0, bb.y0 - bounds.y0, bb.x1 - bounds.x1, bb.y1 - bounds.y1].iter().all(|v| v.abs() < 1e-3), "{bb:?} vs {bounds:?}");
+ assert!((bg.size.0 - g.size.0).abs() < 1e-3 && (bg.size.1 - g.size.1).abs() < 1e-3);
+ let (a, b) = ((bi.xf * bg.xf).as_coeffs(), (item.xf * g.xf).as_coeffs());
+ assert!(a.iter().zip(b).all(|(x, y)| (x - y).abs() < 1e-3), "{a:?} vs {b:?}");
+
+ // A page the PDF doesn't have imports, and the PDF export leaves it out with a warning.
+ let mut zip = zip::ZipArchive::new(std::io::Cursor::new(bytes.as_slice())).unwrap();
+ let mut out = zip::ZipWriter::new(std::io::Cursor::new(Vec::new()));
+ for i in 0..zip.len() {
+ let mut f = zip.by_index(i).unwrap();
+ let mut body = String::new();
+ std::io::Read::read_to_string(&mut f, &mut body).unwrap();
+ out.start_file(f.name(), zip::write::SimpleFileOptions::default()).unwrap();
+ std::io::Write::write_all(&mut out, body.replace(r#"PageNumber="2""#, r#"PageNumber="4294967295""#).as_bytes()).unwrap();
+ }
+ let hostile = designcraft_idml::import_idml(&out.finish().unwrap().into_inner()).unwrap();
+ assert_eq!(hostile.assets.values().map(|a| a.page).collect::<Vec<_>>(), [u32::MAX - 1]);
+ t.edit(|doc, _| {
+ *doc = hostile;
+ Ok(())
+ })
+ .unwrap();
+ let r = t.execute("file.exportPdf", &json!({})).unwrap();
+ assert!(r["warnings"].to_string().contains("has no page 4294967295"), "{r}");
+}
+
+/// An IDML placed PDF cropped to its media box, without `GraphicBounds`: the graphic takes the
+/// media box (the page with its 9 pt bleed).
+#[test]
+fn idml_placed_pdf_cropped_to_its_media_box_gets_media_box_bounds() {
+ let mut s = Session::new();
+ s.execute("file.new", &json!({})).unwrap();
+ s.execute("layout.documentSetup", &json!({"bleed": 9})).unwrap();
+ let b64 = s.execute("file.exportPdf", &json!({"bleed": true})).unwrap()["base64"].as_str().unwrap().to_string();
+ let mut t = Session::new();
+ t.execute("file.new", &json!({})).unwrap();
+ t.execute("file.place", &json!({"base64": b64, "name": "a.pdf", "pdfCrop": "trim", "width": 630, "x": 0, "y": 0})).unwrap();
+ let bytes = designcraft_idml::export_idml(&t.doc().unwrap().doc);
+
+ let mut zip = zip::ZipArchive::new(std::io::Cursor::new(bytes.as_slice())).unwrap();
+ let mut out = zip::ZipWriter::new(std::io::Cursor::new(Vec::new()));
+ let mut edited = false;
+ for i in 0..zip.len() {
+ let mut f = zip.by_index(i).unwrap();
+ let mut body = Vec::new();
+ std::io::Read::read_to_end(&mut f, &mut body).unwrap();
+ if f.name().starts_with("Spreads/") {
+ let text = String::from_utf8(body).unwrap().replace(r#"PDFCrop="CropTrim""#, r#"PDFCrop="CropMedia""#);
+ let start = text.find("<GraphicBounds ").unwrap();
+ let end = start + text[start..].find("/>").unwrap() + 2;
+ body = format!("{}{}", &text[..start], &text[end..]).into_bytes();
+ edited = true;
+ }
+ out.start_file(f.name(), zip::write::SimpleFileOptions::default()).unwrap();
+ std::io::Write::write_all(&mut out, &body).unwrap();
+ }
+ assert!(edited);
+ let back = crate::cmd::interchange::import(&out.finish().unwrap().into_inner(), None).unwrap();
+ let g = back.spreads.iter().flat_map(|sp| sp.items.iter()).find_map(|i| i.graphic().cloned()).unwrap();
+ let a = &back.assets[&g.asset];
+ assert_eq!(a.pdf_crop, designcraft_doc::PdfCrop::Media);
+ assert!((g.size.0 - 630.0).abs() < 1e-3 && (g.size.1 - 810.0).abs() < 1e-3, "{:?}", g.size);
+ let b = a.shown_box().unwrap_or([0.0, 0.0, 1.0, 1.0]);
+ assert!(b.iter().zip([0.0, 0.0, 1.0, 1.0]).all(|(x, y)| (x - y).abs() < 1e-6), "{b:?}");
+}
+
+/// A Bounding Box crop needs the page rendered to find its box. IDML import leaves that until
+/// the graphic is drawn or exported (its `GraphicBounds` give its size), so opening a document
+/// doesn't render every placed PDF; drawing and PDF export find the same box placing it did.
+#[test]
+fn idml_bounding_box_crop_is_measured_when_drawn_not_on_import() {
+ let mut s = Session::new();
+ s.execute("file.new", &json!({})).unwrap();
+ s.execute("frame.create", &json!({"rect": [100, 200, 300, 260], "content": "unassigned"})).unwrap();
+ s.execute("object.fill", &json!({"swatch": "[Black]"})).unwrap();
+ let b64 = s.execute("file.exportPdf", &json!({})).unwrap()["base64"].as_str().unwrap().to_string();
+ let mut t = Session::new();
+ t.execute("file.new", &json!({})).unwrap();
+ t.execute("file.place", &json!({"base64": b64, "name": "a.pdf", "pdfCrop": "contentVisible", "width": 200, "x": 20, "y": 30})).unwrap();
+ let placed = t.doc().unwrap().doc.assets.values().next().unwrap().shown_box().expect("placing measures the box");
+ assert!(placed[0] > 0.1 && placed[2] < 0.6, "the drawn rectangle, not the page: {placed:?}");
+
+ let bytes = designcraft_idml::export_idml(&t.doc().unwrap().doc);
+ let back = crate::cmd::interchange::import(&bytes, None).unwrap();
+ let a = back.assets.values().next().unwrap();
+ assert_eq!(a.pdf_crop, designcraft_doc::PdfCrop::ContentVisible);
+ assert!(a.content_box_pending(), "import didn't render the page: {:?}", a.pdf_box);
+ let close = |b: [f64; 4]| b.iter().zip(placed).all(|(x, y)| (x - y).abs() < 1e-9);
+ let drawn = designcraft_render::shown_box(a).expect("drawing measures the box");
+ assert!(close(drawn), "{drawn:?} vs {placed:?}");
+ let boxed = crate::cmd::interchange::with_pdf_boxes(&back);
+ let exported = boxed.assets.values().next().unwrap().shown_box().expect("PDF export gets the box");
+ assert!(close(exported), "{exported:?} vs {placed:?}");
+}
++
+ #[test]
+ fn parent_and_page_margins_round_trip_through_idml() {
+ let mut s = Session::new();
+ s.execute("file.new", &json!({"pages": 3})).unwrap();
+ s.execute("layout.marginsAndColumns", &json!({"parent": "A", "margins": 48, "columns": 2})).unwrap();
+ s.execute("layout.marginsAndColumns", &json!({"pages": [2], "margins": 100})).unwrap();
+ let back = designcraft_idml::import_idml(&designcraft_idml::export_idml(&s.doc().unwrap().doc)).unwrap();
+ let pages: Vec<(f64, u32, bool)> =
+ (0..back.page_count()).filter_map(|i| back.page(i)).map(|p| (p.margins.top, p.columns.count, p.local_margins)).collect();
+ assert_eq!(pages, vec![(48.0, 2, false), (48.0, 2, false), (100.0, 2, true)]);
+ assert!(back.parents[0].pages.iter().all(|p| p.margins.top == 48.0 && p.columns.count == 2));
+ // The imported pages still follow their parent.
+ let mut d = back;
+ std::sync::Arc::make_mut(&mut d.parents[0]).pages[1].margins.top = 60.0;
+ d.sync_parent_margins();
+ assert_eq!(d.page(0).unwrap().margins.top, 60.0);
+ assert_eq!(d.page(2).unwrap().margins.top, 100.0);
+ }
diff --cc crates/format/src/lib.rs
index 628ce7c5c,7a5b01957..1c2ff3575
--- a/crates/format/src/lib.rs
+++ b/crates/format/src/lib.rs
@@@ -122,20 -104,10 +122,21 @@@ fn load_zip(bytes: &[u8]) -> Result<Doc
let Some(stem) = name.strip_prefix("assets/") else { continue };
let Some(id) = stem.split('.').next().and_then(|s| s.parse::<u64>().ok()) else { continue };
if let (Some(data), Some(a)) = (read(&mut z, &name), doc.assets.get_mut(&AssetId(id))) {
- Arc::make_mut(a).data = Arc::new(data);
+ let same = loaded.entry(data.len()).or_default();
+ let data = match same.iter().find(|d| ***d == data) {
+ Some(d) => d.clone(),
+ None => {
+ let d = Arc::new(data);
+ same.push(d.clone());
+ d
+ }
+ };
+ Arc::make_mut(a).data = data;
}
}
+ upgrade(&mut doc, version);
+ doc.merge_duplicate_assets();
+ doc.mark_differing_margins_local();
doc.check().map_err(|e| FormatError::NotOurs(e.to_string()))?;
Ok(doc)
}
@@@ -200,8 -125,7 +201,9 @@@ fn load_legacy_json(bytes: &[u8]) -> Re
}
}
}
+ upgrade(&mut doc, 1);
+ doc.merge_duplicate_assets();
+ doc.mark_differing_margins_local();
doc.check().map_err(|e| FormatError::NotOurs(e.to_string()))?;
Ok(doc)
}
diff --cc crates/idml/src/import.rs
index f2a0c60ac,c79c2e9de..b695426bb
--- a/crates/idml/src/import.rs
+++ b/crates/idml/src/import.rs
@@@ -2213,6 -1860,22 +2209,22 @@@ impl<'r> Importer<'r>
PageSide::Right
};
let parent = p.get("AppliedMaster").and_then(|m| self.parent_ids.get(m)).copied();
+ // A document page's margins are local when they differ from its parent page's; a
+ // page without its own takes the parent page's.
+ let from_parent = if master {
+ None
+ } else {
+ parent
+ .and_then(|id| self.parents.iter().find(|sp| sp.id == id))
- .and_then(|sp| sp.pages.get(sp.parent_page_index(side)?))
++ .and_then(|sp| sp.pages.get(sp.parent_page_for_side(side)?))
+ .map(|q| (q.margins, q.columns.clone()))
+ };
+ let (margins, columns) = match (p.find("MarginPreference"), &from_parent) {
+ (Some(m), _) => margins_of(m),
+ (None, Some(own)) => own.clone(),
+ (None, None) => self.default_margins.clone().unwrap_or((Margins::uniform(36.0), Columns::default())),
+ };
+ let local_margins = from_parent.is_some_and(|(m, c)| m != margins || c != columns);
out_pages.push(Page {
id: pid,
width: r.width(),
diff --cc docs/target-app-parity.md
index 156600f4b,66b5c0150..6a4ae8fa6
--- a/docs/target-app-parity.md
+++ b/docs/target-app-parity.md
@@@ -371,7 -369,7 +371,7 @@@ It is evidence of breadth: each item ex
- Preferences: Dictionary (user dictionary; `spelling.setWords/words`), Spelling (Dynamic Spelling: red squiggles on the canvas, also Edit ▸ Spelling), Autocorrect (word list, applied as you type), Notes, Track Changes, Story Editor Display and File Handling (recovery interval) sections.
- Colour management exposed: Edit ▸ Color Settings (`color.settings`: RGB/CMYK working spaces, intent, black-point compensation; `color.loadProfile` for ICC files; `color.convert` through the working spaces, with gamut checks) and View ▸ Proof Setup / Proof Colors (press, sRGB, legacy Mac RGB, colour-blindness simulations, simulate paper) on the canvas.
- Keyboard: Tab / Shift+Tab hide and show all panels / all but Tools (`window.hidePanels`, `window.hidePanelsExceptTools`); Cmd+F6 / Cmd+Shift+F6 cycle documents; panel fields are reached with Tab and Escape returns to the layout.
- - Smart guides and snapping (View ▸ Snap to Guides / Snap to Document Grid / Smart Guides, `view.snapPreferences` and Preferences ▸ Guides & Pasteboard): moving, drawing, resizing, rotating and pen/anchor drags snap in order to the document grid, ruler guides, margins and columns, other objects' edges and centres (parent-page items too, by visible stroked bounds), equal spacing (centred between two neighbours too), matching dimensions, the baseline grid and matching rotation, with guides, gap marks and measurements drawn on the canvas. Shift and Cmd constrain the gesture.
-- Smart guides and snapping (View ▸ Snap to Guides / Snap to Document Grid / Smart Guides, `view.snapPreferences` and Preferences ▸ Guides & Pasteboard): moving, drawing, resizing, rotating and pen/anchor drags snap in order to the document and baseline grids, ruler guides (a page's own and its parent page's), margins and columns, other objects' edges and centres (parent-page items too, by visible stroked bounds), equal spacing, matching dimensions and matching rotation, with guides, gap marks and measurements drawn on the canvas. Shift and Cmd constrain the gesture.
++- Smart guides and snapping (View ▸ Snap to Guides / Snap to Document Grid / Smart Guides, `view.snapPreferences` and Preferences ▸ Guides & Pasteboard): moving, drawing, resizing, rotating and pen/anchor drags snap in order to the document grid, ruler guides (a page's own and its parent page's), margins and columns, other objects' edges and centres (parent-page items too, by visible stroked bounds), equal spacing (centred between two neighbours too), matching dimensions, the baseline grid and matching rotation, with guides, gap marks and measurements drawn on the canvas. Shift and Cmd constrain the gesture.
- View ▸ Rotate Spread (`view.rotateSpread`, `layout.rotateSpreadView`): the spread in view turns in quarter turns on screen (stored with the document; output is unaffected). The canvas maps each spread through its own transform, so tools, snapping, resize handles, guides, overlays and rendering all follow the turned spread.
- Vertical type (Vertical Type Tool, Type ▸ Story Direction `type.storyDirection`, IDML StoryOrientation): the direction belongs to the story, so every frame of a thread is vertical or horizontal together and a frame threaded onto a story takes its direction (`object.textFrameOptions {vertical}` sets the frames' stories); lines run top to bottom and follow each other right to left; the arrow keys follow them (Down and Up along the line, Left and Right to the next and previous line, keeping the position along it); CJK characters stay upright and other text turns, on screen and in PDF; CJK line breaking with basic kinsoku (also in horizontal text); Korean breaks at spaces, word by word (Hangul in any language, hanja in Korean text), or between syllables when the paragraph asks for it (`type.para {koreanCharBreaks}`, Paragraph Style Options ▸ Justification; not written to IDML). Upright text is shaped top to bottom: punctuation and brackets take their vertical forms (OpenType `vert`; `vkrn` and `vpal` through OpenType features), glyphs advance by their vertical metrics (`vmtx`) and hang from their vertical origins (`VORG`) on the centre of the ideographic em box (`BASE`, else OS/2), which the first line's ascent follows; turned text keeps its horizontal forms. Tate-chu-yoko (Type ▸ Tate-Chu-Yoko, `type.tateChuYoko`, IDML `Tatechuyoko`) sets a run such as "12" side by side within one em of the line. Ruby (Type ▸ Ruby…, `type.ruby`, IDML RubyString; group ruby spread 1-2-1 or centred) and kenten emphasis dots (`type.kenten`, IDML KentenKind) are set over their text — to its right in vertical frames — without changing line breaks. Warichu and ruby options (per-character ruby, positions, overhang) aren't there yet.
- Math expressions (Type ▸ Insert Math Expression…, `math.insert`, `math.svg`): a LaTeX subset (fractions, scripts, roots, big operators with limits, Greek, relations and operators with math spacing, `\left…\right`, `\text`) typeset by our own engine into SVG, placed inline at the cursor or as a frame; the LaTeX is kept as alt text and can be edited.