-
Notifications
You must be signed in to change notification settings - Fork 362
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
Proper gradient support #34
Comments
Yes, I'm willing to improve gradient support, but currently I'm super slim on time (building a house). Fixing the xlink:href should be quite easy, gradientUnits=userSpaceOnUse is a bit harder, but surely not impossible. These fixes should be done in the parser side. I'm happy to help you to figure out how to fix them. |
Yes, I can imagine that building a house is really time consuming. I can provide a patch as soon as the other things are working, too.
data->xform seems to be "gradientTransform", but what is "attr->xform"? And which space are you computing in the following code? I suppose it is bounding box space -> gradient space?
What do you mean with
in this context? Do you mean that you've mistaken the units in my example for relative coordinates at first?
That astonishes me. Why should it work when "gradientUnits=userSpaceOnUse" is not yet supported? |
OK, so it seems to work quite well now. I guess you meant to say that gradientUnits="objectBoundingBox" is not yet supported, and not "userSpaceOnUse". I've filed a pull request with some changes: #35 Fixed/added the following things:
So I guess you can close the following reports: For #21 I believe there's still offsetting the radial gradient focus point missing. static NSVGgradient* nsvg__createGradient(NSVGparser* p, const char* id, const float* bounds, char* paintType)
[...]
// TODO: use ref to fill in all unset values too.
[...]
static char nsvg__parseLineCap(const char* str)
[...]
// TODO: handle inherit.
[...]
static char nsvg__parseLineJoin(const char* str)
[...]
// TODO: handle inherit.
[...] I guess this could still be some work. Currently, NanoSVG stores attributes like a gradient's "spread" as chars. In functions like "nsvg__createGradient" there is no way to see whether a value is not set and just initialized to the standard value or it is actually set to the standard value in the file (and therefore mustn't be inherited). The SVG standard states
This could result in some elemental changes in the underlying attribute system. But for now, all features I need seems to work. |
Good fixes, I added one minor nag about style. Otherwise it was good. One option would be to use some value in the attributes which signals that it is not set (i.e. NaN, or -1 depending on value), and make sure a nice default is set in |
I'll see if I have some time in the following days to have a look at it. If the values are initialized with -1, the data type might need to change as the C/C++ standard doesn't define whether a char is signed or unsigned. Different compilers handle it in different ways. |
Just wanted to let you know that I fixed number of issues with gradients and percent coords. If you have time, please test it and see if it works for you. |
Sorry for the late update. |
If I rasterize an object with a (linear) gradient that has a non-identity transform, it is rendered incorrectly (similar to the transform not being set at all).
Here is an example:
NanoSVG rasterizer (my program is applying a blur to the image):
Qt & Inkscape rasterizer (with same blurring code):
Note: The object is not in the center. So when viewing the file in Inkscape, you have to zoom out a bit.
Are you still interested in working on gradients/NanoSVG?
A lot of people would be really grateful if you'd fix these bugs, as NanoSVG is the best lightweight SVG rasterizer out there. There are also libraries like Qt and Cairo, but getting them to work on Android devices could be really hard.
Buggy gradients seem to be a problem for some months now:
#26 (look especially on the linear gradient on the left of the picture)
#27
I can also reproduce this bug: #21
NanoSVG isn't able to dereference "xlink:href" properly, as it doesn't remove the hash in front of the id.
The text was updated successfully, but these errors were encountered: