Changeset - r20448:799c881fb514
[Not reviewed]
master
0 2 0
rubidium - 11 years ago 2013-06-25 20:21:21
rubidium@openttd.org
(svn r25463) -Codechange: export more size related information from the fonts
2 files changed with 38 insertions and 9 deletions:
0 comments (0 inline, 0 general)
src/fontcache.cpp
Show inline comments
 
@@ -25,13 +25,16 @@ static const int ASCII_LETTERSTART = 32;
 
static const int MAX_FONT_SIZE     = 72; ///< Maximum font size.
 

	
 
/** Default heights for the different sizes of fonts. */
 
static const int _default_font_height[FS_END] = {10, 6, 18, 10};
 
static const int _default_font_height[FS_END]   = {10, 6, 18, 10};
 
static const int _default_font_ascender[FS_END] = { 8, 5, 15,  8};
 

	
 
/**
 
 * Create a new font cache.
 
 * @param fs The size of the font.
 
 */
 
FontCache::FontCache(FontSize fs) : parent(FontCache::Get(fs)), fs(fs), height(_default_font_height[fs])
 
FontCache::FontCache(FontSize fs) : parent(FontCache::Get(fs)), fs(fs), height(_default_font_height[fs]),
 
		ascender(_default_font_ascender[fs]), descender(_default_font_ascender[fs] - _default_font_height[fs]),
 
		units_per_em(1)
 
{
 
	assert(parent == NULL || this->fs == parent->fs);
 
	FontCache::caches[this->fs] = this;
 
@@ -187,8 +190,6 @@ bool SpriteFontCache::GetDrawGlyphShadow
 
class FreeTypeFontCache : public FontCache {
 
private:
 
	FT_Face face;  ///< The font face associated with this font.
 
	int ascender;  ///< The ascender value of this font.
 
	int descender; ///< The descender value of this font.
 

	
 
	/** Container for information about a glyph. */
 
	struct GlyphEntry {
 
@@ -272,9 +273,10 @@ FreeTypeFontCache::FreeTypeFontCache(Fon
 
		FT_Set_Pixel_Sizes(this->face, 0, n);
 
	}
 

	
 
	this->ascender  = this->face->size->metrics.ascender >> 6;
 
	this->descender = this->face->size->metrics.descender >> 6;
 
	this->height    = this->ascender - this->descender;
 
	this->units_per_em = this->face->units_per_EM;
 
	this->ascender     = this->face->size->metrics.ascender >> 6;
 
	this->descender    = this->face->size->metrics.descender >> 6;
 
	this->height       = this->ascender - this->descender;
 
}
 

	
 
/**
src/fontcache.h
Show inline comments
 
@@ -26,16 +26,43 @@ private:
 
protected:
 
	FontCache *parent;                ///< The parent of this font cache.
 
	const FontSize fs;                ///< The size of the font.
 
	int height;                       ///< The height of the font;
 
	int height;                       ///< The height of the font.
 
	int ascender;                     ///< The ascender value of the font.
 
	int descender;                    ///< The descender value of the font.
 
	int units_per_em;                 ///< The units per EM value of the font.
 
public:
 
	FontCache(FontSize fs);
 
	virtual ~FontCache();
 

	
 
	/**
 
	 * Get the FontSize of the font.
 
	 * @return The FontSize.
 
	 */
 
	inline FontSize GetSize() const { return this->fs; }
 

	
 
	/**
 
	 * Get the height of the font.
 
	 * @return The height of the font.
 
	 */
 
	inline int GetHeight() { return this->height; }
 
	inline int GetHeight() const { return this->height; }
 

	
 
	/**
 
	 * Get the ascender value of the font.
 
	 * @return The ascender value of the font.
 
	 */
 
	inline int GetAscender() const { return this->ascender; }
 

	
 
	/**
 
	 * Get the descender value of the font.
 
	 * @return The descender value of the font.
 
	 */
 
	inline int GetDescender() const{ return this->descender; }
 

	
 
	/**
 
	 * Get the units per EM value of the font.
 
	 * @return The units per EM value of the font.
 
	 */
 
	inline int GetUnitsPerEM() const { return this->units_per_em; }
 

	
 
	/**
 
	 * Get the SpriteID mapped to the given key
0 comments (0 inline, 0 general)