aboutsummaryrefslogtreecommitdiff
path: root/graphics/fonts
diff options
context:
space:
mode:
authorJohannes Schickel2012-01-09 03:33:59 +0100
committerWillem Jan Palenstijn2012-01-29 16:26:20 +0100
commitf63df3bf7b95ddd9eaa4f55c4f21f53f3bd00f68 (patch)
treeb7ec71daf5c1d957c818e62ec87cd079fa7f2dbc /graphics/fonts
parent9f3fbe1bd773664b1e86241e71875cd97230d791 (diff)
downloadscummvm-rg350-f63df3bf7b95ddd9eaa4f55c4f21f53f3bd00f68.tar.gz
scummvm-rg350-f63df3bf7b95ddd9eaa4f55c4f21f53f3bd00f68.tar.bz2
scummvm-rg350-f63df3bf7b95ddd9eaa4f55c4f21f53f3bd00f68.zip
GRAPHICS/GUI: Implement charset mapping for TTF fonts.
The charsets used by the translations now need to have a "$(name).cp" file, which contains an charset index => unicode mapping. Otherwise create_translations will fail.
Diffstat (limited to 'graphics/fonts')
-rw-r--r--graphics/fonts/ttf.cpp30
-rw-r--r--graphics/fonts/ttf.h2
2 files changed, 23 insertions, 9 deletions
diff --git a/graphics/fonts/ttf.cpp b/graphics/fonts/ttf.cpp
index b5bf5c0158..2ba6205a11 100644
--- a/graphics/fonts/ttf.cpp
+++ b/graphics/fonts/ttf.cpp
@@ -101,7 +101,7 @@ public:
TTFFont();
virtual ~TTFFont();
- bool load(Common::SeekableReadStream &stream, int size, bool monochrome);
+ bool load(Common::SeekableReadStream &stream, int size, bool monochrome, const uint32 *mapping);
virtual int getFontHeight() const;
@@ -157,7 +157,7 @@ TTFFont::~TTFFont() {
}
}
-bool TTFFont::load(Common::SeekableReadStream &stream, int size, bool monochrome) {
+bool TTFFont::load(Common::SeekableReadStream &stream, int size, bool monochrome, const uint32 *mapping) {
if (!g_ttf.isInitialized())
return false;
@@ -211,10 +211,24 @@ bool TTFFont::load(Common::SeekableReadStream &stream, int size, bool monochrome
_width = ftCeil26_6(FT_MulFix(_face->max_advance_width, _face->size->metrics.x_scale));
_height = _ascent - _descent + 1;
- // Load all ISO-8859-1 characters.
- for (uint i = 0; i < 256; ++i) {
- if (!cacheGlyph(_glyphs[i], _glyphSlots[i], i))
- _glyphSlots[i] = 0;
+ 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;
+ }
+ } else {
+ for (uint i = 0; i < 256; ++i) {
+ const uint32 unicode = mapping[i] & 0x7FFFFFFF;
+ 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 (isRequired)
+ return false;
+ }
+ }
}
_initialized = (_glyphs.size() != 0);
@@ -447,10 +461,10 @@ bool TTFFont::cacheGlyph(Glyph &glyph, FT_UInt &slot, uint chr) {
return true;
}
-Font *loadTTFFont(Common::SeekableReadStream &stream, int size, bool monochrome) {
+Font *loadTTFFont(Common::SeekableReadStream &stream, int size, bool monochrome, const uint32 *mapping) {
TTFFont *font = new TTFFont();
- if (!font->load(stream, size, monochrome)) {
+ if (!font->load(stream, size, monochrome, mapping)) {
delete font;
return 0;
}
diff --git a/graphics/fonts/ttf.h b/graphics/fonts/ttf.h
index f5349883e9..7222d6e112 100644
--- a/graphics/fonts/ttf.h
+++ b/graphics/fonts/ttf.h
@@ -32,7 +32,7 @@
namespace Graphics {
class Font;
-Font *loadTTFFont(Common::SeekableReadStream &stream, int size, bool monochrome = false);
+Font *loadTTFFont(Common::SeekableReadStream &stream, int size, bool monochrome = false, const uint32 *mapping = 0);
} // End of namespace Graphics