feat(core): add font kernings for non-ascii characters.
What changed, and why it matters
This commit updates how the Trezor device calculates spacing (kerning) between pairs of text characters so it also works for non-ASCII characters used in translations. It is a UI rendering feature change, not a security fix.
No security action needed; review as normal UI/translation feature code.
Security signals we found
No strong security signals were identified.
Evidence from the diff
The change extends FontInfo::get_kerning to handle Unicode code points above 0x7F by looking up kerning values from translation glyph data when the ‘translations’ feature is enabled. ASCII pairs continue to use the existing static kernings table. There is no evidence in the commit of a vulnerability, bounds-checking bug, or security-relevant correction.
Changed components
core/embed/rust/src/ui/display/font.rsInspect captured patch +26 / −7
diff --git a/core/embed/rust/src/ui/display/font.rs b/core/embed/rust/src/ui/display/font.rs
index d0e17076..a284646a 100644
--- a/core/embed/rust/src/ui/display/font.rs
+++ b/core/embed/rust/src/ui/display/font.rs
@@ -260,13 +260,32 @@ impl FontInfo {
ascent + descent
}
- 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;
- if let Some(kernings) = self.kernings {
- for &(l, r, v) in kernings {
- if l == left && r == right {
- return v;
+ pub fn get_kerning(&'static self, left_ch: char, right_ch: char) -> i8 {
+ let left: u16 = left_ch as u16;
+ let right: u16 = right_ch as u16;
+
+ if left >= 0x7F || right >= 0x7F {
+ #[cfg(feature = "translations")]
+ {
+ return self.with_glyph_data(|data| {
+ data.translations_guard
+ .as_ref()
+ .and_then(|guard| guard.as_ref())
+ .and_then(|translations| {
+ translations.get_utf8_kernings(left, right, self.translation_blob_idx)
+ })
+ .unwrap_or(0)
+ });
+ }
+ } else {
+ let left = left as u8;
+ let right = right as u8;
+
+ if let Some(kernings) = self.kernings {
+ for &(l, r, v) in kernings {
+ if l == left && r == right {
+ return v;
+ }
}
}
}
Why this scored 11/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.