Changeset - r6913:a28cda7a5f13
[Not reviewed]
master
0 3 0
peter1138 - 17 years ago 2007-06-15 16:21:56
peter1138@openttd.org
(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.
3 files changed with 28 insertions and 5 deletions:
0 comments (0 inline, 0 general)
src/fontcache.cpp
Show inline comments
 
@@ -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, WC
 

	
 
	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, WC
 
	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, WC
 

	
 
	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;
 
			}
 
		}
 
	}
src/fontcache.h
Show inline comments
 
@@ -21,6 +21,9 @@ struct FreeTypeSettings {
 
	uint small_size;
 
	uint medium_size;
 
	uint large_size;
 
	bool small_aa;
 
	bool medium_aa;
 
	bool large_aa;
 
};
 

	
 
extern FreeTypeSettings _freetype;
src/settings.cpp
Show inline comments
 
@@ -1256,6 +1256,9 @@ static const SettingDescGlobVarList _mis
 
	  SDTG_VAR("small_size",       SLE_UINT, S, 0, _freetype.small_size,   6, 0, 72, 0, STR_NULL, NULL),
 
	  SDTG_VAR("medium_size",      SLE_UINT, S, 0, _freetype.medium_size, 10, 0, 72, 0, STR_NULL, NULL),
 
	  SDTG_VAR("large_size",       SLE_UINT, S, 0, _freetype.large_size,  16, 0, 72, 0, STR_NULL, NULL),
 
	 SDTG_BOOL("small_aa",                   S, 0, _freetype.small_aa,    false,    STR_NULL, NULL),
 
	 SDTG_BOOL("medium_aa",                  S, 0, _freetype.medium_aa,   false,    STR_NULL, NULL),
 
	 SDTG_BOOL("large_aa",                   S, 0, _freetype.large_aa,    false,    STR_NULL, NULL),
 
#endif
 
	  SDTG_VAR("sprite_cache_size",SLE_UINT, S, 0, _sprite_cache_size,     4, 1, 64, 0, STR_NULL, NULL),
 
	  SDTG_END()
0 comments (0 inline, 0 general)