diff --git a/src/text/ft2.c b/src/text/ft2.c index 37bed4e..0cff866 100644 --- a/src/text/ft2.c +++ b/src/text/ft2.c @@ -100,11 +100,11 @@ static int ft2_MwDrawText(MwWidget handle, MwFLFont ttf, MwPoint* point, const c } static int ft2_MwTextWidth(MwFLFont ttf, const char* text) { - int tw = 0; + int tw = 0; + FT_Vector vec; while(text[0] != 0) { int c, c2; - FT_Vector vec; const char* old_text; text += MwUTF8ToUTF32(text, &c); @@ -123,7 +123,11 @@ static int ft2_MwTextWidth(MwFLFont ttf, const char* text) { text = old_text; } - tw += ttf->face->glyph->bitmap_left + ttf->face->glyph->bitmap.width; + if(tw > 0) { + tw -= vec.x >> 6; + tw -= ttf->face->glyph->advance.x >> 6; + 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 369ad20..bd26741 100644 --- a/src/text/stbtt.c +++ b/src/text/stbtt.c @@ -91,9 +91,9 @@ static int stbtt_MwTextWidth(MwFLFont ttf, const char* text) { int tw = 0; int c; int x0, y0, x1, y1; + int kern; while(text[0] != 0) { - int kern; int c2; const char* old_text; @@ -113,8 +113,13 @@ 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; + if(tw > 0) { + tw -= ceil(kern * ttf->scale); + tw -= ceil(ax * ttf->scale); + stbtt_GetCodepointBitmapBox(&ttf->font, c, ttf->scale, ttf->scale, &x0, &y0, &x1, &y1); + tw += ceil(lsb * ttf->scale); + tw += x1 - x0; + } return tw + 1; }