Closed Bug 1766039 Opened 3 years ago Closed 2 years ago

Poor font rendering when viewing some documents in pdf.js on Linux

Categories

(Firefox :: PDF Viewer, defect, P1)

defect

Tracking

()

VERIFIED FIXED
115 Branch
Tracking Status
firefox-esr91 --- wontfix
firefox-esr102 --- wontfix
firefox99 --- wontfix
firefox100 --- wontfix
firefox101 --- wontfix
firefox102 --- wontfix
firefox113 --- wontfix
firefox114 --- wontfix
firefox115 --- verified
firefox116 --- verified

People

(Reporter: botond, Assigned: calixte)

References

(Regression)

Details

(Keywords: regression)

Attachments

(8 files, 1 obsolete file)

STR

Load https://www.tcc-cci.gc.ca/Content/assets/forms/base/general_motion_form65_e.pdf in Firefox Nightly on Linux. Tested using Debian 10.

Actual results

Poor font rendering, with the letters being cramped and in some cases slightly overlapping, as shown in the attached screenshot.

Expected results

PDF renders as it does in a non-browser PDF viewer.

Attached image PDF rendering in Okular

As a point of comparison, here is how the PDF renders in Okular (the default PDF viewer in the KDE desktop environment) on the same system.

Attachment #9273460 - Attachment description: Screenshot → PDF rendering in Firefox Nightly

Finally, here is how the PDF renders in Firefox 78 on the same system. It's still not as nice as Okular (the letters are taller than they should be), but at least they are not overlapping, so the rendering has regressed on the Firefox side since then.

(In reply to Botond Ballo [:botond] from comment #2)

Finally, here is how the PDF renders in Firefox 78 on the same system. It's still not as nice as Okular (the letters are taller than they should be), but at least they are not overlapping, so the rendering has regressed on the Firefox side since then.

Regression range:

https://hg.mozilla.org/mozilla-central/pushloghtml?fromchange=c6d819bd39daf86acd5e0c5bce5d74c2db8b8d64&tochange=bdc02548880557ac7a7d9023e6cadc0c8a44a2b5

I'm guessing "Bug 1686102 - Update pdf.js to version 2.7.510. r=bdahl"?

(In reply to Botond Ballo [:botond] from comment #3)

Regression range:

https://hg.mozilla.org/mozilla-central/pushloghtml?fromchange=c6d819bd39daf86acd5e0c5bce5d74c2db8b8d64&tochange=bdc02548880557ac7a7d9023e6cadc0c8a44a2b5

I'm guessing "Bug 1686102 - Update pdf.js to version 2.7.510. r=bdahl"?

Assuming that's the regressing change, changing component to PDF Viewer. Not sure if there's some way to bisect among pdf.js commits themselves.

Component: Layout: Text and Fonts → PDF Viewer
Product: Core → Firefox

The pdf.js rendering is showing a completely different font from the Okular screenshot. This PDF appears to use Times (actually, TimesNewRomanPSMT, which IIRC is the psname of the Times New Roman shipped on Windows, for example), but does not actually embed the font; it relies on the viewer/renderer having support for the "standard" PDF fonts (Times, Helvetica, Courier, etc) built in.

I'm guessing your Debian system doesn't have a Times font, so we get whatever substitution fontconfig offers, and that doesn't work well because it doesn't match the glyph metrics of Times that were used to lay out the text.

(In reply to Jonathan Kew (:jfkthame) from comment #5)

I'm guessing your Debian system doesn't have a Times font,

Hmm, I do get "Times New Roman" as an option when choosing font in e.g. Kate.

Interesting. In that case it seems surprising that it doesn't get used by pdf.js here, but the glyphs in your screenshots are most definitely not TNR glyphs. Maybe there's an issue with how pdf.js takes the name requested by the PDF and tries to access it on the local system.

What does fc-match -v :family="Times New Roman" show? Curious what names it exposes.

(In reply to Jonathan Kew (:jfkthame) from comment #7)

What does fc-match -v :family="Times New Roman" show? Curious what names it exposes.

Attached the output of this

Thanks. AFAICS, that looks like exactly the expected font.

I don't know how pdf.js goes about accessing installed fonts, but to check whether there's anything weird about the fontconfig setup that might be interfering, could you try the two examples

data:text/html,<div style="font:40px Times New Roman,monospace">Hello world

data:text/html,<style>@font-face{font-family:x;src:local("TimesNewRomanPSMT")}</style><div style="font:40px x,monospace">Hello world

and see what they render? They should both use your installed TNR.

Note that while the "regression" range in comment 3 is interesting -- it seems something about how pdf.js handles the font has changed there -- the Firefox 78 rendering as shown in comment 2 was not using the correct font either. The glyphs there are definitely not Times; they look to me like they're probably DejaVu Serif or something closely related to that.

The font name is changed to Times and it's likely the root cause of the issue here.
We should use the name as it is in the pdf and possibly fallback on an embedded standard font when the font cannot be found on the system.

Assignee: nobody → cdenizet
Severity: -- → S3
Status: NEW → ASSIGNED
Priority: -- → P1

(In reply to Jonathan Kew (:jfkthame) from comment #9)

to check whether there's anything weird about the fontconfig setup that might be interfering, could you try the two examples

data:text/html,<div style="font:40px Times New Roman,monospace">Hello world

data:text/html,<style>@font-face{font-family:x;src:local("TimesNewRomanPSMT")}</style><div style="font:40px x,monospace">Hello world

and see what they render? They should both use your installed TNR.

They render the same. Looks like Times to me, but I attached a screenshot to be sure.

Thanks. Yes, that's Times (New Roman). Good; that confirms there's nothing fundamentally interfering with Firefox finding and using it.
Per comment 10, it sounds pretty clear this is strictly a pdf.js issue; hopefully Calixte can come up with a fix there.

Keywords: regression
Regressed by: 1686102
Has Regression Range: --- → yes

Set release status flags based on info from the regressing bug 1686102

Unsure whether this is the same bug (viewing https://cscie92.dce.harvard.edu/spring2021/Microsoft%20Extensible%20Firmware%20Initiative%20FAT32%20File%20System%20Specification,%20Version%201.03,%2020001206.pdf), but there seem kind of arbitrary font changes (wrong font being used). PDF creator was Microsoft Word 2002. Some fonts seem to be partially embedded, while others are not.

When viewing the same portion of the document in Evince, the fonts seem to display correctly.

the same bug also reported in pdf.js github https://github.com/mozilla/pdf.js/issues/15317

Duplicate of this bug: 1799076
Duplicate of this bug: 1820288
Attachment #9273846 - Attachment is obsolete: true
Status: ASSIGNED → RESOLVED
Closed: 2 years ago
Resolution: --- → FIXED
Target Milestone: --- → 115 Branch

\o/ Thanks very much Calixte & Jonas for your work on this!

Duplicate of this bug: 1752414
Duplicate of this bug: 1768783
Duplicate of this bug: 1752557
Duplicate of this bug: 1124912

I tried multiple builds 78.0, 86.0a1, 91.11.0esr but I could not reproduce the issue on Ubuntu 20.04.
Reporter, can you please confirm issue is fixed on latest Nightly build 116.0a1 (https://archive.mozilla.org/pub/firefox/nightly/2023/06/2023-06-26-09-42-17-mozilla-central/) and latest Beta build 115.0b9 (https://archive.mozilla.org/pub/firefox/candidates/115.0b9-candidates/build1/linux-x86_64/en-US/). Thank you very much.

Flags: needinfo?(botond)

Confirmed that the issue is fixed in the builds from comment 26.

Flags: needinfo?(botond)

Mark issue as verified based on comment#27.

Status: RESOLVED → VERIFIED
Flags: qe-verify+
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Created:
Updated:
Size: