diff --git a/examples/basic/periodic.c b/examples/basic/periodic.c index 7403ca7..91dd601 100644 --- a/examples/basic/periodic.c +++ b/examples/basic/periodic.c @@ -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); diff --git a/src/text/ft2.c b/src/text/ft2.c index 90a0de8..26cf8cd 100644 --- a/src/text/ft2.c +++ b/src/text/ft2.c @@ -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; } diff --git a/src/text/stbtt.c b/src/text/stbtt.c index ace0190..0bacc80 100644 --- a/src/text/stbtt.c +++ b/src/text/stbtt.c @@ -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; }