Open abrenoch opened 1 year ago
Hey, overriding ctx.save
works in a browser so I think it's completely reasonable for pdfjs
to do this.
It's a bit annoying that node-canvas
now makes this property readonly. You're right that we could probably use a Proxy
to bypass this limitation.
Thanks for the reply! Since this is such a new change, I'm going to bring it up over in the the node-canvas PR... Maybe the read only behavior is just an oversight.
Thanks for the reply! Since this is such a new change, I'm going to bring it up over in the the node-canvas PR... Maybe the read only behavior is just an oversight.
To follow-up here, it is confirmed by node-canvas team (https://github.com/Automattic/node-canvas/pull/2235#issuecomment-1759632954) that it was indeed just an oversight and they will fix when they have some time but also requested if anyone can for a PR they will approve. As @abrenoch mentioned in that thread, I as well do not have C++ experience so if someone else wants to take a look that would be wonderful!
Hey there.
As noted in #225, there is an upcoming major release of
node-canvas
that appears to actually compile correctly with electron. I have been testing this withpdf-to-img
, and it more or less works... But there is an issue I encountered I wanted to bring up because I think it will need to be addressed in some capacity or another. I'm not sure if this is apdfjs
orpdf-to-img
problem (actually I'm about certain it is apdfjs
problem, but the canvas dependency resides in this repo).First things first, my
package.json
looks something like this:This appears to work as expected and installs the
3.0
version of canvas.My test file looks like this:
When running the file, I'm presented with this error:
Looking under the hood of
pdfjs
, the problem seems to arise from themirrorContextOperations
function, which is overwriting many of the built-in canvas context methods such assave
,restore
,scale
, etc.This doesn't seem to have been an issue for the previous version of canvas, but looking over some of the update it received to support NAPI, it seems like those methods are now defined as read-only properties.
Now I'm not sure if this is really an issue for this repo or for the
pdfjs
one. The problem certainly comes from their usage of the canvas context, but considering they don't even have a canvas dependency, I thought maybe this was the place to start. Maybe a sort of proxy object or something that would allow the methods overridden inmirrorContextOperations
to be done so safely.Just wanted to open a discussion!