summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorrubidium <rubidium@openttd.org>2013-06-25 20:39:58 +0000
committerrubidium <rubidium@openttd.org>2013-06-25 20:39:58 +0000
commit7b10e39bf104e9983548ee1b6d94e9dbb57fdb27 (patch)
treecfd5dc61fe35cb3b29819ca3b56f133a40965cd2 /src
parentc90dbe20186059eb20574cab442f792b449d16ba (diff)
downloadopenttd-7b10e39bf104e9983548ee1b6d94e9dbb57fdb27.tar.xz
(svn r25469) -Add: method for getting the font tables from freetype fonts
Diffstat (limited to 'src')
-rw-r--r--src/fontcache.cpp32
-rw-r--r--src/fontcache.h7
2 files changed, 36 insertions, 3 deletions
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<uint32, const void*> 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<uint32, const void *> *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<uint32, const void *> *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<FT_Byte>(len);
+ FT_Load_Sfnt_Table(this->face, tag, 0, result, &len);
+ }
+
+ this->font_tables.Insert(tag, result);
+ return result;
+}
+
#endif /* WITH_FREETYPE */
/**
diff --git a/src/fontcache.h b/src/fontcache.h
index a910ac0e4..6e4d18b3b 100644
--- a/src/fontcache.h
+++ b/src/fontcache.h
@@ -112,6 +112,13 @@ public:
virtual GlyphID MapCharToGlyph(WChar key) = 0;
/**
+ * Read a font table from the font.
+ * @param tag The of the table to load.
+ * @return The loaded table data.
+ */
+ virtual const void *GetFontTable(uint32 tag) = 0;
+
+ /**
* Get the font cache of a given font size.
* @param fs The font size to look up.
* @return The font cache.