Skip to content

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

Sections: the section marker shows the section's marker text (#556)

aiongg406f1b3d267f
diff --git a/ROADMAP.md b/ROADMAP.md
index d33353caa..e4cb88230 100644
--- a/ROADMAP.md
+++ b/ROADMAP.md
@@ -129,6 +129,7 @@ list) · [roadmap.md](docs/roadmap.md) (milestones, plan) · [parity-checklist.m
Newest first.
+- **2026-10-12** · The section marker character shows its section's marker text on document pages (nothing when the section has none) instead of the word "Section", which stays on parent pages; editing the marker recomposes (#556). No readiness percentage change.
- **2026-10-12** · Words in capitals hyphenate like capitalized words (FERRUM COM-MODI), as in InDesign; Hyphenate Capitalized Words off keeps them whole. No readiness percentage change.
- **2026-10-11** · `transform.move {copy}`, Edit › Duplicate and Step and Repeat return the copies' ids, so a script can go on with them. No readiness percentage change.
- **2026-10-11** · `object.fill` and `object.stroke` refuse a swatch name the document doesn't have (it painted nothing) and suggest the name meant (`Paper` → `[Paper]`). No readiness percentage change.
diff --git a/crates/compose/src/cache.rs b/crates/compose/src/cache.rs
index 8aabbf0f1..4ede03594 100644
--- a/crates/compose/src/cache.rs
+++ b/crates/compose/src/cache.rs
@@ -67,10 +67,18 @@ impl Cache {
// The key holds the page's index, which a renumbering doesn't change: its name (section
// start number, style, prefix) is part of the signature.
let page_name = page.map(|p| doc.page_name(p));
+ let section_marker = page.map(|p| crate::section_marker(doc, p));
if let Some(name) = &page_name {
use std::hash::{Hash, Hasher};
let mut h = std::collections::hash_map::DefaultHasher::new();
- name.hash(&mut h);
+ (name, &section_marker).hash(&mut h);
+ sig.push(h.finish() as usize);
+ }
+ if story.text.contains(designcraft_doc::story::SECTION_MARKER) {
+ // Frames on document pages show their section's marker text.
+ use std::hash::{Hash, Hasher};
+ let mut h = std::collections::hash_map::DefaultHasher::new();
+ doc.sections.iter().for_each(|s| (s.start, &s.marker).hash(&mut h));
sig.push(h.finish() as usize);
}
let with_vars = crate::vars::has_vars(story);
@@ -144,7 +152,7 @@ impl Cache {
let out = Arc::new(crate::compose_story(
doc,
sid,
- &ComposeOptions { page_name, page, running, label: None, xrefs: with_xrefs.then(|| self.xref_index(doc)) },
+ &ComposeOptions { page_name, section_marker, page, running, label: None, xrefs: with_xrefs.then(|| self.xref_index(doc)) },
));
let mut g = self.map.lock().unwrap_or_else(|e| e.into_inner());
let stamp = g.1;
diff --git a/crates/compose/src/lib.rs b/crates/compose/src/lib.rs
index 3dd7c25b3..7db6bd27a 100644
--- a/crates/compose/src/lib.rs
+++ b/crates/compose/src/lib.rs
@@ -303,6 +303,8 @@ pub struct FrameSpec {
pub vertical: bool,
pub exclusions: Vec<Exclusion>,
pub page_name: Option<String>,
+ /// Marker text of the section the frame's page is in (None on parent pages).
+ pub section_marker: Option<String>,
/// Absolute document page the frame is on (None on parent pages).
pub page: Option<usize>,
/// Baseline grid in inner space: (first grid line y, increment).
@@ -329,11 +331,18 @@ impl FrameSpec {
}
}
+/// The marker text of the section absolute page `abs` is in (empty when it has none).
+pub fn section_marker(doc: &Document, abs: usize) -> String {
+ doc.section_of(abs).map(|s| s.marker.clone()).unwrap_or_default()
+}
+
/// Composition inputs that are not in the story itself.
#[derive(Clone, Debug, Default)]
pub struct ComposeOptions {
/// Page name for page-number markers when the story is composed for a specific page (parent items).
pub page_name: Option<String>,
+ /// Section marker text when the story is composed for a specific page (parent items).
+ pub section_marker: Option<String>,
/// Absolute page for text variables when composed for a specific page (parent items).
pub page: Option<usize>,
/// Running-header index (needed when the story contains running-header variables).
@@ -387,6 +396,7 @@ pub fn frame_specs(doc: &Document, sid: StoryId) -> Vec<FrameSpec> {
}
_ => (None, None, false),
};
+ let section_marker = page.map(|abs| section_marker(doc, abs));
// The page under the frame and its margins, in inner space (bounding boxes).
let page_rect = match (loc.spread, spread) {
(_, Some(sp)) => sp
@@ -438,6 +448,7 @@ pub fn frame_specs(doc: &Document, sid: StoryId) -> Vec<FrameSpec> {
vertical,
exclusions: if tf.options.path.is_some() { vec![] } else { exclusions },
page_name,
+ section_marker,
page,
grid,
left_page,
@@ -618,7 +629,7 @@ fn compose_with_db(doc: &Document, story: &Story, frames: &[FrameSpec], opts: &C
};
let mut sub = SubstCtx {
page_name: opts.page_name.clone().or_else(|| cur_frame.and_then(|f| f.page_name.clone())),
- section_marker: None,
+ section_marker: opts.section_marker.clone().or_else(|| cur_frame.and_then(|f| f.section_marker.clone())),
vars: var_values,
hidden_conditions: doc.conditions.iter().filter(|c| !c.visible).map(|c| c.name.clone()).collect(),
vertical: cur_frame.is_some_and(|f| f.vertical),
diff --git a/crates/compose/src/notes.rs b/crates/compose/src/notes.rs
index 32b2bbec2..d0055ee06 100644
--- a/crates/compose/src/notes.rs
+++ b/crates/compose/src/notes.rs
@@ -102,6 +102,7 @@ impl Notes {
vertical: false,
exclusions: vec![],
page_name: f.page_name.clone(),
+ section_marker: f.section_marker.clone(),
page: f.page,
grid: None,
left_page: f.left_page,
@@ -109,6 +110,7 @@ impl Notes {
};
let nopts = ComposeOptions {
page_name: opts.page_name.clone(),
+ section_marker: opts.section_marker.clone(),
page: opts.page,
running: opts.running.clone(),
label: Some(label),
diff --git a/crates/compose/src/shape.rs b/crates/compose/src/shape.rs
index 1e1af40a7..0d00d3275 100644
--- a/crates/compose/src/shape.rs
+++ b/crates/compose/src/shape.rs
@@ -88,6 +88,7 @@ pub struct ShapedPara {
#[derive(Clone, Debug, Default)]
pub struct SubstCtx {
pub page_name: Option<String>,
+ /// The section marker text of the page being composed (`None` on parent pages: "Section").
pub section_marker: Option<String>,
/// Text variable values by index (on the page being composed).
pub vars: Arc<Vec<String>>,
@@ -586,7 +587,14 @@ fn shape_run_raw(
} else {
sub.page_name.clone().unwrap_or_else(|| "#".into())
};
- shape_segment(db, text, i..i + c.len_utf8(), Some(&s), p, &primary, auto_leading, style, out, sub.vertical);
+ if s.is_empty() {
+ // A section without marker text: the character takes no space.
+ let mut g = control_glyph(&primary, p, auto_leading, style, i, c);
+ g.adv = 0.0;
+ out.push(g);
+ } else {
+ shape_segment(db, text, i..i + c.len_utf8(), Some(&s), p, &primary, auto_leading, style, out, sub.vertical);
+ }
}
designcraft_doc::OBJECT_MARK => {
let mut g = control_glyph(&primary, p, auto_leading, style, i, c);
diff --git a/crates/compose/src/table.rs b/crates/compose/src/table.rs
index c70f477be..bc4f0d06f 100644
--- a/crates/compose/src/table.rs
+++ b/crates/compose/src/table.rs
@@ -112,6 +112,7 @@ fn compose_cell(doc: &Document, cell: &Cell, w: f64, opts: &ComposeOptions, left
vertical: false,
exclusions: vec![],
page_name: opts.page_name.clone(),
+ section_marker: opts.section_marker.clone(),
page: opts.page,
grid: None,
left_page,
diff --git a/crates/engine/src/cmd/variables.rs b/crates/engine/src/cmd/variables.rs
index e7772d4ea..3288e8161 100644
--- a/crates/engine/src/cmd/variables.rs
+++ b/crates/engine/src/cmd/variables.rs
@@ -153,6 +153,38 @@ mod tests {
assert_eq!(shown(&s, 2), 3, "page 102 after renumbering");
}
+ /// A section marker character shows the marker text of the section of the page it is composed
+ /// for: on each document page a parent-page frame is shown on, and in a frame on a document
+ /// page. A section without marker text shows nothing; the parent page itself shows "Section".
+ #[test]
+ fn section_marker_shows_the_pages_section_marker() {
+ let mut s = Session::new();
+ s.execute("file.new", &json!({"pages": 4, "facingPages": false})).unwrap();
+ s.execute("layout.section", &json!({"page": 3, "startNumber": 1, "marker": "Intro"})).unwrap();
+ let marker = designcraft_doc::story::SECTION_MARKER.to_string();
+ let r = s
+ .execute("frame.create", &json!({"spread": {"kind": "parent", "index": 0}, "rect": [72, 30, 500, 60], "content": "text", "text": marker}))
+ .unwrap();
+ let parent = s.doc().unwrap().doc.item(designcraft_doc::ItemId(r["id"].as_u64().unwrap())).unwrap().text_frame().unwrap().story;
+ let sp = s.doc().unwrap().doc.page_loc(3).unwrap().0;
+ let r = s.execute("frame.create", &json!({"spread": sp, "rect": [72, 200, 400, 260], "content": "text", "text": marker})).unwrap();
+ let own = s.doc().unwrap().doc.item(designcraft_doc::ItemId(r["id"].as_u64().unwrap())).unwrap().text_frame().unwrap().story;
+ let shown = |s: &Session, sid, page: Option<usize>| -> usize {
+ let d = s.doc().unwrap().doc.clone();
+ let cs = s.cache.get(&d, sid, page);
+ cs.frames.iter().flat_map(|f| f.lines.iter()).map(|l| l.glyphs.iter().filter(|g| g.visible && g.adv > 0.0).count()).sum()
+ };
+ assert_eq!(shown(&s, parent, Some(0)), 0, "the first section has no marker");
+ assert_eq!(shown(&s, parent, Some(2)), "Intro".len());
+ assert_eq!(shown(&s, parent, Some(3)), "Intro".len());
+ assert_eq!(shown(&s, own, None), "Intro".len(), "a frame on a document page");
+ assert_eq!(shown(&s, parent, None), "Section".len(), "the parent page itself");
+ // Editing the marker recomposes.
+ s.execute("layout.section", &json!({"page": 3, "marker": "Appendix"})).unwrap();
+ assert_eq!(shown(&s, parent, Some(2)), "Appendix".len());
+ assert_eq!(shown(&s, own, None), "Appendix".len());
+ }
+
/// Two sections that both number from 1 repeat page names ("1, 2, 1, 2"). A parent-page running
/// header is composed for the page it is shown on, not the first page with that name.
#[test]