You are not logged in.

#1 2024-06-22 22:05:10

BrianDMS
Member
From: Amsterdam, Netherlands
Registered: 2022-03-10
Posts: 25

[SOLVED] PDF font rendering/fallback issue, only on firefox?

When trying to open a PDF in Firefox (both flatpak and native), font spacing and rendering is completely broken. Additionally, some dialogs have very pixelated fonts, e.g. for firefox addons like bitwarden.
I'm running Gnome on Xorg, didn't change its default fonts in Gnome tweaks so they're still Cantarell for "interface and document text" and Source Code Pro for Monospace Text.
I instead always set up fonts using fontconfig: my fonts.conf uses aliases and matches with font families, this setup has worked for me in the past iirc. I also have rules 10, 11 and 70 in conf.d.
The issue does not occur in Chromium or in Gnome's PDF viewer, only in Firefox so far, anyone has any ideas how to fix it?

The PDF in question (works fine in Gnome document viewer btw)
How it looks like for me
Pixelated extension popup

pdffonts output for this pdf:

name                                 type              encoding         emb sub uni object ID
------------------------------------ ----------------- ---------------- --- --- --- ---------
PXAAAA+Roboto-Regular                TrueType          MacRoman         yes yes no    4275  0
BCDEEE+Calibri                       TrueType          WinAnsi          yes yes no    3086  0
TimesNewRomanPSMT                    TrueType          WinAnsi          no  no  no    3087  0
TimesNewRomanPSMT                    CID TrueType      Identity-H       yes no  yes   3088  0
TimesNewRomanPS-BoldMT               TrueType          WinAnsi          no  no  no    3556  0
TimesNewRomanPS-ItalicMT             TrueType          WinAnsi          no  no  no    3089  0
BCDFEE+SimSun                        CID TrueType      Identity-H       yes yes yes   4239  0
TimesNewRomanPS-ItalicMT             CID TrueType      Identity-H       yes no  yes   3177  0

Btw, every single one of those fonts resolves to LiberationSans-Regular.ttf: "Liberation Sans" "Regular" for some reason even though TNR should be serif?
Clearly the output is a serif so Firefox ignores my fonts.conf (while e.g. Chromium does not and renders it all in sans, according to this fc-match resolution)

This is my fc-match output for the 3 font families:

$ fc-match serif
LiberationSerif-Regular.ttf: "Liberation Serif" "Regular"
$ fc-match "sans serif"
LiberationSans-Regular.ttf: "Liberation Sans" "Regular"
$ fc-match monospace
LiberationMono-Regular.ttf: "Liberation Mono" "Regular"

This is my full fonts.conf with my font fallback for each family, before trying liberation and liberation nerd i tried noto and the issue was exactly the same.

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE fontconfig SYSTEM "fonts.dtd">
<fontconfig>
    <alias>
        <family>sans-serif</family>
	<prefer>
	    <family>Liberation Sans</family>
	    <family>LiterationSans Nerd Font</family>
	    <family>Noto Sans</family>
	    <family>Noto Color Emoji</family>
	    <family>Noto Sans CJK JP</family>
	    <family>Noto Sans CJK SC</family>
	    <family>Noto Sans CJK TC</family>
	    <family>Noto Sans CJK HK</family>
	    <family>Noto Sans CJK KR</family>
	</prefer>
    </alias>
    <alias>
        <family>serif</family>
	<prefer>
	    <family>Liberation Serif</family>
	    <family>LiterationSerif Nerd Font</family>
	    <family>Noto Serif</family>
	    <family>Noto Color Emoji</family>
	    <family>Noto Serif CJK JP</family>
	    <family>Noto Serif CJK SC</family>
	    <family>Noto Serif CJK TC</family>
	    <family>Noto Serif CJK HK</family>
	    <family>Noto Serif CJK KR</family>
	</prefer>
    </alias>
    <alias>
        <family>monospace</family>
	<prefer>
	    <family>Liberation Mono</family>
	    <family>LiterationMono Nerd Font</family>
	    <family>Noto Sans Mono</family>
	    <family>Noto Emoji</family>
	    <family>Noto Sans Mono CJK JP</family>
	    <family>Noto Sans Mono CJK SC</family>
	    <family>Noto Sans Mono CJK TC</family>
	    <family>Noto Sans Mono CJK HK</family>
	    <family>Noto Sans Mono CJK KR</family>
	</prefer>
    </alias>
