From 190e4353e47d21421c67c7cffee887bc6c109497 Mon Sep 17 00:00:00 2001 From: NishiOwO Date: Mon, 27 Apr 2026 03:39:02 +0900 Subject: [PATCH] fix ft2 rendering --- src/text/ft2.c | 19 ++++++------------- src/text/stbtt.c | 15 ++++----------- 2 files changed, 10 insertions(+), 24 deletions(-) diff --git a/src/text/ft2.c b/src/text/ft2.c index 32e6587..3634656 100644 --- a/src/text/ft2.c +++ b/src/text/ft2.c @@ -81,7 +81,7 @@ static int ft2_MwDrawText(MwWidget handle, MwFLFont ttf, MwPoint* point, const c } } - x += (ttf->face->glyph->advance.x >> 6) + (ttf->face->glyph->metrics.horiBearingX >> 6); + x += (ttf->face->glyph->advance.x >> 6); old_text = text; text += MwUTF8ToUTF32(text, &c2); @@ -109,7 +109,7 @@ static int ft2_MwDrawText(MwWidget handle, MwFLFont ttf, MwPoint* point, const c } static int ft2_MwTextWidth(MwFLFont ttf, const char* text) { - int tw = 0, mtw = 0; + int tw = 0; while(text[0] != 0) { int c, c2; @@ -117,29 +117,22 @@ static int ft2_MwTextWidth(MwFLFont ttf, const char* text) { const char* old_text; text += MwUTF8ToUTF32(text, &c); - if(c == '\n') { - tw = 0; - continue; - } ft_table.FT_Load_Char(ttf->face, c, FT_LOAD_DEFAULT); - tw += (ttf->face->glyph->advance.x >> 6) + (ttf->face->glyph->metrics.horiBearingX >> 6); + tw += (ttf->face->glyph->advance.x >> 6); old_text = text; text += MwUTF8ToUTF32(text, &c2); - if(c2 != '\n') { - ft_table.FT_Get_Kerning(ttf->face, c, c2, FT_KERNING_DEFAULT, &vec); + ft_table.FT_Get_Kerning(ttf->face, c, c2, FT_KERNING_DEFAULT, &vec); - tw += vec.x >> 6; - } + tw += vec.x >> 6; text = old_text; - if(tw > mtw) mtw = tw; } - return mtw + 1; + return tw + 1; } static int ft2_MwTextHeight(MwFLFont ttf, int count) { diff --git a/src/text/stbtt.c b/src/text/stbtt.c index a841907..ace0190 100644 --- a/src/text/stbtt.c +++ b/src/text/stbtt.c @@ -95,7 +95,7 @@ static int stbtt_MwDrawText(MwWidget handle, MwFLFont ttf, MwPoint* point, const static int stbtt_MwTextWidth(MwFLFont ttf, const char* text) { int ax, lsb; - int tw = 0, mtw = 0; + int tw = 0; while(text[0] != 0) { int kern; @@ -103,10 +103,6 @@ static int stbtt_MwTextWidth(MwFLFont ttf, const char* text) { const char* old_text; text += MwUTF8ToUTF32(text, &c); - if(c == '\n') { - tw = 0; - continue; - } stbtt_GetCodepointHMetrics(&ttf->font, c, &ax, &lsb); @@ -115,17 +111,14 @@ static int stbtt_MwTextWidth(MwFLFont ttf, const char* text) { old_text = text; text += MwUTF8ToUTF32(text, &c2); - if(c2 != '\n') { - kern = stbtt_GetCodepointKernAdvance(&ttf->font, c, c2); + kern = stbtt_GetCodepointKernAdvance(&ttf->font, c, c2); - tw += ceil(kern * ttf->scale); - } + tw += ceil(kern * ttf->scale); text = old_text; - if(tw > mtw) mtw = tw; } - return mtw + 1; + return tw + 1; } static int stbtt_MwTextHeight(MwFLFont ttf, int count) {