diff options
| -rw-r--r-- | src/displayapp/fonts/neofont.c | 238 |
1 files changed, 176 insertions, 62 deletions
diff --git a/src/displayapp/fonts/neofont.c b/src/displayapp/fonts/neofont.c index 163e7e0..b1abad4 100644 --- a/src/displayapp/fonts/neofont.c +++ b/src/displayapp/fonts/neofont.c @@ -25,7 +25,7 @@ #define X 1 #define _ 0 -static uint8_t glyphs[][2] = { +static const uint8_t glyphs[][2] = { G( _, X, _, X, _, X, X, _, X, @@ -38,8 +38,8 @@ static uint8_t glyphs[][2] = { _, X, _, X, X, X ), - G( _, X, _, - X, _, X, + G( X, X, _, + _, _, X, _, _, X, _, X, _, X, X, X ), @@ -243,6 +243,12 @@ static uint8_t glyphs[][2] = { X, X, X ), + G( _, X, _, + _, X, _, + _, X, _, + _, X, _, + _, X, _ ), + G( _, _, _, _, _, _, X, X, X, @@ -320,7 +326,7 @@ static uint8_t glyphs[][2] = { * Store the result in `dsc_out`. * The next letter (`unicode_letter_next`) might be used to calculate the width required by this glyph (kerning) */ -static bool neofont0_glyph_dsc_cb(const lv_font_t * font, lv_font_glyph_dsc_t * dsc_out, uint32_t unicode_letter, uint32_t unicode_letter_next) +static bool neofont0mono_glyph_dsc_cb(const lv_font_t * font, lv_font_glyph_dsc_t * dsc_out, uint32_t unicode_letter, uint32_t unicode_letter_next) { /*Your code here*/ @@ -338,7 +344,7 @@ static bool neofont0_glyph_dsc_cb(const lv_font_t * font, lv_font_glyph_dsc_t * } /* Get the bitmap of `unicode_letter` from `font`. */ -static const uint8_t * neofont0_glyph_bitmap_cb(const lv_font_t * font, uint32_t unicode_letter) +static const uint8_t * neofont0mono_glyph_bitmap_cb(const lv_font_t * font, uint32_t unicode_letter) { static const uint8_t spc[2] = {0,0}; /* Your code here */ @@ -356,7 +362,7 @@ static const uint8_t * neofont0_glyph_bitmap_cb(const lv_font_t * font, uint32_t } if (unicode_letter == ' ') { return spc; } - static const char *symbols = "-/:.,_?!%#"; + static const char *symbols = "|-/:.,_?!%#"; if (unicode_letter < 0x80) { char*x = strchr(symbols,((uint8_t)unicode_letter)); if (x != NULL) { @@ -372,9 +378,9 @@ static const uint8_t * neofont0_glyph_bitmap_cb(const lv_font_t * font, uint32_t return glyphs[sizeof(glyphs)/sizeof(glyphs[0])-2]; } -lv_font_t neofont0 = { - .get_glyph_dsc = neofont0_glyph_dsc_cb, /*Set a callback to get info about gylphs*/ - .get_glyph_bitmap = neofont0_glyph_bitmap_cb, /*Set a callback to get bitmap of a glyp*/ +const lv_font_t neofont0mono = { + .get_glyph_dsc = neofont0mono_glyph_dsc_cb, /*Set a callback to get info about gylphs*/ + .get_glyph_bitmap = neofont0mono_glyph_bitmap_cb, /*Set a callback to get bitmap of a glyp*/ .line_height = 6, /*The real line height where any text fits*/ .base_line = 1, /*Base line measured from the top of line_height*/ .dsc = 0, /*Store any implementation specific data here*/ @@ -388,7 +394,7 @@ lv_font_t neofont0 = { .user_data = 0 /*Optionally some extra user data*/ }; -static bool neofont1_glyph_dsc_cb(const lv_font_t * font, lv_font_glyph_dsc_t * dsc_out, uint32_t unicode_letter, uint32_t unicode_letter_next) +static bool neofont1mono_glyph_dsc_cb(const lv_font_t * font, lv_font_glyph_dsc_t * dsc_out, uint32_t unicode_letter, uint32_t unicode_letter_next) { /*Your code here*/ @@ -417,7 +423,7 @@ static bool neofont1_glyph_dsc_cb(const lv_font_t * font, lv_font_glyph_dsc_t * dsc_out->box_h = 10; /*Height of the bitmap in [px]*/ dsc_out->box_w = 6; /*Width of the bitmap in [px]*/ dsc_out->ofs_x = 1; /*X offset of the bitmap in [pf]*/ - dsc_out->ofs_y = 0; /*Y offset of the bitmap measured from the as line*/ + dsc_out->ofs_y = -1; /*Y offset of the bitmap measured from the as line*/ dsc_out->bpp = 1; /*Bits per pixel: 1/2/4/8*/ return true; /*true: glyph found; false: glyph was not found*/ @@ -425,9 +431,9 @@ static bool neofont1_glyph_dsc_cb(const lv_font_t * font, lv_font_glyph_dsc_t * #if 0 /* Get the bitmap of `unicode_letter` from `font`. */ -static const uint8_t * neofont1_glyph_bitmap_cb(const lv_font_t * font, uint32_t unicode_letter) +static const uint8_t * neofont1mono_glyph_bitmap_cb(const lv_font_t * font, uint32_t unicode_letter) { - const uint8_t *u = neofont0_glyph_bitmap_cb(font, unicode_letter); + const uint8_t *u = neofont0mono_glyph_bitmap_cb(font, unicode_letter); static uint8_t v[(10*10+7)/8]; uint8_t u0 = u[0]; uint8_t u1 = u[1]; @@ -480,9 +486,9 @@ static const uint8_t * neofont1_glyph_bitmap_cb(const lv_font_t * font, uint32_t #endif /* Get the bitmap of `unicode_letter` from `font`. */ -static const uint8_t * neofont1_glyph_bitmap_cb(const lv_font_t * font, uint32_t unicode_letter) +static const uint8_t * neofont1mono_glyph_bitmap_cb(const lv_font_t * font, uint32_t unicode_letter) { - const uint8_t *u = neofont0_glyph_bitmap_cb(font, unicode_letter); + const uint8_t *u = neofont0mono_glyph_bitmap_cb(font, unicode_letter); static uint8_t v[8]; uint8_t u0 = u[0]; uint8_t u1 = u[1]; @@ -550,9 +556,9 @@ static const uint8_t * neofont1_glyph_bitmap_cb(const lv_font_t * font, uint32_t } /*Describe the properties of a font*/ -lv_font_t neofont1 = { - .get_glyph_dsc = neofont1_glyph_dsc_cb, /*Set a callback to get info about gylphs*/ - .get_glyph_bitmap = neofont1_glyph_bitmap_cb, /*Set a callback to get bitmap of a glyp*/ +const lv_font_t neofont1mono = { + .get_glyph_dsc = neofont1mono_glyph_dsc_cb, /*Set a callback to get info about gylphs*/ + .get_glyph_bitmap = neofont1mono_glyph_bitmap_cb, /*Set a callback to get bitmap of a glyp*/ .line_height = 12, /*The real line height where any text fits*/ .base_line = 2, /*Base line measured from the top of line_height*/ .dsc = 0, /*Store any implementation specific data here*/ @@ -566,46 +572,22 @@ lv_font_t neofont1 = { .user_data = 0 /*Optionally some extra user data*/ }; -static bool neofont15_glyph_dsc_cb(const lv_font_t * font, lv_font_glyph_dsc_t * dsc_out, uint32_t unicode_letter, uint32_t unicode_letter_next) +static bool neofont15mono_glyph_dsc_cb(const lv_font_t * font, lv_font_glyph_dsc_t * dsc_out, uint32_t unicode_letter, uint32_t unicode_letter_next) { - /*Your code here*/ - - /* Store the result. - * For example ... - */ - - // ######..###### - // ##::::..::##:: - // ######..::##:: - // ::::##..::##:: - // ######..::##:: - - // ######..######.. - // ######..######.. - // ##::::..::##::.. - // ##::::..::##::.. - // ######..::##::.. - // ######..::##::.. - // ::::##..::##::.. - // ::::##..::##::.. - // ######..::##::.. - // ######..::##::.. - dsc_out->adv_w = 12; /*Horizontal space required by the glyph in [px]*/ dsc_out->box_h = 15; /*Height of the bitmap in [px]*/ dsc_out->box_w = 9; /*Width of the bitmap in [px]*/ dsc_out->ofs_x = 1; /*X offset of the bitmap in [pf]*/ - dsc_out->ofs_y = 0; /*Y offset of the bitmap measured from the as line*/ + dsc_out->ofs_y = -1; /*Y offset of the bitmap measured from the as line*/ dsc_out->bpp = 1; /*Bits per pixel: 1/2/4/8*/ return true; /*true: glyph found; false: glyph was not found*/ } - /* Get the bitmap of `unicode_letter` from `font`. */ -static const uint8_t * neofont15_glyph_bitmap_cb(const lv_font_t * font, uint32_t unicode_letter) +static const uint8_t * neofont15mono_glyph_bitmap_cb(const lv_font_t * font, uint32_t unicode_letter) { - const uint8_t *u = neofont0_glyph_bitmap_cb(font, unicode_letter); + const uint8_t *u = neofont0mono_glyph_bitmap_cb(font, unicode_letter); static uint8_t v[17]; uint8_t u0 = u[0]; uint8_t u1 = u[1]; @@ -681,9 +663,9 @@ static const uint8_t * neofont15_glyph_bitmap_cb(const lv_font_t * font, uint32_ } /*Describe the properties of a font*/ -lv_font_t neofont15 = { - .get_glyph_dsc = neofont15_glyph_dsc_cb, /*Set a callback to get info about gylphs*/ - .get_glyph_bitmap = neofont15_glyph_bitmap_cb, /*Set a callback to get bitmap of a glyp*/ +const lv_font_t neofont15mono = { + .get_glyph_dsc = neofont15mono_glyph_dsc_cb, /*Set a callback to get info about gylphs*/ + .get_glyph_bitmap = neofont15mono_glyph_bitmap_cb, /*Set a callback to get bitmap of a glyp*/ .line_height = 18, /*The real line height where any text fits*/ .base_line = 2, .dsc = 0, /*Store any implementation specific data here*/ @@ -701,21 +683,21 @@ lv_font_t neofont15 = { * Store the result in `dsc_out`. * The next letter (`unicode_letter_next`) might be used to calculate the width required by this glyph (kerning) */ -static bool neofont2_glyph_dsc_cb(const lv_font_t * font, lv_font_glyph_dsc_t * dsc_out, uint32_t unicode_letter, uint32_t unicode_letter_next) +static bool neofont2mono_glyph_dsc_cb(const lv_font_t * font, lv_font_glyph_dsc_t * dsc_out, uint32_t unicode_letter, uint32_t unicode_letter_next) { dsc_out->adv_w = 16; /*Horizontal space required by the glyph in [px]*/ dsc_out->box_h = 20; /*Height of the bitmap in [px]*/ dsc_out->box_w = 12; /*Width of the bitmap in [px]*/ dsc_out->ofs_x = 2; /*X offset of the bitmap in [pf]*/ - dsc_out->ofs_y = 0; /*Y offset of the bitmap measured from the as line*/ + dsc_out->ofs_y = -2; /*Y offset of the bitmap measured from the as line*/ dsc_out->bpp = 1; /*Bits per pixel: 1/2/4/8*/ return true; /*true: glyph found; false: glyph was not found*/ } /* Get the bitmap of `unicode_letter` from `font`. */ -static const uint8_t * neofont2_glyph_bitmap_cb(const lv_font_t * font, uint32_t unicode_letter) +static const uint8_t * neofont2mono_glyph_bitmap_cb(const lv_font_t * font, uint32_t unicode_letter) { - const uint8_t *u = neofont0_glyph_bitmap_cb(font, unicode_letter); + const uint8_t *u = neofont0mono_glyph_bitmap_cb(font, unicode_letter); static uint8_t v[30]; uint8_t u0 = u[0]; uint8_t u1 = u[1]; @@ -780,9 +762,9 @@ static const uint8_t * neofont2_glyph_bitmap_cb(const lv_font_t * font, uint32_t } /*Describe the properties of a font*/ -lv_font_t neofont2 = { - .get_glyph_dsc = neofont2_glyph_dsc_cb, /*Set a callback to get info about gylphs*/ - .get_glyph_bitmap = neofont2_glyph_bitmap_cb, /*Set a callback to get bitmap of a glyp*/ +const lv_font_t neofont2mono = { + .get_glyph_dsc = neofont2mono_glyph_dsc_cb, /*Set a callback to get info about gylphs*/ + .get_glyph_bitmap = neofont2mono_glyph_bitmap_cb, /*Set a callback to get bitmap of a glyp*/ .line_height = 24, /*The real line height where any text fits*/ .base_line = 4, /*Base line measured from the top of line_height*/ .dsc = 0, /*Store any implementation specific data here*/ @@ -800,21 +782,21 @@ lv_font_t neofont2 = { * Store the result in `dsc_out`. * The next letter (`unicode_letter_next`) might be used to calculate the width required by this glyph (kerning) */ -static bool neofont3_glyph_dsc_cb(const lv_font_t * font, lv_font_glyph_dsc_t * dsc_out, uint32_t unicode_letter, uint32_t unicode_letter_next) +static bool neofont3mono_glyph_dsc_cb(const lv_font_t * font, lv_font_glyph_dsc_t * dsc_out, uint32_t unicode_letter, uint32_t unicode_letter_next) { dsc_out->adv_w = 32; /*Horizontal space required by the glyph in [px]*/ dsc_out->box_h = 40; /*Height of the bitmap in [px]*/ dsc_out->box_w = 24; /*Width of the bitmap in [px]*/ dsc_out->ofs_x = 4; /*X offset of the bitmap in [pf]*/ - dsc_out->ofs_y = 0; /*Y offset of the bitmap measured from the as line*/ + dsc_out->ofs_y = -4; /*Y offset of the bitmap measured from the as line*/ dsc_out->bpp = 1; /*Bits per pixel: 1/2/4/8*/ return true; /*true: glyph found; false: glyph was not found*/ } static void mono_bitmap_scale_4( const uint8_t *u, uint8_t *v, unsigned int w, unsigned int h, - uint8_t *u0, uint8_t *u1, - uint8_t *v0, uint8_t *v1 + const uint8_t *u0, const uint8_t *u1, + const uint8_t *v0, const uint8_t *v1 ) { unsigned int y = 0; uint8_t U; @@ -870,15 +852,62 @@ static void mono_bitmap_scale_4( } /* Get the bitmap of `unicode_letter` from `font`. */ -static const uint8_t * neofont3_glyph_bitmap_cb(const lv_font_t * font, uint32_t unicode_letter) +static const uint8_t * neofont3mono_glyph_bitmap_cb(const lv_font_t * font, uint32_t unicode_letter) { - const uint8_t *u = neofont1_glyph_bitmap_cb(font, unicode_letter); + const uint8_t *u = neofont1mono_glyph_bitmap_cb(font, unicode_letter); static uint8_t v[120 /* = 40 * 24 / 8 */ ]; mono_bitmap_scale_4(u,v,6,10,u,u+(60+7)/8,v,v+120); return v; } /*Describe the properties of a font*/ +const lv_font_t neofont3mono = { + .get_glyph_dsc = neofont3mono_glyph_dsc_cb, /*Set a callback to get info about gylphs*/ + .get_glyph_bitmap = neofont3mono_glyph_bitmap_cb, /*Set a callback to get bitmap of a glyp*/ + .line_height = 48, /*The real line height where any text fits*/ + .base_line = 8, /*Base line measured from the top of line_height*/ + .dsc = 0, /*Store any implementation specific data here*/ +#if !(LVGL_VERSION_MAJOR == 6 && LVGL_VERSION_MINOR == 0) + .subpx = LV_FONT_SUBPX_NONE, +#endif +#if LV_VERSION_CHECK(7, 4, 0) || LVGL_VERSION_MAJOR >= 8 + .underline_position = 0, + .underline_thickness = 0, +#endif + .user_data = 0 /*Optionally some extra user data*/ +}; + +static bool isthin(uint32_t unicode_letter) { + return + unicode_letter == ' ' || + unicode_letter == ':' || + unicode_letter == 'I' || + unicode_letter == 'i' || + unicode_letter == '.'; + // May also add: "'|" +} + +static bool neofont3_glyph_dsc_cb(const lv_font_t * font, lv_font_glyph_dsc_t * dsc_out, uint32_t unicode_letter, uint32_t unicode_letter_next) { + // if (unicode_letter == '\n') { return false; } + bool thin = isthin(unicode_letter); + dsc_out->adv_w = thin ? 16 : 32; /*Horizontal space required by the glyph in [px]*/ + dsc_out->box_h = 40; /*Height of the bitmap in [px]*/ + dsc_out->box_w = 24; /*Width of the bitmap in [px]*/ + dsc_out->ofs_x = thin ? (4-8) : 4; /*X offset of the bitmap in [pf]*/ + dsc_out->ofs_y = -4; /*Y offset of the bitmap measured from the as line*/ + dsc_out->bpp = 1; /*Bits per pixel: 1/2/4/8*/ + return true; /*true: glyph found; false: glyph was not found*/ +} + +/* Get the bitmap of `unicode_letter` from `font`. */ +static const uint8_t * neofont3_glyph_bitmap_cb(const lv_font_t * font, uint32_t unicode_letter) { + if ((unicode_letter == 'I') || (unicode_letter == 'i')) { + unicode_letter = '|'; + } + return neofont3mono_glyph_bitmap_cb(font, unicode_letter); +} + +/*Describe the properties of a font*/ const lv_font_t neofont3 = { .get_glyph_dsc = neofont3_glyph_dsc_cb, /*Set a callback to get info about gylphs*/ .get_glyph_bitmap = neofont3_glyph_bitmap_cb, /*Set a callback to get bitmap of a glyp*/ @@ -895,3 +924,88 @@ const lv_font_t neofont3 = { .user_data = 0 /*Optionally some extra user data*/ }; +/* Get info about glyph of `unicode_letter` in `font` font. + * Store the result in `dsc_out`. + * The next letter (`unicode_letter_next`) might be used to calculate the width required by this glyph (kerning) + */ +static bool neofont2_glyph_dsc_cb(const lv_font_t * font, lv_font_glyph_dsc_t * dsc_out, uint32_t unicode_letter, uint32_t unicode_letter_next) +{ + // if (unicode_letter == '\n') { return false; } + bool thin = isthin(unicode_letter); + dsc_out->adv_w = thin ? 8 : 16; /*Horizontal space required by the glyph in [px]*/ + dsc_out->box_h = 20; /*Height of the bitmap in [px]*/ + dsc_out->box_w = 12; /*Width of the bitmap in [px]*/ + dsc_out->ofs_x = thin ? (2-4) : 2; /*X offset of the bitmap in [pf]*/ + dsc_out->ofs_y = -2; /*Y offset of the bitmap measured from the as line*/ + dsc_out->bpp = 1; /*Bits per pixel: 1/2/4/8*/ + return true; /*true: glyph found; false: glyph was not found*/ +} + +/* Get the bitmap of `unicode_letter` from `font`. */ +static const uint8_t * neofont2_glyph_bitmap_cb(const lv_font_t * font, uint32_t unicode_letter) { + if ((unicode_letter == 'I') || (unicode_letter == 'i')) { + unicode_letter = '|'; + } + return neofont2mono_glyph_bitmap_cb(font, unicode_letter); +} + +/*Describe the properties of a font*/ +const lv_font_t neofont2 = { + .get_glyph_dsc = neofont2_glyph_dsc_cb, /*Set a callback to get info about gylphs*/ + .get_glyph_bitmap = neofont2_glyph_bitmap_cb, /*Set a callback to get bitmap of a glyp*/ + .line_height = 24, /*The real line height where any text fits*/ + .base_line = 4, /*Base line measured from the top of line_height*/ + .dsc = 0, /*Store any implementation specific data here*/ +#if !(LVGL_VERSION_MAJOR == 6 && LVGL_VERSION_MINOR == 0) + .subpx = LV_FONT_SUBPX_NONE, +#endif +#if LV_VERSION_CHECK(7, 4, 0) || LVGL_VERSION_MAJOR >= 8 + .underline_position = 0, + .underline_thickness = 0, +#endif + .user_data = 0 /*Optionally some extra user data*/ +}; + +static bool neofont15_glyph_dsc_cb(const lv_font_t * font, lv_font_glyph_dsc_t * dsc_out, uint32_t unicode_letter, uint32_t unicode_letter_next) { + // if (unicode_letter == '\n') { return false; } + bool thin = isthin(unicode_letter); + dsc_out->adv_w = thin ? 6 : 12; /*Horizontal space required by the glyph in [px]*/ + dsc_out->box_h = 15; /*Height of the bitmap in [px]*/ + dsc_out->box_w = 9; /*Width of the bitmap in [px]*/ + dsc_out->ofs_x = thin ? (1-3) : 1; /*X offset of the bitmap in [pf]*/ + dsc_out->ofs_y = -1; /*Y offset of the bitmap measured from the as line*/ + dsc_out->bpp = 1; /*Bits per pixel: 1/2/4/8*/ + + return true; /*true: glyph found; false: glyph was not found*/ +} + +/* Get the bitmap of `unicode_letter` from `font`. */ +static const uint8_t * neofont15_glyph_bitmap_cb(const lv_font_t * font, uint32_t unicode_letter) { + if ((unicode_letter == 'I') || (unicode_letter == 'i')) { + unicode_letter = '|'; + } + return neofont15mono_glyph_bitmap_cb(font, unicode_letter); +} + +/*Describe the properties of a font*/ +const lv_font_t neofont15 = { + .get_glyph_dsc = neofont15_glyph_dsc_cb, /*Set a callback to get info about gylphs*/ + .get_glyph_bitmap = neofont15_glyph_bitmap_cb, /*Set a callback to get bitmap of a glyp*/ + .line_height = 18, /*The real line height where any text fits*/ + .base_line = 2, + .dsc = 0, /*Store any implementation specific data here*/ +#if !(LVGL_VERSION_MAJOR == 6 && LVGL_VERSION_MINOR == 0) + .subpx = LV_FONT_SUBPX_NONE, +#endif +#if LV_VERSION_CHECK(7, 4, 0) || LVGL_VERSION_MAJOR >= 8 + .underline_position = 0, + .underline_thickness = 0, +#endif + .user_data = 0 /*Optionally some extra user data*/ +}; + + +const lv_font_t neofont1 = neofont1mono; +const lv_font_t neofont0 = neofont0mono; + + |
