fix ft2 rendering

This commit is contained in:
Nishi 2026-04-27 03:39:02 +09:00
commit 190e4353e4
Signed by: nishi
GPG key ID: 27EF69B208EB9343
2 changed files with 10 additions and 24 deletions

View file

@ -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) {

View file

@ -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) {