Skip to content

Conversation

@hyperair
Copy link

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 the fltk and slic3r-prusa packages.

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.

AlbrechtS and others added 2 commits September 23, 2025 22:06
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
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Comment all parameters.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed in 32a62bf

*
*/

/* Modified by FLTK to support non-square X,Y axes scaling.
Copy link
Owner

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.

Copy link
Author

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)
Copy link
Owner

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:

  1. flatten the paths, but adjust the tessellation so that it takes scaling into account
  2. expand strokes, including dashing
  3. 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.

Copy link
Author

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.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants