fix(ui/fonts): make font kernings optional.
What changed, and why it matters
This commit changes the font system so that kerning (spacing adjustments between letter pairs) can be omitted when generating a font. It is a build/code-generation feature change, not a security fix or vulnerability.
No security action required; review as normal UI/build tooling change.
Security signals we found
No strong security signals were identified.
Evidence from the diff
The patch makes the kernings field of FontInfo an Option<&'static [(u8, u8, i8)]> and updates the font code generator to conditionally emit kerning arrays based on a new gen_kernings flag. The Rust rendering code now checks for Some(kernings) before iterating. No memory-safety bug, bounds error, or cryptographic issue is present in the diff.
Changed components
core/embed/rust/src/ui/display/font.rscore/tools/codegen/gen_font.makocore/tools/codegen/gen_font.pyInspect captured patch +19 / −7
diff --git a/core/embed/rust/src/ui/display/font.rs b/core/embed/rust/src/ui/display/font.rs
index 76c8b01d..d0e17076 100644
--- a/core/embed/rust/src/ui/display/font.rs
+++ b/core/embed/rust/src/ui/display/font.rs
@@ -21,7 +21,7 @@ pub struct FontInfo {
pub baseline: i16,
pub glyph_data: &'static [&'static [u8]],
pub glyph_nonprintable: &'static [u8],
- pub kernings: &'static [(u8, u8, i8)],
+ pub kernings: Option<&'static [(u8, u8, i8)]>,
}
/// Convenience type for font references defined in the `fonts` module.
pub type Font = &'static FontInfo;
@@ -263,9 +263,11 @@ impl FontInfo {
pub fn get_kerning(&self, left_ch: char, right_ch: char) -> i8 {
let left: u8 = left_ch as u8;
let right = right_ch as u8;
- for &(l, r, v) in self.kernings {
- if l == left && r == right {
- return v;
+ if let Some(kernings) = self.kernings {
+ for &(l, r, v) in kernings {
+ if l == left && r == right {
+ return v;
+ }
}
}
0
diff --git a/core/tools/codegen/gen_font.mako b/core/tools/codegen/gen_font.mako
index 3aa911ab..0ba5603e 100644
--- a/core/tools/codegen/gen_font.mako
+++ b/core/tools/codegen/gen_font.mako
@@ -33,7 +33,7 @@ const Font_${name}_upper: [&[u8]; ${len(glyph_array_upper)}] = [
% endfor
];
% endif
-% if gen_normal:
+% if gen_kernings:
/// Array of kerning tripples
const Font_${name}_kernings: [(u8, u8, i8); ${len(kernings)}] = [
@@ -44,7 +44,6 @@ const Font_${name}_kernings: [(u8, u8, i8); ${len(kernings)}] = [
% endif
% if gen_normal:
-
/// FontInfo struct for normal ASCII usage
pub const Font_${name}_info: FontInfo = FontInfo {
translation_blob_idx: ${font_info["translation_blob_idx"]},
@@ -53,7 +52,11 @@ pub const Font_${name}_info: FontInfo = FontInfo {
baseline: ${font_info["baseline"]},
glyph_data: &${font_info["glyph_array"]},
glyph_nonprintable: &${font_info["nonprintable"]},
- kernings: &${font_info["kernings"]},
+%if gen_kernings:
+ kernings: &${font_info_upper["kernings"]},
+%else:
+ kernings: None,
+%endif
};
% endif
% if gen_upper:
@@ -66,6 +69,10 @@ pub const Font_${name}_upper_info: FontInfo = FontInfo {
baseline: ${font_info_upper["baseline"]},
glyph_data: &${font_info_upper["glyph_array"]},
glyph_nonprintable: &${font_info_upper["nonprintable"]},
+%if gen_kernings:
kernings: &${font_info_upper["kernings"]},
+%else:
+ kernings: None,
+%endif
};
% endif
diff --git a/core/tools/codegen/gen_font.py b/core/tools/codegen/gen_font.py
index 4953ca00..9f4292af 100755
--- a/core/tools/codegen/gen_font.py
+++ b/core/tools/codegen/gen_font.py
@@ -248,6 +248,7 @@ class FaceProcessor:
ext: str = "ttf",
gen_normal: bool = True, # generate font with all the letters
gen_upper: bool = False, # generate font with only upper-cased letters
+ gen_kernings: bool = False, # generate kerning data
font_idx: int | None = None, # idx to UTF-8 foreign chars data
font_idx_upper: int | None = None, # idx to UTF-8 upper-cased foreign chars
) -> None:
@@ -266,6 +267,7 @@ class FaceProcessor:
self.ext = ext
self.gen_normal = gen_normal
self.gen_upper = gen_upper
+ self.gen_kernings = gen_kernings
self.face = freetype.Face(str(FONTS_DIR / f"{name}-{style}.{ext}"))
self.face.set_pixel_sizes(0, size)
@@ -491,6 +493,7 @@ class FaceProcessor:
"kernings": kernings,
"gen_normal": self.gen_normal,
"gen_upper": self.gen_upper,
+ "gen_kernings": self.gen_kernings,
"font_info": font_info,
"font_info_upper": font_info_upper,
}
Why this scored 15/100
Community notes
Notes can correct, qualify, or add evidence to the AI analysis. Every note shown here has been validated by a human moderator.
The AI analysis stands alone for now. Submit a note if you can add evidence or important context.