diff --git a/crates/compose/src/shape.rs b/crates/compose/src/shape.rs index 1e1af40a7..844ddfcf9 100644 --- a/crates/compose/src/shape.rs +++ b/crates/compose/src/shape.rs @@ -522,9 +522,9 @@ fn shape_run_raw( arabic_context = Some(context); } // Digits drawn in another script (World-Ready Digits): each is set as its substitute. - { + let digits = { use designcraft_doc::Digits; - let mode = if p.digits != Digits::Default { + if p.digits != Digits::Default { p.digits } else { match arabic_context { @@ -532,8 +532,10 @@ fn shape_run_raw( Some(true) if Digits::Native.map('0', &p.language) == '0' => Digits::Hindi, _ => Digits::Native, } - }; - let d = mode.map(c, &p.language); + } + }; + { + let d = digits.map(c, &p.language); if d != c { flush(seg_start, i, &seg_face, out); seg_start = i + c.len_utf8(); @@ -586,6 +588,8 @@ fn shape_run_raw( } else { sub.page_name.clone().unwrap_or_else(|| "#".into()) }; + // Page numbers take the digits of the text they stand in. + let s: String = s.chars().map(|ch| digits.map(ch, &p.language)).collect(); shape_segment(db, text, i..i + c.len_utf8(), Some(&s), p, &primary, auto_leading, style, out, sub.vertical); } designcraft_doc::OBJECT_MARK => { diff --git a/crates/compose/src/tests.rs b/crates/compose/src/tests.rs index 0d1fe2d27..b8aa481c2 100644 --- a/crates/compose/src/tests.rs +++ b/crates/compose/src/tests.rs @@ -1037,6 +1037,25 @@ fn digits_option_draws_figures_in_another_script() { assert_ne!(gid(&plain, 4), gid(&hindi, 4)); } +#[test] +fn page_numbers_take_the_digits_option() { + use designcraft_fonts::testing::font_mapping; + // Draws ١ as X, every other character as itself. + let glyphs = [('N', 'N'), ('o', 'o'), ('.', '.'), (' ', ' '), ('1', '1'), ('\u{661}', 'X')]; + designcraft_fonts::FontDb::global().add_font(font_mapping("DC Test Page Digits", &glyphs).unwrap()); + // The glyph drawn at byte 4: the page number, or a typed Arabic-Indic one. + let fourth = |text: &str| { + let (mut d, sid, _) = doc_with(text, Rect::new(100.0, 100.0, 400.0, 200.0), ParaAttrs::default()); + d.story_mut(sid).unwrap().format_chars(0..text.len(), |f| { + f.over.font_family = Some("DC Test Page Digits".into()); + f.over.digits = Some(designcraft_doc::Digits::Hindi); + }); + let cs = compose_story(&d, sid, &ComposeOptions::default()); + cs.frames[0].lines[0].glyphs.iter().find(|g| g.byte == 4).map(|g| g.gid).unwrap() + }; + assert_eq!(fourth(&format!("No. {}", story::PAGE_NUMBER)), fourth("No. \u{661}")); +} + #[test] fn ruby_and_kenten_sit_over_their_text() { let mut d = Document::new(&designcraft_doc::build::NewDocument::default());