Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow FontFaceObject.getPathGenerator to ignore non-embedded fonts during rendering #9809

Merged

Conversation

Snuffleupagus
Copy link
Collaborator

This fixes, first of all, the inconsistent error handling that PR #9689 introduced in InternalRenderTask._scheduleNext. With the code currently in master, a "regular" canvas rendering operation is still left in a perpetually pending state if an error is thrown at any point during rendering (leading to a permanent spinner in the viewer).

Furthermore, rather than stopping all rendering when attempting to draw non-embedded fonts as paths, the FontFaceObject.getPathGenerator method is now able to ignore errors[1] and let rendering continue with a warning/notification.

Please note: While this provides a (perhaps) slightly less jarring behaviour for issue #4244 (and its duplicates), keep in mind that the only "real" solution would be to start shipping standard fonts with the PDF.js library.


[1] Similar to PRs #8240 and #8922, this is all controlled with the stopAtErrors parameter; please see

pdf.js/src/display/api.js

Lines 154 to 157 in 2030d17

* @property {boolean} stopAtErrors - (optional) Reject certain promises, e.g.
* `getOperatorList`, `getTextContent`, and `RenderTask`, when the associated
* PDF data cannot be successfully parsed, instead of attempting to recover
* whatever possible of the data. The default value is `false`.

… `InternalRenderTask._scheduleNext`

To support these changes, `InternalRenderTask._next` now returns a Promise.
 - Reduce the overall indentation level, by making use of early returns.

 - Replace `var` with `let`.
…r, and utilize it in `getPathGenerator` to ignore missing glyphs

Obviously it's still not possible to render non-embedded fonts as paths, but in this way the rest of the page will at least be allowed to continue rendering.

*Please note:* Including the 14 standard fonts in PDF.js probably wouldn't be *that* difficult to implement. (I'm not a lawyer, but the fonts from PDFium could probably be used given their BSD license.)
However, the main blocker ought to be the total size of the necessary font data, since I cannot imagine people being OK with shipping ~5 MB of (additional) font data with Firefox. (Based on the reactions when the CMap files were added, and those are only ~1 MB in size.)
@Snuffleupagus
Copy link
Collaborator Author

/botio test

@pdfjsbot
Copy link

From: Bot.io (Linux m4)


Received

Command cmd_test from @Snuffleupagus received. Current queue size: 0

Live output at: http://54.67.70.0:8877/92076e2853494f1/output.txt

@pdfjsbot
Copy link

From: Bot.io (Windows)


Received

Command cmd_test from @Snuffleupagus received. Current queue size: 0

Live output at: http://54.215.176.217:8877/358819db1ba519e/output.txt

@pdfjsbot
Copy link

From: Bot.io (Windows)


Failed

Full output at http://54.215.176.217:8877/358819db1ba519e/output.txt

Total script time: 23.67 mins

  • Font tests: Passed
  • Unit tests: Passed
  • Regression tests: FAILED

Image differences available at: http://54.215.176.217:8877/358819db1ba519e/reftest-analyzer.html#web=eq.log

@pdfjsbot
Copy link

From: Bot.io (Linux m4)


Success

Full output at http://54.67.70.0:8877/92076e2853494f1/output.txt

Total script time: 38.67 mins

  • Font tests: Passed
  • Unit tests: Passed
  • Regression tests: Passed

@timvandermeij
Copy link
Contributor

timvandermeij commented Jun 13, 2018

Something I noticed while looking at this quickly: why do we need the unsupported feature commit exactly? Either we're throwing errors or printing warnings, but in both cases they should end up in the console, which is where the unsupported feature message will be too AFAICT. Wouldn't that result in two messages for the same exception, or is the unsupported feature meant for e.g., the extension?

@Snuffleupagus
Copy link
Collaborator Author

why do we need the unsupported feature commit exactly?

For the native Firefox notification bar, please see

pdf.js/web/app.js

Lines 760 to 761 in b590519

// Listen for unsupported features to trigger the fallback UI.
loadingTask.onUnsupportedFeature = this.fallback.bind(this);
and then the MOZCENTRAL specific code-path in

pdf.js/web/app.js

Lines 825 to 844 in b590519

fallback(featureId) {
if (typeof PDFJSDev !== 'undefined' &&
PDFJSDev.test('FIREFOX || MOZCENTRAL')) {
// Only trigger the fallback once so we don't spam the user with messages
// for one PDF.
if (this.fellback) {
return;
}
this.fellback = true;
this.externalServices.fallback({
featureId,
url: this.baseUrl,
}, function response(download) {
if (!download) {
return;
}
PDFViewerApplication.download();
});
}
},

Hence PDFViewerApplication.fallback is a no-op in non-Firefox builds, so there shouldn't be any duplicate messages. Both the code as written and actual testing agrees with me here :-)

@timvandermeij
Copy link
Contributor

/botio-linux preview

@pdfjsbot
Copy link

From: Bot.io (Linux m4)


Received

Command cmd_preview from @timvandermeij received. Current queue size: 0

Live output at: http://54.67.70.0:8877/80b52a2e130cc3b/output.txt

@pdfjsbot
Copy link

From: Bot.io (Linux m4)


Success

Full output at http://54.67.70.0:8877/80b52a2e130cc3b/output.txt

Total script time: 8.31 mins

Published

@timvandermeij
Copy link
Contributor

/botio makeref

@pdfjsbot
Copy link

From: Bot.io (Linux m4)


Received

Command cmd_makeref from @timvandermeij received. Current queue size: 0

Live output at: http://54.67.70.0:8877/e810ef777e21e02/output.txt

@pdfjsbot
Copy link

From: Bot.io (Windows)


Received

Command cmd_makeref from @timvandermeij received. Current queue size: 0

Live output at: http://54.215.176.217:8877/6ca063f21fab6d3/output.txt

@pdfjsbot
Copy link

From: Bot.io (Windows)


Success

Full output at http://54.215.176.217:8877/6ca063f21fab6d3/output.txt

Total script time: 21.17 mins

  • Lint: Passed
  • Make references: Passed
  • Check references: Passed

@pdfjsbot
Copy link

From: Bot.io (Linux m4)


Success

Full output at http://54.67.70.0:8877/e810ef777e21e02/output.txt

Total script time: 35.54 mins

  • Lint: Passed
  • Make references: Passed
  • Check references: Passed

@timvandermeij timvandermeij merged commit 280f20b into mozilla:master Jun 16, 2018
@timvandermeij
Copy link
Contributor

Really good that rendering now continues; thanks!

@Snuffleupagus Snuffleupagus deleted the getPathGenerator-ignoreErrors branch June 16, 2018 14:49
@Snuffleupagus
Copy link
Collaborator Author

As always, thank you for reviewing :-)

Also, mind closing #9675 as duplicate of #4244, since I don't think the former is needed any more?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants