summaryrefslogtreecommitdiff
path: root/src/fontcache.h
diff options
context:
space:
mode:
authorrubidium <rubidium@openttd.org>2013-06-25 20:20:15 +0000
committerrubidium <rubidium@openttd.org>2013-06-25 20:20:15 +0000
commit092c33be3ff9541074c41b1a5af82095461906ff (patch)
tree21ebd06e10be1c5dbbddef0516b1295689862682 /src/fontcache.h
parentb4106e686b113ee1fa704b1bf7a10be179cf4fcc (diff)
downloadopenttd-092c33be3ff9541074c41b1a5af82095461906ff.tar.xz
(svn r25462) -Codechange: make a better distinction between characters and glyphs
Diffstat (limited to 'src/fontcache.h')
-rw-r--r--src/fontcache.h34
1 files changed, 24 insertions, 10 deletions
diff --git a/src/fontcache.h b/src/fontcache.h
index df425886f..91e695640 100644
--- a/src/fontcache.h
+++ b/src/fontcache.h
@@ -12,8 +12,13 @@
#ifndef FONTCACHE_H
#define FONTCACHE_H
+#include "string_type.h"
#include "spritecache.h"
+/** Glyphs are characters from a font. */
+typedef uint32 GlyphID;
+static const GlyphID SPRITE_GLYPH = 1U << 30;
+
/** Font cache for basic fonts. */
class FontCache {
private:
@@ -37,14 +42,14 @@ public:
* @param key The key to get the sprite for.
* @return The sprite.
*/
- virtual SpriteID GetUnicodeGlyph(uint32 key) = 0;
+ virtual SpriteID GetUnicodeGlyph(WChar key) = 0;
/**
* Map a SpriteID to the key
* @param key The key to map to.
* @param sprite The sprite that is being mapped.
*/
- virtual void SetUnicodeGlyph(uint32 key, SpriteID sprite) = 0;
+ virtual void SetUnicodeGlyph(WChar key, SpriteID sprite) = 0;
/** Initialize the glyph map */
virtual void InitializeUnicodeGlyphMap() = 0;
@@ -57,14 +62,14 @@ public:
* @param key The key to look up.
* @return The sprite.
*/
- virtual const Sprite *GetGlyph(uint32 key) = 0;
+ virtual const Sprite *GetGlyph(GlyphID key) = 0;
/**
* Get the width of the glyph with the given key.
* @param key The key to look up.
* @return The width.
*/
- virtual uint GetGlyphWidth(uint32 key) = 0;
+ virtual uint GetGlyphWidth(GlyphID key) = 0;
/**
* Do we need to draw a glyph shadow?
@@ -73,6 +78,13 @@ public:
virtual bool GetDrawGlyphShadow() = 0;
/**
+ * Map a character into a glyph.
+ * @param key The character.
+ * @return The glyph ID used to draw the character.
+ */
+ virtual GlyphID MapCharToGlyph(WChar key) = 0;
+
+ /**
* Get the font cache of a given font size.
* @param fs The font size to look up.
* @return The font cache.
@@ -93,13 +105,13 @@ public:
};
/** Get the SpriteID mapped to the given font size and key */
-static inline SpriteID GetUnicodeGlyph(FontSize size, uint32 key)
+static inline SpriteID GetUnicodeGlyph(FontSize size, WChar key)
{
return FontCache::Get(size)->GetUnicodeGlyph(key);
}
/** Map a SpriteID to the font size and key */
-static inline void SetUnicodeGlyph(FontSize size, uint32 key, SpriteID sprite)
+static inline void SetUnicodeGlyph(FontSize size, WChar key, SpriteID sprite)
{
FontCache::Get(size)->SetUnicodeGlyph(key, sprite);
}
@@ -119,15 +131,17 @@ static inline void ClearFontCache() {
}
/** Get the Sprite for a glyph */
-static inline const Sprite *GetGlyph(FontSize size, uint32 key)
+static inline const Sprite *GetGlyph(FontSize size, WChar key)
{
- return FontCache::Get(size)->GetGlyph(key);
+ FontCache *fc = FontCache::Get(size);
+ return fc->GetGlyph(fc->MapCharToGlyph(key));
}
/** Get the width of a glyph */
-static inline uint GetGlyphWidth(FontSize size, uint32 key)
+static inline uint GetGlyphWidth(FontSize size, WChar key)
{
- return FontCache::Get(size)->GetGlyphWidth(key);
+ FontCache *fc = FontCache::Get(size);
+ return fc->GetGlyphWidth(fc->MapCharToGlyph(key));
}
static inline bool GetDrawGlyphShadow(FontSize size)