From e73ca8b481217c2eb6001513854123ff409b9333 Mon Sep 17 00:00:00 2001 From: obrusvit Date: Fri, 24 Jan 2025 20:17:23 +0100 Subject: [PATCH] refactor(core): map FontInfo to translation idx [no changelog] --- core/embed/rust/src/ui/display/font.rs | 5 +- .../fonts/font_robotomono_medium_20.rs | 1 + .../layout_bolt/fonts/font_tthoves_bold_17.rs | 1 + .../fonts/font_tthoves_demibold_21.rs | 1 + .../fonts/font_tthoves_regular_21.rs | 1 + .../fonts/font_pixeloperator_bold_8.rs | 2 + .../fonts/font_pixeloperator_regular_8.rs | 2 + .../fonts/font_pixeloperatormono_regular_8.rs | 1 + .../fonts/font_unifont_bold_16.rs | 1 + .../fonts/font_unifont_regular_16.rs | 1 + .../fonts/font_robotomono_medium_21.rs | 1 + .../fonts/font_ttsatoshi_demibold_18.rs | 1 + .../fonts/font_ttsatoshi_demibold_21.rs | 1 + .../fonts/font_ttsatoshi_demibold_42.rs | 1 + core/embed/rust/src/ui/mod.rs | 13 ----- core/tools/codegen/gen_font.py | 57 ++++++++++++++----- 16 files changed, 59 insertions(+), 31 deletions(-) diff --git a/core/embed/rust/src/ui/display/font.rs b/core/embed/rust/src/ui/display/font.rs index dcf9941024..3813068eed 100644 --- a/core/embed/rust/src/ui/display/font.rs +++ b/core/embed/rust/src/ui/display/font.rs @@ -17,6 +17,7 @@ use crate::translations::Translations; /// Font information structure containing metadata and pointers to font data #[derive(PartialEq, Eq)] pub struct FontInfo { + pub translation_blob_idx: u16, pub height: i16, pub max_height: i16, pub baseline: i16, @@ -179,9 +180,7 @@ impl GlyphData { .as_ref() .and_then(|guard| guard.as_ref()) .and_then(|translations| { - // let font_id = font_to_font_id(self.font); - let font_id = 1; - translations.get_utf8_glyph(codepoint, font_id) + translations.get_utf8_glyph(codepoint, self.font.translation_blob_idx) }) { return glyph; diff --git a/core/embed/rust/src/ui/layout_bolt/fonts/font_robotomono_medium_20.rs b/core/embed/rust/src/ui/layout_bolt/fonts/font_robotomono_medium_20.rs index a7362b4067..18c50721d4 100644 --- a/core/embed/rust/src/ui/layout_bolt/fonts/font_robotomono_medium_20.rs +++ b/core/embed/rust/src/ui/layout_bolt/fonts/font_robotomono_medium_20.rs @@ -397,6 +397,7 @@ const Font_RobotoMono_Medium_20: [&[u8]; 95] = [ /// FontInfo struct for normal ASCII usage pub const Font_RobotoMono_Medium_20_info: FontInfo = FontInfo { + translation_blob_idx: 3, height: 20, max_height: 22, baseline: 5, diff --git a/core/embed/rust/src/ui/layout_bolt/fonts/font_tthoves_bold_17.rs b/core/embed/rust/src/ui/layout_bolt/fonts/font_tthoves_bold_17.rs index ff57108d0f..aab3e04a1c 100644 --- a/core/embed/rust/src/ui/layout_bolt/fonts/font_tthoves_bold_17.rs +++ b/core/embed/rust/src/ui/layout_bolt/fonts/font_tthoves_bold_17.rs @@ -319,6 +319,7 @@ const Font_TTHoves_Bold_17_upper: [&[u8]; 95] = [ /// FontInfo struct for forced uppercase usage pub const Font_TTHoves_Bold_17_upper_info: FontInfo = FontInfo { + translation_blob_idx: 7, height: 17, max_height: 18, baseline: 4, diff --git a/core/embed/rust/src/ui/layout_bolt/fonts/font_tthoves_demibold_21.rs b/core/embed/rust/src/ui/layout_bolt/fonts/font_tthoves_demibold_21.rs index 71f964fed1..5cecf68404 100644 --- a/core/embed/rust/src/ui/layout_bolt/fonts/font_tthoves_demibold_21.rs +++ b/core/embed/rust/src/ui/layout_bolt/fonts/font_tthoves_demibold_21.rs @@ -397,6 +397,7 @@ const Font_TTHoves_DemiBold_21: [&[u8]; 95] = [ /// FontInfo struct for normal ASCII usage pub const Font_TTHoves_DemiBold_21_info: FontInfo = FontInfo { + translation_blob_idx: 5, height: 21, max_height: 21, baseline: 4, diff --git a/core/embed/rust/src/ui/layout_bolt/fonts/font_tthoves_regular_21.rs b/core/embed/rust/src/ui/layout_bolt/fonts/font_tthoves_regular_21.rs index 4cafb4a910..69ac897b72 100644 --- a/core/embed/rust/src/ui/layout_bolt/fonts/font_tthoves_regular_21.rs +++ b/core/embed/rust/src/ui/layout_bolt/fonts/font_tthoves_regular_21.rs @@ -397,6 +397,7 @@ const Font_TTHoves_Regular_21: [&[u8]; 95] = [ /// FontInfo struct for normal ASCII usage pub const Font_TTHoves_Regular_21_info: FontInfo = FontInfo { + translation_blob_idx: 1, height: 21, max_height: 21, baseline: 4, diff --git a/core/embed/rust/src/ui/layout_caesar/fonts/font_pixeloperator_bold_8.rs b/core/embed/rust/src/ui/layout_caesar/fonts/font_pixeloperator_bold_8.rs index 7a806f9e1e..c202e1d1dd 100644 --- a/core/embed/rust/src/ui/layout_caesar/fonts/font_pixeloperator_bold_8.rs +++ b/core/embed/rust/src/ui/layout_caesar/fonts/font_pixeloperator_bold_8.rs @@ -498,6 +498,7 @@ const Font_PixelOperator_Bold_8_upper: [&[u8]; 95] = [ /// FontInfo struct for normal ASCII usage pub const Font_PixelOperator_Bold_8_info: FontInfo = FontInfo { + translation_blob_idx: 2, height: 8, max_height: 8, baseline: 1, @@ -507,6 +508,7 @@ pub const Font_PixelOperator_Bold_8_info: FontInfo = FontInfo { /// FontInfo struct for forced uppercase usage pub const Font_PixelOperator_Bold_8_upper_info: FontInfo = FontInfo { + translation_blob_idx: 7, height: 8, max_height: 8, baseline: 1, diff --git a/core/embed/rust/src/ui/layout_caesar/fonts/font_pixeloperator_regular_8.rs b/core/embed/rust/src/ui/layout_caesar/fonts/font_pixeloperator_regular_8.rs index 63d487b79c..6f8ebde2ed 100644 --- a/core/embed/rust/src/ui/layout_caesar/fonts/font_pixeloperator_regular_8.rs +++ b/core/embed/rust/src/ui/layout_caesar/fonts/font_pixeloperator_regular_8.rs @@ -498,6 +498,7 @@ const Font_PixelOperator_Regular_8_upper: [&[u8]; 95] = [ /// FontInfo struct for normal ASCII usage pub const Font_PixelOperator_Regular_8_info: FontInfo = FontInfo { + translation_blob_idx: 1, height: 8, max_height: 8, baseline: 1, @@ -507,6 +508,7 @@ pub const Font_PixelOperator_Regular_8_info: FontInfo = FontInfo { /// FontInfo struct for forced uppercase usage pub const Font_PixelOperator_Regular_8_upper_info: FontInfo = FontInfo { + translation_blob_idx: 6, height: 8, max_height: 8, baseline: 1, diff --git a/core/embed/rust/src/ui/layout_caesar/fonts/font_pixeloperatormono_regular_8.rs b/core/embed/rust/src/ui/layout_caesar/fonts/font_pixeloperatormono_regular_8.rs index 8b468a9098..af7fa70bc8 100644 --- a/core/embed/rust/src/ui/layout_caesar/fonts/font_pixeloperatormono_regular_8.rs +++ b/core/embed/rust/src/ui/layout_caesar/fonts/font_pixeloperatormono_regular_8.rs @@ -401,6 +401,7 @@ const Font_PixelOperatorMono_Regular_8: [&[u8]; 95] = [ /// FontInfo struct for normal ASCII usage pub const Font_PixelOperatorMono_Regular_8_info: FontInfo = FontInfo { + translation_blob_idx: 3, height: 8, max_height: 8, baseline: 1, diff --git a/core/embed/rust/src/ui/layout_caesar/fonts/font_unifont_bold_16.rs b/core/embed/rust/src/ui/layout_caesar/fonts/font_unifont_bold_16.rs index 241e5ff13a..8c876fb357 100644 --- a/core/embed/rust/src/ui/layout_caesar/fonts/font_unifont_bold_16.rs +++ b/core/embed/rust/src/ui/layout_caesar/fonts/font_unifont_bold_16.rs @@ -397,6 +397,7 @@ const Font_Unifont_Bold_16: [&[u8]; 95] = [ /// FontInfo struct for normal ASCII usage pub const Font_Unifont_Bold_16_info: FontInfo = FontInfo { + translation_blob_idx: 5, height: 16, max_height: 15, baseline: 2, diff --git a/core/embed/rust/src/ui/layout_caesar/fonts/font_unifont_regular_16.rs b/core/embed/rust/src/ui/layout_caesar/fonts/font_unifont_regular_16.rs index 6136506b0b..f0b6775f4c 100644 --- a/core/embed/rust/src/ui/layout_caesar/fonts/font_unifont_regular_16.rs +++ b/core/embed/rust/src/ui/layout_caesar/fonts/font_unifont_regular_16.rs @@ -401,6 +401,7 @@ const Font_Unifont_Regular_16: [&[u8]; 95] = [ /// FontInfo struct for normal ASCII usage pub const Font_Unifont_Regular_16_info: FontInfo = FontInfo { + translation_blob_idx: 4, height: 16, max_height: 15, baseline: 2, diff --git a/core/embed/rust/src/ui/layout_delizia/fonts/font_robotomono_medium_21.rs b/core/embed/rust/src/ui/layout_delizia/fonts/font_robotomono_medium_21.rs index d1320af99c..ef93582f21 100644 --- a/core/embed/rust/src/ui/layout_delizia/fonts/font_robotomono_medium_21.rs +++ b/core/embed/rust/src/ui/layout_delizia/fonts/font_robotomono_medium_21.rs @@ -397,6 +397,7 @@ const Font_RobotoMono_Medium_21: [&[u8]; 95] = [ /// FontInfo struct for normal ASCII usage pub const Font_RobotoMono_Medium_21_info: FontInfo = FontInfo { + translation_blob_idx: 3, height: 21, max_height: 23, baseline: 5, diff --git a/core/embed/rust/src/ui/layout_delizia/fonts/font_ttsatoshi_demibold_18.rs b/core/embed/rust/src/ui/layout_delizia/fonts/font_ttsatoshi_demibold_18.rs index 3678b729bd..8e433d4a7b 100644 --- a/core/embed/rust/src/ui/layout_delizia/fonts/font_ttsatoshi_demibold_18.rs +++ b/core/embed/rust/src/ui/layout_delizia/fonts/font_ttsatoshi_demibold_18.rs @@ -399,6 +399,7 @@ const Font_TTSatoshi_DemiBold_18: [&[u8]; 95] = [ /// FontInfo struct for normal ASCII usage pub const Font_TTSatoshi_DemiBold_18_info: FontInfo = FontInfo { + translation_blob_idx: 8, height: 18, max_height: 19, baseline: 4, diff --git a/core/embed/rust/src/ui/layout_delizia/fonts/font_ttsatoshi_demibold_21.rs b/core/embed/rust/src/ui/layout_delizia/fonts/font_ttsatoshi_demibold_21.rs index fd5272f4ce..f7d2634fd7 100644 --- a/core/embed/rust/src/ui/layout_delizia/fonts/font_ttsatoshi_demibold_21.rs +++ b/core/embed/rust/src/ui/layout_delizia/fonts/font_ttsatoshi_demibold_21.rs @@ -399,6 +399,7 @@ const Font_TTSatoshi_DemiBold_21: [&[u8]; 95] = [ /// FontInfo struct for normal ASCII usage pub const Font_TTSatoshi_DemiBold_21_info: FontInfo = FontInfo { + translation_blob_idx: 1, height: 21, max_height: 21, baseline: 4, diff --git a/core/embed/rust/src/ui/layout_delizia/fonts/font_ttsatoshi_demibold_42.rs b/core/embed/rust/src/ui/layout_delizia/fonts/font_ttsatoshi_demibold_42.rs index 9bd12208ec..6adca37a04 100644 --- a/core/embed/rust/src/ui/layout_delizia/fonts/font_ttsatoshi_demibold_42.rs +++ b/core/embed/rust/src/ui/layout_delizia/fonts/font_ttsatoshi_demibold_42.rs @@ -195,6 +195,7 @@ const Font_TTSatoshi_DemiBold_42: [&[u8]; 95] = [ /// FontInfo struct for normal ASCII usage pub const Font_TTSatoshi_DemiBold_42_info: FontInfo = FontInfo { + translation_blob_idx: 1, height: 42, max_height: 44, baseline: 9, diff --git a/core/embed/rust/src/ui/mod.rs b/core/embed/rust/src/ui/mod.rs index d0053293df..4fe5b62b77 100644 --- a/core/embed/rust/src/ui/mod.rs +++ b/core/embed/rust/src/ui/mod.rs @@ -44,16 +44,3 @@ pub type ModelUI = crate::ui::layout_caesar::UICaesar; #[cfg(feature = "layout_bolt")] pub type ModelUI = crate::ui::layout_bolt::UIBolt; - -// Re-export fonts for each layout -#[cfg(all( - feature = "layout_bolt", - not(feature = "layout_delizia"), - not(feature = "layout_caesar") -))] -#[cfg(feature = "layout_bolt")] -pub use layout_bolt::fonts; -#[cfg(all(feature = "layout_caesar", not(feature = "layout_delizia")))] -pub use layout_caesar::fonts; -#[cfg(feature = "layout_delizia")] -pub use layout_delizia::fonts; diff --git a/core/tools/codegen/gen_font.py b/core/tools/codegen/gen_font.py index 49f8b6be2c..5702c9eea5 100755 --- a/core/tools/codegen/gen_font.py +++ b/core/tools/codegen/gen_font.py @@ -268,6 +268,8 @@ 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 + 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 ): if gen_normal is False and gen_upper is False: raise ValueError( @@ -277,6 +279,8 @@ class FaceProcessor: self.name = name self.style = style self.size = size + self.font_idx = font_idx + self.font_idx_upper = font_idx_upper self.bpp = bpp self.shaveX = shaveX self.ext = ext @@ -563,8 +567,13 @@ class FaceProcessor: font_info = None font_info_upper = None if self.gen_normal: + if self.font_idx is None: + raise ValueError( + f"font_idx must be set when generating FontInfo for {self._name_style_size}" + ) font_info = { "variant": "normal", + "translation_blob_idx": self.font_idx, "height": self.size, "max_height": self.font_ymax - self.font_ymin, "baseline": -self.font_ymin, @@ -572,8 +581,13 @@ class FaceProcessor: "nonprintable": f"Font_{self._name_style_size}_glyph_nonprintable", } if self.gen_upper: + if self.font_idx_upper is None: + raise ValueError( + f"font_idx_upper must be set when generating `only_upper` FontInfo for {self._name_style_size}" + ) font_info_upper = { "variant": "upper", + "translation_blob_idx": self.font_idx_upper, "height": self.size, "max_height": self.font_ymax - self.font_ymin, "baseline": -self.font_ymin, @@ -608,14 +622,18 @@ class FaceProcessor: def gen_layout_bolt(gen_c: bool = False): global LAYOUT_NAME LAYOUT_NAME = "bolt" - FaceProcessor("Roboto", "Regular", 20).write_files(gen_c) - FaceProcessor("Roboto", "Bold", 20).write_files(gen_c) - FaceProcessor("TTHoves", "Regular", 21, ext="otf").write_files(gen_c) - FaceProcessor("TTHoves", "DemiBold", 21, ext="otf").write_files(gen_c) + FaceProcessor("TTHoves", "Regular", 21, ext="otf", font_idx=1).write_files(gen_c) + FaceProcessor("TTHoves", "DemiBold", 21, ext="otf", font_idx=5).write_files(gen_c) FaceProcessor( - "TTHoves", "Bold", 17, ext="otf", gen_normal=False, gen_upper=True + "TTHoves", + "Bold", + 17, + ext="otf", + gen_normal=False, + gen_upper=True, + font_idx_upper=7, ).write_files(gen_c) - FaceProcessor("RobotoMono", "Medium", 20).write_files(gen_c) + FaceProcessor("RobotoMono", "Medium", 20, font_idx=3).write_files(gen_c) def gen_layout_caesar(gen_c: bool = False): @@ -629,6 +647,8 @@ def gen_layout_caesar(gen_c: bool = False): shaveX=1, gen_normal=True, gen_upper=True, + font_idx=1, + font_idx_upper=6, ).write_files(gen_c) FaceProcessor( "PixelOperator", @@ -638,22 +658,29 @@ def gen_layout_caesar(gen_c: bool = False): shaveX=1, gen_normal=True, gen_upper=True, + font_idx=2, + font_idx_upper=7, + ).write_files(gen_c) + FaceProcessor( + "PixelOperatorMono", "Regular", 8, bpp=1, shaveX=1, font_idx=3 + ).write_files(gen_c) + FaceProcessor( + "Unifont", "Regular", 16, bpp=1, shaveX=1, ext="otf", font_idx=4 ).write_files(gen_c) - FaceProcessor("PixelOperatorMono", "Regular", 8, bpp=1, shaveX=1).write_files(gen_c) - FaceProcessor("Unifont", "Regular", 16, bpp=1, shaveX=1, ext="otf").write_files( - gen_c - ) # NOTE: Unifont Bold does not seem to have czech characters - FaceProcessor("Unifont", "Bold", 16, bpp=1, shaveX=1, ext="otf").write_files(gen_c) + FaceProcessor( + "Unifont", "Bold", 16, bpp=1, shaveX=1, ext="otf", font_idx=5 + ).write_files(gen_c) def gen_layout_delizia(gen_c: bool = False): global LAYOUT_NAME LAYOUT_NAME = "delizia" - FaceProcessor("TTSatoshi", "DemiBold", 42, ext="otf").write_files(gen_c) - FaceProcessor("TTSatoshi", "DemiBold", 21, ext="otf").write_files(gen_c) - FaceProcessor("TTSatoshi", "DemiBold", 18, ext="otf").write_files(gen_c) - FaceProcessor("RobotoMono", "Medium", 21).write_files(gen_c) + # FIXME: BIG font id not needed + FaceProcessor("TTSatoshi", "DemiBold", 42, ext="otf", font_idx=1).write_files(gen_c) + FaceProcessor("TTSatoshi", "DemiBold", 21, ext="otf", font_idx=1).write_files(gen_c) + FaceProcessor("TTSatoshi", "DemiBold", 18, ext="otf", font_idx=8).write_files(gen_c) + FaceProcessor("RobotoMono", "Medium", 21, font_idx=3).write_files(gen_c) LAYOUTS = {