mirror of https://github.com/OpenTTD/OpenTTD
(svn r18096) -Fix (r5079/r7158??): Use free type ascender/descender metrics to position font offset correctly.
parent
f6ec2fa5b9
commit
f28d32943d
|
@ -36,6 +36,7 @@ static FT_Library _library = NULL;
|
|||
static FT_Face _face_small = NULL;
|
||||
static FT_Face _face_medium = NULL;
|
||||
static FT_Face _face_large = NULL;
|
||||
static int _ascender[FS_END];
|
||||
|
||||
FreeTypeSettings _freetype;
|
||||
|
||||
|
@ -707,6 +708,22 @@ FT_Error GetFontByFaceName(const char *font_name, FT_Face *face) {return FT_Err_
|
|||
bool SetFallbackFont(FreeTypeSettings *settings, const char *language_isocode, int winlangid, const char *str) { return false; }
|
||||
#endif /* WITH_FONTCONFIG */
|
||||
|
||||
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;
|
||||
|
||||
_ascender[size] = asc;
|
||||
_font_height[size] = asc - dec;
|
||||
} else {
|
||||
_ascender[size] = pixels;
|
||||
_font_height[size] = pixels;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Loads the freetype font.
|
||||
* First type to load the fontname as if it were a path. If that fails,
|
||||
|
@ -781,16 +798,13 @@ void InitFreeType()
|
|||
|
||||
/* Set each font size */
|
||||
if (_face_small != NULL) {
|
||||
FT_Set_Pixel_Sizes(_face_small, 0, _freetype.small_size);
|
||||
_font_height[FS_SMALL] = _freetype.small_size;
|
||||
SetFontGeometry(_face_small, FS_SMALL, _freetype.small_size);
|
||||
}
|
||||
if (_face_medium != NULL) {
|
||||
FT_Set_Pixel_Sizes(_face_medium, 0, _freetype.medium_size);
|
||||
_font_height[FS_NORMAL] = _freetype.medium_size;
|
||||
SetFontGeometry(_face_medium, FS_NORMAL, _freetype.medium_size);
|
||||
}
|
||||
if (_face_large != NULL) {
|
||||
FT_Set_Pixel_Sizes(_face_large, 0, _freetype.large_size);
|
||||
_font_height[FS_LARGE] = _freetype.large_size;
|
||||
SetFontGeometry(_face_large, FS_LARGE, _freetype.large_size);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -934,7 +948,6 @@ const Sprite *GetGlyph(FontSize size, WChar key)
|
|||
int height;
|
||||
int x;
|
||||
int y;
|
||||
int y_adj;
|
||||
|
||||
assert(IsPrintable(key));
|
||||
|
||||
|
@ -968,9 +981,7 @@ const Sprite *GetGlyph(FontSize size, WChar key)
|
|||
sprite.width = width;
|
||||
sprite.height = height;
|
||||
sprite.x_offs = slot->bitmap_left;
|
||||
/* XXX 2 should be determined somehow... it's right for the normal face */
|
||||
y_adj = (size == FS_NORMAL) ? 2 : 0;
|
||||
sprite.y_offs = GetCharacterHeight(size) - slot->bitmap_top - y_adj;
|
||||
sprite.y_offs = _ascender[size] - slot->bitmap_top;
|
||||
|
||||
/* Draw shadow for medium size */
|
||||
if (size == FS_NORMAL) {
|
||||
|
|
Loading…
Reference in New Issue