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

Elias MÃ¥rtenson lokedhs at gmail.com
Sun Jul 1 14:59:27 UTC 2018


On 1 July 2018 at 18:00, Akira TAGOH <akira at tagoh.org> wrote:

> Hi,
>

Hello Akira, and thanks for your reply.


> Exactly speaking, there are three types of matching pattern in
> fontconfig though, trying to mention only two here in a question.
>

The third one is FcMatchScan, I presume? That one is even
more confusing to me, and the only reason I never mentioned
it is that I really don't understand that one at all.


> FcFontMatch() will evaluates the best font against this result.
>
speaking more details, FcFontRenderprepare() will calls the sort of
> FcConfigSubstitite() with FcMatchFont in FcFontMatch(), to evaluate
> that pattern against fonts on the system and then returns best font.
> So basically you don't need to worry about FcMatchFont unless you
> yourself need to emulate something in fontconfig to match on fonts.


Based on what you just told me, FcFontRenderPrepare is what
I should be using, and I've just spent a little time playing around
with it. However, I seem unable to make it return anything useful
at all. The reason for this is probably that I am using it wrong
and/or that my expectations are wrong.

Perhaps it's easier if I explain what my needs are for my McCLIM
work. I'm hoping that perhaps you or someone else could share
your expertise and give me some pointers as to which functions I
should be using to achieve what I need.

Please don't take my questions as demands. It's probably very
likely that I simply don't understand what Fontconfig can and
cannot do.

What I'm trying to do is the following:

1:

Find the "best" font to use for all permutations of the following:
    Typeface: Serif, Sans-serif, Monospace
    Style: Plain, Italic, Bold, Bold-Italic

In other words, the user may choose "Serif + Italic" or
"Monospace + Bold" and my code needs return the correct (or
"best", whatever that means) font for Freetype to load. If such
font doesn't exist, I can fall back to "Plain" style.

2:

Given a specific font (probably from the result of a solution
to (1)), and a given character, (for example U+1D161 MUSICAL SYMBOL
SIXTEENTH NOTE,
which I have been using in my tests, since I have very few
fonts that contain this character), provide the "best" font that
contains this character.

At this point, I'm not even entirely sure that Fontconfig is able
to actually do what I need, but if it is, I'd be extremely thankful
if someone could help me out by giving specific pointers as to
how to do it.

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


More information about the Fontconfig mailing list