5

Original question

I downloaded the Cozette font, which includes CozetteVector.ttf and CozetteVector.otf. I copied both of these files to ~/.local/share/fonts and ran fc-cache -v ~/.local/share/fonts. Now when I run fc-list | grep -i cozette, I can see that both the TTF and OTF versions are listed, with the same name, CozetteVector:style=Regular.

When I select the CozetteVector font in a graphical program, which font will be used?

How does Fontconfig handle this situation?

Will having both versions cause problems or create conflicts?


Additional context on why this might occur, and why someone might care

On Fedora 35, font packages often include both OTF and TTF formats of the same font. For example, redhat-text-fonts package includes both /usr/share/fonts/redhat/RedHatText-LightItalic.otf and /usr/share/fonts/redhat/RedHatText-LightItalic.ttf.

I have also encountered a situation where I "installed" a font manually by copying it to ~/.local/share/fonts and running fc-cache -f, but then I later installed the same fonts with a system-provided package. Now I have the same font files, defining the same font families, in two entirely different directories. The filenames might be exactly identical, or there might be some variations.

Usually the duplicates are actually duplicates and the difference doesn't matter. But sometimes these conflicts are nontrivial, e.g. one version is a variable font while another version isn't, or one version includes several stylistic sets while the other version doesn't.

2 Answers 2

3

Which?

Could be in the order it scans fonts. Try and check document properties.

Also you may try something like and see if order is not stable: fc-match -f '%{fullname} %{file}\n' CozetteVector

Problems?

No, font-config deals with them as separate font as long they are separate files.

The order may depend on application making the query. Here is the reference:font-config user configuration (FreeDesktop project)

Fontconfig rule example to change font priority

:) I missed the bounty, anyway it was something that kept hunting me to check in depth.

Here is an example that manipulate the priority between both types of same font:

~/.config/fontconfig/conf.d/00-custom.conf

<?xml version="1.0"?>
<!DOCTYPE fontconfig SYSTEM "fonts.dtd">
<fontconfig>

 <!-- this drop a font from matching, also allow matching with font type
 <selectfont>
  <rejectfont>
   <pattern>
     <patelt name="family"><string>CozetteVector</string></patelt>
   </pattern>
  </rejectfont>
 </selectfont>
 -->

 <!-- this forces a type
 <match>
  <test name="family">
   <string>CozetteVector</string>
  </test>
  <edit mode="prepend" name="fontformat">
   <string>TrueType</string>
  </edit>
 </match>
 -->

 <!-- this prioritize the last one which appended, this is for TTF then OTF --> 
 <match>
  <test name="family">
   <string>CozetteVector</string>
  </test>
  <edit mode="prepend" name="fontformat">
   <string>CFF</string>
  </edit>
 </match>

<match>
  <test name="family">
   <string>CozetteVector</string>
  </test>
  <edit mode="prepend" name="fontformat">
   <string>TrueType</string>
  </edit>
 </match>

</fontconfig>

Debug fontconfig matching and review font properties

You can review manpage for advanced matching. Also using fc-match -av ... or FC_DEBUG=1 fc-match ... to know available properties and their value for each font.

Notes

  • OTF is more advanced then TTF, I wont be surprised if fontconfig prioritize OTF over TTF. However, I don't have prove that support it my claim, but I suspect to be somewhere inside upstream fontconfig configuration, similar to disabled bitmap font type which I found in Ubuntu.

  • Arch Wiki listed a good fontconfig example for activating Stylistic sets (I didn't test yet)

  • By the way, alias is a very powerful feature for advanced rules, same font can have multiple aliases, each has it own settings. (I didn't test yet)

1
  • 1
    The docs you listed say this: "The canonical font pattern is finally matched against all available fonts. The distance from the pattern to the font is measured for each of several properties: ... . This list is in priority order -- results of comparing earlier elements of this list weigh more heavily than later elements." But this unfortunately doesn't say anything about what happens when multiple files are matched. Nor do I see any way to control matching precedence. Apr 15, 2022 at 21:35
2

I found the answer in a mailing list thread from early this year: https://lists.freedesktop.org/archives/fontconfig/2022-January/006860.html

The latest one has a priority. It is measured by FC_FONTVERSION. If both are the same, it is up to the order of elements. The first one has a priority.

It seems that the order is defined by the order of directories in the user's config file. Beyond that, it's entirely arbitrary and probably dependent on the user's filesystem. I looked in the source code but I couldn't figure out where exactly the font file list is generated.

2
  • The is no such list but cached font info, because font priority is dynamic depending on the query and config files. Fonts can be user or system installed same as fontconfig files, user can customize them and distributions are heavily changing those. For example, Ubuntu which trying to be universal, so they keep injecting new rare font that used for specific language scripts (that implies some exceptions and overrides in priority).
    – user.dz
    Apr 16, 2022 at 23:12
  • 1
    Interesting, thanks @user.dz. Do you know if there is a configuration option that lets you control the font priority for things like file format (OTF vs TTF) and feature availability (ligatures, stylistic sets, etc)? I saw some suggestions of this in the source code, but I didn't track it all the way down to the underlying config objects. Apr 17, 2022 at 0:16

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .