From f5cd02a2693122ab02747882f5eb3c256cc409dd Mon Sep 17 00:00:00 2001 From: Comma Device Date: Sat, 17 Oct 2026 16:36:01 +0800 Subject: [PATCH] ui: sharpen offroad home heading --- openpilot/selfdrive/ui/layouts/home.py | 4 ++-- openpilot/system/ui/lib/application.py | 31 +++++++++++++++++++++----- 2 files changed, 28 insertions(+), 7 deletions(-) diff --git a/openpilot/selfdrive/ui/layouts/home.py b/openpilot/selfdrive/ui/layouts/home.py index 147dfd6f1..78a4fb8a2 100644 --- a/openpilot/selfdrive/ui/layouts/home.py +++ b/openpilot/selfdrive/ui/layouts/home.py @@ -184,8 +184,8 @@ class HomeLayout(Widget): def _render_home_content(self): # Display banner + logo + welcome text centered in content area (3xl style) - font = gui_app.font(FontWeight.BOLD) - tag_font = gui_app.font(FontWeight.NORMAL) + font = gui_app.high_res_text_font(FontWeight.BOLD) + tag_font = gui_app.high_res_text_font(FontWeight.NORMAL) text = "Welcome to MR.ONE" tagline = "Drive smarter. Arrive safer." # 3xl used 100/54; c3xl-dev adds 1.3x CJK scale, so divide by 1.3 to match diff --git a/openpilot/system/ui/lib/application.py b/openpilot/system/ui/lib/application.py index 83b2e1af7..6d4ee00d7 100644 --- a/openpilot/system/ui/lib/application.py +++ b/openpilot/system/ui/lib/application.py @@ -104,6 +104,7 @@ NOTO_FONTS = { } HIGH_RES_SPEED_CHARS = "0123456789.-–/ kmhp" HIGH_RES_SPEED_FONT_SIZE = 280 +HIGH_RES_TEXT_FONT_SIZE = 176 class FontWeight(StrEnum): @@ -134,7 +135,7 @@ class TextAlignmentVertical(IntEnum): def font_fallback(font: rl.Font) -> rl.Font: """Use a Noto fallback for languages not covered by Inter.""" - if multilang.requires_font_fallback() and not gui_app.is_high_res_speed_font(font): + if multilang.requires_font_fallback() and not gui_app.is_high_res_font(font): return gui_app.fallback_font() return font @@ -225,7 +226,8 @@ class GuiApplication(GuiApplicationExt): self._fonts: dict[FontWeight, rl.Font] = {} self._fallback_fonts: dict[str, rl.Font] = {} self._high_res_speed_fonts: dict[str, rl.Font] = {} - self._high_res_speed_font_ids: set[int] = set() + self._high_res_text_fonts: dict[str, rl.Font] = {} + self._high_res_font_ids: set[int] = set() self._width = width if width is not None else GuiApplication._default_width() self._height = height if height is not None else GuiApplication._default_height() @@ -766,11 +768,30 @@ class GuiApplication(GuiApplicationExt): rl.set_texture_filter(font.texture, rl.TextureFilter.TEXTURE_FILTER_TRILINEAR) self._high_res_speed_fonts[language] = font if font.texture.id != 0: - self._high_res_speed_font_ids.add(font.texture.id) + self._high_res_font_ids.add(font.texture.id) return self._high_res_speed_fonts[language] - def is_high_res_speed_font(self, font: rl.Font) -> bool: - return font.texture.id in self._high_res_speed_font_ids + def high_res_text_font(self, font_weight: FontWeight = FontWeight.BOLD) -> rl.Font: + """ASCII font rasterized near the size used by large offroad headings.""" + if not multilang.requires_font_fallback(): + return self._fonts[font_weight] + + language = multilang.language + if language not in self._high_res_text_fonts: + codepoints = list(range(32, 127)) + codepoint_buffer = rl.ffi.new("int[]", codepoints) + with as_file(FONT_DIR) as fspath: + font = rl.load_font_ex((fspath / NOTO_FONTS[language]).as_posix(), HIGH_RES_TEXT_FONT_SIZE, + rl.ffi.cast("int *", codepoint_buffer), len(codepoints)) + rl.gen_texture_mipmaps(font.texture) + rl.set_texture_filter(font.texture, rl.TextureFilter.TEXTURE_FILTER_TRILINEAR) + self._high_res_text_fonts[language] = font + if font.texture.id != 0: + self._high_res_font_ids.add(font.texture.id) + return self._high_res_text_fonts[language] + + def is_high_res_font(self, font: rl.Font) -> bool: + return font.texture.id in self._high_res_font_ids @property def width(self):