</fontconfig>

And finally, the rules in conf.d are 10-sub-pixel-rgb.conf, 11-lcdfilter-default.conf and 70-no-bitmaps.conf
It seems to me that the issue is with firefox not respecting fonts.conf for some reason, any ideas?

EDIT/SOLUTION:

Firefox has its own fontconfig parser which is not always fully consistent. In my case, removing all font-related Xorg packages (other than xorg-fonts-encodings) fixed this particular issue, as Firefox was likely resolving to those fonts for whatever reason.

Last edited by BrianDMS (2024-06-24 17:39:00)


alias ffs='sudo $(fc -ln -1)'

Offline

#2 2024-06-22 22:25:42

BrianDMS
Member
From: Amsterdam, Netherlands
Registered: 2022-03-10
Posts: 25

Re: [SOLVED] PDF font rendering/fallback issue, only on firefox?

Found one more strange thing, when inspecting the element in Firefox' PDF viewer, it actually shows that the font family is sans-serif, yet displays a very clearly serif font.
(my fc-match for sans-serif is ofc liberation sans and again, it renders well in chromium)

Check this out


alias ffs='sudo $(fc -ln -1)'

Offline

#3 2024-06-22 22:56:16

BrianDMS
Member
From: Amsterdam, Netherlands
Registered: 2022-03-10
Posts: 25

Re: [SOLVED] PDF font rendering/fallback issue, only on firefox?

1 more strange discovery, for the title page firefox uses Cantarell which is the default Gnome font (which I have not changed), though that page at least renders fine, but for the rest of the document (the broken part) it tries to use DejaVu which I don't even have installed so no clue where that even comes from, as it's not on the list as shown by pdffonts either, take a look at THIS. I also tried the same thing with Chromium and upon inspection it shows THIS (and I don't have roboto installed either), I guess it also doesn't respect fonts.conf but somehow works anyway? I'm totally lost at this point...


alias ffs='sudo $(fc -ln -1)'

Offline

#4 2024-06-23 07:30:17

seth
Member
Registered: 2012-09-03
Posts: 54,177

Re: [SOLVED] PDF font rendering/fallback issue, only on firefox?

Wild guess because of your last comment: try to replace cantarell w/ https://aur.archlinux.org/packages/cant … atic-fonts
llpp/mupdf render the article in some serif (probably the embedded TNR) but the header page is sans, no idea whetehr that's what you're seeing in FF

Offline

#5 2024-06-23 11:54:27

BrianDMS
Member
From: Amsterdam, Netherlands
Registered: 2022-03-10
Posts: 25

Re: [SOLVED] PDF font rendering/fallback issue, only on firefox?

Cantarell wasn't an issue apparently, it seems that Firefox is just really weird when resolving fonts sometimes. I found an old post where the solution turned out to be deleting some xorg font packages.

 sudo pacman -Rns xorg-font-util xorg-fonts-100dpi xorg-fonts-75dpi xorg-fonts-alias-100dpi xorg-fonts-alias-75dpi 

This did the trick but tbh I have no idea why, unless Firefox has its own obscure built in font resolution or something?
I had and still have the "allow pages to use their own fonts" firefox setting btw (it's default), disabling it still changes the font but both are "normal" at least.
Anyway, none of the fonts from the document/browser actually resolved to any of the potentially broken fonts provided by those xorg packages.
It also showed DejaVu before because that's the default Firefox font which I guess is compiled together with it, but DejaVu also resolved to my regular fonts according to fc-match.
I also have the rule that disables bitmap fonts, but maybe Firefox just ignores fontconfig somehow and resolves the fonts on its own so it used those fonts anyway?
I have no idea what xorg-font-util does but maybe it somehow overrides fontconfig and is the culprit? That's pretty much the only reason I can think of at least.

I'll leave it open for a bit, maybe someone has more insights to share because I'd definitely like to know what's going on even though my issue is fixed for now.


alias ffs='sudo $(fc -ln -1)'

Offline

#6 2024-06-23 12:04:42

Lone_Wolf
Forum Moderator
From: Netherlands, Europe
Registered: 2005-10-04
Posts: 12,317

Re: [SOLVED] PDF font rendering/fallback issue, only on firefox?

The number of fonts present may be involved.

Have you tried increasing gfx.font_rendering.fontconfig.max_generic_substitutions as described on archwiki on firefox font troubleshooting


Disliking systemd intensely, but not satisfied with alternatives so focusing on taming systemd.


(A works at time B)  && (time C > time B ) ≠  (A works at time C)

Online

#7 2024-06-23 14:33:35

BrianDMS
Member
From: Amsterdam, Netherlands
Registered: 2022-03-10
Posts: 25

Re: [SOLVED] PDF font rendering/fallback issue, only on firefox?

Yeah that was my first try, forgot to mention, did all 3 of those steps, that didn't change anything in this case.


alias ffs='sudo $(fc -ln -1)'

Offline

#8 2024-06-23 14:39:08

seth
Member
Registered: 2012-09-03
Posts: 54,177

Re: [SOLVED] PDF font rendering/fallback issue, only on firefox?

What does

fc-match "Times New Roman"

resolve for you now resp. w/ the xorg fonts installed?

Offline

#9 2024-06-23 14:50:49

BrianDMS
Member
From: Amsterdam, Netherlands
Registered: 2022-03-10
Posts: 25

Re: [SOLVED] PDF font rendering/fallback issue, only on firefox?

With xorg fonts uninstalled (where the issue doesn't occur anymore):
LiberationSerif-Regular.ttf: "Liberation Serif" "Regular"

With xorg fonts installed (the issue occurs again after fc-cache --really-force and firefox restart):
LiberationSerif-Regular.ttf: "Liberation Serif" "Regular"

Same thing in both cases


alias ffs='sudo $(fc -ln -1)'

Offline

#10 2024-06-23 15:28:37

seth
Member
Registered: 2012-09-03
Posts: 54,177

Re: [SOLVED] PDF font rendering/fallback issue, only on firefox?

Ok, so that's not it - FF has it's internal fontconfig implementation which is less tolerant against ill-formed config files but I don't see how that could become relevant here.
sad

Offline

#11 2024-06-24 17:30:39

BrianDMS
Member
From: Amsterdam, Netherlands
Registered: 2022-03-10
Posts: 25

Re: [SOLVED] PDF font rendering/fallback issue, only on firefox?

Interesting, somehow suspected this was the case based on this behavior. I think it would make sense though, seems like Firefox was ignoring the no-bitmap rules and resolving the document font to one of the Xorg (bitmap?) fonts when they were installed. Uninstalling them fixed the issue and Firefox at the very least resolves to a normal looking font now (still not sure if it's in line with my fontconfig though, I'm not enough of a font expert to visually tell xd). Maybe it specifically doesn't do well parsing the alias/family/prefer style of fontconfig that I like to use, who knows.

I'll mark it as solved but just wondering, anyone tried talking to Mozilla about this behavior/potential bug? I see no reason why they'd even parse fonts.conf themselves rather than relying on a standard system-wide implementation.


alias ffs='sudo $(fc -ln -1)'

Offline

#12 2024-06-24 20:13:01

seth
Member
Registered: 2012-09-03
Posts: 54,177

Re: [SOLVED] PDF font rendering/fallback issue, only on firefox?

cross-platform, also there's obviously a present xml parser
The wired part is that you apparently (likely) end up w/ "Adobe Times" (part of the packages you removed) which doesn't match "Times New Roman" for me and I can also not find a related fontconfig rule hmm

Offline

Board footer

Powered by FluxBB