diff options
Diffstat (limited to 'src/displayapp/fonts/neofont.c')
| -rw-r--r-- | src/displayapp/fonts/neofont.c | 1273 |
1 files changed, 1273 insertions, 0 deletions
diff --git a/src/displayapp/fonts/neofont.c b/src/displayapp/fonts/neofont.c new file mode 100644 index 0000000..a3adde4 --- /dev/null +++ b/src/displayapp/fonts/neofont.c @@ -0,0 +1,1273 @@ +#ifdef LV_LVGL_H_INCLUDE_SIMPLE +#include "lvgl.h" +#else +#include "lvgl/lvgl.h" +#endif + + +#include <stdint.h> +// #include <stdio.h> +// #include <string.h> + +#define G( \ + a,b,c, \ + d,e,f, \ + g,h,i, \ + j,k,l, \ + m,n,o \ +) \ +{ \ + h + (g<<1) + (f<<2) + (e<<3) + (d << 4) + (c << 5) + (b << 6) + (a << 7), \ + 0 + (o<<1) + (n<<2) + (m<<3) + (l << 4) + (k << 5) + (j << 6) + (i << 7) \ +} + +#define X 1 +#define _ 0 + +static const uint8_t glyphs[][2] = { + G( _, X, _, + X, _, X, + X, _, X, + X, _, X, + _, X, _ ), + + G( _, X, _, + X, X, _, + _, X, _, + _, X, _, + X, X, X ), + + G( X, X, _, + _, _, X, + _, _, X, + _, X, _, + X, X, X ), + + G( X, X, _, + _, _, X, + _, X, _, + _, _, X, + X, X, _ ), + + G( _, _, X, + _, X, X, + X, _, X, + X, X, X, + _, _, X ), + + G( X, X, X, + X, _, _, + X, X, _, + _, _, X, + X, X, _ ), + + G( _, X, X, + X, _, _, + X, X, _, + X, _, X, + _, X, _ ), + + G( X, X, X, + _, _, X, + _, _, X, + _, X, _, + _, X, _ ), + + G( _, X, _, + X, _, X, + _, X, _, + X, _, X, + _, X, _ ), + + G( _, X, _, + X, _, X, + _, X, X, + _, _, X, + X, X, _ ), + + G( _, X, _, + X, _, X, + X, _, X, + X, X, X, + X, _, X ), + + G( X, X, _, + X, _, X, + X, X, _, + X, _, X, + X, X, _ ), + + G( _, X, X, + X, _, _, + X, _, _, + X, _, _, + _, X, X ), + + G( X, X, _, + X, _, X, + X, _, X, + X, _, X, + X, X, _ ), + + G( X, X, X, + X, _, _, + X, X, _, + X, _, _, + X, X, X ), + + G( X, X, X, + X, _, _, + X, X, _, + X, _, _, + X, _, _ ), + + G( _, X, X, + X, _, _, + X, _, _, + X, _, X, + _, X, X ), + + G( X, _, X, + X, _, X, + X, X, X, + X, _, X, + X, _, X ), + + G( X, X, X, + _, X, _, + _, X, _, + _, X, _, + X, X, X ), + + G( X, X, X, + _, _, X, + _, _, X, + X, _, X, + _, X, _ ), + + G( X, _, X, + X, _, X, + X, X, _, + X, _, X, + X, _, X ), + + G( X, _, _, + X, _, _, + X, _, _, + X, _, _, + X, X, X ), + + G( X, _, X, + X, X, X, + X, _, X, + X, _, X, + X, _, X ), + + G( X, X, _, + X, _, X, + X, _, X, + X, _, X, + X, _, X ), + + G( X, X, X, + X, _, X, + X, _, X, + X, _, X, + X, X, X ), + + G( X, X, X, + X, _, X, + X, X, X, + X, _, _, + X, _, _ ), + + G( _, X, _, + X, _, X, + X, _, X, + X, _, X, + _, X, X ), + + G( X, X, _, + X, _, X, + X, X, _, + X, _, X, + X, _, X ), + + G( _, X, X, + X, _, _, + _, X, _, + _, _, X, + X, X, _ ), + + G( X, X, X, + _, X, _, + _, X, _, + _, X, _, + _, X, _ ), + + G( X, _, X, + X, _, X, + X, _, X, + X, _, X, + X, X, X ), + + G( X, _, X, + X, _, X, + X, _, X, + _, X, _, + _, X, _ ), + + G( X, _, X, + X, _, X, + X, X, X, + X, X, X, + X, _, X ), + + G( X, _, X, + X, _, X, + _, X, _, + X, _, X, + X, _, X ), + + G( X, _, X, + X, _, X, + _, X, _, + _, X, _, + _, X, _ ), + + G( X, X, X, + _, _, X, + _, X, _, + X, _, _, + X, X, X ), + + + G( _, _, _, + X, X, _, + _, X, X, + X, _, X, + _, X, X ), + + G( X, _, _, + X, X, _, + X, _, X, + X, _, X, + X, X, _ ), + + G( _, _, _, + _, X, X, + X, _, _, + X, _, _, + _, X, X ), + + G( _, _, X, + _, X, X, + X, _, X, + X, _, X, + _, X, X ), + + G( _, _, _, + _, X, _, + X, _, X, + X, X, _, + _, X, X ), + + G( _, _, X, + _, X, _, + X, X, X, + _, X, _, + _, X, _ ), + + G( _, _, _, + X, X, X, + X, _, X, + _, X, X, + X, X, X ), + + G( X, _, _, + X, _, _, + X, X, _, + X, _, X, + X, _, X ), + + G( _, X, _, + _, _, _, + _, X, _, + _, X, _, + X, X, X ), + + G( _, X, _, + _, _, _, + _, X, _, + _, X, _, + X, _, _ ), + + G( X, _, _, + X, _, X, + X, X, _, + X, X, _, + X, _, X ), + + G( X, X, _, + _, X, _, + _, X, _, + _, X, _, + _, X, X ), + + G( _, _, _, + X, X, _, + X, X, X, + X, X, X, + X, _, X ), + + G( _, _, _, + X, X, _, + X, _, X, + X, _, X, + X, _, X ), + + G( _, _, _, + X, X, X, + X, _, X, + X, _, X, + X, X, X ), + + G( _, _, _, + X, X, _, + X, _, X, + X, X, _, + X, _, _ ), + + G( _, _, _, + _, X, X, + X, _, X, + _, X, X, + _, _, X ), + + G( _, _, _, + X, _, X, + X, X, _, + X, _, _, + X, _, _ ), + + G( _, _, _, + _, X, X, + X, _, _, + _, X, X, + X, X, _ ), + + G( _, X, _, + X, X, X, + _, X, _, + _, X, _, + _, X, _ ), + + G( _, _, _, + X, _, X, + X, _, X, + X, _, X, + X, X, X ), + + G( _, _, _, + X, _, X, + X, _, X, + _, X, _, + _, X, _ ), + + G( _, _, _, + X, _, X, + X, _, X, + X, X, X, + X, X, X ), + + G( _, _, _, + X, _, X, + _, X, _, + _, X, _, + X, _, X ), + + G( _, _, _, + X, _, X, + X, X, X, + _, _, X, + X, X, _ ), + + G( _, _, _, + X, X, X, + _, X, _, + X, _, _, + X, X, X ), + + + G( _, X, _, + _, X, _, + _, X, _, + _, X, _, + _, X, _ ), + + G( _, _, _, + _, _, _, + X, X, X, + _, _, _, + _, _, _ ), + + + G( _, _, _, + _, _, X, + _, X, _, + X, _, _, + _, _, _ ), + + G( _, _, _, + _, X, _, + _, _, _, + _, X, _, + _, _, _ ), + + G( _, _, _, + _, _, _, + _, _, _, + _, X, _, + _, _, _ ), + + G( _, _, _, + _, _, _, + _, _, _, + _, X, _, + X, _, _ ), + + G( _, _, _, + _, _, _, + _, _, _, + _, _, _, + X, X, X ), + + G( X, X, _, + _, _, X, + _, X, _, + _, _, _, + _, X, _ ), + + G( _, X, _, + _, X, _, + _, X, _, + _, _, _, + _, X, _ ), + + G( X, _, _, + _, _, X, + _, X, _, + X, _, _, + _, _, X ), + + G( _, _, _, + _, X, _, + X, X, X, + _, X, _, + _, _, _ ), + + G( _, X, _, + X, X, X, + _, X, _, + X, X, X, + _, X, _ ), + + G( _, X, _, + X, _, X, + _, X, _, + _, _, _, + _, _, _ ), + +}; + +#undef X +#undef _ +#undef G + +/* 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 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*/ + + /* Store the result. + * For example ... + */ + dsc_out->adv_w = 4; /*Horizontal space required by the glyph in [px]*/ + dsc_out->box_h = 5; /*Height of the bitmap in [px]*/ + dsc_out->box_w = 3; /*Width of the bitmap in [px]*/ + dsc_out->ofs_x = 0; /*X offset of the bitmap in [pf]*/ + dsc_out->ofs_y = 0; /*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 * neofont0mono_glyph_bitmap_cb(const lv_font_t * font, uint32_t unicode_letter) +{ + if (unicode_letter < 0x20) return NULL; + + static const uint8_t spc[] = { 0, 0 }; + static uint8_t custom[2]; + /* Your code here */ + + // /* The bitmap should be a continuous bitstream where + // * each pixel is represented by `bpp` bits */ + if ('0' <= unicode_letter && unicode_letter <= '9') { + return glyphs[(unicode_letter - '0')]; + } + if ('A' <= unicode_letter && unicode_letter <= 'Z') { + return glyphs[(unicode_letter - 'A')+10]; + } + if ('a' <= unicode_letter && unicode_letter <= 'z') { + return glyphs[(unicode_letter - 'a')+36]; + } + + if (unicode_letter == ' ') { return spc; } + static const char *symbols = "|-/:.,_?!%+#"; + if (unicode_letter < 0x80) { + char*x = strchr(symbols,((uint8_t)unicode_letter)); + if (x != NULL) { + return glyphs[62+(x-symbols)]; + } + } + + switch (unicode_letter) { + case 0xB0: + return glyphs[sizeof(glyphs)/sizeof(glyphs[0])-1]; + } + +#define NEOFONT_LOWERCASE_I (0xF0000 + (1 << 0) + (1 << 6) + (1 << 9) + (1 << 12)) + + if ((0xF0000 < unicode_letter) && (unicode_letter < 0xF7FFF)) { + custom[0] = unicode_letter; + custom[1] = (unicode_letter >> 7); + return custom; + } + + return glyphs[sizeof(glyphs)/sizeof(glyphs[0])-2]; + +} + +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*/ +#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 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*/ + + /* Store the result. + * For example ... + */ + + // ######..###### + // ##::::..::##:: + // ######..::##:: + // ::::##..::##:: + // ######..::##:: + + // ######..######.. + // ######..######.. + // ##::::..::##::.. + // ##::::..::##::.. + // ######..::##::.. + // ######..::##::.. + // ::::##..::##::.. + // ::::##..::##::.. + // ######..::##::.. + // ######..::##::.. + + dsc_out->adv_w = 8; /*Horizontal space required by the glyph in [px]*/ + 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 = -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*/ +} + +#if 0 +/* Get the bitmap of `unicode_letter` from `font`. */ +static const uint8_t * neofont1mono_glyph_bitmap_cb(const lv_font_t * font, uint32_t unicode_letter) +{ + const uint8_t *u = neofont0mono_glyph_bitmap_cb(font, unicode_letter); + if (u == NULL) return NULL; + static uint8_t v[(10*10+7)/8]; + uint8_t u0 = u[0]; + uint8_t u1 = u[1]; + + // .. .. .. .. .2 .2 .1 .1 .0 .0 + // .9 .8 .7 .6 .5 .4 .3 .2 .1 .0 + // .. .. .. .. .2 .2 .1 .1 .0 .0 + // 19 18 17 16 15 14 13 12 11 10 + // .. .. .. .5 .5 .4 .4 .3 .3 .. + // 29 28 27 26 25 24 23 22 21 20 + // .. .. .. .5 .5 .4 .4 .3 .3 .. + // 39 38 37 36 35 34 33 32 31 30 + + // v[7] = 0x00; + + uint8_t a,b,c, d,e,f, g,h,i, j,k,l, m,n,o; + a = (u0>>7)&1; u0 <<= 1; + b = (u0>>7)&1; u0 <<= 1; + c = (u0>>7)&1; u0 <<= 1; + d = (u0>>7)&1; u0 <<= 1; + e = (u0>>7)&1; u0 <<= 1; + f = (u0>>7)&1; u0 <<= 1; + g = (u0>>7)&1; u0 <<= 1; + h = (u0>>7)&1; + i = (u1>>7)&1; u1 <<= 1; + j = (u1>>7)&1; u1 <<= 1; + k = (u1>>7)&1; u1 <<= 1; + l = (u1>>7)&1; u1 <<= 1; + m = (u1>>7)&1; u1 <<= 1; + n = (u1>>7)&1; u1 <<= 1; + o = (u1>>7)&1; + +#define P(a,b,c,d, e,f,g,h) ((a<<7)|(b<<6)|(c<<5)|(d<<4)|(e<<3)|(f<<2)|(g<<1)|h) + + v[0] = P(0,0,a,a,b,b,c,c); + v[1] = P(0,0,a,a,b,b,c,c); + v[2] = P(0,0,d,d,e,e,f,f); + v[3] = P(0,d,d,e,e,f,f,0); + v[4] = P(0,g,g,h,h,i,i,0); + v[5] = P(g,g,h,h,i,i,0,0); + v[6] = P(j,j,k,k,l,l,0,0); + v[7] = P(j,j,k,k,l,l,0,0); + v[8] = P(m,m,n,n,o,o,0,0); + v[9] = P(m,m,n,n,o,o,0,0); + +#undef P + + return v; /*Or NULL if not found*/ +} +#endif + +/* Get the bitmap of `unicode_letter` from `font`. */ +static const uint8_t * neofont1mono_glyph_bitmap_cb(const lv_font_t * font, uint32_t unicode_letter) +{ + const uint8_t *u = neofont0mono_glyph_bitmap_cb(font, unicode_letter); + if (u == NULL) return NULL; + static uint8_t v[8]; + uint8_t u0 = u[0]; + uint8_t u1 = u[1]; + + // .. .. .. .. .2 .2 .1 .1 .0 .0 + // .9 .8 .7 .6 .5 .4 .3 .2 .1 .0 + // .. .. .. .. .2 .2 .1 .1 .0 .0 + // 19 18 17 16 15 14 13 12 11 10 + // .. .. .. .5 .5 .4 .4 .3 .3 .. + // 29 28 27 26 25 24 23 22 21 20 + // .. .. .. .5 .5 .4 .4 .3 .3 .. + // 39 38 37 36 35 34 33 32 31 30 + + // v[7] = 0x00; + + uint8_t a,b,c, d,e,f, g,h,i, j,k,l, m,n,o; + a = (u0>>7)&1; u0 <<= 1; + b = (u0>>7)&1; u0 <<= 1; + c = (u0>>7)&1; u0 <<= 1; + d = (u0>>7)&1; u0 <<= 1; + e = (u0>>7)&1; u0 <<= 1; + f = (u0>>7)&1; u0 <<= 1; + g = (u0>>7)&1; u0 <<= 1; + h = (u0>>7)&1; + i = (u1>>7)&1; u1 <<= 1; + j = (u1>>7)&1; u1 <<= 1; + k = (u1>>7)&1; u1 <<= 1; + l = (u1>>7)&1; u1 <<= 1; + m = (u1>>7)&1; u1 <<= 1; + n = (u1>>7)&1; u1 <<= 1; + o = (u1>>7)&1; + +#define P(a,b,c,d, e,f,g,h) ((a<<7)|(b<<6)|(c<<5)|(d<<4)|(e<<3)|(f<<2)|(g<<1)|h) + + v[0] = P(a,a,b,b,c,c, + + a,a); + v[1] = P(b,b,c,c, + + d,d,e,e); + v[2] = P(f,f, + + d,d,e,e,f,f); + + v[3] = P(g,g,h,h,i,i, + + g,g); + v[4] = P(h,h,i,i, + + j,j,k,k); + v[5] = P(l,l, + + j,j,k,k,l,l); + + v[6] = P(m,m,n,n,o,o, + + m,m); + v[7] = P(n,n,o,o, + + 0,0,0,0); + +#undef P + + return v; /*Or NULL if not found*/ +} + +/*Describe the properties of a font*/ +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*/ +#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 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) +{ + 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 = -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 * neofont15mono_glyph_bitmap_cb(const lv_font_t * font, uint32_t unicode_letter) +{ + const uint8_t *u = neofont0mono_glyph_bitmap_cb(font, unicode_letter); + if (u == NULL) return NULL; + static uint8_t v[17]; + uint8_t u0 = u[0]; + uint8_t u1 = u[1]; + + // .. .. .. .. .2 .2 .1 .1 .0 .0 + // .9 .8 .7 .6 .5 .4 .3 .2 .1 .0 + // .. .. .. .. .2 .2 .1 .1 .0 .0 + // 19 18 17 16 15 14 13 12 11 10 + // .. .. .. .5 .5 .4 .4 .3 .3 .. + // 29 28 27 26 25 24 23 22 21 20 + // .. .. .. .5 .5 .4 .4 .3 .3 .. + // 39 38 37 36 35 34 33 32 31 30 + + // v[7] = 0x00; + + uint8_t a,b,c, d,e,f, g,h,i, j,k,l, m,n,o; + a = (u0>>7)&1; u0 <<= 1; + b = (u0>>7)&1; u0 <<= 1; + c = (u0>>7)&1; u0 <<= 1; + d = (u0>>7)&1; u0 <<= 1; + e = (u0>>7)&1; u0 <<= 1; + f = (u0>>7)&1; u0 <<= 1; + g = (u0>>7)&1; u0 <<= 1; + h = (u0>>7)&1; + i = (u1>>7)&1; u1 <<= 1; + j = (u1>>7)&1; u1 <<= 1; + k = (u1>>7)&1; u1 <<= 1; + l = (u1>>7)&1; u1 <<= 1; + m = (u1>>7)&1; u1 <<= 1; + n = (u1>>7)&1; u1 <<= 1; + o = (u1>>7)&1; + +#define P(a,b,c,d, e,f,g,h) ((a<<7)|(b<<6)|(c<<5)|(d<<4)|(e<<3)|(f<<2)|(g<<1)|h) + + v[0] = P(a,a,a,b,b,b,c,c); + v[1] = P(c, + a,a,a,b,b,b,c); + v[2] = P(c,c, + a,a,a,b,b,b); + v[3] = P(c,c,c, + + d,d,d,e,e); + v[4] = P(e,f,f,f, + d,d,d,e); + v[5] = P(e,e,f,f,f, + d,d,d); + v[6] = P(e,e,e,f,f,f, + + g,g); + v[7] = P(g,h,h,h,i,i,i, + g); + v[8] = P(g,g,h,h,h,i,i,i); + v[9] = P(g,g,g,h,h,h,i,i); + v[10] = P(i, + + j,j,j,k,k,k,l); + v[11] = P(l,l, + j,j,j,k,k,k); + v[12] = P(l,l,l, + j,j,j,k,k); + v[13] = P(k,l,l,l, + + m,m,m,n); + v[14] = P(n,n,o,o,o, + m,m,m); + v[15] = P(n,n,n,o,o,o, + m,m); + v[16] = P(m,n,n,n,o,o,o,0); + +#undef P + + return v; /*Or NULL if not found*/ +} + +/*Describe the properties of a font*/ +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*/ +#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*/ +}; + +/* 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 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 = -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 * neofont2mono_glyph_bitmap_cb(const lv_font_t * font, uint32_t unicode_letter) +{ + const uint8_t *u = neofont0mono_glyph_bitmap_cb(font, unicode_letter); + if (u == NULL) return NULL; + static uint8_t v[30]; + uint8_t u0 = u[0]; + uint8_t u1 = u[1]; + + uint8_t a,b,c, d,e,f, g,h,i, j,k,l, m,n,o; + a = (u0>>7)&1; u0 <<= 1; + b = (u0>>7)&1; u0 <<= 1; + c = (u0>>7)&1; u0 <<= 1; + d = (u0>>7)&1; u0 <<= 1; + e = (u0>>7)&1; u0 <<= 1; + f = (u0>>7)&1; u0 <<= 1; + g = (u0>>7)&1; u0 <<= 1; + h = (u0>>7)&1; + i = (u1>>7)&1; u1 <<= 1; + j = (u1>>7)&1; u1 <<= 1; + k = (u1>>7)&1; u1 <<= 1; + l = (u1>>7)&1; u1 <<= 1; + m = (u1>>7)&1; u1 <<= 1; + n = (u1>>7)&1; u1 <<= 1; + o = (u1>>7)&1; + +#define P(a,b) (a?0xf0:0)|(b?0x0f:0) + + v[0] = P(a,b); + v[1] = P(c, + a); + v[2] = P(b,c); + + v[3] = v[0]; v[4] = v[1]; v[5] = v[2]; + + v[6] = P(d,e); + v[7] = P(f, + d); + v[8] = P(e,f); + + v[9] = v[6]; v[10] = v[7]; v[11] = v[8]; + + v[12] = P(g,h); + v[13] = P(i, + g); + v[14] = P(h,i); + + v[15] = v[12]; v[16] = v[13]; v[17] = v[14]; + + v[18] = P(j,k); + v[19] = P(l, + j); + v[20] = P(k,l); + + v[21] = v[18]; v[22] = v[19]; v[23] = v[20]; + + v[24] = P(m,n); + v[25] = P(o, + m); + v[26] = P(n,o); + + v[27] = v[24]; v[28] = v[25]; v[29] = v[26]; + +#undef P + + return v; /*Or NULL if not found*/ +} + +/*Describe the properties of a font*/ +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*/ +#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*/ +}; + +/* 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 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 = -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, + const uint8_t *u0, const uint8_t *u1, + const uint8_t *v0, const uint8_t *v1 +) { + unsigned int y = 0; + uint8_t U; + const uint8_t *V = v; + const uint8_t *v_line_end = &(v[w]); + const uint8_t *v_line_next = &(v[w<<2]); + for (;;) { + U = *u; + if (!(v0 <= v && v < v1)) { + // fprintf(stderr, "Overflow 0!\n"); + return; + } + *v = ( ((U&0x80) ? 0xf0 : 0) | ((U&0x40) ? 0x0f : 0) ); + U <<= 2; v++; + if (!(v0 <= v && v < v1)) { return; } + *v = ( ((U&0x80) ? 0xf0 : 0) | ((U&0x40) ? 0x0f : 0) ); + U <<= 2; v++; + if (v >= v_line_end) { + while (v < v_line_next) { + if (!(v0 <= v && v < v1)) { + // fprintf(stderr, "Overflow 1!\n"); + return; + } + *v = *V; v++; V++; + } + y++; + if (y >= h) { return; } + V = v; + v_line_end = &(v[w]); + v_line_next = &(v[w<<2]); + } + if (!(v0 <= v && v < v1)) { return; } + *v = ( ((U&0x80) ? 0xf0 : 0) | ((U&0x40) ? 0x0f : 0) ); + U <<= 2; v++; + if (!(v0 <= v && v < v1)) { return; } + *v = ( ((U&0x80) ? 0xf0 : 0) | ((U&0x40) ? 0x0f : 0) ); + u++; v++; + if (v >= v_line_end) { + while (v < v_line_next) { + if (!(v0 <= v && v < v1)) { + // fprintf(stderr, "Overflow 2!\n"); + return; + } + *v = *V; v++; V++; + } + y++; + if (y >= h) { return; } + V = v; + v_line_end = &(v[w]); + v_line_next = &(v[w<<2]); + } + } +} + +/* Get the bitmap of `unicode_letter` from `font`. */ +static const uint8_t * neofont3mono_glyph_bitmap_cb(const lv_font_t * font, uint32_t unicode_letter) +{ + const uint8_t *u = neofont1mono_glyph_bitmap_cb(font, unicode_letter); + if (u == NULL) return NULL; + 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*/ +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 == NEOFONT_LOWERCASE_I || + unicode_letter == 'I' || + unicode_letter == 'i' || + unicode_letter == '|' || + unicode_letter == '.'; +} + +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 = '|'; + } else if (unicode_letter == 'i') { + unicode_letter = NEOFONT_LOWERCASE_I; + } + return neofont3mono_glyph_bitmap_cb(font, unicode_letter); +} + +/*Describe the properties of a font*/ +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*/ + .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*/ +}; + +/* 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 = '|'; + } else if (unicode_letter == 'i') { + unicode_letter = NEOFONT_LOWERCASE_I; + } + return neofont2mono_glyph_bitmap_cb(font, unicode_letter); +} + +/*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*/ + .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 = '|'; + } else if (unicode_letter == 'i') { + unicode_letter = NEOFONT_LOWERCASE_I; + } + return neofont15mono_glyph_bitmap_cb(font, unicode_letter); +} + +/*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*/ + .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*/ +}; + +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) { + // if (unicode_letter == '\n') { return false; } + bool thin = isthin(unicode_letter); + dsc_out->adv_w = thin ? 4 : 8; /*Horizontal space required by the glyph in [px]*/ + 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 = thin ? (1-2) : 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 * neofont1_glyph_bitmap_cb(const lv_font_t * font, uint32_t unicode_letter) { + if ((unicode_letter == 'I')) { + unicode_letter = '|'; + } else if (unicode_letter == 'i') { + unicode_letter = NEOFONT_LOWERCASE_I; + } + return neofont1mono_glyph_bitmap_cb(font, unicode_letter); +} + +/*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*/ + .line_height = 12, /*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*/ +}; + +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) { + // if (unicode_letter == '\n') { return false; } + bool thin = isthin(unicode_letter); + dsc_out->adv_w = thin ? 2 : 4; /*Horizontal space required by the glyph in [px]*/ + dsc_out->box_h = 5; /*Height of the bitmap in [px]*/ + dsc_out->box_w = 3; /*Width of the bitmap in [px]*/ + dsc_out->ofs_x = thin ? (0-1) : 0; /*X offset of the bitmap in [pf]*/ + dsc_out->ofs_y = 0; /*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 * neofont0_glyph_bitmap_cb(const lv_font_t * font, uint32_t unicode_letter) { + if ((unicode_letter == 'I')) { + unicode_letter = '|'; + } else if (unicode_letter == 'i') { + unicode_letter = NEOFONT_LOWERCASE_I; + } + return neofont0mono_glyph_bitmap_cb(font, unicode_letter); +} + +/*Describe the properties of a font*/ +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*/ + .line_height = 12, /*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*/ +}; + + |
