Files
OpenRCT2-Web/src/openrct2/interface/Fonts.cpp
T

192 lines
8.1 KiB
C++
Raw Normal View History

2017-06-01 21:55:10 +02:00
#pragma region Copyright(c) 2014 - 2017 OpenRCT2 Developers
/*****************************************************************************
* OpenRCT2, an open source clone of Roller Coaster Tycoon 2.
*
* OpenRCT2 is the work of many authors, a full list can be found in contributors.md
* For more information, visit https://github.com/OpenRCT2/OpenRCT2
*
* OpenRCT2 is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* A full copy of the GNU General Public License can be found in licence.txt
*****************************************************************************/
#pragma endregion
#include "../config/Config.h"
#include "../core/Console.hpp"
#include "../core/String.hpp"
#include "../localisation/LanguagePack.h"
2016-12-01 15:05:00 +01:00
#include "Fonts.h"
2017-10-26 23:23:24 +02:00
#include "FontFamilies.h"
2018-01-05 21:17:33 +00:00
#include "../drawing/Drawing.h"
2018-01-05 21:14:20 +00:00
#include "../drawing/TTF.h"
#include "../localisation/language.h"
2017-01-03 22:57:15 +01:00
#ifndef NO_TTF
uint8 const HINTING_THRESHOLD_LOW = 40;
uint8 const HINTING_THRESHOLD_MEDIUM = 60;
2017-10-09 10:53:09 +02:00
TTFFontSetDescriptor TTFFontMSGothic = { {
{ "msgothic.ttc", "MS PGothic", 9, 1, -1, 10, HINTING_THRESHOLD_MEDIUM, nullptr },
{ "msgothic.ttc", "MS PGothic", 12, 1, 0, 14, HINTING_THRESHOLD_MEDIUM, nullptr },
{ "msgothic.ttc", "MS PGothic", 12, 1, 0, 14, HINTING_THRESHOLD_MEDIUM, nullptr },
{ "msgothic.ttc", "MS PGothic", 13, 1, 0, 15, HINTING_THRESHOLD_MEDIUM, nullptr },
} };
TTFFontSetDescriptor TTFFontHiragano = { {
{ u8"ヒラギノ丸ゴ ProN W4.ttc", "Hiragino Maru Gothic ProN", 8, 1, -1, 9, HINTING_THRESHOLD_MEDIUM, nullptr },
{ 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 },
{ u8"ヒラギノ丸ゴ ProN W4.ttc", "Hiragino Maru Gothic ProN", 12, 1, 0, 14, HINTING_THRESHOLD_MEDIUM, nullptr },
} };
2017-10-09 10:53:09 +02:00
TTFFontSetDescriptor TTFFontMingLiu = { {
{ "msjh.ttc", "JhengHei", 9, -1, -3, 6, HINTING_THRESHOLD_MEDIUM, nullptr },
{ "mingliu.ttc", "MingLiU", 11, 1, 1, 14, HINTING_THRESHOLD_MEDIUM, nullptr },
{ "mingliu.ttc", "MingLiU", 12, 1, 0, 15, HINTING_THRESHOLD_MEDIUM, nullptr },
{ "mingliu.ttc", "MingLiU", 13, 1, 0, 15, HINTING_THRESHOLD_MEDIUM, nullptr },
} };
TTFFontSetDescriptor TTFFontHeiti = { {
{ u8"华文黑体.ttf", "STHeiti", 9, -1, -3, 6, HINTING_THRESHOLD_MEDIUM, nullptr },
{ u8"华文黑体.ttf", "STHeiti", 11, 1, 1, 14, HINTING_THRESHOLD_MEDIUM, nullptr },
{ u8"华文黑体.ttf", "STHeiti", 12, 1, 0, 15, HINTING_THRESHOLD_MEDIUM, nullptr },
{ u8"华文黑体.ttf", "STHeiti", 13, 1, 0, 15, HINTING_THRESHOLD_MEDIUM, nullptr },
} };
2017-10-09 10:53:09 +02:00
TTFFontSetDescriptor TTFFontSimSun = { {
{ "msyh.ttc", "YaHei", 9, -1, -3, 6, HINTING_THRESHOLD_MEDIUM, nullptr },
{ "simsun.ttc", "SimSun", 11, 1, -1, 14, HINTING_THRESHOLD_MEDIUM, nullptr },
{ "simsun.ttc", "SimSun", 12, 1, -2, 15, HINTING_THRESHOLD_MEDIUM, nullptr },
{ "simsun.ttc", "SimSun", 13, 1, 0, 16, HINTING_THRESHOLD_MEDIUM, nullptr },
} };
TTFFontSetDescriptor TTFFontLiHeiPro = { {
{ u8"儷黑 Pro.ttf", "LiHei Pro", 9, 1, -1, 10, HINTING_THRESHOLD_MEDIUM, nullptr },
{ 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 },
{ u8"儷黑 Pro.ttf", "LiHei Pro", 13, 1, 0, 16, HINTING_THRESHOLD_MEDIUM, nullptr },
} };
2017-10-09 10:53:09 +02:00
TTFFontSetDescriptor TTFFontGulim = { {
{ "gulim.ttc", "Gulim", 11, 1, 0, 13, HINTING_THRESHOLD_MEDIUM, 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", 11, 1, 0, 13, HINTING_THRESHOLD_LOW, 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 },
} };
2017-10-09 10:53:09 +02:00
TTFFontSetDescriptor TTFFontArial = { {
{ "arial.ttf", "Arial", 8, 0, -1, 6, HINTING_THRESHOLD_LOW, nullptr },
{ "arial.ttf", "Arial", 10, 0, -1, 12, HINTING_THRESHOLD_LOW, nullptr },
{ "arial.ttf", "Arial", 11, 0, -1, 12, HINTING_THRESHOLD_LOW, nullptr },
{ "arial.ttf", "Arial", 12, 0, -1, 14, HINTING_THRESHOLD_LOW, nullptr },
} };
TTFFontSetDescriptor TTFFontArialUnicode = { {
{ "arialuni.ttf", "Arial Unicode MS", 8, 0, -1, 6, HINTING_THRESHOLD_LOW, nullptr },
{ "arialuni.ttf", "Arial Unicode MS", 10, 0, -1, 12, HINTING_THRESHOLD_LOW, nullptr },
{ "arialuni.ttf", "Arial Unicode MS", 11, 0, -1, 12, HINTING_THRESHOLD_LOW, nullptr },
{ "arialuni.ttf", "Arial Unicode MS", 12, 0, -1, 14, HINTING_THRESHOLD_LOW, nullptr },
} };
2017-01-03 22:57:15 +01:00
#endif // NO_TTF
static void LoadSpriteFont()
{
ttf_dispose();
gUseTrueTypeFont = false;
2017-01-04 13:51:12 +01:00
#ifndef NO_TTF
gCurrentTTFFontSet = nullptr;
2017-01-04 13:51:12 +01:00
#endif // NO_TTF
}
2017-01-03 22:57:15 +01:00
#ifndef NO_TTF
static bool LoadFont(TTFFontSetDescriptor * font)
{
gUseTrueTypeFont = true;
gCurrentTTFFontSet = font;
ttf_dispose();
bool fontInitialised = ttf_initialise();
return fontInitialised;
}
static bool LoadCustomConfigFont()
{
static TTFFontSetDescriptor TTFFontCustom = { {
{ gConfigFonts.file_name, gConfigFonts.font_name, gConfigFonts.size_tiny, gConfigFonts.x_offset, gConfigFonts.y_offset,
gConfigFonts.height_tiny, gConfigFonts.hinting_threshold, nullptr },
{ gConfigFonts.file_name, gConfigFonts.font_name, gConfigFonts.size_small, gConfigFonts.x_offset, gConfigFonts.y_offset,
gConfigFonts.height_small, gConfigFonts.hinting_threshold, nullptr },
{ gConfigFonts.file_name, gConfigFonts.font_name, gConfigFonts.size_medium, gConfigFonts.x_offset,
gConfigFonts.y_offset, gConfigFonts.height_medium, gConfigFonts.hinting_threshold, nullptr },
{ gConfigFonts.file_name, gConfigFonts.font_name, gConfigFonts.size_big, gConfigFonts.x_offset, gConfigFonts.y_offset,
gConfigFonts.height_big, gConfigFonts.hinting_threshold, nullptr },
} };
ttf_dispose();
gUseTrueTypeFont = true;
gCurrentTTFFontSet = &TTFFontCustom;
bool fontInitialised = ttf_initialise();
return fontInitialised;
}
2017-01-03 22:57:15 +01:00
#endif // NO_TTF
void TryLoadFonts()
{
2017-01-03 22:57:15 +01:00
#ifndef NO_TTF
2017-10-26 23:23:24 +02:00
TTFontFamily const * fontFamily = LanguagesDescriptors[gCurrentLanguage].font_family;
if (fontFamily != FAMILY_OPENRCT2_SPRITE)
{
if (!String::IsNullOrEmpty(gConfigFonts.file_name))
{
if (LoadCustomConfigFont())
{
return;
}
2017-10-30 15:39:36 +01:00
log_verbose("Unable to initialise configured TrueType font -- falling back to the language's default.");
}
2017-10-26 23:23:24 +02:00
for (auto &font : *fontFamily)
{
2017-10-26 23:23:24 +02:00
if (LoadFont(font))
{
return;
}
2017-10-26 23:23:24 +02:00
TTFFontDescriptor smallFont = font->size[FONT_SIZE_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)
{
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
for (auto &font : TTFFamilySansSerif)
{
if (LoadFont(font))
{
return;
}
TTFFontDescriptor smallFont = font->size[FONT_SIZE_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.");
}
}
2017-01-03 22:57:15 +01:00
#endif // NO_TTF
LoadSpriteFont();
}