paperjs / paper.js

The Swiss Army Knife of Vector Graphics Scripting – Scriptographer ported to JavaScript and the browser, using HTML5 Canvas. Created by @lehni & @puckey
http://paperjs.org
Other
14.5k stars 1.23k forks source link

NodeJS exportSVG() - document is not defined #214

Closed tranek closed 11 years ago

tranek commented 11 years ago

When calling project.exportSVG() in a NodeJS instance of paper, it errors with:

svg/SVGExport.js:40 document.createElementNS('http://www.w3.org/2000/svg', t ag), attrs); ^ ReferenceError: document is not defined at createElement (svg/SVGExport.js:40:4) at Project.inject.exportSVG (svg/SVGExport.js:515:15) at end_external_path (C:\Users\dan\Documents\GitHub\draw\server.js:201:11) at Socket. (C:\Users\dan\Documents\GitHub\draw\server.js:84:5) at Socket.EventEmitter.emit as $emit at SocketNamespace.handlePacket (C:\Users\dan\node_modules\socket.io\lib\nam espace.js:335:22) at Manager.onClientMessage (C:\Users\dan\node_modules\socket.io\lib\manager. js:488:38) at WebSocket.Transport.onMessage (C:\Users\dan\node_modules\socket.io\lib\tr ansport.js:387:20) at Parser. (C:\Users\dan\node_modules\socket.io\lib\transports\we bsocket\hybi-16.js:39:10) at Parser.EventEmitter.emit (events.js:95:17)

lehni commented 11 years ago

Yeah we haven't ported that code to Node yet. It's relying on browser functionality right now. Thanks for pointing that out! I think there should be a DOM abstraction library that we can pull in to help. It might not be that trivial though. Will investigate soon.

tranek commented 11 years ago

Thank you for responding! Let me know if I can help from the testing side -- the paperjs code is a bit over my head so I don't think that I can help there :)

lehni commented 11 years ago

No it's fine... I know what's there to do, but it might take some time to get it sorted. Hope that's not a show stopper for you guys.

tranek commented 11 years ago

At the moment, it's not a show stopper at all. That's planned for future functionality so no rush from us :)

lehni commented 11 years ago

This was easier than I thought, thanks to the amazing https://github.com/tmpvar/jsdom module. And I was able to squash a few bugs in the node paper module along the way.

SVGImport still needs fixing though! But SVGExport is ready for test spin.

tranek commented 11 years ago

But SVGExport is ready for test spin.

Is that change pushed to the version in npm? Still getting the document error on a quick test.

lehni commented 11 years ago

Done!

lehni commented 11 years ago

And now SVGImport works too! Closing this for now, but these features need extensive testing.

tranek commented 11 years ago

No errors from my quick and dirty testing :)

Thanks!