[Fontconfig] trying to specify fonts for a specific language
Derek Leach
DLeach at qnx.com
Thu Nov 21 08:07:55 PST 2013
Hi all,
I have inherited a system that uses the fontconfig 2.8.0 library.
In this particular case, we wish to render Unicode 0x60c5.
Font NewHDR contains it, while NewHDB does not.
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>
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);
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?
The code then has:
for(int i = 0; i < fs->nfont; i++)
{ FcPatternGetLangSet(fs->fonts[i], FC_LANG, 0, &langset);
FcLangResult langresult = FcLangSetHasLang(langset, (FcChar8*) lang);
if(langresult != FcLangDifferentLang)
{ char const * str = NULL;
int result;
result = FcPatternGetString(fs->fonts[i], FC_FAMILY, 0, &str);
if(bypass_family != NULL && result == FcResultMatch)
{
match = fs->fonts[i];
break;
}
}
In this case, 'match' actually turns out to point to NewHDB, which is not even
in the lang "ko" section of the fonts.conf file.
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
More information about the Fontconfig
mailing list