Closed Bug 1767925 Opened 2 years ago Closed 2 years ago

Fallback fonts in snap package are not the same as apt package

Categories

(Firefox Build System :: Third Party Packaging, defect)

Firefox 99
x86_64
Linux
defect

Tracking

(Not tracked)

RESOLVED FIXED

People

(Reporter: rahul.siddharthan, Unassigned)

References

(Blocks 1 open bug)

Details

Attachments

(2 files)

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

Steps to reproduce:

My setup is Firefox 99.0.1 snap on Ubuntu 22.04 Jammy. I filed an Ubuntu bug but they said the firefox snap is from upstream and sent me here.
I opened http://www.wormbook.org/chapters/www_intromethodscellbiology/intromethodscellbiology.pdf and the fonts are wrong and spacing is ugly.

Over on reddit people suggested disabling use document fonts (browser.display.use_document_fonts=0) and that fixed it; but for html pages it uses the wrong fonts then.

Also on reddit, someone said reproducible in a Ubuntu VM; someone else said, not reproducible on Linux Mint, which is based on Ubuntu but doesn't use snaps.

Actual results:

Ugly fonts. Results in first image here
https://www.reddit.com/r/firefox/comments/uhz6d1/continued_messedup_font_rendering_in_firefox_pdf/

Expected results:

Beautiful fonts. Second image here
https://www.reddit.com/r/firefox/comments/uhz6d1/continued_messedup_font_rendering_in_firefox_pdf/

Update: the bug remains in firefox 100.

Component: Untriaged → PDF Viewer
OS: Unspecified → Linux
Hardware: Unspecified → x86_64

Do you have gsfonts installed on your system? I had the same problem, but I fixed it by installing gsfonts.

Flags: needinfo?(rahul.siddharthan)

I do have gsfonts installed, version 1:8.11+urwcyr1.0.7~pre44-4.5 . As noted, the font rendering is fine if I disable "browser.display.use_document_fonts". So it is not a missing font problem.

Flags: needinfo?(rahul.siddharthan)

Update: this problem does not occur with firefox-trunk (version 101.0a1), which is installed via apt. I strongly suspect it is a problem with the snap packaging of firefox.

I've managed to reproduce this issue using Firefox 100.0.1 Snap on Ubuntu 22.04.
Marking this as dupe because it has been already reported in bug 1752414.

Status: UNCONFIRMED → RESOLVED
Closed: 2 years ago
Resolution: --- → DUPLICATE
Blocks: snap
Status: RESOLVED → REOPENED
Ever confirmed: true
Resolution: DUPLICATE → ---

The issue seems to be that the ubuntu snap doesn't find fonts on the system that are not embedded in the pdf. The ubuntu deb from the mozillateam ppa finds the fonts fine. So it is a snap packaging problem.

The fonts used on the first page are not embedded in the pdf and so we use a fallback font.
For any reason this font is not the same from a package to an other but It's very likely not bug related to the snap packaging.

No longer blocks: snap
Status: REOPENED → RESOLVED
Closed: 2 years ago2 years ago
Resolution: --- → DUPLICATE

Let's use this bug to track the mismatch of the fallback font in the Ubuntu snap.

Status: RESOLVED → REOPENED
Component: PDF Viewer → Third Party Packaging
Product: Firefox → Firefox Build System
Resolution: DUPLICATE → ---
Summary: Firefox PDF font rendering is often messed up → Fallback fonts in snap package are not the same as apt package
Blocks: snap

I repro on snap stable & nightly, is there some MOZ_LOG I could use to see what is happening on the font loading path?

Sandbox logging did not immediately reveal anything wrong.

Flags: needinfo?(cdenizet)

Side by side repro of the issue. On the left, Nightly Snap, on the right, Nightly from us.
Opened the linked PDF, selected the main title « Methids in cell biology » and moved to "Fonts" in the devtools. It seems weird, because they report the exact same fonts, and characteristics.

about:support on the snap package reports mesa 21.2.6 while it reports 22.0.1 on non snap package

Most of the fonts aren't embedded in the pdf.
The text is drawn on a canvas, hence the font properties are not visible in devtools (what you see is the text layer used to allow text selection).
With a local dev, the fonts set in the canvas are:

  • "Times", serif
  • "Helvetica", sans-serif

So either a font called Times or Helvetica is found in a case and not in the other, or the font behind serif or sans-serif is not the same.

Flags: needinfo?(cdenizet)

