Skip to content

Commit

Permalink
SVG: added support for parsing exponentiated numbers - solve #376
Browse files Browse the repository at this point in the history
  • Loading branch information
Lucas-C committed Apr 1, 2022
1 parent 1369316 commit 4ec48b6
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 5 deletions.
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ and [PEP 440](https://www.python.org/dev/peps/pep-0440/).
### Fixed
- a regression: now again `multi_cell()` always renders a cell, even if `txt` is an empty string - _cf._ [#349](https://github.com/PyFPDF/fpdf2/issues/349)
- a bug with string width calculation when Markdown is enabled - _cf._ [#351](https://github.com/PyFPDF/fpdf2/issues/351)
- a few bugs when parsing some SVG files - _cf._ [#356](https://github.com/PyFPDF/fpdf2/issues/356) & [#358](https://github.com/PyFPDF/fpdf2/issues/358)
- a few bugs when parsing some SVG files - _cf._ [#356](https://github.com/PyFPDF/fpdf2/issues/356), [#358](https://github.com/PyFPDF/fpdf2/issues/358) & [#376](https://github.com/PyFPDF/fpdf2/issues/376)
- a bug when using `multi_cell(..., split_only=True)` inside an `unbreakable` section - _cf._ [#359](https://github.com/PyFPDF/fpdf2/issues/359)

## [2.5.1] - 2022-03-07
Expand Down
4 changes: 2 additions & 2 deletions docs/UsageInWebAPI.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,6 @@ def report(request):

## web2py ##

Usage of the original PyFPDF lib with [web2py](http://www.web2py.com/) is described here: https://github.com/reingart/pyfpdf/blob/master/docs/Web2Py.md
Usage of the original PyFPDF lib with [web2py](http://www.web2py.com/) is described here: <https://github.com/reingart/pyfpdf/blob/master/docs/Web2Py.md>

PyFPDF is included in `web2py` since release `1.85.2`: <https://github.com/web2py/web2py/tree/master/gluon/contrib/fpdf>
`v1.7.2` of PyFPDF is included in `web2py` since release `1.85.2`: <https://github.com/web2py/web2py/tree/master/gluon/contrib/fpdf>
6 changes: 4 additions & 2 deletions fpdf/svg.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,10 @@ def force_nodocument(item):
"xlink": "http://www.w3.org/1999/xlink",
}

ALPHABET = re.compile(r"([a-zA-Z])")
NUMBER_SIGN = re.compile(r"([+-])")
# "e" is excluded as it is used to build numbers like -2e-3:
ALPHABET = re.compile(r"([a-df-zA-Z])")
# We use a negative lookbehind to NOT split after "e" used as exponentiation:
NUMBER_SIGN = re.compile(r"(?<!e)([+-])")
NUMBER_SPLIT = re.compile(r"(?:\s+,\s+|\s+,|,\s+|\s+|,)")
DECIMAL_DISASTER = re.compile(r"(\d+\.\d+|\d+\.|\.\d+)(\.)")
TRANSFORM_GETTER = re.compile(
Expand Down
5 changes: 5 additions & 0 deletions test/svg/parameters.py
Original file line number Diff line number Diff line change
Expand Up @@ -838,6 +838,11 @@ def Gs(**kwargs):
[M(0, 1), L(2, 3), iz(), M(3, 4), L(5, 6)],
id="implicit close",
),
pytest.param(
"M 0 1 c -7e-5 -4e-5 -8.8492 -3.1382 -8.8493 -3.1383",
[M(0, 1), c(-7e-5, -4e-5, -8.8492, -3.1382, -8.8493, -3.1383)],
id="exponentiated numbers", # cf. issue #376
),
)

svg_path_render_tests = (
Expand Down

0 comments on commit 4ec48b6

Please sign in to comment.