mirror of https://github.com/OpenTTD/OpenTTD
(svn r23279) -Codechange: try to prevent slanted and skinny fonts with fontconfig. This should generally make the fallback choice better legible
parent
9835600cd1
commit
7f390964c3
|
@ -709,7 +709,7 @@ bool SetFallbackFont(FreeTypeSettings *settings, const char *language_isocode, i
|
||||||
/* First create a pattern to match the wanted language. */
|
/* First create a pattern to match the wanted language. */
|
||||||
FcPattern *pat = FcNameParse((FcChar8*)lang);
|
FcPattern *pat = FcNameParse((FcChar8*)lang);
|
||||||
/* We only want to know the filename. */
|
/* We only want to know the filename. */
|
||||||
FcObjectSet *os = FcObjectSetBuild(FC_FILE, FC_SPACING, NULL);
|
FcObjectSet *os = FcObjectSetBuild(FC_FILE, FC_SPACING, FC_SLANT, FC_WEIGHT, NULL);
|
||||||
/* Get the list of filenames matching the wanted language. */
|
/* Get the list of filenames matching the wanted language. */
|
||||||
FcFontSet *fs = FcFontList(NULL, pat, os);
|
FcFontSet *fs = FcFontList(NULL, pat, os);
|
||||||
|
|
||||||
|
@ -718,6 +718,9 @@ bool SetFallbackFont(FreeTypeSettings *settings, const char *language_isocode, i
|
||||||
FcPatternDestroy(pat);
|
FcPatternDestroy(pat);
|
||||||
|
|
||||||
if (fs != NULL) {
|
if (fs != NULL) {
|
||||||
|
int best_weight = -1;
|
||||||
|
const char *best_font = NULL;
|
||||||
|
|
||||||
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];
|
||||||
|
|
||||||
|
@ -727,21 +730,36 @@ bool SetFallbackFont(FreeTypeSettings *settings, const char *language_isocode, i
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* Get a font with the right spacing .*/
|
||||||
int value = 0;
|
int value = 0;
|
||||||
FcPatternGetInteger(font, FC_SPACING, 0, &value);
|
FcPatternGetInteger(font, FC_SPACING, 0, &value);
|
||||||
if (callback->Monospace() != (value == FC_MONO) && value != FC_DUAL) continue;
|
if (callback->Monospace() != (value == FC_MONO) && value != FC_DUAL) continue;
|
||||||
|
|
||||||
|
/* Do not use those that explicitly say they're slanted. */
|
||||||
|
FcPatternGetInteger(font, FC_SLANT, 0, &value);
|
||||||
|
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);
|
callback->SetFontNames(settings, (const char*)file);
|
||||||
|
|
||||||
bool missing = callback->FindMissingGlyphs(NULL);
|
bool missing = callback->FindMissingGlyphs(NULL);
|
||||||
DEBUG(freetype, 1, "Font \"%s\" misses%s glyphs", file, missing ? "" : " no");
|
DEBUG(freetype, 1, "Font \"%s\" misses%s glyphs", file, missing ? "" : " no");
|
||||||
|
|
||||||
if (!missing) {
|
if (!missing) {
|
||||||
ret = true;
|
best_weight = value;
|
||||||
break;
|
best_font = (const char *)file;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (best_font != NULL) {
|
||||||
|
ret = true;
|
||||||
|
callback->SetFontNames(settings, best_font);
|
||||||
|
InitFreeType(callback->Monospace());
|
||||||
|
}
|
||||||
|
|
||||||
/* Clean up the list of filenames. */
|
/* Clean up the list of filenames. */
|
||||||
FcFontSetDestroy(fs);
|
FcFontSetDestroy(fs);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue