system-ui tries to match fonts that contain "UI" in their names
Categories
(Core :: Layout: Text and Fonts, defect, P3)
Tracking
()
People
(Reporter: i, Unassigned)
References
Details
Attachments
(1 file)
|
196.19 KB,
image/png
|
Details |
User Agent: Mozilla/5.0 (X11; Linux x86_64; rv:73.0) Gecko/20100101 Firefox/73.0
Steps to reproduce:
(On Arch Linux, please adapt to your OS when trying to reproduce)
- Install noto-fonts and ttf-roboto
- In Firefox, open URL:
data:text/html,<span style='font-family: system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Ubuntu, "Helvetica Neue", sans-serif'>(1a2b3c4d5e6f7g8h9i0j)+.*/\
- Open developer tools and switch to the Inspector -> Fonts tab
Actual results:
Firefox tries to use 3 fonts to render the text, but the actual match is Roboto, which exists in the system.
If "system-ui" is removed from font-family, all characters are rendered with Roboto correctly.
Expected results:
Only Roboto is used.
Updated•6 years ago
|
Comment 1•6 years ago
|
||
Hmm, Firefox doesn't support system-ui yet (bug 1226042), so I am not sure its presence or absence should change how the font matching works here. Jonathan?
Comment 2•6 years ago
|
||
I suspect the reporter's fontconfig configuration is providing a mapping (perhaps installed by the noto-fonts package).
hexchain, what do you get if you run fc-match system-ui in a terminal?
No, there are no mapping for system-ui here.
% fc-match -s system | head
Roboto-Regular.ttf: "Roboto" "Regular"
NotoSansCJK-Regular.ttc: "Noto Sans CJK SC" "Regular"
Twemoji.ttf: "Twemoji" "Regular"
DejaVuSans.ttf: "DejaVu Sans" "Book"
DejaVuSans-Bold.ttf: "DejaVu Sans" "Bold"
DejaVuSans-Oblique.ttf: "DejaVu Sans" "Oblique"
DejaVuSans-BoldOblique.ttf: "DejaVu Sans" "Bold Oblique"
NimbusSans-Regular.otf: "Nimbus Sans" "Regular"
NotoSans-Regular.ttf: "Noto Sans" "Regular"
Font Awesome 5 Brands-Regular-400.otf: "Font Awesome 5 Brands" "Regular"
Comment 4•6 years ago
|
||
Unless it's just a typo here, comment 3 seems to indicate testing system rather than system-ui; does it make any difference to include the -ui suffix?
Comment 5•6 years ago
|
||
I'm not able to reproduce this: I installed a VM with ArchLinux including the ttf-roboto and noto-fonts packages, and tried the given example, but I see only Roboto being used. There must be something else about the configuration that is affecting it...
(In reply to Jonathan Kew (:jfkthame) from comment #4)
Unless it's just a typo here, comment 3 seems to indicate testing
systemrather thansystem-ui; does it make any difference to include the-uisuffix?
That is indeed a typo. Changing the query to system-ui does not make any difference though.
(In reply to Jonathan Kew (:jfkthame) from comment #5)
I'm not able to reproduce this: I installed a VM with ArchLinux including the ttf-roboto and noto-fonts packages, and tried the given example, but I see only Roboto being used. There must be something else about the configuration that is affecting it...
I do have some custom fontconfig in place, I'll try to reproduce in a clean environment and report back.
I've produced this issue in a newly installed Arch Linux VM image, under GNOME.
The cantarell-fonts package should not be installed, or it should be disabled with fontconfig, e.g. ~/.config/fontconfig/fonts.conf:
<?xml version="1.0"?>
<!DOCTYPE fontconfig SYSTEM "file:///etc/fonts/fonts.dtd">
<fontconfig>
<its:rules xmlns:its="http://www.w3.org/2005/11/its" version="1.0">
<its:translateRule translate="no" selector="/fontconfig/*[not(self::description)]"/>
</its:rules>
<selectfont>
<rejectfont>
<pattern>
<patelt name="family"><string>Cantarell</string></patelt>
</pattern>
</rejectfont>
</selectfont>
</fontconfig>
If the Cantarell font is not disabled then Firefox will use it to render everything. I noticed that /etc/fonts/conf.d/{45,60}-latin.conf might be interesting, as they bind Cantarell with system-ui.
More observations:
When the Cantarell font is not disabled:
$ fc-match -s cantarell | head -n4
Cantarell-Regular.otf: "Cantarell" "Regular"
NotoSansArabicUI-Regular.ttf: "Noto Sans Arabic UI" "Regular"
NotoSansBengaliUI-Regular.ttf: "Noto Sans Bengali UI" "Regular"
NotoSansDevanagariUI-Regular.ttf: "Noto Sans Devanagari UI" "Regular"
But even if /etc/fonts/conf.d/{45,60}-latin.conf are in place, fontconfig does not return Cantarell as a candidate for system-ui:
$ fc-match -s system-ui | grep -i cantarell
(no output)
... which is really strange.
And when Cantarell is disabled:
$ fc-match -s cantarell | head -n4
NimbusSans-Regular.otf: "Nimbus Sans" "Regular"
NotoSansArabicUI-Regular.ttf: "Noto Sans Arabic UI" "Regular"
NotoSansBengaliUI-Regular.ttf: "Noto Sans Bengali UI" "Regular"
NotoSansDevanagariUI-Regular.ttf: "Noto Sans Devanagari UI" "Regular"
These results seem to partly explain why "Noto Sans {Arabic,Bengali} UI" appears, but why is the first candidate ignored?
The bug title might need a little change, though.
Also noticed that to actually match against "system-ui" with fc-match, we need to use fc-match "system\-ui", or the actual pattern is "system" instead.
| Reporter | ||
Comment 10•6 years ago
|
||
A VM image is available here: https://surfdrive.surf.nl/files/index.php/s/AQXbEyz3n3wN1U3
It is created with VMware, so probably it is also best used with VMware Player.
Comment 11•6 years ago
|
||
Thanks, that may be helpful! Could you let me know the password for the "test" user that appears to be set up?
| Reporter | ||
Comment 12•6 years ago
|
||
Ah! Really sorry for that...
The password is 12345678. There is a fontconfig file at ~/.config/fontconfig/fonts.conf. Uncomment that code block in the file and launch Firefox to reproduce the bug.
Comment 13•6 years ago
|
||
No worries - thanks for the reply. (I'd tried some simple guesses, but didn't hit that one - obviously it's too secure for me!)
So I believe the problem is happening because of /etc/fonts/conf.avail/65-nonlatin.conf. This file includes:
<alias>
<family>system-ui</family>
<prefer>
<family>Noto Sans Arabic UI</family><!-- ar -->
<family>Noto Sans Bengali UI</family><!-- bn -->
<family>Noto Sans Devanagari UI</family><!-- hi, mai, mr -->
...etc
Which means that when Firefox asks fontconfig to resolve a pattern that requests font-family: system-ui, we get back a pattern that lists a whole bunch of Noto*UI fonts, and this all ends up ahead of Roboto in the list.
When Cantarell is available, it gets used because of /etc/fonts/conf.avail/60-latin.conf, which aliases system-ui to Cantarell (and to Noto Sans UI and Segoe UI, but they're not present). But when Cantarell is disabled, none of the Latin fonts preferred for system-ui are found, but all those non-Latins are - and so they get used, because system-ui is at the beginning of your font-family list.
| Reporter | ||
Comment 14•6 years ago
|
||
But there is an exact match "Roboto" in font-family. I guess that should be used instead of "system-ui" (which does not have any match with the same name), no?
Comment 15•6 years ago
•
|
||
No, that's not how I believe font-family works. It's an ordered list of font family names to try, and Firefox will try each in turn to see if it provides something usable. Given the configuration in /etc/fonts/conf.avail/65-nonlatin.conf, the request for system-ui resolves to a whole set of non-Latin faces, and all those will be tried ahead of whatever comes later in the font-family list.
I'm not sure it is really a good idea to use fontconfig to match the family name system-ui like this and alias it to "real" families; it's not a font family name in the usual sense, it's something specific to CSS that I would expect to be handled by browsers. But if it is to be handled by fontconfig, then you want to resolve it to the appropriate font for Latin text as well as for all those non-Latin scripts. And then if you put system-ui at the head of your font-family list, that's what will be used in preference to anything later in the list.
The configuration files here try to handle that, as /etc/fonts/conf.avail/60-latin.conf provides the aliasing of system-ui to Cantarell for Latin text (or to a few other candidates), but if none of the Latin-script fonts it mentions are present, then you've in effect got a system-ui family that supports everything except Latin script, and using that as the primary font in font-family will give weird, mixed results.
| Reporter | ||
Comment 16•6 years ago
|
||
Thanks for the explanation!
One more question is that why Firefox uses a different font from what fc-match says. In the VM image if you disable Cantarell, fc-match will return Nimbus Sans, but Firefox apparently is not using that. Does Firefox has its own font selection logic and only uses fontconfig to generate a list of matches?
Comment 17•6 years ago
|
||
Yes, Firefox has its own logic, it's not directly/solely using fontconfig - partly because it needs to handle things like @font-face-defined families which are not part of the font set normally known to fontconfig. So it uses fontconfig to try and respect the system's configuration (aliases, default mappings for generic names like serif, etc), but incorporates this into its own logic for processing the font-family list.
Nimbus Sans seems to be configured as fontconfig's default, which you also get from something like fc-match "SomeRandomFontName", so it makes sense you'd get this for fc-match "system\-ui" when none of the aliases of system-ui are available.
(If you try fc-match "system-\ui, serif" with Cantarell disabled, you'll see that you get Nimbus Roman instead of Sans, illustrating that this isn't coming from the system-uiname at all; fontconfig is failing to resolve that, and falling back to the next family requested, or its default ofsans-serif` if it falls off the end of the list.)
Updated•4 years ago
|
Description
•