From 3ca29af7c5314fb9406ed2502da6e5c6de1508f6 Mon Sep 17 00:00:00 2001 From: Petri Lipponen Date: Fri, 17 Jan 2025 12:31:16 +0200 Subject: [PATCH 1/3] Feature: SVG optimization - Use copy=False flag when calling add_item in svg.build_group --- fpdf/svg.py | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) 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)", From b9f460e80d1fa6c673bb43be80a87b0c6609c9de Mon Sep 17 00:00:00 2001 From: Petri Lipponen Date: Fri, 17 Jan 2025 13:26:24 +0200 Subject: [PATCH 2/3] - updated CHANGELOG.md --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index fda2db23a..8d27c18d3 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 ### 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) From bb472f899c162e2847d97de32eefbedb17887019 Mon Sep 17 00:00:00 2001 From: Lucas Cimon <925560+Lucas-C@users.noreply.github.com> Date: Fri, 17 Jan 2025 14:42:48 +0100 Subject: [PATCH 3/3] Update CHANGELOG.md --- CHANGELOG.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 8d27c18d3..cbeb87044 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -20,7 +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 +* 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)