1
0
mirror of https://github.com/lvgl/lvgl.git synced 2025-01-28 07:03:00 +08:00

merge new font API

This commit is contained in:
Gabor Kiss-Vamosi 2019-05-29 05:31:03 +02:00
commit b174398cb5
35 changed files with 1703 additions and 147602 deletions

View File

@ -229,11 +229,15 @@ void lv_draw_fill(const lv_area_t * cords_p, const lv_area_t * mask_p, lv_color_
void lv_draw_letter(const lv_point_t * pos_p, const lv_area_t * mask_p, const lv_font_t * font_p, void lv_draw_letter(const lv_point_t * pos_p, const lv_area_t * mask_p, const lv_font_t * font_p,
uint32_t letter, lv_color_t color, lv_opa_t opa) uint32_t letter, lv_color_t color, lv_opa_t opa)
{ {
const uint8_t bpp1_opa_table[2] = { /*clang-format off*/
0, 255}; /*Opacity mapping with bpp = 1 (Just for compatibility)*/ const uint8_t bpp1_opa_table[2] = { 0, 255}; /*Opacity mapping with bpp = 1 (Just for compatibility)*/
const uint8_t bpp2_opa_table[4] = {0, 85, 170, 255}; /*Opacity mapping with bpp = 2*/ const uint8_t bpp2_opa_table[4] = {0, 85, 170, 255}; /*Opacity mapping with bpp = 2*/
const uint8_t bpp4_opa_table[16] = {0, 17, 34, 51, /*Opacity mapping with bpp = 4*/ const uint8_t bpp4_opa_table[16] = {0, 17, 34, 51, /*Opacity mapping with bpp = 4*/
68, 85, 102, 119, 136, 153, 170, 187, 204, 221, 238, 255}; 68, 85, 102, 119,
136, 153, 170, 187,
204, 221, 238, 255};
/*clang-format on*/
if(opa < LV_OPA_MIN) return; if(opa < LV_OPA_MIN) return;
if(opa > LV_OPA_MAX) opa = LV_OPA_COVER; if(opa > LV_OPA_MAX) opa = LV_OPA_COVER;
@ -242,45 +246,43 @@ void lv_draw_letter(const lv_point_t * pos_p, const lv_area_t * mask_p, const lv
return; return;
} }
lv_coord_t pos_x = pos_p->x; lv_font_glyph_dsc_t g;
lv_coord_t pos_y = pos_p->y; bool g_ret = lv_font_get_glyph_dsc(font_p, &g, letter);
uint8_t letter_w = lv_font_get_real_width(font_p, letter); if(g_ret == false) return;
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)*/ lv_coord_t pos_x = pos_p->x + g.ofs_x;
lv_coord_t pos_y = pos_p->y + g.ofs_y;
const uint8_t * bpp_opa_table; const uint8_t * bpp_opa_table;
uint8_t mask_init; uint8_t bitmask_init;
uint8_t mask; uint8_t bitmask;
if(lv_font_is_monospace(font_p, letter)) { switch(g.bpp) {
pos_x += (lv_font_get_width(font_p, letter) - letter_w) / 2;
}
switch(bpp) {
case 1: case 1:
bpp_opa_table = bpp1_opa_table; bpp_opa_table = bpp1_opa_table;
mask_init = 0x80; bitmask_init = 0x80;
break; break;
case 2: case 2:
bpp_opa_table = bpp2_opa_table; bpp_opa_table = bpp2_opa_table;
mask_init = 0xC0; bitmask_init = 0xC0;
break; break;
case 4: case 4:
bpp_opa_table = bpp4_opa_table; bpp_opa_table = bpp4_opa_table;
mask_init = 0xF0; bitmask_init = 0xF0;
break; break;
case 8: case 8:
bpp_opa_table = NULL; bpp_opa_table = NULL;
mask_init = 0xFF; bitmask_init = 0xFF;
break; /*No opa table, pixel value will be used directly*/ break; /*No opa table, pixel value will be used directly*/
default: return; /*Invalid bpp. Can't render the letter*/ default: return; /*Invalid bpp. Can't render the letter*/
} }
const uint8_t * map_p = lv_font_get_bitmap(font_p, letter); const uint8_t * map_p = lv_font_get_glyph_bitmap(font_p, letter);
if(map_p == NULL) return; if(map_p == NULL) return;
/*If the letter is completely out of mask don't draw it */ /*If the letter is completely out of mask don't draw it */
if(pos_x + letter_w < mask_p->x1 || pos_x > mask_p->x2 || pos_y + letter_h < mask_p->y1 || if(pos_x + g.box_w < mask_p->x1 || pos_x > mask_p->x2 || pos_y + g.box_h < mask_p->y1 ||
pos_y > mask_p->y2) pos_y > mask_p->y2)
return; return;
@ -293,19 +295,16 @@ void lv_draw_letter(const lv_point_t * pos_p, const lv_area_t * mask_p, const lv
uint8_t col_bit; uint8_t col_bit;
uint8_t col_byte_cnt; uint8_t col_byte_cnt;
/*Width in bytes (on the screen finally) (e.g. w = 11 -> 2 bytes wide)*/ uint8_t width_byte_scr = g.box_w >> 3; /*Width in bytes (on the screen finally) (e.g. w = 11 -> 2 bytes wide)*/
uint8_t width_byte_scr = letter_w >> 3; if(g.box_w & 0x7) width_byte_scr++;
if(letter_w & 0x7) width_byte_scr++; uint8_t width_byte_bpp = (g.box_w * g.bpp) >> 3; /*Letter width in byte. Real width in the font*/
if((g.box_w * g.bpp) & 0x7) width_byte_bpp++;
/*Letter width in byte. Real width in the font*/
uint8_t width_byte_bpp = (letter_w * bpp) >> 3;
if((letter_w * bpp) & 0x7) width_byte_bpp++;
/* Calculate the col/row start/end on the map*/ /* Calculate the col/row start/end on the map*/
lv_coord_t col_start = pos_x >= mask_p->x1 ? 0 : mask_p->x1 - pos_x; 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 col_end = pos_x + g.box_w <= mask_p->x2 ? g.box_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_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; lv_coord_t row_end = pos_y + g.box_h <= mask_p->y2 ? g.box_h : mask_p->y2 - pos_y + 1;
/*Set a pointer on VDB to the first pixel of the letter*/ /*Set a pointer on VDB to the first pixel of the letter*/
vdb_buf_tmp += ((pos_y - vdb->area.y1) * vdb_width) + pos_x - vdb->area.x1; vdb_buf_tmp += ((pos_y - vdb->area.y1) * vdb_width) + pos_x - vdb->area.x1;
@ -314,21 +313,21 @@ void lv_draw_letter(const lv_point_t * pos_p, const lv_area_t * mask_p, const lv
vdb_buf_tmp += (row_start * vdb_width) + col_start; vdb_buf_tmp += (row_start * vdb_width) + col_start;
/*Move on the map too*/ /*Move on the map too*/
map_p += (row_start * width_byte_bpp) + ((col_start * bpp) >> 3); map_p += (row_start * width_byte_bpp) + ((col_start * g.bpp) >> 3);
uint8_t letter_px; uint8_t letter_px;
lv_opa_t px_opa; lv_opa_t px_opa;
for(row = row_start; row < row_end; row++) { for(row = row_start; row < row_end; row++) {
col_byte_cnt = 0; col_byte_cnt = 0;
col_bit = (col_start * bpp) % 8; col_bit = (col_start * g.bpp) % 8;
mask = mask_init >> col_bit; bitmask = bitmask_init >> col_bit;
for(col = col_start; col < col_end; col++) { for(col = col_start; col < col_end; col++) {
letter_px = (*map_p & mask) >> (8 - col_bit - bpp); letter_px = (*map_p & bitmask) >> (8 - col_bit - g.bpp);
if(letter_px != 0) { if(letter_px != 0) {
if(opa == LV_OPA_COVER) { if(opa == LV_OPA_COVER) {
px_opa = bpp == 8 ? letter_px : bpp_opa_table[letter_px]; px_opa = g.bpp == 8 ? letter_px : bpp_opa_table[letter_px];
} else { } else {
px_opa = bpp == 8 ? (uint16_t)((uint16_t)letter_px * opa) >> 8 px_opa = g.bpp == 8 ? (uint16_t)((uint16_t)letter_px * opa) >> 8
: (uint16_t)((uint16_t)bpp_opa_table[letter_px] * opa) >> 8; : (uint16_t)((uint16_t)bpp_opa_table[letter_px] * opa) >> 8;
} }
@ -351,13 +350,13 @@ void lv_draw_letter(const lv_point_t * pos_p, const lv_area_t * mask_p, const lv
vdb_buf_tmp++; vdb_buf_tmp++;
if(col_bit < 8 - bpp) { if(col_bit < 8 - g.bpp) {
col_bit += bpp; col_bit += g.bpp;
mask = mask >> bpp; bitmask = bitmask >> g.bpp;
} else { } else {
col_bit = 0; col_bit = 0;
col_byte_cnt++; col_byte_cnt++;
mask = mask_init; bitmask = bitmask_init;
map_p++; map_p++;
} }
} }

View File

@ -70,7 +70,7 @@ void lv_draw_label(const lv_area_t * coords, const lv_area_t * mask, const lv_st
w = p.x; w = p.x;
} }
lv_coord_t line_height = lv_font_get_height(font) + style->text.line_space; lv_coord_t line_height = lv_font_get_line_height(font) + style->text.line_space;
/*Init variables for the first line*/ /*Init variables for the first line*/
lv_coord_t line_width = 0; lv_coord_t line_width = 0;
@ -136,8 +136,10 @@ void lv_draw_label(const lv_area_t * coords, const lv_area_t * mask, const lv_st
cmd_state = CMD_STATE_WAIT; cmd_state = CMD_STATE_WAIT;
i = line_start; i = line_start;
uint32_t letter; uint32_t letter;
uint32_t letter_next;
while(i < line_end) { while(i < line_end) {
letter = lv_txt_encoded_next(txt, &i); letter = lv_txt_encoded_next(txt, &i);
letter_next = lv_txt_encoded_next(&txt[i], NULL);
/*Handle the re-color command*/ /*Handle the re-color command*/
if((flag & LV_TXT_FLAG_RECOLOR) != 0) { if((flag & LV_TXT_FLAG_RECOLOR) != 0) {
@ -181,7 +183,7 @@ void lv_draw_label(const lv_area_t * coords, const lv_area_t * mask, const lv_st
if(cmd_state == CMD_STATE_IN) color = recolor; if(cmd_state == CMD_STATE_IN) color = recolor;
letter_w = lv_font_get_width(font, letter); letter_w = lv_font_get_glyph_width(font, letter, letter_next);
if(sel_start != 0xFFFF && sel_end != 0xFFFF) { if(sel_start != 0xFFFF && sel_end != 0xFFFF) {
int char_ind = lv_encoded_get_char_id(txt, i); int char_ind = lv_encoded_get_char_id(txt, i);

View File

@ -37,127 +37,7 @@
*/ */
void lv_font_builtin_init(void) void lv_font_builtin_init(void)
{ {
/*DEJAVU 10*/
#if LV_USE_FONT_DEJAVU_10 != 0
lv_font_add(&lv_font_dejavu_10, NULL);
#endif
#if LV_USE_FONT_DEJAVU_10_LATIN_SUP != 0
#if LV_USE_FONT_DEJAVU_10 != 0
lv_font_add(&lv_font_dejavu_10_latin_sup, &lv_font_dejavu_10);
#else
lv_font_add(&lv_font_dejavu_10_latin_sup, NULL);
#endif
#endif
#if LV_USE_FONT_DEJAVU_10_CYRILLIC != 0
#if LV_USE_FONT_DEJAVU_10 != 0
lv_font_add(&lv_font_dejavu_10_cyrillic, &lv_font_dejavu_10);
#else
lv_font_add(&lv_font_dejavu_10_cyrillic, NULL);
#endif
#endif
/*SYMBOL 10*/
#if LV_USE_FONT_SYMBOL_10 != 0
#if LV_USE_FONT_DEJAVU_10 != 0
lv_font_add(&lv_font_symbol_10, &lv_font_dejavu_10);
#else
lv_font_add(&lv_font_symbol_10, NULL);
#endif
#endif
/*DEJAVU 20*/
#if LV_USE_FONT_DEJAVU_20 != 0
lv_font_add(&lv_font_dejavu_20, NULL);
#endif
#if LV_USE_FONT_DEJAVU_20_LATIN_SUP != 0
#if LV_USE_FONT_DEJAVU_20 != 0
lv_font_add(&lv_font_dejavu_20_latin_sup, &lv_font_dejavu_20);
#else
lv_font_add(&lv_font_symbol_20_latin_sup, NULL);
#endif
#endif
#if LV_USE_FONT_DEJAVU_20_CYRILLIC != 0
#if LV_USE_FONT_DEJAVU_20 != 0
lv_font_add(&lv_font_dejavu_20_cyrillic, &lv_font_dejavu_20);
#else
lv_font_add(&lv_font_dejavu_20_cyrillic, NULL);
#endif
#endif
/*SYMBOL 20*/
#if LV_USE_FONT_SYMBOL_20 != 0
#if LV_USE_FONT_DEJAVU_20 != 0
lv_font_add(&lv_font_symbol_20, &lv_font_dejavu_20);
#else
lv_font_add(&lv_font_symbol_20, NULL);
#endif
#endif
/*DEJAVU 30*/
#if LV_USE_FONT_DEJAVU_30 != 0
lv_font_add(&lv_font_dejavu_30, NULL);
#endif
#if LV_USE_FONT_DEJAVU_30_LATIN_SUP != 0
#if LV_USE_FONT_DEJAVU_30 != 0
lv_font_add(&lv_font_dejavu_30_latin_sup, &lv_font_dejavu_30);
#else
lv_font_add(&lv_font_dejavu_30_latin_sup, NULL);
#endif
#endif
#if LV_USE_FONT_DEJAVU_30_CYRILLIC != 0
#if LV_USE_FONT_DEJAVU_30 != 0
lv_font_add(&lv_font_dejavu_30_cyrillic, &lv_font_dejavu_30);
#else
lv_font_add(&lv_font_dejavu_30_cyrillic, NULL);
#endif
#endif
/*SYMBOL 30*/
#if LV_USE_FONT_SYMBOL_30 != 0
#if LV_USE_FONT_DEJAVU_30 != 0
lv_font_add(&lv_font_symbol_30, &lv_font_dejavu_30);
#else
lv_font_add(&lv_font_symbol_30, NULL);
#endif
#endif
/*DEJAVU 40*/
#if LV_USE_FONT_DEJAVU_40 != 0
lv_font_add(&lv_font_dejavu_40, NULL);
#endif
#if LV_USE_FONT_DEJAVU_40_LATIN_SUP != 0
#if LV_USE_FONT_DEJAVU_40 != 0
lv_font_add(&lv_font_dejavu_40_latin_sup, &lv_font_dejavu_40);
#else
lv_font_add(&lv_font_dejavu_40_latin_sup, NULL);
#endif
#endif
#if LV_USE_FONT_DEJAVU_40_CYRILLIC != 0
#if LV_USE_FONT_DEJAVU_40 != 0
lv_font_add(&lv_font_dejavu_40_cyrillic, &lv_font_dejavu_40);
#else
lv_font_add(&lv_font_dejavu_40_cyrillic, NULL);
#endif
#endif
/*SYMBOL 40*/
#if LV_USE_FONT_SYMBOL_40 != 0
#if LV_USE_FONT_DEJAVU_40 != 0
lv_font_add(&lv_font_symbol_40, &lv_font_dejavu_40);
#else
lv_font_add(&lv_font_symbol_40, NULL);
#endif
#endif
} }
/********************** /**********************

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

1102
src/lv_fonts/lvgl_sample.c Normal file

File diff suppressed because it is too large Load Diff

View File

@ -42,7 +42,7 @@ static int32_t lv_font_codeCompare(const void * pRef, const void * pElement);
**********************/ **********************/
/** /**
* Initialize the fonts * Initialize the font module
*/ */
void lv_font_init(void) void lv_font_init(void)
{ {
@ -82,41 +82,17 @@ void lv_font_remove(lv_font_t * child, lv_font_t * parent)
parent->next_page = child->next_page; parent->next_page = child->next_page;
} }
/**
* 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. * Return with the bitmap of a font.
* @param font_p pointer to a font * @param font_p pointer to a font
* @param letter an UNICODE character code * @param letter an UNICODE character code
* @return pointer to the bitmap of the letter * @return pointer to the bitmap of the letter
*/ */
const uint8_t * lv_font_get_bitmap(const lv_font_t * font_p, uint32_t letter) const uint8_t * lv_font_get_glyph_bitmap(const lv_font_t * font_p, uint32_t letter)
{ {
const lv_font_t * font_i = font_p; const lv_font_t * font_i = font_p;
while(font_i != NULL) { while(font_i != NULL) {
const uint8_t * bitmap = font_i->get_bitmap(font_i, letter); const uint8_t * bitmap = font_i->get_glyph_bitmap(font_i, letter);
if(bitmap) return bitmap; if(bitmap) return bitmap;
font_i = font_i->next_page; font_i = font_i->next_page;
@ -126,171 +102,27 @@ 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. * Get the descriptor of a glyph
* @param font_p pointer to a font * @param font_p pointer to font
* @param letter an UNICODE character code * @param dsc_out store the result descriptor here
* @return the width of a letter * @param letter an UNICODE letter code
* @return true: descriptor is successfully loaded into `dsc_out`.
* false: the letter was not found, no data is loaded to `dsc_out`
*/ */
uint8_t lv_font_get_width(const lv_font_t * font_p, uint32_t letter) bool lv_font_get_glyph_dsc(const lv_font_t * font_p, lv_font_glyph_dsc_t * dsc_out, uint32_t letter)
{ {
const lv_font_t * font_i = font_p; const lv_font_t * font_i = font_p;
int16_t w; bool ret;
while(font_i != NULL) { while(font_i != NULL) {
w = font_i->get_width(font_i, letter); ret = font_i->get_glyph_dsc(font_i, dsc_out, letter);
if(w >= 0) { if(ret) return ret;
/*Glyph found*/
uint8_t m = font_i->monospace;
if(m) w = m;
return w;
}
font_i = font_i->next_page; font_i = font_i->next_page;
} }
return 0; return false;
}
/**
* 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;
while(font_i != NULL) {
w = font_i->get_width(font_i, letter);
if(w >= 0) return w;
font_i = font_i->next_page;
}
return 0;
}
/**
* Get the bit-per-pixel of font
* @param font pointer to font
* @param letter a letter from font (font extensions can have different bpp)
* @return bpp of the font (or font extension)
*/
uint8_t lv_font_get_bpp(const lv_font_t * font, uint32_t letter)
{
const lv_font_t * font_i = font;
while(font_i != NULL) {
if(letter >= font_i->unicode_first && letter <= font_i->unicode_last) {
return font_i->bpp;
}
font_i = font_i->next_page;
}
return 0;
}
/**
* Generic bitmap get function used in 'font->get_bitmap' when the font contains all characters in
* the range
* @param font pointer to font
* @param unicode_letter an unicode letter which bitmap should be get
* @return pointer to the bitmap or NULL if not found
*/
const uint8_t * lv_font_get_bitmap_continuous(const lv_font_t * font, uint32_t unicode_letter)
{
/*Check the range*/
if(unicode_letter < font->unicode_first || unicode_letter > font->unicode_last) return NULL;
uint32_t index = (unicode_letter - font->unicode_first);
return &font->glyph_bitmap[font->glyph_dsc[index].glyph_index];
}
/**
* Generic bitmap get function used in 'font->get_bitmap' when the font NOT contains all characters
* in the range (sparse)
* @param font pointer to font
* @param unicode_letter an unicode letter which bitmap should be get
* @return pointer to the bitmap or NULL if not found
*/
const uint8_t * lv_font_get_bitmap_sparse(const lv_font_t * font, uint32_t unicode_letter)
{
/*Check the range*/
if(unicode_letter < font->unicode_first || unicode_letter > font->unicode_last) return NULL;
uint32_t * pUnicode;
pUnicode = lv_utils_bsearch(&unicode_letter, (uint32_t *)font->unicode_list, font->glyph_cnt,
sizeof(uint32_t), lv_font_codeCompare);
if(pUnicode != NULL) {
uint32_t idx = (uint32_t)(pUnicode - font->unicode_list);
return &font->glyph_bitmap[font->glyph_dsc[idx].glyph_index];
}
return NULL;
}
/**
* Generic glyph width get function used in 'font->get_width' when the font contains all characters
* in the range
* @param font pointer to font
* @param unicode_letter an unicode letter which width should be get
* @return width of the gylph or -1 if not found
*/
int16_t lv_font_get_width_continuous(const lv_font_t * font, uint32_t unicode_letter)
{
/*Check the range*/
if(unicode_letter < font->unicode_first || unicode_letter > font->unicode_last) {
return -1;
}
uint32_t index = (unicode_letter - font->unicode_first);
return font->glyph_dsc[index].w_px;
}
/**
* Generic glyph width get function used in 'font->get_bitmap' when the font NOT contains all
* characters in the range (sparse)
* @param font pointer to font
* @param unicode_letter an unicode letter which width should be get
* @return width of the glyph or -1 if not found
*/
int16_t lv_font_get_width_sparse(const lv_font_t * font, uint32_t unicode_letter)
{
/*Check the range*/
if(unicode_letter < font->unicode_first || unicode_letter > font->unicode_last) return -1;
uint32_t * pUnicode;
pUnicode = lv_utils_bsearch(&unicode_letter, (uint32_t *)font->unicode_list, font->glyph_cnt,
sizeof(uint32_t), lv_font_codeCompare);
if(pUnicode != NULL) {
uint32_t idx = (uint32_t)(pUnicode - font->unicode_list);
return font->glyph_dsc[idx].w_px;
}
return -1;
} }
/********************** /**********************
* STATIC FUNCTIONS * STATIC FUNCTIONS
**********************/ **********************/
/** Code Comparator.
*
* Compares the value of both input arguments.
*
* @param[in] pRef Pointer to the reference.
* @param[in] pElement Pointer to the element to compare.
*
* @return Result of comparison.
* @retval < 0 Reference is greater than element.
* @retval = 0 Reference is equal to element.
* @retval > 0 Reference is less than element.
*
*/
static int32_t lv_font_codeCompare(const void * pRef, const void * pElement)
{
return (*(uint32_t *)pRef) - (*(uint32_t *)pElement);
}

View File

@ -28,39 +28,74 @@ extern "C" {
/********************* /*********************
* DEFINES * DEFINES
*********************/ *********************/
/*Number of fractional digits in the advanced width (`adv_w`) field of `lv_font_glyph_dsc_t`*/
#define LV_FONT_WIDTH_FRACT_DIGIT 4
#define LV_FONT_KERN_POSITIVE 0
#define LV_FONT_KERN_NEGATIVE 1
/********************** /**********************
* TYPEDEFS * TYPEDEFS
**********************/ **********************/
/*------------------
* General types
*-----------------*/
/*Describe the properties of a glyph*/
typedef struct typedef struct
{ {
uint32_t w_px : 8; uint16_t adv_w; /*The glyph needs this space. Draw the next glyph after this width. 8 bit integer, 4 bit fractional */
uint32_t glyph_index : 24; uint8_t box_w; /*Width of the glyph's bounding box*/
} lv_font_glyph_dsc_t; uint8_t box_h; /*Height of the glyph's bounding box*/
int8_t ofs_x; /*x offset of the bounding box*/
typedef struct int8_t ofs_y; /*y offset of the bounding box*/
{ uint8_t bpp; /*Bit-per-pixel: 1, 2, 4, 8*/
uint32_t unicode : 21; }lv_font_glyph_dsc_t;
uint32_t glyph_dsc_index : 11;
} lv_font_unicode_map_t;
/*Describe the properties of a font*/
typedef struct _lv_font_struct typedef struct _lv_font_struct
{ {
uint32_t unicode_first; /*Get a glyph's descriptor from a font*/
uint32_t unicode_last; bool (*get_glyph_dsc)(const struct _lv_font_struct *, lv_font_glyph_dsc_t *, uint32_t letter);
const uint8_t * glyph_bitmap;
const lv_font_glyph_dsc_t * glyph_dsc; /*Get a glyph's bitmap from a font*/
const uint32_t * unicode_list; const uint8_t * (*get_glyph_bitmap)(const struct _lv_font_struct *, uint32_t);
const uint8_t * (*get_bitmap)(const struct _lv_font_struct *,
uint32_t); /*Get a glyph's bitmap from a font*/ /*Pointer to the font in a font pack (must have the same line height)*/
int16_t (*get_width)(const struct _lv_font_struct *, uint8_t line_height; /*The real line height where any text fits*/
uint32_t); /*Get a glyph's with with a given font*/ uint8_t base_line; /*Base line measured from the top of the line_height*/
struct _lv_font_struct * next_page; /*Pointer to a font extension*/ void * dsc; /*Store implementation specific data here*/
uint32_t h_px : 8;
uint32_t bpp : 4; /*Bit per pixel: 1, 2 or 4*/ /*
uint32_t monospace : 8; /*Fix width (0: normal width)*/ - Font size:
uint16_t glyph_cnt; /*Number of glyphs (letters) in the font*/ not required for calculations
- Ascent
- Descent
- typoAscent
- typoDescent
- typographic descent:
Better to skip them to avoid confusion. Only line height and baseline matter for rendering.
- typoLineGap
Will be overwritten by the style.
- default advanceWidth
Not supported in text format. glyph->advacedWidth is always present
- glyphIdFormat
Has foxed size on text format
- advanceWidthFormat
Fix 8.4 format
- Glyph BBox x/y bits length (signed value)
- Glyph BBox w/h bits length (unsigned)
Has fixed size
- Glyph advanceWidth bits length (unsigned, may be FP4)
Fix 8.4 format
*/
} lv_font_t; } lv_font_t;
/********************** /**********************
@ -68,7 +103,7 @@ typedef struct _lv_font_struct
**********************/ **********************/
/** /**
* Initialize the fonts * Initialize the font module
*/ */
void lv_font_init(void); void lv_font_init(void);
@ -86,97 +121,53 @@ void lv_font_add(lv_font_t * child, lv_font_t * parent);
*/ */
void lv_font_remove(lv_font_t * child, lv_font_t * parent); void lv_font_remove(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. * Return with the bitmap of a font.
* @param font_p pointer to a font * @param font_p pointer to a font
* @param letter an UNICODE character code * @param letter an UNICODE character code
* @return pointer to the bitmap of the letter * @return pointer to the bitmap of the letter
*/ */
const uint8_t * lv_font_get_bitmap(const lv_font_t * font_p, uint32_t letter); const uint8_t * lv_font_get_glyph_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. * Get the descriptor of a glyph
* @param font_p pointer to a font * @param font_p pointer to font
* @param letter an UNICODE character code * @param dsc_out store the result descriptor here
* @return the width of a letter * @param letter an UNICODE letter code
* @return true: descriptor is successfully loaded into `dsc_out`.
* false: the letter was not found, no data is loaded to `dsc_out`
*/ */
uint8_t lv_font_get_width(const lv_font_t * font_p, uint32_t letter); bool lv_font_get_glyph_dsc(const lv_font_t * font_p, lv_font_glyph_dsc_t * dsc_out, uint32_t letter);
/** /**
* Get the width of the letter without overwriting it with the `monospace` attribute * Get the width of a glyph with kerning
* @param font_p pointer to a font * @param font pointer to a font
* @param letter an UNICODE character code * @param letter an UNICODE letter
* @return the width of a letter * @param letter_next the next letter after `letter`. Used for kerning
* @return the width of the glyph
*/ */
uint8_t lv_font_get_real_width(const lv_font_t * font_p, uint32_t letter); uint8_t lv_font_get_glyph_width(const lv_font_t * font, uint32_t letter, uint32_t letter_next);
/** /**
* Get the height of a font * Get the line height of a font. All characters fit into this height
* @param font_p pointer to a font * @param font_p pointer to a font
* @return the height of a font * @return the height of a font
*/ */
static inline uint8_t lv_font_get_height(const lv_font_t * font_p) static inline uint8_t lv_font_get_line_height(const lv_font_t * font_p)
{ {
return font_p->h_px; return font_p->line_height;
} }
/**
* Get the bit-per-pixel of font
* @param font pointer to font
* @param letter a letter from font (font extensions can have different bpp)
* @return bpp of the font (or font extension)
*/
uint8_t lv_font_get_bpp(const lv_font_t * font, uint32_t letter);
/**
* Generic bitmap get function used in 'font->get_bitmap' when the font contains all characters in
* the range
* @param font pointer to font
* @param unicode_letter an unicode letter which bitmap should be get
* @return pointer to the bitmap or NULL if not found
*/
const uint8_t * lv_font_get_bitmap_continuous(const lv_font_t * font, uint32_t unicode_letter);
/**
* Generic bitmap get function used in 'font->get_bitmap' when the font NOT contains all characters
* in the range (sparse)
* @param font pointer to font
* @param unicode_letter an unicode letter which bitmap should be get
* @return pointer to the bitmap or NULL if not found
*/
const uint8_t * lv_font_get_bitmap_sparse(const lv_font_t * font, uint32_t unicode_letter);
/**
* Generic glyph width get function used in 'font->get_width' when the font contains all characters
* in the range
* @param font pointer to font
* @param unicode_letter an unicode letter which width should be get
* @return width of the gylph or -1 if not found
*/
int16_t lv_font_get_width_continuous(const lv_font_t * font, uint32_t unicode_letter);
/**
* Generic glyph width get function used in 'font->get_bitmap' when the font NOT contains all
* characters in the range (sparse)
* @param font pointer to font
* @param unicode_letter an unicode letter which width should be get
* @return width of the glyph or -1 if not found
*/
int16_t lv_font_get_width_sparse(const lv_font_t * font, uint32_t unicode_letter);
/********************** /**********************
* MACROS * MACROS
**********************/ **********************/
#define LV_FONT_DECLARE(font_name) extern lv_font_t font_name; #define LV_FONT_DECLARE(font_name) extern lv_font_t font_name;
#define LV_FONT_SET_WIDTH(_integer, _fract) ((_integer << LV_FONT_WIDTH_FRACT_DIGIT) + _fract)
#define LV_FONT_GET_WIDTH_INT(_w) (_w >> LV_FONT_WIDTH_FRACT_DIGIT)
#define LV_FONT_GET_WIDTH_FRACT(_w) (_w & ((1 << LV_FONT_WIDTH_FRACT_DIGIT) -1))
/********************** /**********************
* ADD BUILT IN FONTS * ADD BUILT IN FONTS
**********************/ **********************/

View File

@ -0,0 +1,141 @@
/**
* @file lv_font.c
*
*/
/*********************
* INCLUDES
*********************/
#include "lv_font.h"
#include "lv_log.h"
#include "lv_utils.h"
/*********************
* DEFINES
*********************/
/**********************
* TYPEDEFS
**********************/
/**********************
* STATIC PROTOTYPES
**********************/
static int32_t lv_font_codeCompare(const void * pRef, const void * pElement);
/**********************
* STATIC VARIABLES
**********************/
/**********************
* GLOBAL PROTOTYPES
**********************/
/**********************
* MACROS
**********************/
/**********************
* GLOBAL FUNCTIONS
**********************/
/**
* Used as `get_glyph_bitmap` callback in LittelvGL's native font format if the font is uncompressed.
* @param font pointer to font
* @param unicode_letter an unicode letter which bitmap should be get
* @return pointer to the bitmap or NULL if not found
*/
const uint8_t * lv_font_get_bitmap_fmt_txt(const lv_font_t * font, uint32_t unicode_letter)
{
/*Check the range*/
if(unicode_letter < font->unicode_first || unicode_letter > font->unicode_last) return NULL;
lv_font_dsc_built_in_t * font_dsc = (lv_font_dsc_built_in_t *) font->dsc;
/*No Unicode list -> Continuous font*/
if(font_dsc->unicode_list == NULL) {
uint32_t index = (unicode_letter - font->unicode_first);
return &font_dsc->glyph_bitmap[font_dsc->glyph_dsc[index].bitmap_index];
}
/*Has Unicode list -> Sparse font */
else {
uint16_t * pUnicode;
pUnicode = lv_utils_bsearch(&unicode_letter, font_dsc->unicode_list, font_dsc->glyph_cnt,
sizeof(font_dsc->unicode_list[0]), lv_font_codeCompare);
if(pUnicode != NULL) {
uint32_t idx = (uint32_t)(pUnicode - font_dsc->unicode_list);
return &font_dsc->glyph_bitmap[font_dsc->glyph_dsc[idx].bitmap_index];
}
}
/*If not returned earlier then the letter is not found in this font*/
return NULL;
}
/**
* Used as `get_glyph_dsc` callback in LittelvGL's native font format if the font is uncompressed.
* @param font_p pointer to font
* @param dsc_out store the result descriptor here
* @param letter an UNICODE letter code
* @return true: descriptor is successfully loaded into `dsc_out`.
* false: the letter was not found, no data is loaded to `dsc_out`
*/
bool lv_font_get_glyph_dsc_fmt_txt(const lv_font_t * font, lv_font_glyph_dsc_t * dsc_out, uint32_t unicode_letter)
{
/*Check the range*/
if(unicode_letter < font->unicode_first || unicode_letter > font->unicode_last) return NULL;
lv_font_dsc_built_in_t * font_dsc = (lv_font_dsc_built_in_t *) font->dsc;
int32_t index = -1;
/*No Unicode list -> Continuous font*/
if(font_dsc->unicode_list == NULL) {
index = (unicode_letter - font->unicode_first);
}
/*Has Unicode list -> Sparse font */
else {
uint16_t * pUnicode;
pUnicode = lv_utils_bsearch(&unicode_letter, font_dsc->unicode_list, font_dsc->glyph_cnt,
sizeof(font_dsc->unicode_list[0]), lv_font_codeCompare);
if(pUnicode != NULL) {
index = (uint16_t)(pUnicode - font_dsc->unicode_list);
}
}
if(index > 0) {
dsc_out->adv_w = font_dsc->glyph_dsc[index].adv_w;
dsc_out->box_h = font_dsc->glyph_dsc[index].box_h;
dsc_out->box_w = font_dsc->glyph_dsc[index].box_w;
dsc_out->ofs_x = font_dsc->glyph_dsc[index].ofs_x;
dsc_out->ofs_y = font_dsc->glyph_dsc[index].ofs_y;
dsc_out->kern_table = font_dsc->glyph_dsc[index].kern_table;
dsc_out->bpp = font_dsc->bpp;
return true;
} else {
return false;
}
}
/**********************
* STATIC FUNCTIONS
**********************/
/** Code Comparator.
*
* Compares the value of both input arguments.
*
* @param[in] pRef Pointer to the reference.
* @param[in] pElement Pointer to the element to compare.
*
* @return Result of comparison.
* @retval < 0 Reference is greater than element.
* @retval = 0 Reference is equal to element.
* @retval > 0 Reference is less than element.
*
*/
static int32_t lv_font_codeCompare(const void * pRef, const void * pElement)
{
return (*(uint16_t *)pRef) - (*(uint16_t *)pElement);
}

View File

@ -0,0 +1,233 @@
/**
* @file lv_font.h
*
*/
#ifndef LV_FONT_FMT_TXT_H
#define LV_FONT_FMT_TXT_H
#ifdef __cplusplus
extern "C" {
#endif
/*********************
* INCLUDES
*********************/
#ifdef LV_CONF_INCLUDE_SIMPLE
#include "lv_conf.h"
#else
#include "../../../lv_conf.h"
#endif
#include <stdint.h>
#include <stddef.h>
#include <stdbool.h>
#include "../lv_font.h"
/*********************
* DEFINES
*********************/
/**********************
* TYPEDEFS
**********************/
/*Describe a glyph*/
typedef struct
{
uint32_t bitmap_index : 20; /* Start index of the bitmap. A font can be max 1 MB. */
uint32_t adv_w :12; /*Draw the next glyph after this width. 12.4 format (real_value * 16 is stored). */
uint8_t box_w; /*Width of the glyph's bounding box*/
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_fmt_txt_glyph_dsc_t;
typedef enum {
LV_FONT_FMT_TXT_CMAP_FORMAT0_TINY,
LV_FONT_FMT_TXT_CMAP_FORMAT0_FULL,
LV_FONT_FMT_TXT_CMAP_SPARSE_TINY,
LV_FONT_FMT_TXT_CMAP_SPARSE_FULL,
}lv_font_fmt_txt_cmap_type_t;
/* Map codepoints to a `glyph_dsc`s
* Several formats are supported to optimize memory usage
* See https://github.com/littlevgl/lv_font_conv/blob/master/doc/font_spec.md
*/
typedef struct {
/* First Unicode character for this range */
uint32_t range_start;
/* Number of Unicode characters related to this range.
* Last Unicode character = range_start + range_length - 1*/
uint16_t range_length;
/* First glyph ID (array index of `glyph_dsc`) for this range */
uint16_t glyph_id_start;
/*
According the specification there are 4 formats:
https://github.com/littlevgl/lv_font_conv/blob/master/doc/font_spec.md
For simplicity introduce "relative code point":
rcp = codepoint - range_start
and a search function:
search a "value" in an "array" and returns the index of "value".
Format 0 tiny
unicode_list == NULL && glyph_id_ofs_list == NULL
glyph_id = glyph_id_start + rcp
Format 0 full
unicode_list == NULL && glyph_id_ofs_list != NULL
glyph_id = glyph_id_start + glyph_id_ofs_list[rcp]
Sparse tiny
unicode_list != NULL && glyph_id_ofs_list == NULL
glyph_id = glyph_id_start + search(unicode_list, rcp)
Sparse full
unicode_list != NULL && glyph_id_ofs_list != NULL
glyph_id = glyph_id_start + glyph_id_ofs_list[search(unicode_list, rcp)]
*/
uint16_t * unicode_list;
/* 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;
/*Length of `unicode_list` and/or `glyph_id_ofs_list`*/
uint16_t list_length;
/*Type of this character map*/
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];
*/
lv_font_fmt_txt_kern_pair_id_t glyph_ids;
uint8_t * values;
uint16_t pair_cnt;
}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_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)
return i;
3. value = class_pair_values[(left_class-1)*right_class_cnt + (righ_class-1)]
*/
uint8_t * class_pair_values; /*left_class_num * right_class_num value*/
uint8_t * left_class_mapping; /*Map the glyph_ids to classes: index -> glyph_id -> class_id*/
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_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 {
/*The bitmaps os all glyphs*/
const uint8_t * glyph_bitmap;
/*Describe the glyphs*/
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_fmt_txt_cmap_t * cmaps;
/* Store kerning values.
* 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;
/*Scale kern values in 12.4 format*/
uint16_t kern_scale;
/*Number of cmap tables*/
uint16_t cmap_num :10;
/*Bit per pixel: 1, 2, 4 or 8*/
uint16_t bpp :3;
/*Type of `kern_dsc`*/
uint16_t kern_classes :1;
/*
* storage format of the bitmap
* from `lv_font_fmt_txt_bitmap_format_t`
*/
uint16_t bitmap_format :2;
}lv_font_fmt_txt_dsc_t;
/**********************
* GLOBAL PROTOTYPES
**********************/
/**
* Used as `get_glyph_bitmap` callback in LittelvGL's native font format if the font is uncompressed.
* @param font pointer to font
* @param unicode_letter an unicode letter which bitmap should be get
* @return pointer to the bitmap or NULL if not found
*/
const uint8_t * lv_font_get_bitmap_fmt_txt(const lv_font_t * font, uint32_t letter);
/**
* Used as `get_glyph_dsc` callback in LittelvGL's native font format if the font is uncompressed.
* @param font_p pointer to font
* @param dsc_out store the result descriptor here
* @param letter an UNICODE letter code
* @return true: descriptor is successfully loaded into `dsc_out`.
* false: the letter was not found, no data is loaded to `dsc_out`
*/
bool lv_font_get_glyph_dsc_fmt_txt(const lv_font_t * font, lv_font_glyph_dsc_t * dsc_out, uint32_t unicode_letter);
/**********************
* MACROS
**********************/
/**********************
* ADD BUILT IN FONTS
**********************/
#ifdef __cplusplus
} /* extern "C" */
#endif
#endif /*LV_FONT_FMT_TXT_H*/

View File

@ -119,7 +119,7 @@ void lv_txt_get_size(lv_point_t * size_res, const char * text, const lv_font_t *
uint32_t line_start = 0; uint32_t line_start = 0;
uint32_t new_line_start = 0; uint32_t new_line_start = 0;
lv_coord_t act_line_length; lv_coord_t act_line_length;
uint8_t letter_height = lv_font_get_height(font); uint8_t letter_height = lv_font_get_line_height(font);
/*Calc. the height and longest line*/ /*Calc. the height and longest line*/
while(text[line_start] != '\0') { while(text[line_start] != '\0') {
@ -173,11 +173,13 @@ uint16_t lv_txt_get_next_line(const char * txt, const lv_font_t * font, lv_coord
uint32_t n_char_since_last_break = 0; /* Used count word length of long words */ uint32_t n_char_since_last_break = 0; /* Used count word length of long words */
uint32_t last_break = NO_BREAK_FOUND; uint32_t last_break = NO_BREAK_FOUND;
lv_txt_cmd_state_t cmd_state = LV_TXT_CMD_STATE_WAIT; lv_txt_cmd_state_t cmd_state = LV_TXT_CMD_STATE_WAIT;
uint32_t letter = 0; uint32_t letter;
uint32_t letter_next;
while(txt[i] != '\0') { while(txt[i] != '\0') {
lv_coord_t letter_width; lv_coord_t letter_width;
letter = lv_txt_encoded_next(txt, &i); letter = lv_txt_encoded_next(txt, &i);
letter_next = lv_txt_encoded_next(&txt[i], NULL);
/*Handle the recolor command*/ /*Handle the recolor command*/
if((flag & LV_TXT_FLAG_RECOLOR) != 0) { if((flag & LV_TXT_FLAG_RECOLOR) != 0) {
@ -196,7 +198,7 @@ uint16_t lv_txt_get_next_line(const char * txt, const lv_font_t * font, lv_coord
} else { /*Check the actual length*/ } else { /*Check the actual length*/
n_char_since_last_break++; n_char_since_last_break++;
letter_width = lv_font_get_width(font, letter); letter_width = lv_font_get_glyph_width(font, letter, letter_next);
cur_w += letter_width; cur_w += letter_width;
/* Get the length of the current work and determine best place /* Get the length of the current work and determine best place
@ -210,12 +212,12 @@ uint16_t lv_txt_get_next_line(const char * txt, const lv_font_t * font, lv_coord
i = last_break; i = last_break;
} else { } else {
uint32_t i_tmp = i; uint32_t i_tmp = i;
cur_w -= /*ignore the first letter_space after the break char */
w_at_last_break + cur_w -= w_at_last_break + letter_space;
letter_space; /*ignore the first letter_space after the break char */
bool other = true; bool other = true;
while(txt[i_tmp] != '\0') { while(txt[i_tmp] != '\0') {
letter = lv_txt_encoded_next(txt, &i_tmp); letter = lv_txt_encoded_next(txt, &i_tmp);
letter_next = lv_txt_encoded_next(&txt[i_tmp], NULL);
/*Handle the recolor command*/ /*Handle the recolor command*/
if((flag & LV_TXT_FLAG_RECOLOR) != 0) { if((flag & LV_TXT_FLAG_RECOLOR) != 0) {
@ -242,7 +244,7 @@ uint16_t lv_txt_get_next_line(const char * txt, const lv_font_t * font, lv_coord
break; break;
} }
n_char_since_last_break++; n_char_since_last_break++;
lv_coord_t letter_width2 = lv_font_get_width(font, letter); lv_coord_t letter_width2 = lv_font_get_glyph_width(font, letter, letter_next);
cur_w += letter_width2; cur_w += letter_width2;
if(cur_w > max_width) { if(cur_w > max_width) {
/* Current letter already exceeds, return previous */ /* Current letter already exceeds, return previous */
@ -323,17 +325,19 @@ lv_coord_t lv_txt_get_width(const char * txt, uint16_t length, const lv_font_t *
lv_coord_t width = 0; lv_coord_t width = 0;
lv_txt_cmd_state_t cmd_state = LV_TXT_CMD_STATE_WAIT; lv_txt_cmd_state_t cmd_state = LV_TXT_CMD_STATE_WAIT;
uint32_t letter; uint32_t letter;
uint32_t letter_next;
if(length != 0) { if(length != 0) {
while(i < length) { while(i < length) {
letter = lv_txt_encoded_next(txt, &i); letter = lv_txt_encoded_next(txt, &i);
letter_next = lv_txt_encoded_next(&txt[i], NULL);
if((flag & LV_TXT_FLAG_RECOLOR) != 0) { if((flag & LV_TXT_FLAG_RECOLOR) != 0) {
if(lv_txt_is_cmd(&cmd_state, letter) != false) { if(lv_txt_is_cmd(&cmd_state, letter) != false) {
continue; continue;
} }
} }
lv_coord_t char_width = lv_font_get_width(font, letter); lv_coord_t char_width = lv_font_get_glyph_width(font, letter, letter_next);
if(char_width > 0) { if(char_width > 0) {
width += char_width; width += char_width;
width += letter_space; width += letter_space;

View File

@ -626,7 +626,7 @@ static lv_coord_t get_header_height(lv_obj_t * calendar)
{ {
lv_calendar_ext_t * ext = lv_obj_get_ext_attr(calendar); lv_calendar_ext_t * ext = lv_obj_get_ext_attr(calendar);
return lv_font_get_height(ext->style_header->text.font) + ext->style_header->body.padding.top + return lv_font_get_line_height(ext->style_header->text.font) + ext->style_header->body.padding.top +
ext->style_header->body.padding.bottom; ext->style_header->body.padding.bottom;
} }
@ -639,7 +639,7 @@ static lv_coord_t get_day_names_height(lv_obj_t * calendar)
{ {
lv_calendar_ext_t * ext = lv_obj_get_ext_attr(calendar); lv_calendar_ext_t * ext = lv_obj_get_ext_attr(calendar);
return lv_font_get_height(ext->style_day_names->text.font) + return lv_font_get_line_height(ext->style_day_names->text.font) +
ext->style_day_names->body.padding.top + ext->style_day_names->body.padding.bottom; ext->style_day_names->body.padding.top + ext->style_day_names->body.padding.bottom;
} }
@ -704,7 +704,7 @@ static void draw_day_names(lv_obj_t * calendar, const lv_area_t * mask)
lv_area_t label_area; lv_area_t label_area;
label_area.y1 = label_area.y1 =
calendar->coords.y1 + get_header_height(calendar) + ext->style_day_names->body.padding.top; calendar->coords.y1 + get_header_height(calendar) + ext->style_day_names->body.padding.top;
label_area.y2 = label_area.y1 + lv_font_get_height(ext->style_day_names->text.font); label_area.y2 = label_area.y1 + lv_font_get_line_height(ext->style_day_names->text.font);
uint32_t i; uint32_t i;
for(i = 0; i < 7; i++) { for(i = 0; i < 7; i++) {
label_area.x1 = calendar->coords.x1 + (w * i) / 7 + l_pad; label_area.x1 = calendar->coords.x1 + (w * i) / 7 + l_pad;
@ -727,15 +727,15 @@ static void draw_days(lv_obj_t * calendar, const lv_area_t * mask)
lv_opa_t opa_scale = lv_obj_get_opa_scale(calendar); lv_opa_t opa_scale = lv_obj_get_opa_scale(calendar);
label_area.y1 = calendar->coords.y1 + get_header_height(calendar) + label_area.y1 = calendar->coords.y1 + get_header_height(calendar) +
ext->style_day_names->body.padding.top + ext->style_day_names->body.padding.top +
lv_font_get_height(ext->style_day_names->text.font) + lv_font_get_line_height(ext->style_day_names->text.font) +
ext->style_day_names->body.padding.bottom; ext->style_day_names->body.padding.bottom;
label_area.y2 = label_area.y1 + lv_font_get_height(style_bg->text.font); label_area.y2 = label_area.y1 + lv_font_get_line_height(style_bg->text.font);
lv_coord_t w = lv_coord_t w =
lv_obj_get_width(calendar) - style_bg->body.padding.left - style_bg->body.padding.right; lv_obj_get_width(calendar) - style_bg->body.padding.left - style_bg->body.padding.right;
lv_coord_t h = calendar->coords.y2 - label_area.y1 - style_bg->body.padding.bottom; lv_coord_t h = calendar->coords.y2 - label_area.y1 - style_bg->body.padding.bottom;
lv_coord_t box_w = w / 7; lv_coord_t box_w = w / 7;
lv_coord_t vert_space = (h - (6 * lv_font_get_height(style_bg->text.font))) / 5; lv_coord_t vert_space = (h - (6 * lv_font_get_line_height(style_bg->text.font))) / 5;
uint32_t week; uint32_t week;
uint8_t day_cnt; uint8_t day_cnt;
@ -856,8 +856,8 @@ static void draw_days(lv_obj_t * calendar, const lv_area_t * mask)
} }
/*Got to the next weeks row*/ /*Got to the next weeks row*/
label_area.y1 += vert_space + lv_font_get_height(style_bg->text.font); label_area.y1 += vert_space + lv_font_get_line_height(style_bg->text.font);
label_area.y2 += vert_space + lv_font_get_height(style_bg->text.font); label_area.y2 += vert_space + lv_font_get_line_height(style_bg->text.font);
} }
} }

View File

@ -314,8 +314,8 @@ static lv_res_t lv_cb_signal(lv_obj_t * cb, lv_signal_t sign, void * param)
if(sign == LV_SIGNAL_STYLE_CHG) { if(sign == LV_SIGNAL_STYLE_CHG) {
const lv_style_t * label_style = lv_label_get_style(ext->label); const lv_style_t * label_style = lv_label_get_style(ext->label);
lv_obj_set_size(ext->bullet, lv_font_get_height(label_style->text.font), lv_obj_set_size(ext->bullet, lv_font_get_line_height(label_style->text.font),
lv_font_get_height(label_style->text.font)); lv_font_get_line_height(label_style->text.font));
lv_btn_set_state(ext->bullet, lv_btn_get_state(cb)); lv_btn_set_state(ext->bullet, lv_btn_get_state(cb));
} else if(sign == LV_SIGNAL_PRESSED || sign == LV_SIGNAL_RELEASED || } else if(sign == LV_SIGNAL_PRESSED || sign == LV_SIGNAL_RELEASED ||
sign == LV_SIGNAL_PRESS_LOST) { sign == LV_SIGNAL_PRESS_LOST) {

View File

@ -547,7 +547,7 @@ static bool lv_ddlist_design(lv_obj_t * ddlist, const lv_area_t * mask, lv_desig
if(ext->opened != 0 || ext->force_sel) { if(ext->opened != 0 || ext->force_sel) {
const lv_style_t * style = lv_ddlist_get_style(ddlist, LV_DDLIST_STYLE_BG); const lv_style_t * style = lv_ddlist_get_style(ddlist, LV_DDLIST_STYLE_BG);
const lv_font_t * font = style->text.font; const lv_font_t * font = style->text.font;
lv_coord_t font_h = lv_font_get_height(font); lv_coord_t font_h = lv_font_get_line_height(font);
/*Draw the selected*/ /*Draw the selected*/
lv_area_t rect_area; lv_area_t rect_area;
@ -572,7 +572,7 @@ static bool lv_ddlist_design(lv_obj_t * ddlist, const lv_area_t * mask, lv_desig
if(ext->opened || ext->force_sel) { if(ext->opened || ext->force_sel) {
const lv_style_t * style = lv_ddlist_get_style(ddlist, LV_DDLIST_STYLE_BG); const lv_style_t * style = lv_ddlist_get_style(ddlist, LV_DDLIST_STYLE_BG);
const lv_font_t * font = style->text.font; const lv_font_t * font = style->text.font;
lv_coord_t font_h = lv_font_get_height(font); lv_coord_t font_h = lv_font_get_line_height(font);
lv_area_t area_sel; lv_area_t area_sel;
area_sel.y1 = ext->label->coords.y1; area_sel.y1 = ext->label->coords.y1;
@ -604,7 +604,7 @@ static bool lv_ddlist_design(lv_obj_t * ddlist, const lv_area_t * mask, lv_desig
const lv_style_t * style = lv_ddlist_get_style(ddlist, LV_DDLIST_STYLE_BG); const lv_style_t * style = lv_ddlist_get_style(ddlist, LV_DDLIST_STYLE_BG);
const lv_font_t * font = style->text.font; const lv_font_t * font = style->text.font;
const lv_style_t * sel_style = lv_ddlist_get_style(ddlist, LV_DDLIST_STYLE_BG); const lv_style_t * sel_style = lv_ddlist_get_style(ddlist, LV_DDLIST_STYLE_BG);
lv_coord_t font_h = lv_font_get_height(font); lv_coord_t font_h = lv_font_get_line_height(font);
lv_style_t new_style; lv_style_t new_style;
lv_style_copy(&new_style, style); lv_style_copy(&new_style, style);
new_style.text.color = sel_style->text.color; new_style.text.color = sel_style->text.color;
@ -869,7 +869,7 @@ static void lv_ddlist_refr_size(lv_obj_t * ddlist, bool anim_en)
else { else {
const lv_font_t * font = style->text.font; const lv_font_t * font = style->text.font;
const lv_style_t * label_style = lv_obj_get_style(ext->label); const lv_style_t * label_style = lv_obj_get_style(ext->label);
lv_coord_t font_h = lv_font_get_height(font); lv_coord_t font_h = lv_font_get_line_height(font);
new_height = font_h + 2 * label_style->text.line_space; new_height = font_h + 2 * label_style->text.line_space;
lv_page_set_sb_mode(ddlist, LV_SB_MODE_HIDE); lv_page_set_sb_mode(ddlist, LV_SB_MODE_HIDE);
@ -956,7 +956,7 @@ static void lv_ddlist_pos_current_option(lv_obj_t * ddlist)
lv_ddlist_ext_t * ext = lv_obj_get_ext_attr(ddlist); lv_ddlist_ext_t * ext = lv_obj_get_ext_attr(ddlist);
const lv_style_t * style = lv_obj_get_style(ddlist); const lv_style_t * style = lv_obj_get_style(ddlist);
const lv_font_t * font = style->text.font; const lv_font_t * font = style->text.font;
lv_coord_t font_h = lv_font_get_height(font); lv_coord_t font_h = lv_font_get_line_height(font);
const lv_style_t * label_style = lv_obj_get_style(ext->label); const lv_style_t * label_style = lv_obj_get_style(ext->label);
lv_obj_t * scrl = lv_page_get_scrl(ddlist); lv_obj_t * scrl = lv_page_get_scrl(ddlist);

View File

@ -465,7 +465,7 @@ void lv_label_get_letter_pos(const lv_obj_t * label, uint16_t index, lv_point_t
lv_coord_t max_w = lv_obj_get_width(label); lv_coord_t max_w = lv_obj_get_width(label);
const lv_style_t * style = lv_obj_get_style(label); const lv_style_t * style = lv_obj_get_style(label);
const lv_font_t * font = style->text.font; const lv_font_t * font = style->text.font;
uint8_t letter_height = lv_font_get_height(font); uint8_t letter_height = lv_font_get_line_height(font);
lv_coord_t y = 0; lv_coord_t y = 0;
lv_txt_flag_t flag = LV_TXT_FLAG_NONE; lv_txt_flag_t flag = LV_TXT_FLAG_NONE;
@ -538,7 +538,7 @@ uint16_t lv_label_get_letter_on(const lv_obj_t * label, lv_point_t * pos)
lv_coord_t max_w = lv_obj_get_width(label); lv_coord_t max_w = lv_obj_get_width(label);
const lv_style_t * style = lv_obj_get_style(label); const lv_style_t * style = lv_obj_get_style(label);
const lv_font_t * font = style->text.font; const lv_font_t * font = style->text.font;
uint8_t letter_height = lv_font_get_height(font); uint8_t letter_height = lv_font_get_line_height(font);
lv_coord_t y = 0; lv_coord_t y = 0;
lv_txt_flag_t flag = LV_TXT_FLAG_NONE; lv_txt_flag_t flag = LV_TXT_FLAG_NONE;
@ -572,12 +572,20 @@ uint16_t lv_label_get_letter_on(const lv_obj_t * label, lv_point_t * pos)
} }
lv_txt_cmd_state_t cmd_state = LV_TXT_CMD_STATE_WAIT; lv_txt_cmd_state_t cmd_state = LV_TXT_CMD_STATE_WAIT;
uint32_t i = line_start; uint32_t i = line_start;
uint32_t i_current = i; uint32_t i_current = i;
uint32_t letter; uint32_t letter;
uint32_t letter_next;
while(i <= new_line_start - 1) { while(i <= new_line_start - 1) {
letter = /* Get the current letter.
lv_txt_encoded_next(txt, &i); /*Be careful 'i' already points to the next character*/ * Be careful 'i' already points to the next character*/
letter = lv_txt_encoded_next(txt, &i);
/*Get the next letter too for kerning*/
letter_next = lv_txt_encoded_next(&txt[i], NULL);
/*Handle the recolor command*/ /*Handle the recolor command*/
if((flag & LV_TXT_FLAG_RECOLOR) != 0) { if((flag & LV_TXT_FLAG_RECOLOR) != 0) {
if(lv_txt_is_cmd(&cmd_state, txt[i]) != false) { if(lv_txt_is_cmd(&cmd_state, txt[i]) != false) {
@ -585,7 +593,7 @@ uint16_t lv_label_get_letter_on(const lv_obj_t * label, lv_point_t * pos)
} }
} }
x += lv_font_get_width(font, letter); x += lv_font_get_glyph_width(font, letter, letter_next);
if(pos->x < x) { if(pos->x < x) {
i = i_current; i = i_current;
break; break;
@ -643,7 +651,7 @@ bool lv_label_is_char_under_pos(const lv_obj_t * label, lv_point_t * pos)
lv_coord_t max_w = lv_obj_get_width(label); lv_coord_t max_w = lv_obj_get_width(label);
const lv_style_t * style = lv_obj_get_style(label); const lv_style_t * style = lv_obj_get_style(label);
const lv_font_t * font = style->text.font; const lv_font_t * font = style->text.font;
uint8_t letter_height = lv_font_get_height(font); uint8_t letter_height = lv_font_get_line_height(font);
lv_coord_t y = 0; lv_coord_t y = 0;
lv_txt_flag_t flag = LV_TXT_FLAG_NONE; lv_txt_flag_t flag = LV_TXT_FLAG_NONE;
@ -678,12 +686,20 @@ bool lv_label_is_char_under_pos(const lv_obj_t * label, lv_point_t * pos)
} }
lv_txt_cmd_state_t cmd_state = LV_TXT_CMD_STATE_WAIT; lv_txt_cmd_state_t cmd_state = LV_TXT_CMD_STATE_WAIT;
uint32_t i = line_start; uint32_t i = line_start;
uint32_t i_current = i; uint32_t i_current = i;
uint32_t letter = 0; uint32_t letter;
uint32_t letter_next;
while(i <= new_line_start - 1) { while(i <= new_line_start - 1) {
letter = /* Get the current letter
lv_txt_encoded_next(txt, &i); /*Be careful 'i' already points to the next character*/ * Be careful 'i' already points to the next character */
letter = lv_txt_encoded_next(txt, &i);
/*Get the next letter for kerning*/
letter_next = lv_txt_encoded_next(&txt[i], NULL);
/*Handle the recolor command*/ /*Handle the recolor command*/
if((flag & LV_TXT_FLAG_RECOLOR) != 0) { if((flag & LV_TXT_FLAG_RECOLOR) != 0) {
if(lv_txt_is_cmd(&cmd_state, txt[i]) != false) { if(lv_txt_is_cmd(&cmd_state, txt[i]) != false) {
@ -691,7 +707,7 @@ bool lv_label_is_char_under_pos(const lv_obj_t * label, lv_point_t * pos)
} }
} }
last_x = x; last_x = x;
x += lv_font_get_width(font, letter); x += lv_font_get_glyph_width(font, letter, letter_next);
if(pos->x < x) { if(pos->x < x) {
i = i_current; i = i_current;
break; break;
@ -700,7 +716,7 @@ bool lv_label_is_char_under_pos(const lv_obj_t * label, lv_point_t * pos)
i_current = i; i_current = i;
} }
int max_diff = lv_font_get_width(font, letter) + style->text.letter_space + 1; int32_t max_diff = lv_font_get_glyph_width(font, letter, letter_next) + style->text.letter_space + 1;
return (pos->x >= (last_x - style->text.letter_space) && pos->x <= (last_x + max_diff)); return (pos->x >= (last_x - style->text.letter_space) && pos->x <= (last_x + max_diff));
} }
@ -841,10 +857,11 @@ static bool lv_label_design(lv_obj_t * label, const lv_area_t * mask, lv_design_
style->text.line_space, LV_COORD_MAX, flag); style->text.line_space, LV_COORD_MAX, flag);
lv_point_t ofs; lv_point_t ofs;
/*Draw the text again next to the original to make an circular effect */ /*Draw the text again next to the original to make an circular effect */
if(size.x > lv_obj_get_width(label)) { if(size.x > lv_obj_get_width(label)) {
ofs.x = ext->offset.x + size.x + ofs.x = ext->offset.x + size.x +
lv_font_get_width(style->text.font, ' ') * LV_LABEL_WAIT_CHAR_COUNT; lv_font_get_glyph_width(style->text.font, ' ', ' ') * LV_LABEL_WAIT_CHAR_COUNT;
ofs.y = ext->offset.y; ofs.y = ext->offset.y;
lv_draw_label(&coords, mask, style, opa_scale, ext->text, flag, &ofs, lv_draw_label(&coords, mask, style, opa_scale, ext->text, flag, &ofs,
@ -854,7 +871,7 @@ static bool lv_label_design(lv_obj_t * label, const lv_area_t * mask, lv_design_
/*Draw the text again below the original to make an circular effect */ /*Draw the text again below the original to make an circular effect */
if(size.y > lv_obj_get_height(label)) { if(size.y > lv_obj_get_height(label)) {
ofs.x = ext->offset.x; ofs.x = ext->offset.x;
ofs.y = ext->offset.y + size.y + lv_font_get_height(style->text.font); ofs.y = ext->offset.y + size.y + lv_font_get_line_height(style->text.font);
lv_draw_label(&coords, mask, style, opa_scale, ext->text, flag, &ofs, lv_draw_label(&coords, mask, style, opa_scale, ext->text, flag, &ofs,
lv_label_get_text_sel_start(label), lv_label_get_text_sel_end(label)); lv_label_get_text_sel_start(label), lv_label_get_text_sel_end(label));
} }
@ -958,8 +975,7 @@ static void lv_label_refr_text(lv_obj_t * label)
anim.start = 0; anim.start = 0;
anim.ready_cb = NULL; anim.ready_cb = NULL;
anim.path_cb = lv_anim_path_linear; anim.path_cb = lv_anim_path_linear;
anim.playback_pause = anim.playback_pause = (((lv_font_get_glyph_width(style->text.font, ' ', ' ') + style->text.letter_space) * 1000) /
(((lv_font_get_width(style->text.font, ' ') + style->text.letter_space) * 1000) /
ext->anim_speed) * LV_LABEL_WAIT_CHAR_COUNT; ext->anim_speed) * LV_LABEL_WAIT_CHAR_COUNT;
anim.repeat_pause = anim.playback_pause; anim.repeat_pause = anim.playback_pause;
anim.act_time = -anim.playback_pause; anim.act_time = -anim.playback_pause;
@ -978,8 +994,9 @@ static void lv_label_refr_text(lv_obj_t * label)
} }
if(size.y > lv_obj_get_height(label) && hor_anim == false) { if(size.y > lv_obj_get_height(label) && hor_anim == false) {
anim.end = lv_obj_get_height(label) - size.y - (lv_font_get_height(font)); anim.end = lv_obj_get_height(label) - size.y - (lv_font_get_line_height(font));
anim.exec_cb = (lv_anim_exec_cb_t)lv_label_set_offset_y; anim.exec_cb = (lv_anim_exec_cb_t)lv_label_set_offset_y;
anim.time = lv_anim_speed_to_time(ext->anim_speed, anim.start, anim.end); anim.time = lv_anim_speed_to_time(ext->anim_speed, anim.start, anim.end);
lv_anim_create(&anim); lv_anim_create(&anim);
} else { } else {
@ -997,8 +1014,7 @@ static void lv_label_refr_text(lv_obj_t * label)
anim.repeat = 1; anim.repeat = 1;
anim.playback = 0; anim.playback = 0;
anim.start = 0; anim.start = 0;
anim.act_time = anim.act_time = -(((lv_font_get_glyph_width(style->text.font, ' ', ' ') + style->text.letter_space) * 1000) /
-(((lv_font_get_width(style->text.font, ' ') + style->text.letter_space) * 1000) /
ext->anim_speed) * LV_LABEL_WAIT_CHAR_COUNT; ext->anim_speed) * LV_LABEL_WAIT_CHAR_COUNT;
anim.ready_cb = NULL; anim.ready_cb = NULL;
anim.path_cb = lv_anim_path_linear; anim.path_cb = lv_anim_path_linear;
@ -1007,7 +1023,7 @@ static void lv_label_refr_text(lv_obj_t * label)
bool hor_anim = false; bool hor_anim = false;
if(size.x > lv_obj_get_width(label)) { if(size.x > lv_obj_get_width(label)) {
anim.end = -size.x - lv_font_get_width(font, ' ') * LV_LABEL_WAIT_CHAR_COUNT; anim.end = -size.x - lv_font_get_glyph_width(font, ' ', ' ') * LV_LABEL_WAIT_CHAR_COUNT;
anim.exec_cb = (lv_anim_exec_cb_t)lv_label_set_offset_x; anim.exec_cb = (lv_anim_exec_cb_t)lv_label_set_offset_x;
anim.time = lv_anim_speed_to_time(ext->anim_speed, anim.start, anim.end); anim.time = lv_anim_speed_to_time(ext->anim_speed, anim.start, anim.end);
lv_anim_create(&anim); lv_anim_create(&anim);
@ -1019,7 +1035,7 @@ static void lv_label_refr_text(lv_obj_t * label)
} }
if(size.y > lv_obj_get_height(label) && hor_anim == false) { if(size.y > lv_obj_get_height(label) && hor_anim == false) {
anim.end = -size.y - (lv_font_get_height(font)); anim.end = -size.y - (lv_font_get_line_height(font));
anim.exec_cb = (lv_anim_exec_cb_t)lv_label_set_offset_y; anim.exec_cb = (lv_anim_exec_cb_t)lv_label_set_offset_y;
anim.time = lv_anim_speed_to_time(ext->anim_speed, anim.start, anim.end); anim.time = lv_anim_speed_to_time(ext->anim_speed, anim.start, anim.end);
lv_anim_create(&anim); lv_anim_create(&anim);
@ -1038,10 +1054,10 @@ static void lv_label_refr_text(lv_obj_t * label)
} else { } else {
lv_point_t p; lv_point_t p;
p.x = lv_obj_get_width(label) - p.x = lv_obj_get_width(label) -
(lv_font_get_width(style->text.font, '.') + style->text.letter_space) * (lv_font_get_glyph_width(style->text.font, '.', '.') + style->text.letter_space) *
LV_LABEL_DOT_NUM; /*Shrink with dots*/ LV_LABEL_DOT_NUM; /*Shrink with dots*/
p.y = lv_obj_get_height(label); p.y = lv_obj_get_height(label);
p.y -= p.y % (lv_font_get_height(style->text.font) + p.y -= p.y % (lv_font_get_line_height(style->text.font) +
style->text.line_space); /*Round down to the last line*/ style->text.line_space); /*Round down to the last line*/
p.y -= style->text.line_space; /*Trim the last line space*/ p.y -= style->text.line_space; /*Trim the last line space*/
uint32_t letter_id = lv_label_get_letter_on(label, &p); uint32_t letter_id = lv_label_get_letter_on(label, &p);

View File

@ -522,7 +522,7 @@ static void mbox_realign(lv_obj_t * mbox)
if(ext->btnm) { if(ext->btnm) {
const lv_style_t * btn_bg_style = lv_mbox_get_style(mbox, LV_MBOX_STYLE_BTN_BG); const lv_style_t * btn_bg_style = lv_mbox_get_style(mbox, LV_MBOX_STYLE_BTN_BG);
const lv_style_t * btn_rel_style = lv_mbox_get_style(mbox, LV_MBOX_STYLE_BTN_REL); const lv_style_t * btn_rel_style = lv_mbox_get_style(mbox, LV_MBOX_STYLE_BTN_REL);
lv_coord_t font_h = lv_font_get_height(btn_rel_style->text.font); lv_coord_t font_h = lv_font_get_line_height(btn_rel_style->text.font);
lv_obj_set_size(ext->btnm, w, lv_obj_set_size(ext->btnm, w,
font_h + btn_rel_style->body.padding.top + font_h + btn_rel_style->body.padding.top +
btn_rel_style->body.padding.bottom + btn_bg_style->body.padding.top + btn_rel_style->body.padding.bottom + btn_bg_style->body.padding.top +

View File

@ -214,7 +214,7 @@ void lv_roller_set_visible_row_count(lv_obj_t * roller, uint8_t row_cnt)
lv_roller_ext_t * ext = lv_obj_get_ext_attr(roller); lv_roller_ext_t * ext = lv_obj_get_ext_attr(roller);
const lv_style_t * style_label = lv_obj_get_style(ext->ddlist.label); const lv_style_t * style_label = lv_obj_get_style(ext->ddlist.label);
uint8_t n_line_space = (row_cnt > 1) ? row_cnt - 1 : 1; uint8_t n_line_space = (row_cnt > 1) ? row_cnt - 1 : 1;
lv_ddlist_set_fix_height(roller, lv_font_get_height(style_label->text.font) * row_cnt + lv_ddlist_set_fix_height(roller, lv_font_get_line_height(style_label->text.font) * row_cnt +
style_label->text.line_space * n_line_space); style_label->text.line_space * n_line_space);
} }
@ -321,7 +321,7 @@ static bool lv_roller_design(lv_obj_t * roller, const lv_area_t * mask, lv_desig
lv_opa_t opa_scale = lv_obj_get_opa_scale(roller); lv_opa_t opa_scale = lv_obj_get_opa_scale(roller);
const lv_font_t * font = style->text.font; const lv_font_t * font = style->text.font;
lv_roller_ext_t * ext = lv_obj_get_ext_attr(roller); lv_roller_ext_t * ext = lv_obj_get_ext_attr(roller);
lv_coord_t font_h = lv_font_get_height(font); lv_coord_t font_h = lv_font_get_line_height(font);
lv_area_t rect_area; lv_area_t rect_area;
rect_area.y1 = roller->coords.y1 + lv_obj_get_height(roller) / 2 - font_h / 2 - rect_area.y1 = roller->coords.y1 + lv_obj_get_height(roller) / 2 - font_h / 2 -
style->text.line_space / 2; style->text.line_space / 2;
@ -338,7 +338,7 @@ static bool lv_roller_design(lv_obj_t * roller, const lv_area_t * mask, lv_desig
const lv_style_t * style = lv_roller_get_style(roller, LV_ROLLER_STYLE_BG); const lv_style_t * style = lv_roller_get_style(roller, LV_ROLLER_STYLE_BG);
lv_roller_ext_t * ext = lv_obj_get_ext_attr(roller); lv_roller_ext_t * ext = lv_obj_get_ext_attr(roller);
const lv_font_t * font = style->text.font; const lv_font_t * font = style->text.font;
lv_coord_t font_h = lv_font_get_height(font); lv_coord_t font_h = lv_font_get_line_height(font);
lv_opa_t opa_scale = lv_obj_get_opa_scale(roller); lv_opa_t opa_scale = lv_obj_get_opa_scale(roller);
/*Redraw the text on the selected area with a different color*/ /*Redraw the text on the selected area with a different color*/
@ -503,7 +503,7 @@ static lv_res_t lv_roller_scrl_signal(lv_obj_t * roller_scrl, lv_signal_t sign,
const lv_style_t * style_label = lv_obj_get_style(ext->ddlist.label); const lv_style_t * style_label = lv_obj_get_style(ext->ddlist.label);
const lv_font_t * font = style_label->text.font; const lv_font_t * font = style_label->text.font;
lv_coord_t font_h = lv_font_get_height(font); lv_coord_t font_h = lv_font_get_line_height(font);
if(sign == LV_SIGNAL_DRAG_END) { if(sign == LV_SIGNAL_DRAG_END) {
/*If dragged then align the list to there be an element in the middle*/ /*If dragged then align the list to there be an element in the middle*/
@ -615,7 +615,7 @@ static void refr_position(lv_obj_t * roller, bool anim_en)
lv_roller_ext_t * ext = lv_obj_get_ext_attr(roller); lv_roller_ext_t * ext = lv_obj_get_ext_attr(roller);
const lv_style_t * style_label = lv_obj_get_style(ext->ddlist.label); const lv_style_t * style_label = lv_obj_get_style(ext->ddlist.label);
const lv_font_t * font = style_label->text.font; const lv_font_t * font = style_label->text.font;
lv_coord_t font_h = lv_font_get_height(font); lv_coord_t font_h = lv_font_get_line_height(font);
lv_coord_t h = lv_obj_get_height(roller); lv_coord_t h = lv_obj_get_height(roller);
/* Normally the animtaion's `end_cb` sets correct position of the roller is infinite. /* Normally the animtaion's `end_cb` sets correct position of the roller is infinite.
@ -705,7 +705,7 @@ static void inf_normalize(void * scrl)
/*Move to the new id*/ /*Move to the new id*/
const lv_style_t * style_label = lv_obj_get_style(ext->ddlist.label); const lv_style_t * style_label = lv_obj_get_style(ext->ddlist.label);
const lv_font_t * font = style_label->text.font; const lv_font_t * font = style_label->text.font;
lv_coord_t font_h = lv_font_get_height(font); lv_coord_t font_h = lv_font_get_line_height(font);
lv_coord_t h = lv_obj_get_height(roller); lv_coord_t h = lv_obj_get_height(roller);
lv_coord_t line_y1 = ext->ddlist.sel_opt_id * (font_h + style_label->text.line_space) + lv_coord_t line_y1 = ext->ddlist.sel_opt_id * (font_h + style_label->text.line_space) +

View File

@ -467,7 +467,7 @@ void lv_ta_set_text(lv_obj_t * ta, const char * txt)
/*Don't let 'width == 0' because the cursor will not be visible*/ /*Don't let 'width == 0' because the cursor will not be visible*/
if(lv_obj_get_width(ext->label) == 0) { if(lv_obj_get_width(ext->label) == 0) {
const lv_style_t * style = lv_obj_get_style(ext->label); const lv_style_t * style = lv_obj_get_style(ext->label);
lv_obj_set_width(ext->label, lv_font_get_width(style->text.font, ' ')); lv_obj_set_width(ext->label, lv_font_get_glyph_width(style->text.font, ' ', '\0'));
} }
if(ext->pwd_mode != 0) { if(ext->pwd_mode != 0) {
@ -559,7 +559,7 @@ void lv_ta_set_cursor_pos(lv_obj_t * ta, int16_t pos)
lv_obj_get_coords(ext->label, &label_cords); lv_obj_get_coords(ext->label, &label_cords);
/*Check the top*/ /*Check the top*/
lv_coord_t font_h = lv_font_get_height(font_p); lv_coord_t font_h = lv_font_get_line_height(font_p);
if(lv_obj_get_y(label_par) + cur_pos.y < 0) { if(lv_obj_get_y(label_par) + cur_pos.y < 0) {
lv_obj_set_y(label_par, -cur_pos.y + style->body.padding.top); lv_obj_set_y(label_par, -cur_pos.y + style->body.padding.top);
} }
@ -677,7 +677,7 @@ void lv_ta_set_one_line(lv_obj_t * ta, bool en)
const lv_style_t * style_ta = lv_obj_get_style(ta); const lv_style_t * style_ta = lv_obj_get_style(ta);
const lv_style_t * style_scrl = lv_obj_get_style(lv_page_get_scrl(ta)); const lv_style_t * style_scrl = lv_obj_get_style(lv_page_get_scrl(ta));
const lv_style_t * style_label = lv_obj_get_style(ext->label); const lv_style_t * style_label = lv_obj_get_style(ext->label);
lv_coord_t font_h = lv_font_get_height(style_label->text.font); lv_coord_t font_h = lv_font_get_line_height(style_label->text.font);
ext->one_line = 1; ext->one_line = 1;
lv_page_set_scrl_fit2(ta, LV_FIT_TIGHT, LV_FIT_FLOOD); lv_page_set_scrl_fit2(ta, LV_FIT_TIGHT, LV_FIT_FLOOD);
@ -1140,7 +1140,7 @@ void lv_ta_cursor_down(lv_obj_t * ta)
/*Increment the y with one line and keep the valid x*/ /*Increment the y with one line and keep the valid x*/
const lv_style_t * label_style = lv_obj_get_style(ext->label); const lv_style_t * label_style = lv_obj_get_style(ext->label);
const lv_font_t * font_p = label_style->text.font; const lv_font_t * font_p = label_style->text.font;
lv_coord_t font_h = lv_font_get_height(font_p); lv_coord_t font_h = lv_font_get_line_height(font_p);
pos.y += font_h + label_style->text.line_space + 1; pos.y += font_h + label_style->text.line_space + 1;
pos.x = ext->cursor.valid_x; pos.x = ext->cursor.valid_x;
@ -1171,7 +1171,7 @@ void lv_ta_cursor_up(lv_obj_t * ta)
/*Decrement the y with one line and keep the valid x*/ /*Decrement the y with one line and keep the valid x*/
const lv_style_t * label_style = lv_obj_get_style(ext->label); const lv_style_t * label_style = lv_obj_get_style(ext->label);
const lv_font_t * font = label_style->text.font; const lv_font_t * font = label_style->text.font;
lv_coord_t font_h = lv_font_get_height(font); lv_coord_t font_h = lv_font_get_line_height(font);
pos.y -= font_h + label_style->text.line_space - 1; pos.y -= font_h + label_style->text.line_space - 1;
pos.x = ext->cursor.valid_x; pos.x = ext->cursor.valid_x;
@ -1313,7 +1313,7 @@ static lv_res_t lv_ta_signal(lv_obj_t * ta, lv_signal_t sign, void * param)
if(ext->one_line) { if(ext->one_line) {
/*In one line mode refresh the Text Area height because 'vpad' can modify it*/ /*In one line mode refresh the Text Area height because 'vpad' can modify it*/
const lv_style_t * style_label = lv_obj_get_style(ext->label); const lv_style_t * style_label = lv_obj_get_style(ext->label);
lv_coord_t font_h = lv_font_get_height(style_label->text.font); lv_coord_t font_h = lv_font_get_line_height(style_label->text.font);
lv_obj_set_height( lv_obj_set_height(
ta, font_h + style_ta->body.padding.top + style_ta->body.padding.bottom + ta, font_h + style_ta->body.padding.top + style_ta->body.padding.bottom +
style_scrl->body.padding.top + style_scrl->body.padding.bottom); style_scrl->body.padding.top + style_scrl->body.padding.bottom);
@ -1443,7 +1443,7 @@ static lv_res_t lv_ta_scrollable_signal(lv_obj_t * scrl, lv_signal_t sign, void
if(sign == LV_SIGNAL_REFR_EXT_DRAW_PAD) { if(sign == LV_SIGNAL_REFR_EXT_DRAW_PAD) {
/*Set ext. size because the cursor might be out of this object*/ /*Set ext. size because the cursor might be out of this object*/
const lv_style_t * style_label = lv_obj_get_style(ext->label); const lv_style_t * style_label = lv_obj_get_style(ext->label);
lv_coord_t font_h = lv_font_get_height(style_label->text.font); lv_coord_t font_h = lv_font_get_line_height(style_label->text.font);
scrl->ext_draw_pad = LV_MATH_MAX(scrl->ext_draw_pad, style_label->text.line_space + font_h); scrl->ext_draw_pad = LV_MATH_MAX(scrl->ext_draw_pad, style_label->text.line_space + font_h);
} else if(sign == LV_SIGNAL_CORD_CHG) { } else if(sign == LV_SIGNAL_CORD_CHG) {
/*Set the label width according to the text area width*/ /*Set the label width according to the text area width*/
@ -1620,13 +1620,15 @@ static void refr_cursor_area(lv_obj_t * ta)
uint32_t letter = lv_txt_encoded_next(&txt[byte_pos], NULL); uint32_t letter = lv_txt_encoded_next(&txt[byte_pos], NULL);
lv_coord_t letter_h = lv_font_get_height(label_style->text.font); lv_coord_t letter_h = lv_font_get_line_height(label_style->text.font);
/*Set letter_w (set not 0 on non printable but valid chars)*/ /*Set letter_w (set not 0 on non printable but valid chars)*/
lv_coord_t letter_w; lv_coord_t letter_w;
if(letter == '\0' || letter == '\n' || letter == '\r') { if(letter == '\0' || letter == '\n' || letter == '\r') {
letter_w = lv_font_get_width(label_style->text.font, ' '); letter_w = lv_font_get_glyph_width(label_style->text.font, ' ', '\0');
} else { } else {
letter_w = lv_font_get_width(label_style->text.font, letter); /*`letter_next` parameter is '\0' to ignore kerning*/
letter_w = lv_font_get_glyph_width(label_style->text.font, letter, '\0');
} }
lv_point_t letter_pos; lv_point_t letter_pos;
@ -1644,9 +1646,9 @@ static void refr_cursor_area(lv_obj_t * ta)
} }
if(letter == '\0' || letter == '\n' || letter == '\r') { if(letter == '\0' || letter == '\n' || letter == '\r') {
letter_w = lv_font_get_width(label_style->text.font, ' '); letter_w = lv_font_get_glyph_width(label_style->text.font, ' ', '\0');
} else { } else {
letter_w = lv_font_get_width(label_style->text.font, letter); letter_w = lv_font_get_glyph_width(label_style->text.font, letter, '\0');
} }
} }

View File

@ -804,7 +804,7 @@ static lv_coord_t get_row_height(lv_obj_t * table, uint16_t row_id)
uint16_t row_start = row_id * ext->col_cnt; uint16_t row_start = row_id * ext->col_cnt;
uint16_t cell; uint16_t cell;
uint16_t col; uint16_t col;
lv_coord_t h_max = lv_font_get_height(ext->cell_style[0]->text.font) + lv_coord_t h_max = lv_font_get_line_height(ext->cell_style[0]->text.font) +
ext->cell_style[0]->body.padding.top + ext->cell_style[0]->body.padding.top +
ext->cell_style[0]->body.padding.bottom; ext->cell_style[0]->body.padding.bottom;
@ -834,7 +834,7 @@ static lv_coord_t get_row_height(lv_obj_t * table, uint16_t row_id)
/*With text crop assume 1 line*/ /*With text crop assume 1 line*/
if(format.s.crop) { if(format.s.crop) {
h_max = h_max =
LV_MATH_MAX(lv_font_get_height(cell_style->text.font) + LV_MATH_MAX(lv_font_get_line_height(cell_style->text.font) +
cell_style->body.padding.top + cell_style->body.padding.bottom, cell_style->body.padding.top + cell_style->body.padding.bottom,
h_max); h_max);
} }

View File

@ -1042,7 +1042,7 @@ static void tabview_realign(lv_obj_t * tabview)
switch(ext->btns_pos) { switch(ext->btns_pos) {
case LV_TABVIEW_BTNS_POS_TOP: case LV_TABVIEW_BTNS_POS_TOP:
case LV_TABVIEW_BTNS_POS_BOTTOM: case LV_TABVIEW_BTNS_POS_BOTTOM:
btns_size = lv_font_get_height(style_btn_rel->text.font) + btns_size = lv_font_get_line_height(style_btn_rel->text.font) +
style_btn_rel->body.padding.top + style_btn_rel->body.padding.top +
style_btn_rel->body.padding.bottom + style_btn_rel->body.padding.bottom +
style_btn_bg->body.padding.top + style_btn_bg->body.padding.bottom; style_btn_bg->body.padding.top + style_btn_bg->body.padding.bottom;
@ -1050,7 +1050,7 @@ static void tabview_realign(lv_obj_t * tabview)
break; break;
case LV_TABVIEW_BTNS_POS_LEFT: case LV_TABVIEW_BTNS_POS_LEFT:
case LV_TABVIEW_BTNS_POS_RIGHT: case LV_TABVIEW_BTNS_POS_RIGHT:
btns_size = lv_font_get_width(style_btn_rel->text.font, 0x0041) + // 'A' btns_size = lv_font_get_glyph_width(style_btn_rel->text.font, 'A', '\0') +
style_btn_rel->body.padding.left + style_btn_rel->body.padding.left +
style_btn_rel->body.padding.right + style_btn_rel->body.padding.right +
style_btn_bg->body.padding.left + style_btn_bg->body.padding.right; style_btn_bg->body.padding.left + style_btn_bg->body.padding.right;