mirror of
https://github.com/mankidev/antialgorithm.git
synced 2026-11-30 19:33:35 -10:00
Retagging <line>, <rect>, <circle> and the other shapes as <path> broke
<style> rules that select by element name. In t2.svg, line.css{stroke:
#e33} and circle{fill:#3c6} stopped matching, so the red line vanished
and the green circle went black. Rules for path went the other way:
path{fill:none} began to empty every converted circle and rect.
Copying each rule to a selector that matches the converted path cannot
keep its specificity: :where() and :is() would, but librsvg 2.63 ignores
both. A copied rule path[data-rough-shape="circle"] (0,1,1) then beats a
class rule (0,1,0), so in
<style>circle{fill:#c00} .blue{fill:#06c}</style>
<circle cx="75" cy="75" r="50"/>
<circle class="blue" cx="225" cy="75" r="50"/>
both circles came out red. Rewriting path to path:not([data-rough-shape])
raised path rules from (0,0,1) to (0,1,1) in the same way, so with
path{fill:#c00} .x{fill:#06c}, a real <path class="x"> turned red as soon
as the drawing also had a shape to convert.
The stylesheet is now left as it is. Each element's matching rules are
found once before any shape changes and once after, and where they
differ, the value the original cascade gave each property those rules
declare is written back onto the element: the first circle above gets
fill="#c00", the blue one is left alone. If a rule the matcher sees
still sets the property on the path, the value goes into the style
attribute instead, with !important when such a rule is !important, so
path{stroke-dasharray:4} does not reach converted shapes. A property the
original did not get at all is written as inherit, or as its initial
value (opacity:1) if it is not inherited; unset and initial are not
used, because librsvg 2.63 ignores both and cairosvg reads unset as
initial. Values rough.py sets itself, fill:none on lines and marker:none
on shapes, are kept.
Writing the value as a presentation attribute where possible keeps it
below any rule the matcher does not see. A rule with another
pseudo-class that still matches the path, such as .a:nth-child(3) or
.a:not(.b), still wins over it. A rule that names the old tag with such a
pseudo-class, circle:nth-child(2){fill:#0a0}, is still lost, as before.
Rules inside @media blocks are not matched, as in librsvg and cairosvg,
so a type rule in one, such as circle{fill:#fff} in
@media (prefers-color-scheme: dark), stops reaching converted shapes in
a browser.