Open Bug 1685670 Opened 5 years ago Updated 4 years ago

Garbled PDF when printing if font-loading-api is disabled (via about:config layout.css.font-loading-api.enabled = false)

Categories

(Core :: Printing: Output, defect)

defect

Tracking

()

People

(Reporter: info, Unassigned)

Details

Attachments

(1 file)

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

Steps to reproduce:

Precondition:
In about:config, for security reasons, the option layout.css.font-loading-api.enabled is false.

Test environment:

Steps to reproduce:
1.) Open the PDF file in the browser
2.) wait 30sec (at first view document is displayed correctly)
3.) Print preview of PDF via hamburger button->Print... open

Actual results:

Some (or all) of the text is garbled (see attached file).

Expected results:

correct preview and printout

Bugbug thinks this bug should belong to this component, but please revert this change in case of error.

Component: Untriaged → Printing: Output
Product: Firefox → Core

I was able to reproduce twice on Ubuntu, using a fresh profile (with layout.css.font-loading-api.enabled set to false, per STR).

jfkthame, do you know what might be going on here? The fact that the 30-second delay makes a difference seems particularly odd/interesting.

Flags: needinfo?(jfkthame)
Status: UNCONFIRMED → NEW
Ever confirmed: true
Summary: Garbled PDF when printing if font-loading-api is false → Garbled PDF when printing if font-loading-api is disabld (via about:config layout.css.font-loading-api.enabled = false)
Version: 78 Branch → Trunk

I think the need for the 30-second delay to reproduce this is related to the gfxFontCache expiration timeout: font instances get "aged out" of the cache after not being used for 30 seconds.

Without knowing details of the pdf.js code, what I guess happens is that it extracts embedded font resources from the PDF and constructs @font-face rules with the resources as data: URLs, which works to display the document in the browser even if the font loading API is disabled.

But when we render the print preview (or the actual printed document, presumably), if the PDF's webfonts have expired from cache and need to be reloaded, we fail to wait for them to load (which would be detected via the font loading API) before rendering the document.

Flags: needinfo?(jfkthame)

In about:config, for security reasons, the option layout.css.font-loading-api.enabled is false.

Curious, what security reasons? If it's just about security hardening, the font loading API seems like an odd place to start.

In any case, we have this code to clone the non-rule font-face objects for static documents, and this pdf.js-specific code to deal with fonts.add() while printing, not 100% sure what that's about, it comes from bug 1524640. I wonder if this happens when:

  • printing non-PDF pages which use @font-face and are static or such (I'm hoping we don't mess those up).
  • PDF.js uses mozPrintCallback and a canvas element. I wonder if a reduced test-case could be created for loading a font with @font-face and using canvas after 30s, and whether it'd reproduce the issue.

Simplest fix is probably giving privileged access to the font-loading API to PDF.js (should be trivial-ish using the same nsContentUtils::IsPDFJs function to guard the access to the API). But I also wonder whether there's any reason to keep the font-loading-api.enabled flag around... We're not likely to disable it any time soon...

Summary: Garbled PDF when printing if font-loading-api is disabld (via about:config layout.css.font-loading-api.enabled = false) → Garbled PDF when printing if font-loading-api is disabled (via about:config layout.css.font-loading-api.enabled = false)

jfkthame: Do we expect this to be fixed by 1690235?

Flags: needinfo?(jfkthame)

I think this is a separate issue. For one thing, bug 1690235 is Mac-specific.

Flags: needinfo?(jfkthame)
Severity: -- → S4
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Creator:
Created:
Updated:
Size: