Comment 113 for bug 105900

Revision history for this message
In , Pgajdos-f (pgajdos-f) wrote :

Hi again,

the workaround for fc-match:

--- fontconfig-2.8.0.orig/src/fcmatch.c
+++ fontconfig-2.8.0/src/fcmatch.c
@@ -413,6 +413,56 @@ FcFontRenderPrepare (FcConfig *confi
        }
        else
            v = FcValueCanonicalize(&FcPatternEltValues (fe)->value);
+
+ /* This is workaround only!! */
+ if (fe->object == FC_STYLE_OBJECT)
+ {
+ FcPatternElt *le, *sle;
+ FcValue lang, stlang, style;
+ FcValueList *stlangs, *sts, *en_style;
+ int l;
+
+ /* Try to learn lang from pat. */
+ if ((le = FcPatternObjectFindElt(pat, FC_LANG_OBJECT)))
+ lang = FcValueCanonicalize(&FcPatternEltValues(le)->value);
+ else /* FC_LANG_OBJECT not found in pat. I think it can't happen. */
+ {
+ lang.type = FcTypeString;
+ lang.u.s = (const FcChar8 *)"en";
+ }
+
+ sle = FcPatternObjectFindElt(font, FC_STYLELANG_OBJECT); /* element of font containing */
+ sts = FcPatternEltValues(fe); /* styles translations associated to font */
+ /* langs of styles translations */
+
+ en_style = 0;
+ if (sle) /* style elt can be present, stylelang no (e. g. fc-match Times) */
+ { /* if so, sts list contain only one value, so we can jump to style = .. */
+ stlangs = FcPatternEltValues(sle);
+ l = 0;
+
+ do /* Find style corresponding to lang(.u.s). */
+ {
+ stlang = FcValueCanonicalize(&stlangs->value);
+ if (FcLangCompare(stlang.u.s, lang.u.s) < FcLangDifferentLang)
+ break;
+ if (FcLangCompare(stlang.u.s, "en") < FcLangDifferentLang)
+ en_style = sts; /* Will be used when translation not found for lang. */
+ sts = FcValueListNext(sts);
+ l++;
+ } while ((stlangs = FcValueListNext(stlangs)));
+ }
+
+ if (sts) /* Style translation was found for lang.u.s. */
+ style = FcValueCanonicalize(&sts->value);
+ else if (en_style) /* Not found, try English. */
+ style = FcValueCanonicalize(&en_style->value);
+ else /* Nor English found, take first one. */
+ style = FcValueCanonicalize(&FcPatternEltValues(fe)->value);
+
+ v.u.s = style.u.s;
+ }
+
        FcPatternObjectAdd (new, fe->object, v, FcFalse);
     }
     for (i = 0; i < pat->num; i++)