Skip to content

Commit

Permalink
Only emitting warnings on unsupported SVG features (#1034)
Browse files Browse the repository at this point in the history
  • Loading branch information
Lucas-C authored Nov 20, 2023
1 parent 121a93c commit c76329a
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 9 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@ This can also be enabled programmatically with `warnings.simplefilter('default',
* [`FPDF.multi_cell(fill=True)`](https://py-pdf.github.io/fpdf2/fpdf/fpdf.html#fpdf.fpdf.FPDF.multi_cell) now avoids overlapping multiline strings when `padding` is non-zero.
### Changed
* the public `.images`, `.icc_profiles` & `.image_filter` attributes of `FPDF` instances have been moved inside a nested `FPDF.image_cache` attribute
* the `fpdf.svg` module now produces `WARNING` log messages for unsupported SVG tags & attributes.
If those logs annoy you, you can suppress them: `logging.getLogger("fpdf.svg").level = logging.ERROR`
* [`FPDF.table()`](https://py-pdf.github.io/fpdf2/fpdf/fpdf.html#fpdf.fpdf.FPDF.table): If cell styles are provided for cells in heading rows, combine the cell style as an override with the overall heading style.

## [2.7.6] - 2023-10-11
Expand Down
22 changes: 13 additions & 9 deletions fpdf/svg.py
Original file line number Diff line number Diff line change
Expand Up @@ -929,7 +929,10 @@ def build_group(self, group, pdf_group=None):
elif child.tag in xmlns_lookup("svg", "image"):
pdf_group.add_item(self.build_image(child))
else:
LOGGER.debug("Unsupported SVG tag: <%s>", child.tag)
LOGGER.warning(
"Ignoring unsupported SVG tag: <%s> (contributions are welcome to add support for it)",
child.tag,
)

self.update_xref(group.attrib.get("id"), pdf_group)

Expand Down Expand Up @@ -980,16 +983,16 @@ def build_image(self, image):
width = float(image.attrib.get("width", 0))
height = float(image.attrib.get("height", 0))
if "preserveAspectRatio" in image.attrib:
raise NotImplementedError(
'"preserveAspectRatio" defined on <image> is currently not supported (but contributions are welcome!)'
LOGGER.warning(
'"preserveAspectRatio" defined on <image> is currently not supported (contributions are welcome to add support for it)'
)
if "style" in image.attrib:
raise NotImplementedError(
'"style" defined on <image> is currently not supported (but contributions are welcome!)'
LOGGER.warning(
'"style" defined on <image> is currently not supported (contributions are welcome to add support for it)'
)
if "transform" in image.attrib:
raise NotImplementedError(
'"transform" defined on <image> is currently not supported (but contributions are welcome!)'
LOGGER.warning(
'"transform" defined on <image> is currently not supported (contributions are welcome to add support for it)'
)
# Note: at this moment, self.image_cache is not set yet:
svg_image = SVGImage(
Expand Down Expand Up @@ -1037,9 +1040,10 @@ def render(self, _gsd_registry, _style, last_item, initial_point):

_, _, info = preload_image(image_cache, self.href)
if isinstance(info, VectorImageInfo):
raise NotImplementedError(
"Inserting .svg vector graphics in <image> tags is currently not supported (but contributions are welcome!)"
LOGGER.warning(
"Inserting .svg vector graphics in <image> tags is currently not supported (contributions are welcome to add support for it)"
)
return "", last_item, initial_point
w, h = info.size_in_document_units(self.width, self.height)
stream_content = stream_content_for_raster_image(
info=info,
Expand Down

0 comments on commit c76329a

Please sign in to comment.