diff --git a/system/ui/lib/application.py b/system/ui/lib/application.py index 54a18d96d3..2f749ba6a0 100644 --- a/system/ui/lib/application.py +++ b/system/ui/lib/application.py @@ -360,36 +360,53 @@ class GuiApplication: return self._height def _load_fonts(self): - # Create a character set from our keyboard layouts + # Create a minimal character set for Inter (base UI/keyboard) from openpilot.system.ui.widgets.keyboard import KEYBOARD_LAYOUTS - all_chars = set() + base_chars = set() for layout in KEYBOARD_LAYOUTS.values(): - all_chars.update(key for row in layout for key in row) - all_chars |= set("–‑✓×°§•") - - # Load only the characters used in translations - for language, code in multilang.languages.items(): - all_chars |= set(language) + base_chars.update(key for row in layout for key in row) + base_chars |= set("–‑✓×°§•") + + # Build extra glyphs only for the current language if it requires Unifont + unifont_chars = set() + if multilang.requires_unifont(): + # Include language identifier text (e.g., zh-CHT) + unifont_chars |= set(multilang.language) try: - with open(os.path.join(TRANSLATIONS_DIR, f"app_{code}.po")) as f: - all_chars |= set(f.read()) + with open(os.path.join(TRANSLATIONS_DIR, f"app_{multilang.language}.po"), encoding="utf-8") as f: + unifont_chars |= set(f.read()) except FileNotFoundError: - cloudlog.warning(f"Translation file for language '{code}' not found when loading fonts.") + cloudlog.warning( + f"Translation file for current language '{multilang.language}' not found when loading fonts.") + + base_chars_str = "".join(base_chars) + cloudlog.debug(f"Loading base fonts with {len(base_chars_str)} glyphs.") - all_chars = "".join(all_chars) - cloudlog.debug(f"Loading fonts with {len(all_chars)} glyphs.") + base_count = rl.ffi.new("int *", 1) + base_codepoints = rl.load_codepoints(base_chars_str, base_count) - codepoint_count = rl.ffi.new("int *", 1) - codepoints = rl.load_codepoints(all_chars, codepoint_count) + # Prepare Unifont codepoints only if needed; include base chars so UI symbols render + unifont_codepoints = None + unifont_count = rl.ffi.new("int *", 1) + if unifont_chars: + unifont_chars_str = "".join(base_chars | unifont_chars) + cloudlog.debug(f"Loading Unifont with {len(unifont_chars_str)} glyphs.") + unifont_codepoints = rl.load_codepoints(unifont_chars_str, unifont_count) for font_weight_file in FontWeight: with as_file(FONT_DIR.joinpath(font_weight_file)) as fspath: - font = rl.load_font_ex(fspath.as_posix(), 200, codepoints, codepoint_count[0]) + if font_weight_file == FontWeight.UNIFONT and unifont_codepoints is not None: + font = rl.load_font_ex(fspath.as_posix(), 200, unifont_codepoints, unifont_count[0]) + else: + # Keep Inter lean: only load base UI/keyboard glyphs + font = rl.load_font_ex(fspath.as_posix(), 200, base_codepoints, base_count[0]) rl.set_texture_filter(font.texture, rl.TextureFilter.TEXTURE_FILTER_BILINEAR) self._fonts[font_weight_file] = font - rl.unload_codepoints(codepoints) + rl.unload_codepoints(base_codepoints) + if unifont_codepoints is not None: + rl.unload_codepoints(unifont_codepoints) rl.gui_set_font(self._fonts[FontWeight.NORMAL]) def _set_styles(self):