GRAPHICS: Let Font take uint32 as character codes.
This is required to support UTF-32 strings but does not make them work automatically!
This commit is contained in:
parent
b90400da44
commit
afa3f50b8a
9 changed files with 33 additions and 29 deletions
|
@ -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];
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -26,7 +26,7 @@
|
|||
|
||||
namespace Graphics {
|
||||
|
||||
int Font::getKerningOffset(byte left, byte right) const {
|
||||
int Font::getKerningOffset(uint32 left, uint32 right) const {
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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<byte, Glyph> GlyphCache;
|
||||
typedef Common::HashMap<uint32, Glyph> 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;
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue