1
0
mirror of https://github.com/OpenTTD/OpenTTD.git synced 2025-08-14 18:19:11 +00:00

(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.

This commit is contained in:
2011-10-18 17:57:42 +00:00
parent 7f90fcb5e6
commit f0ef9a09ff

@@ -746,18 +746,25 @@ bool SetFallbackFont(FreeTypeSettings *settings, const char *language_isocode, i
static void SetFontGeometry(FT_Face face, FontSize size, int pixels) static void SetFontGeometry(FT_Face face, FontSize size, int pixels)
{ {
FT_Set_Pixel_Sizes(face, 0, pixels); FT_Error err = FT_Set_Pixel_Sizes(face, 0, pixels);
if (err == FT_Err_Invalid_Pixel_Size) {
if (FT_IS_SCALABLE(face)) { /* Find nearest size to that requested */
int asc = face->ascender * pixels / face->units_per_EM; FT_Bitmap_Size *bs = face->available_sizes;
int dec = face->descender * pixels / face->units_per_EM; int i = face->num_fixed_sizes;
int n = bs->height;
for (; --i; bs++) {
if (abs(pixels - bs->height) < abs(pixels - n)) n = bs->height;
}
FT_Set_Pixel_Sizes(face, 0, n);
}
int asc = face->size->metrics.ascender >> 6;
int dec = face->size->metrics.descender >> 6;
_ascender[size] = asc; _ascender[size] = asc;
_font_height[size] = asc - dec; _font_height[size] = asc - dec;
} else {
_ascender[size] = pixels;
_font_height[size] = pixels;
}
} }
/** /**