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.45k stars 1.22k forks source link

Proposal: Snap to pixel #1012

Closed georeith closed 8 years ago

georeith commented 8 years ago

Would be useful to certain use cases to tell items to render at whole pixels to remove anti-aliasing.

They could still be allowed to have decimal bounds internally to maintain the spatial relationship of items within groups say. Purely a setting that would tell item._draw to round certain values so that its bounds are all integer values, things like bezier curves can still be allowed to draw on subpixels of course, only anchor points would be rounded.

The setting is probably best defined at a Project level, to let you turn it on and off per view.

If this sounds like something you would like in the library I would be happy to make a fork and take a stab at implementing it.

lehni commented 8 years ago

We had this discussion before. There is no nice way to implement this with nested matrices and view transformations. I think this belongs into the code that uses paper.js, not into the library itself...

https://groups.google.com/forum/#!msg/paperjs/pqm9VCuXDnY/4MM8wGfjtJgJ

georeith commented 8 years ago

@lehni Even in the case where only the calls to CanvasRenderingContext2D have their values rounded? Are they not post every transformation?

The issue with doing this externally is you have to maintain separate bounds for each item... the real ones you want to use for calculations and the lossy ones to render, where it feels like the library could do it far more efficiently. Especially as this is only a render time setting and thats solely performed by the library.

lehni commented 8 years ago

The transformations are applied to the canvas natively, unfortunately there is no way to tell it to round after transforming the coordinates internally. The only solution would be to perform all transformations in JS, but that's overkill.

georeith commented 8 years ago

Ah yeah that makes sense, yeah definitely that would be overkill. Thanks for explaining.