DesignCraft: An open-source page and layout design editor written by scratch in pure Rust
T: endnotes — numbered references, generated endnote frame, options
Brandon Thomasd11b23d80539
diff --git a/ROADMAP.md b/ROADMAP.mdindex ba31c40c3..45bd17d9e 100644--- a/ROADMAP.md+++ b/ROADMAP.md@@ -46,6 +46,7 @@ DesignCraft aims at full Adobe InDesign parity — and to be better: faster, ope- Swatches panel colour groups (`swatch.newColorGroup`, `moveToGroup`, `ungroupColorGroup`, `renameColorGroup`; folders and a row context menu; IDML ColorGroup).- Object ▸ Generate QR Code (`object.qrCode`: web link, text, SMS, email, business card; vector modules as a compound path, into a frame or re-encoded in place).- Conditional text (`condition.new/options/delete/apply/list`, Conditional Text panel): hidden conditions drop their text from layout and exports, indicators underline on screen, IDML Condition/AppliedConditions.+- Endnotes (`endnote.insert/edit/delete/list/options`, Type ▸ Insert Endnote): references number through the document, the endnote frame on a new last page lists them under a heading; IDML keeps the listed text only.- Drag and drop text editing: drag selected text to move it (Alt copies) with its formatting (`text.release`).- Image Import Options: place any page of a multi-page PDF (`file.place {pdfPage}`; the app asks which page), shown on screen and embedded as that page in PDF export.- Define Lists: named numbered lists that continue across stories in page order (`list.define`, paragraph `listName` / `startAt`), round-tripped through IDML; `null` in `type.para` / `type.char` now removes an override.@@ -94,7 +95,7 @@ DesignCraft aims at full Adobe InDesign parity — and to be better: faster, ope## How far from full parity (estimate, 2026-10-02, updated)-**Breadth: ~85% weighted** (P0 core 99%, P1 87%, P2 24%) over the 275 features of the InDesign catalogue, scored+**Breadth: ~87% weighted** (P0 core 99%, P1 89%, P2 33%) over the 275 features of the InDesign catalogue, scoredrow by row in [docs/parity.md](docs/parity.md) (`cargo xtask parity` recomputes it). Many features scored done stilllack some of InDesign's options or dialog details, so **overall parity including depth is about 70%**.diff --git a/crates/compose/src/cache.rs b/crates/compose/src/cache.rsindex b1c9ea9bb..7f8500550 100644--- a/crates/compose/src/cache.rs+++ b/crates/compose/src/cache.rs@@ -88,6 +88,10 @@ impl Cache {format!("{:?}", doc.footnote_options).hash(&mut h);sig.extend([doc.footnote_start(sid) as usize, h.finish() as usize]);}+ // Endnote numbers continue from stories on earlier pages.+ if !story.endnotes.is_empty() {+ sig.push(doc.endnote_start(sid) as usize);+ }// Hidden conditions take their text out of the layout.for (i, c) in doc.conditions.iter().enumerate() {if !c.visible {diff --git a/crates/compose/src/lib.rs b/crates/compose/src/lib.rsindex bc746f4b1..1a20dadd2 100644--- a/crates/compose/src/lib.rs+++ b/crates/compose/src/lib.rs@@ -458,6 +458,13 @@ pub fn compose(doc: &Document, story: &Story, frames: &[FrameSpec], opts: &Compohidden_conditions: doc.conditions.iter().filter(|c| !c.visible).map(|c| c.name.clone()).collect(),..Default::default()};+ if !story.endnotes.is_empty() {+ // Endnote reference numbers continue through the document.+ let first = doc.endnote_start(story.id) + story.text[..prange.start].matches(designcraft_doc::ENDNOTE_REF).count() as u32;+ for (k, (i, _)) in story.text[prange.clone()].match_indices(designcraft_doc::ENDNOTE_REF).enumerate() {+ sub.notes.insert(prange.start + i, doc.endnote_options.label(first + k as u32));+ }+ }if !story.objects.is_empty() {let before = story.text[..prange.start].matches(designcraft_doc::OBJECT_MARK).count();for (k, (i, _)) in story.text[prange.clone()].match_indices(designcraft_doc::OBJECT_MARK).enumerate() {diff --git a/crates/compose/src/shape.rs b/crates/compose/src/shape.rsindex a2096e4b9..c3a7580fa 100644--- a/crates/compose/src/shape.rs+++ b/crates/compose/src/shape.rs@@ -207,11 +207,13 @@ pub(crate) fn shape_para(}continue;}- if !story.text[a..b].contains(designcraft_doc::FOOTNOTE_REF) {+ let is_ref = |c: char| c == designcraft_doc::FOOTNOTE_REF || c == designcraft_doc::ENDNOTE_REF;+ if !story.text[a..b].contains(is_ref) {shape_run(db, &story.text, a..b, &props, auto_leading, style, sub, &mut glyphs);continue;}- // Footnote references take the reference position / character style.+ // Footnote references take the reference position / character style; endnote references+ // are superscript.let mut rf = fmt.clone();if let Some(cs) = &sub.note_style {rf.style = cs.clone();@@ -219,14 +221,22 @@ pub(crate) fn shape_para(rf.over.position = Some(sub.note_position);let rprops = styles.resolve_char(para_chars, &rf);let rstyle = table.intern(&rprops);+ let mut ef = fmt.clone();+ ef.over.position = Some(designcraft_doc::Position::Superscript);+ let eprops = styles.resolve_char(para_chars, &ef);+ let estyle = table.intern(&eprops);let mut k = a;- for (i, _) in story.text[a..b].match_indices(designcraft_doc::FOOTNOTE_REF) {+ for (i, m) in story.text[a..b].match_indices(is_ref) {let i = a + i;if k < i {shape_run(db, &story.text, k..i, &props, auto_leading, style, sub, &mut glyphs);}- let e = i + designcraft_doc::FOOTNOTE_REF.len_utf8();- shape_run(db, &story.text, i..e, &rprops, auto_leading, rstyle, sub, &mut glyphs);+ let e = i + m.len();+ if m.starts_with(designcraft_doc::ENDNOTE_REF) {+ shape_run(db, &story.text, i..e, &eprops, auto_leading, estyle, sub, &mut glyphs);+ } else {+ shape_run(db, &story.text, i..e, &rprops, auto_leading, rstyle, sub, &mut glyphs);+ }k = e;}if k < b {@@ -307,6 +317,7 @@ fn shape_run(| story::RIGHT_INDENT_TAB| story::TABLE_ANCHOR| designcraft_doc::FOOTNOTE_REF+ | designcraft_doc::ENDNOTE_REF| designcraft_doc::XREF_MARK| designcraft_doc::ANCHOR_MARK| designcraft_doc::INDEX_MARK@@ -363,7 +374,7 @@ fn shape_run(out.push(g);}},- designcraft_doc::FOOTNOTE_REF => {+ designcraft_doc::FOOTNOTE_REF | designcraft_doc::ENDNOTE_REF => {let s = sub.notes.get(&i).map_or("#", String::as_str);shape_segment(db, text, i..i + c.len_utf8(), Some(s), p, &primary, auto_leading, style, out);}diff --git a/crates/doc/src/build.rs b/crates/doc/src/build.rsindex a9fcad691..acd544fcb 100644--- a/crates/doc/src/build.rs+++ b/crates/doc/src/build.rs@@ -128,6 +128,8 @@ impl Document {swatches: designcraft_color::default_swatches(),color_groups: vec![],conditions: vec![],+ endnote_options: Default::default(),+ endnote_story: None,sections: vec![Section {start: 0,start_number: Some(nd.start_page.max(1)),diff --git a/crates/doc/src/endnotes.rs b/crates/doc/src/endnotes.rsnew file mode 100644index 000000000..6fad0c686--- /dev/null+++ b/crates/doc/src/endnotes.rs@@ -0,0 +1,170 @@+//! Endnotes (Type › Insert Endnote).+//!+//! An endnote reference is an [`ENDNOTE_REF`] character; the story's [`Story::endnotes`] holds one+//! entry per reference in text order (like footnotes). Numbering runs through the document in+//! page order. The endnote frame shows a story that is generated from every endnote: a heading+//! and one numbered paragraph per endnote ([`Document::endnote_text`]); its text isn't typed+//! into, endnotes are edited through their references.++use std::sync::Arc;++use serde::{Deserialize, Serialize};++use crate::attrs::NumberStyle;+use crate::ids::StoryId;+use crate::notes::Footnote;+use crate::story::{BASIC_PARAGRAPH, CharFormat, ParaFormat, Story};++/// Endnote reference character (the number shown in the text).+pub const ENDNOTE_REF: char = '\u{E00F}';++/// Document Endnote Options.+#[derive(Clone, Debug, PartialEq, Serialize, Deserialize)]+#[serde(rename_all = "camelCase", default)]+pub struct EndnoteOptions {+ pub style: NumberStyle,+ pub start_at: u32,+ pub prefix: String,+ pub suffix: String,+ /// Endnote frame heading (empty: none) and its paragraph style.+ pub heading: String,+ pub heading_style: String,+ /// Endnote entries' paragraph style.+ pub para_style: String,+ /// Between the number and the endnote text.+ pub separator: String,+}++impl Default for EndnoteOptions {+ fn default() -> Self {+ EndnoteOptions {+ style: NumberStyle::Arabic,+ start_at: 1,+ prefix: String::new(),+ suffix: String::new(),+ heading: "Endnotes".into(),+ heading_style: BASIC_PARAGRAPH.into(),+ para_style: BASIC_PARAGRAPH.into(),+ separator: "\t".into(),+ }+ }+}++impl EndnoteOptions {+ pub fn label(&self, n: u32) -> String {+ format!("{}{}{}", self.prefix, self.style.format(n), self.suffix)+ }+}++impl Story {+ /// Index (in [`Story::endnotes`]) of the endnote whose reference is the k-th before `pos`.+ pub fn endnotes_before(&self, pos: usize) -> usize {+ let pos = crate::story::floor_char_boundary(&self.text, pos);+ self.text[..pos].matches(ENDNOTE_REF).count()+ }++ pub fn endnote(&self, id: u64) -> Option<&Footnote> {+ self.endnotes.iter().find(|n| n.id == id).map(|n| &**n)+ }++ /// Mutable endnote (copy-on-write); bumps the story revision.+ pub fn endnote_mut(&mut self, id: u64) -> Option<&mut Footnote> {+ let n = self.endnotes.iter_mut().find(|n| n.id == id)?;+ self.rev += 1;+ Some(Arc::make_mut(n))+ }++ /// Insert an endnote reference at `pos` with the given text. Returns the endnote id.+ pub fn insert_endnote(&mut self, pos: usize, text: &str, para: ParaFormat) -> u64 {+ let pos = crate::story::floor_char_boundary(&self.text, pos.min(self.len()));+ let fmt = self.char_format_at(pos).clone();+ self.insert_with(pos, &ENDNOTE_REF.to_string(), fmt);+ let k = self.endnotes_before(pos);+ let note = Arc::make_mut(&mut self.endnotes[k]);+ note.text = Story::with_text(StoryId(0), text, para);+ note.id+ }++ /// Insert empty endnotes for `n` new reference characters before which `k` references sit.+ pub(crate) fn endnotes_inserted(&mut self, k: usize, n: usize) {+ for i in 0..n {+ let id = self.endnotes.iter().map(|x| x.id).max().unwrap_or(0) + 1;+ let mut text = Story::new(StoryId(0));+ text.chars[0].format = CharFormat::default();+ self.endnotes.insert((k + i).min(self.endnotes.len()), Arc::new(Footnote { id, text }));+ }+ }++ pub(crate) fn check_endnotes(&self) -> Result<(), String> {+ let n = self.text.matches(ENDNOTE_REF).count();+ if n != self.endnotes.len() {+ return Err(format!("story {}: {n} endnote references, {} endnotes", self.id.0, self.endnotes.len()));+ }+ Ok(())+ }+}++impl crate::Document {+ /// Stories with endnotes in numbering order (page of their first frame, then id).+ fn endnote_order(&self) -> Vec<&Story> {+ let key = |st: &Story| -> (usize, u64) { (st.frames.first().and_then(|f| self.page_of_item(*f)).unwrap_or(usize::MAX), st.id.0) };+ let mut v: Vec<&Story> = self.stories.values().map(|s| s.as_ref()).filter(|s| !s.endnotes.is_empty()).collect();+ v.sort_by_key(|s| key(s));+ v+ }++ /// Number of the first endnote of story `sid`.+ pub fn endnote_start(&self, sid: StoryId) -> u32 {+ let mut n = self.endnote_options.start_at;+ for st in self.endnote_order() {+ if st.id == sid {+ break;+ }+ n += st.endnotes.len() as u32;+ }+ n+ }++ /// The endnote frame's text: the heading, then "number separator text" per endnote, in order.+ pub fn endnote_text(&self, id: StoryId) -> Story {+ let o = &self.endnote_options;+ let para = |style: &str| ParaFormat { style: style.to_string(), ..Default::default() };+ let mut out = Story::with_text(id, &o.heading, para(&o.heading_style));+ let mut n = o.start_at;+ for st in self.endnote_order() {+ for note in &st.endnotes {+ let at = out.len();+ let first = at == 0 && o.heading.is_empty();+ if !first {+ out.insert(at, "\n");+ }+ let pi = out.paras.len() - 1;+ out.paras[pi] = para(&o.para_style);+ let at = out.len();+ out.insert_with(at, &format!("{}{}", o.label(n), o.separator), CharFormat::default());+ for (r, f) in note.text.runs() {+ let at = out.len();+ out.insert_with(at, ¬e.text.text[r].replace('\n', " "), f.clone());+ }+ n += 1;+ }+ }+ out+ }++ /// Bring the endnote frame's story up to date with the endnotes (after any edit).+ pub fn sync_endnote_story(&mut self) {+ let Some(sid) = self.endnote_story else { return };+ let Some(cur) = self.stories.get(&sid) else {+ self.endnote_story = None;+ return;+ };+ let fresh = self.endnote_text(sid);+ if cur.text == fresh.text && cur.paras == fresh.paras && cur.chars == fresh.chars {+ return;+ }+ let st = Arc::make_mut(self.stories.get_mut(&sid).expect("checked"));+ let (frames, rev) = (std::mem::take(&mut st.frames), st.rev);+ *st = Story { frames, rev: rev + 1, ..fresh };+ }+}diff --git a/crates/doc/src/lib.rs b/crates/doc/src/lib.rsindex 49cdab2b3..cd5f05711 100644--- a/crates/doc/src/lib.rs+++ b/crates/doc/src/lib.rs@@ -13,6 +13,7 @@ pub mod arrow;pub mod attrs;pub mod build;mod edit;+pub mod endnotes;pub mod ids;pub mod index;pub mod item;@@ -35,6 +36,7 @@ pub use attrs::*;pub use designcraft_color as color;pub use designcraft_geom as geom;pub use edit::{ItemLoc, ItemPath, SpreadRef, item_hit as edit_hit};+pub use endnotes::{ENDNOTE_REF, EndnoteOptions};pub use ids::*;pub use index::{INDEX_MARK, IndexRef};pub use item::*;@@ -322,6 +324,11 @@ pub struct Document {/// the top level.#[serde(default, skip_serializing_if = "Vec::is_empty")]pub color_groups: Vec<ColorGroup>,+ /// Document Endnote Options, and the story shown in the endnote frame (generated).+ #[serde(default)]+ pub endnote_options: EndnoteOptions,+ #[serde(default, skip_serializing_if = "Option::is_none")]+ pub endnote_story: Option<StoryId>,/// Conditional text conditions; text whose conditions are all hidden isn't composed.#[serde(default, skip_serializing_if = "Vec::is_empty")]pub conditions: Vec<Condition>,diff --git a/crates/doc/src/story.rs b/crates/doc/src/story.rsindex 844b93731..152b83e80 100644--- a/crates/doc/src/story.rs+++ b/crates/doc/src/story.rs@@ -98,6 +98,9 @@ pub struct Story {/// Footnotes, one per [`crate::notes::FOOTNOTE_REF`] in text order (see [`crate::notes`]).#[serde(default, skip_serializing_if = "Vec::is_empty")]pub notes: Vec<Arc<crate::notes::Footnote>>,+ /// Endnotes, one per [`crate::endnotes::ENDNOTE_REF`] in text order.+ #[serde(default, skip_serializing_if = "Vec::is_empty")]+ pub endnotes: Vec<Arc<crate::notes::Footnote>>,/// Text anchors, one per [`crate::xref::ANCHOR_MARK`] in text order.#[serde(default, skip_serializing_if = "Vec::is_empty")]pub anchors: Vec<Arc<crate::xref::TextAnchor>>,@@ -123,6 +126,7 @@ impl Story {rev: 0,tables: BTreeMap::new(),notes: Vec::new(),+ endnotes: Vec::new(),anchors: Vec::new(),xrefs: Vec::new(),index_refs: Vec::new(),@@ -215,6 +219,11 @@ impl Story {let k = self.notes_before(pos);self.notes_inserted(k, refs);}+ let erefs = text.matches(crate::endnotes::ENDNOTE_REF).count();+ if erefs > 0 {+ let k = self.endnotes_before(pos);+ self.endnotes_inserted(k, erefs);+ }if text.contains([crate::xref::ANCHOR_MARK, crate::xref::XREF_MARK, crate::index::INDEX_MARK, crate::anchored::OBJECT_MARK]) {self.marks_inserted(pos, text);}@@ -246,6 +255,11 @@ impl Story {let k = self.notes_before(a);self.notes.drain(k..(k + refs).min(self.notes.len()));}+ let erefs = self.text[a..b].matches(crate::endnotes::ENDNOTE_REF).count();+ if erefs > 0 {+ let k = self.endnotes_before(a);+ self.endnotes.drain(k..(k + erefs).min(self.endnotes.len()));+ }self.marks_deleted(a, b);let pi = self.para_at(a);let removed = self.text[a..b].bytes().filter(|c| *c == b'\n').count();@@ -351,6 +365,7 @@ impl Story {}self.check_tables()?;self.check_notes()?;+ self.check_endnotes()?;self.check_marks()}diff --git a/crates/engine/src/cmd/endnotes.rs b/crates/engine/src/cmd/endnotes.rsnew file mode 100644index 000000000..e97fc45d5--- /dev/null+++ b/crates/engine/src/cmd/endnotes.rs@@ -0,0 +1,168 @@+//! Type › Insert Endnote and Document Endnote Options. Endnote text lives with its reference;+//! the endnote frame (made on a new last page with the first endnote) lists them all.++use designcraft_doc::{ParaFormat, SpreadRef, StoryId};+use serde_json::{Value, json};++use super::{CommandSpec, bad, cmd, has_doc, has_text, ok, str_param};+use crate::{Result, Session};++pub fn specs() -> Vec<CommandSpec> {+ vec![+ cmd!(+ "endnote.insert",+ "Insert Endnote",+ ["Type"],+ None,+ "{text?} — a reference at the insertion point; the first one makes the endnote frame on a new last page → {story, id, frame}",+ has_text,+ insert+ ),+ cmd!("endnote.edit", "Edit Endnote", [], None, "{story, id, text}", has_doc, |s, p| {+ let (sid, id) = target(p)?;+ let text = str_param(p, "text").unwrap_or("").to_string();+ s.edit(|d, _| {+ let style = d.endnote_options.para_style.clone();+ let st = d.story_mut(sid).ok_or_else(|| bad("endnote.edit", "no such story"))?;+ let n = st.endnote_mut(id).ok_or_else(|| bad("endnote.edit", format!("no endnote {id}")))?;+ n.text = designcraft_doc::Story::with_text(StoryId(0), &text, ParaFormat { style, ..Default::default() });+ ok()+ })+ }),+ cmd!("endnote.delete", "Delete Endnote", [], None, "{story, id} — removes the reference and its text", has_doc, |s, p| {+ let (sid, id) = target(p)?;+ s.edit(|d, _| {+ let st = d.story_mut(sid).ok_or_else(|| bad("endnote.delete", "no such story"))?;+ let k = st.endnotes.iter().position(|n| n.id == id).ok_or_else(|| bad("endnote.delete", format!("no endnote {id}")))?;+ let at = st.text.match_indices(designcraft_doc::ENDNOTE_REF).nth(k).map(|(i, _)| i).expect("one reference per endnote");+ st.delete(at..at + designcraft_doc::ENDNOTE_REF.len_utf8());+ ok()+ })+ }),+ cmd!(query "endnote.list", "Endnotes", [], None, "{} → [{story, id, number, text}] in numbering order", has_doc, |s, _| {+ let d = &s.doc()?.doc;+ let mut out = Vec::new();+ for st in d.stories.values().filter(|st| !st.endnotes.is_empty()) {+ let first = d.endnote_start(st.id);+ for (k, n) in st.endnotes.iter().enumerate() {+ out.push(json!({"story": st.id.0, "id": n.id, "number": first + k as u32, "text": n.text.text}));+ }+ }+ out.sort_by_key(|v| v["number"].as_u64());+ Ok(Value::Array(out))+ }),+ cmd!(+ "endnote.options",+ "Document Endnote Options…",+ ["Type"],+ None,+ "{style?: arabic|upperRoman|lowerRoman|upperLetters|lowerLetters, startAt?, prefix?, suffix?, heading?, headingStyle?, paraStyle?, separator?} → the options",+ has_doc,+ |s, p| {+ let cur = serde_json::to_value(&s.doc()?.doc.endnote_options).map_err(|e| bad("endnote.options", e.to_string()))?;+ let mut new = cur.clone();+ if let (Some(n), Some(o)) = (new.as_object_mut(), p.as_object()) {+ for (k, v) in o {+ if !n.contains_key(k) {+ return Err(bad("endnote.options", format!("unknown option {k}")));+ }+ n.insert(k.clone(), v.clone());+ }+ }+ let opts: designcraft_doc::EndnoteOptions = serde_json::from_value(new.clone()).map_err(|e| bad("endnote.options", e.to_string()))?;+ if new != cur {+ s.edit(|d, _| {+ d.endnote_options = opts;+ ok()+ })?;+ }+ Ok(new)+ }+ ),+ ]+}++fn target(p: &Value) -> Result<(StoryId, u64)> {+ let sid = p.get("story").and_then(Value::as_u64).ok_or_else(|| bad("endnote", "`story` required"))?;+ let id = p.get("id").and_then(Value::as_u64).ok_or_else(|| bad("endnote", "`id` required"))?;+ Ok((StoryId(sid), id))+}++fn insert(s: &mut Session, p: &Value) -> Result<Value> {+ const ID: &str = "endnote.insert";+ let st = s.doc()?;+ let ts = st.selection.text.ok_or_else(|| bad(ID, "place the insertion point in text"))?;+ if ts.cell.is_some() {+ return Err(bad(ID, "endnotes go in story text, not tables or footnotes"));+ }+ if st.doc.endnote_story == Some(ts.story) {+ return Err(bad(ID, "the endnote frame lists the endnotes"));+ }+ let text = str_param(p, "text").unwrap_or("").to_string();+ let at = ts.anchor.max(ts.focus);+ s.edit(|d, sel| {+ // The endnote frame: a text frame in the margins of a new last page.+ let mut frame = None;+ if d.endnote_story.is_none() {+ let last = d.page_count().saturating_sub(1);+ let parent = d.page_loc(last).and_then(|(si, pi)| d.spreads[si].pages[pi].parent);+ d.insert_pages(Some(last), 1, parent)?;+ let (si, pi) = d.page_loc(last + 1).ok_or_else(|| bad(ID, "page insert failed"))?;+ let r = d.spreads[si].pages[pi].margin_rect();+ let layer = d.default_layer();+ let (fid, esid) = d.add_text_frame(SpreadRef::Doc(si), r, layer, "", ParaFormat::default())?;+ d.endnote_story = Some(esid);+ frame = Some(fid.0);+ }+ let style = d.endnote_options.para_style.clone();+ let story = d.story_mut(ts.story).ok_or_else(|| bad(ID, "no such story"))?;+ let id = story.insert_endnote(at, &text, ParaFormat { style, ..Default::default() });+ let caret = at + designcraft_doc::ENDNOTE_REF.len_utf8();+ if let Some(t) = &mut sel.text {+ (t.anchor, t.focus) = (caret, caret);+ }+ Ok(json!({"story": ts.story.0, "id": id, "frame": frame}))+ })+}++#[cfg(test)]+mod tests {+ use serde_json::json;++ use crate::Session;++ #[test]+ fn endnotes_number_through_the_document_and_fill_the_endnote_frame() {+ let mut s = Session::new();+ s.execute("file.new", &json!({"pages": 2})).unwrap();+ let a = s.execute("frame.create", &json!({"rect": [72, 72, 400, 300], "content": "text", "text": "Alpha beta."})).unwrap();+ s.execute("text.select", &json!({"story": a["story"], "anchor": 5, "focus": 5})).unwrap();+ let r1 = s.execute("endnote.insert", &json!({"text": "First source."})).unwrap();+ let pages = s.doc().unwrap().doc.page_count();+ assert_eq!(pages, 3, "a new last page holds the endnote frame");+ assert!(r1["frame"].is_u64());+ s.execute("text.select", &json!({"story": a["story"], "anchor": 0, "focus": 0})).unwrap();+ let r0 = s.execute("endnote.insert", &json!({"text": "Earlier."})).unwrap();+ assert!(r0["frame"].is_null(), "one endnote frame");+ let list = s.execute("endnote.list", &json!({})).unwrap();+ assert_eq!(list.as_array().unwrap().len(), 2);+ let d = s.doc().unwrap().doc.clone();+ let esid = d.endnote_story.unwrap();+ assert_eq!(d.stories[&esid].text, "Endnotes\n1\tEarlier.\n2\tFirst source.", "numbered in text order");+ // The references are numbered in the composed text.+ let sid = designcraft_doc::StoryId(a["story"].as_u64().unwrap());+ let cs = s.cache.get(&d, sid, None);+ let shown = cs.frames[0].lines[0].glyphs.len();+ assert!(shown > "Alpha beta.".chars().count(), "reference numbers take glyphs");+ s.execute("endnote.edit", &json!({"story": r1["story"], "id": r1["id"], "text": "Edited."})).unwrap();+ s.execute("endnote.options", &json!({"style": "lowerRoman", "heading": "Notes"})).unwrap();+ let d = s.doc().unwrap().doc.clone();+ assert_eq!(d.stories[&esid].text, "Notes\ni\tEarlier.\nii\tEdited.");+ s.execute("endnote.delete", &json!({"story": r0["story"], "id": r0["id"]})).unwrap();+ let d = s.doc().unwrap().doc.clone();+ assert_eq!(d.stories[&esid].text, "Notes\ni\tEdited.");+ assert_eq!(d.stories[&sid].text.matches(designcraft_doc::ENDNOTE_REF).count(), 1);+ s.execute("edit.undo", &json!({})).unwrap();+ assert_eq!(s.doc().unwrap().doc.stories[&esid].text, "Notes\ni\tEarlier.\nii\tEdited.");+ }+}diff --git a/crates/engine/src/cmd/mod.rs b/crates/engine/src/cmd/mod.rsindex 5c3ceb422..76767f305 100644--- a/crates/engine/src/cmd/mod.rs+++ b/crates/engine/src/cmd/mod.rs@@ -6,6 +6,7 @@ mod captions;mod conditions;mod datamerge;mod edit;+mod endnotes;mod export;mod file;mod find;@@ -133,6 +134,7 @@ pub fn command_specs() -> &'static [CommandSpec] {v.extend(interchange::specs());v.extend(export::specs());v.extend(edit::specs());+ v.extend(endnotes::specs());v.extend(object::specs());v.extend(anchors::specs());v.extend(paths::specs());diff --git a/crates/engine/src/lib.rs b/crates/engine/src/lib.rsindex e561a4860..940654cd4 100644--- a/crates/engine/src/lib.rs+++ b/crates/engine/src/lib.rs@@ -390,6 +390,7 @@ impl Session {let mut doc = (*st.doc).clone();let mut sel = st.selection.clone();let r = f(&mut doc, &mut sel)?;+ doc.sync_endnote_story();st.doc = Arc::new(doc);st.selection = sel;st.revision += 1;diff --git a/crates/idml/src/export.rs b/crates/idml/src/export.rsindex 3f7c07bae..fab6fc019 100644--- a/crates/idml/src/export.rs+++ b/crates/idml/src/export.rs@@ -1776,6 +1776,9 @@ impl<'a> Ex<'a> {csrs.push(src);self.xref_sources.push((me, x.target));}+ } else if ch == designcraft_doc::ENDNOTE_REF {+ // Endnotes aren't written to IDML yet: the endnote frame keeps their text+ // (numbers included) and the references are left out.} else if ch == designcraft_doc::FOOTNOTE_REF {// The reference: its own range carrying the reference position.flush_text(&mut cur, &mut pending);diff --git a/crates/idml/src/import.rs b/crates/idml/src/import.rsindex 39b4677d2..d94e2793f 100644--- a/crates/idml/src/import.rs+++ b/crates/idml/src/import.rs@@ -1233,6 +1233,7 @@ impl<'r> Importer<'r> {rev: 0,tables,notes,+ endnotes: Vec::new(),anchors: anchor_list,xrefs: xref_list,index_refs: index_refs.into_iter().map(Arc::new).collect(),@@ -1981,6 +1982,8 @@ impl<'r> Importer<'r> {swatches: std::mem::take(&mut self.swatches),color_groups: std::mem::take(&mut self.color_groups),conditions: std::mem::take(&mut self.conditions),+ endnote_options: Default::default(),+ endnote_story: None,sections: std::mem::take(&mut self.sections),assets: std::mem::take(&mut self.assets),hyperlinks: vec![],diff --git a/crates/ui-egui/src/menus.rs b/crates/ui-egui/src/menus.rsindex 16e02a0ed..0dc41dd78 100644--- a/crates/ui-egui/src/menus.rs+++ b/crates/ui-egui/src/menus.rs@@ -284,6 +284,7 @@ pub const MENUS: &[(&str, &[&str])] = &["<","-","cmd:footnote.insert",+ "cmd:endnote.insert","ui:app.footnoteOptionsDialog","cmd:footnote.goToReference",],diff --git a/docs/parity.md b/docs/parity.mdindex 7b33c46ef..ff09079bc 100644--- a/docs/parity.md+++ b/docs/parity.md@@ -10,8 +10,8 @@ Each row of the InDesign feature catalogue is scored **D** (done), **P** (partia| Priority | Features | Done | Partial | Missing | Parity ||---|---|---|---|---|---|| P0 | 102 | 99 | 3 | 0 | 99% |-| P1 | 97 | 74 | 21 | 2 | 87% |-| P2 | 76 | 16 | 13 | 47 | 30% |+| P1 | 97 | 75 | 20 | 2 | 88% |+| P2 | 76 | 17 | 13 | 46 | 31% || Area | Parity ||---|---|@@ -23,11 +23,11 @@ Each row of the InDesign feature catalogue is scored **D** (done), **P** (partia| Fill, stroke, colour | 88% || Effects & transparency | 62% || Placing & links | 82% |-| Type & text frames | 89% |+| Type & text frames | 91% || Typography | 88% || Styles | 92% || Tables | 88% |-| Long documents | 79% |+| Long documents | 88% || Interactivity & digital | 45% || Output & production | 70% || XML & automation | 50% |@@ -205,7 +205,7 @@ Open P0 items: Preferences, Vector/page formats (PDF/AI/SVG/EPS place), Export t| Type & text frames | Font menu with preview, favourites | P1 | P || Type & text frames | Missing fonts handling | P0 | D || Type & text frames | Footnotes | P1 | D |-| Type & text frames | Endnotes | P2 | M |+| Type & text frames | Endnotes | P2 | D || Type & text frames | Cross-references | P2 | D || Type & text frames | Text anchors & hyperlinks | P1 | D || Type & text frames | Data merge | P2 | D |@@ -266,7 +266,7 @@ Open P0 items: Preferences, Vector/page formats (PDF/AI/SVG/EPS place), Export t| Long documents | Numbered lists across stories | P1 | D || Long documents | Cross-references | P2 | D || Long documents | Running headers via variables | P1 | D |-| Long documents | Footnotes/endnotes | P1 | P |+| Long documents | Footnotes/endnotes | P1 | D || Long documents | Captions | P2 | P || Interactivity & digital | Hyperlinks panel | P1 | P || Interactivity & digital | Bookmarks | P1 | P |