diff options
author | peter1138 <peter1138@openttd.org> | 2011-10-18 17:57:42 +0000 |
---|---|---|
committer | peter1138 <peter1138@openttd.org> | 2011-10-18 17:57:42 +0000 |
commit | f0ef9a09ff125e1dc737d1dd74cefbadbc9918f3 (patch) | |
tree | 79e88063056698775ec6bd727baa3ff896715d1a | |
parent | 7f90fcb5e6411bc5aa3ef2e3d99463d37d4a082b (diff) | |
download | openttd-f0ef9a09ff125e1dc737d1dd74cefbadbc9918f3.tar.xz |
(svn r23038) -Fix: Check that the selected font size is valid the font face in use and choose the nearest size to that selected if not. Font metrics should then just work.
-rw-r--r-- | src/fontcache.cpp | 27 |
1 files changed, 17 insertions, 10 deletions
diff --git a/src/fontcache.cpp b/src/fontcache.cpp index 8b00ab5cc..820287caf 100644 --- a/src/fontcache.cpp +++ b/src/fontcache.cpp @@ -746,18 +746,25 @@ bool SetFallbackFont(FreeTypeSettings *settings, const char *language_isocode, i static void SetFontGeometry(FT_Face face, FontSize size, int pixels) { - FT_Set_Pixel_Sizes(face, 0, pixels); - - if (FT_IS_SCALABLE(face)) { - int asc = face->ascender * pixels / face->units_per_EM; - int dec = face->descender * pixels / face->units_per_EM; + FT_Error err = FT_Set_Pixel_Sizes(face, 0, pixels); + if (err == FT_Err_Invalid_Pixel_Size) { + + /* Find nearest size to that requested */ + FT_Bitmap_Size *bs = face->available_sizes; + int i = face->num_fixed_sizes; + int n = bs->height; + for (; --i; bs++) { + if (abs(pixels - bs->height) < abs(pixels - n)) n = bs->height; + } - _ascender[size] = asc; - _font_height[size] = asc - dec; - } else { - _ascender[size] = pixels; - _font_height[size] = pixels; + FT_Set_Pixel_Sizes(face, 0, n); } + + int asc = face->size->metrics.ascender >> 6; + int dec = face->size->metrics.descender >> 6; + + _ascender[size] = asc; + _font_height[size] = asc - dec; } /** |