Closed Bug 1794822 Opened 3 years ago Closed 2 years ago

Firefox picks the "Nimbus Sans" font to substitute Helvetica, despite user's edits to font config files to remove it as a Helvetica substitute

Categories

(Core :: Layout: Text and Fonts, defect)

Firefox 105
defect

Tracking

()

RESOLVED WORKSFORME

People

(Reporter: brianpeiris, Unassigned)

Details

Attachments

(8 files)

Attached file font-test.html

User Agent: Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:105.0) Gecko/20100101 Firefox/105.0

Steps to reproduce:

Many websites use "Helvetica" as a sans-serif font, including github.com. Text and UI elements appear offset because of this bug. I've also attached a simple reproduction here to compare how Firefox renders common fonts.

Actual results:

On Ubuntu 22.04, Firefox picks "Nimbus Sans" as the substitute for Helvetica. It then renders the font incorrectly, vertically offset towards the top of the page, compared to other fonts.

Firefox picks "Nimbus Sans" even though fc-match Helvetica returns "Liberation Sans".

Chrome on the other hand picks "Liberation Sans", and renders it correctly.

Expected results:

Firefox should either render "Nimbus Sans" correctly, without the vertical offset, or pick "Liberation Sans" or "DejaVu Sans" on Ubuntu.

Attached image font-test-firefox.png
Attached image font-test-chrome.png

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 correct in case you think the bot is wrong.

Component: Untriaged → Layout: Text and Fonts
Product: Firefox → Core

