lv_font: add monospace support

This commit is contained in:
Gabor Kiss-Vamosi
2018-06-22 23:32:21 +02:00
parent 7503242a6a
commit 46ae9146d8
18 changed files with 104 additions and 26 deletions
+17 -9
View File
@@ -217,13 +217,21 @@ void lv_vletter(const lv_point_t * pos_p, const lv_area_t * mask_p,
if(font_p == NULL) return;
uint8_t letter_w = lv_font_get_width(font_p, letter);
lv_coord_t pos_x = pos_p->x;
lv_coord_t pos_y = pos_p->y;
uint8_t letter_w = lv_font_get_real_width(font_p, letter);
uint8_t letter_h = lv_font_get_height(font_p);
uint8_t bpp = lv_font_get_bpp(font_p, letter); /*Bit per pixel (1,2, 4 or 8)*/
uint8_t * bpp_opa_table;
uint8_t mask_init;
uint8_t mask;
if(lv_font_is_monospace(font_p, letter)) {
pos_x += (lv_font_get_width(font_p, letter) - letter_w) / 2;
}
switch(bpp) {
case 1:
bpp_opa_table = bpp1_opa_table;
@@ -250,8 +258,8 @@ void lv_vletter(const lv_point_t * pos_p, const lv_area_t * mask_p,
if(map_p == NULL) return;
/*If the letter is completely out of mask don't draw it */
if(pos_p->x + letter_w < mask_p->x1 || pos_p->x > mask_p->x2 ||
pos_p->y + letter_h < mask_p->y1 || pos_p->y > mask_p->y2) return;
if(pos_x + letter_w < mask_p->x1 || pos_x > mask_p->x2 ||
pos_y + letter_h < mask_p->y1 || pos_y > mask_p->y2) return;
lv_vdb_t * vdb_p = lv_vdb_get();
lv_coord_t vdb_width = lv_area_get_width(&vdb_p->area);
@@ -265,14 +273,14 @@ void lv_vletter(const lv_point_t * pos_p, const lv_area_t * mask_p,
if((letter_w * bpp) & 0x7) width_byte_bpp++;
/* Calculate the col/row start/end on the map*/
lv_coord_t col_start = pos_p->x >= mask_p->x1 ? 0 : mask_p->x1 - pos_p->x;
lv_coord_t col_end = pos_p->x + letter_w <= mask_p->x2 ? letter_w : mask_p->x2 - pos_p->x + 1;
lv_coord_t row_start = pos_p->y >= mask_p->y1 ? 0 : mask_p->y1 - pos_p->y;
lv_coord_t row_end = pos_p->y + letter_h <= mask_p->y2 ? letter_h : mask_p->y2 - pos_p->y + 1;
lv_coord_t col_start = pos_x >= mask_p->x1 ? 0 : mask_p->x1 - pos_x;
lv_coord_t col_end = pos_x + letter_w <= mask_p->x2 ? letter_w : mask_p->x2 - pos_x + 1;
lv_coord_t row_start = pos_y >= mask_p->y1 ? 0 : mask_p->y1 - pos_y;
lv_coord_t row_end = pos_y + letter_h <= mask_p->y2 ? letter_h : mask_p->y2 - pos_y + 1;
/*Set a pointer on VDB to the first pixel of the letter*/
vdb_buf_tmp += ((pos_p->y - vdb_p->area.y1) * vdb_width)
+ pos_p->x - vdb_p->area.x1;
vdb_buf_tmp += ((pos_y - vdb_p->area.y1) * vdb_width)
+ pos_x - vdb_p->area.x1;
/*If the letter is partially out of mask the move there on VDB*/
vdb_buf_tmp += (row_start * vdb_width) + col_start;
+51 -7
View File
@@ -18,11 +18,6 @@
/**********************
* TYPEDEFS
**********************/
typedef struct {
uint32_t glyph_index;
uint32_t unicode;
uint8_t w_px;
} asd_glyph_dsc_t;
/**********************
* STATIC PROTOTYPES
@@ -191,10 +186,34 @@ void lv_font_add(lv_font_t * child, lv_font_t * parent)
}
/**
* Tells if font which contains `letter` is monospace or not
* @param font_p point to font
* @param letter an UNICODE character code
* @return true: the letter is monospace; false not monospace
*/
bool lv_font_is_monospace(const lv_font_t * font_p, uint32_t letter)
{
const lv_font_t * font_i = font_p;
int16_t w;
while(font_i != NULL) {
w = font_i->get_width(font_i, letter);
if(w >= 0) {
/*Glyph found*/
if(font_i->monospace) return true;
return false;
}
font_i = font_i->next_page;
}
return 0;
}
/**
* Return with the bitmap of a font.
* @param font_p pointer to a font
* @param letter a letter
* @param letter an UNICODE character code
* @return pointer to the bitmap of the letter
*/
const uint8_t * lv_font_get_bitmap(const lv_font_t * font_p, uint32_t letter)
@@ -211,12 +230,37 @@ const uint8_t * lv_font_get_bitmap(const lv_font_t * font_p, uint32_t letter)
}
/**
* Get the width of a letter in a font
* Get the width of a letter in a font. If `monospace` is set then return with it.
* @param font_p pointer to a font
* @param letter an UNICODE character code
* @return the width of a letter
*/
uint8_t lv_font_get_width(const lv_font_t * font_p, uint32_t letter)
{
const lv_font_t * font_i = font_p;
int16_t w;
while(font_i != NULL) {
w = font_i->get_width(font_i, letter);
if(w >= 0) {
/*Glyph found*/
uint8_t m = font_i->monospace;
if(m) w = m;
return w;
}
font_i = font_i->next_page;
}
return 0;
}
/**
* Get the width of the letter without overwriting it with the `monospace` attribute
* @param font_p pointer to a font
* @param letter an UNICODE character code
* @return the width of a letter
*/
uint8_t lv_font_get_real_width(const lv_font_t * font_p, uint32_t letter)
{
const lv_font_t * font_i = font_p;
int16_t w;
+21 -10
View File
@@ -18,6 +18,7 @@ extern "C" {
#include <stdint.h>
#include <stddef.h>
#include <stdbool.h>
#include "lv_fonts/lv_symbol_def.h"
@@ -52,7 +53,8 @@ typedef struct _lv_font_struct
const uint8_t * (*get_bitmap)(const struct _lv_font_struct *,uint32_t); /*Get a glyph's bitmap from a font*/
int16_t (*get_width)(const struct _lv_font_struct *,uint32_t); /*Get a glyph's with with a given font*/
struct _lv_font_struct * next_page; /*Pointer to a font extension*/
uint32_t bpp :4; /*Bit per pixel: 1, 2 or 4*/
uint32_t bpp :4; /*Bit per pixel: 1, 2 or 4*/
uint32_t monospace :8; /*Fix width (0: normal width)*/
} lv_font_t;
/**********************
@@ -71,14 +73,31 @@ void lv_font_init(void);
*/
void lv_font_add(lv_font_t *child, lv_font_t *parent);
/**
* Tells if font which contains `letter` is monospace or not
* @param font_p point to font
* @param letter an UNICODE character code
* @return true: the letter is monospace; false not monospace
*/
bool lv_font_is_monospace(const lv_font_t * font_p, uint32_t letter);
/**
* Return with the bitmap of a font.
* @param font_p pointer to a font
* @param letter a letter
* @param letter an UNICODE character code
* @return pointer to the bitmap of the letter
*/
const uint8_t * lv_font_get_bitmap(const lv_font_t * font_p, uint32_t letter);
/**
* Get the width of a letter in a font. If `monospace` is set then return with it.
* @param font_p pointer to a font
* @param letter an UNICODE character code
* @return the width of a letter
*/
uint8_t lv_font_get_width(const lv_font_t * font_p, uint32_t letter);
/**
* Get the height of a font
* @param font_p pointer to a font
@@ -89,14 +108,6 @@ static inline uint8_t lv_font_get_height(const lv_font_t * font_p)
return font_p->h_px;
}
/**
* Get the width of a letter in a font
* @param font_p pointer to a font
* @param letter a letter
* @return the width of a letter
*/
uint8_t lv_font_get_width(const lv_font_t * font_p, uint32_t letter);
/**
* Get the bit-per-pixel of font
* @param font pointer to font
+1
View File
@@ -5372,6 +5372,7 @@ lv_font_t lv_font_dejavu_10 = {
#elif USE_LV_FONT_DEJAVU_10 == 8
.bpp = 8, /*Bit per pixel*/
#endif
.monospace = 0,
.next_page = NULL, /*Pointer to a font extension*/
};
@@ -3636,6 +3636,7 @@ lv_font_t lv_font_dejavu_10_cyrillic = {
#elif USE_LV_FONT_DEJAVU_10_CYRILLIC == 8
.bpp = 8, /*Bit per pixel*/
#endif
.monospace = 0,
.next_page = NULL, /*Pointer to a font extension*/
};
@@ -5428,6 +5428,7 @@ lv_font_t lv_font_dejavu_10_latin_sup = {
#elif USE_LV_FONT_DEJAVU_10_LATIN_SUP == 8
.bpp = 8, /*Bit per pixel*/
#endif
.monospace = 0,
.next_page = NULL, /*Pointer to a font extension*/
};
+1
View File
@@ -9172,6 +9172,7 @@ lv_font_t lv_font_dejavu_20 = {
#elif USE_LV_FONT_DEJAVU_20 == 8
.bpp = 8, /*Bit per pixel*/
#endif
.monospace = 0,
.next_page = NULL, /*Pointer to a font extension*/
};
@@ -6196,6 +6196,7 @@ lv_font_t lv_font_dejavu_20_cyrillic = {
#elif USE_LV_FONT_DEJAVU_20_CYRILLIC == 8
.bpp = 8, /*Bit per pixel*/
#endif
.monospace = 0,
.next_page = NULL, /*Pointer to a font extension*/
};
@@ -9268,6 +9268,7 @@ lv_font_t lv_font_dejavu_20_latin_sup = {
#elif USE_LV_FONT_DEJAVU_20_LATIN_SUP == 8
.bpp = 8, /*Bit per pixel*/
#endif
.monospace = 0,
.next_page = NULL, /*Pointer to a font extension*/
};
+1
View File
@@ -12972,6 +12972,7 @@ lv_font_t lv_font_dejavu_30 = {
#elif USE_LV_FONT_DEJAVU_30 == 8
.bpp = 8, /*Bit per pixel*/
#endif
.monospace = 0,
.next_page = NULL, /*Pointer to a font extension*/
};
@@ -8756,6 +8756,7 @@ lv_font_t lv_font_dejavu_30_cyrillic = {
#elif USE_LV_FONT_DEJAVU_30_CYRILLIC == 8
.bpp = 8, /*Bit per pixel*/
#endif
.monospace = 0,
.next_page = NULL, /*Pointer to a font extension*/
};
@@ -13108,6 +13108,7 @@ lv_font_t lv_font_dejavu_30_latin_sup = {
#elif USE_LV_FONT_DEJAVU_30_LATIN_SUP == 8
.bpp = 8, /*Bit per pixel*/
#endif
.monospace = 0,
.next_page = NULL, /*Pointer to a font extension*/
};
+1
View File
@@ -16772,6 +16772,7 @@ lv_font_t lv_font_dejavu_40 = {
#elif USE_LV_FONT_DEJAVU_40 == 8
.bpp = 8, /*Bit per pixel*/
#endif
.monospace = 0,
.next_page = NULL, /*Pointer to a font extension*/
};
@@ -16948,6 +16948,7 @@ lv_font_t lv_font_dejavu_40_latin_sup = {
#elif USE_LV_FONT_DEJAVU_40_LATIN_SUP == 8
.bpp = 8, /*Bit per pixel*/
#endif
.monospace = 0,
.next_page = NULL, /*Pointer to a font extension*/
};
+1
View File
@@ -2858,6 +2858,7 @@ lv_font_t lv_font_symbol_10 = {
#elif USE_LV_FONT_SYMBOL_10 == 8
.bpp = 8, /*Bit per pixel*/
#endif
.monospace = 0,
.next_page = NULL, /*Pointer to a font extension*/
};
+1
View File
@@ -4858,6 +4858,7 @@ lv_font_t lv_font_symbol_20 = {
#elif USE_LV_FONT_SYMBOL_20 == 8
.bpp = 8, /*Bit per pixel*/
#endif
.monospace = 0,
.next_page = NULL, /*Pointer to a font extension*/
};
+1
View File
@@ -6852,6 +6852,7 @@ lv_font_t lv_font_symbol_30 = {
#elif USE_LV_FONT_SYMBOL_30 == 8
.bpp = 8, /*Bit per pixel*/
#endif
.monospace = 0,
.next_page = NULL, /*Pointer to a font extension*/
};
+1
View File
@@ -8858,6 +8858,7 @@ lv_font_t lv_font_symbol_40 = {
#elif USE_LV_FONT_SYMBOL_40 == 8
.bpp = 8, /*Bit per pixel*/
#endif
.monospace = 0,
.next_page = NULL, /*Pointer to a font extension*/
};