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! --- engines/groovie/font.cpp | 4 ++-- engines/groovie/font.h | 6 +++--- graphics/font.cpp | 2 +- graphics/font.h | 6 +++--- graphics/fonts/bdf.cpp | 8 ++++---- graphics/fonts/bdf.h | 6 +++--- graphics/fonts/ttf.cpp | 18 +++++++++++------- graphics/fonts/winfont.cpp | 6 +++--- graphics/fonts/winfont.h | 6 +++--- 9 files changed, 33 insertions(+), 29 deletions(-) diff --git a/engines/groovie/font.cpp b/engines/groovie/font.cpp index d29c22dd02..a55d8fad95 100644 --- a/engines/groovie/font.cpp +++ b/engines/groovie/font.cpp @@ -112,7 +112,7 @@ bool T7GFont::load(Common::SeekableReadStream &stream) { return true; } -void T7GFont::drawChar(Graphics::Surface *dst, byte chr, int x, int y, uint32 color) const { +void T7GFont::drawChar(Graphics::Surface *dst, uint32 chr, int x, int y, uint32 color) const { // We ignore the color, as the font is already colored const Glyph *glyph = getGlyph(chr); const byte *src = glyph->pixels; @@ -125,7 +125,7 @@ void T7GFont::drawChar(Graphics::Surface *dst, byte chr, int x, int y, uint32 co } } -const T7GFont::Glyph *T7GFont::getGlyph(byte chr) const { +const T7GFont::Glyph *T7GFont::getGlyph(uint32 chr) const { assert (chr < 128); byte numGlyph = _mapChar2Glyph[chr]; diff --git a/engines/groovie/font.h b/engines/groovie/font.h index 20aaa4cf23..49cf4b7b06 100644 --- a/engines/groovie/font.h +++ b/engines/groovie/font.h @@ -37,8 +37,8 @@ public: int getFontHeight() const { return _maxHeight; } int getMaxCharWidth() const { return _maxWidth; } - int getCharWidth(byte chr) const { return getGlyph(chr)->width; } - void drawChar(Graphics::Surface *dst, byte chr, int x, int y, uint32 color) const; + int getCharWidth(uint32 chr) const { return getGlyph(chr)->width; } + void drawChar(Graphics::Surface *dst, uint32 chr, int x, int y, uint32 color) const; private: int _maxHeight, _maxWidth; @@ -55,7 +55,7 @@ private: byte _mapChar2Glyph[128]; Glyph *_glyphs; - const Glyph *getGlyph(byte chr) const; + const Glyph *getGlyph(uint32 chr) const; }; } // End of Groovie namespace diff --git a/graphics/font.cpp b/graphics/font.cpp index a852274b06..519d63a393 100644 --- a/graphics/font.cpp +++ b/graphics/font.cpp @@ -26,7 +26,7 @@ namespace Graphics { -int Font::getKerningOffset(byte left, byte right) const { +int Font::getKerningOffset(uint32 left, uint32 right) const { return 0; } diff --git a/graphics/font.h b/graphics/font.h index 6819b42f52..62538e3e59 100644 --- a/graphics/font.h +++ b/graphics/font.h @@ -70,7 +70,7 @@ public: * @param chr The character to query the width of. * @return The character's width. */ - virtual int getCharWidth(byte chr) const = 0; + virtual int getCharWidth(uint32 chr) const = 0; /** * Query the kerning offset between two characters. @@ -79,7 +79,7 @@ public: * @param right The right character. May be 0. * @return The horizontal displacement. */ - virtual int getKerningOffset(byte left, byte right) const; + virtual int getKerningOffset(uint32 left, uint32 right) const; /** * Draw a character at a specific point on a surface. @@ -96,7 +96,7 @@ public: * @param y The y coordinate where to draw the character. * @param color The color of the character. */ - virtual void drawChar(Surface *dst, byte chr, int x, int y, uint32 color) const = 0; + virtual void drawChar(Surface *dst, uint32 chr, int x, int y, uint32 color) const = 0; // TODO: Add doxygen comments to this void drawString(Surface *dst, const Common::String &str, int x, int y, int w, uint32 color, TextAlign align = kTextAlignLeft, int deltax = 0, bool useEllipsis = true) const; diff --git a/graphics/fonts/bdf.cpp b/graphics/fonts/bdf.cpp index e523a36ad5..7b2290cc3a 100644 --- a/graphics/fonts/bdf.cpp +++ b/graphics/fonts/bdf.cpp @@ -51,7 +51,7 @@ int BdfFont::getMaxCharWidth() const { return _data.maxAdvance; } -int BdfFont::getCharWidth(byte chr) const { +int BdfFont::getCharWidth(uint32 chr) const { // In case all font have the same advance value, we use the maximum. if (!_data.advances) return _data.maxAdvance; @@ -85,9 +85,9 @@ void drawCharIntern(byte *ptr, uint pitch, const byte *src, int h, int width, in } } -int BdfFont::mapToIndex(byte ch) const { +int BdfFont::mapToIndex(uint32 ch) const { // Check whether the character is included - if (_data.firstCharacter <= ch && ch <= _data.firstCharacter + _data.numCharacters) { + if (_data.firstCharacter <= (int)ch && (int)ch <= _data.firstCharacter + _data.numCharacters) { if (_data.bitmaps[ch - _data.firstCharacter]) return ch - _data.firstCharacter; } @@ -95,7 +95,7 @@ int BdfFont::mapToIndex(byte ch) const { return _data.defaultCharacter - _data.firstCharacter; } -void BdfFont::drawChar(Surface *dst, byte chr, const int tx, const int ty, const uint32 color) const { +void BdfFont::drawChar(Surface *dst, uint32 chr, const int tx, const int ty, const uint32 color) const { assert(dst != 0); // TODO: Where is the relation between the max advance being smaller or diff --git a/graphics/fonts/bdf.h b/graphics/fonts/bdf.h index b0166a2095..842e54f851 100644 --- a/graphics/fonts/bdf.h +++ b/graphics/fonts/bdf.h @@ -61,14 +61,14 @@ public: virtual int getFontHeight() const; virtual int getMaxCharWidth() const; - virtual int getCharWidth(byte chr) const; - virtual void drawChar(Surface *dst, byte chr, int x, int y, uint32 color) const; + virtual int getCharWidth(uint32 chr) const; + virtual void drawChar(Surface *dst, uint32 chr, int x, int y, uint32 color) const; static BdfFont *loadFont(Common::SeekableReadStream &stream); static bool cacheFontData(const BdfFont &font, const Common::String &filename); static BdfFont *loadFromCache(Common::SeekableReadStream &stream); private: - int mapToIndex(byte ch) const; + int mapToIndex(uint32 ch) const; const BdfFontData _data; const DisposeAfterUse::Flag _dispose; 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; diff --git a/graphics/fonts/winfont.cpp b/graphics/fonts/winfont.cpp index 3bad92236d..c0ebab19ba 100644 --- a/graphics/fonts/winfont.cpp +++ b/graphics/fonts/winfont.cpp @@ -200,7 +200,7 @@ char WinFont::indexToCharacter(uint16 index) const { return index + _firstChar; } -uint16 WinFont::characterToIndex(byte character) const { +uint16 WinFont::characterToIndex(uint32 character) const { // Go to the default character if we didn't find a mapping if (character < _firstChar || character > _lastChar) character = _defaultChar; @@ -208,7 +208,7 @@ uint16 WinFont::characterToIndex(byte character) const { return character - _firstChar; } -int WinFont::getCharWidth(byte chr) const { +int WinFont::getCharWidth(uint32 chr) const { return _glyphs[characterToIndex(chr)].charWidth; } @@ -324,7 +324,7 @@ bool WinFont::loadFromFNT(Common::SeekableReadStream &stream) { return true; } -void WinFont::drawChar(Surface *dst, byte chr, int x, int y, uint32 color) const { +void WinFont::drawChar(Surface *dst, uint32 chr, int x, int y, uint32 color) const { assert(dst); assert(dst->format.bytesPerPixel == 1 || dst->format.bytesPerPixel == 2 || dst->format.bytesPerPixel == 4); assert(_glyphs); diff --git a/graphics/fonts/winfont.h b/graphics/fonts/winfont.h index 4382d7ed6b..2c7ba07b41 100644 --- a/graphics/fonts/winfont.h +++ b/graphics/fonts/winfont.h @@ -62,8 +62,8 @@ public: // Font API int getFontHeight() const { return _pixHeight; } int getMaxCharWidth() const { return _maxWidth; } - int getCharWidth(byte chr) const; - void drawChar(Surface *dst, byte chr, int x, int y, uint32 color) const; + int getCharWidth(uint32 chr) const; + void drawChar(Surface *dst, uint32 chr, int x, int y, uint32 color) const; private: bool loadFromPE(const Common::String &fileName, const WinFontDirEntry &dirEntry); @@ -72,7 +72,7 @@ private: uint32 getFontIndex(Common::SeekableReadStream &stream, const WinFontDirEntry &dirEntry); bool loadFromFNT(Common::SeekableReadStream &stream); char indexToCharacter(uint16 index) const; - uint16 characterToIndex(byte character) const; + uint16 characterToIndex(uint32 character) const; uint16 _pixHeight; uint16 _maxWidth; -- cgit v1.2.3