[Fontconfig] fontconfig match question

Owen Taylor otaylor at redhat.com
Mon Jul 17 09:22:23 PDT 2006

On Mon, 2006-07-17 at 12:05 -0400, Stephen C. North wrote:
> OK, "fail over to a default font" may not be quite the right way to describe
> what happens.  At the end of the day, when fontconfig can't resolve a request
> like "Cursive-Script-Like-Don-Knuth's-Handwriting at 12 pt" to anything
> better, its rule of last resort substitutes a system default like "Sans".
> In our world, we would consider this worth a runtime warning.  So, how can
> I tell if the last resort rule was matched?  Just check if the family
> is "Sans" when we didn't ask for "Sans"?

Basically, what you want to do is detect whether the resulting font

 A) The family that was originally specified
 B) A family that was added by an alias rule, except for families
    resulting indirectly from the rule in the default config:
    "If the font still has no generic name, add sans-serif"

But that's hard to do. An approximation might be:

 - If the user specifies sans-serif, sans, mono, monospace, serif,
   never warn.

 - Otherwise warn unless the font matches a "strongly bound" family
   name in the config-expanded pattern

(Aliases like "sans-serif" are weak, and result in tagging the expanded
family names differently from strong aliases. Maybe someone can give
a more detailed recipe for how to do the above giving the fontconfig

This isn't perfect, and could give false-positive warnings, especially
with custom font configurations, but would probably normally work pretty

The basic problem, however, is that fontconfig simply has no idea of 
failure. As long as you have a single font on your system, it thinks
the match succeeded.

> BTW, it's impressive that a request for Arial can be resolved to Albany AMT.
> How was that knowledge built into fontconfig?  Rule by painstaking rule,
> defined manually by the fontconfig developers?
Yes. (or by the system integrator)

More information about the Fontconfig mailing list