mirror of
https://github.com/lvgl/lvgl.git
synced 2025-01-28 07:03:00 +08:00
font: separate int. and fract. advanced width
This commit is contained in:
parent
c7e6af03e6
commit
d8a17c483a
@ -256,10 +256,6 @@ void lv_draw_letter(const lv_point_t * pos_p, const lv_area_t * mask_p, const lv
|
||||
uint8_t bitmask_init;
|
||||
uint8_t bitmask;
|
||||
|
||||
if(lv_font_is_monospace(font_p, letter)) {
|
||||
pos_x += (lv_font_get_width(font_p, letter) - g->box_w) / 2;
|
||||
}
|
||||
|
||||
switch(bpp) {
|
||||
case 1:
|
||||
bpp_opa_table = bpp1_opa_table;
|
||||
|
@ -181,7 +181,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;
|
||||
|
||||
letter_w = lv_font_get_width(font, letter);
|
||||
letter_w = lv_font_get_width_int(font, letter);
|
||||
|
||||
if(sel_start != 0xFFFF && sel_end != 0xFFFF) {
|
||||
int char_ind = lv_encoded_get_char_id(txt, i);
|
||||
|
@ -124,10 +124,16 @@ const lv_font_glyph_dsc_t * lv_font_get_glyph_dsc(const lv_font_t * font_p, uint
|
||||
return NULL;
|
||||
}
|
||||
|
||||
uint8_t lv_font_get_width(const lv_font_t * font, uint32_t letter)
|
||||
uint8_t lv_font_get_width_int(const lv_font_t * font, uint32_t letter)
|
||||
{
|
||||
const lv_font_glyph_dsc_t * dsc = lv_font_get_glyph_dsc(font, letter);
|
||||
return dsc ? dsc->adv_w : 0;
|
||||
return dsc ? LV_FONT_GET_ADV_W_INT(dsc->adv_w) : 0;
|
||||
}
|
||||
|
||||
uint8_t lv_font_get_width_fract(const lv_font_t * font, uint32_t letter)
|
||||
{
|
||||
const lv_font_glyph_dsc_t * dsc = lv_font_get_glyph_dsc(font, letter);
|
||||
return dsc ? LV_FONT_GET_ADV_W_FRACT(dsc->adv_w) : 0;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -122,22 +122,14 @@ const uint8_t * lv_font_get_glyph_bitmap(const lv_font_t * font_p, uint32_t lett
|
||||
*/
|
||||
const lv_font_glyph_dsc_t * lv_font_get_glyph_dsc(const lv_font_t * font_p, uint32_t letter);
|
||||
|
||||
uint8_t lv_font_get_width(const lv_font_t * font, uint32_t letter);
|
||||
uint8_t lv_font_get_width_int(const lv_font_t * font, 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 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);
|
||||
uint8_t lv_font_get_width_int(const lv_font_t * font_p, uint32_t letter);
|
||||
|
||||
/**
|
||||
* Get the line height of a font. All characters fit into this height
|
||||
@ -183,8 +175,8 @@ const lv_font_glyph_dsc_t * lv_font_get_glyph_dsc_plain(const lv_font_t * font,
|
||||
#define LV_FONT_DECLARE(font_name) extern lv_font_t font_name;
|
||||
|
||||
#define LV_FONT_SET_ADV_W(_integer, _fract) ((_integer << LV_FONT_ADV_W_FRACT_DIGIT) + _fract)
|
||||
#define LV_FONT_GET_ADV_W_INT(_adv_w) (_adw_v >> LV_FONT_ADV_W_FRACT_DIGIT)
|
||||
#define LV_FONT_GET_ADV_W_FRACT(_adv_w) (_adw_v & ((1 << LV_FONT_ADV_W_FRACT_DIGIT) -1))
|
||||
#define LV_FONT_GET_ADV_W_INT(_adv_w) (_adv_w >> LV_FONT_ADV_W_FRACT_DIGIT)
|
||||
#define LV_FONT_GET_ADV_W_FRACT(_adv_w) (_adv_w & ((1 << LV_FONT_ADV_W_FRACT_DIGIT) -1))
|
||||
|
||||
|
||||
/**********************
|
||||
|
@ -196,7 +196,7 @@ uint16_t lv_txt_get_next_line(const char * txt, const lv_font_t * font, lv_coord
|
||||
|
||||
} else { /*Check the actual length*/
|
||||
n_char_since_last_break++;
|
||||
letter_width = lv_font_get_width(font, letter);
|
||||
letter_width = lv_font_get_width_int(font, letter);
|
||||
cur_w += letter_width;
|
||||
|
||||
/* Get the length of the current work and determine best place
|
||||
@ -242,7 +242,7 @@ uint16_t lv_txt_get_next_line(const char * txt, const lv_font_t * font, lv_coord
|
||||
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_width_int(font, letter);
|
||||
cur_w += letter_width2;
|
||||
if(cur_w > max_width) {
|
||||
/* Current letter already exceeds, return previous */
|
||||
@ -333,7 +333,7 @@ lv_coord_t lv_txt_get_width(const char * txt, uint16_t length, const lv_font_t *
|
||||
}
|
||||
}
|
||||
|
||||
lv_coord_t char_width = lv_font_get_width(font, letter);
|
||||
lv_coord_t char_width = lv_font_get_width_int(font, letter);
|
||||
if(char_width > 0) {
|
||||
width += char_width;
|
||||
width += letter_space;
|
||||
|
@ -577,7 +577,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_width_int(font, letter);
|
||||
if(pos->x < x) {
|
||||
i = i_current;
|
||||
break;
|
||||
@ -683,7 +683,7 @@ bool lv_label_is_char_under_pos(const lv_obj_t * label, lv_point_t * pos)
|
||||
}
|
||||
}
|
||||
last_x = x;
|
||||
x += lv_font_get_width(font, letter);
|
||||
x += lv_font_get_width_int(font, letter);
|
||||
if(pos->x < x) {
|
||||
i = i_current;
|
||||
break;
|
||||
@ -692,7 +692,7 @@ bool lv_label_is_char_under_pos(const lv_obj_t * label, lv_point_t * pos)
|
||||
i_current = i;
|
||||
}
|
||||
|
||||
int max_diff = lv_font_get_width(font, letter) + style->text.letter_space + 1;
|
||||
int max_diff = lv_font_get_width_int(font, letter) + style->text.letter_space + 1;
|
||||
return (pos->x >= (last_x - style->text.letter_space) && pos->x <= (last_x + max_diff));
|
||||
}
|
||||
|
||||
@ -836,7 +836,7 @@ static bool lv_label_design(lv_obj_t * label, const lv_area_t * mask, lv_design_
|
||||
/*Draw the text again next to the original to make an circular effect */
|
||||
if(size.x > lv_obj_get_width(label)) {
|
||||
ofs.x = ext->offset.x + size.x +
|
||||
lv_font_get_width(style->text.font, ' ') * LV_LABEL_WAIT_CHAR_COUNT;
|
||||
lv_font_get_width_int(style->text.font, ' ') * LV_LABEL_WAIT_CHAR_COUNT;
|
||||
ofs.y = ext->offset.y;
|
||||
|
||||
lv_draw_label(&coords, mask, style, opa_scale, ext->text, flag, &ofs,
|
||||
@ -951,7 +951,7 @@ static void lv_label_refr_text(lv_obj_t * label)
|
||||
anim.ready_cb = NULL;
|
||||
anim.path_cb = lv_anim_path_linear;
|
||||
anim.playback_pause =
|
||||
(((lv_font_get_width(style->text.font, ' ') + style->text.letter_space) * 1000) /
|
||||
(((lv_font_get_width_int(style->text.font, ' ') + style->text.letter_space) * 1000) /
|
||||
ext->anim_speed) * LV_LABEL_WAIT_CHAR_COUNT;
|
||||
anim.repeat_pause = anim.playback_pause;
|
||||
anim.act_time = -anim.playback_pause;
|
||||
@ -991,7 +991,7 @@ static void lv_label_refr_text(lv_obj_t * label)
|
||||
anim.playback = 0;
|
||||
anim.start = 0;
|
||||
anim.act_time =
|
||||
-(((lv_font_get_width(style->text.font, ' ') + style->text.letter_space) * 1000) /
|
||||
-(((lv_font_get_width_int(style->text.font, ' ') + style->text.letter_space) * 1000) /
|
||||
ext->anim_speed) * LV_LABEL_WAIT_CHAR_COUNT;
|
||||
anim.ready_cb = NULL;
|
||||
anim.path_cb = lv_anim_path_linear;
|
||||
@ -1000,7 +1000,7 @@ static void lv_label_refr_text(lv_obj_t * label)
|
||||
|
||||
bool hor_anim = false;
|
||||
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_width_int(font, ' ') * LV_LABEL_WAIT_CHAR_COUNT;
|
||||
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);
|
||||
lv_anim_create(&anim);
|
||||
@ -1031,7 +1031,7 @@ static void lv_label_refr_text(lv_obj_t * label)
|
||||
} else {
|
||||
lv_point_t p;
|
||||
p.x = lv_obj_get_width(label) -
|
||||
(lv_font_get_width(style->text.font, '.') + style->text.letter_space) *
|
||||
(lv_font_get_width_int(style->text.font, '.') + style->text.letter_space) *
|
||||
LV_LABEL_DOT_NUM; /*Shrink with dots*/
|
||||
p.y = lv_obj_get_height(label);
|
||||
p.y -= p.y % (lv_font_get_line_height(style->text.font) +
|
||||
|
@ -455,7 +455,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*/
|
||||
if(lv_obj_get_width(ext->label) == 0) {
|
||||
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_width_int(style->text.font, ' '));
|
||||
}
|
||||
|
||||
if(ext->pwd_mode != 0) {
|
||||
@ -1524,9 +1524,9 @@ static void refr_cursor_area(lv_obj_t * ta)
|
||||
/*Set letter_w (set not 0 on non printable but valid chars)*/
|
||||
lv_coord_t letter_w;
|
||||
if(letter == '\0' || letter == '\n' || letter == '\r') {
|
||||
letter_w = lv_font_get_width(label_style->text.font, ' ');
|
||||
letter_w = lv_font_get_width_int(label_style->text.font, ' ');
|
||||
} else {
|
||||
letter_w = lv_font_get_width(label_style->text.font, letter);
|
||||
letter_w = lv_font_get_width_int(label_style->text.font, letter);
|
||||
}
|
||||
|
||||
lv_point_t letter_pos;
|
||||
@ -1544,9 +1544,9 @@ static void refr_cursor_area(lv_obj_t * ta)
|
||||
}
|
||||
|
||||
if(letter == '\0' || letter == '\n' || letter == '\r') {
|
||||
letter_w = lv_font_get_width(label_style->text.font, ' ');
|
||||
letter_w = lv_font_get_width_int(label_style->text.font, ' ');
|
||||
} else {
|
||||
letter_w = lv_font_get_width(label_style->text.font, letter);
|
||||
letter_w = lv_font_get_width_int(label_style->text.font, letter);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1031,7 +1031,7 @@ static void tabview_realign(lv_obj_t * tabview)
|
||||
break;
|
||||
case LV_TABVIEW_BTNS_POS_LEFT:
|
||||
case LV_TABVIEW_BTNS_POS_RIGHT:
|
||||
btns_size = lv_font_get_width(style_btn_rel->text.font, 0x0041) + // 'A'
|
||||
btns_size = lv_font_get_width_int(style_btn_rel->text.font, 0x0041) + // 'A'
|
||||
style_btn_rel->body.padding.left +
|
||||
style_btn_rel->body.padding.right +
|
||||
style_btn_bg->body.padding.left + style_btn_bg->body.padding.right;
|
||||
|
Loading…
x
Reference in New Issue
Block a user