[Scummvm-cvs-logs] scummvm master -> 5b03ba04d78be0f7d60ac777dbf8b51584192f7d
lordhoto
lordhoto at gmail.com
Mon Jun 9 01:06:47 CEST 2014
This automated email contains information about 1 new commit which have been
pushed to the 'scummvm' repo located at https://github.com/scummvm/scummvm .
Summary:
5b03ba04d7 GRAPHICS: Allow client code to specify TTF render mode.
Commit: 5b03ba04d78be0f7d60ac777dbf8b51584192f7d
https://github.com/scummvm/scummvm/commit/5b03ba04d78be0f7d60ac777dbf8b51584192f7d
Author: Johannes Schickel (lordhoto at scummvm.org)
Date: 2014-06-09T01:04:47+02:00
Commit Message:
GRAPHICS: Allow client code to specify TTF render mode.
This allows clients to use the default FreeType2 render mode instead of light.
We really only use light as default because that's what looks best with the
font we use in our GUI right now (which is the same reason why formerly light
was always used in non-monochrome mode).
Changed paths:
graphics/fonts/ttf.cpp
graphics/fonts/ttf.h
gui/ThemeEngine.cpp
diff --git a/graphics/fonts/ttf.cpp b/graphics/fonts/ttf.cpp
index 93f119f..09a0067 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, uint dpi, bool monochrome, const uint32 *mapping);
+ bool load(Common::SeekableReadStream &stream, int size, uint dpi, TTFRenderMode renderMode, const uint32 *mapping);
virtual int getFontHeight() const;
@@ -135,13 +135,15 @@ private:
bool _allowLateCaching;
void assureCached(uint32 chr) const;
- bool _monochrome;
+ FT_Int32 _loadFlags;
+ FT_Render_Mode _renderMode;
bool _hasKerning;
};
TTFFont::TTFFont()
: _initialized(false), _face(), _ttfFile(0), _size(0), _width(0), _height(0), _ascent(0),
- _descent(0), _glyphs(), _monochrome(false), _hasKerning(false), _allowLateCaching(false) {
+ _descent(0), _glyphs(), _loadFlags(FT_LOAD_TARGET_NORMAL), _renderMode(FT_RENDER_MODE_NORMAL),
+ _hasKerning(false), _allowLateCaching(false) {
}
TTFFont::~TTFFont() {
@@ -158,7 +160,7 @@ TTFFont::~TTFFont() {
}
}
-bool TTFFont::load(Common::SeekableReadStream &stream, int size, uint dpi, bool monochrome, const uint32 *mapping) {
+bool TTFFont::load(Common::SeekableReadStream &stream, int size, uint dpi, TTFRenderMode renderMode, const uint32 *mapping) {
if (!g_ttf.isInitialized())
return false;
@@ -203,7 +205,22 @@ bool TTFFont::load(Common::SeekableReadStream &stream, int size, uint dpi, bool
return false;
}
- _monochrome = monochrome;
+ switch (renderMode) {
+ case kTTFRenderModeNormal:
+ _loadFlags = FT_LOAD_TARGET_NORMAL;
+ _renderMode = FT_RENDER_MODE_NORMAL;
+ break;
+
+ case kTTFRenderModeLight:
+ _loadFlags = FT_LOAD_TARGET_LIGHT;
+ _renderMode = FT_RENDER_MODE_LIGHT;
+ break;
+
+ case kTTFRenderModeMonochrome:
+ _loadFlags = FT_LOAD_TARGET_MONO;
+ _renderMode = FT_RENDER_MODE_MONO;
+ break;
+ }
FT_Fixed yScale = _face->size->metrics.y_scale;
_ascent = ftCeil26_6(FT_MulFix(_face->ascender, yScale));
@@ -413,10 +430,10 @@ bool TTFFont::cacheGlyph(Glyph &glyph, uint32 chr) const {
// 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.
- if (FT_Load_Glyph(_face, slot, (_monochrome ? FT_LOAD_TARGET_MONO : FT_LOAD_TARGET_LIGHT)))
+ if (FT_Load_Glyph(_face, slot, _loadFlags))
return false;
- if (FT_Render_Glyph(_face->glyph, (_monochrome ? FT_RENDER_MODE_MONO : FT_RENDER_MODE_LIGHT)))
+ if (FT_Render_Glyph(_face->glyph, _renderMode))
return false;
if (_face->glyph->format != FT_GLYPH_FORMAT_BITMAP)
@@ -503,10 +520,10 @@ void TTFFont::assureCached(uint32 chr) const {
}
}
-Font *loadTTFFont(Common::SeekableReadStream &stream, int size, uint dpi, bool monochrome, const uint32 *mapping) {
+Font *loadTTFFont(Common::SeekableReadStream &stream, int size, uint dpi, TTFRenderMode renderMode, const uint32 *mapping) {
TTFFont *font = new TTFFont();
- if (!font->load(stream, size, dpi, monochrome, mapping)) {
+ if (!font->load(stream, size, dpi, renderMode, mapping)) {
delete font;
return 0;
}
diff --git a/graphics/fonts/ttf.h b/graphics/fonts/ttf.h
index 65aba32..bd25b69 100644
--- a/graphics/fonts/ttf.h
+++ b/graphics/fonts/ttf.h
@@ -34,14 +34,35 @@ namespace Graphics {
class Font;
/**
+ * This specifies the mode in which TTF glyphs are rendered. This, for example,
+ * allows to render glyphs fully monochrome, i.e. without any anti-aliasing.
+ */
+enum TTFRenderMode {
+ /**
+ * Standard render mode. Equivalent of FreeType2's FT_RENDER_MODE_NORMAL.
+ */
+ kTTFRenderModeNormal,
+
+ /**
+ * Use lighter hinting. Equivalent of FreeType2's FT_RENDER_MODE_LIGHT.
+ */
+ kTTFRenderModeLight,
+
+ /**
+ * Render fully monochrome. This makes glyph pixels either be fully opaque
+ * or fully transparent.
+ */
+ kTTFRenderModeMonochrome
+};
+
+/**
* Loads a TTF font file from a given data stream object.
*
* @param stream Stream object to load font data from.
* @param size The point size to load.
* @param dpi The dpi to use for size calculations, by default 72dpi
* are used.
- * @param monochrome Whether the font should be loaded in pure monochrome
- * mode. In case this is true no aliasing is used.
+ * @param renderMode FreeType2 mode used to render glyphs. @see TTFRenderMode
* @param mapping A mapping from code points 0-255 into UTF-32 code points.
* This can be used to support various 8bit character sets.
* In case the msb of the UTF-32 code point is set the font
@@ -50,7 +71,7 @@ class Font;
* supported.
* @return 0 in case loading fails, otherwise a pointer to the Font object.
*/
-Font *loadTTFFont(Common::SeekableReadStream &stream, int size, uint dpi = 0, bool monochrome = false, const uint32 *mapping = 0);
+Font *loadTTFFont(Common::SeekableReadStream &stream, int size, uint dpi = 0, TTFRenderMode renderMode = kTTFRenderModeLight, const uint32 *mapping = 0);
void shutdownTTF();
diff --git a/gui/ThemeEngine.cpp b/gui/ThemeEngine.cpp
index 9e54597..ed01204 100644
--- a/gui/ThemeEngine.cpp
+++ b/gui/ThemeEngine.cpp
@@ -1446,7 +1446,7 @@ const Graphics::Font *ThemeEngine::loadScalableFont(const Common::String &filena
for (Common::ArchiveMemberList::const_iterator i = members.begin(), end = members.end(); i != end; ++i) {
Common::SeekableReadStream *stream = (*i)->createReadStream();
if (stream) {
- font = Graphics::loadTTFFont(*stream, pointsize, 0, false,
+ font = Graphics::loadTTFFont(*stream, pointsize, 0, Graphics::kTTFRenderModeLight,
#ifdef USE_TRANSLATION
TransMan.getCharsetMapping()
#else
More information about the Scummvm-git-logs
mailing list