Skip to content

SVG: read stroke-dasharray and stroke-dashoffset lengths with a unit - #2173

Merged
andersonhc merged 3 commits into
py-pdf:masterfrom
RavSinghChandan:svg-dasharray-units
Nov 12, 2026
Merged

andersonhc merged 3 commits into
py-pdf:masterfrom
RavSinghChandan:svg-dasharray-units

Conversation

@RavSinghChandan

Copy link
Copy Markdown

Plotly writes every dotted or dashed line with pixel lengths. Its Drawing.dashStyle() (src/components/drawing/index.js) turns dash="dot" into 3px,3px and "dash" into 9px,9px. So any Plotly figure with a dashed line, exported to SVG, fails in pdf.image():

ValueError: could not convert string to float: '3px'

stroke-dasharray and stroke-dashoffset were read with float(), while stroke-width already goes through resolve_length(). A new convert_dash_length() keeps plain numbers on float(), so nan and inf still get their own "must be finite" errors. A value with a unit now goes through resolve_length(), so 4px is 3 and 1mm is 72/25.4, as for stroke-width="2px".

Two new cases in test_svg_attribute_conversion cover a dasharray and dashoffset in px, and mixed units. Both fail without the change.

Plotly writes every dotted or dashed line as stroke-dasharray: 3px,3px,
which failed with ValueError: could not convert string to float. Plain
numbers are still read with float(), so that NaN and infinity keep
their own error.
@andersonhc
andersonhc merged commit 53f8f06 into py-pdf:master Nov 12, 2026
23 checks passed
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.

2 participants