diff --git a/src/openrct2/drawing/string.c b/src/openrct2/drawing/string.c index fc45f42bb3..dcd71f8f2f 100644 --- a/src/openrct2/drawing/string.c +++ b/src/openrct2/drawing/string.c @@ -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) diff --git a/src/openrct2/drawing/ttf.c b/src/openrct2/drawing/ttf.c index 73884fd3d9..150015326f 100644 --- a/src/openrct2/drawing/ttf.c +++ b/src/openrct2/drawing/ttf.c @@ -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; diff --git a/src/openrct2/drawing/ttf.h b/src/openrct2/drawing/ttf.h index 6714d445a5..973bc60f92 100644 --- a/src/openrct2/drawing/ttf.h +++ b/src/openrct2/drawing/ttf.h @@ -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 diff --git a/src/openrct2/drawing/ttf_sdlport.c b/src/openrct2/drawing/ttf_sdlport.c index 1ad66919b8..52455caa20 100644 --- a/src/openrct2/drawing/ttf_sdlport.c +++ b/src/openrct2/drawing/ttf_sdlport.c @@ -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) { diff --git a/src/openrct2/interface/console.c b/src/openrct2/interface/console.c index dc2c49fba1..2087938510 100644 --- a/src/openrct2/interface/console.c +++ b/src/openrct2/interface/console.c @@ -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) {