1
0
mirror of https://github.com/OpenRCT2/OpenRCT2 synced 2026-01-17 03:53:07 +01:00

Use light hinting mode iff hinting is enabled.

This makes use of TTF_SetFontHinting, which was ported from SDL_ttf for the occasion.
This commit is contained in:
Aaron van Geffen
2017-10-13 22:57:36 +02:00
committed by Marijn van der Werf
parent 4213a66069
commit 899c859948
5 changed files with 38 additions and 5 deletions

View File

@@ -805,7 +805,7 @@ static void ttf_draw_string_raw_ttf(rct_drawpixelinfo *dpi, const utf8 *text, te
// Centre of the glyph: use full colour.
*dst = colour;
}
else if (*src > 80)
else if (*src > 60)
{
// Simulate font hinting by shading the background colour instead.
if (info->flags & TEXT_DRAW_FLAG_OUTLINE)

View File

@@ -60,6 +60,7 @@ static TTF_Font * ttf_open_font(const utf8 * fontPath, sint32 ptSize);
static void ttf_close_font(TTF_Font * font);
static uint32 ttf_surface_cache_hash(TTF_Font * font, const utf8 * text);
static void ttf_surface_cache_dispose(ttf_cache_entry * entry);
static void ttf_surface_cache_dispose_all();
static void ttf_getwidth_cache_dispose_all();
static bool ttf_get_size(TTF_Font * font, const utf8 * text, sint32 * width, sint32 * height);
static TTFSurface * ttf_render(TTF_Font * font, const utf8 * text);
@@ -72,7 +73,7 @@ bool ttf_initialise()
return false;
}
for (sint32 i = 0; i < 4; i++) {
for (sint32 i = 0; i < FONT_SIZE_COUNT; i++) {
TTFFontDescriptor *fontDesc = &(gCurrentTTFFontSet->size[i]);
utf8 fontPath[MAX_PATH];
@@ -86,7 +87,10 @@ bool ttf_initialise()
log_error("Unable to load '%s'", fontPath);
return false;
}
}
ttf_toggle_hinting();
_ttfInitialised = true;
}
return true;
@@ -143,7 +147,7 @@ static void ttf_surface_cache_dispose(ttf_cache_entry *entry)
}
}
void ttf_surface_cache_dispose_all()
static void ttf_surface_cache_dispose_all()
{
for (sint32 i = 0; i < TTF_SURFACE_CACHE_SIZE; i++) {
ttf_surface_cache_dispose(&_ttfSurfaceCache[i]);
@@ -151,6 +155,20 @@ void ttf_surface_cache_dispose_all()
}
}
void ttf_toggle_hinting()
{
for (sint32 i = 0; i < FONT_SIZE_COUNT; i++)
{
TTFFontDescriptor *fontDesc = &(gCurrentTTFFontSet->size[i]);
TTF_SetFontHinting(fontDesc->font, gConfigFonts.enable_hinting ? 1 : 0);
}
if (_ttfSurfaceCacheCount)
{
ttf_surface_cache_dispose_all();
}
}
TTFSurface * ttf_surface_cache_get_or_add(TTF_Font * font, const utf8 * text)
{
ttf_cache_entry *entry;

View File

@@ -43,8 +43,8 @@ extern "C" {
#endif
TTFFontDescriptor * ttf_get_font_from_sprite_base(uint16 spriteBase);
void ttf_toggle_hinting();
TTFSurface * ttf_surface_cache_get_or_add(TTF_Font * font, const utf8 * text);
void ttf_surface_cache_dispose_all();
uint32 ttf_getwidth_cache_get_or_add(TTF_Font * font, const utf8 * text);
bool ttf_provides_glyph(const TTF_Font * font, codepoint_t codepoint);
void ttf_free_surface(TTFSurface * surface);
@@ -57,6 +57,7 @@ int TTF_SizeUTF8(TTF_Font *font, const char *text, int *w, int *h);
TTFSurface * TTF_RenderUTF8_Solid(TTF_Font *font, const char *text, uint32 colour);
TTFSurface * TTF_RenderUTF8_Shaded(TTF_Font *font, const char *text, uint32 fg, uint32 bg);
void TTF_CloseFont(TTF_Font *font);
void TTF_SetFontHinting(TTF_Font* font, int hinting);
void TTF_Quit(void);
#ifdef __cplusplus

View File

@@ -1433,6 +1433,20 @@ static bool CharacterIsDelimiter(char c, const char *delimiters)
return false;
}
void TTF_SetFontHinting(TTF_Font* font, int hinting)
{
if (hinting == TTF_HINTING_LIGHT)
font->hinting = FT_LOAD_TARGET_LIGHT;
else if (hinting == TTF_HINTING_MONO)
font->hinting = FT_LOAD_TARGET_MONO;
else if (hinting == TTF_HINTING_NONE)
font->hinting = FT_LOAD_NO_HINTING;
else
font->hinting = 0;
Flush_Cache(font);
}
void TTF_Quit(void)
{
if (TTF_initialized) {

View File

@@ -1083,7 +1083,7 @@ static sint32 cc_set(const utf8 **argv, sint32 argc)
gConfigFonts.enable_hinting = (int_val[0] != 0);
config_save_default();
console_execute_silent("get enable_hinting");
ttf_surface_cache_dispose_all();
ttf_toggle_hinting();
}
#endif
else if (invalidArgs) {