DesignCraft: An open-source page and layout design editor written by scratch in pure Rust
Running headers read a page in text order, not by height
Claude34632c0b153c
diff --git a/ROADMAP.md b/ROADMAP.mdindex 9bd0274ef..a982e1326 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** · Running headers: *first/last on page* read a page in text order (story order, then column by column), not by height — a multi-column page's right header showed the lowest entry of column 1 instead of the page's last entry. 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/compose/src/vars.rs b/crates/compose/src/vars.rsindex 945d8bd04..b633d7a8f 100644--- a/crates/compose/src/vars.rs+++ b/crates/compose/src/vars.rs@@ -53,6 +53,30 @@ pub(crate) fn place(doc: &Document, cs: &ComposedStory, pos: usize) -> Option<(uSome((doc.first_page_of_spread(si) + pi, ((b.y0 + baseline) * 10.0) as i64, ((b.x0 + x) * 10.0) as i64))}+/// A paragraph or run a running header may show: where it starts ([`place`]), its story and byte+/// there, and its text.+struct Hit {+ at: (usize, i64, i64),+ story: StoryId,+ pos: usize,+ text: String,+}++/// (page, text) in the order running headers read a page: text order within a story (a story's+/// second column comes after its first, however high its entries sit), and stories by where their+/// first entry on the page is (top to bottom, then left to right).+fn in_page_order(hits: Vec<Hit>) -> Vec<(usize, String)> {+ let mut first: HashMap<(usize, StoryId), (i64, i64)> = HashMap::new();+ for h in &hits {+ let (page, y, x) = h.at;+ first.entry((page, h.story)).and_modify(|f| *f = (*f).min((y, x))).or_insert((y, x));+ }+ let mut hits: Vec<_> =+ hits.into_iter().map(|h| (h.at.0, first.get(&(h.at.0, h.story)).copied().unwrap_or((h.at.1, h.at.2)), h.story, h.pos, h.text)).collect();+ hits.sort_by_key(|a| (a.0, a.1, a.2.0, a.3));+ hits.into_iter().map(|(page, _, _, _, text)| (page, text)).collect()+}+impl RunningIndex {/// Index the paragraphs / runs that running-header variables refer to. `get` composes a story/// (normally through the cache); stories that themselves contain running headers are skipped.@@ -65,7 +89,8 @@ impl RunningIndex {_ => None,}).collect();- let mut hits: HashMap<(String, bool), Vec<((usize, i64, i64), String)>> = HashMap::new();+ // (place, story, byte) of each paragraph or run, with its text.+ let mut hits: HashMap<(String, bool), Vec<Hit>> = HashMap::new();if wanted.is_empty() {return RunningIndex::default();}@@ -90,7 +115,7 @@ impl RunningIndex {continue;}if let Some(at) = place(doc, &cs, r.start) {- hits.entry(key).or_default().push((at, text));+ hits.entry(key).or_default().push(Hit { at, story: *sid, pos: r.start, text });}}}@@ -105,16 +130,15 @@ impl RunningIndex {continue;}if let Some(at) = place(doc, &cs, r.start) {- hits.entry(key).or_default().push((at, text));+ hits.entry(key).or_default().push(Hit { at, story: *sid, pos: r.start, text });}}}}let mut map = HashMap::new();- for (key, mut v) in hits {- v.sort_by_key(|(at, _)| *at);+ for (key, v) in hits {let mut pages: BTreeMap<usize, (String, String)> = BTreeMap::new();- for ((page, ..), text) in v {+ for (page, text) in in_page_order(v) {pages.entry(page).and_modify(|e| e.1 = text.clone()).or_insert((text.clone(), text));}map.insert(key, pages);diff --git a/crates/engine/src/cmd/variables.rs b/crates/engine/src/cmd/variables.rsindex d2e513430..9c5dd20c8 100644--- a/crates/engine/src/cmd/variables.rs+++ b/crates/engine/src/cmd/variables.rs@@ -356,4 +356,34 @@ mod tests {s.execute("variables.delete", &json!({"name": "Last Page Number"})).unwrap();assert!(s.doc().unwrap().doc.story(sid).unwrap().text.ends_with(" · 3"));}++ /// A running header reads a page in text order: in a two-column frame the right column's+ /// headings come after the left column's, even when they sit higher on the page. (The first+ /// and last were picked by height, so a dictionary page's header named its left column's last+ /// entry, which sits lowest, instead of the right column's.)+ #[test]+ fn running_header_reads_columns_in_text_order() {+ use designcraft_doc::story::COLUMN_BREAK;+ let mut s = Session::new();+ s.execute("file.new", &json!({"pages": 1, "facingPages": false})).unwrap();+ s.execute("style.paragraph.create", &json!({"name": "Heading"})).ok();+ // Left column: a line, Alpha, a line, Beta (low). Right column: Gamma (at the top), a line.+ let text = format!("x\nAlpha\nx\nBeta{COLUMN_BREAK}\nGamma\ny");+ let r = s.execute("frame.create", &json!({"rect": [72, 72, 472, 400], "content": "text", "text": text})).unwrap();+ s.execute("object.textFrameOptions", &json!({"ids": [r["id"]], "columns": 2, "gutter": 20})).unwrap();+ let sid = s.doc().unwrap().doc.item(designcraft_doc::ItemId(r["id"].as_u64().unwrap())).unwrap().text_frame().unwrap().story;+ for word in ["Alpha", "Beta", "Gamma"] {+ let at = text.find(word).unwrap();+ s.execute("text.select", &json!({"story": sid.0, "anchor": at, "focus": at + word.len()})).unwrap();+ s.execute("style.paragraph.apply", &json!({"name": "Heading"})).unwrap();+ }+ s.execute("variables.define", &json!({"name": "Entry", "type": "runningHeader", "style": "Heading"})).unwrap();+ let d = s.doc().unwrap().doc.clone();+ let cs = s.cache.get(&d, sid, None);+ let y = |word: &str| crate::compose::caret(&cs, text.find(word).unwrap()).unwrap().2;+ assert!(y("Gamma") < y("Beta") && y("Gamma") < y("Alpha"), "Gamma heads the right column, above the left column's headings");+ let idx = s.cache.running_index(&d);+ assert_eq!(idx.value("Heading", false, designcraft_doc::vars::Use::FirstOnPage, 0), "Alpha");+ assert_eq!(idx.value("Heading", false, designcraft_doc::vars::Use::LastOnPage, 0), "Gamma");+ }}