From b366272221dbf48b37a102a9a9d0b87fde43cd0e Mon Sep 17 00:00:00 2001 From: petri-lipponen-movesense <95341815+petri-lipponen-movesense@users.noreply.github.com> Date: Fri, 17 Jan 2025 15:43:18 +0200 Subject: [PATCH] Feature: SVG optimization (#1350) Co-authored-by: Lucas Cimon <925560+Lucas-C@users.noreply.github.com> --- CHANGELOG.md | 1 + fpdf/svg.py | 10 +++++----- 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index fda2db23a..cbeb87044 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -20,6 +20,7 @@ This can also be enabled programmatically with `warnings.simplefilter('default', ### Added * support for [shading patterns (gradients)](https://py-pdf.github.io/fpdf2/Patterns.html) * support for strikethrough text +* Improved SVG image speed by 50% to 70% - thanks to @petri-lipponen-movesense - [PR #1350](https://github.com/py-pdf/fpdf2/pull/1350) ### Fixed * [`FPDF.write_html()`](https://py-pdf.github.io/fpdf2/fpdf/fpdf.html#fpdf.fpdf.FPDF.write_html): Fixed rendering of content following `` tags; now correctly resets emphasis style post `` tag: hyperlink styling contained within the tag authority. - [Issue #1311](https://github.com/py-pdf/fpdf2/issues/1311) diff --git a/fpdf/svg.py b/fpdf/svg.py index 503354ca2..fc9d0f7da 100644 --- a/fpdf/svg.py +++ b/fpdf/svg.py @@ -917,15 +917,15 @@ def build_group(self, group, pdf_group=None): if child.tag in xmlns_lookup("svg", "defs"): self.handle_defs(child) elif child.tag in xmlns_lookup("svg", "g"): - pdf_group.add_item(self.build_group(child)) + pdf_group.add_item(self.build_group(child), False) elif child.tag in xmlns_lookup("svg", "path"): - pdf_group.add_item(self.build_path(child)) + pdf_group.add_item(self.build_path(child), False) elif child.tag in shape_tags: - pdf_group.add_item(self.build_shape(child)) + pdf_group.add_item(self.build_shape(child), False) elif child.tag in xmlns_lookup("svg", "use"): - pdf_group.add_item(self.build_xref(child)) + pdf_group.add_item(self.build_xref(child), False) elif child.tag in xmlns_lookup("svg", "image"): - pdf_group.add_item(self.build_image(child)) + pdf_group.add_item(self.build_image(child), False) else: LOGGER.warning( "Ignoring unsupported SVG tag: <%s> (contributions are welcome to add support for it)",