Skip to content

Commit

Permalink
SVG-Fix clipping path being painted - issue #1147 (#1150)
Browse files Browse the repository at this point in the history
* Add DONT_PAINT to path clippingPath

* fix missing import

* add test

* add changelog
  • Loading branch information
andersonhc committed Apr 25, 2024
1 parent 9e847b9 commit 23d76b1
Show file tree
Hide file tree
Showing 5 changed files with 1,297 additions and 0 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Expand Up @@ -29,6 +29,7 @@ This can also be enabled programmatically with `warnings.simplefilter('default',
### Fixed
* ordering RTL fragments on bidirectional texts
* fixed type hint of member `level` in class [`OutlineSection`](https://py-pdf.github.io/fpdf2/fpdf/outline.html#fpdf.outline.OutlineSection) from `str` to `int`.
* SVG clipping paths being incorrectly painted - _cf._ [issue #1147](https://github.com/py-pdf/fpdf2/issues/1147)]
### Changed
* improved the performance of `FPDF.start_section()` - _cf._ [issue #1092](https://github.com/py-pdf/fpdf2/issues/1092)
### Deprecated
Expand Down
3 changes: 3 additions & 0 deletions fpdf/svg.py
Expand Up @@ -13,6 +13,8 @@
from fontTools.svgLib.path import parse_path
from fontTools.pens.basePen import BasePen

from .enums import PathPaintRule

try:
from defusedxml.ElementTree import fromstring as parse_xml_str
except ImportError:
Expand Down Expand Up @@ -963,6 +965,7 @@ def build_clipping_path(self, shape, clip_id):
elif shape.tag in xmlns_lookup("svg", "path"):
clipping_path_shape = PaintedPath()
apply_styles(clipping_path_shape, shape)
clipping_path_shape.paint_rule = PathPaintRule.DONT_PAINT
svg_path = shape.attrib.get("d")
if svg_path is not None:
svg_path_converter(clipping_path_shape, svg_path)
Expand Down
Binary file added test/svg/generated_pdf/path_clippingpath.pdf
Binary file not shown.
4 changes: 4 additions & 0 deletions test/svg/parameters.py
Expand Up @@ -779,6 +779,10 @@ def Gs(**kwargs):
svgfile("issue-1076.svg"),
id="<clipPath> containing a <path>",
),
pytest.param(
svgfile("path_clippingpath.svg"),
id="<clipPath> containing a <path> used in a group with color - issue #1147",
),
)

svg_path_edge_cases = (
Expand Down

0 comments on commit 23d76b1

Please sign in to comment.