1
0
mirror of https://github.com/OpenRCT2/OpenRCT2 synced 2026-01-16 03:23:15 +01:00

Make font hinting optional on a per-font basis.

Previously, hinting could only be disabled globally.
This commit disables hinting if the hinting threshold is set to 0.
Note that this parameter is configurable through config.ini, too.
This commit is contained in:
Aaron van Geffen
2018-02-12 21:32:47 +01:00
parent 1809eec079
commit bd928bc27e
6 changed files with 24 additions and 7 deletions

View File

@@ -1575,6 +1575,8 @@ static void scrolling_text_set_bitmap_for_ttf(utf8 *text, sint32 scroll, uint8 *
sint32 min_vpos = -fontDesc->offset_y;
sint32 max_vpos = std::min(surface->h - 2, min_vpos + 7);
bool use_hinting = gConfigFonts.enable_hinting && fontDesc->hinting_threshold > 0;
for (sint32 x = 0; ; x++)
{
if (x >= width)
@@ -1593,7 +1595,7 @@ static void scrolling_text_set_bitmap_for_ttf(utf8 *text, sint32 scroll, uint8 *
for (sint32 y = min_vpos; y < max_vpos; y++)
{
if (src[y * pitch + x] > 92 || (src[y * pitch + x] != 0 && !gConfigFonts.enable_hinting))
if (src[y * pitch + x] > 92 || (src[y * pitch + x] != 0 && !use_hinting))
*dst = colour;
// Jump to next row

View File

@@ -541,6 +541,7 @@ static void ttf_draw_string_raw_ttf(rct_drawpixelinfo *dpi, const utf8 *text, te
{
dst = dst_orig;
src = src_orig;
bool use_hinting = gConfigFonts.enable_hinting && fontDesc->hinting_threshold > 0;
for (sint32 yy = 0; yy < height; yy++) {
for (sint32 xx = 0; xx < width; xx++) {
if (*src != 0) {
@@ -548,12 +549,12 @@ static void ttf_draw_string_raw_ttf(rct_drawpixelinfo *dpi, const utf8 *text, te
*(dst + width + dstScanSkip + 1) = info->palette[3];
}
if (*src > 180 || !gConfigFonts.enable_hinting)
if (*src > 180 || !use_hinting)
{
// Centre of the glyph: use full colour.
*dst = colour;
}
else if (*src > fontDesc->hinting_threshold)
else if (use_hinting && *src > fontDesc->hinting_threshold)
{
// Simulate font hinting by shading the background colour instead.
if (info->flags & TEXT_DRAW_FLAG_OUTLINE)

View File

@@ -165,7 +165,8 @@ 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);
bool use_hinting = gConfigFonts.enable_hinting && fontDesc->hinting_threshold;
TTF_SetFontHinting(fontDesc->font, use_hinting ? 1 : 0);
}
if (_ttfSurfaceCacheCount)
@@ -299,7 +300,7 @@ static bool ttf_get_size(TTF_Font * font, const utf8 * text, sint32 * outWidth,
static TTFSurface * ttf_render(TTF_Font * font, const utf8 * text)
{
if (gConfigFonts.enable_hinting)
if (TTF_GetFontHinting(font) != 0)
{
return TTF_RenderUTF8_Shaded(font, text, 0x000000FF, 0x000000FF);
}

View File

@@ -46,6 +46,7 @@ TTFSurface * TTF_RenderUTF8_Solid(TTF_Font *font, const char *text, uint32 colou
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);
int TTF_GetFontHinting(const TTF_Font* font);
void TTF_Quit(void);
#endif // NO_TTF

View File

@@ -1401,6 +1401,17 @@ void TTF_SetFontHinting(TTF_Font* font, int hinting)
Flush_Cache(font);
}
int TTF_GetFontHinting(const TTF_Font* font)
{
if (font->hinting == FT_LOAD_TARGET_LIGHT)
return TTF_HINTING_LIGHT;
else if (font->hinting == FT_LOAD_TARGET_MONO)
return TTF_HINTING_MONO;
else if (font->hinting == FT_LOAD_NO_HINTING)
return TTF_HINTING_NONE;
return 0;
}
void TTF_Quit(void)
{
if (TTF_initialized) {

View File

@@ -26,6 +26,7 @@
#include "../localisation/Language.h"
#ifndef NO_TTF
uint8 const HINTING_DISABLED = 0;
uint8 const HINTING_THRESHOLD_LOW = 40;
uint8 const HINTING_THRESHOLD_MEDIUM = 60;
@@ -73,14 +74,14 @@ TTFFontSetDescriptor TTFFontLiHeiPro = { {
} };
TTFFontSetDescriptor TTFFontGulim = { {
{ "gulim.ttc", "Gulim", 10, 1, 0, 10, HINTING_THRESHOLD_MEDIUM, nullptr },
{ "gulim.ttc", "Gulim", 10, 1, 0, 10, HINTING_DISABLED, nullptr },
{ "gulim.ttc", "Gulim", 12, 1, 0, 15, HINTING_THRESHOLD_MEDIUM, nullptr },
{ "gulim.ttc", "Gulim", 12, 1, 0, 15, HINTING_THRESHOLD_MEDIUM, nullptr },
{ "gulim.ttc", "Gulim", 13, 1, 0, 16, HINTING_THRESHOLD_MEDIUM, nullptr },
} };
TTFFontSetDescriptor TTFFontNanum = { {
{ "NanumGothic.ttc", "Nanum Gothic", 10, 1, 0, 10, HINTING_THRESHOLD_LOW, nullptr },
{ "NanumGothic.ttc", "Nanum Gothic", 10, 1, 0, 10, HINTING_DISABLED, nullptr },
{ "NanumGothic.ttc", "Nanum Gothic", 12, 1, 0, 15, HINTING_THRESHOLD_LOW, nullptr },
{ "NanumGothic.ttc", "Nanum Gothic", 12, 1, 0, 15, HINTING_THRESHOLD_LOW, nullptr },
{ "NanumGothic.ttc", "Nanum Gothic", 13, 1, 0, 16, HINTING_THRESHOLD_LOW, nullptr },