@@ -138,13 +138,15 @@ void LoadFreeTypeFont(FontSize fs)
}
const char *font_name = settings->font.c_str();
FT_Face face = nullptr;
/* 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) {
/* Check if font is a relative filename in one of our search-paths. */
std::string full_font = FioFindFullPath(BASE_DIR, font_name);
if (!full_font.empty()) {
error = FT_New_Face(_library, full_font.c_str(), 0, &face);
@@ -108,24 +108,25 @@ bool SetFallbackFont(FontCacheSettings *
* before the _ of e.g. en_GB is used, so "remove" everything after
* the _. */
std::string lang = fmt::format(":lang={}", language_isocode.substr(0, language_isocode.find('_')));
/* First create a pattern to match the wanted language. */
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);
/* We only want to know these attributes. */
FcObjectSet *os = FcObjectSetBuild(FC_FILE, FC_INDEX, FC_SPACING, FC_SLANT, FC_WEIGHT, nullptr);
/* Get the list of filenames matching the wanted language. */
FcFontSet *fs = FcFontList(nullptr, pat, os);
/* We don't need these anymore. */
FcObjectSetDestroy(os);
FcPatternDestroy(pat);
if (fs != nullptr) {
int best_weight = -1;
const char *best_font = nullptr;
int best_index = 0;
for (int i = 0; i < fs->nfont; i++) {
FcPattern *font = fs->fonts[i];
FcChar8 *file = nullptr;
FcResult res = FcPatternGetString(font, FC_FILE, 0, &file);
@@ -143,26 +144,32 @@ bool SetFallbackFont(FontCacheSettings *
if (value != 0) continue;
/* We want the fatter font as they look better at small sizes. */
FcPatternGetInteger(font, FC_WEIGHT, 0, &value);
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();
Debug(fontcache, 1, "Font \"{}\" misses{} glyphs", (char *)file, missing ? "" : " no");
if (!missing) {
best_weight = value;
best_font = (const char *)file;
best_index = index;
if (best_font != nullptr) {
ret = true;
callback->SetFontNames(settings, best_font);
callback->SetFontNames(settings, best_font, &best_index);
InitFontCache(callback->Monospace());
/* Clean up the list of filenames. */
FcFontSetDestroy(fs);
Status change: