Skip to content

Commit

Permalink
additional fix for bug #2749.
Browse files Browse the repository at this point in the history
  • Loading branch information
sezero committed Oct 24, 2018
1 parent c5f9522 commit 6439a04
Showing 1 changed file with 22 additions and 22 deletions.
44 changes: 22 additions & 22 deletions SDL_ttf.c
Expand Up @@ -134,6 +134,8 @@ static FT_Library library;
static int TTF_initialized = 0;
static int TTF_byteswapped = 0;

static int TTF_SizeUNICODE_Internal(TTF_Font *font, const Uint16 *text,
int *w, int *h, int *xstart);

/* Gets the top row of the underline. The outline
is taken into account.
Expand Down Expand Up @@ -477,7 +479,6 @@ TTF_Font* TTF_OpenFontIndexRW( SDL_RWops *src, int freesrc, int ptsize, long ind
font->lineskip = FT_CEIL(FT_MulFix(face->height, scale));
font->underline_offset = FT_FLOOR(FT_MulFix(face->underline_position, scale));
font->underline_height = FT_FLOOR(FT_MulFix(face->underline_thickness, scale));

} else {
/* Non-scalable font case. ptsize determines which family
* or series of fonts to grab from the non-scalable format.
Expand Down Expand Up @@ -637,7 +638,7 @@ static FT_Error Load_Glyph( TTF_Font* font, Uint16 ch, c_glyph* cached, int want
cached->yoffset = 0;
cached->advance = FT_CEIL(metrics->horiAdvance);
}

/* Adjust for bold and italic text */
if( TTF_HANDLE_STYLE_BOLD(font) ) {
cached->maxx += font->glyph_overhang;
Expand Down Expand Up @@ -1081,7 +1082,7 @@ int TTF_SizeText(TTF_Font *font, const char *text, int *w, int *h)
LATIN1_to_UNICODE(unicode_text+1, text, unicode_len);

/* Render the new text */
status = TTF_SizeUNICODE(font, unicode_text, w, h);
status = TTF_SizeUNICODE_Internal(font, unicode_text, w, h, NULL);

/* Free the text buffer and return */
FREEA(unicode_text);
Expand All @@ -1105,14 +1106,19 @@ int TTF_SizeUTF8(TTF_Font *font, const char *text, int *w, int *h)
UTF8_to_UNICODE(unicode_text+1, text, unicode_len);

/* Render the new text */
status = TTF_SizeUNICODE(font, unicode_text, w, h);
status = TTF_SizeUNICODE_Internal(font, unicode_text, w, h, NULL);

/* Free the text buffer and return */
FREEA(unicode_text);
return status;
}

int TTF_SizeUNICODE(TTF_Font *font, const Uint16 *text, int *w, int *h)
{
return TTF_SizeUNICODE_Internal(font, text, w, h, NULL);
}

static int TTF_SizeUNICODE_Internal(TTF_Font *font, const Uint16 *text, int *w, int *h, int *xstart)
{
int status;
const Uint16 *ch;
Expand Down Expand Up @@ -1224,6 +1230,12 @@ int TTF_SizeUNICODE(TTF_Font *font, const Uint16 *text, int *w, int *h)
prev_index = glyph->index;
}

/* Initial x start position: often 0, except when a glyph would be written at
* a negative position. In this case an offset is needed for the whole line.*/
if ( xstart ) {
*xstart = (minx < 0)? -minx : 0;
}

/* Fill the bounds rectangle */
if ( w ) {
/* Add outline extra width */
Expand Down Expand Up @@ -1323,7 +1335,7 @@ SDL_Surface *TTF_RenderUNICODE_Solid(TTF_Font *font,
FT_UInt prev_index = 0;

/* Get the dimensions of the text surface */
if( ( TTF_SizeUNICODE(font, text, &width, &height) < 0 ) || !width ) {
if( ( TTF_SizeUNICODE_Internal(font, text, &width, &height, &xstart) < 0 ) || !width ) {
TTF_SetError( "Text has zero width" );
return NULL;
}
Expand Down Expand Up @@ -1352,7 +1364,6 @@ SDL_Surface *TTF_RenderUNICODE_Solid(TTF_Font *font,
use_kerning = FT_HAS_KERNING( font->face ) && font->kerning;

/* Load and render each character */
xstart = 0;
swapped = TTF_byteswapped;
for( ch=text; *ch; ++ch ) {
Uint16 c = *ch;
Expand Down Expand Up @@ -1394,12 +1405,9 @@ SDL_Surface *TTF_RenderUNICODE_Solid(TTF_Font *font,
FT_Get_Kerning( font->face, prev_index, glyph->index, ft_kerning_default, &delta );
xstart += delta.x >> 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;
}
Expand Down Expand Up @@ -1587,7 +1595,7 @@ SDL_Surface* TTF_RenderUNICODE_Shaded( TTF_Font* font,
FT_UInt prev_index = 0;

/* Get the dimensions of the text surface */
if( ( TTF_SizeUNICODE(font, text, &width, &height) < 0 ) || !width ) {
if( ( TTF_SizeUNICODE_Internal(font, text, &width, &height, &xstart) < 0 ) || !width ) {
TTF_SetError("Text has zero width");
return NULL;
}
Expand Down Expand Up @@ -1618,7 +1626,6 @@ SDL_Surface* TTF_RenderUNICODE_Shaded( TTF_Font* font,
use_kerning = FT_HAS_KERNING( font->face ) && font->kerning;

/* Load and render each character */
xstart = 0;
swapped = TTF_byteswapped;
for( ch = text; *ch; ++ch ) {
Uint16 c = *ch;
Expand Down Expand Up @@ -1659,13 +1666,10 @@ SDL_Surface* TTF_RenderUNICODE_Shaded( TTF_Font* font,
FT_Get_Kerning( font->face, prev_index, glyph->index, ft_kerning_default, &delta );
xstart += delta.x >> 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;
}
Expand Down Expand Up @@ -1853,7 +1857,7 @@ SDL_Surface *TTF_RenderUNICODE_Blended(TTF_Font *font,
FT_UInt prev_index = 0;

/* Get the dimensions of the text surface */
if ( (TTF_SizeUNICODE(font, text, &width, &height) < 0) || !width ) {
if ( (TTF_SizeUNICODE_Internal(font, text, &width, &height, &xstart) < 0) || !width ) {
TTF_SetError("Text has zero width");
return(NULL);
}
Expand All @@ -1873,7 +1877,6 @@ SDL_Surface *TTF_RenderUNICODE_Blended(TTF_Font *font,
use_kerning = FT_HAS_KERNING( font->face ) && font->kerning;

/* Load and render each character */
xstart = 0;
swapped = TTF_byteswapped;
pixel = (fg.r<<16)|(fg.g<<8)|fg.b;
SDL_FillRect(textbuf, NULL, pixel); /* Initialize with fg and 0 alpha */
Expand Down Expand Up @@ -1916,12 +1919,9 @@ SDL_Surface *TTF_RenderUNICODE_Blended(TTF_Font *font,
FT_Get_Kerning( font->face, prev_index, glyph->index, ft_kerning_default, &delta );
xstart += delta.x >> 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;
}
Expand Down

0 comments on commit 6439a04

Please sign in to comment.