-
Couldn't load subscription status.
- Fork 92
Transform gradients in strokes #143
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
Transform gradients in strokes #143
Conversation
src/transform-applier.js
Outdated
| const svg = SvgElement.set(windowRef.document.createElementNS(SvgElement.svg, 'svg')); | ||
| const path = SvgElement.set(windowRef.document.createElementNS(SvgElement.svg, 'path')); |
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.
| const svg = SvgElement.set(windowRef.document.createElementNS(SvgElement.svg, 'svg')); | |
| const path = SvgElement.set(windowRef.document.createElementNS(SvgElement.svg, 'path')); | |
| const svg = SvgElement.set(doc.createElementNS(SvgElement.svg, 'svg')); | |
| const path = SvgElement.set(doc.createElementNS(SvgElement.svg, 'path')); |
Should I include this code style enhancement as part of this PR?
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.
Sure
| fill = element.attributes.fill.value; | ||
| if (element.attributes) { | ||
| if (element.attributes.fill) fill = element.attributes.fill.value; | ||
| if (element.attributes.stroke) stroke = element.attributes.stroke.value; |
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.
Why are we checking if element.attributes exists here but not checking it in the previous if-block (if (element.attributes['stroke-width']))?
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.
It looks like element.attributes should exist if element.tagName exists, which is what we check for in _isContainerElement, except on Internet Explorer. So the if above would break on IE (but we don't support IE anyway)
e6658ed to
bea1ac6
Compare
| const newStrokeRef = _createGradient(strokeGradientId, svgTag, bbox, matrix); | ||
| if (newStrokeRef) stroke = newStrokeRef; | ||
| } | ||
| } |
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.
It seems like fillGradientId and strokeGradientId might be the same, and if they're the same, we should try not to make a duplicate definition (although I'm not sure if it hurts anything if we do have duplicates)
Instead of checking if an element is a graphics element, check if it's "paintable" (fill/stroke applies to it). This includes several text-related elements, and excludes `use` and `image` elements.
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.
Looks good! Let's merge this after the deploy.
Resolves
Resolves #142
Proposed Changes
This PR extends the gradient-transforming logic in
transformStrokeWidthsto transform gradients not only in fills (as it previously did) but in strokes as well.Reason for Changes
Strokes can also have gradients (and scratchfoundation/scratch-paint#1004 makes this much more likely). Previously, they weren't being taken into account when transforms were being applied.
Test Coverage
Tested manually