diff -r a701614d029f SDL_ttf.c --- a/SDL_ttf.c Thu Oct 18 12:11:00 2018 +0300 +++ b/SDL_ttf.c Fri Oct 19 22:12:05 2018 +0200 @@ -196,6 +196,8 @@ return TTF_strikethrough_top_row(font) - font->ascent + glyph->maxy; } +static int g_padding_xstart; + static void TTF_initLineMectrics(const TTF_Font *font, const SDL_Surface *textbuf, const int row, Uint8 **pdst, int *pheight) { Uint8 *dst; @@ -1253,7 +1255,7 @@ /* Load each character and sum it's bounding box */ textlen = SDL_strlen(text); - x= 0; + x = 0; while (textlen > 0) { Uint32 c = UTF8_getch(&text, &textlen); if (c == UNICODE_BOM_NATIVE || c == UNICODE_BOM_SWAPPED) { @@ -1319,6 +1321,9 @@ prev_index = glyph->index; } + /* Remember the padding for the current string */ + g_padding_xstart = (minx < 0 ? - minx : 0); + /* Fill the bounds rectangle */ if (w) { /* Add outline extra width */ @@ -1433,7 +1438,7 @@ /* Load and render each character */ textlen = SDL_strlen(text); - xstart = 0; + xstart = g_padding_xstart; while (textlen > 0) { Uint32 c = UTF8_getch(&text, &textlen); if (c == UNICODE_BOM_NATIVE || c == UNICODE_BOM_SWAPPED) { @@ -1463,9 +1468,6 @@ for (row = 0; row < current->rows; ++row) { /* Make sure we don't go either over, or under the limit */ - if ((xstart + glyph->minx) < 0) { - xstart -= (xstart + glyph->minx); - } if ((row + glyph->yoffset) < 0) { continue; } @@ -1625,7 +1627,7 @@ /* Load and render each character */ textlen = SDL_strlen(text); - xstart = 0; + xstart = g_padding_xstart; while (textlen > 0) { Uint32 c = UTF8_getch(&text, &textlen); if (c == UNICODE_BOM_NATIVE || c == UNICODE_BOM_SWAPPED) { @@ -1655,9 +1657,6 @@ current = &glyph->pixmap; for (row = 0; row < current->rows; ++row) { /* Make sure we don't go either over, or under the limit */ - if ((xstart + glyph->minx) < 0) { - xstart -= (xstart + glyph->minx); - } if ((row + glyph->yoffset) < 0) { continue; } @@ -1807,7 +1806,7 @@ /* Load and render each character */ textlen = SDL_strlen(text); - xstart = 0; + xstart = g_padding_xstart; pixel = (fg.r<<16)|(fg.g<<8)|fg.b; SDL_FillRect(textbuf, NULL, pixel); /* Initialize with fg and 0 alpha */ while (textlen > 0) { @@ -1838,9 +1837,6 @@ for (row = 0; row < glyph->pixmap.rows; ++row) { /* Make sure we don't go either over, or under the limit */ - if ((xstart + glyph->minx) < 0) { - xstart -= (xstart + glyph->minx); - } if ((row + glyph->yoffset) < 0) { continue; } @@ -2099,7 +2095,7 @@ text = strLines[line]; } textlen = SDL_strlen(text); - xstart = 0; + xstart = g_padding_xstart; while (textlen > 0) { Uint32 c = UTF8_getch(&text, &textlen); if (c == UNICODE_BOM_NATIVE || c == UNICODE_BOM_SWAPPED) { @@ -2132,9 +2128,6 @@ for (row = 0; row < glyph->pixmap.rows; ++row) { /* Make sure we don't go either over, or under the limit */ - if ((xstart + glyph->minx) < 0) { - xstart -= (xstart + glyph->minx); - } if ((row + glyph->yoffset) < 0) { continue; }