diff --git a/src/fontcache.cpp b/src/fontcache.cpp index 6bea59c103..4a43592edd 100644 --- a/src/fontcache.cpp +++ b/src/fontcache.cpp @@ -43,6 +43,7 @@ FontCache::FontCache(FontSize fs) : parent(FontCache::Get(fs)), fs(fs), height(_ { assert(parent == NULL || this->fs == parent->fs); FontCache::caches[this->fs] = this; + font_height_cache[this->fs] = this->height; Layouter::ResetFontCache(this->fs); } @@ -54,18 +55,6 @@ FontCache::~FontCache() Layouter::ResetFontCache(this->fs); } - -/** - * Get height of a character for a given font size. - * @param size Font size to get height of - * @return Height of characters in the given font (pixels) - */ -int GetCharacterHeight(FontSize size) -{ - return FontCache::Get(size)->GetHeight(); -} - - /** Font cache for fonts that are based on a freetype font. */ class SpriteFontCache : public FontCache { private: @@ -151,6 +140,7 @@ void SpriteFontCache::InitializeUnicodeGlyphMap() this->SetUnicodeGlyph(_default_unicode_map[i].code, sprite); } } + font_height_cache[this->fs] = this->GetHeight(); } /** @@ -197,6 +187,7 @@ bool SpriteFontCache::GetDrawGlyphShadow() } /* static */ FontCache *FontCache::caches[FS_END] = { new SpriteFontCache(FS_NORMAL), new SpriteFontCache(FS_SMALL), new SpriteFontCache(FS_LARGE), new SpriteFontCache(FS_MONO) }; +int font_height_cache[FS_END]; #ifdef WITH_FREETYPE #include @@ -312,6 +303,8 @@ FreeTypeFontCache::FreeTypeFontCache(FontSize fs, FT_Face face, int pixels) : Fo /* Both FT_Set_Pixel_Sizes and FT_Select_Size failed. */ DEBUG(freetype, 0, "Font size selection failed. Using FontCache defaults."); } + + font_height_cache[this->fs] = this->GetHeight(); } /** diff --git a/src/fontcache.h b/src/fontcache.h index 8caf4f1bd3..2cb7efea5a 100644 --- a/src/fontcache.h +++ b/src/fontcache.h @@ -19,6 +19,8 @@ typedef uint32 GlyphID; static const GlyphID SPRITE_GLYPH = 1U << 30; +extern int font_height_cache[FS_END]; ///< Cache of font heights + /** Font cache for basic fonts. */ class FontCache { private: diff --git a/src/gfx_func.h b/src/gfx_func.h index 6576dee4fb..4162ad370a 100644 --- a/src/gfx_func.h +++ b/src/gfx_func.h @@ -158,7 +158,17 @@ byte GetCharacterWidth(FontSize size, uint32 key); byte GetDigitWidth(FontSize size = FS_NORMAL); void GetBroadestDigit(uint *front, uint *next, FontSize size = FS_NORMAL); -int GetCharacterHeight(FontSize size); +extern int font_height_cache[FS_END]; + +/** + * Get height of a character for a given font size. + * @param size Font size to get height of + * @return Height of characters in the given font (pixels) + */ +inline int GetCharacterHeight(FontSize size) +{ + return font_height_cache[size]; +} /** Height of characters in the small (#FS_SMALL) font. */ #define FONT_HEIGHT_SMALL (GetCharacterHeight(FS_SMALL))