Oddities and possibile enhancements of :postscriptname pattern with partial matches
Francesco Pretto
ceztko at gmail.com
Tue Dec 3 11:28:15 UTC 2024
Hello,
I was testing matching of fonts with a :postscriptname pattern with
partial name matching, for example "Noto", "Liberation", "Deja". I
know that FontConfig doesn't support matching with wildcards and I
know these loosely qualified patterns are cringe. Still API
FcFontMatch and/or fc-match seem to do a bare minimum to handle them,
but fail with a less trivial pattern, casting some doubts they are
really respecting the contract of "using the normal fontconfig
matching rules to find the best font available" (as per the
documentation).
First I make the questions, then I elaborate them:
1) Why a :postscriptname pattern partially matching name seems it
can't be used together a :style pattern?
2) Why match on a :postscriptname doesn't perform more pattern
normalizations? For examples it trims spaces, which is good, but it
doesn't (for example) convert commas ',' to hyphen '-' (which it would
in general match more fonts);
3) Why partial match on :family produces even worse results than on
:postscriptname?
Elaborating the questions, at first I actually tried doing some
partial matches on family name, and the results were quite bad:
$ fc-match ":family=Liberation" postscriptname style family
Noto Sans:style=Regular:postscriptname=NotoSans-Regular
... (notice it returned a Noto font instead of any available
Liberation font). Then I tried with matching :postscriptname and these
matches seem to to be promising:
$ fc-match ":postscriptname=Liberation" postscriptname style family
Liberation Mono:style=Regular:postscriptname=LiberationMono
$ fc-match ":postscriptname=Noto" postscriptname style family
Noto Mono:style=Regular:postscriptname=NotoMono
$ fc-match ":postscriptname=Deja" postscriptname style family
DejaVu Sans:style=Book:postscriptname=DejaVuSans
At this pointed I really want to enforce a scalable font, and not a
monospaced one. This works:
$ fc-match ":postscriptname=Liberation:spacing=0" postscriptname style family
Liberation Sans:style=Regular:postscriptname=LiberationSans
But if I also want an italic font (which is definitely available) then
this fails:
fc-match ":postscriptname=Liberation:spacing=0:style=Italic"
postscriptname style family
Liberation Sans:style=Regular:postscriptname=LiberationSans
The behavior is reproducible using the linked testbed which has a
small font database[1] (with small differences, as it seems to prefer
"Bold" fonts to "Regular" ones), using the latest FontConfig git
revision.
As one more discussion point, I noticed that some pattern
normalization is performed in :postscriptname, as for example trimming
spaces. For example the following works, which is great:
fc-match ":postscriptname=Liberation Sans-Bold" postscriptname family style
Liberation Sans:style=Bold:postscriptname=LiberationSans-Bold
But that's seem to be the only normalization performed, and the
following match will fail:
fc-match ":postscriptname=LiberationSans,Bold" postscriptname family style
Liberation Sans:style=Regular:postscriptname=LiberationSans
Please consider that using the comma as in "LiberationSans,Bold" is
quite a common convention as suggested in the PdfReference for a long
time (before ISO standardization) to compose a postscript name for the
font (read 5.5.2 TrueType Fonts in PdfReference 1.7[2], suggestion
removed starting with ISO 32000-1:2008).
Thank you for your attention.
Cheers,
Francesco
[1] https://github.com/user-attachments/files/17990992/testpsmatch.zip
[2] https://opensource.adobe.com/dc-acrobat-sdk-docs/pdfstandards/pdfreference1.7old.pdf
More information about the Fontconfig
mailing list