Skip to content

Conversation

@poke1024
Copy link
Contributor

@poke1024 poke1024 commented Jul 9, 2018

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):

without-pr

Rendering with PR (background not part of NanoSVG rendering):

with-pr

static NSVGgradientLink* nsvg__createGradientLink(const char* id, const float *xform)
{
NSVGgradientLink* grad = (NSVGgradientLink*)malloc(sizeof(NSVGgradientLink));
if (grad == NULL) return NULL;

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

Copy link
Contributor Author

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).

int nstops = 0;

data = nsvg__findGradientData(p, id);
data = nsvg__findGradientData(p, link->id);

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?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I changed nsvg__assignGradientsto gracefully handle type == NSVG_PAINT_GRADIENT_LINK && gradientLink == NULL (which, with the modification above, should never happen anyway, so we should be safe now).

Copy link

@SergeySlice SergeySlice left a comment

Choose a reason for hiding this comment

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

Needed to improve

@SergeySlice
Copy link

All is good now.

@diimdeep
Copy link

Please merge!

@poke1024
Copy link
Contributor Author

I'm closing this in favour of #157, which I think is the cleaner and better solution.

@poke1024 poke1024 closed this Mar 23, 2019
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.

3 participants