Repository navigation
SVG: give currentColor the color property when the SVG sets one - #2184
RavSinghChandan wants to merge 10 commits into
Conversation
currentColor was always read as inherit, so <g color="red"><path fill="currentColor"/></g> was not red. The color property is now carried like the font properties, and apply_styles() gives it to a currentColor fill or stroke of groups, paths, shapes, text and <use>. With no color property, currentColor still inherits, so the color set on the FPDF applies, as py-pdf#1531 intended.
# Conflicts: # CHANGELOG.md
# Conflicts: # CHANGELOG.md
andersonhc
left a comment
There was a problem hiding this comment.
I tested the PR and found two inheritance cases that still need attention:
- With <rect color="blue" …/>, the rectangle renders red instead of blue. The inherited currentColor should resolve using the rectangle’s own color.
- With <rect fill="currentColor" …/>, the rectangle falls back to the FPDF fill color instead of red. Using color="currentColor" on the inner group has the same issue.
Could you take a look at these
# Conflicts: # CHANGELOG.md
A fill or stroke of currentColor inherited from a group now takes the color of the element that uses it, and a color of inherit or currentColor takes the color of the parent, as in CSS.
|
Thanks, both fixed. A group with |
andersonhc
left a comment
There was a problem hiding this comment.
Thanks for fixing the earlier cases and adding tests! I checked the latest revision and found two more inheritance cases:
- a still renders red instead of blue. The same happens with a inside red text that uses fill="currentColor".
- renders red, while omitting fill="inherit" correctly renders blue. Explicit inheritance should behave the same here.
Could you take a look and add regression coverage for these too?
andersonhc
left a comment
There was a problem hiding this comment.
Thanks for fixing the earlier cases and adding regression tests! I found one more inheritance case involving :
<switch color="red" fill="currentColor">
<rect color="blue" width="5" height="5"/>
</switch>The rectangle renders red instead of blue. The equivalent works correctly, and changing the switch to style="fill:currentColor" also produces blue.
Could you apply the same keyword-preservation logic to ?
|
Thanks, both fixed. |
|
Thanks, fixed. The fill and stroke logic of is now a small helper that uses too, so a passes the currentColor keyword down the same way: your example is blue. Two new cases in test_svg_current_color_inheritance cover a with fill="currentColor" and one with fill="inherit" inside a group. |
currentColoris always read asinherit(#1531), so thecolorproperty never reaches it:Icon sets are written this way: the shapes use
fill="currentColor"orstroke="currentColor", andcolorpicks the color.The
colorproperty is now carried down like the font properties, andapply_styles()gives it to acurrentColorfill or stroke of groups, paths, shapes and text, also when it is set in astyleor on an ancestor. When the SVG sets nocolor,currentColorstill inherits, so the color set on theFPDFapplies, as #1531 intended.test_svg_current_color_without_color_propertyand the existingtest_svg_image_style_inherited_from_fpdfcover that.An element in
<defs>that a<use>references is still built once, outside anycolor, so acoloron the<use>does not reach it yet; that would be a follow-up.test_svg_current_color_uses_color_propertycovers an own and an inheritedcolor,fill="currentColor"on a group, acolorin a style, text and a<tspan>; all fail without the change.