summaryrefslogtreecommitdiff
path: root/src/fontcache.cpp
diff options
context:
space:
mode:
authorpeter1138 <peter1138@openttd.org>2007-06-15 16:21:56 +0000
committerpeter1138 <peter1138@openttd.org>2007-06-15 16:21:56 +0000
commitef099dbc27fe513d8a915c23186179cde3f338c3 (patch)
tree3f3afc243812cee2eaed281cc99d3347b470b3d9 /src/fontcache.cpp
parentd6267f553959089f1208cf59fd33410f78e86fe2 (diff)
downloadopenttd-ef099dbc27fe513d8a915c23186179cde3f338c3.tar.xz
(svn r10166) -Feature(tte): Add support for antialiased typefaces via FreeType. This is configurable for each font size in the configuration settings and requires using the 32bpp blitter and suitable fonts.
Diffstat (limited to 'src/fontcache.cpp')
-rw-r--r--src/fontcache.cpp27
1 files changed, 22 insertions, 5 deletions
diff --git a/src/fontcache.cpp b/src/fontcache.cpp
index a04936aec..7363e4ef8 100644
--- a/src/fontcache.cpp
+++ b/src/fontcache.cpp
@@ -369,6 +369,21 @@ void *AllocateFont(size_t size)
}
+/* Check if a glyph should be rendered with antialiasing */
+static bool GetFontAAState(FontSize size)
+{
+ /* AA is only supported for 32 bpp */
+ if (BlitterFactoryBase::GetCurrentBlitter()->GetScreenDepth() != 32) return false;
+
+ switch (size) {
+ default: NOT_REACHED();
+ case FS_NORMAL: return _freetype.medium_aa;
+ case FS_SMALL: return _freetype.small_aa;
+ case FS_LARGE: return _freetype.large_aa;
+ }
+}
+
+
const Sprite *GetGlyph(FontSize size, WChar key)
{
FT_Face face = GetFontFace(size);
@@ -397,8 +412,10 @@ const Sprite *GetGlyph(FontSize size, WChar key)
slot = face->glyph;
+ bool aa = GetFontAAState(size);
+
FT_Load_Char(face, key, FT_LOAD_DEFAULT);
- FT_Render_Glyph(face->glyph, FT_RENDER_MODE_MONO);
+ FT_Render_Glyph(face->glyph, aa ? FT_RENDER_MODE_NORMAL : FT_RENDER_MODE_MONO);
/* Add 1 pixel for the shadow on the medium font. Our sprite must be at least 1x1 pixel */
width = max(1, slot->bitmap.width + (size == FS_NORMAL));
@@ -417,9 +434,9 @@ const Sprite *GetGlyph(FontSize size, WChar key)
if (size == FS_NORMAL) {
for (y = 0; y < slot->bitmap.rows; y++) {
for (x = 0; x < slot->bitmap.width; x++) {
- if (HASBIT(slot->bitmap.buffer[(x / 8) + y * slot->bitmap.pitch], 7 - (x % 8))) {
+ if (aa ? (slot->bitmap.buffer[x + y * slot->bitmap.pitch] > 0) : HASBIT(slot->bitmap.buffer[(x / 8) + y * slot->bitmap.pitch], 7 - (x % 8))) {
sprite.data[1 + x + (1 + y) * sprite.width].m = SHADOW_COLOUR;
- sprite.data[1 + x + (1 + y) * sprite.width].a = 0xFF;
+ sprite.data[1 + x + (1 + y) * sprite.width].a = aa ? slot->bitmap.buffer[x + y * slot->bitmap.pitch] : 0xFF;
}
}
}
@@ -427,9 +444,9 @@ const Sprite *GetGlyph(FontSize size, WChar key)
for (y = 0; y < slot->bitmap.rows; y++) {
for (x = 0; x < slot->bitmap.width; x++) {
- if (HASBIT(slot->bitmap.buffer[(x / 8) + y * slot->bitmap.pitch], 7 - (x % 8))) {
+ if (aa ? (slot->bitmap.buffer[x + y * slot->bitmap.pitch] > 0) : HASBIT(slot->bitmap.buffer[(x / 8) + y * slot->bitmap.pitch], 7 - (x % 8))) {
sprite.data[x + y * sprite.width].m = FACE_COLOUR;
- sprite.data[x + y * sprite.width].a = 0xFF;
+ sprite.data[x + y * sprite.width].a = aa ? slot->bitmap.buffer[x + y * slot->bitmap.pitch] : 0xFF;
}
}
}