mirror of
https://gitee.com/zlgopen/awtk.git
synced 2024-12-02 03:58:33 +08:00
add vgcanvas_get_text_metrics
This commit is contained in:
parent
603e672f09
commit
37055a7f56
@ -3,6 +3,7 @@
|
||||
* 2020/06/30
|
||||
* 完善 font gen(感谢智明提供补丁)。
|
||||
* 完善 image dither(感谢大恒提供补丁)。
|
||||
* add vgcanvas\_get\_text\_metrics.
|
||||
|
||||
* 2020/06/29
|
||||
* 完善 listview layout(感谢尧燊提供补丁)
|
||||
|
@ -1799,3 +1799,25 @@ ret_t canvas_reset(canvas_t* c) {
|
||||
|
||||
return RET_OK;
|
||||
}
|
||||
|
||||
ret_t canvas_get_text_metrics(canvas_t* c, float_t* ascent, float_t* descent,
|
||||
float_t* line_hight) {
|
||||
return_value_if_fail(c!= NULL, RET_BAD_PARAMS);
|
||||
return_value_if_fail(ascent != NULL && descent != NULL && line_hight != NULL, RET_BAD_PARAMS);
|
||||
|
||||
if(c->lcd != NULL && c->lcd->get_text_metrics != NULL) {
|
||||
return c->lcd->get_text_metrics(c->lcd, ascent, descent, line_hight);
|
||||
} else if(c->font != NULL) {
|
||||
font_vmetrics_t vmetrics = font_get_vmetrics(c->font, c->font_size);
|
||||
|
||||
*ascent = vmetrics.ascent;
|
||||
*descent = vmetrics.descent;
|
||||
*line_hight = vmetrics.line_gap + vmetrics.ascent + vmetrics.descent;
|
||||
return RET_OK;
|
||||
} else {
|
||||
*ascent = 0;
|
||||
*descent = 0;
|
||||
*line_hight = 0;
|
||||
return RET_FAIL;
|
||||
}
|
||||
}
|
||||
|
@ -690,6 +690,20 @@ ret_t canvas_set_font_manager(canvas_t* c, font_manager_t* font_manager);
|
||||
*/
|
||||
ret_t canvas_set_assets_manager(canvas_t* c, assets_manager_t* assets_manager);
|
||||
|
||||
/**
|
||||
* @method canvas_get_text_metrics
|
||||
* 获取当前字体的度量信息。
|
||||
*
|
||||
* @param {canvas_t*} canvas canvas对象。
|
||||
* @param {float_t*} ascent 用于返回ascent。
|
||||
* @param {float_t*} descent 用于返回descent。
|
||||
* @param {float_t*} line_hight 用于返回line height。
|
||||
*
|
||||
* @return {ret_t} 返回RET_OK表示成功,否则表示失败。
|
||||
*/
|
||||
ret_t canvas_get_text_metrics(canvas_t* canvas, float_t* ascent,
|
||||
float_t* descent, float_t* line_hight);
|
||||
|
||||
/**
|
||||
* @method canvas_begin_frame
|
||||
* 绘制开始。
|
||||
|
@ -320,3 +320,11 @@ wh_t lcd_get_height(lcd_t* lcd) {
|
||||
return lcd->h;
|
||||
}
|
||||
}
|
||||
|
||||
ret_t lcd_get_text_metrics(lcd_t* lcd, float_t* ascent,
|
||||
float_t* descent, float_t* line_hight) {
|
||||
return_value_if_fail(lcd != NULL && lcd->get_text_metrics != NULL, RET_BAD_PARAMS);
|
||||
|
||||
return lcd->get_text_metrics(lcd, ascent, descent, line_hight);
|
||||
}
|
||||
|
||||
|
@ -45,6 +45,8 @@ typedef ret_t (*lcd_begin_frame_t)(lcd_t* lcd, rect_t* dirty_rect);
|
||||
typedef ret_t (*lcd_set_clip_rect_t)(lcd_t* lcd, rect_t* rect);
|
||||
typedef ret_t (*lcd_get_clip_rect_t)(lcd_t* lcd, rect_t* rect);
|
||||
typedef ret_t (*lcd_resize_t)(lcd_t* lcd, wh_t w, wh_t h, uint32_t line_length);
|
||||
typedef ret_t (*lcd_get_text_metrics_t)(lcd_t* lcd, float_t* ascent,
|
||||
float_t* descent, float_t* line_hight);
|
||||
|
||||
typedef ret_t (*lcd_set_global_alpha_t)(lcd_t* lcd, uint8_t alpha);
|
||||
typedef ret_t (*lcd_set_text_color_t)(lcd_t* lcd, color_t color);
|
||||
@ -164,6 +166,7 @@ struct _lcd_t {
|
||||
lcd_set_fill_color_t set_fill_color;
|
||||
lcd_set_font_name_t set_font_name;
|
||||
lcd_set_font_size_t set_font_size;
|
||||
lcd_get_text_metrics_t get_text_metrics;
|
||||
lcd_draw_vline_t draw_vline;
|
||||
lcd_draw_hline_t draw_hline;
|
||||
lcd_fill_rect_t fill_rect;
|
||||
@ -608,6 +611,20 @@ bool_t lcd_is_swappable(lcd_t* lcd);
|
||||
*/
|
||||
ret_t lcd_end_frame(lcd_t* lcd);
|
||||
|
||||
/**
|
||||
* @method lcd_get_text_metrics
|
||||
* 获取当前字体的度量信息。
|
||||
*
|
||||
* @param {lcd_t*} lcd lcd对象。
|
||||
* @param {float_t*} ascent 用于返回ascent。
|
||||
* @param {float_t*} descent 用于返回descent。
|
||||
* @param {float_t*} line_hight 用于返回line height。
|
||||
*
|
||||
* @return {ret_t} 返回RET_OK表示成功,否则表示失败。
|
||||
*/
|
||||
ret_t lcd_get_text_metrics(lcd_t* lcd, float_t* ascent,
|
||||
float_t* descent, float_t* line_hight);
|
||||
|
||||
/**
|
||||
* @method lcd_destroy
|
||||
* 销毁lcd对象。
|
||||
|
@ -510,3 +510,12 @@ wh_t vgcanvas_get_height(vgcanvas_t* vgcanvas) {
|
||||
return vgcanvas->h;
|
||||
}
|
||||
}
|
||||
|
||||
ret_t vgcanvas_get_text_metrics(vgcanvas_t* vg, float_t* ascent,
|
||||
float_t* descent, float_t* line_hight) {
|
||||
return_value_if_fail(vg != NULL && vg->vt != NULL, RET_BAD_PARAMS);
|
||||
return_value_if_fail(vg->vt->get_text_metrics != NULL, RET_BAD_PARAMS);
|
||||
|
||||
return vg->vt->get_text_metrics(vg, ascent, descent, line_hight);
|
||||
}
|
||||
|
||||
|
@ -86,6 +86,8 @@ typedef ret_t (*vgcanvas_set_font_t)(vgcanvas_t* vg, const char* font);
|
||||
typedef ret_t (*vgcanvas_set_font_size_t)(vgcanvas_t* vg, float_t size);
|
||||
typedef ret_t (*vgcanvas_set_text_align_t)(vgcanvas_t* vg, const char* value);
|
||||
typedef ret_t (*vgcanvas_set_text_baseline_t)(vgcanvas_t* vg, const char* value);
|
||||
typedef ret_t (*vgcanvas_get_text_metrics_t)(vgcanvas_t* vg, float_t* ascent,
|
||||
float_t* descent, float_t* line_hight);
|
||||
typedef ret_t (*vgcanvas_fill_text_t)(vgcanvas_t* vg, const char* text, float_t x, float_t y,
|
||||
float_t max_width);
|
||||
typedef float_t (*vgcanvas_measure_text_t)(vgcanvas_t* vg, const char* text);
|
||||
@ -169,6 +171,7 @@ typedef struct _vgcanvas_vtable_t {
|
||||
vgcanvas_set_font_size_t set_font_size;
|
||||
vgcanvas_set_text_align_t set_text_align;
|
||||
vgcanvas_set_text_baseline_t set_text_baseline;
|
||||
vgcanvas_get_text_metrics_t get_text_metrics;
|
||||
vgcanvas_fill_text_t fill_text;
|
||||
vgcanvas_measure_text_t measure_text;
|
||||
vgcanvas_draw_image_t draw_image;
|
||||
@ -853,6 +856,20 @@ ret_t vgcanvas_set_text_align(vgcanvas_t* vg, const char* value);
|
||||
*/
|
||||
ret_t vgcanvas_set_text_baseline(vgcanvas_t* vg, const char* value);
|
||||
|
||||
/**
|
||||
* @method vgcanvas_get_text_metrics
|
||||
* 获取当前字体的度量信息。
|
||||
*
|
||||
* @param {vgcanvas_t*} vg vgcanvas对象。
|
||||
* @param {float_t*} ascent 用于返回ascent。
|
||||
* @param {float_t*} descent 用于返回descent。
|
||||
* @param {float_t*} line_hight 用于返回line height。
|
||||
*
|
||||
* @return {ret_t} 返回RET_OK表示成功,否则表示失败。
|
||||
*/
|
||||
ret_t vgcanvas_get_text_metrics(vgcanvas_t* vg, float_t* ascent,
|
||||
float_t* descent, float_t* line_hight);
|
||||
|
||||
/**
|
||||
* @method vgcanvas_fill_text
|
||||
* 绘制文本。
|
||||
|
@ -251,6 +251,12 @@ static bitmap_format_t lcd_vgcanvas_get_desired_bitmap_format(lcd_t* lcd) {
|
||||
return BITMAP_FMT_RGBA8888;
|
||||
}
|
||||
|
||||
static ret_t lcd_vgcanvas_get_text_metrics(lcd_t* lcd, float_t* ascender,
|
||||
float_t* descender, float_t* lineh) {
|
||||
vgcanvas_t* canvas = LCD(lcd)->canvas;
|
||||
return vgcanvas_get_text_metrics(canvas, ascender, descender, lineh);
|
||||
}
|
||||
|
||||
lcd_t* lcd_vgcanvas_init(wh_t w, wh_t h, vgcanvas_t* canvas) {
|
||||
lcd_vgcanvas_t* lcd = TKMEM_ZALLOC(lcd_vgcanvas_t);
|
||||
lcd_t* base = &(lcd->base);
|
||||
@ -279,7 +285,7 @@ lcd_t* lcd_vgcanvas_init(wh_t w, wh_t h, vgcanvas_t* canvas) {
|
||||
base->get_width = lcd_vgcanvas_get_width;
|
||||
base->get_height = lcd_vgcanvas_get_height;
|
||||
base->destroy = lcd_vgcanvas_destroy;
|
||||
|
||||
base->get_text_metrics = lcd_vgcanvas_get_text_metrics;
|
||||
base->w = (wh_t)w;
|
||||
base->h = (wh_t)h;
|
||||
base->ratio = canvas->ratio;
|
||||
|
@ -393,6 +393,31 @@ static float_t vgcanvas_nanovg_measure_text(vgcanvas_t* vgcanvas, const char* te
|
||||
return nvgTextBounds(vg, 0, 0, text, text + strlen(text), bounds);
|
||||
}
|
||||
|
||||
static ret_t vgcanvas_nanovg_get_text_metrics(vgcanvas_t* vgcanvas, float_t* ascent,
|
||||
float_t* descent, float_t* line_hight) {
|
||||
NVGcontext* vg = ((vgcanvas_nanovg_t*)vgcanvas)->vg;
|
||||
|
||||
float a = 0;
|
||||
float d = 0;
|
||||
float h = 0;
|
||||
|
||||
nvgTextMetrics(vg, &a, &d, &h);
|
||||
|
||||
if(ascent != NULL) {
|
||||
*ascent = a;
|
||||
}
|
||||
|
||||
if(descent != NULL) {
|
||||
*descent = d;
|
||||
}
|
||||
|
||||
if(line_hight != NULL) {
|
||||
*line_hight = h;
|
||||
}
|
||||
|
||||
return RET_OK;
|
||||
}
|
||||
|
||||
static ret_t vgcanvas_nanovg_draw_image(vgcanvas_t* vgcanvas, bitmap_t* img, float_t sx, float_t sy,
|
||||
float_t sw, float_t sh, float_t dx, float_t dy, float_t dw,
|
||||
float_t dh) {
|
||||
@ -616,6 +641,7 @@ static const vgcanvas_vtable_t vt = {
|
||||
.set_line_join = vgcanvas_nanovg_set_line_join,
|
||||
.set_line_cap = vgcanvas_nanovg_set_line_cap,
|
||||
.set_miter_limit = vgcanvas_nanovg_set_miter_limit,
|
||||
.get_text_metrics = vgcanvas_nanovg_get_text_metrics,
|
||||
.save = vgcanvas_nanovg_save,
|
||||
.restore = vgcanvas_nanovg_restore,
|
||||
.end_frame = vgcanvas_nanovg_end_frame,
|
||||
|
Loading…
Reference in New Issue
Block a user