From 7b10e39bf104e9983548ee1b6d94e9dbb57fdb27 Mon Sep 17 00:00:00 2001 From: rubidium Date: Tue, 25 Jun 2013 20:39:58 +0000 Subject: (svn r25469) -Add: method for getting the font tables from freetype fonts --- src/fontcache.cpp | 32 +++++++++++++++++++++++++++++--- 1 file changed, 29 insertions(+), 3 deletions(-) (limited to 'src/fontcache.cpp') diff --git a/src/fontcache.cpp b/src/fontcache.cpp index 9e3ab2925..a8dd71c75 100644 --- a/src/fontcache.cpp +++ b/src/fontcache.cpp @@ -14,6 +14,7 @@ #include "fontdetection.h" #include "blitter/factory.hpp" #include "core/math_func.hpp" +#include "core/smallmap_type.hpp" #include "strings_func.h" #include "zoom_type.h" @@ -71,11 +72,12 @@ public: virtual SpriteID GetUnicodeGlyph(WChar key); virtual void SetUnicodeGlyph(WChar key, SpriteID sprite); virtual void InitializeUnicodeGlyphMap(); - virtual void ClearFontCache(); + virtual void ClearFontCache() {} virtual const Sprite *GetGlyph(GlyphID key); virtual uint GetGlyphWidth(GlyphID key); virtual bool GetDrawGlyphShadow(); virtual GlyphID MapCharToGlyph(WChar key) { return SPRITE_GLYPH | key; } + virtual const void *GetFontTable(uint32 tag) { return NULL; } }; /** @@ -157,8 +159,6 @@ void SpriteFontCache::ClearGlyphToSpriteMap() this->glyph_to_spriteid_map = NULL; } -void SpriteFontCache::ClearFontCache() {} - const Sprite *SpriteFontCache::GetGlyph(GlyphID key) { SpriteID sprite = this->GetUnicodeGlyph(key); @@ -191,6 +191,8 @@ class FreeTypeFontCache : public FontCache { private: FT_Face face; ///< The font face associated with this font. + SmallMap font_tables; ///< Cached font tables. + /** Container for information about a glyph. */ struct GlyphEntry { Sprite *sprite; ///< The loaded sprite. @@ -227,6 +229,7 @@ public: virtual uint GetGlyphWidth(GlyphID key); virtual bool GetDrawGlyphShadow(); virtual GlyphID MapCharToGlyph(WChar key); + virtual const void *GetFontTable(uint32 tag); }; FT_Library _library = NULL; @@ -359,6 +362,10 @@ FreeTypeFontCache::~FreeTypeFontCache() { FT_Done_Face(this->face); this->ClearFontCache(); + + for (SmallPair *iter = this->font_tables.Begin(); iter != this->font_tables.End(); iter++) { + free(iter->second); + } } /** @@ -545,6 +552,25 @@ GlyphID FreeTypeFontCache::MapCharToGlyph(WChar key) return FT_Get_Char_Index(this->face, key); } +const void *FreeTypeFontCache::GetFontTable(uint32 tag) +{ + const SmallPair *iter = this->font_tables.Find(tag); + if (iter != this->font_tables.End()) return iter->second; + + FT_ULong len = 0; + FT_Byte *result = NULL; + + FT_Load_Sfnt_Table(this->face, tag, 0, NULL, &len); + + if (len > 0) { + result = MallocT(len); + FT_Load_Sfnt_Table(this->face, tag, 0, result, &len); + } + + this->font_tables.Insert(tag, result); + return result; +} + #endif /* WITH_FREETYPE */ /** -- cgit v1.2.3-70-g09d2