Skip to content

Commit

Permalink
refactor(core): use font_id_t instead of plain int
Browse files Browse the repository at this point in the history
[no changelog]
  • Loading branch information
obrusvit committed Sep 19, 2024
1 parent 6e50231 commit 94db1ee
Show file tree
Hide file tree
Showing 8 changed files with 40 additions and 35 deletions.
18 changes: 10 additions & 8 deletions core/embed/lib/display_draw.c
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ void display_bar(int x, int y, int w, int h, uint16_t c) {
display_pixeldata_dirty();
}

void display_text_render_buffer(const char *text, int textlen, int font,
void display_text_render_buffer(const char *text, int textlen, font_id_t font,
buffer_text_t *buffer, int text_offset) {
// determine text length if not provided
if (textlen < 0) {
Expand Down Expand Up @@ -159,7 +159,8 @@ void display_text_render_buffer(const char *text, int textlen, int font,

#ifdef FRAMEBUFFER
static void display_text_render(int x, int y, const char *text, int textlen,
int font, uint16_t fgcolor, uint16_t bgcolor) {
font_id_t font, uint16_t fgcolor,
uint16_t bgcolor) {
// determine text length if not provided
if (textlen < 0) {
textlen = strlen(text);
Expand Down Expand Up @@ -226,7 +227,8 @@ static void display_text_render(int x, int y, const char *text, int textlen,

#else
static void display_text_render(int x, int y, const char *text, int textlen,
int font, uint16_t fgcolor, uint16_t bgcolor) {
font_id_t font, uint16_t fgcolor,
uint16_t bgcolor) {
// determine text length if not provided
if (textlen < 0) {
textlen = strlen(text);
Expand Down Expand Up @@ -282,23 +284,23 @@ static void display_text_render(int x, int y, const char *text, int textlen,
}
#endif

void display_text(int x, int y, const char *text, int textlen, int font,
void display_text(int x, int y, const char *text, int textlen, font_id_t font,
uint16_t fgcolor, uint16_t bgcolor) {
x += DISPLAY_OFFSET.x;
y += DISPLAY_OFFSET.y;
display_text_render(x, y, text, textlen, font, fgcolor, bgcolor);
}

void display_text_center(int x, int y, const char *text, int textlen, int font,
uint16_t fgcolor, uint16_t bgcolor) {
void display_text_center(int x, int y, const char *text, int textlen,
font_id_t font, uint16_t fgcolor, uint16_t bgcolor) {
x += DISPLAY_OFFSET.x;
y += DISPLAY_OFFSET.y;
int w = font_text_width(font, text, textlen);
display_text_render(x - w / 2, y, text, textlen, font, fgcolor, bgcolor);
}

void display_text_right(int x, int y, const char *text, int textlen, int font,
uint16_t fgcolor, uint16_t bgcolor) {
void display_text_right(int x, int y, const char *text, int textlen,
font_id_t font, uint16_t fgcolor, uint16_t bgcolor) {
x += DISPLAY_OFFSET.x;
y += DISPLAY_OFFSET.y;
int w = font_text_width(font, text, textlen);
Expand Down
12 changes: 6 additions & 6 deletions core/embed/lib/display_draw.h
Original file line number Diff line number Diff line change
Expand Up @@ -35,13 +35,13 @@ void display_clear(void);

void display_bar(int x, int y, int w, int h, uint16_t c);

void display_text(int x, int y, const char *text, int textlen, int font,
void display_text(int x, int y, const char *text, int textlen, font_id_t font,
uint16_t fgcolor, uint16_t bgcolor);
void display_text_center(int x, int y, const char *text, int textlen, int font,
uint16_t fgcolor, uint16_t bgcolor);
void display_text_right(int x, int y, const char *text, int textlen, int font,
uint16_t fgcolor, uint16_t bgcolor);
void display_text_render_buffer(const char *text, int textlen, int font,
void display_text_center(int x, int y, const char *text, int textlen,
font_id_t font, uint16_t fgcolor, uint16_t bgcolor);
void display_text_right(int x, int y, const char *text, int textlen,
font_id_t font, uint16_t fgcolor, uint16_t bgcolor);
void display_text_render_buffer(const char *text, int textlen, font_id_t font,
buffer_text_t *buffer, int text_offset);

void display_qrcode(int x, int y, const char *data, uint8_t scale);
Expand Down
14 changes: 7 additions & 7 deletions core/embed/lib/fonts/fonts.c
Original file line number Diff line number Diff line change
Expand Up @@ -96,22 +96,22 @@ static const font_info_t *get_font_info(font_id_t font_id) {
}
}

int font_height(int font_id) {
int font_height(font_id_t font_id) {
const font_info_t *font_info = get_font_info(font_id);
return font_info ? font_info->height : 0;
}

int font_max_height(int font) {
int font_max_height(font_id_t font) {
const font_info_t *font_info = get_font_info(font);
return font_info ? font_info->max_height : 0;
}

int font_baseline(int font) {
int font_baseline(font_id_t font) {
const font_info_t *font_info = get_font_info(font);
return font_info ? font_info->baseline : 0;
}

const uint8_t *font_get_glyph(int font, uint16_t c) {
const uint8_t *font_get_glyph(font_id_t font, uint16_t c) {
#ifdef TRANSLATIONS
// found UTF8 character
// it is not hardcoded in firmware fonts, it must be extracted from the
Expand All @@ -136,12 +136,12 @@ const uint8_t *font_get_glyph(int font, uint16_t c) {
return font_nonprintable_glyph(font);
}

const uint8_t *font_nonprintable_glyph(int font) {
const uint8_t *font_nonprintable_glyph(font_id_t font) {
const font_info_t *font_info = get_font_info(font);
return font_info ? font_info->glyph_nonprintable : NULL;
}

font_glyph_iter_t font_glyph_iter_init(const int font, const uint8_t *text,
font_glyph_iter_t font_glyph_iter_init(font_id_t font, const uint8_t *text,
const int len) {
return (font_glyph_iter_t){
.font = font,
Expand Down Expand Up @@ -212,7 +212,7 @@ bool font_next_glyph(font_glyph_iter_t *iter, const uint8_t **out) {
}

// compute the width of the text (in pixels)
int font_text_width(int font, const char *text, int textlen) {
int font_text_width(font_id_t font, const char *text, int textlen) {
int width = 0;
// determine text length if not provided
if (textlen < 0) {
Expand Down
14 changes: 7 additions & 7 deletions core/embed/lib/fonts/fonts.h
Original file line number Diff line number Diff line change
Expand Up @@ -54,15 +54,15 @@
TREZOR_FONT_MONO_ENABLE ? FONT_MONO_MAX_HEIGHT : 0)
// clang-format on

int font_height(int font);
int font_max_height(int font);
int font_baseline(int font);
const uint8_t *font_get_glyph(int font, uint16_t c);
const uint8_t *font_nonprintable_glyph(int font);
int font_height(font_id_t font);
int font_max_height(font_id_t font);
int font_baseline(font_id_t font);
const uint8_t *font_get_glyph(font_id_t font, const uint16_t c);
const uint8_t *font_nonprintable_glyph(font_id_t font);

font_glyph_iter_t font_glyph_iter_init(const int font, const uint8_t *text,
font_glyph_iter_t font_glyph_iter_init(font_id_t font, const uint8_t *text,
const int len);
bool font_next_glyph(font_glyph_iter_t *iter, const uint8_t **out);
int font_text_width(int font, const char *text, int textlen);
int font_text_width(font_id_t font, const char *text, int textlen);

#endif //_FONTS_H
2 changes: 1 addition & 1 deletion core/embed/lib/fonts/fonts_types.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ typedef enum {

/// Font glyph iterator structure
typedef struct {
const int font;
const font_id_t font;
const uint8_t* text;
int remaining;
} font_glyph_iter_t;
Expand Down
6 changes: 3 additions & 3 deletions core/embed/lib/gfx_draw.c
Original file line number Diff line number Diff line change
Expand Up @@ -297,7 +297,7 @@ void display_bar(int x, int y, int w, int h, uint16_t c) {
gfx_draw_bar(gfx_rect_wh(x, y, w, h), c);
}

void display_text(int x, int y, const char* text, int textlen, int font,
void display_text(int x, int y, const char* text, int textlen, font_id_t font,
uint16_t fg_color, uint16_t bg_color) {
gfx_text_attr_t attr = {
.font = font,
Expand All @@ -309,8 +309,8 @@ void display_text(int x, int y, const char* text, int textlen, int font,
gfx_draw_text(gfx_offset(x, y), text, maxlen, &attr);
}

void display_text_center(int x, int y, const char* text, int textlen, int font,
uint16_t fg_color, uint16_t bg_color) {
void display_text_center(int x, int y, const char* text, int textlen,
font_id_t font, uint16_t fg_color, uint16_t bg_color) {
gfx_text_attr_t attr = {
.font = font,
.fg_color = fg_color,
Expand Down
4 changes: 3 additions & 1 deletion core/embed/rust/librust_fonts.h
Original file line number Diff line number Diff line change
@@ -1 +1,3 @@
const uint8_t *get_utf8_glyph(uint16_t char_code, int font);
#include "fonts/fonts_types.h"

const uint8_t *get_utf8_glyph(uint16_t char_code, font_id_t font);
5 changes: 3 additions & 2 deletions core/embed/trezorhal/xdisplay_legacy.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,9 @@
#ifndef TREZORHAL_DISPLAY_LEGACY_H
#define TREZORHAL_DISPLAY_LEGACY_H

#include <buffers.h>
#include <stdint.h>
#include "buffers.h"
#include "fonts/fonts_types.h"

// These declarationscode emulates will be removed after the
// final cleanup of display drivers. They are here just to simplify
Expand All @@ -48,7 +49,7 @@ void display_pixeldata(uint16_t c);
uint32_t* display_get_fb_addr(void);

void display_clear(void);
void display_text_render_buffer(const char* text, int textlen, int font,
void display_text_render_buffer(const char* text, int textlen, font_id_t font,
buffer_text_t* buffer, int text_offset);

#define PIXELDATA(c) display_pixeldata(c)
Expand Down

0 comments on commit 94db1ee

Please sign in to comment.