2016-11-30 11:50:43 +01:00
|
|
|
/*****************************************************************************
|
2023-01-01 04:58:01 -06:00
|
|
|
* Copyright (c) 2014-2023 OpenRCT2 developers
|
2016-11-30 11:50:43 +01:00
|
|
|
*
|
2018-06-15 14:07:34 +02:00
|
|
|
* For a complete list of all authors, please refer to contributors.md
|
|
|
|
|
* Interested in contributing? Visit https://github.com/OpenRCT2/OpenRCT2
|
2016-11-30 11:50:43 +01:00
|
|
|
*
|
2018-06-15 14:07:34 +02:00
|
|
|
* OpenRCT2 is licensed under the GNU General Public License version 3.
|
2016-11-30 11:50:43 +01:00
|
|
|
*****************************************************************************/
|
|
|
|
|
|
2018-06-22 22:59:46 +02:00
|
|
|
#include "Fonts.h"
|
|
|
|
|
|
2017-06-13 20:50:14 +01:00
|
|
|
#include "../config/Config.h"
|
2016-11-30 11:50:43 +01:00
|
|
|
#include "../core/String.hpp"
|
2018-01-05 21:14:20 +00:00
|
|
|
#include "../drawing/TTF.h"
|
2018-01-06 18:32:25 +01:00
|
|
|
#include "../localisation/Language.h"
|
2018-04-26 23:03:02 +01:00
|
|
|
#include "../localisation/LocalisationService.h"
|
2022-10-12 22:40:59 +02:00
|
|
|
#include "../util/Util.h"
|
2018-06-22 22:59:46 +02:00
|
|
|
#include "FontFamilies.h"
|
2018-04-26 23:03:02 +01:00
|
|
|
|
|
|
|
|
using namespace OpenRCT2::Localisation;
|
2016-11-30 11:50:43 +01:00
|
|
|
|
2017-01-03 22:57:15 +01:00
|
|
|
#ifndef NO_TTF
|
2018-06-22 22:59:46 +02:00
|
|
|
uint8_t const HINTING_DISABLED = 0;
|
|
|
|
|
uint8_t const HINTING_THRESHOLD_LOW = 40;
|
2018-06-20 17:28:51 +02:00
|
|
|
uint8_t const HINTING_THRESHOLD_MEDIUM = 60;
|
2017-10-14 21:24:42 +02:00
|
|
|
|
2018-01-10 16:14:36 +01:00
|
|
|
// clang-format off
|
2017-10-09 10:53:09 +02:00
|
|
|
TTFFontSetDescriptor TTFFontMSGothic = { {
|
2022-10-12 22:40:59 +02:00
|
|
|
{ "msgothic.ttc", "MS PGothic", 12, 1, 0, 14, HINTING_THRESHOLD_MEDIUM, nullptr },
|
|
|
|
|
{ "msgothic.ttc", "MS PGothic", 12, 1, 0, 14, HINTING_THRESHOLD_MEDIUM, nullptr },
|
2018-02-09 15:57:32 +01:00
|
|
|
{ "msgothic.ttc", "MS PGothic", 9, 1, 1, 9, HINTING_THRESHOLD_MEDIUM, nullptr },
|
2016-11-30 11:50:43 +01:00
|
|
|
} };
|
|
|
|
|
|
2020-03-19 12:36:33 +01:00
|
|
|
TTFFontSetDescriptor TTFFontNotoSansMono = { {
|
2022-10-12 22:40:59 +02:00
|
|
|
{ "NotoSansCJK-Regular.ttc", "Noto Sans Mono CJK JP", 12, 1, -3, 14, HINTING_THRESHOLD_MEDIUM, nullptr },
|
|
|
|
|
{ "NotoSansCJK-Regular.ttc", "Noto Sans Mono CJK JP", 12, 1, -3, 14, HINTING_THRESHOLD_MEDIUM, nullptr },
|
2020-03-19 12:36:33 +01:00
|
|
|
{ "NotoSansCJK-Regular.ttc", "Noto Sans Mono CJK JP", 9, 1, -2, 9, HINTING_THRESHOLD_MEDIUM, nullptr },
|
|
|
|
|
} };
|
|
|
|
|
|
2017-10-27 17:32:27 +02:00
|
|
|
TTFFontSetDescriptor TTFFontHiragano = { {
|
2022-10-12 22:40:59 +02:00
|
|
|
{ u8"ヒラギノ丸ゴ ProN W4.ttc", "Hiragino Maru Gothic ProN", 11, 1, 0, 13, HINTING_THRESHOLD_MEDIUM, nullptr },
|
|
|
|
|
{ u8"ヒラギノ丸ゴ ProN W4.ttc", "Hiragino Maru Gothic ProN", 11, 1, 0, 13, HINTING_THRESHOLD_MEDIUM, nullptr },
|
2018-02-09 15:57:32 +01:00
|
|
|
{ u8"ヒラギノ丸ゴ ProN W4.ttc", "Hiragino Maru Gothic ProN", 9, 1, 1, 9, HINTING_THRESHOLD_MEDIUM, nullptr },
|
2017-10-27 17:32:27 +02:00
|
|
|
} };
|
|
|
|
|
|
2017-10-09 10:53:09 +02:00
|
|
|
TTFFontSetDescriptor TTFFontMingLiu = { {
|
2017-10-20 12:38:41 +02:00
|
|
|
{ "mingliu.ttc", "MingLiU", 11, 1, 1, 14, HINTING_THRESHOLD_MEDIUM, nullptr },
|
|
|
|
|
{ "mingliu.ttc", "MingLiU", 12, 1, 0, 15, HINTING_THRESHOLD_MEDIUM, nullptr },
|
2022-10-12 22:40:59 +02:00
|
|
|
{ "msjh.ttc", "JhengHei", 9, -1, -1, 9, HINTING_THRESHOLD_MEDIUM, nullptr },
|
2016-11-30 11:50:43 +01:00
|
|
|
} };
|
|
|
|
|
|
2017-10-28 11:32:06 +02:00
|
|
|
TTFFontSetDescriptor TTFFontHeiti = { {
|
|
|
|
|
{ u8"华文黑体.ttf", "STHeiti", 11, 1, 1, 14, HINTING_THRESHOLD_MEDIUM, nullptr },
|
|
|
|
|
{ u8"华文黑体.ttf", "STHeiti", 12, 1, 0, 15, HINTING_THRESHOLD_MEDIUM, nullptr },
|
2022-10-12 22:40:59 +02:00
|
|
|
{ u8"华文黑体.ttf", "STHeiti", 9, -1, -1, 9, HINTING_THRESHOLD_MEDIUM, nullptr },
|
2017-10-28 11:32:06 +02:00
|
|
|
} };
|
|
|
|
|
|
2017-10-09 10:53:09 +02:00
|
|
|
TTFFontSetDescriptor TTFFontSimSun = { {
|
2017-10-14 21:24:42 +02:00
|
|
|
{ "simsun.ttc", "SimSun", 11, 1, -1, 14, HINTING_THRESHOLD_MEDIUM, nullptr },
|
2017-10-20 12:38:41 +02:00
|
|
|
{ "simsun.ttc", "SimSun", 12, 1, -2, 15, HINTING_THRESHOLD_MEDIUM, nullptr },
|
2022-10-12 22:40:59 +02:00
|
|
|
{ "msyh.ttc", "Microsoft YaHei", 9, -1, -1, 9, HINTING_THRESHOLD_MEDIUM, nullptr },
|
2016-11-30 11:50:43 +01:00
|
|
|
} };
|
|
|
|
|
|
2017-10-28 11:27:24 +02:00
|
|
|
TTFFontSetDescriptor TTFFontLiHeiPro = { {
|
|
|
|
|
{ u8"儷黑 Pro.ttf", "LiHei Pro", 11, 1, 0, 14, HINTING_THRESHOLD_MEDIUM, nullptr },
|
|
|
|
|
{ u8"儷黑 Pro.ttf", "LiHei Pro", 12, 1, 0, 15, HINTING_THRESHOLD_MEDIUM, nullptr },
|
2022-10-12 22:40:59 +02:00
|
|
|
{ u8"儷黑 Pro.ttf", "LiHei Pro", 9, 1, -1, 9, HINTING_THRESHOLD_MEDIUM, nullptr },
|
2017-10-28 11:27:24 +02:00
|
|
|
} };
|
|
|
|
|
|
2017-10-09 10:53:09 +02:00
|
|
|
TTFFontSetDescriptor TTFFontGulim = { {
|
2022-10-12 22:40:59 +02:00
|
|
|
{ "gulim.ttc", "Gulim", 12, 1, 0, 15, HINTING_THRESHOLD_MEDIUM, nullptr },
|
|
|
|
|
{ "gulim.ttc", "Gulim", 12, 1, 0, 15, HINTING_THRESHOLD_MEDIUM, nullptr },
|
2018-02-12 21:32:47 +01:00
|
|
|
{ "gulim.ttc", "Gulim", 10, 1, 0, 10, HINTING_DISABLED, nullptr },
|
2016-11-30 11:50:43 +01:00
|
|
|
} };
|
|
|
|
|
|
2021-07-03 15:21:54 +09:00
|
|
|
TTFFontSetDescriptor TTFFontMalgun = { {
|
2022-10-12 22:40:59 +02:00
|
|
|
{ "malgun.ttf", "Malgun Gothic", 12, 1, -3, 15, HINTING_THRESHOLD_LOW, nullptr },
|
|
|
|
|
{ "malgun.ttf", "Malgun Gothic", 12, 1, -3, 15, HINTING_THRESHOLD_LOW, nullptr },
|
2021-07-03 15:21:54 +09:00
|
|
|
{ "malgun.ttf", "Malgun Gothic", 10, 1, -3, 10, HINTING_THRESHOLD_LOW, nullptr },
|
|
|
|
|
} };
|
|
|
|
|
|
2017-10-27 18:25:28 +02:00
|
|
|
TTFFontSetDescriptor TTFFontNanum = { {
|
2022-10-12 22:40:59 +02:00
|
|
|
{ "NanumGothic.ttf", "Nanum Gothic", 12, 1, -2, 15, HINTING_THRESHOLD_LOW, nullptr },
|
|
|
|
|
{ "NanumGothic.ttf", "Nanum Gothic", 12, 1, -2, 15, HINTING_THRESHOLD_LOW, nullptr },
|
2021-07-03 15:32:41 +09:00
|
|
|
{ "NanumGothic.ttf", "Nanum Gothic", 10, 1, -2, 10, HINTING_DISABLED, nullptr },
|
2017-10-27 18:25:28 +02:00
|
|
|
} };
|
|
|
|
|
|
2017-10-09 10:53:09 +02:00
|
|
|
TTFFontSetDescriptor TTFFontArial = { {
|
2022-10-12 22:40:59 +02:00
|
|
|
{ "arial.ttf", "Arial", 12, 0, -1, 12, HINTING_THRESHOLD_LOW, nullptr },
|
|
|
|
|
{ "arial.ttf", "Arial", 12, 0, -1, 12, HINTING_THRESHOLD_LOW, nullptr },
|
2020-09-07 19:21:32 +02:00
|
|
|
{ "arial.ttf", "Arial", 10, 0, -1, 9, HINTING_THRESHOLD_LOW, nullptr },
|
2016-11-30 11:50:43 +01:00
|
|
|
} };
|
2017-10-27 17:44:51 +02:00
|
|
|
|
|
|
|
|
TTFFontSetDescriptor TTFFontArialUnicode = { {
|
2022-10-12 22:40:59 +02:00
|
|
|
{ "arialuni.ttf", "Arial Unicode MS", 12, 0, -1, 12, HINTING_THRESHOLD_LOW, nullptr },
|
|
|
|
|
{ "arialuni.ttf", "Arial Unicode MS", 12, 0, -1, 12, HINTING_THRESHOLD_LOW, nullptr },
|
2020-09-07 19:21:32 +02:00
|
|
|
{ "arialuni.ttf", "Arial Unicode MS", 10, 0, -1, 9, HINTING_THRESHOLD_LOW, nullptr },
|
2017-10-27 17:44:51 +02:00
|
|
|
} };
|
2019-07-17 17:22:38 +08:00
|
|
|
|
|
|
|
|
TTFFontSetDescriptor TTFFontMicroHei = { {
|
|
|
|
|
{ "wqy-microhei.ttc", "WenQuanYi Micro Hei", 11, 1, -1, 14, HINTING_THRESHOLD_MEDIUM, nullptr },
|
|
|
|
|
{ "wqy-microhei.ttc", "WenQuanYi Micro Hei", 11, 1, -2, 14, HINTING_THRESHOLD_MEDIUM, nullptr },
|
2022-10-12 22:40:59 +02:00
|
|
|
{ "wqy-microhei.ttc", "WenQuanYi Micro Hei", 10, -1, -1, 10, HINTING_THRESHOLD_MEDIUM, nullptr },
|
2019-07-17 17:22:38 +08:00
|
|
|
} };
|
2018-01-10 16:14:36 +01:00
|
|
|
// clang-format on
|
2017-01-03 22:57:15 +01:00
|
|
|
#endif // NO_TTF
|
2016-11-30 11:50:43 +01:00
|
|
|
|
2018-04-26 23:03:02 +01:00
|
|
|
static void LoadSpriteFont(LocalisationService& localisationService)
|
2016-11-30 11:50:43 +01:00
|
|
|
{
|
2023-01-16 22:31:34 +00:00
|
|
|
TTFDispose();
|
2018-04-26 23:03:02 +01:00
|
|
|
localisationService.UseTrueTypeFont(false);
|
2017-01-04 13:51:12 +01:00
|
|
|
#ifndef NO_TTF
|
2016-11-30 11:50:43 +01:00
|
|
|
gCurrentTTFFontSet = nullptr;
|
2017-01-04 13:51:12 +01:00
|
|
|
#endif // NO_TTF
|
2016-11-30 11:50:43 +01:00
|
|
|
}
|
|
|
|
|
|
2017-01-03 22:57:15 +01:00
|
|
|
#ifndef NO_TTF
|
2018-06-22 22:59:46 +02:00
|
|
|
static bool LoadFont(LocalisationService& localisationService, TTFFontSetDescriptor* font)
|
2016-11-30 11:50:43 +01:00
|
|
|
{
|
2018-04-26 23:03:02 +01:00
|
|
|
localisationService.UseTrueTypeFont(true);
|
2016-11-30 11:50:43 +01:00
|
|
|
gCurrentTTFFontSet = font;
|
|
|
|
|
|
2023-01-16 22:31:34 +00:00
|
|
|
TTFDispose();
|
|
|
|
|
bool fontInitialised = TTFInitialise();
|
2016-11-30 11:50:43 +01:00
|
|
|
return fontInitialised;
|
|
|
|
|
}
|
|
|
|
|
|
2018-04-26 23:03:02 +01:00
|
|
|
static bool LoadCustomConfigFont(LocalisationService& localisationService)
|
2016-11-30 11:50:43 +01:00
|
|
|
{
|
|
|
|
|
static TTFFontSetDescriptor TTFFontCustom = { {
|
2023-01-07 15:27:29 +01:00
|
|
|
{ gConfigFonts.FileName.c_str(), gConfigFonts.FontName.c_str(), gConfigFonts.SizeTiny, gConfigFonts.OffsetX,
|
|
|
|
|
gConfigFonts.OffsetY, gConfigFonts.HeightTiny, gConfigFonts.HintingThreshold, nullptr },
|
|
|
|
|
{ gConfigFonts.FileName.c_str(), gConfigFonts.FontName.c_str(), gConfigFonts.SizeSmall, gConfigFonts.OffsetX,
|
|
|
|
|
gConfigFonts.OffsetY, gConfigFonts.HeightSmall, gConfigFonts.HintingThreshold, nullptr },
|
|
|
|
|
{ gConfigFonts.FileName.c_str(), gConfigFonts.FontName.c_str(), gConfigFonts.SizeMedium, gConfigFonts.OffsetX,
|
|
|
|
|
gConfigFonts.OffsetY, gConfigFonts.HeightMedium, gConfigFonts.HintingThreshold, nullptr },
|
2016-11-30 11:50:43 +01:00
|
|
|
} };
|
|
|
|
|
|
2023-01-16 22:31:34 +00:00
|
|
|
TTFDispose();
|
2018-04-26 23:03:02 +01:00
|
|
|
localisationService.UseTrueTypeFont(true);
|
2016-11-30 11:50:43 +01:00
|
|
|
gCurrentTTFFontSet = &TTFFontCustom;
|
|
|
|
|
|
2023-01-16 22:31:34 +00:00
|
|
|
bool fontInitialised = TTFInitialise();
|
2016-11-30 11:50:43 +01:00
|
|
|
return fontInitialised;
|
|
|
|
|
}
|
2017-01-03 22:57:15 +01:00
|
|
|
#endif // NO_TTF
|
2016-11-30 11:50:43 +01:00
|
|
|
|
2018-04-26 23:03:02 +01:00
|
|
|
void TryLoadFonts(LocalisationService& localisationService)
|
2016-11-30 11:50:43 +01:00
|
|
|
{
|
2017-01-03 22:57:15 +01:00
|
|
|
#ifndef NO_TTF
|
2018-04-26 23:48:25 +01:00
|
|
|
auto currentLanguage = localisationService.GetCurrentLanguage();
|
2018-06-22 22:59:46 +02:00
|
|
|
TTFontFamily const* fontFamily = LanguagesDescriptors[currentLanguage].font_family;
|
2017-10-26 23:23:24 +02:00
|
|
|
|
|
|
|
|
if (fontFamily != FAMILY_OPENRCT2_SPRITE)
|
2016-11-30 11:50:43 +01:00
|
|
|
{
|
2023-01-07 15:27:29 +01:00
|
|
|
if (!gConfigFonts.FileName.empty())
|
2016-11-30 11:50:43 +01:00
|
|
|
{
|
2018-04-26 23:03:02 +01:00
|
|
|
if (LoadCustomConfigFont(localisationService))
|
2016-11-30 11:50:43 +01:00
|
|
|
{
|
|
|
|
|
return;
|
|
|
|
|
}
|
2017-10-30 15:39:36 +01:00
|
|
|
log_verbose("Unable to initialise configured TrueType font -- falling back to the language's default.");
|
2016-11-30 11:50:43 +01:00
|
|
|
}
|
|
|
|
|
|
2018-06-22 22:59:46 +02:00
|
|
|
for (auto& font : *fontFamily)
|
2016-11-30 11:50:43 +01:00
|
|
|
{
|
2018-04-26 23:03:02 +01:00
|
|
|
if (LoadFont(localisationService, font))
|
2017-10-26 23:23:24 +02:00
|
|
|
{
|
|
|
|
|
return;
|
|
|
|
|
}
|
2016-11-30 11:50:43 +01:00
|
|
|
|
2022-10-12 22:40:59 +02:00
|
|
|
TTFFontDescriptor smallFont = font->size[EnumValue(FontStyle::Small)];
|
2017-10-30 15:39:36 +01:00
|
|
|
log_verbose("Unable to load TrueType font '%s' -- trying the next font in the family.", smallFont.font_name);
|
2017-10-26 23:23:24 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (fontFamily != &TTFFamilySansSerif)
|
2016-11-30 11:50:43 +01:00
|
|
|
{
|
2017-10-30 15:39:36 +01:00
|
|
|
log_verbose("Unable to initialise any of the preferred TrueType fonts -- falling back to sans serif fonts.");
|
2017-10-26 23:23:24 +02:00
|
|
|
|
2018-06-22 22:59:46 +02:00
|
|
|
for (auto& font : TTFFamilySansSerif)
|
2017-10-26 23:23:24 +02:00
|
|
|
{
|
2018-04-26 23:03:02 +01:00
|
|
|
if (LoadFont(localisationService, font))
|
2017-10-26 23:23:24 +02:00
|
|
|
{
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2022-10-12 22:40:59 +02:00
|
|
|
TTFFontDescriptor smallFont = font->size[EnumValue(FontStyle::Small)];
|
2017-10-30 15:39:36 +01:00
|
|
|
log_verbose("Unable to load TrueType font '%s' -- trying the next font in the family.", smallFont.font_name);
|
2017-10-26 23:23:24 +02:00
|
|
|
}
|
|
|
|
|
|
2017-10-30 15:39:36 +01:00
|
|
|
log_verbose("Unable to initialise any of the preferred TrueType fonts -- falling back to sprite font.");
|
2016-11-30 11:50:43 +01:00
|
|
|
}
|
|
|
|
|
}
|
2017-01-03 22:57:15 +01:00
|
|
|
#endif // NO_TTF
|
2018-04-26 23:03:02 +01:00
|
|
|
LoadSpriteFont(localisationService);
|
2016-11-30 11:50:43 +01:00
|
|
|
}
|