mirror of https://github.com/OpenTTD/OpenTTD
Codechange: Pass face index as font os_handle for FreeType fonts. (#11073)
This allows fallback font detection to test the specific face within the font rather instead of only the first.pull/11075/head
parent
794b642b9a
commit
8465559488
|
@ -141,7 +141,9 @@ void LoadFreeTypeFont(FontSize fs)
|
||||||
FT_Face face = nullptr;
|
FT_Face face = nullptr;
|
||||||
|
|
||||||
/* If font is an absolute path to a ttf, try loading that first. */
|
/* If font is an absolute path to a ttf, try loading that first. */
|
||||||
FT_Error error = FT_New_Face(_library, font_name, 0, &face);
|
int32_t index = 0;
|
||||||
|
if (settings->os_handle != nullptr) index = *static_cast<const int32_t *>(settings->os_handle);
|
||||||
|
FT_Error error = FT_New_Face(_library, font_name, index, &face);
|
||||||
|
|
||||||
if (error != FT_Err_Ok) {
|
if (error != FT_Err_Ok) {
|
||||||
/* Check if font is a relative filename in one of our search-paths. */
|
/* Check if font is a relative filename in one of our search-paths. */
|
||||||
|
|
|
@ -111,8 +111,8 @@ bool SetFallbackFont(FontCacheSettings *settings, const std::string &language_is
|
||||||
|
|
||||||
/* First create a pattern to match the wanted language. */
|
/* First create a pattern to match the wanted language. */
|
||||||
FcPattern *pat = FcNameParse((const FcChar8 *)lang.c_str());
|
FcPattern *pat = FcNameParse((const FcChar8 *)lang.c_str());
|
||||||
/* We only want to know the filename. */
|
/* We only want to know these attributes. */
|
||||||
FcObjectSet *os = FcObjectSetBuild(FC_FILE, FC_SPACING, FC_SLANT, FC_WEIGHT, nullptr);
|
FcObjectSet *os = FcObjectSetBuild(FC_FILE, FC_INDEX, FC_SPACING, FC_SLANT, FC_WEIGHT, nullptr);
|
||||||
/* Get the list of filenames matching the wanted language. */
|
/* Get the list of filenames matching the wanted language. */
|
||||||
FcFontSet *fs = FcFontList(nullptr, pat, os);
|
FcFontSet *fs = FcFontList(nullptr, pat, os);
|
||||||
|
|
||||||
|
@ -123,6 +123,7 @@ bool SetFallbackFont(FontCacheSettings *settings, const std::string &language_is
|
||||||
if (fs != nullptr) {
|
if (fs != nullptr) {
|
||||||
int best_weight = -1;
|
int best_weight = -1;
|
||||||
const char *best_font = nullptr;
|
const char *best_font = nullptr;
|
||||||
|
int best_index = 0;
|
||||||
|
|
||||||
for (int i = 0; i < fs->nfont; i++) {
|
for (int i = 0; i < fs->nfont; i++) {
|
||||||
FcPattern *font = fs->fonts[i];
|
FcPattern *font = fs->fonts[i];
|
||||||
|
@ -146,7 +147,12 @@ bool SetFallbackFont(FontCacheSettings *settings, const std::string &language_is
|
||||||
FcPatternGetInteger(font, FC_WEIGHT, 0, &value);
|
FcPatternGetInteger(font, FC_WEIGHT, 0, &value);
|
||||||
if (value <= best_weight) continue;
|
if (value <= best_weight) continue;
|
||||||
|
|
||||||
callback->SetFontNames(settings, (const char *)file);
|
/* Possible match based on attributes, get index. */
|
||||||
|
int32_t index;
|
||||||
|
res = FcPatternGetInteger(font, FC_INDEX, 0, &index);
|
||||||
|
if (res != FcResultMatch) continue;
|
||||||
|
|
||||||
|
callback->SetFontNames(settings, (const char *)file, &index);
|
||||||
|
|
||||||
bool missing = callback->FindMissingGlyphs();
|
bool missing = callback->FindMissingGlyphs();
|
||||||
Debug(fontcache, 1, "Font \"{}\" misses{} glyphs", (char *)file, missing ? "" : " no");
|
Debug(fontcache, 1, "Font \"{}\" misses{} glyphs", (char *)file, missing ? "" : " no");
|
||||||
|
@ -154,12 +160,13 @@ bool SetFallbackFont(FontCacheSettings *settings, const std::string &language_is
|
||||||
if (!missing) {
|
if (!missing) {
|
||||||
best_weight = value;
|
best_weight = value;
|
||||||
best_font = (const char *)file;
|
best_font = (const char *)file;
|
||||||
|
best_index = index;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (best_font != nullptr) {
|
if (best_font != nullptr) {
|
||||||
ret = true;
|
ret = true;
|
||||||
callback->SetFontNames(settings, best_font);
|
callback->SetFontNames(settings, best_font, &best_index);
|
||||||
InitFontCache(callback->Monospace());
|
InitFontCache(callback->Monospace());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue