fix font rendering
All checks were successful
pyrite-dev/milsko/pipeline/head This commit looks good

This commit is contained in:
Nishi 2026-04-27 03:48:15 +09:00
commit 2ae01d3902
Signed by: nishi
GPG key ID: 27EF69B208EB9343
3 changed files with 11 additions and 4 deletions

View file

@ -266,7 +266,7 @@ int main() {
add(f);
f = frame("Label", -PaddingContent, -PaddingContent, MwLabelClass,
MwNtext, "Epic text",
MwNtext, "Epic text\nI am newline too!",
NULL);
add(f);

View file

@ -66,7 +66,7 @@ static int ft2_MwDrawText(MwWidget handle, MwFLFont ttf, MwPoint* point, const c
for(cy = 0; cy < bmp->rows; cy++) {
for(cx = 0; cx < bmp->width; cx++) {
int ox = x + (ttf->face->glyph->metrics.horiBearingX >> 6) + cx + ttf->face->glyph->bitmap_left;
int ox = x + cx + (ttf->face->glyph->metrics.horiBearingX >> 6) + ttf->face->glyph->bitmap_left;
int oy = y + (ttf->face->height * ttf->px / ttf->face->units_per_EM) - ttf->face->glyph->bitmap_top + cy + (ttf->face->descender * ttf->px / ttf->face->units_per_EM);
unsigned char* opx = &px[(oy * tw + ox) * 4];
opx[0] = color->common.red;
@ -120,7 +120,7 @@ static int ft2_MwTextWidth(MwFLFont ttf, const char* text) {
ft_table.FT_Load_Char(ttf->face, c, FT_LOAD_DEFAULT);
tw += (ttf->face->glyph->advance.x >> 6);
tw += ttf->face->glyph->advance.x >> 6;
old_text = text;
text += MwUTF8ToUTF32(text, &c2);
@ -132,6 +132,8 @@ static int ft2_MwTextWidth(MwFLFont ttf, const char* text) {
text = old_text;
}
tw += ttf->face->glyph->bitmap_left + ttf->face->glyph->bitmap.width;
return tw + 1;
}

View file

@ -96,10 +96,12 @@ 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;
int c;
int x0, y0, x1, y1;
while(text[0] != 0) {
int kern;
int c, c2;
int c2;
const char* old_text;
text += MwUTF8ToUTF32(text, &c);
@ -118,6 +120,9 @@ static int stbtt_MwTextWidth(MwFLFont ttf, const char* text) {
text = old_text;
}
stbtt_GetCodepointBitmapBox(&ttf->font, c, ttf->scale, ttf->scale, &x0, &y0, &x1, &y1);
tw += x1;
return tw + 1;
}