Skip to content

Paint line elements with stroke only - #144

Open
mkantautas wants to merge 1 commit into
dompdf:masterfrom
mkantautas:fix/line-never-filled
Open

mkantautas wants to merge 1 commit into
dompdf:masterfrom
mkantautas:fix/line-never-filled

Conversation

@mkantautas

Copy link
Copy Markdown

SVG line elements are never filled (SVG 1.1, 9.5). Shape::after() applied the fill to lines as well, and the default fill is black, so:

  • a line with stroke="none" or no stroke emits a zero-area fill (m … l f), which PDF viewers draw as a hairline. This is the first problem in line not rendered correctly #122.
  • a stroked line is filled and stroked (B) instead of stroked (S).

This adds Shape::isFillable(), which Line overrides to return false. A line is stroked when it has a stroke and otherwise ends its path without painting (n).

Rendered through Dompdf 3.1.6 (an <img> with an SVG data URI, uncompressed output):

SVG Before After
<line x1="0" y1="20" x2="200" y2="20" stroke="none"/> f, a hairline in PDFium and poppler n, nothing drawn
the same line with stroke="#3366cc" stroke-width="4" B S
<rect width="200" height="40" fill="#eeeeee"/> re f re f

tests/Svg/ShapePaintTest.php renders each shape onto a mocked surface and checks the paint call. Its four line cases fail on master; with this change the suite passes on PHP 7.1 to 8.4 (PHPUnit 7.5 to 11.5). The percentage stroke-opacity reported in #122 stays open.

SVG line elements are never filled. Shape::after() applied the fill,
black by default, to lines as well, so a line with stroke="none" still
emitted a zero-area fill that PDF viewers draw as a hairline, and a
stroked line was filled and stroked.

Refs dompdf#122
@bsweeney bsweeney added this to the 1.0.3 milestone Oct 26, 2026
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