Default fonts not respected on different language
Categories
(Core :: Layout: Text and Fonts, defect)
Tracking
()
People
(Reporter: intrnl28, Unassigned)
Details
Attachments
(2 files)
User Agent: Mozilla/5.0 (X11; Linux x86_64; rv:93.0) Gecko/20100101 Firefox/93.0
Steps to reproduce:
-
Start Firefox
-
Change your default font settings in Firefox preferences so it can be noticeable, in which case I have Roboto as my default font for sans-serif
-
In my case I usually have some custom CSS on to force sites to use
sans-serifinstead of whatever defaults they may have, but turning off the optionAllow pages to use their own fontworks too -
Open any site containing elements with a different lang attributes like jp, such as the following tweets, where the tweet container element has lang=jp attribute.
https://twitter.com/kosamari/status/1431479968396087298?s=20
https://twitter.com/onsenradio/status/1431466784029241344?s=20
Actual results:
The links are in a different font than what my preferences are set. In my case, I'm seeing Cantarell, the default GTK font.
Expected results:
It should respect my preferences and used what I set, Roboto, as the font.
Notice in the screenshot that the g in the sidebar and the g in the links are different.
I do notice that there's a dropdown in the font settings that allows you to pick the default fonts for a specific language/script, but I also have them set to default (which also corresponds to Roboto).
I remembered I had made a codepen a while back that shows this,
https://codepen.io/intrnl/pen/WNjpwxR
Comment 3•5 years ago
|
||
The Bugbug bot thinks this bug should belong to the 'Core::Layout: Text and Fonts' component, and is moving the bug to that component. Please revert this change in case you think the bot is wrong.
Comment 4•5 years ago
•
|
||
Tagging jfkthame who's the real expert here.
I think in general, it's expected that font-choice may differ between lang=en and lang=jp or zh sections, in all browsers. (There are lots of mentions of this happening in Chrome -- i.e. this isn't Firefox-specific -- e.g. here and here and here.) When given a generic font-family and a particular lang attribute, the browser tries to pick a font that's most likely to look good with that language.
You mentioned that you want Roboto, and unfortunately that's a font that doesn't include Japanese glyphs, which might be why we're avoiding it -- see https://github.com/googlefonts/roboto/issues/228#issuecomment-278783774 , "Roboto is limited to Latin, Greek, and Cyrillic". I suspect that's why Firefox is avoiding it here, despite you setting it as your chosen sans-serif font in Firefox.
I don't know why we would be landing on Cantarell in particular as a replacement. (Does it have Japanese characters? I can't tell from some quick googling.) Maybe jfkthame can weigh in on what might be going on to result in us landing on that font. Initially I suspect it'd be because we ask the system font library, and it ends up telling us to use Cantarell since it's your OS default, or something along those lines.
I'd imagine that to be the case as well, that it would avoid using my default font as it doesn't support CJK glyphs, but it does seem like an unwanted behavior though for someone that would use their custom fonts in order to read properly, which could happen on a Japanese webpage containing translated English text. ^^
Comment 6•5 years ago
|
||
I think one issue here -- and a frequent source of confusion -- is how the default font settings (as configured in Preferences) for "generic" names like serif or sans-serif are resolved. Currently, they are categorized into around 30 "language groups", and the settings that are used to resolve the CSS generic names will be chosen according to the lang attribute of the content (if any). Unrecognized lang values will end up using the "Other writing systems" setting, IIRC, which means that for languages/writing systems that aren't in the list, you can only configure one set of fonts, even though there may be many quite different such languages.
A better approach, IMO, would be to choose the font preferences to use based primarily on the script of the actual content, with lang tags as an additional differentiator where necessary (e.g. to distinguish Simplified Chinese vs Traditional Chinese vs Japanese, where they share the "unified Han" Unicode characters). So Latin characters would use the Latin-script font prefs, even when they occur on a page that is tagged with lang=ja.
On Linux only, an additional complication is that by default, the generics are not mapped to specific families within the Firefox preferences, but instead are passed to fontconfig. (You can override this by explicitly choosing specific fonts in Preferences, but it's the default behavior.) What fontconfig will return varies greatly between systems/distros/individual installations.
intrnl28: I'd be curious to know what queries such as
fc-match :family=sans-serif
fc-match :family=sans-serif:lang=en
fc-match :family=sans-serif:lang=ja
fc-match :family=sans-serif:lang=zh
return on your system? Does it map sans-serif differently depending on the lang setting?
I tried, and the only difference is for ja, it returns Noto Sans CJK JP, which I suppose what it's been using all along? I've never noticed since I've always used Roboto as my default haha.
$ fc-match :family=sans-serif
Roboto-Regular.ttf: "Roboto" "Regular"
$ fc-match :family=sans-serif:lang=en
Roboto-Regular.ttf: "Roboto" "Regular"
$ fc-match :family=sans-serif:lang=ja
NotoSansCJK-Regular.ttc: "Noto Sans CJK JP" "Regular"
$ fc-match :family=sans-serif:lang=zh
Roboto-Regular.ttf: "Roboto" "Regular"
Has there been any consideration on a (hidden) option to not follow fontconfig? I feel like it's been one of my growing source of pain since fontconfig tries to substitute a missing font with something else, which I clearly don't want, and also resulting DevTools to incorrectly show currently used font, though this is a separate issue.
Comment 9•5 years ago
|
||
Regarding DevTools: the Inspector should be able to show the used font correctly, but you need to look at the Fonts view (in the far right-hand pane, might need to use the drop-down arrow to reveal it) to see the actual used font(s) for an element. The CSS styles panel, and the Computed style view in the right-hand pane, only show you the value of the font-family property, which doesn't account for the fact that if the requested font(s) are unavailable or don't support the characters in the text, some other font will be chosen via a fallback process.
The Fonts view in the right-hand panel should show what is ultimately being used to render the text, after browser fallback, fontconfig substitution, or any other such features have done their work.
Updated•5 years ago
|
Description
•