fix(i18n): validate the Georgian face before offering or loading it; REQUIRED alone enforces it (M8)

This commit is contained in:
Davit Matchakhelidze committed 2026-11-11 20:13:21 +04:00
1 parent 20cfea4aea
commit 39cc5484d5
3 files changed
+31 -7

No files matched your search

+1 -1
View File
@@ -118,7 +118,7 @@ shaping. So:
| Script | Today |
|---|---|
| Latin, Greek, Cyrillic | Offered when a catalog exists. |
| Georgian | Offered when a catalog exists and the build embedded Noto Sans Georgian from craft-fonts (`i18n::ready_codes`); without `CRAFT_FONTS_DIR` it stays hidden. |
| Georgian | Offered when a catalog exists and the build embedded a valid Noto Sans Georgian from craft-fonts (via `CRAFT_FONTS_DIR` or the nearby checkout `build.rs` discovers); hidden only when it did not (`i18n::ready_codes`). |
| Chinese, Japanese, Korean | Draw correctly, but need a font the app doesn't bundle (a craft-fonts face), then a `READY` entry. |
| Arabic, Hebrew, Persian, Urdu, Kurdish, Dhivehi | Not offered: right to left needs bidi and shaping in egui's text layout, and mirrored widgets. We follow upstream egui rather than fork it. |
| Devanagari, Bengali, Tamil, Telugu, Thai, Lao | Not offered: they need shaping. |
+10 -2
View File
@@ -303,8 +303,8 @@ fn georgian_is_offered_only_when_its_face_is_embedded() {
assert_eq!(ready_codes().contains(&"ka"), crate::theme::georgian_font().is_some());
// CRAFT_FONTS_REQUIRED=1 (release builds, CI with craft-fonts) makes a missing face a failure.
let face = crate::theme::georgian_font();
if std::env::var("CRAFT_FONTS_REQUIRED").is_ok_and(|v| v == "1") && std::env::var_os("CRAFT_FONTS_DIR").is_some() {
assert!(face.is_some(), "CRAFT_FONTS_DIR has no NotoSansGeorgian.ttf (craft-fonts `Geor`)");
if std::env::var("CRAFT_FONTS_REQUIRED").is_ok_and(|v| v == "1") {
assert!(face.is_some(), "CRAFT_FONTS_REQUIRED=1 but this build embeds no valid NotoSansGeorgian.ttf (craft-fonts `Geor`)");
}
let Some(face) = face else {
println!("georgian face test: skipped, this build embeds no Georgian face");
@@ -314,6 +314,14 @@ fn georgian_is_offered_only_when_its_face_is_embedded() {
let fonts = anicraft_engine::text::Fonts::from_faces([face.to_vec()]);
let laid = fonts.layout(&letters, &anicraft_engine::text::Style::default()).expect("layout");
assert_eq!(laid.missing, 0, "the face lacks some of U+10D0..U+10FA");
// ... and through the families the app really builds (Proportional and Monospace).
let ctx = egui::Context::default();
crate::theme::install_fonts(&ctx, None, None);
let _ = ctx.run(egui::RawInput::default(), |_| {}); // fonts apply at the start of a frame
for family in [egui::FontFamily::Proportional, egui::FontFamily::Monospace] {
let id = egui::FontId::new(14.0, family.clone());
assert!(ctx.fonts_mut(|f| f.has_glyphs(&id, &letters)), "{family:?} lacks Georgian letters");
}
println!("georgian face test: ran, {} letters covered", letters.chars().count());
}
+20 -4
View File
@@ -368,10 +368,26 @@ pub fn embedded_fonts() -> Vec<std::sync::Arc<[u8]>> {
[craft_fonts::UI_FONT, craft_fonts::MONO_FONT].into_iter().flatten().map(std::sync::Arc::from).collect()
}
/// Noto Sans Georgian (craft-fonts `Geor`) when this build embedded it. The interface offers
/// Georgian only then (`i18n::ready_codes`).
/// Noto Sans Georgian (craft-fonts `Geor`) when this build embedded a face that parses. The
/// interface offers Georgian only then (`i18n::ready_codes`), and `install_fonts` loads the same
/// face: epaint panics on bytes it cannot parse, so a damaged file must never reach it.
pub fn georgian_font() -> Option<&'static [u8]> {
craft_fonts::GEORGIAN_FONT
static FACE: std::sync::OnceLock<Option<&'static [u8]>> = std::sync::OnceLock::new();
*FACE.get_or_init(|| craft_fonts::GEORGIAN_FONT.filter(|b| parses_as_font(b)))
}
/// Whether `bytes` is a font file (any face in it parses).
fn parses_as_font(bytes: &[u8]) -> bool {
!anicraft_engine::text::Fonts::from_faces([bytes.to_vec()]).families().is_empty()
}
#[cfg(test)]
mod georgian_face_tests {
#[test]
fn garbage_bytes_are_not_a_font() {
assert!(!super::parses_as_font(b"not a font file at all"));
assert!(!super::parses_as_font(&[]));
}
}
/// Which typefaces are active (for About and diagnostics), in the interface language.
@@ -401,7 +417,7 @@ pub fn install_fonts(ctx: &egui::Context, ui_font: Option<&UserFont>, data_font:
defs.families.entry(family).or_default().insert(0, name.to_owned());
}
}
if let Some(b) = craft_fonts::GEORGIAN_FONT {
if let Some(b) = georgian_font() {
defs.font_data.insert("craft-noto-sans-georgian".to_owned(), Arc::new(FontData::from_static(b)));
for family in [FontFamily::Proportional, FontFamily::Monospace] {
defs.families.entry(family).or_default().push("craft-noto-sans-georgian".to_owned());