Changeset - r13564:81d26c235297
[Not reviewed]
master
0 1 0
peter1138 - 15 years ago 2009-11-15 14:39:37
peter1138@openttd.org
(svn r18096) -Fix (r5079/r7158??): Use free type ascender/descender metrics to position font offset correctly.
1 file changed with 21 insertions and 10 deletions:
0 comments (0 inline, 0 general)
src/fontcache.cpp
Show inline comments
 
@@ -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 *f
 
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, WC
 
	int height;
 
	int x;
 
	int y;
 
	int y_adj;
 

	
 
	assert(IsPrintable(key));
 

	
 
@@ -968,9 +981,7 @@ const Sprite *GetGlyph(FontSize size, WC
 
	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) {
0 comments (0 inline, 0 general)