Skip to content

SVG: read a missing coordinate of a <line> as 0 - #2167

Merged
andersonhc merged 2 commits into
py-pdf:masterfrom
RavSinghChandan:svg-line-default-coordinates
Nov 12, 2026
Merged

andersonhc merged 2 commits into
py-pdf:masterfrom
RavSinghChandan:svg-line-default-coordinates

Conversation

@RavSinghChandan

Copy link
Copy Markdown

A <line> without one of x1, y1, x2 or y2 fails with a KeyError:

SVGObject('<svg xmlns="http://www.w3.org/2000/svg"><line stroke="black" y2="6"/></svg>')
# KeyError: 'x1'

In the SVG specification the initial value of each of the four is 0. D3 relies on that: every tick of a D3 axis is written with only y2 (or x2), as <line stroke="currentColor" y2="6"></line> (tickEnter.append("line").attr(x + "2", k * tickSizeInner) in d3-axis), so an SVG export of a D3 chart could not be converted.

ShapeBuilder.line() now reads a missing coordinate as "0", as circle() and ellipse() already do for cx and cy.

The line no x1 case of test_svg_shape_tags expected the KeyError; it now expects the line from (0, 0), and a new line only y2 case covers a D3 tick. Both fail on master. The SVG tests, black and pylint pass

@andersonhc
andersonhc merged commit 9fabe6e 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