From 0acabe460cb78266849c6ca48c1714b6ff631d0b Mon Sep 17 00:00:00 2001 From: Gabor Kiss-Vamosi Date: Tue, 28 May 2019 08:46:43 +0200 Subject: [PATCH] font: add new types --- src/lv_fonts/lv_font_dejavu_20.c | 10 +-- src/lv_fonts/lv_font_template.c | 104 +++++++++++----------- src/lv_misc/lv_font_fmt/lv_font_fmt_txt.h | 53 ++++++----- 3 files changed, 90 insertions(+), 77 deletions(-) diff --git a/src/lv_fonts/lv_font_dejavu_20.c b/src/lv_fonts/lv_font_dejavu_20.c index 264df6dd8..a9d582d4a 100644 --- a/src/lv_fonts/lv_font_dejavu_20.c +++ b/src/lv_fonts/lv_font_dejavu_20.c @@ -95,7 +95,7 @@ static uint8_t kern_pair_values[] = 15, 52, 73 }; -static lv_font_kern_pair_fmt_txt_t kern_pairs = +static lv_font_fmt_txt_kern_pair_t kern_pairs = { .left_gylph_ids = kern_left_gylph_ids, .right_gylph_ids = kern_right_gylph_ids, @@ -119,7 +119,7 @@ static uint8_t kern_class_values = }; -static lv_font_kern_classes_fmt_txt_t kern_classes = +static lv_font_fmt_txt_kern_classes_t kern_classes = { .class_pair_values = kern_class_values, .left_class_mapping = kern_left_class_mapping, @@ -136,20 +136,20 @@ static uint8_t glyph_id_ofs_list_3 = {32, 45, 66}; /*Store the glyph descriptions*/ -static const lv_font_cmap_fmt_txt_t cmaps[] = { +static const lv_font_fmt_txt_cmap_t cmaps[] = { { .range_start = 0x280, .range_length = 124, .glyph_id_start = 223, .unicode_list = uniocde_list_1, .glyph_id_ofs_list = glyph_id_ofs_list_1}, { .range_start = 0x20, .range_length = 112, .glyph_id_start = 456, .unicode_list = NULL, .glyph_id_ofs_list = NULL}, { .range_start = 0x560, .range_length = 7654, .glyph_id_start = 756, .unicode_list = NULL, .glyph_id_ofs_list = glyph_id_ofs_list_3}, }; -static lv_font_glyph_dsc_fmt_txt_t glyph_dsc[] = { +static lv_font_fmt_txt_glyph_dsc_t glyph_dsc[] = { {.bitmap_index = 0, .adv_w = 123, .box_h = 13, .box_w = 9, .ofs_x = 2, .ofs_y = 5}, {.bitmap_index = 32, .adv_w = 234, .box_h = 12, .box_w = 7, .ofs_x = 1, .ofs_y = 3}, {.bitmap_index = 55, .adv_w = 98, .box_h = 11, .box_w = 8, .ofs_x = 0, .ofs_y = 4}, }; -static lv_font_dsc_fmt_txt_t font_dsc = { +static lv_font_fmt_txt_dsc_t font_dsc = { .glyph_bitmap = gylph_bitmap, .glyph_dsc = glyph_dsc, .cmaps = cmaps, diff --git a/src/lv_fonts/lv_font_template.c b/src/lv_fonts/lv_font_template.c index 2ad51f29e..3b2f057a1 100644 --- a/src/lv_fonts/lv_font_template.c +++ b/src/lv_fonts/lv_font_template.c @@ -37,10 +37,11 @@ static const uint8_t gylph_bitmap[] = { * GLYPH DESCRIPTION *--------------------*/ -static lv_font_glyph_dsc_fmt_txt_t glyph_dsc[] = { - {.bitmap_index = 0, .adv_w = 23, .box_h = 13, .box_w = 9, .ofs_x = 2, .ofs_y = 5}, - {.bitmap_index = 32, .adv_w = 44, .box_h = 12, .box_w = 7, .ofs_x = 1, .ofs_y = 3}, - {.bitmap_index = 55, .adv_w = 29, .box_h = 11, .box_w = 8, .ofs_x = 0, .ofs_y = 4}, +static lv_font_fmt_txt_glyph_dsc_t glyph_dsc[] = +{ + {.bitmap_index = 0, .adv_w = 23, .box_h = 13, .box_w = 9, .ofs_x = 2, .ofs_y = 5}, + {.bitmap_index = 32, .adv_w = 44, .box_h = 12, .box_w = 7, .ofs_x = 1, .ofs_y = 3}, + {.bitmap_index = 55, .adv_w = 29, .box_h = 11, .box_w = 8, .ofs_x = 0, .ofs_y = 4}, }; /*--------------------- @@ -54,35 +55,32 @@ static uint8_t glyph_id_ofs_list_3 = {32, 45, 66}; /*Collect the unicode lists and glyph_id offsets*/ -static const lv_font_cmap_fmt_txt_t cmaps[] = { - { - .range_start = 0x280, .range_length = 124, .type = LV_FONT_FMT_TXT_CMAP_SPARSE_FULL, - .glyph_id_start = 223, .unicode_list = unicode_list_1, .glyph_id_ofs_list = glyph_id_ofs_list_1 - }, - { - .range_start = 0x20, .range_length = 112, .type = LV_FONT_FMT_TXT_CMAP_FORMAT0_TINY, - .glyph_id_start = 456, .unicode_list = NULL, .glyph_id_ofs_list = NULL - }, - { - .range_start = 0x560, .range_length = 7654, .type = LV_FONT_FMT_TXT_CMAP_FORMAT0_FULL, - .glyph_id_start = 756, .unicode_list = NULL, .glyph_id_ofs_list = glyph_id_ofs_list_3}, - +static const lv_font_fmt_txt_cmap_t cmaps[] = +{ + { + .range_start = 0x280, .range_length = 124, .type = LV_FONT_FMT_TXT_CMAP_SPARSE_FULL, + .glyph_id_start = 223, .unicode_list = unicode_list_1, .glyph_id_ofs_list = glyph_id_ofs_list_1 + }, + { + .range_start = 0x20, .range_length = 112, .type = LV_FONT_FMT_TXT_CMAP_FORMAT0_TINY, + .glyph_id_start = 456, .unicode_list = NULL, .glyph_id_ofs_list = NULL + }, + { + .range_start = 0x560, .range_length = 7654, .type = LV_FONT_FMT_TXT_CMAP_FORMAT0_FULL, + .glyph_id_start = 756, .unicode_list = NULL, .glyph_id_ofs_list = glyph_id_ofs_list_3 + }, }; /*----------------- * KERNING *----------------*/ -/*Left glyphs for kering*/ -static uint16_t kern_left_gylph_ids[] = +/*Pair left and right glyphs for kerning*/ +static lv_font_fmt_txt_kern_pair_id_t kern_pair_gylph_ids[] = { - 0x21, 0x42, 0x53 -}; - -/*Left glyphs for kering*/ -static uint16_t kern_right_gylph_ids[] = -{ - 0x41, 0x342, 0x333 + {.pair.left = 0x23, .pair.right = 0x283}, + {.pair.left = 0x43, .pair.right = 0x383}, + {.pair.left = 0x73, .pair.right = 0x583}, }; /* Kerning between the respective left and right glyphs @@ -93,10 +91,9 @@ static int8_t kern_pair_values[] = }; /*Collect the kern pair's data in one place*/ -static lv_font_kern_pair_fmt_txt_t kern_pairs = +static lv_font_fmt_txt_kern_pair_t kern_pairs = { - .left_gylph_ids = kern_left_gylph_ids, - .right_gylph_ids = kern_right_gylph_ids, + .glyph_ids = kern_pair_gylph_ids, .values = kern_pair_values, .pair_cnt = 3, }; @@ -106,52 +103,55 @@ static lv_font_kern_pair_fmt_txt_t kern_pairs = /*Map glyph_ids to kern left classes*/ static uint8_t kern_left_class_mapping[] = { - 1, 2, 1, 1, 1, 1, 1, 1 + 1, 2, 1, 1, 1, 1, 1, 1 }; /*Map glyph_ids to kern right classes*/ static uint8_t kern_right_class_mapping[] = { - 1, 2, 3, 2, 2, 3, 3, 1 + 1, 2, 3, 2, 2, 3, 3, 1 }; /* Kern values between classes * 4.4 format which needs to scaled with `kern_scale`*/ static int8_t kern_class_values = { - 44, -66, 24, -23, 56, 23 + 44, -66, 24, -23, 56, 23 }; - /*Collect the kern class' data in one place*/ -static lv_font_kern_classes_fmt_txt_t kern_classes = +static lv_font_fmt_txt_kern_classes_t kern_classes = { - .class_pair_values = kern_class_values, - .left_class_mapping = kern_left_class_mapping, - .right_class_mapping = kern_right_class_mapping, - .left_class_cnt = 2, - .right_class_cnt = 3, + .class_pair_values = kern_class_values, + .left_class_mapping = kern_left_class_mapping, + .right_class_mapping = kern_right_class_mapping, + .left_class_cnt = 2, + .right_class_cnt = 3, }; - /*-------------------- * ALL CUSTOM DATA *--------------------*/ /*Store all the custom data of the font*/ -static lv_font_dsc_fmt_txt_t font_dsc = { - .glyph_bitmap = gylph_bitmap, - .glyph_dsc = glyph_dsc, - .cmaps = cmaps, - .cmap_num = 3, - .bpp = 4, +static lv_font_fmt_txt_dsc_t font_dsc = { + .glyph_bitmap = gylph_bitmap, + .glyph_dsc = glyph_dsc, + .cmaps = cmaps, + .cmap_num = 3, + .bpp = 4, + .bitmap_format = LV_FONT_FMT_TXT_PLAIN, - .kerning_scale = 324, - .kern_dsc = kern_classes, - .kern_classes = 1, - /*** OR ***/ - .kern_dsc = kern_pairs, - .kern_classes = 0, + .kerning_scale = 324, + + .kern_dsc = kern_classes, + .kern_classes = 1, + /*** OR ***/ + .kern_dsc = kern_pairs, + .kern_classes = 0, + /*** OR ***/ + .kern_dsc = NULL, + .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 c4a36ae38..7474c5241 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 @@ -43,7 +43,7 @@ typedef struct uint8_t box_h; /*Height of the glyph's bounding box*/ int8_t ofs_x; /*x offset of the bounding box*/ uint8_t ofs_y; /*y offset of the bounding box. Measured from the top of the line*/ -}lv_font_glyph_dsc_fmt_txt_t; +}lv_font_fmt_txt_glyph_dsc_t; typedef enum { @@ -100,31 +100,39 @@ typedef struct { uint16_t * unicode_list; - /* if unicode_list == NULL uint8_t * - * else uint16_t * + /* if(type == LV_FONT_FMT_TXT_CMAP_FORMAT0_...) it's `uint8_t *` + * if(type == LV_FONT_FMT_TXT_CMAP_SPARSE_...) it's `uint16_t *` */ const void * glyph_id_ofs_list; -}lv_font_cmap_fmt_txt_t; +}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_cmap_built_in_t + 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(left_gylph_ids[i] == glyph_id_left && - right_gylph_ids[i] == glyph_id_right) + if(gylph_ids[i].pair.left == glyph_id_left && + gylph_ids[i].pair.right == glyph_id_right) return values[i]; */ - uint16_t * left_gylph_ids; - uint16_t * right_gylph_ids; + lv_font_fmt_txt_kern_pair_id_t glyph_ids; uint8_t * values; uint16_t pair_cnt; -}lv_font_kern_pair_fmt_txt_t; +}lv_font_fmt_txt_kern_pair_t; /*More complex but more optimal class based kern value storage*/ typedef struct { /*To get a kern value of two code points: - 1. Get the `glyph_id_left` and `glyph_id_right` from `lv_font_cmap_built_in_t + 1. Get the `glyph_id_left` and `glyph_id_right` from `lv_font_fmt_txt_cmap_t 2 Get the class of the left and right glyphs as `left_class` and `right_class` for(i = 0; i < left_class_num; i++) if(left_class_mapping[i] == glyph_id_left) @@ -137,7 +145,15 @@ typedef struct { uint8_t * right_class_mapping; /*Map the glyph_ids to classes: index -> glyph_id -> class_id*/ uint8_t left_class_cnt; uint8_t right_class_cnt; -}lv_font_kern_classes_fmt_txt_t; +}lv_font_fmt_txt_kern_classes_t; + + +/*Bitmap formats*/ +typedef enum { + LV_FONT_FMT_TXT_PLAIN = 0, + LV_FONT_FMT_TXT_COMPRESSED = 1, +}lv_font_fmt_txt_bitmap_format_t; + /*Describe store additional data for fonts */ typedef struct { @@ -145,14 +161,14 @@ typedef struct { const uint8_t * glyph_bitmap; /*Describe the glyphs*/ - const lv_font_glyph_dsc_fmt_txt_t * glyph_dsc; + const lv_font_fmt_txt_glyph_dsc_t * glyph_dsc; /* Map the glyphs to Unicode characters. * Array of `lv_font_cmap_fmt_txt_t` variables*/ - const lv_font_cmap_fmt_txt_t * cmaps; + const lv_font_fmt_txt_cmap_t * cmaps; /* Store kerning values. - * Can be `lv_font_kern_pair_fmt_txt_t * or `lv_font_kern_classes_fmt_txt_t *` + * Can be `lv_font_fmt_txt_kern_pair_t * or `lv_font_kern_classes_fmt_txt_t *` * depending on `kern_classes` */ const void * kern_dsc; @@ -171,13 +187,10 @@ typedef struct { /* * storage format of the bitmap - * 0: plain - * 1: compressed: RLE with XOR pre-filter - * 2: reserved - * 3: reserved + * from `lv_font_fmt_txt_bitmap_format_t` */ uint16_t bitmap_format :2; -}lv_font_dsc_fmt_txt_t; +}lv_font_fmt_txt_dsc_t; /********************** * GLOBAL PROTOTYPES