Merge outside PR #160: feat(ui): draw and offer Georgian with Noto Sans Georgian from craft-fonts (M8)

This commit is contained in:
Tanish Manku committed 2026-11-17 13:31:38 -07:00
commit 7cc7507664
7 files changed
+90 -8

No files matched your search

+1
View File
@@ -61,6 +61,7 @@ here.
|---|---|---|---|
| Inter Regular | UI prose (primary) | The Inter Project Authors (Rasmus Andersson) | SIL OFL 1.1, shipped as `OFL-Inter.txt` |
| JetBrains Mono Regular | UI data: timeline, readouts, values, shortcuts (primary) | The JetBrains Mono Project Authors | SIL OFL 1.1, shipped as `OFL-JetBrainsMono.txt` |
| Noto Sans Georgian (variable) | Fallback face for Georgian (`Geor` in craft-fonts) | The Noto Project Authors | SIL OFL 1.1, shipped as `OFL-noto-sans-georgian.txt` |
### Optional build input: craft-i18n (not files in this repo)
+4 -2
View File
@@ -3,7 +3,8 @@
//!
//! `CRAFT_FONTS_DIR=<craft-fonts checkout> cargo build` embeds the UI typefaces chosen in
//! ADR 0005: Inter (prose) and JetBrains Mono (data), both SIL OFL 1.1. Font files are never
//! committed to this repository. Without the variable the app uses egui's bundled defaults, and
//! committed to this repository. It also embeds Noto Sans Georgian (`Geor` in craft-fonts) as a
//! fallback face, which is what lets the interface offer Georgian. Without the variable the app uses egui's bundled defaults, and
//! everything still works.
//!
//! `CRAFT_I18N_DIR=<craft-i18n checkout>` embeds the interface catalogs (ADR 0040); without it
@@ -12,7 +13,8 @@
use std::path::{Path, PathBuf};
/// Files we look for, and the generated constant each fills.
const FONTS: [(&str, &str); 2] = [("Inter-Regular.ttf", "UI_FONT"), ("JetBrainsMono-Regular.ttf", "MONO_FONT")];
const FONTS: [(&str, &str); 3] =
[("Inter-Regular.ttf", "UI_FONT"), ("JetBrainsMono-Regular.ttf", "MONO_FONT"), ("NotoSansGeorgian.ttf", "GEORGIAN_FONT")];
fn find(dir: &Path, name: &str, depth: u32) -> Option<PathBuf> {
let entries = std::fs::read_dir(dir).ok()?;
+1 -1
View File
@@ -14,7 +14,7 @@ cargo deny check licenses bans sources
cargo run --release -p anicraft-cli -- bench # performance probe
```
Fonts: builds embed Inter and JetBrains Mono when `CRAFT_FONTS_DIR` points at a craft-fonts
Fonts: builds embed Inter, JetBrains Mono and Noto Sans Georgian (the interface offers Georgian only then) when `CRAFT_FONTS_DIR` points at a craft-fonts
checkout, or when one is found next to the repository (ADR 0005). Otherwise they use the
built-in fallback fonts.
+3 -2
View File
@@ -96,7 +96,7 @@ and a trailing `…`. Then open a pull request in craft-i18n. Follow its clean-r
from the plain meaning of the English, never from another product's translated interface.
A language is offered once craft-i18n has its `anicraft.tsv` and it is in `i18n::READY`
(left-to-right Latin, Greek and Cyrillic scripts today).
(left-to-right Latin, Greek and Cyrillic scripts today, and Georgian in builds with its craft-fonts face).
## Building with translations
@@ -118,7 +118,8 @@ shaping. So:
| Script | Today |
|---|---|
| Latin, Greek, Cyrillic | Offered when a catalog exists. |
| Chinese, Japanese, Korean, Georgian | Draw correctly, but need a font the app doesn't bundle (a craft-fonts face), then a `READY` entry. |
| 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. |
| Vietnamese | Not offered yet: needs a check that every fallback face has its letters. |
+17 -2
View File
@@ -39,11 +39,26 @@ pub const PSEUDO: &str = "pseudo";
/// Languages the interface can be drawn in today: written left to right, in scripts the bundled
/// faces cover and egui lays out a letter at a time (Latin, Greek, Cyrillic). A catalog for any
/// other locale is embedded but not offered (docs/localisation.md › Scripts and direction).
/// A regional variant (`es-mx`) is ready when its language is.
/// A regional variant (`es-mx`) is ready when its language is. Georgian is not listed here: its
/// face is not bundled, so [`ready_codes`] adds it only when the build embedded Noto Sans
/// Georgian from craft-fonts.
pub const READY: &[&str] = &[
"az", "bg", "bs", "ca", "cs", "da", "de", "el", "es", "et", "fi", "fr", "gl", "hr", "hu", "id", "it", "kk", "lt", "lv", "nb", "nl", "pl", "pt", "pt-br", "ro", "ru", "sk", "sl", "sq", "sr", "sr-latn", "sv", "tr", "uk",
];
/// [`READY`] plus the languages whose script needs a craft-fonts face this build embedded.
pub fn ready_codes() -> Vec<&'static str> {
ready_with(crate::theme::georgian_font().is_some())
}
fn ready_with(georgian_face: bool) -> Vec<&'static str> {
let mut codes = READY.to_vec();
if georgian_face {
codes.push("ka");
}
codes
}
enum Kind {
English,
Pseudo,
@@ -177,7 +192,7 @@ impl Languages {
static ENGLISH_LANGUAGE: Language = Language { code: String::new(), name: String::new(), kind: Kind::English };
static LANGUAGES: LazyLock<Languages> = LazyLock::new(|| {
let (languages, problems) = Languages::new(CRAFT_I18N, READY);
let (languages, problems) = Languages::new(CRAFT_I18N, &ready_codes());
for p in problems {
eprintln!("interface catalog: {p} (shown in English)");
}
+31
View File
@@ -308,6 +308,37 @@ fn offered_languages_have_their_own_catalog_and_a_ready_script() {
assert_eq!(names, ["English", "Deutsch", "Português (Brasil)", "Русский", "Pseudo-locale (layout test)"]);
}
#[test]
fn georgian_is_offered_only_when_its_face_is_embedded() {
let ka = [("ka", "", "@id\tlanguage.name\tქართული\n")];
let offered = |face: bool| Languages::new(&ka, &ready_with(face)).0.list.iter().any(|l| l.code == "ka");
assert!(!offered(false), "no face, no Georgian");
assert!(offered(true));
// The real build agrees with its own face.
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") {
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");
return;
};
let letters: String = ('\u{10D0}'..='\u{10FA}').collect();
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 Proportional family install_fonts builds. Not Monospace: epaint's
// has_glyph is a false negative there (the Georgian face is that chain's replacement-glyph face).
let ctx = egui::Context::default();
crate::theme::install_fonts(&ctx, None, None);
ctx.run_ui(egui::RawInput::default(), |_| {}).textures_delta.clear(); // fonts apply at the start of a frame
let prop = egui::FontId::proportional(14.0);
assert!(ctx.fonts_mut(|f| f.has_glyphs(&prop, &letters)), "Proportional lacks Georgian letters");
println!("georgian face test: ran, {} letters covered", letters.chars().count());
}
#[test]
fn lookups_fall_back_from_app_to_shared_to_base_language_to_english() {
let l = fixture();
+33 -1
View File
@@ -517,6 +517,31 @@ 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 a face that parses and covers
/// the Georgian letters. 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]> {
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 that draws every Georgian letter (U+10D0..U+10FA).
fn parses_as_font(bytes: &[u8]) -> bool {
let letters: String = ('\u{10D0}'..='\u{10FA}').collect();
let fonts = anicraft_engine::text::Fonts::from_faces([bytes.to_vec()]);
fonts.layout(&letters, &anicraft_engine::text::Style::default()).is_ok_and(|laid| laid.missing == 0)
}
#[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.
pub fn font_summary() -> String {
match (craft_fonts::UI_FONT, craft_fonts::MONO_FONT) {
@@ -532,7 +557,8 @@ pub type UserFont = (String, Vec<u8>, u32);
/// Installs the UI typefaces (ADR 0005). Order in each family: the user's system font (from
/// Preferences), then the craft-fonts pair (when embedded at build time), then egui's bundled
/// fonts, which stay as fallbacks for glyph coverage.
/// fonts, which stay as fallbacks for glyph coverage, then Noto Sans Georgian (when embedded)
/// for the letters none of them has.
pub fn install_fonts(ctx: &egui::Context, ui_font: Option<&UserFont>, data_font: Option<&UserFont>) {
use egui::{FontData, FontDefinitions, FontFamily};
use std::sync::Arc;
@@ -543,6 +569,12 @@ 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) = 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());
}
}
for (user, family) in [(ui_font, FontFamily::Proportional), (data_font, FontFamily::Monospace)] {
if let Some((name, bytes, index)) = user {
let key = format!("user:{name}");