(In reply to Brian Peiris from comment #0)

Firefox picks "Nimbus Sans" even though fc-match Helvetica returns "Liberation Sans".

FWIW, on my system (also Ubuntu 22.04), fc-match Helvetica returns NimbusSans-Regular.otf: "Nimbus Sans" "Regular"

It then renders the font incorrectly, vertically offset towards the top of the page, compared to other fonts.

Are you sure this part (the vertical offset) is a Firefox bug? If I explicitly specify font-family: 'Nimbus sans', Chrome matches Firefox on the vertical placement. (I think this is just Nimbus Sans having slightly different metrics, which Firefox is dutifully honoring, as does Chrome if you explicitly ask it to use Nimbus Sans.)

Flags: needinfo?(brianpeiris)

(In reply to Daniel Holbert [:dholbert] from comment #6)

If I explicitly specify font-family: 'Nimbus sans', Chrome matches Firefox on the vertical placement.

Here's a variant of your testcase, to demonstrate this^ note about the vertical placement. Firefox and Chrome agree on this vertical placement of the text here, on my system -- with the Nimbus Sans text being placed a bit higher than the other text.

Regardless of whether Firefox is rendering Nimbus badly vs. if Nimbus just renders badly regardless of browser (my suspicion)...

The "choosing Nimbus Sans despite fc-match returning something else" thing still seems to be a bug (possibly the same as bug 1547743), though I'm curious why fc-match is giving different results for me vs. for you. Possibly there's something locale-related?

jfkthame knows fontconfig stuff better than I do, so he might have more-insightful questions to ask here. But I'm curious if your Ubuntu font configuration files are missing the Helvetica-to-Nimbus mapping that I have locally (from https://github.com/behdad/fontconfig/blob/master/conf.d/30-metric-aliases.conf , per bug 1547743 comment 7), vs. if you've got them but they're being interpreted by fc-match differently, vs. if they're being overridden by something else (and maybe Firefox isn't seeing that something-else).

If you look at /etc/fonts/conf.avail/30-metric-aliases.conf in a text editor and search for "Helvetica" and "Nimbus" and "Liberation", do you find anything interesting? For me, I see a handful of <alias binding="same"> tags which tie together Helvetica and Nimbus, and a separate chunk of same tags that tie together Liberation and Arial (and indeed fc-match Arial gives me Liberation Sans, and data:text/html,<div style="font-family:Arial">Text renders with Liberation Sans in Firefox).

But I don't see any obvious mapping there that would have Liberation Sans be considered the same as Helvetica.

I assume you have something different in that file or another config file, though, which is why fc-match is doing that mapping on your system...

I can confirm Chrome renders "Nimbus Sans" in the same way as Firefox on my machine as well

I should have mentioned that I've manually edited my font configs to remove references to Nimbus in an attempt to fix the rendering issues on websites in Firefox, which is why fc-match Helvetica now returns "Liberation Sans", so this bug may just be about having Firefox respect fc-match Helvetica. Feel free to close this as a duplicate of bug 1547743, unless the test cases here are useful to you.

Thanks for looking into it!

Flags: needinfo?(brianpeiris)

(In reply to Brian Peiris from comment #9)

I can confirm Chrome renders "Nimbus Sans" in the same way as Firefox on my machine as well

OK, great. So Firefox isn't rendering Nimbus improperly.

I should have mentioned that I've manually edited my font configs to remove references to Nimbus in an attempt to fix the rendering issues on websites in Firefox, which is why fc-match Helvetica now returns "Liberation Sans", so this bug may just be about having Firefox respect fc-match Helvetica.

Thanks, that helps clarify why I'm seeing different results. Hopefully jfkthame might be able to offer better insight on what might be going on here. As in bug 1547743 comment 2, it sounds like he would need to see your edited font config files; could you zip up your /etc/fonts directory and attach it here? Not sure if there's anything else that he might want to take a look at, but that'd be a start.

(Also FWIW, it's not obvious to me that Chrome is respecting fc-match; they seem to just automatically use Liberation Sans for Helvetica; and on my system, that disagrees with what fc-match recommends. Nonetheless, it would be good to understand why Firefox isn't agreeing with fc-match.)

Flags: needinfo?(brianpeiris)

(ni=jfkthame for thoughts, per comment 10. RE duping -- that might end up being appropriate, though this might be a different issue since it's not obvious that bug 1547743's reporter had any edits (or the same edits as you) to their fontconfig files. Let's keep it distinct for now, at least for the purposes of investigating what your fontconfig files look like.)

Flags: needinfo?(jfkthame)
Attached file etc-fonts.zip

Zipped up /etc/fonts

Flags: needinfo?(brianpeiris)
Attached file fontconfig-fonts.conf

Also including my ~/.config/fontconfig/fonts.conf file

If it helps, a similar issue and discussion was started on launchpad a while ago: https://bugs.launchpad.net/ubuntu/+source/firefox/+bug/1874842

Thanks. That bug also references https://nolanlawson.com/2020/05/02/customizing-fonts-in-firefox-on-linux/ which has some notes on an apparently-successful attempt to add fontconfig rules that Firefox respects (though it's a few years old so I'm not sure if the exact recommendations there would would still work or not).

I just tried the instructions in that blog post, replacing my ~/.config/fontconfig/fonts.conf with the <alias> configuration mentioned there, and it had no effect in Firefox, even after a restart and fc-cache reset. So perhaps those instructions too outdated.

Summary: Firefox picks the "Nimbus Sans" font to substitute Helvetica, and renders it incorrectly → Firefox picks the "Nimbus Sans" font to substitute Helvetica
Summary: Firefox picks the "Nimbus Sans" font to substitute Helvetica → Firefox picks the "Nimbus Sans" font to substitute Helvetica, despite user's edits to font config files to remove it as a Helvetica substitute
Severity: -- → S3

I don't really have a thorough grasp of how fontconfig behaves in the face of various types of aliases etc. I do see several mentions of Helvetica and Nimbus Sans still in the config files from comment 12 and comment 13; see in particular 61-urw-nimbus-sans.conf and 61-urw-fallback-generics.conf, but I don't know how all these things interact.

At least as an experiment, it might be worth removing all rules that associate Helvetica with Nimbus Sans in any way, and see what effect that has. I don't know any reason Firefox would make such a substitution except if it's being returned from fontconfig at some point.

Flags: needinfo?(jfkthame)

I know that the flatpak does not (always) adhere to system fontconfig settings, particularly the user's fontconfig settings. I don't know if that's also the case for snap. In either case, this might not be a firefox issue, but a flatpak one: https://github.com/flatpak/flatpak/issues/1563

An update now that I'm on a fresh install of Ubuntu 23.10, with Firefox snap v120.
Without any config tweaks on this Ubuntu install, fc-match Helvetica gives "Nimbus Sans", however, for whatever reason, Firefox now renders it at the same vertical offset as the default sans-serif font (Noto Sans). My motivating reason for opening this bug is no longer an issue, since text on most sites, including GitHub now looks visually correct relative to other elements, so I'm going to close this bug. Thanks!

Status: UNCONFIRMED → RESOLVED
Closed: 2 years ago
Resolution: --- → WORKSFORME

Thanks for letting us know! I'm glad things are working better now.

You need to log in before you can comment on or make changes to this bug.

Attachment

General

Creator:
Created:
Updated:
Size: