diff --git a/demos/demo_vg_app.c b/demos/demo_vg_app.c index e91dfc383..0c245c127 100644 --- a/demos/demo_vg_app.c +++ b/demos/demo_vg_app.c @@ -283,6 +283,31 @@ static ret_t on_paint_center(void* ctx, event_t* e) { #include "vg_common.inc" +static ret_t on_paint_text(void* ctx, event_t* e) { + int32_t x = 0; + int32_t y = 0; + paint_event_t* evt = (paint_event_t*)e; + canvas_t* c = evt->c; + color_t color = color_init(0xff, 0, 0, 0xff); + vgcanvas_t* vg = canvas_get_vgcanvas(c); + + color = color_init(0xff, 0, 0, 0xff); + canvas_set_stroke_color(c, color); + canvas_stroke_rect(c, x, y, 100, 30); + + color = color_init(0xff, 0, 0, 0xff); + canvas_set_text_color(c, color); + canvas_set_font(c, NULL, 30); + + vgcanvas_set_fill_color(vg, color); + vgcanvas_fill_text(vg, "ABC", 0, 0, 100); + /* + vgcanvas_translate(vg, x, y); + canvas_draw_text(c, L"abc", 3, 0, 0); + */ + return RET_OK; +} + static ret_t on_paint_vg(void* ctx, event_t* e) { paint_event_t* evt = (paint_event_t*)e; canvas_t* c = evt->c; diff --git a/docs/changes.md b/docs/changes.md index 3d1f2b918..b3923841b 100644 --- a/docs/changes.md +++ b/docs/changes.md @@ -2,6 +2,7 @@ * 2019/03/05 * 更新文档。 * slide view支持循环切换。 + * 修改canvas\_draw\_text和vgcanvas\_fill\_text坐标不一致的问题。 * 2019/03/04 * 完善progressbar/slider的显示函数。 diff --git a/src/base/canvas.c b/src/base/canvas.c index a758e8a88..d0227f12f 100644 --- a/src/base/canvas.c +++ b/src/base/canvas.c @@ -1349,6 +1349,8 @@ vgcanvas_t* canvas_get_vgcanvas(canvas_t* c) { canvas_get_clip_rect(c, &r); vgcanvas_clip_rect(vg, r.x, r.y, r.w, r.h); vgcanvas_begin_path(vg); + vgcanvas_set_text_align(vg, "left"); + vgcanvas_set_text_baseline(vg, "top"); } return vg;