Back in 2012, when Thunor developed the tool, he received a bug report . The preview of some fonts would display the default Sans but not the designated font. Thunor called them "fonts that gtk/Pango doesn't like" and out of frustration developed sfontview, a better working but less attractive binary. So the buggy pfontview lives on to this date as the default font viewer.
The same issue came up in the recent Font Preview thread. Again many people - including me - scratched their heads and wild theories about the possible cause were discussed.
I decided to take a closer look.
One of my problem fonts is called "Comic Book" and according to the fc-query tools everything looks normal:
- Pattern has 19 elts (size 32)
family: "Comic Book"
familylang: "en"
style: "Normal"
stylelang: "en"
fullname: "Comic Book Normal"
fullnamelang: "en"
gxmessage -fn "Comic Book Bold 10" Hello
the message text is rendered with DejaVu Sans, not Comic Book. No luck either with "Comic Book 10" or just "Comic Book"
On the other hand a seemingly more complicated
gxmessage -fn "Nimbus Sans L Bold 10" Hello
would work perfectly.
What's going on here?
I found it strange that the GTK font dialog appears to have no problems with my Comic Book and would show a correct preview. Maybe its return values can give a clue?
With yad installed the easiest way to find out is to open a console and type "yad --font". From the resulting dialog I selected family "Nimbus Sans L" with style "Bold"
Code: Select all
# yad --font
Nimbus Sans L Bold 10
Now the same with "Comic Book" and style "Bold" :
Code: Select all
# yad --font
Comic Book, Bold 10
Subsequently I tried
gxmessage -fn "Comic Book, Bold 10" Hello
Success! Also "Comic Book, 10" works.
So all we need is a comma after the name! Halleluja! An undocumented feature? Not at all.
According to the Pango documentation
- "font_name must have the form "[FAMILY-LIST] [STYLE-OPTIONS] [SIZE]", where FAMILY-LIST is a comma separated list of families optionally terminated by a comma, STYLE_OPTIONS is a whitespace separated list of words where each WORD describes one of style, variant, weight, or stretch, and SIZE is an decimal number (size in points). Any one of the options may be absent."
Pango's documentation can explain this too. Above mentioned WORDs describing the element of STYLE_OPTIONS are defined. Here is a list:
- Styles:
normal (same as also recognized 'regular' and 'roman')
italic
oblique
Variants:
normal
small-caps
Weights:
thin
ultralight
light
semilight
book
normal
medium
semibold
bold
ultrabold
heavy
ultraheavy
Explains also this mystery. A fancy style name like 'R' may be defined in the font, but as long as it is not an official Pango style name Pango will treat it as part of the name. On the other hand Pango doesn't check if an official style name is actually supported by the font. Even a completely bogus style name is OK ("Comic Book, blabla") as long as a comma separates it from the family name. In this case Pango reverts to the font's default style.
Now everything falls into place and can be explained.
A single comma can make all font viewers 100% reliable.
That's all. Have fun!