DesignCraft: An open-source page and layout design editor written by scratch in pure Rust
T: Digits (World-Ready) — figures in Arabic-Indic, Persian and native scripts
Brandon Thomasee55acd85844
diff --git a/ROADMAP.md b/ROADMAP.mdindex d7787ea1d..5c5aceef0 100644--- a/ROADMAP.md+++ b/ROADMAP.md@@ -96,7 +96,7 @@ DesignCraft aims at full Adobe InDesign parity — and to be better: faster, ope- Split Window / New Window (`window.split`, `window.newWindow`, Window ▸ Arrange): two side-by-side views of the document with their own zoom, scroll and render cache. New Window puts the second view in its own OS window (an egui viewport; a floating window on the web).- Transparency flattener (`file.exportPdf {flatten: high|medium|low|ppi}`, Edit ▸ Transparency Flattener Presets): each object involving transparency becomes an opaque image of its area over what's beneath it, so everything else stays vector (spreads with transparent parent items are rasterised whole).- Video and sound (place .mp4/.mov/.webm/.mp3/.wav…, `media.options/get`, Media panel): media frames show a poster or placeholder on screen, in print and in PDF, and export as HTML5 `<video>`/`<audio>` in EPUB. No in-app playback or PDF rich media.-- Right-to-left text (World-Ready basics): right-to-left runs are shaped right to left, lines are reordered by the Unicode Bidirectional Algorithm (matched against the reference implementation), Paragraph Direction (`type.para {direction}`, Paragraph panel, IDML ParagraphDirection, EPUB `dir`). Kashida justification, caret movement in visual order and digit substitution aren't there yet.+- Right-to-left text (World-Ready basics): right-to-left runs are shaped right to left, lines are reordered by the Unicode Bidirectional Algorithm (matched against the reference implementation), Paragraph Direction (`type.para {direction}`, Paragraph panel, IDML ParagraphDirection, EPUB `dir`). Digits (`digits`: Default, Arabic, Hindi, Farsi, Native by language; Character panel for right-to-left text; IDML DigitsType) draw 0–9 in another script. Kashida justification and caret movement in visual order aren't there yet.- Interface language (Edit ▸ Interface Language, `app.language`): German, French, Spanish and Japanese menu titles, common menu items and panel names (our own translations); dialogs and the rest of the UI stay English.- Page transitions (`page.transition/transitions`, Page Transitions panel): twelve transition types with speed and direction per spread, written into exported PDFs as `/Trans` entries through an incremental update.- PDF/X-4 export (`file.exportPdf {standard: "x4"}`): an output intent with our own Generic CMYK ICC profile (lut16 tables generated from the parametric press model), GTS_PDFXVersion in Info and XMP, and built-in PDF/X-4 checks reported as warnings. qpdf finds no errors in the result.diff --git a/crates/compose/src/shape.rs b/crates/compose/src/shape.rsindex 091aa2134..a91581bfe 100644--- a/crates/compose/src/shape.rs+++ b/crates/compose/src/shape.rs@@ -349,6 +349,17 @@ fn shape_run(};for (i, c) in text[range.clone()].char_indices() {let i = range.start + i;+ // Digits drawn in another script (World-Ready Digits): each is set as its substitute.+ if c.is_ascii_digit() && p.digits != designcraft_doc::Digits::Default {+ let d = p.digits.map(c, &p.language);+ if d != c {+ flush(seg_start, i, &seg_face, out);+ seg_start = i + 1;+ let face = if primary.covers(d) { primary.clone() } else { db.fallback_for(d, primary.id()).unwrap_or_else(|| primary.clone()) };+ shape_segment(db, text, i..i + 1, Some(d.encode_utf8(&mut [0; 4])), p, &face, auto_leading, style, out, sub.vertical);+ continue;+ }+ }let special = matches!(c,'\t' | story::FORCED_LINE_BREAKdiff --git a/crates/compose/src/tests.rs b/crates/compose/src/tests.rsindex 436d20c59..7918f47c9 100644--- a/crates/compose/src/tests.rs+++ b/crates/compose/src/tests.rs@@ -841,6 +841,23 @@ fn bidi_matches_the_reference_order() {}}+#[test]+fn digits_option_draws_figures_in_another_script() {+ let mut d = Document::new(&designcraft_doc::build::NewDocument::default());+ let lid = d.default_layer();+ let (_, sid) = d.add_text_frame(SpreadRef::Doc(0), Rect::new(100.0, 100.0, 400.0, 200.0), lid, "No. 2024", ParaFormat::default()).unwrap();+ let plain = compose_story(&d, sid, &ComposeOptions::default()).frames[0].lines[0].glyphs.clone();+ d.story_mut(sid).unwrap().format_chars(0..8, |f| f.over.digits = Some(designcraft_doc::Digits::Hindi));+ let hindi = compose_story(&d, sid, &ComposeOptions::default()).frames[0].lines[0].glyphs.clone();+ // One glyph per digit, each still mapped to its own source character.+ let digits: Vec<_> = hindi.iter().filter(|g| g.byte >= 4 && g.len > 0).collect();+ assert_eq!(digits.iter().map(|g| (g.byte, g.len)).collect::<Vec<_>>(), [(4, 1), (5, 1), (6, 1), (7, 1)]);+ // The letters are untouched; the digits are other glyphs.+ assert_eq!(plain[0].gid, hindi[0].gid);+ let gid = |gs: &[PlacedGlyph], b: usize| gs.iter().find(|g| g.byte == b).map(|g| g.gid);+ assert_ne!(gid(&plain, 4), gid(&hindi, 4));+}+#[test]fn tate_chu_yoko_sets_digits_across_one_em() {let mut d = Document::new(&designcraft_doc::build::NewDocument::default());diff --git a/crates/doc/src/attrs.rs b/crates/doc/src/attrs.rsindex a44cf6801..d8a5150dc 100644--- a/crates/doc/src/attrs.rs+++ b/crates/doc/src/attrs.rs@@ -124,6 +124,57 @@ pub enum TextDirection {RightToLeft,}+/// Digits (World-Ready): the figures 0–9 are drawn as these.+#[derive(Clone, Copy, Debug, Default, PartialEq, Eq, Serialize, Deserialize)]+#[serde(rename_all = "camelCase")]+pub enum Digits {+ /// As typed.+ #[default]+ Default,+ /// European (0123).+ Arabic,+ /// Arabic-Indic (٠١٢٣).+ Hindi,+ /// Extended Arabic-Indic, as used for Persian and Urdu (۰۱۲۳).+ Farsi,+ /// Those of the text's language (Thai, Devanagari, Bengali, Arabic, Persian…); else as typed.+ Native,+}++impl Digits {+ /// The digit `c` (0–9) is drawn as, for text in `language`.+ pub fn map(self, c: char, language: &str) -> char {+ let Some(d) = c.to_digit(10) else { return c };+ let zero = match self {+ Digits::Default | Digits::Arabic => return c,+ Digits::Hindi => 0x0660,+ Digits::Farsi => 0x06F0,+ Digits::Native => {+ let l = language.to_ascii_lowercase();+ match () {+ _ if l.starts_with("arabic") => 0x0660,+ _ if l.starts_with("persian") || l.starts_with("farsi") || l.starts_with("urdu") => 0x06F0,+ _ if l.starts_with("hindi") || l.starts_with("marathi") || l.starts_with("nepali") || l.starts_with("sanskrit") => 0x0966,+ _ if l.starts_with("bengali") => 0x09E6,+ _ if l.starts_with("gujarati") => 0x0AE6,+ _ if l.starts_with("punjabi") => 0x0A66,+ _ if l.starts_with("tamil") => 0x0BE6,+ _ if l.starts_with("telugu") => 0x0C66,+ _ if l.starts_with("kannada") => 0x0CE6,+ _ if l.starts_with("malayalam") => 0x0D66,+ _ if l.starts_with("thai") => 0x0E50,+ _ if l.starts_with("lao") => 0x0ED0,+ _ if l.starts_with("tibetan") => 0x0F20,+ _ if l.starts_with("burmese") => 0x1040,+ _ if l.starts_with("khmer") => 0x17E0,+ _ => return c,+ }+ }+ };+ char::from_u32(zero + d).unwrap_or(c)+ }+}+/// A tracked change on text.#[derive(Clone, Copy, Debug, Default, PartialEq, Eq, Serialize, Deserialize)]#[serde(rename_all = "camelCase")]@@ -480,6 +531,8 @@ attr_set! {no_break: bool = false,/// Tate-chu-yoko: in vertical text, the run is set horizontally within one em of the line.tate_chu_yoko: bool = false,+ /// Digits (World-Ready): how 0–9 are drawn.+ digits: Digits = Digits::Default,language: String = "English: USA".into(),/// Additional OpenType features, e.g. `["onum", "ss01"]`.otf_features: Vec<String> = Vec::new(),@@ -580,6 +633,16 @@ attr_set! {mod tests {use super::*;+ #[test]+ fn digits_map_to_their_script() {+ assert_eq!(Digits::Default.map('7', "Arabic"), '7');+ assert_eq!(Digits::Hindi.map('3', ""), '\u{0663}');+ assert_eq!(Digits::Farsi.map('0', ""), '\u{06F0}');+ assert_eq!(Digits::Native.map('5', "Thai"), '\u{0E55}');+ assert_eq!(Digits::Native.map('5', "English: USA"), '5');+ assert_eq!(Digits::Hindi.map('x', ""), 'x');+ }+#[test]fn merge_and_resolve() {let mut a = CharAttrs { size: Some(10.0), ..Default::default() };diff --git a/crates/idml/src/export.rs b/crates/idml/src/export.rsindex 87ebd1f3b..d5754862d 100644--- a/crates/idml/src/export.rs+++ b/crates/idml/src/export.rs@@ -1037,6 +1037,9 @@ impl<'a> Ex<'a> {if let Some(v) = a.no_break {el.set("NoBreak", bool_s(v));}+ if let Some(v) = a.digits {+ el.set("DigitsType", names::digits_out(v));+ }if let Some(v) = a.tate_chu_yoko {el.set("Tatechuyoko", bool_s(v));}diff --git a/crates/idml/src/import.rs b/crates/idml/src/import.rsindex b57f57be7..17bf39206 100644--- a/crates/idml/src/import.rs+++ b/crates/idml/src/import.rs@@ -1070,6 +1070,7 @@ impl<'r> Importer<'r> {}a.no_break = e.boolean("NoBreak");a.tate_chu_yoko = e.boolean("Tatechuyoko");+ a.digits = e.get("DigitsType").and_then(names::digits_in);if let Some(v) = e.get("AppliedConditions").filter(|v| !v.trim().is_empty()) {let names: Vec<String> = v.split_whitespace().filter_map(|r| self.condition_names.get(r).cloned()).collect();if !names.is_empty() {diff --git a/crates/idml/src/names.rs b/crates/idml/src/names.rsindex e3a87346b..ae2805bda 100644--- a/crates/idml/src/names.rs+++ b/crates/idml/src/names.rs@@ -636,3 +636,18 @@ pub fn path_align_in(v: &str) -> designcraft_doc::PathAlign {_ => designcraft_doc::PathAlign::Baseline,}}++pub fn digits_out(d: designcraft_doc::Digits) -> &'static str {+ use designcraft_doc::Digits;+ match d {+ Digits::Default => "DefaultDigits",+ Digits::Arabic => "ArabicDigits",+ Digits::Hindi => "HindiDigits",+ Digits::Farsi => "FarsiDigits",+ Digits::Native => "NativeDigits",+ }+}+pub fn digits_in(s: &str) -> Option<designcraft_doc::Digits> {+ use designcraft_doc::Digits;+ [Digits::Default, Digits::Arabic, Digits::Hindi, Digits::Farsi, Digits::Native].into_iter().find(|d| digits_out(*d) == s)+}diff --git a/crates/ui-egui/src/panels/properties.rs b/crates/ui-egui/src/panels/properties.rsindex 68566c9b5..bb29f41a6 100644--- a/crates/ui-egui/src/panels/properties.rs+++ b/crates/ui-egui/src/panels/properties.rs@@ -1196,6 +1196,22 @@ pub fn character_panel(app: &mut DesignApp, ui: &mut egui::Ui) {}});});+ // Digits (World-Ready): shown for right-to-left paragraphs or once set.+ let digits = c["digits"].as_str().unwrap_or("default").to_string();+ if digits != "default" || a["para"]["direction"].as_str() == Some("rightToLeft") {+ ui.horizontal(|ui| {+ caption(ui, "Digits");+ let opts = [("default", "Default"), ("arabic", "Arabic"), ("hindi", "Hindi"), ("farsi", "Farsi"), ("native", "Native")];+ let cur = opts.iter().find(|o| o.0 == digits).map_or("Default", |o| o.1);+ egui::ComboBox::from_id_salt("char_digits").selected_text(cur).width(120.0).show_ui(ui, |ui| {+ for (k, l) in opts {+ if ui.selectable_label(k == digits, l).clicked() {+ let _ = app.run("type.char", json!({"attrs": {"digits": k}}));+ }+ }+ });+ });+ }egui::Grid::new("chargrid").num_columns(4).spacing(vec2(6.0, 4.0)).show(ui, |ui| {caption(ui, "Size");if let Some(v) = number(ui, "pcs", c["size"].as_f64(), " pt", 60.0, 2) {