[Fontconfig] trying to specify fonts for a specific language

Akira TAGOH akira at tagoh.org
Thu Nov 21 22:22:22 PST 2013

On Fri, Nov 22, 2013 at 1:07 AM, Derek Leach <DLeach at qnx.com> wrote:
> We have this in the fonts.conf file:
> <!--
>   Korean characters should be rasterized from the 'NewHD' font.
> -->
>    <match target="font">
>       <test name="lang" compare="contains"><string>ko</string></test>
>       <edit name="family" mode="prepend" binding="strong">               <-- I have also tried weak, and no binding at all -->
>               <string>NewHDR</string>
>       </edit>
>    </match>

doing like that in target="font" is wrong. that means you are about to
add NewHDR family name into the matched font pattern. fontconfig
already determines better font at that point. given that FontA is
better for the certain query, that recipe is adding NewHDR to the
pattern for FontA. which in fact just looks like an alias name for

> At this point, code has discovered that NewHDB does not have 0x60c5.
> So this next code executes:
> lang is "ko"
> genericFamily is "sans-serif"
> FcPattern* pattern = FcPatternBuild(
>                 NULL,
>                 FC_LANG, FcTypeString, lang,
>                 FC_FAMILY, FcTypeString, genericFamily,
>                 FC_SCALABLE, FcTypeBool, true,
>                 (const char *)NULL
>         );
> FcConfigSubstitute(0, pattern, FcMatchPattern);
> FcDefaultSubstitute(pattern);
> FcResult result;
> FcPattern* match = NULL;
> FcFontSet *fs = NULL;
> fs = FcFontSort(NULL, pattern, FcTrue, NULL, &result);

the above recipe isn't yet evaluated at this point, but target="pattern".

> At this point, 'fs' contains practically every font on the target system.
> Why not just the ones listed in the lang "ko" section, i.e. NewHDR?

Even if you do the above with target="pattern", the result from
FcFontSort() may contains patterns not matching lang="ko". it really
depends on other recipes. it is just building better patterns against
recipes on your box.
You need to call FcFontRenderPrepare() to evaluate target="font" and
finalize to get the result of better fonts against your query, or just
call FcFontMatch().

> So I guess my questions are:
> What's wrong with the fonts.conf lang "ko" section?
> Why does 'fs' contains all these fonts, even though we pass FC_LANG of "ko"?
> Why is NewHDB returned in 'match', even though NewHDR is the only one listed in this section?
> Many Thanks, sorry for all the questions! :)
> Derek
> _______________________________________________
> Fontconfig mailing list
> Fontconfig at lists.freedesktop.org
> http://lists.freedesktop.org/mailman/listinfo/fontconfig


More information about the Fontconfig mailing list