diff --git a/core/embed/rust/librust_fonts.h b/core/embed/rust/librust_fonts.h index a04a0bf541..17249c4b1b 100644 --- a/core/embed/rust/librust_fonts.h +++ b/core/embed/rust/librust_fonts.h @@ -1,7 +1 @@ -typedef struct { - const uint8_t* ptr; - uint32_t len; -} PointerData; - -// TODO: Theoretically, the `len` is not used by the client and does not have to be sent -PointerData get_utf8_glyph(uint16_t char_code, int font); +const uint8_t *get_utf8_glyph(uint16_t char_code, int font); diff --git a/core/embed/rust/src/trezorhal/display.rs b/core/embed/rust/src/trezorhal/display.rs index 70760abf7c..80684a7e9d 100644 --- a/core/embed/rust/src/trezorhal/display.rs +++ b/core/embed/rust/src/trezorhal/display.rs @@ -72,7 +72,7 @@ pub fn char_width(ch: char, font: i32) -> i16 { text_width(encoding, font) } -pub fn get_char_glyph(ch: u8, font: i32) -> *const u8 { +pub fn get_char_glyph(ch: u16, font: i32) -> *const u8 { unsafe { ffi::font_get_glyph(font, ch) } } diff --git a/core/embed/rust/src/ui/display/font.rs b/core/embed/rust/src/ui/display/font.rs index 0e4eaf8661..0859709355 100644 --- a/core/embed/rust/src/ui/display/font.rs +++ b/core/embed/rust/src/ui/display/font.rs @@ -144,22 +144,10 @@ impl Font { display::text_width(text, self.into()) } - /// Supports UTF8 characters - fn get_glyph_from_char(self, c: char) -> Option { - let mut buffer = [0; 4]; - let bytes = c.encode_utf8(&mut buffer); - for byte in bytes.bytes() { - if let Some(glyph) = self.get_glyph(byte) { - return Some(glyph); - } - } - None - } - /// Supports UTF8 characters fn get_first_glyph_from_text(self, text: &str) -> Option { if let Some(c) = text.chars().next() { - self.get_glyph_from_char(c) + Some(self.get_glyph(c)) } else { None } @@ -168,7 +156,7 @@ impl Font { /// Supports UTF8 characters fn get_last_glyph_from_text(self, text: &str) -> Option { if let Some(c) = text.chars().next_back() { - self.get_glyph_from_char(c) + Some(self.get_glyph(c)) } else { None } @@ -236,25 +224,21 @@ impl Font { constant::LINE_SPACE + self.text_height() } - pub fn get_glyph(self, char_byte: u8) -> Option { - let gl_data = display::get_char_glyph(char_byte, self.into()); + pub fn get_glyph(self, ch: char) -> Glyph { + let gl_data = display::get_char_glyph(ch as u16, self.into()); - if gl_data.is_null() { - return None; - } + ensure!(!gl_data.is_null(), "Failed to load glyph"); // SAFETY: Glyph::load is valid for data returned by get_char_glyph - unsafe { Some(Glyph::load(gl_data)) } + unsafe { Glyph::load(gl_data) } } pub fn display_text(self, text: &str, baseline: Point, fg_color: Color, bg_color: Color) { let colortable = get_color_table(fg_color, bg_color); let mut adv_total = 0; - for c in text.bytes() { - let g = self.get_glyph(c); - if let Some(gly) = g { - let adv = gly.print(baseline + Offset::new(adv_total, 0), colortable); - adv_total += adv; - } + for c in text.chars() { + let gly = self.get_glyph(c); + let adv = gly.print(baseline + Offset::new(adv_total, 0), colortable); + adv_total += adv; } } diff --git a/core/embed/rust/src/ui/display/mod.rs b/core/embed/rust/src/ui/display/mod.rs index 0f3ad5fa15..f43b8a534c 100644 --- a/core/embed/rust/src/ui/display/mod.rs +++ b/core/embed/rust/src/ui/display/mod.rs @@ -400,8 +400,8 @@ impl> TextOverlay { for g in self .text .as_ref() - .bytes() - .filter_map(|c| self.font.get_glyph(c)) + .chars() + .map(|c| self.font.get_glyph(c)) { let top = self.max_height - self.baseline - g.bearing_y; let char_area = Rect::new(