diff options
author | fonsinchen <fonsinchen@openttd.org> | 2014-03-03 21:34:36 +0000 |
---|---|---|
committer | fonsinchen <fonsinchen@openttd.org> | 2014-03-03 21:34:36 +0000 |
commit | b816e077423880d49ecea74fa2df57db4655c3ee (patch) | |
tree | 17ea68032f2772bf5fb248acd437dba38c6d8400 | |
parent | 6b61c4608fab00c7bfc78c296b3c85f611681f59 (diff) | |
download | openttd-b816e077423880d49ecea74fa2df57db4655c3ee.tar.xz |
(svn r26389) -Fix [FS#5885]: Select a specific font size when freetype fails to select one automatically.
-rw-r--r-- | src/fontcache.cpp | 32 |
1 files changed, 22 insertions, 10 deletions
diff --git a/src/fontcache.cpp b/src/fontcache.cpp index 50fbe0d6a..4d369ad51 100644 --- a/src/fontcache.cpp +++ b/src/fontcache.cpp @@ -274,23 +274,35 @@ FreeTypeFontCache::FreeTypeFontCache(FontSize fs, FT_Face face, int pixels) : Fo } FT_Error err = FT_Set_Pixel_Sizes(this->face, 0, pixels); - if (err == FT_Err_Invalid_Pixel_Size) { + if (err != FT_Err_Ok) { /* Find nearest size to that requested */ FT_Bitmap_Size *bs = this->face->available_sizes; int i = this->face->num_fixed_sizes; - int n = bs->height; - for (; --i; bs++) { - if (abs(pixels - bs->height) < abs(pixels - n)) n = bs->height; - } + if (i > 0) { // In pathetic cases one might get no fixed sizes at all. + int n = bs->height; + FT_Int chosen = 0; + for (; --i; bs++) { + if (abs(pixels - bs->height) >= abs(pixels - n)) continue; + n = bs->height; + chosen = this->face->num_fixed_sizes - i; + } - FT_Set_Pixel_Sizes(this->face, 0, n); + /* Don't use FT_Set_Pixel_Sizes here - it might give us another + * error, even though the size is available (FS#5885). */ + err = FT_Select_Size(this->face, chosen); + } } - this->units_per_em = this->face->units_per_EM; - this->ascender = this->face->size->metrics.ascender >> 6; - this->descender = this->face->size->metrics.descender >> 6; - this->height = this->ascender - this->descender; + if (err == FT_Err_Ok) { + this->units_per_em = this->face->units_per_EM; + this->ascender = this->face->size->metrics.ascender >> 6; + this->descender = this->face->size->metrics.descender >> 6; + this->height = this->ascender - this->descender; + } else { + /* Both FT_Set_Pixel_Sizes and FT_Select_Size failed. */ + DEBUG(freetype, 0, "Font size selection failed. Using FontCache defaults."); + } } /** |