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

[api-minor] Use the NodeCanvasFactory/NodeCMapReaderFactory classes as defaults in Node.js environments (issue 11900) #12039

Merged
merged 1 commit into from
Jul 3, 2020

Conversation

Snuffleupagus
Copy link
Collaborator

@Snuffleupagus Snuffleupagus commented Jun 29, 2020

This moves, and slightly simplifies, code that's currently residing in the unit-test utils into the actual library, such that it's bundled with GENERIC-builds and used in e.g. the API-code.

As an added bonus, this also brings out-of-the-box support for CMaps in e.g. the Node.js examples.

Fixes #11900

Edit: Slightly smaller diff with https://github.com/mozilla/pdf.js/pull/12039/files?w=1

@@ -863,9 +874,9 @@ class PDFDocumentProxy {
* just before viewport transform.
* @property {Object} [imageLayer] - An object that has beginLayout,
* endLayout and appendImage functions.
* @property {Object} [canvasFactory] - The factory that will be used
* @property {Object} [canvasFactory] - The factory instance that will be used
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm really not happy about the discrepancy between CMapReaderFactory (on getDocument) and canvasFactory, since in the first case the user needs to pass a class and in the second one a class instance.
I've tried to make this at least slightly clearer by updating the JSDoc comment here, but it still doesn't seem great. Unfortunately it might simply be (years) too late to try and "fix" this, and furthermore I'm also not entirely sure how to improve it (given how canvasFactory is being used). Oh, well...

@@ -50,14 +50,20 @@ NodeCanvasFactory.prototype = {

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe we should also export the various canvas/CMap-factories in the API as well, such that we could remove things like e.g.

function NodeCanvasFactory() {}
NodeCanvasFactory.prototype = {
create: function NodeCanvasFactory_create(width, height) {
assert(width > 0 && height > 0, "Invalid canvas size");
var canvas = Canvas.createCanvas(width, height);
var context = canvas.getContext("2d");
return {
canvas: canvas,
context: context,
};
},
reset: function NodeCanvasFactory_reset(canvasAndContext, width, height) {
assert(canvasAndContext.canvas, "Canvas is not specified");
assert(width > 0 && height > 0, "Invalid canvas size");
canvasAndContext.canvas.width = width;
canvasAndContext.canvas.height = height;
},
destroy: function NodeCanvasFactory_destroy(canvasAndContext) {
assert(canvasAndContext.canvas, "Canvas is not specified");
// Zeroing the width and height cause Firefox to release graphics
// resources immediately, which can greatly reduce memory consumption.
canvasAndContext.canvas.width = 0;
canvasAndContext.canvas.height = 0;
canvasAndContext.canvas = null;
canvasAndContext.context = null;
},
};

However, I'm not sure if that's (generally) desirable and it also felt somewhat orthogonal to the rest of the patch...

@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/9335ecda106e40a/output.txt

@pdfjsbot
Copy link

From: Bot.io (Windows)


Failed

Full output at http://54.215.176.217:8877/9335ecda106e40a/output.txt

Total script time: 28.66 mins

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

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

@Snuffleupagus Snuffleupagus force-pushed the Node-utils branch 5 times, most recently from 9dbb6d2 to cb6e745 Compare July 2, 2020 01:43
@pdfjsbot
Copy link

pdfjsbot commented Jul 2, 2020

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/f56549a31f87230/output.txt

@pdfjsbot
Copy link

pdfjsbot commented Jul 2, 2020

From: Bot.io (Windows)


Received

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

Live output at: http://54.215.176.217:8877/c02c37c1fd358b1/output.txt

@pdfjsbot
Copy link

pdfjsbot commented Jul 2, 2020

From: Bot.io (Linux m4)


Failed

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

Total script time: 26.44 mins

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

Image differences available at: http://54.67.70.0:8877/f56549a31f87230/reftest-analyzer.html#web=eq.log

@pdfjsbot
Copy link

pdfjsbot commented Jul 2, 2020

From: Bot.io (Windows)


Failed

Full output at http://54.215.176.217:8877/c02c37c1fd358b1/output.txt

Total script time: 29.26 mins

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

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

…es as defaults in Node.js environments (issue 11900)

This moves, and slightly simplifies, code that's currently residing in the unit-test utils into the actual library, such that it's bundled with `GENERIC`-builds and used in e.g. the API-code.

As an added bonus, this also brings out-of-the-box support for CMaps in e.g. the Node.js examples.
@Snuffleupagus
Copy link
Collaborator Author

/botio test

@pdfjsbot
Copy link

pdfjsbot commented Jul 2, 2020

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/e675f011ae31818/output.txt

@pdfjsbot
Copy link

pdfjsbot commented Jul 2, 2020

From: Bot.io (Windows)


Received

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

Live output at: http://54.215.176.217:8877/10a595b8c4ad3a2/output.txt

@pdfjsbot
Copy link

pdfjsbot commented Jul 2, 2020

From: Bot.io (Linux m4)


Failed

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

Total script time: 26.30 mins

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

Image differences available at: http://54.67.70.0:8877/e675f011ae31818/reftest-analyzer.html#web=eq.log

@pdfjsbot
Copy link

pdfjsbot commented Jul 2, 2020

From: Bot.io (Windows)


Failed

Full output at http://54.215.176.217:8877/10a595b8c4ad3a2/output.txt

Total script time: 30.86 mins

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

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

@timvandermeij timvandermeij merged commit 1f71755 into mozilla:master Jul 3, 2020
@timvandermeij
Copy link
Contributor

Looks like a good step forwards to me. Thank you!

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.

pdf2png example cannot render Japanese font
3 participants