Repository navigation
SVG: read the context-fill and context-stroke paints - #2198
RavSinghChandan wants to merge 5 commits into
Conversation
The icons of Firefox set fill="context-fill" on the root <svg>, which failed with ValueError. These paints and their opacities are now those of the <use> that draws the element, or else are inherited, as from the colors set on the FPDF.
andersonhc
left a comment
There was a problem hiding this comment.
I noticed one case to address before merging: mapping both context-fill and context-stroke to INHERIT loses the distinction between them. For example, with , a referenced path using fill="context-stroke" should have a lime fill, but currently renders red. An intervening group’s fill can also override the color.
Could we preserve these as distinct values and resolve them against the referencing ? Regression tests for swapped fill/stroke and an intervening group would help cover this.
andersonhc
left a comment
There was a problem hiding this comment.
I found one remaining inheritance case:
<defs>
<path id="p" d="M0 0h5v5z" fill="context-stroke"/>
</defs>
<g fill="red" stroke="lime">
<use href="#p"/>
</g>The path fills red instead of lime. The context lookup misses presentation attributes inherited from the parent; writing those colors in style="..." works. Could we handle inherited presentation attributes too and add regression coverage, including opacity?
One small lint fix: reassigning value in the new test triggers pylint’s redefined-loop-name. A separate variable for the converted expected color should resolve it.
|
Thanks, fixed. context-fill and context-stroke (and their opacities) are now resolved against the referencing : an element that uses them is built again with the fill, stroke and opacities of the , so |
|
Thanks, fixed. When the doesn't set a fill, stroke or opacity, the context lookup now walks up its ancestors and reads presentation attributes as well as styles, so your example fills lime. test_svg_context_paints_inherited_by_the_use covers the attributes (with stroke-opacity) and the style form, through an extra . The test now uses a separate variable for the expected color. |
The icons of Firefox set
fill="context-fill" fill-opacity="context-fill-opacity"on the root<svg>, as in the icons of Firefox-UI-Fix. They fail withValueError: unsupported color specification context-fill.These SVG 2 paints take the fill or stroke of the context element. For an element drawn by a
<use>, that is the<use>. For the SVG itself, it is the document drawing it: Firefox lets the page set it. Socontext-fill,context-stroke,context-fill-opacityandcontext-stroke-opacityare now inherited: inside a<use>they take its paint, and at the root the colors set on the FPDF, ascurrentColordoes without acolorproperty.test_svg_context_fill_is_the_color_of_the_fpdfandtest_svg_context_fill_is_the_paint_of_the_usefail without the change.