Integration: exported ruler guides are measured from the exported ruler origin

next writes the document's ruler origin (Spread, Page or Spine) to IDML; main
measured guide locations from the spread's left edge, as for SpreadOrigin only.
A page-origin document's guides came back one page width to the right. The
round-trip test covers all three origins.
This commit is contained in:
aiongg
2026-10-16 03:37:26 +00:00
parent 02a0023edc
commit f419fa2a7a
2 changed files with 19 additions and 7 deletions
+10 -2
View File
@@ -1819,15 +1819,23 @@ impl<'a> Ex<'a> {
.attr("ItemTransform", format!("1 0 0 1 {} {}", num(pg.x - ox), num(-oy)))
.child(margin_el(pg));
let mut pe = pe;
// Ruler guides, measured from the spread's top left (RulerOrigin is SpreadOrigin).
// Ruler guides, measured from the ruler origin written in the preferences: the
// spread's top left, the page's, or the spine (the import reads them the same way).
let left = sp.pages.iter().map(|p| p.x).fold(f64::INFINITY, f64::min);
let left = if left.is_finite() { left } else { 0.0 };
let spine = sp.pages.iter().map(|p| p.x - left).filter(|x| *x > 1e-6).fold(f64::INFINITY, f64::min);
let spine = if spine.is_finite() && facing { spine } else { 0.0 };
let origin_x = match d.settings.ruler_origin {
designcraft_doc::RulerOrigin::Spread => left,
designcraft_doc::RulerOrigin::Page => pg.x,
designcraft_doc::RulerOrigin::Spine => left + spine,
};
for g in &pg.guides {
let vertical = g.orientation == designcraft_doc::Orientation::Vertical;
let mut ge = El::new("Guide")
.attr("Self", format!("{}g{}", uid(pg.id.0), pe.elements().count()))
.attr("Orientation", if vertical { "Vertical" } else { "Horizontal" })
.attr("Location", num(if vertical { g.position - left } else { g.position }))
.attr("Location", num(if vertical { g.position - origin_x } else { g.position }))
.attr("FitToPage", bool_s(!g.spread))
.attr("ViewThreshold", "5")
.attr("Locked", bool_s(g.locked))
+9 -5
View File
@@ -3838,11 +3838,15 @@ fn ruler_guides_import_and_round_trip() {
assert_eq!(guides(&d)[0].1, 40.0);
assert_eq!(d.parents[0].pages[0].guides.len(), 1, "a parent page's guide");
assert_eq!(d.parents[0].pages[0].guides[0].position, 84.0);
// Round trip: written under each page, read back where they were.
let d = import_idml(&guides_package("PageOrigin")).unwrap();
let back = import_idml(&export_idml(&d)).unwrap();
assert_eq!(guides(&back), guides(&d));
assert_eq!(back.parents[0].pages[0].guides.len(), 1);
// Round trip: written under each page from the document's ruler origin, read back where
// they were.
for origin in ["PageOrigin", "SpineOrigin", "SpreadOrigin"] {
let d = import_idml(&guides_package(origin)).unwrap();
let back = import_idml(&export_idml(&d)).unwrap();
assert_eq!(guides(&back), guides(&d), "{origin}");
assert_eq!(back.parents[0].pages[0].guides.len(), 1);
assert_eq!(back.parents[0].pages[0].guides[0].position, d.parents[0].pages[0].guides[0].position, "{origin}");
}
}
/// A package entry nothing in `designmap.xml` refers to is never decompressed: a damaged one