-
Notifications
You must be signed in to change notification settings - Fork 372
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
fix handling of <defs> after <g> #123
Conversation
static NSVGgradientLink* nsvg__createGradientLink(const char* id, const float *xform) | ||
{ | ||
NSVGgradientLink* grad = (NSVGgradientLink*)malloc(sizeof(NSVGgradientLink)); | ||
if (grad == NULL) return NULL; |
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.
We should not return NULL because nsvg__createGradient(...NULL...) will crash
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.
You're right, that logic was flawed. Modified the checks for NULL
in nsvg__addShape
(where nsvg__createGradientLink
is called) to reset type
to NSVG_PAINT_NONE
in this case. That way, nsvg__createGradient
will not get called (nsvg__assignGradients
checks for type == NSVG_PAINT_GRADIENT_LINK
).
NSVGgradientData* data = NULL; | ||
NSVGgradientData* ref = NULL; | ||
NSVGgradientStop* stops = NULL; | ||
NSVGgradient* grad; | ||
float ox, oy, sw, sh, sl; | ||
int nstops = 0; | ||
|
||
data = nsvg__findGradientData(p, id); | ||
data = nsvg__findGradientData(p, link->id); |
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.
here what if link==NULL?
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 changed nsvg__assignGradients
to gracefully handle type == NSVG_PAINT_GRADIENT_LINK && gradientLink == NULL
(which, with the modification above, should never happen anyway, so we should be safe now).
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.
Needed to improve
All is good now. |
Please merge! |
a573824
to
02072e0
Compare
I'm closing this in favour of #157, which I think is the cleaner and better solution. |
Some SVGs (like the ones exported from Affinity Designer) have their
<defs>
tags after their<g>
tags. Example file:gradient-circles.svg.zip
Currently, NanoSVG will miss those tags as they're not yet available at the time
<g>
is parsed (i.e. the shapes needing those gradient will not be painted). This PR fixes this by relaying the resolution of gradient names to a point when the whole XML has been parsed.Rendering without PR (background not part of NanoSVG rendering):
Rendering with PR (background not part of NanoSVG rendering):