Changeset - r20454:35a010f0c655
[Not reviewed]
master
0 2 0
rubidium - 11 years ago 2013-06-25 20:39:58
rubidium@openttd.org
(svn r25469) -Add: method for getting the font tables from freetype fonts
2 files changed with 36 insertions and 3 deletions:
0 comments (0 inline, 0 general)
src/fontcache.cpp
Show inline comments
 
@@ -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::ClearGlyphToSprite
 
	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 FontCac
 
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::MapCharToGlyp
 
	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 */
 

	
 
/**
src/fontcache.h
Show inline comments
 
@@ -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.
0 comments (0 inline, 0 general)