|
|
|
@ -360,36 +360,53 @@ class GuiApplication: |
|
|
|
return self._height |
|
|
|
return self._height |
|
|
|
|
|
|
|
|
|
|
|
def _load_fonts(self): |
|
|
|
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 |
|
|
|
from openpilot.system.ui.widgets.keyboard import KEYBOARD_LAYOUTS |
|
|
|
|
|
|
|
|
|
|
|
all_chars = set() |
|
|
|
base_chars = set() |
|
|
|
for layout in KEYBOARD_LAYOUTS.values(): |
|
|
|
for layout in KEYBOARD_LAYOUTS.values(): |
|
|
|
all_chars.update(key for row in layout for key in row) |
|
|
|
base_chars.update(key for row in layout for key in row) |
|
|
|
all_chars |= set("–‑✓×°§•") |
|
|
|
base_chars |= set("–‑✓×°§•") |
|
|
|
|
|
|
|
|
|
|
|
# Load only the characters used in translations |
|
|
|
# Build extra glyphs only for the current language if it requires Unifont |
|
|
|
for language, code in multilang.languages.items(): |
|
|
|
unifont_chars = set() |
|
|
|
all_chars |= set(language) |
|
|
|
if multilang.requires_unifont(): |
|
|
|
|
|
|
|
# Include language identifier text (e.g., zh-CHT) |
|
|
|
|
|
|
|
unifont_chars |= set(multilang.language) |
|
|
|
try: |
|
|
|
try: |
|
|
|
with open(os.path.join(TRANSLATIONS_DIR, f"app_{code}.po")) as f: |
|
|
|
with open(os.path.join(TRANSLATIONS_DIR, f"app_{multilang.language}.po"), encoding="utf-8") as f: |
|
|
|
all_chars |= set(f.read()) |
|
|
|
unifont_chars |= set(f.read()) |
|
|
|
except FileNotFoundError: |
|
|
|
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) |
|
|
|
base_count = rl.ffi.new("int *", 1) |
|
|
|
cloudlog.debug(f"Loading fonts with {len(all_chars)} glyphs.") |
|
|
|
base_codepoints = rl.load_codepoints(base_chars_str, base_count) |
|
|
|
|
|
|
|
|
|
|
|
codepoint_count = rl.ffi.new("int *", 1) |
|
|
|
# Prepare Unifont codepoints only if needed; include base chars so UI symbols render |
|
|
|
codepoints = rl.load_codepoints(all_chars, codepoint_count) |
|
|
|
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: |
|
|
|
for font_weight_file in FontWeight: |
|
|
|
with as_file(FONT_DIR.joinpath(font_weight_file)) as fspath: |
|
|
|
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) |
|
|
|
rl.set_texture_filter(font.texture, rl.TextureFilter.TEXTURE_FILTER_BILINEAR) |
|
|
|
self._fonts[font_weight_file] = font |
|
|
|
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]) |
|
|
|
rl.gui_set_font(self._fonts[FontWeight.NORMAL]) |
|
|
|
|
|
|
|
|
|
|
|
def _set_styles(self): |
|
|
|
def _set_styles(self): |
|
|
|
|