Merge branch 'master' into jgrpp

# Conflicts:
#	os/macosx/notarize.sh
#	src/3rdparty/CMakeLists.txt
#	src/3rdparty/squirrel/squirrel/sqcompiler.cpp
#	src/3rdparty/squirrel/squirrel/sqdebug.cpp
#	src/3rdparty/squirrel/squirrel/sqvm.cpp
#	src/console_cmds.cpp
#	src/core/span_type.hpp
#	src/crashlog.cpp
#	src/currency.h
#	src/date_gui.cpp
#	src/driver.cpp
#	src/fios.cpp
#	src/genworld_gui.cpp
#	src/hotkeys.cpp
#	src/misc_gui.cpp
#	src/music/os2_m.cpp
#	src/network/core/os_abstraction.h
#	src/network/network_server.cpp
#	src/newgrf.cpp
#	src/newgrf_config.h
#	src/newgrf_text.cpp
#	src/openttd.cpp
#	src/os/macosx/font_osx.cpp
#	src/os/macosx/misc_osx.cpp
#	src/os/os2/CMakeLists.txt
#	src/os/os2/os2.cpp
#	src/os/unix/CMakeLists.txt
#	src/os/windows/font_win32.cpp
#	src/os/windows/win32_main.cpp
#	src/saveload/saveload.cpp
#	src/script/api/script_text.cpp
#	src/settings.cpp
#	src/settings_gui.cpp
#	src/stdafx.h
#	src/strings.cpp
#	src/timetable_gui.cpp
#	src/town_gui.cpp
#	src/train_cmd.cpp
#	src/video/dedicated_v.cpp
#	src/video/video_driver.cpp
#	src/video/win32_v.cpp
#	src/viewport.cpp
#	src/waypoint_gui.cpp
#	src/widgets/dropdown_type.h
#	src/window.cpp
#	src/window_gui.h
This commit is contained in:
Jonathan G Rennison
2023-09-12 20:06:47 +01:00
242 changed files with 4733 additions and 6402 deletions

View File

@@ -17,13 +17,25 @@
#include "safeguards.h"
#ifdef WITH_FREETYPE
#include <ft2build.h>
#include FT_FREETYPE_H
extern FT_Library _library;
/**
* Split the font name into the font family and style. These fields are separated by a comma,
* but the style does not necessarily need to exist.
* @param font_name The font name.
* @return The font family and style.
*/
static std::tuple<std::string, std::string> SplitFontFamilyAndStyle(std::string_view font_name)
{
auto separator = font_name.find(',');
if (separator == std::string_view::npos) return { std::string(font_name), std::string() };
auto begin = font_name.find_first_not_of("\t ", separator + 1);
return { std::string(font_name.substr(0, separator)), std::string(font_name.substr(begin)) };
}
FT_Error GetFontByFaceName(const char *font_name, FT_Face *face)
{
@@ -37,39 +49,26 @@ FT_Error GetFontByFaceName(const char *font_name, FT_Face *face)
auto fc_instance = FcConfigReference(nullptr);
assert(fc_instance != nullptr);
FcPattern *match;
FcPattern *pat;
FcFontSet *fs;
FcResult result;
char *font_style;
char *font_family;
/* Split & strip the font's style */
font_family = stredup(font_name);
font_style = strchr(font_family, ',');
if (font_style != nullptr) {
font_style[0] = '\0';
font_style++;
while (*font_style == ' ' || *font_style == '\t') font_style++;
}
auto [font_family, font_style] = SplitFontFamilyAndStyle(font_name);
/* Resolve the name and populate the information structure */
pat = FcNameParse((FcChar8 *)font_family);
if (font_style != nullptr) FcPatternAddString(pat, FC_STYLE, (FcChar8 *)font_style);
FcPattern *pat = FcNameParse((FcChar8 *)font_family.data());
if (!font_style.empty()) FcPatternAddString(pat, FC_STYLE, (FcChar8 *)font_style.data());
FcConfigSubstitute(nullptr, pat, FcMatchPattern);
FcDefaultSubstitute(pat);
fs = FcFontSetCreate();
match = FcFontMatch(nullptr, pat, &result);
FcFontSet *fs = FcFontSetCreate();
FcResult result;
FcPattern *match = FcFontMatch(nullptr, pat, &result);
if (fs != nullptr && match != nullptr) {
int i;
FcChar8 *family;
FcChar8 *style;
FcChar8 *file;
int32_t index;
FcFontSetAdd(fs, match);
for (i = 0; err != FT_Err_Ok && i < fs->nfont; i++) {
for (int i = 0; err != FT_Err_Ok && i < fs->nfont; i++) {
/* Try the new filename */
if (FcPatternGetString(fs->fonts[i], FC_FILE, 0, &file) == FcResultMatch &&
FcPatternGetString(fs->fonts[i], FC_FAMILY, 0, &family) == FcResultMatch &&
@@ -77,7 +76,7 @@ FT_Error GetFontByFaceName(const char *font_name, FT_Face *face)
FcPatternGetInteger(fs->fonts[i], FC_INDEX, 0, &index) == FcResultMatch) {
/* The correct style? */
if (font_style != nullptr && !StrEqualsIgnoreCase(font_style, (char *)style)) continue;
if (!font_style.empty() && !StrEqualsIgnoreCase(font_style, (char *)style)) continue;
/* Font config takes the best shot, which, if the family name is spelled
* wrongly a 'random' font, so check whether the family name is the
@@ -89,7 +88,6 @@ FT_Error GetFontByFaceName(const char *font_name, FT_Face *face)
}
}
free(font_family);
FcPatternDestroy(pat);
FcFontSetDestroy(fs);
FcConfigDestroy(fc_instance);
@@ -97,10 +95,7 @@ FT_Error GetFontByFaceName(const char *font_name, FT_Face *face)
return err;
}
#endif /* WITH_FREETYPE */
bool SetFallbackFont(FontCacheSettings *settings, const char *language_isocode, int winlangid, MissingGlyphSearcher *callback)
bool SetFallbackFont(FontCacheSettings *settings, const std::string &language_isocode, int winlangid, MissingGlyphSearcher *callback)
{
bool ret = false;
@@ -112,13 +107,10 @@ bool SetFallbackFont(FontCacheSettings *settings, const char *language_isocode,
/* Fontconfig doesn't handle full language isocodes, only the part
* before the _ of e.g. en_GB is used, so "remove" everything after
* the _. */
char lang[16];
seprintf(lang, lastof(lang), ":lang=%s", language_isocode);
char *split = strchr(lang, '_');
if (split != nullptr) *split = '\0';
std::string lang = ":lang=" + language_isocode.substr(0, language_isocode.find('_'));
/* First create a pattern to match the wanted language. */
FcPattern *pat = FcNameParse((FcChar8 *)lang);
FcPattern *pat = FcNameParse((const FcChar8 *)lang.c_str());
/* We only want to know the filename. */
FcObjectSet *os = FcObjectSetBuild(FC_FILE, FC_SPACING, FC_SLANT, FC_WEIGHT, nullptr);
/* Get the list of filenames matching the wanted language. */