12 Commits

Author SHA1 Message Date
Cosimo Lupo
b488d10768
Merge pull request #2611 from tshinnic/svglib_parser_real_number_format
Handle one more valid real number format in svgLib parse_path()
2022-05-04 08:27:24 +01:00
Thomas Shinnick
5abfef15e1 Handle one more valid real number format in svgLib parse_path()
Using svg.draw(pen) and parse_path() from svgLib threw exception
     ValueError: could not convert string to float: 'a'
on a SVG <path> string generated by Inkscape. Altering the path
string might object to other string bits like 'Z' or 'v', or
give even stranger exceptions.

Finally tracked it down to the path containing particular valid
numbers like "-4e-5" or "1e-4". Changing these to "-4.0e-5" or
"1.0e-4" would stop the exceptions. The parse_path() was not
accepting valid SVG real numbers.

The specification for real number formats is a bit of a mess in
CSS land right now, but the reassuringly concrete spec is:
    https://www.w3.org/TR/css-syntax-3/#number-token-diagram
which allows a real number having an exponent but without having
a fractional part, such as the number "1e3".

This change updates an RE to make fractional parts optional,
and adds a test for this valid SVG number format.
2022-05-03 17:48:14 -05:00
Thomas Shinnick
2066d3ad95 Update svgLib test for now non-negative arc radius values
Missed this test in previous commit.

Test is testing that parsing extraction of individual parameters
works as specified when spaces are omitted. Such as signaled when
a new number is specified with a leading sign +/-

Test previously used
     "M1-2A3-4-1.0 01.5.7",
where the first arc radius value was '3' and the second was '-4'.

Now that we are forcing radius values to be non-negative using abs()
the value returned in the test is not
     ("arcTo", (3.0, -4.0, -1.0, False, True, (0.5, 0.7))),
but rather
     ("arcTo", (3.0, 4.0, -1.0, False, True, (0.5, 0.7))),

Changed to expect the positive value, nicely the test continues to
test omitting spaces, but now also tests that negative radius values
are forced non-negative.
2022-05-03 17:21:48 -05:00
Just van Rossum
5fc65d7168
Misc py23 cleanups (#2243)
* Replaced all from ...py23 import * with explicit name imports, or removed completely when possible.
* Replaced tounicode() with tostr()
* Changed all BytesIO ans StringIO imports to from io import ..., replaced all UnicodeIO with StringIO.
* Replaced all unichr() with chr()
* Misc minor tweaks and fixes
2021-03-29 11:45:58 +02:00
Cosimo Lupo
aad51ec4d9
svgLib: handle arc commands with bool flags not separated by space/comma
Some SVG authoring tool write arc commands without any space or comma around the boolean 'large-arc' and 'sweep' flags, leading our svg path parser to choke.
This makes the path parser smarter by special-casing arc command parsing so that it only consumes one character ('0' or '1') for these special boolean flags.
2020-10-29 15:31:47 +00:00
Nikolaus Waxweiler
01328213c7 Remove __future__ imports 2019-08-09 12:20:13 +01:00
Cosimo Lupo
fd219f5d93
add tests for parsing SVG arcs 2019-01-24 11:16:49 +00:00
Cosimo Lupo
40e50b60c3 Revert "Merge pull request #1136 from santhoshtr/svg-arc-support"
This reverts commit 5c392bc86542fbbc0c63335cfedae0d1406b0794, reversing
changes made to 4b69d77ae57776480901e2af82c7d9c1c29de8d6.
2018-01-05 13:07:57 +00:00
Santhosh Thottingal
a8abf7246c Remove duplicate point, add more tests 2018-01-05 17:31:53 +05:30
Santhosh Thottingal
3926353a9f Fix tests for arc parsing using approximate comparison of float values 2018-01-04 21:14:58 +05:30
Santhosh Thottingal
37b3889429 svgLib: Add test for arc parser 2018-01-01 20:46:20 +05:30
Cosimo Lupo
de59719db4 move stuff to fontTools.svgLib.path sub-package
in case later on we want to add things to svgLib which don't have to do with paths specifically
2017-09-12 22:21:20 -04:00