Skip to content

Commit

Permalink
Fixed bug 1088 (Broken cache of glyphs [patch])
Browse files Browse the repository at this point in the history
 Peter Kosyh      2011-01-11 22:38:59 PST

It's like that cache of glyphs works only with symbols with codes <= 255.

It is too bad, because leads to very high cpu load on slow machines. Here is a
tiny patch, that makes cache more clever and speed up non english languages
rendering about 50 times in my project (build wince, s60, android).
  • Loading branch information
slouken committed Feb 28, 2011
1 parent 3b73ec9 commit 5ef6d84
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 14 deletions.
2 changes: 2 additions & 0 deletions CHANGES
@@ -1,4 +1,6 @@
2.0.11:
Peter Kosyh - Mon Feb 28 14:57:03 PST 2011
* Improved font glyph caching for non-latin languages
Erik Snoek - Wed Jan 12 09:10:15 PST 2011
* Added API to get kerning info: TTF_GetFontKerningSize()

Expand Down
22 changes: 8 additions & 14 deletions SDL_ttf.c
Expand Up @@ -107,8 +107,7 @@ struct _TTF_Font {

/* Cache for style-transformed glyphs */
c_glyph *current;
c_glyph cache[256];
c_glyph scratch;
c_glyph cache[257]; /* 257 is a prime */

/* We are responsible for closing the font stream */
SDL_RWops *src;
Expand Down Expand Up @@ -574,10 +573,6 @@ static void Flush_Cache( TTF_Font* font )
}

}
if( font->scratch.cached ) {
Flush_Glyph( &font->scratch );
}

}

static FT_Error Load_Glyph( TTF_Font* font, Uint16 ch, c_glyph* cached, int want )
Expand Down Expand Up @@ -897,15 +892,14 @@ static FT_Error Load_Glyph( TTF_Font* font, Uint16 ch, c_glyph* cached, int want
static FT_Error Find_Glyph( TTF_Font* font, Uint16 ch, int want )
{
int retval = 0;
int hsize = sizeof( font->cache ) / sizeof( font->cache[0] );

int h = ch % hsize;
font->current = &font->cache[h];

if (font->current->cached != ch)
Flush_Glyph( font->current );

if( ch < 256 ) {
font->current = &font->cache[ch];
} else {
if ( font->scratch.cached != ch ) {
Flush_Glyph( &font->scratch );
}
font->current = &font->scratch;
}
if ( (font->current->stored & want) != want ) {
retval = Load_Glyph( font, ch, font->current, want );
}
Expand Down

0 comments on commit 5ef6d84

Please sign in to comment.