-
Notifications
You must be signed in to change notification settings - Fork 10.1k
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
Conversation
e7d13b1
to
a26aed7
Compare
@@ -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 |
There was a problem hiding this comment.
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 = { | |||
|
There was a problem hiding this comment.
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.
pdf.js/examples/node/pdf2png/pdf2png.js
Lines 20 to 49 in 9993397
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...
a26aed7
to
ae0580e
Compare
From: Bot.io (Windows)ReceivedCommand cmd_test from @Snuffleupagus received. Current queue size: 0 Live output at: http://54.215.176.217:8877/9335ecda106e40a/output.txt |
From: Bot.io (Windows)FailedFull output at http://54.215.176.217:8877/9335ecda106e40a/output.txt Total script time: 28.66 mins
Image differences available at: http://54.215.176.217:8877/9335ecda106e40a/reftest-analyzer.html#web=eq.log |
9dbb6d2
to
cb6e745
Compare
From: Bot.io (Linux m4)ReceivedCommand cmd_test from @Snuffleupagus received. Current queue size: 0 Live output at: http://54.67.70.0:8877/f56549a31f87230/output.txt |
From: Bot.io (Windows)ReceivedCommand cmd_test from @Snuffleupagus received. Current queue size: 0 Live output at: http://54.215.176.217:8877/c02c37c1fd358b1/output.txt |
From: Bot.io (Linux m4)FailedFull output at http://54.67.70.0:8877/f56549a31f87230/output.txt Total script time: 26.44 mins
Image differences available at: http://54.67.70.0:8877/f56549a31f87230/reftest-analyzer.html#web=eq.log |
From: Bot.io (Windows)FailedFull output at http://54.215.176.217:8877/c02c37c1fd358b1/output.txt Total script time: 29.26 mins
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.
/botio test |
From: Bot.io (Linux m4)ReceivedCommand cmd_test from @Snuffleupagus received. Current queue size: 0 Live output at: http://54.67.70.0:8877/e675f011ae31818/output.txt |
From: Bot.io (Windows)ReceivedCommand cmd_test from @Snuffleupagus received. Current queue size: 0 Live output at: http://54.215.176.217:8877/10a595b8c4ad3a2/output.txt |
From: Bot.io (Linux m4)FailedFull output at http://54.67.70.0:8877/e675f011ae31818/output.txt Total script time: 26.30 mins
Image differences available at: http://54.67.70.0:8877/e675f011ae31818/reftest-analyzer.html#web=eq.log |
From: Bot.io (Windows)FailedFull output at http://54.215.176.217:8877/10a595b8c4ad3a2/output.txt Total script time: 30.86 mins
Image differences available at: http://54.215.176.217:8877/10a595b8c4ad3a2/reftest-analyzer.html#web=eq.log |
Looks like a good step forwards to me. Thank you! |
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