(In reply to Alexandre LISSY :gerard-majax from comment #10)

Created attachment 9284140 [details]
Screenshot_ubuntu22.04_2022-07-05_16:08:03.png

Side by side repro of the issue. On the left, Nightly Snap, on the right, Nightly from us.
Opened the linked PDF, selected the main title « Methids in cell biology » and moved to "Fonts" in the devtools. It seems weird, because they report the exact same fonts, and characteristics.

I am puzzled that the one on the right reports the font as DejaVu Sans. It is Helvetica and rendered correctly. The one on the left is, indeed, DejaVu Sans and should not be.

(In reply to rahul.siddharthan from comment #13)

(In reply to Alexandre LISSY :gerard-majax from comment #10)

Created attachment 9284140 [details]
Screenshot_ubuntu22.04_2022-07-05_16:08:03.png

Side by side repro of the issue. On the left, Nightly Snap, on the right, Nightly from us.
Opened the linked PDF, selected the main title « Methids in cell biology » and moved to "Fonts" in the devtools. It seems weird, because they report the exact same fonts, and characteristics.

I am puzzled that the one on the right reports the font as DejaVu Sans. It is Helvetica and rendered correctly. The one on the left is, indeed, DejaVu Sans and should not be.

Yeah, I was told I read the dev tools wrong

Depends on: 1780540

fc-match :family=Times return different things under (snap run --shell firefox) / outside of Snap:

Under snap:

$ fc-match :family=Times
LiberationSerif-Regular.ttf: "Liberation Serif" "Regular"

Outside of snap:

$ fc-match :family=Times
NimbusRoman-Regular.otf: "Nimbus Roman" "Regular"

Outside:

user@ubuntu-2204-snap:~$ fc-match :family=Times
NimbusRoman-Regular.otf: "Nimbus Roman" "Regular"
user@ubuntu-2204-snap:~$ fc-match :family=Helvetica
NimbusSans-Regular.otf: "Nimbus Sans" "Regular"
user@ubuntu-2204-snap:~$ fc-match :family="Times New Roman"
LiberationSerif-Regular.ttf: "Liberation Serif" "Regular"
user@ubuntu-2204-snap:~$ fc-match :family=serif
DejaVuSerif.ttf: "DejaVu Serif" "Book"
user@ubuntu-2204-snap:~$ fc-match :family=sans-serif
DejaVuSans.ttf: "DejaVu Sans" "Book"
user@ubuntu-2204-snap:~$ fc-match :family="Times, serif"
NimbusRoman-Regular.otf: "Nimbus Roman" "Regular"
user@ubuntu-2204-snap:~$ fc-match :family="Helvetica, sans-serif"
NimbusSans-Regular.otf: "Nimbus Sans" "Regular"

Inside:

user@ubuntu-2204-snap:/home/user$ fc-match :family=Times
LiberationSerif-Regular.ttf: "Liberation Serif" "Regular"
user@ubuntu-2204-snap:/home/user$ fc-match :family=Helvetica
LiberationSans-Regular.ttf: "Liberation Sans" "Regular"
user@ubuntu-2204-snap:/home/user$ fc-match :family="Times New Roman"
LiberationSerif-Regular.ttf: "Liberation Serif" "Regular"
user@ubuntu-2204-snap:/home/user$ fc-match :family=serif
DejaVuSerif.ttf: "DejaVu Serif" "Book"
user@ubuntu-2204-snap:/home/user$ fc-match :family=sans-serif
DejaVuSans.ttf: "DejaVu Sans" "Book"
user@ubuntu-2204-snap:/home/user$ fc-match :family="Helvetica, sans-serif"
DejaVuSans.ttf: "DejaVu Sans" "Book"
user@ubuntu-2204-snap:/home/user$ fc-match :family="Times, serif"
DejaVuSerif.ttf: "DejaVu Serif" "Book"
$ cat $XDG_CONFIG_HOME/fontconfig/fonts.conf 
<fontconfig>
  <dir>/snap/firefox/x1/gnome-platform/usr/share/fonts</dir>
  <dir>/usr/local/share//fonts</dir>
  <dir>/usr/share//fonts</dir>
  <include ignore_missing="yes">/etc/fonts/conf.d</include>
  <include ignore_missing="yes">conf.d</include>
  <cachedir prefix="xdg">fontconfig</cachedir>
  <cachedir>/var/snap/firefox/common/fontconfig</cachedir>
</fontconfig>

I would assume this should find all fonts ?

We will look into XDG_DATA_DIRS at https://github.com/ubuntu/snapcraft-desktop-helpers/blob/ec861254c2a1d2447b2c589446e6cdf04c75c260/common/desktop-exports#L274

XDG_DATA_DIRS=/home/user/snap/firefox/x1/.local/share:/home/user/snap/firefox/x1:/snap/firefox/x1/data-dir:/snap/firefox/x1/usr/share:/snap/firefox/x1/gnome-platform/usr/share:/usr/share/ubuntu:/usr/local/share/:/usr/share/:/var/lib/snapd/desktop

And if we find fonts, we add them at https://github.com/ubuntu/snapcraft-desktop-helpers/blob/ec861254c2a1d2447b2c589446e6cdf04c75c260/common/desktop-exports#L288-L292

This is how we end up with <dir>/snap/firefox/x1/gnome-platform/usr/share/fonts</dir> in comment #17.

Unfortunately, this is where we have some DejaVu fonts, and fontconfig seems to prefer them ?

(In reply to Alexandre LISSY :gerard-majax from comment #18)

We will look into XDG_DATA_DIRS at https://github.com/ubuntu/snapcraft-desktop-helpers/blob/ec861254c2a1d2447b2c589446e6cdf04c75c260/common/desktop-exports#L274

XDG_DATA_DIRS=/home/user/snap/firefox/x1/.local/share:/home/user/snap/firefox/x1:/snap/firefox/x1/data-dir:/snap/firefox/x1/usr/share:/snap/firefox/x1/gnome-platform/usr/share:/usr/share/ubuntu:/usr/local/share/:/usr/share/:/var/lib/snapd/desktop

And if we find fonts, we add them at https://github.com/ubuntu/snapcraft-desktop-helpers/blob/ec861254c2a1d2447b2c589446e6cdf04c75c260/common/desktop-exports#L288-L292

This is how we end up with <dir>/snap/firefox/x1/gnome-platform/usr/share/fonts</dir> in comment #17.

Unfortunately, this is where we have some DejaVu fonts, and fontconfig seems to prefer them ?

It's not just that. Removed the extra font directory, I get:

$ grep -n DejaVu inside-snap.txt outside-snap.txt 
inside-snap.txt:4:/usr/share/fonts/truetype/dejavu/DejaVuSerif-Bold.ttf: DejaVu Serif:style=Bold
inside-snap.txt:10:/usr/share/fonts/truetype/dejavu/DejaVuSansMono.ttf: DejaVu Sans Mono:style=Book
inside-snap.txt:32:/usr/share/fonts/truetype/dejavu/DejaVuSans.ttf: DejaVu Sans:style=Book
inside-snap.txt:127:/usr/share/fonts/truetype/dejavu/DejaVuSans-Bold.ttf: DejaVu Sans:style=Bold
inside-snap.txt:190:/usr/share/fonts/truetype/dejavu/DejaVuSansMono-Bold.ttf: DejaVu Sans Mono:style=Bold
inside-snap.txt:353:/usr/share/fonts/truetype/dejavu/DejaVuSerif.ttf: DejaVu Serif:style=Book
outside-snap.txt:4:/usr/share/fonts/truetype/dejavu/DejaVuSerif-Bold.ttf: DejaVu Serif:style=Bold
outside-snap.txt:10:/usr/share/fonts/truetype/dejavu/DejaVuSansMono.ttf: DejaVu Sans Mono:style=Book
outside-snap.txt:32:/usr/share/fonts/truetype/dejavu/DejaVuSans.ttf: DejaVu Sans:style=Book
outside-snap.txt:127:/usr/share/fonts/truetype/dejavu/DejaVuSans-Bold.ttf: DejaVu Sans:style=Bold
outside-snap.txt:190:/usr/share/fonts/truetype/dejavu/DejaVuSansMono-Bold.ttf: DejaVu Sans Mono:style=Bold
outside-snap.txt:353:/usr/share/fonts/truetype/dejavu/DejaVuSerif.ttf: DejaVu Serif:style=Book

So the fc-list output is identical:

$ sha1sum outside-snap.txt inside-snap.txt 
6725ddfa566a886949c5e6b2264887aa2cc38772  outside-snap.txt
6725ddfa566a886949c5e6b2264887aa2cc38772  inside-snap.txt

Yet the behavior is different:

(outside)
user@ubuntu-2204-snap:~$ fc-match :family="Times, sans-serif"
NimbusRoman-Regular.otf: "Nimbus Roman" "Regular"
(inside)
user@ubuntu-2204-snap:/home/user$ fc-match :family="Times, sans-serif"
DejaVuSans.ttf: "DejaVu Sans" "Book"

As suggested by Sebastian on IRC,

$ mkdir ~/snap/firefox/current/.config/fontconfig/conf.d; cp /etc/fonts/conf.d/61-urw-nimbus-roman.conf ~/snap/firefox/current/.config/fontconfig/conf.d

This fixes the example of fc-match above, confirming we are missing some fontconfig on snap-side.

I could confirm locally that the following allows me to get identical PDF rendering:

mkdir ~/snap/firefox/current/.config/fontconfig/conf.d; cp /etc/fonts/conf.d/* ~/snap/firefox/current/.config/fontconfig/conf.d
Flags: needinfo?(rahul.siddharthan)

(In reply to Alexandre LISSY :gerard-majax from comment #20)

As suggested by Sebastian on IRC,

$ mkdir ~/snap/firefox/current/.config/fontconfig/conf.d; cp /etc/fonts/conf.d/61-urw-nimbus-roman.conf ~/snap/firefox/current/.config/fontconfig/conf.d

Confirmed, this fixes it for me.

Flags: needinfo?(rahul.siddharthan)
See Also: → 1760996

The severity field is not set for this bug.
:gerard-majax, could you have a look please?

For more information, please visit auto_nag documentation.

Flags: needinfo?(lissyx+mozillians)

Another workaround is changing pdfjs.disableFontFace = true, although I did encounter it failing to render the title of this document.

Flags: needinfo?(lissyx+mozillians)

The package has been pushed to candidate channel, locally updating my VM with snap refresh --candidate gnome-3-38-2004 and the issue is properly fixed. Thanks all for your patience.

Status: REOPENED → RESOLVED
Closed: 2 years ago2 years ago
Resolution: --- → FIXED
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Creator:
Created:
Updated:
Size: