Ubuntu – the difference between target=“font” and target=“pattern” in fontconfig

fonts

I am trying to understand why some of tests in my fonts.conf work with <match target="pattern"> (the default), another ones with <match target="font">, and not at all otherwise. For example:

<match>
    <test name="family"><string>monospace</string></test>        
    <edit name="family"><string>Cousine</string></edit>
</match>

<match>
    <test name="family"><string>Cousine</string></test>
    <test name="pixelsize" compare="more"><double>17.5</double></test>
    <edit name="family" binding="strong"><string>Liberation Mono</string></edit>
</match>

<match target="font">
    <test name="family"><string>Overpass</string></test>        
    <edit name="hintstyle"><const>hintslight</const></edit>
</match>

Why is that? I have read the documentation and it only says If 'target' is set to "font" instead of the default "pattern", then this element applies to the font name resulting from a match rather than a font pattern to be matched. I do not understand the wording, can someone explain the difference?

Best Answer

From:

https://lists.freedesktop.org/archives/fontconfig/2007-December/002787.html

Applications typically work like this:

  1. Convert user's font request to a fontconfig pattern;
  2. Apply fontconfig configuration on it using target="pattern";
  3. Get a sorted list of fonts matching that pattern from fontconfig. The list is returned as a set of fontconfig patterns itself;
  4. Choose the font to use (typically the first one having the requested character);
  5. Apply fontconfig configuration on the font pattern using target="font".

So, what it means is that for example if you want to turn off antialiasing on Bitstream Vera Sans for sizes less than 7.5, you should do that using target="font". If you do it with target="pattern", it will turn off aa for all fonts if the request is Bitstream Vera Sans, regardless of whether you have that font installed or not.

If you want to write fallback rules such that DejaVu Sans be substituted for Bitstream Vera Sans, that's done with target="pattern", because you want to modify the request.

And also from:

https://lists.freedesktop.org/archives/fontconfig/2003-March/000128.html

Use the font target for all changes to how a particular font is rendered and pattern target for changes in how a font is selected from those available.

Related Question