diff options
author | rubidium <rubidium@openttd.org> | 2011-11-20 12:10:41 +0000 |
---|---|---|
committer | rubidium <rubidium@openttd.org> | 2011-11-20 12:10:41 +0000 |
commit | 7f390964c3202212a696302d774256a950b621d9 (patch) | |
tree | ac8fcc082d6cc69a306184e5a8c3bfdb728792a5 | |
parent | 9835600cd186a2b73513674fbebec9cf041aff98 (diff) | |
download | openttd-7f390964c3202212a696302d774256a950b621d9.tar.xz |
(svn r23279) -Codechange: try to prevent slanted and skinny fonts with fontconfig. This should generally make the fallback choice better legible
-rw-r--r-- | src/fontcache.cpp | 24 |
1 files changed, 21 insertions, 3 deletions
diff --git a/src/fontcache.cpp b/src/fontcache.cpp index 3eb717c30..507ee2940 100644 --- a/src/fontcache.cpp +++ b/src/fontcache.cpp @@ -709,7 +709,7 @@ bool SetFallbackFont(FreeTypeSettings *settings, const char *language_isocode, i /* First create a pattern to match the wanted language. */ FcPattern *pat = FcNameParse((FcChar8*)lang); /* 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. */ FcFontSet *fs = FcFontList(NULL, pat, os); @@ -718,6 +718,9 @@ bool SetFallbackFont(FreeTypeSettings *settings, const char *language_isocode, i FcPatternDestroy(pat); if (fs != NULL) { + int best_weight = -1; + const char *best_font = NULL; + for (int i = 0; i < fs->nfont; i++) { FcPattern *font = fs->fonts[i]; @@ -727,21 +730,36 @@ bool SetFallbackFont(FreeTypeSettings *settings, const char *language_isocode, i continue; } + /* Get a font with the right spacing .*/ int value = 0; FcPatternGetInteger(font, FC_SPACING, 0, &value); 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); bool missing = callback->FindMissingGlyphs(NULL); DEBUG(freetype, 1, "Font \"%s\" misses%s glyphs", file, missing ? "" : " no"); if (!missing) { - ret = true; - break; + best_weight = value; + 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. */ FcFontSetDestroy(fs); } |