From afa3f50b8a2bc47a243156c196f88ab799fe4f8f Mon Sep 17 00:00:00 2001 From: Johannes Schickel Date: Sat, 23 Nov 2013 21:34:54 +0100 Subject: GRAPHICS: Let Font take uint32 as character codes. This is required to support UTF-32 strings but does not make them work automatically! --- graphics/fonts/ttf.cpp | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) (limited to 'graphics/fonts/ttf.cpp') diff --git a/graphics/fonts/ttf.cpp b/graphics/fonts/ttf.cpp index b9e9610d77..f5bd67fe86 100644 --- a/graphics/fonts/ttf.cpp +++ b/graphics/fonts/ttf.cpp @@ -107,11 +107,11 @@ public: virtual int getMaxCharWidth() const; - virtual int getCharWidth(byte chr) const; + virtual int getCharWidth(uint32 chr) const; - virtual int getKerningOffset(byte left, byte right) const; + virtual int getKerningOffset(uint32 left, uint32 right) const; - virtual void drawChar(Surface *dst, byte chr, int x, int y, uint32 color) const; + virtual void drawChar(Surface *dst, uint32 chr, int x, int y, uint32 color) const; private: bool _initialized; FT_Face _face; @@ -129,7 +129,7 @@ private: }; bool cacheGlyph(Glyph &glyph, FT_UInt &slot, uint chr); - typedef Common::HashMap GlyphCache; + typedef Common::HashMap GlyphCache; GlyphCache _glyphs; FT_UInt _glyphSlots[256]; @@ -243,7 +243,7 @@ int TTFFont::getMaxCharWidth() const { return _width; } -int TTFFont::getCharWidth(byte chr) const { +int TTFFont::getCharWidth(uint32 chr) const { GlyphCache::const_iterator glyphEntry = _glyphs.find(chr); if (glyphEntry == _glyphs.end()) return 0; @@ -251,10 +251,14 @@ int TTFFont::getCharWidth(byte chr) const { return glyphEntry->_value.advance; } -int TTFFont::getKerningOffset(byte left, byte right) const { +int TTFFont::getKerningOffset(uint32 left, uint32 right) const { if (!_hasKerning) return 0; + if (left > 255 || right > 255) { + return 0; + } + FT_UInt leftGlyph = _glyphSlots[left]; FT_UInt rightGlyph = _glyphSlots[right]; @@ -304,7 +308,7 @@ void renderGlyph(uint8 *dstPos, const int dstPitch, const uint8 *srcPos, const i } // End of anonymous namespace -void TTFFont::drawChar(Surface *dst, byte chr, int x, int y, uint32 color) const { +void TTFFont::drawChar(Surface *dst, uint32 chr, int x, int y, uint32 color) const { GlyphCache::const_iterator glyphEntry = _glyphs.find(chr); if (glyphEntry == _glyphs.end()) return; -- cgit v1.2.3