1
0
mirror of https://github.com/trezor/trezor-firmware.git synced 2025-02-12 15:42:40 +00:00

refactor(core): map FontInfo to translation idx

[no changelog]
This commit is contained in:
obrusvit 2025-01-24 20:17:23 +01:00 committed by Vít Obrusník
parent be459019b8
commit e73ca8b481
16 changed files with 59 additions and 31 deletions

View File

@ -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;

View File

@ -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,

View File

@ -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,

View File

@ -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,

View File

@ -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,

View File

@ -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,

View File

@ -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,

View File

@ -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,

View File

@ -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,

View File

@ -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,

View File

@ -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,

View File

@ -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,

View File

@ -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,

View File

@ -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,

View File

@ -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;

View File

@ -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 = {