From 565243e032009b7022b49c085b1157c3fb4986d4 Mon Sep 17 00:00:00 2001 From: "agl@chromium.org" Date: Tue, 14 Jul 2009 05:14:07 +0000 Subject: Linux: workaround a fontconfig bug. Fontconfig cannot filter out non-scalable fonts on Hardy. http://codereview.chromium.org/149482 BUG=16411 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@20604 0039d316-1c4b-4281-b951-d872f2087c98 --- skia/ext/SkFontHost_fontconfig_direct.cpp | 39 ++++++++++++++++++++++++------- 1 file changed, 31 insertions(+), 8 deletions(-) (limited to 'skia') diff --git a/skia/ext/SkFontHost_fontconfig_direct.cpp b/skia/ext/SkFontHost_fontconfig_direct.cpp index 9fd1252..7f7be08 100644 --- a/skia/ext/SkFontHost_fontconfig_direct.cpp +++ b/skia/ext/SkFontHost_fontconfig_direct.cpp @@ -115,12 +115,35 @@ bool FontConfigDirect::Match(std::string* result_family, FcPatternGetString(pattern, FC_FAMILY, 0, &post_config_family); FcResult result; - FcPattern* match = FcFontMatch(0, pattern, &result); - if (!match) { + FcFontSet* font_set = FcFontSort(0, pattern, 0, 0, &result); + if (!font_set) { FcPatternDestroy(pattern); return false; } + // Older versions of fontconfig have a bug where they cannot select + // only scalable fonts so we have to manually filter the results. + FcPattern* match = NULL; + for (int i = 0; i < font_set->nfont; ++i) { + FcPattern* current = font_set->fonts[i]; + FcBool is_scalable; + + if (FcPatternGetBool(current, FC_SCALABLE, 0, + &is_scalable) != FcResultMatch || + !is_scalable) { + continue; + } + + match = current; + break; + } + + if (!match) { + FcPatternDestroy(pattern); + FcFontSetDestroy(font_set); + return false; + } + FcChar8* post_match_family; FcPatternGetString(match, FC_FAMILY, 0, &post_match_family); const bool family_names_match = @@ -131,14 +154,14 @@ bool FontConfigDirect::Match(std::string* result_family, FcPatternDestroy(pattern); if (!family_names_match && !IsFallbackFontAllowed(family)) { - FcPatternDestroy(match); + FcFontSetDestroy(font_set); return false; } FcChar8* c_filename; if (FcPatternGetString(match, FC_FILE, 0, &c_filename) != FcResultMatch) { - FcPatternDestroy(match); - return NULL; + FcFontSetDestroy(font_set); + return false; } const std::string filename((char *) c_filename); @@ -162,8 +185,8 @@ bool FontConfigDirect::Match(std::string* result_family, FcChar8* c_family; if (FcPatternGetString(match, FC_FAMILY, 0, &c_family)) { - FcPatternDestroy(match); - return NULL; + FcFontSetDestroy(font_set); + return false; } int resulting_bold; @@ -195,7 +218,7 @@ bool FontConfigDirect::Match(std::string* result_family, if (result_family) *result_family = (char *) c_family; - FcPatternDestroy(match); + FcFontSetDestroy(font_set); return true; } -- cgit v1.1