33 Commits

Author SHA1 Message Date
Nathan Williis
4b9cb1030e Docs: fix code-example blocks in svgLib. 2024-09-03 17:52:59 +01:00
Khaled Hosny
cf08265cd5 Black 2024-02-06 15:47:35 +02:00
Cosimo Lupo
335a1e56ec re-run black v23.10 on all .py files 2023-11-03 10:25:15 +00:00
Nikolaus Waxweiler
d584daa8fd Blacken code 2022-12-13 11:26:36 +00:00
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
812d05c122 Protect SVG path parsing from negative rx ry on arc commands
SVG documentation has an explicit requirement that _consumers_
of path arc commands accept and *correct* certain bad values.
This includes using the absolute value of the arc command's rx
and ry radius parameters.

See "9.5.1. Out-of-range elliptical arc parameters"
https://www.w3.org/TR/SVG/paths.html#PathDataEllipticalArcCommands

Lib\fontTools\svgLib\path\parser.py is missing any guard against
negative values for rx and ry parameter. Adding an abs() to each
value read will implement the SVG specification.

A problem was seen here while most programs and browsers handle
bad arc commands just fine. A bug report has been registered with
Inkscape (!) to protect any other non-SVG compliant programs.
See https://gitlab.com/inkscape/inbox/-/issues/6857 for more details.
2022-04-23 01:36:30 -05:00
Khaled Hosny
232b2ccbc4 Move the rest of py23 module to textTools
Change all imports to use textTools module, except the test_py23.py test
which is kept until we decide to remove the module (if ever).
2021-08-20 01:29:45 +02: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
Miguel Sousa
299b5bcf85 [svgLib] Add support for line element 2019-04-03 12:02:44 -07:00
Miguel Sousa
8d9a935eaa [svgLib] Add support for polyline element 2019-04-03 12:02:36 -07:00
Miguel Sousa
d5adee46d9 [svgLib] Complete support for matrix transforms 2019-04-03 12:02:18 -07:00
Rod Sheeter
dedf14ac8a Roughing in transform=matrix(...) 2019-04-03 11:58:05 -07:00
Miguel Sousa
e63598f944 [svgLib] Add support for ellipse shape 2019-04-01 22:50:24 -07:00
Miguel Sousa
ddff29cb5d Fix DeprecationWarning: invalid escape sequence 2019-04-01 14:04:14 -07:00
Cosimo Lupo
7a25b3a4e1 factor out _strip_xml_ns into its own function 2019-02-14 17:43:44 +00:00
Cosimo Lupo
dda4c1a41e svgLib: rename PathBuilder's 'pathes' attribute to 'paths' 2019-02-14 17:18:33 +00:00
Cosimo Lupo
a4ed057dd1 minor whitespace 2019-02-14 17:16:26 +00:00
Rod Sheeter
416da67fdd Try to follow FT coding style 2019-02-12 11:53:27 -08:00
Rod Sheeter
199aa9e24b Rudimentary decimal support 2019-02-08 14:59:28 -08:00
Rod Sheeter
1e70458679 More simple shape examples 2019-02-08 13:11:33 -08:00
Rod Sheeter
d910ba371b Wire SVGPath to import other shapes 2019-02-08 11:37:00 -08:00
Rod Sheeter
1292029be2 test for basic rounded rect 2019-02-08 10:50:22 -08:00
Rod Sheeter
f0e8e72187 Test wiring for <rect> import 2019-02-08 10:06:14 -08:00
Cosimo Lupo
f0ab265000
svgLib: add support for converting elliptical arcs to cubic bezier curves
Fixes https://github.com/fonttools/fonttools/issues/1141

Uses code from Chromium Blink's SVG path parser, in SVGPathNormalizer::DecomposeArcToCubic
https://github.com/chromium/chromium/blob/master/third_party/blink/renderer/core/svg/svg_path_parser.cc#L169-L278

Each elliptical arc is approximated by series of cubic bezier curves, one cubic every 90-degree portion of an arc.
2019-01-24 10:59:59 +00:00
Cosimo Lupo
9e85f3bcc3
svgLib: use fontTools.misc.etree 2018-10-18 19:50:26 +01: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
06dc10d30b Fix syntax error about starred expression in python < 3.5
Also minor documentation fix.
2018-01-04 17:56:14 +05:30
Santhosh Thottingal
82e119e0e3 svgLib: Add support for arcs in SVG path parser
Implement the arc to curve points calculation using the original
svg.path library and use the curve points for the pen.

The Arc class and methods to parameterize and get curve points are
copied.

This makes the svg to glif conversion possible for any SVGs.
2018-01-01 20:05:02 +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