diff --git a/CHANGELOG.md b/CHANGELOG.md index 00683fc99..22bcbfd1b 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -29,6 +29,7 @@ This can also be enabled programmatically with `warnings.simplefilter('default', - `fpdf2` now uses [fontTools](https://fonttools.readthedocs.io/en/latest/) to read and embed fonts in the PDF, thanks to @gmischler and @RedShy ### Fixed +- The SVG parser now accepts stroke-width attribute values with an explicit unit, thanks to @gmischler; [#526](https://github.com/PyFPDF/fpdf2/issues/526) - Text following a HTML heading can't overlap with that heading anymore, thanks to @gmischler - `arc()` not longer renders artefacts at intersection point, thanks to @Jmillan-Dev; [#488](https://github.com/PyFPDF/fpdf2/issues/488) - [`write_html()`](https://pyfpdf.github.io/fpdf2/HTML.html): diff --git a/fpdf/svg.py b/fpdf/svg.py index 3277ed61d..d6f3e129c 100644 --- a/fpdf/svg.py +++ b/fpdf/svg.py @@ -119,7 +119,10 @@ class Percent(float): @force_nodocument def resolve_length(length_str, default_unit="pt"): """Convert a length unit to our canonical length unit, pt.""" - value, unit = unit_splitter.match(length_str).groups() + match = unit_splitter.match(length_str) + if match == None: + raise ValueError(f"Unable to parse '{length_str}' as a length") from None + value, unit = match.groups() if not unit: unit = default_unit @@ -193,7 +196,7 @@ def svgcolor(colorstr): @force_nodocument def convert_stroke_width(incoming): - val = float(incoming) + val = resolve_length(incoming) if val < 0: raise ValueError(f"stroke width {incoming} cannot be negative") if val == 0: diff --git a/test/svg/parameters.py b/test/svg/parameters.py index a3e8d42b7..72b169a5e 100644 --- a/test/svg/parameters.py +++ b/test/svg/parameters.py @@ -580,6 +580,12 @@ def Gs(**kwargs): no_error(), id="stroke-width number", ), + pytest.param( # issue #526 + '', + Gs(stroke_width=2 * 0.75), + no_error(), + id="stroke-width number", + ), pytest.param( '', Gs(),