From 56d7b986d4851889ee69382be511339acd738424 Mon Sep 17 00:00:00 2001 From: Gabor Kiss-Vamosi Date: Fri, 31 May 2019 05:21:27 +0200 Subject: [PATCH] font: save the original generated font --- src/lv_fonts/lvgl_sample.c | 24 +++++++++++------------ src/lv_misc/lv_font_fmt/lv_font_fmt_txt.h | 22 +++++++-------------- 2 files changed, 19 insertions(+), 27 deletions(-) diff --git a/src/lv_fonts/lvgl_sample.c b/src/lv_fonts/lvgl_sample.c index 454723e5c..9820f26e3 100644 --- a/src/lv_fonts/lvgl_sample.c +++ b/src/lv_fonts/lvgl_sample.c @@ -3,7 +3,7 @@ /******************************************************************************* * Size: 16 px * Bpp: 1 - * Opts: --bpp 1 --size 16 --font ./Roboto-Regular.ttf -r 0x20-0x7F --format lvgl -o ./lvgl_sample.c + * Opts: --no-compress --no-prefilter --bpp 1 --size 16 --font ./Roboto-Regular.ttf -r 0x20-0x7F --format lvgl -o ./lvgl_sample.c ******************************************************************************/ /*----------------- @@ -374,15 +374,15 @@ static const uint8_t gylph_bitmap[] = { /* U+7E "~" */ 0x7, 0x66, 0xdc, 0x20, 0x0 -}; +} /*--------------------- * GLYPH DESCRIPTION *--------------------*/ -static const lv_font_fmt_txt_glyph_dsc_t glyph_dsc[] = { - {.bitmap_index = 0, .adv_w = 0, .box_h = 0, .box_w = 0, .ofs_x = 0, .ofs_y = 0}, // id = 0 reserved, +static lv_font_glyph_dsc_fmt_txt_t glyph_dsc[] = { + {.bitmap_index = 0, .adv_w = 0, .box_h = 0, .box_w = 0, .ofs_x = 0, .ofs_y = 0} // id = 0 reserved, {.bitmap_index = 0, .adv_w = 64, .box_h = 0, .box_w = 0, .ofs_x = 0, .ofs_y = 0}, {.bitmap_index = 0, .adv_w = 67, .box_h = 12, .box_w = 2, .ofs_x = 1, .ofs_y = 0}, {.bitmap_index = 3, .adv_w = 92, .box_h = 5, .box_w = 5, .ofs_x = 0, .ofs_y = 7}, @@ -478,7 +478,7 @@ static const lv_font_fmt_txt_glyph_dsc_t glyph_dsc[] = { {.bitmap_index = 1036, .adv_w = 63, .box_h = 15, .box_w = 2, .ofs_x = 1, .ofs_y = -3}, {.bitmap_index = 1040, .adv_w = 87, .box_h = 16, .box_w = 5, .ofs_x = 0, .ofs_y = -3}, {.bitmap_index = 1050, .adv_w = 174, .box_h = 4, .box_w = 9, .ofs_x = 1, .ofs_y = 3} -}; +} /*--------------------- @@ -495,7 +495,7 @@ static const lv_font_fmt_txt_cmap_t cmaps[] = .range_start = 32, .range_length = 95, .type = LV_FONT_FMT_TXT_CMAP_FORMAT0_TINY, .glyph_id_start = 1, .unicode_list = NULL, .glyph_id_ofs_list = NULL } -}; +} /*----------------- @@ -504,7 +504,7 @@ static const lv_font_fmt_txt_cmap_t cmaps[] = /*Pair left and right glyphs for kerning*/ -static const lv_font_fmt_txt_kern_pair_id_t kern_pair_glyph_ids[] = +static lv_font_fmt_txt_kern_pair_id_t kern_pair_glyph_ids[] = { {.pair.left = 9, .pair.right = 43}, {.pair.left = 9, .pair.right = 55}, @@ -994,7 +994,7 @@ static const lv_font_fmt_txt_kern_pair_id_t kern_pair_glyph_ids[] = /* Kerning between the respective left and right glyphs * 4.4 format which needs to scaled with `kern_scale`*/ -static const int8_t kern_pair_values[] = +static int8_t kern_pair_values[] = { -12, 5, 5, 6, 1, -4, 0, 1, 0, 1, -5, 1, -1, -1, -1, 0, @@ -1060,7 +1060,7 @@ static const int8_t kern_pair_values[] = }; /*Collect the kern pair's data in one place*/ -static const lv_font_fmt_txt_kern_pair_t kern_pairs = +static lv_font_fmt_txt_kern_pair_t kern_pairs = { .glyph_ids = kern_pair_glyph_ids, .values = kern_pair_values, @@ -1073,17 +1073,17 @@ static const lv_font_fmt_txt_kern_pair_t kern_pairs = *--------------------*/ /*Store all the custom data of the font*/ -static const lv_font_fmt_txt_dsc_t font_dsc = { +static lv_font_dsc_fmt_txt_t font_dsc = { .glyph_bitmap = gylph_bitmap, .glyph_dsc = glyph_dsc, .cmaps = cmaps, .cmap_num = 1, .bpp = 1, - .kern_scale = 16, + .kerning_scale = 16, //.kern_dsc = kern_classes, //.kern_classes = 1, - .kern_dsc = &kern_pairs, + .kern_dsc = kern_pairs, .kern_classes = 0, }; diff --git a/src/lv_misc/lv_font_fmt/lv_font_fmt_txt.h b/src/lv_misc/lv_font_fmt/lv_font_fmt_txt.h index 83af9e37f..22965aa8c 100644 --- a/src/lv_misc/lv_font_fmt/lv_font_fmt_txt.h +++ b/src/lv_misc/lv_font_fmt/lv_font_fmt_txt.h @@ -110,27 +110,19 @@ typedef struct { lv_font_fmt_txt_cmap_type_t type :2; }lv_font_fmt_txt_cmap_t; -/*Describe glyph pairs for kerning*/ -typedef union { - struct { - uint16_t left; - uint16_t right; - }pair; - uint32_t both; -}lv_font_fmt_txt_kern_pair_id_t; - /*A simple mapping of kern values from pairs*/ typedef struct { /*To get a kern value of two code points: 1. Get the `glyph_id_left` and `glyph_id_right` from `lv_font_fmt_txt_cmap_t - 2 for(i = 0; i < pair_cnt; i++) - if(gylph_ids[i].pair.left == glyph_id_left && - gylph_ids[i].pair.right == glyph_id_right) - return values[i]; + 2 for(i = 0; i < pair_cnt; i+2) + if(gylph_ids[i] == glyph_id_left && + gylph_ids[i+1] == glyph_id_right) + return values[i / 2]; */ - const lv_font_fmt_txt_kern_pair_id_t * glyph_ids; + const void * glyph_ids; const uint8_t * values; - uint16_t pair_cnt; + uint32_t pair_cnt :24; + uint32_t glyph_ids_size :2; /*1: `glyph_ids` is stored as `uint8_t`; 2: as `uint16_t`*/ }lv_font_fmt_txt_kern_pair_t; /*More complex but more optimal class based kern value storage*/