From 004adac31d0ef1bc34b3d17ca3b74aa731d66506 Mon Sep 17 00:00:00 2001 From: Fabio Guerra Date: Wed, 5 Aug 2020 01:29:54 -0300 Subject: [PATCH] Adding changes to changelog and replacing line style comments with block comments. --- CHANGELOG.md | 2 ++ src/lv_font/lv_font_loader.c | 31 ++++++++++++++++++++----------- 2 files changed, 22 insertions(+), 11 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 4afdd3327..c54f12402 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -12,6 +12,8 @@ - Add `lv_tabview_set_tab_name()` function - used to change a tab's name - Add `LV_THEME_MATERIAL_FLAG_NO_TRANSITION` and `LV_THEME_MATERIAL_FLAG_NO_FOCUS` flags - Reduce code size by adding: `LV_USE_FONT_COMPRESSED` and `LV_FONT_USE_SUBPX` and applying some optimization +- Add `lv_font_load()` function - Loads a `lv_font_t` object from a binary font file +- Add `lv_font_free()` function - Frees the memory allocated by the `lv_font_load()` function ### Bugfixes diff --git a/src/lv_font/lv_font_loader.c b/src/lv_font/lv_font_loader.c index 750cdc25d..9a4035408 100644 --- a/src/lv_font/lv_font_loader.c +++ b/src/lv_font/lv_font_loader.c @@ -80,6 +80,11 @@ static int read_bits(bit_iterator_t *it, int n_bits, lv_fs_res_t * res); * GLOBAL FUNCTIONS **********************/ +/** + * Loads a `lv_font_t` object from a binary font file + * @param font_name filename where the font file is located + * @return a pointer to the font or NULL in case of error + */ lv_font_t * lv_font_load(const char * font_name) { bool success = false; @@ -107,6 +112,10 @@ lv_font_t * lv_font_load(const char * font_name) } +/** + * Frees the memory allocated by the `lv_font_load()` function + * @param font lv_font_t object created by the lv_font_load function + */ void lv_font_free(lv_font_t * font) { if(NULL != font) { @@ -227,7 +236,7 @@ static bool lvgl_load_font(lv_fs_file_t * fp, lv_font_t * font) font->dsc = font_dsc; - // header + /* header */ int32_t header_length = read_label(fp, 0, "head"); if (header_length < 0) { return false; @@ -251,7 +260,7 @@ static bool lvgl_load_font(lv_fs_file_t * fp, lv_font_t * font) font_dsc->kern_scale = font_header.kerning_scale; font_dsc->bitmap_format = font_header.compression_id; - // cmaps + /* cmaps */ uint32_t cmaps_start = header_length; int32_t cmaps_length = read_label(fp, cmaps_start, "cmap"); if (cmaps_length < 0) { @@ -326,7 +335,7 @@ static bool lvgl_load_font(lv_fs_file_t * fp, lv_font_t * font) } } - // loca + /* loca */ uint32_t loca_start = cmaps_start + cmaps_length; int32_t loca_length = read_label(fp, loca_start, "loca"); if (loca_length < 0) { @@ -370,7 +379,7 @@ static bool lvgl_load_font(lv_fs_file_t * fp, lv_font_t * font) return false; } - // glyph + /* glyph */ uint32_t glyph_start = loca_start + loca_length; int32_t glyph_length = read_label(fp, glyph_start, "glyf"); if (glyph_length < 0) { @@ -409,10 +418,10 @@ static bool lvgl_load_font(lv_fs_file_t * fp, lv_font_t * font) break; } - // TODO: understand how to interpret advance_width_format - if(font_header.advance_width_format == 0) { // uint + /* TODO: understand how to interpret advance_width_format */ + if(font_header.advance_width_format == 0) { /* uint */ } - else if(font_header.advance_width_format == 1) { // unsigned with 4 bits fractional part + else if(font_header.advance_width_format == 1) { /* unsigned with 4 bits fractional part */ } else { LV_LOG_WARN("error unknown advance_width_format"); @@ -538,14 +547,14 @@ static bool lvgl_load_font(lv_fs_file_t * fp, lv_font_t * font) memset(kern_classes, 0, sizeof(lv_font_fmt_txt_kern_classes_t)); - font_dsc->kern_dsc = kern_classes; // TODO: review - font_dsc->kern_classes = 1; // TODO: review this + font_dsc->kern_dsc = kern_classes; /* TODO: review */ + font_dsc->kern_classes = 1; /* TODO: review this */ - if(0 == kern_format_type) { // sorted pairs + if(0 == kern_format_type) { /* sorted pairs */ LV_LOG_WARN("kern_format_type 0 not supported yet!"); return false; } - else if(3 == kern_format_type) { // array M*N of classes + else if(3 == kern_format_type) { /* array M*N of classes */ uint16_t kern_class_mapping_length; uint8_t kern_table_rows;