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
Implement currentColor support #158
Conversation
- Add color ColorFill object to AttributeState - Updated when 'color' attribute is found - Update parseColor to include Context as an argument - If colourString is 'currentcolor' then uses color in AttributeState
- Running l2r, t2b, the rectangles in the spec svg test: - Fill is black if the color has not yet been set - Fill is black if the color is invalid - Fill is currentColor if color is set inside same node - Stroke is currentColor if color is set inside same node - Fill as currentColor works inside a nested node - Stroke as currentColor works inside a nested node - Fill as currentColor works inside a doubly nested node - Stroke as currentColor works inside a doubly nested node - currentColor uses the last defined color, including if that latest color is defined in the current node - Verify setting color has no impact on sibling node's currentColor
Very nice! Thank you so much for that - I believe we should definitely consider the "use" use-case, because in my experiencethis is one of the most valuable usages of "currentColor". We might analyse the "defs" and search for occurences of "currentColor" and then opt-out of the PDF-sharing of the elements - I don't believe you can parameterized PDF elements - any ideas, @HackbrettXXX ? |
- Allow currentcolor to be used in objects referenced in <use> - The current 'color' is passed down into the referenced object - ReferencesHandler getRendered API is changed to include the color in the key used to map an element to the rendered element - This is so a different PDF FormObject is used if a different color is present - Allow currentcolor to be used for 'stop-color's in <xGradient>'s - Support isn't perfect - In browser implementations of <stop>, the currentcolor always uses the color in the context of where the <stop> is defined; however the parent elements of the <stop> are never walked so we're unable to access this context! - POSSIBLE FIX: use getComputedStyle() of the <xGradient> element in the Gradient constructor to access the current color. However, this requires the SVG to actually be rendered by a browser.
I've pushed another commit that adds
|
Thanks for these improvements.
|
- If "currentColor" is used in the 'stop-color' attribute of a <stop> node then the color is always taken from the context of the <stop> (and not wherever the gradient is used). - Adds a parent attribute to the SvgNode base class to track the parent SvgNode of every node. - If 'stop-color' is set to "currentColor", walks up the DOM (using the parent reference) to calculate the color context as at the <stop> node.
- If "color" is set on the <stop> element itself, ensure it is noted. - Also amends current-color test to verify this behaviour is correct.
|
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.
Thanks for implementing the support for stop-colors as well :)
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.
Thanks for this awesome pull request! Will merge it now.
This PR implements "currentcolour" support for the
fill
andstroke
properties.As per the SVG 1.1 (and 2.0) color spec, a user may specify a
color
property that is inherited by all child nodes. If thefill
orstroke
of any such nodes are set to "currentcolor", then the inheritedcolor
is used.This is implemented by adding a
color
member toAtrributeState
(that defaults to black).parseColor
is amended to take in the currentContext
so that if "currentcolor" is passed, thecolor
in theContext
'sAttributeState
is returned.Note the implementation is imperfect for two reasons:
The spec states that "currentcolor" may also be used byDone: see commit/comment below.stop-color
in gradients. Current browser implementations only ever use thecolor
in-scope of the gradient as defined inside the<defs>
tag; however, noContext
is consumed when aGradient
node is created (as far as I can tell). This means there is no way to access this 'within<defs>
' context. Therefore "currentcolor" is always black if used inside a gradient.Current browser implementations allow the currentDone: see commit/comment below.color
to flow into the shadow-DOM if a<use>
tag is used. However, theAttributeState
is not passed down when aUse
node is rendered, so the current color is inaccessible. So, again "currentcolor" is always black if used inside an element that is referenced with<use>
.Hopefully someone can assist with these problems!
A number of test cases are also added.