Modify rasterizer to support non-square X,Y axes scaling.#274
Modify rasterizer to support non-square X,Y axes scaling.#274hyperair wants to merge 4 commits intomemononen:masterfrom
Conversation
Add new function nsvgRasterizeXY() similar to nsvgRasterize() but with separate scaling factors for x-axis and y-axis.
| NSVGimage* image, float tx, float ty, float scale, | ||
| unsigned char* dst, int w, int h, int stride); | ||
|
|
||
| // As above, but allow X and Y axes to scale independently for non-square aspects |
| * | ||
| */ | ||
|
|
||
| /* Modified by FLTK to support non-square X,Y axes scaling. |
There was a problem hiding this comment.
This should go to the commit message instead.
| } | ||
|
|
||
| static void nsvg__flattenShapeStroke(NSVGrasterizer* r, NSVGshape* shape, float scale) | ||
| static void nsvg__flattenShapeStroke(NSVGrasterizer* r, NSVGshape* shape, float sx, float sy) |
There was a problem hiding this comment.
This function does not seem correct. When scaling non-proportionally, the stroke should scale non-proportionally too.
I think the correct way could be to:
- flatten the paths, but adjust the tessellation so that it takes scaling into account
- expand strokes, including dashing
- scale paths
It should be possible to implement pt 1 by multiplying dx and dy in nsvg__flattenCubicBez() by the scale factors. This needs to be verified, though.
There was a problem hiding this comment.
I agree that this is a bit hacky at the moment.
I'll try taking a crack at it later, but if I'm being honest, this might be a bit beyond me right now, given that I don't understand bezier math yet 😅
There was a problem hiding this comment.
If you're still working on this, I would suggest following:
- do curve scaling as it is now
- separate lineWidth to lineWidthX and lineWidthY, scaled by corresponding scaling factors
- pass the two line widths to nsvg__expandStroke()
- change the cap/join functions to take 2 line widths too
- calcualte two half widths, like:
wx = lineWidthX * 0.5f; wy = lineWidthY * 0.5f; - apply the halfwidths per component:
lx0 = lx1 = p1->x - p1->dmx * wx;
ly0 = ly1 = p1->y - p1->dmy * wy;
Bonus points if you implement vector-effect="non-scaling-stroke", in which case we do not scale the linewidth at all ;)
https://developer.mozilla.org/en-US/docs/Web/SVG/Reference/Attribute/vector-effect
The middle triangle in above also shows the effect we're after, the outline should "squash" if the scaling is not equal.
Since this is going upstream, this message is no longer needed.
32a62bf to
d745b26
Compare
Add new function nsvgRasterizeXY() similar to nsvgRasterize() but with separate scaling factors for x-axis and y-axis.
This is a forward-port of fltk@abcd277 to the current master branch. It is applied on the nanosvg Debian package, and the new
nsvgRasterizeXY()function is used by thefltkandslic3r-prusapackages.It also seems to be more widely used by a number of other projects (many of them are being Slic3r forks), so it would be really good to have this in the main repo.