Tests: the font-added-later test uses a character no craft-fonts face covers

a_font_added_later_draws_characters_painted_before_it painted 编, which
Noto Sans CJK SC covers. With craft-fonts embedded (as in CI), the test's
font database already held that face, so nothing was reported and the
test failed. It now paints U+F0000, a private-use character, drawn by a
new test face (test_fonts::private_use_font) that maps only it.
This commit is contained in:
dotCooCoo
2026-11-13 07:19:20 -08:00
parent 1f64044f1c
commit 3b072ad078
2 changed files with 26 additions and 11 deletions
+13
View File
@@ -1322,6 +1322,19 @@ fn remapped_source_sans(family: &str, postscript: &str, mapping: &[(char, char)]
Some(builder.build())
}
/// The family of [`private_use_font`].
pub const PRIVATE_USE_FAMILY: &str = "Private Use Sans";
/// The character [`private_use_font`] maps: the first code point of Supplementary Private Use
/// Area-A, which no bundled or craft-fonts face covers.
pub const PRIVATE_USE_CHAR: char = '\u{F0000}';
/// A face that maps only [`PRIVATE_USE_CHAR`] to the bundled Source Sans 3 `H` outline, for tests
/// that need a character no other font covers, with or without craft-fonts.
pub fn private_use_font() -> Option<Vec<u8>> {
remapped_source_sans(PRIVATE_USE_FAMILY, "PrivateUseSans-Regular", &[(PRIVATE_USE_CHAR, 'H')])
}
/// The family of [`tall_ideograph_font`].
pub const TALL_IDEOGRAPH_FAMILY: &str = "Tall Ideograph Sans";
+13 -11
View File
@@ -485,25 +485,27 @@ mod tests {
/// A character painted while no font covers it is reported once, and draws once a font that
/// covers it is added (as the web fetches one), with no further search while the fonts stay
/// the same.
/// the same. The character is a private-use one, which no craft-fonts face covers either (the
/// database holds them when the build embeds craft-fonts).
#[test]
fn a_font_added_later_draws_characters_painted_before_it() {
use vectorcraft_text::test_fonts::{TALL_IDEOGRAPH_FAMILY, tall_ideograph_font};
use vectorcraft_text::test_fonts::{PRIVATE_USE_CHAR, PRIVATE_USE_FAMILY, private_use_font};
let db: &'static FontDb = Box::leak(Box::new(FontDb::with_font_dirs(vec![])));
let ctx = egui::Context::default();
crate::theme::install_fonts(&ctx);
let mut fonts = UiFonts::default();
frame_in(&ctx, &mut fonts, "Layer 编", db);
assert!(!has_glyph(&ctx, '编'), "no font covers 编 yet");
assert_eq!(REPORTED.with(|r| r.borrow().clone()), ['编'], "reported once");
frame_in(&ctx, &mut fonts, "Layer 编", db);
let text = format!("Layer {PRIVATE_USE_CHAR}");
frame_in(&ctx, &mut fonts, &text, db);
assert!(!has_glyph(&ctx, PRIVATE_USE_CHAR), "no font covers the character yet");
assert_eq!(REPORTED.with(|r| r.borrow().clone()), [PRIVATE_USE_CHAR], "reported once");
frame_in(&ctx, &mut fonts, &text, db);
assert!(fonts.pending.is_none() && REPORTED.with(|r| r.borrow().len()) == 1, "no new search while the fonts are the same");
db.add_font(tall_ideograph_font().expect("the test face builds"));
assert!(db.face(TALL_IDEOGRAPH_FAMILY, "Regular").is_some());
db.add_font(private_use_font().expect("the test face builds"));
assert!(db.face(PRIVATE_USE_FAMILY, "Regular").is_some());
// The next frame looks again and adds the face; the one after draws with it.
frame_in(&ctx, &mut fonts, "Layer 编", db);
frame_in(&ctx, &mut fonts, "Layer 编", db);
assert!(has_glyph(&ctx, '编'), "the added face draws 编");
frame_in(&ctx, &mut fonts, &text, db);
frame_in(&ctx, &mut fonts, &text, db);
assert!(has_glyph(&ctx, PRIVATE_USE_CHAR), "the added face draws the character");
assert!(fonts.uncovered.is_empty());
assert_eq!(REPORTED.with(|r| r.borrow().len()), 1, "a covered character is not reported again");
}