Compose: page numbers take the Digits setting of their text

Automatic page numbers (and section markers) were set from the page name as
typed, so a page number in Hindi Digits text drew Western digits, which an
Arabic-only font shows as missing-glyph boxes. They now map their digits like
typed text does.
This commit is contained in:
aiongg
2026-10-10 11:55:28 +00:00
parent 92649ffdb0
commit e6428d2111
2 changed files with 27 additions and 4 deletions
+8 -4
View File
@@ -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 => {
+19
View File
@@ -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());