瀏覽代碼

更新CPU工程中的awtk库文件
修复文字位置误差可能引发的文字显示缺损问题。

helen 2 周之前
父節點
當前提交
6857256538

+ 11 - 3
amt630hv160-freertos-beta/lib/awtk/awtk/3rd/vglite/vgcanvas_nanovg_vglite.c

@@ -1527,7 +1527,7 @@ static uint32_t get_vglite_vertor_font(stbtt_vertex* vertices, int num_vertices)
 	return dataSize;
 }
 
-void vglite_draw_glyph_tt(stbtt_fontinfo* sf, wchar_t chr, const rect_t* dst, rect_t* r, float_t scale, vg_lite_color_t color) {
+void vglite_draw_glyph_truetype(stbtt_fontinfo* sf, wchar_t chr, const rect_t* dst, rect_t* r, float_t scale, float tx, float ty, vg_lite_color_t color) {
 	int glyphIndex, num_vertices;
 	stbtt_vertex* vertices;
 	vg_lite_error_t error;
@@ -1535,12 +1535,20 @@ void vglite_draw_glyph_tt(stbtt_fontinfo* sf, wchar_t chr, const rect_t* dst, re
 	vg_lite_path_t pathx = {0};
 	vg_lite_matrix_t matrix = {0};
 	uint32_t bounds[4] = {dst->x, dst->y - dst->h, dst->w, dst->y};
+	int32_t x0,x1,y0,y1;
 	uint32_t start_address, rt_pixsize, dataSize = 0, vertFlag = 0;
 	void* tempData;
 	vg_lite_enable_scissor();
-	vg_lite_set_scissor(r->x, r->y, r->x + r->w, r->y + r->h);
+
+	x0 = (dst->x < r->x) ? r->x : dst->x;
+	y0 = (dst->y - dst->h < r->y) ? r->y : dst->y - dst->h;
+	x1 = ((dst->x + dst->w) > (r->x + r->w)) ? (r->x + r->w) : (dst->x + dst->w);
+	y1 = (dst->y > (r->y + r->h)) ? (r->y + r->h) : dst->y;
+
+	vg_lite_set_scissor(x0, y0, x1, y1);
+
 	vg_lite_identity(&matrix);
-	vg_lite_translate(dst->x, dst->y, &matrix);
+	vg_lite_translate(dst->x - tx, dst->y + ty, &matrix);
 	vg_lite_scale(scale, -scale, &matrix);
 
 #ifdef VGLITE_FONT_CACHE

+ 7 - 10
amt630hv160-freertos-beta/lib/awtk/awtk/src/base/canvas.c

@@ -755,22 +755,19 @@ extern void font_stb_get_scale_from_font_size(font_t* f, font_size_t font_size,
 
 static ret_t canvas_draw_glyph_vglite(canvas_t* c, void* sf, glyph_t* g, wchar_t chr, xy_t x, xy_t y, float_t scale) {
 
-  rect_t r;
   rect_t dst;
-  xy_t x2 = x + g->w - 1;
-  xy_t y2 = y + g->h - 1;
+  rect_t r;
 
-  if (!canvas_is_rect_in_clip_rect(c, x + g->x, y + g->y, x2, y2)) {
+  if (!canvas_is_rect_in_clip_rect(c, x, y - g->h, x + g->w, y)) {
     return RET_OK;
   }
   canvas_get_clip_rect(c, &r);
 
   dst.x = x;
   dst.y = y;
-  dst.w = x2 - dst.x + 1;
-  dst.h = y2 - dst.y + 1;
-
-  return lcd_draw_glyph_vglite(c->lcd, sf, chr, &dst, &r, scale);
+  dst.w = g->w;
+  dst.h = g->h;
+  return lcd_draw_glyph_vglite(c->lcd, sf, chr, &dst, &r, scale, g->x, g->y);
 }
 
 static ret_t canvas_draw_text_vglite_impl(canvas_t* c, const wchar_t* str, uint32_t nr, xy_t x, xy_t y, bool_t line_breaker) {
@@ -804,8 +801,8 @@ static ret_t canvas_draw_text_vglite_impl(canvas_t* c, const wchar_t* str, uint3
     }
 
     if (font_get_glyph(c->font, chr, c->font_size, &g) == RET_OK) {
-      xy_t xx = x;
-      xy_t yy = y + baseline;
+      xy_t xx = x + g.x;
+      xy_t yy = y - g.y + baseline;
       font_stb_get_scale_from_font_size(c->font, c->font_size, &scale);
       canvas_draw_glyph_vglite(c, (void *)font_stb_get_sf_from_font(c->font), &g, chr,
 		xx, yy, scale);

+ 2 - 2
amt630hv160-freertos-beta/lib/awtk/awtk/src/base/lcd.c

@@ -241,9 +241,9 @@ ret_t lcd_draw_glyph(lcd_t* lcd, glyph_t* glyph, const rect_t* src, xy_t x, xy_t
 }
 
 #ifdef VGLITE_FONT
-ret_t lcd_draw_glyph_vglite(lcd_t* lcd, void* sf, wchar_t chr, const rect_t* dst, rect_t* r, float_t scale) {
+ret_t lcd_draw_glyph_vglite(lcd_t* lcd, void* sf, wchar_t chr, const rect_t* dst, rect_t* r , float_t scale, float tx, float ty) {
   return_value_if_fail(lcd != NULL && lcd->draw_glyph != NULL && dst != NULL, RET_BAD_PARAMS);
-  return lcd->draw_text_vglite(lcd, sf, chr, dst, r, scale);
+  return lcd->draw_text_vglite(lcd, sf, chr, dst, r, scale, tx, ty);
 }
 #endif
 

+ 2 - 2
amt630hv160-freertos-beta/lib/awtk/awtk/src/base/lcd.h

@@ -82,7 +82,7 @@ typedef ret_t (*lcd_draw_glyph_t)(lcd_t* lcd, glyph_t* glyph, const rect_t* src,
 typedef float_t (*lcd_measure_text_t)(lcd_t* lcd, const wchar_t* str, uint32_t nr);
 typedef ret_t (*lcd_draw_text_t)(lcd_t* lcd, const wchar_t* str, uint32_t nr, xy_t x, xy_t y);
 #ifdef VGLITE_FONT
-typedef ret_t (*lcd_draw_text_vglite)(lcd_t* lcd, void* sf, wchar_t chr, const rect_t* dst, rect_t* r, float_t scale);
+typedef ret_t (*lcd_draw_text_vglite)(lcd_t* lcd, void* sf, wchar_t chr, const rect_t* dst, rect_t* r, float_t scale, float tx, float ty);
 #endif
 typedef ret_t (*lcd_draw_image_t)(lcd_t* lcd, bitmap_t* img, const rectf_t* src,
                                   const rectf_t* dst);
@@ -532,7 +532,7 @@ ret_t lcd_draw_glyph(lcd_t* lcd, glyph_t* glyph, const rect_t* src, xy_t x, xy_t
  */
 
 #ifdef VGLITE_FONT
-ret_t lcd_draw_glyph_vglite(lcd_t* lcd, void* sf, wchar_t chr, const rect_t* dst, rect_t *r, float_t scale);
+ret_t lcd_draw_glyph_vglite(lcd_t* lcd, void* sf, wchar_t chr, const rect_t* dst, rect_t* r , float_t scale, float tx, float ty);
 #endif
 
 float_t lcd_measure_text(lcd_t* lcd, const wchar_t* str, uint32_t nr);

+ 9 - 9
amt630hv160-freertos-beta/lib/awtk/awtk/src/font_loader/font_loader_stb.c

@@ -183,10 +183,10 @@ void font_stb_get_scale_from_font_size(font_t* f, font_size_t font_size, float_t
 }
 static ret_t font_stb_find_glyph(font_t* f, wchar_t c, font_size_t font_size, glyph_t* g) {
 
-  int x = 0;
-  int y = 0;
-  int w = 0;
-  int h = 0;
+  int x0 = 0;
+  int y0 = 0;
+  int x1 = 0;
+  int y1 = 0;
   int lsb = 0;
   int advance = 0;
   font_stb_t* font = (font_stb_t*)f;
@@ -202,13 +202,13 @@ static ret_t font_stb_find_glyph(font_t* f, wchar_t c, font_size_t font_size, gl
     return RET_OK;
   }
 
-  stbtt_GetGlyphBitmapBoxSubpixel(sf, stbtt_FindGlyphIndex(sf,c), scale, scale, 0, 0, &w, &h, &x, &y);
+  stbtt_GetGlyphBitmapBoxSubpixel(sf, stbtt_FindGlyphIndex(sf,c), scale, scale, 0, 0, &x0, &y0, &x1, &y1);
   stbtt_GetCodepointHMetrics(sf, c, &advance, &lsb);
 
-  g->x = w;
-  g->y = h;
-  g->w = x - w;
-  g->h = y - h;
+  g->x = x0;
+  g->y = -y1;
+  g->w = x1 - x0;
+  g->h = y1 - y0;
   g->format = GLYPH_FMT_ALPHA;
   g->advance = tk_roundi(advance * scale);
   g->data = NULL;

+ 3 - 3
amt630hv160-freertos-beta/lib/awtk/awtk/src/lcd/lcd_mem.inc

@@ -460,9 +460,9 @@ static ret_t lcd_mem_draw_glyph(lcd_t* lcd, glyph_t* glyph, const rect_t* src, x
 #ifdef VGLITE_FONT
 //#include "vg_lite.h"
 #include "stb\stb_truetype.h"
-extern void vglite_draw_glyph_tt(void* sf, wchar_t chr, const rect_t* dst, rect_t* r, float_t scale, uint32_t color);
-static ret_t vglite_draw_text_vglite(lcd_t* lcd, void* sf, wchar_t chr, const rect_t* dst, rect_t* r, float_t scale) {
-  vglite_draw_glyph_tt(sf, chr, dst, r, scale, lcd->text_color.color);
+extern void vglite_draw_glyph_truetype(void* sf, wchar_t chr, const rect_t* dst, rect_t* r , float_t scale, float tx, float ty, uint32_t color);
+static ret_t vglite_draw_text_vglite(lcd_t* lcd, void* sf, wchar_t chr, const rect_t* dst, rect_t* r , float_t scale, float tx, float ty) {
+  vglite_draw_glyph_truetype(sf, chr, dst, r, scale, tx, ty, lcd->text_color.color);
   return RET_OK;
 }
 #endif