Skip to content

SVG: apply CSS rules with id, compound and descendant selectors - #2201

Open
RavSinghChandan wants to merge 2 commits into
py-pdf:masterfrom
RavSinghChandan:svg-css-descendant-selectors
Open

RavSinghChandan wants to merge 2 commits into
py-pdf:masterfrom
RavSinghChandan:svg-css-descendant-selectors

Conversation

@RavSinghChandan

Copy link
Copy Markdown

Mermaid styles flowcharts with rules such as #mermaid-svg .node rect { fill: #ECECFF; stroke: #9370DB }. fpdf2 only reads class, element and * selectors, so these rules are ignored and every node of a Mermaid flowchart is drawn as a black box.

Selectors made of element names, ids and classes, joined by descendant or child combinators (#m .node rect, rect#a.b, g.node > rect), now apply. The rules of an element are applied by specificity, then in order, as in CSS; class, element and * rules behave as before. Selectors with pseudo-classes, attribute selectors or sibling combinators are still ignored. What is known about each element is kept, so matching takes linear time in the number of elements, even for a long selector over deeply nested groups.

test_svg_css_selectors_with_ids_and_combinators and test_svg_css_descendant_selectors_linear_time cover these; they fail without the change. None of the 258 SVGs with a <style> I tried fails where it did not before.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant