Merge pull request #1614 from MarekSpodBiedry/issue-1577

Align towards/away from spine on parent-page folios by page side (#1577)
This commit is contained in:
Brandon Thomas
2026-10-23 17:26:50 -04:00
committed by GitHub
2 changed files with 18 additions and 3 deletions
+5 -3
View File
@@ -679,10 +679,12 @@ pub fn frame_specs(doc: &Document, sid: StoryId) -> Vec<FrameSpec> {
let abs = doc.first_page_of_spread(si) + pi;
(Some(doc.page_name(abs)), Some(abs), sp.pages.get(pi).is_some_and(|p| p.side == designcraft_doc::PageSide::Left))
}
(Some(designcraft_doc::SpreadRef::Parent(pi)), Some(sp)) => {
(Some(designcraft_doc::SpreadRef::Parent(_)), Some(sp)) => {
let prefix = sp.parent.as_ref().map(|p| p.prefix.clone()).unwrap_or_else(|| "A".into());
let _ = pi;
(Some(prefix), None, false)
// The side of the parent page under the frame, so a folio there aligns to the spine of its own page.
let under = sp.page_at_x(item.bounds().center().x).and_then(|pi| sp.pages.get(pi));
let left = under.is_some_and(|p| p.side == designcraft_doc::PageSide::Left);
(Some(prefix), None, left)
}
_ => (None, None, false),
};
+13
View File
@@ -7310,3 +7310,16 @@ fn rule_above_offset_is_measured_from_the_baseline() {
assert!((rule.height() - 1.5).abs() < 1e-6);
assert!(rule.y0 > first.baseline, "the rule stays below the row above: {rule:?}, its baseline {}", first.baseline);
}
#[test]
fn parent_page_frames_know_which_side_of_the_spine_they_are_on() {
// Folios on a facing-pages parent: towards/away from spine must differ between its left and right page.
let mut d = Document::new(&NewDocument::default());
let lid = d.default_layer();
let w = d.parents[0].pages[0].width;
let para = ParaFormat { para: ParaAttrs { align: Some(Align::TowardsSpine), ..Default::default() }, ..Default::default() };
let (_, left_story) = d.add_text_frame(SpreadRef::Parent(0), Rect::new(36.0, 700.0, w - 36.0, 730.0), lid, "7", para.clone()).unwrap();
let (_, right_story) = d.add_text_frame(SpreadRef::Parent(0), Rect::new(w + 36.0, 700.0, 2.0 * w - 36.0, 730.0), lid, "8", para).unwrap();
assert!(frame_specs(&d, left_story)[0].left_page);
assert!(!frame_specs(&d, right_story)[0].left_page);
}