-
Notifications
You must be signed in to change notification settings - Fork 390
Modify rasterizer to support non-square X,Y axes scaling. #274
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
base: master
Are you sure you want to change the base?
Conversation
Add new function nsvgRasterizeXY() similar to nsvgRasterize() but with separate scaling factors for x-axis and y-axis.
src/nanosvgrast.h
Outdated
| 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 |
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.
Comment all parameters.
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.
Fixed in 32a62bf
src/nanosvgrast.h
Outdated
| * | ||
| */ | ||
|
|
||
| /* Modified by FLTK to support non-square X,Y axes scaling. |
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.
This should go to the commit message instead.
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.
Fixed in 5e802eb
| } | ||
|
|
||
| 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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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 😅
Since this is going upstream, this message is no longer needed.
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.