aboutsummaryrefslogtreecommitdiff
path: root/graphics
diff options
context:
space:
mode:
authorJohannes Schickel2013-11-23 21:34:54 +0100
committerJohannes Schickel2013-11-23 21:34:54 +0100
commit13d470dc61049f231a5ed5a71ce8af111612aba2 (patch)
treee63a9c6e1e0dcb43492ba4529b9bdc6e611a5ee6 /graphics
parentafa3f50b8a2bc47a243156c196f88ab799fe4f8f (diff)
downloadscummvm-rg350-13d470dc61049f231a5ed5a71ce8af111612aba2.tar.gz
scummvm-rg350-13d470dc61049f231a5ed5a71ce8af111612aba2.tar.bz2
scummvm-rg350-13d470dc61049f231a5ed5a71ce8af111612aba2.zip
GRAPHICS: Get rid of _glyphSlots in TTFFont.
Diffstat (limited to 'graphics')
-rw-r--r--graphics/fonts/ttf.cpp39
1 files changed, 26 insertions, 13 deletions
diff --git a/graphics/fonts/ttf.cpp b/graphics/fonts/ttf.cpp
index f5bd67fe86..7c48bdf99b 100644
--- a/graphics/fonts/ttf.cpp
+++ b/graphics/fonts/ttf.cpp
@@ -126,21 +126,20 @@ private:
Surface image;
int xOffset, yOffset;
int advance;
+ FT_UInt slot;
};
- bool cacheGlyph(Glyph &glyph, FT_UInt &slot, uint chr);
+ bool cacheGlyph(Glyph &glyph, uint chr);
typedef Common::HashMap<uint32, Glyph> GlyphCache;
GlyphCache _glyphs;
- FT_UInt _glyphSlots[256];
-
bool _monochrome;
bool _hasKerning;
};
TTFFont::TTFFont()
: _initialized(false), _face(), _ttfFile(0), _size(0), _width(0), _height(0), _ascent(0),
- _descent(0), _glyphs(), _glyphSlots(), _monochrome(false), _hasKerning(false) {
+ _descent(0), _glyphs(), _monochrome(false), _hasKerning(false) {
}
TTFFont::~TTFFont() {
@@ -214,8 +213,9 @@ bool TTFFont::load(Common::SeekableReadStream &stream, int size, uint dpi, bool
if (!mapping) {
// Load all ISO-8859-1 characters.
for (uint i = 0; i < 256; ++i) {
- if (!cacheGlyph(_glyphs[i], _glyphSlots[i], i))
- _glyphSlots[i] = 0;
+ if (!cacheGlyph(_glyphs[i], i)) {
+ _glyphs.erase(i);
+ }
}
} else {
for (uint i = 0; i < 256; ++i) {
@@ -223,8 +223,8 @@ bool TTFFont::load(Common::SeekableReadStream &stream, int size, uint dpi, bool
const bool isRequired = (mapping[i] & 0x80000000) != 0;
// Check whether loading an important glyph fails and error out if
// that is the case.
- if (!cacheGlyph(_glyphs[i], _glyphSlots[i], unicode)) {
- _glyphSlots[i] = 0;
+ if (!cacheGlyph(_glyphs[i], unicode)) {
+ _glyphs.erase(i);
if (isRequired)
return false;
}
@@ -255,12 +255,22 @@ int TTFFont::getKerningOffset(uint32 left, uint32 right) const {
if (!_hasKerning)
return 0;
- if (left > 255 || right > 255) {
+ FT_UInt leftGlyph, rightGlyph;
+ GlyphCache::const_iterator glyphEntry;
+
+ glyphEntry = _glyphs.find(left);
+ if (glyphEntry != _glyphs.end()) {
+ leftGlyph = glyphEntry->_value.slot;
+ } else {
return 0;
}
- FT_UInt leftGlyph = _glyphSlots[left];
- FT_UInt rightGlyph = _glyphSlots[right];
+ glyphEntry = _glyphs.find(right);
+ if (glyphEntry != _glyphs.end()) {
+ rightGlyph = glyphEntry->_value.slot;
+ } else {
+ return 0;
+ }
if (!leftGlyph || !rightGlyph)
return 0;
@@ -380,11 +390,13 @@ void TTFFont::drawChar(Surface *dst, uint32 chr, int x, int y, uint32 color) con
}
}
-bool TTFFont::cacheGlyph(Glyph &glyph, FT_UInt &slot, uint chr) {
- slot = FT_Get_Char_Index(_face, chr);
+bool TTFFont::cacheGlyph(Glyph &glyph, uint chr) {
+ FT_UInt slot = FT_Get_Char_Index(_face, chr);
if (!slot)
return false;
+ glyph.slot = slot;
+
// We use the light target and render mode to improve the looks of the
// glyphs. It is most noticable in FreeSansBold.ttf, where otherwise the
// 't' glyph looks like it is cut off on the right side.
@@ -460,6 +472,7 @@ bool TTFFont::cacheGlyph(Glyph &glyph, FT_UInt &slot, uint chr) {
default:
warning("TTFFont::cacheGlyph: Unsupported pixel mode %d", bitmap.pixel_mode);
+ glyph.image.free();
return false;
}