[Fontconfig] How to use FcFontMatch to find a font with a given character

Elias Mårtenson lokedhs at gmail.com
Sat Jun 30 16:41:01 UTC 2018


On 29 June 2018 at 19:12, Lawrence D'Oliveiro <ldo at geek-central.gen.nz>
wrote:

> On Fri, 29 Jun 2018 18:12:40 +0800, Elias Mårtenson wrote:
>
> > When I use FcMatchPattern, the program returns DejaVuSans.ttf. If I
> > use FcMatchFont instead, it returns FreeMono.ttf.
> >
> > The interesting thing is that none of these fonts actually contains
> > U+0x63A (checked by reading the "charset" value).
>
> I’m not sure what the difference is, but I gather that Fontconfig never
> fails to return a font, as long as it can find at least one on your
> system.


Indeed, and FcFontMatch does always return a font. However, which font it
actually returns changes depending on the argument I use to
FcConfigSubstitute.
Sometimes, it seems as though the result I get from when kind is set to
FcMatchFont is better (using a purely subjective definition of "better")
than what I
get when using FcMatchPattern. However, when I have searched for the use of
this function, people in general seem to use the latter.

The documentation for FcConfigSubstitute has the following to say about the
"kind" parameter, and I have frankly no idea what it means:

*    "Performs the sequence of pattern modification operations, if kind is
FcMatchPattern,*
*    then those tagged as pattern operations are applied, else if kind is
FcMatchFont,*
*    those tagged as font operations are applied and p_pat is used for
<test> elements*

*    with target=pattern."*

Remember that Fontconfig is all about “best effort” to match
> what you require, rather than “perfect match”. I think FcMatchPattern is
> the right one to use. You can then scan the list of candidates returned,
> querying their actual “charset” properties to see which one(s) are
> sufficient for your needs.
>

FcMatchFont always returns only one result though.


> By the way, just checked DejaVu Sans on my system, and it does indeed
> have “U+063A ARABIC LETTER GHAIN”.
>

Do it does. I've been testing with U+03C6 GREEK SMALL LETTER PHI, and it
does exist in DejaVu Sans, Fontconfig correctly finds it when I query for
fonts
that contain this character, but when I use FcCharSetFirstPage and
FcCharSetNextPage, the resulting bitmaps indicates that this character does
not exist.

Bug in Fontconfig?

Regards,
Elias
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.freedesktop.org/archives/fontconfig/attachments/20180701/bea494f6/attachment.html>


More information about the Fontconfig mailing list