Merge pull request #1563 from fonttools/svgLib-ellipse
[svgLib] Add support for ellipse shape
This commit is contained in:
commit
da6fe5f0e3
@ -116,6 +116,18 @@ class PathBuilder(object):
|
|||||||
self.A(r, r, cx + r, cy, large_arc=1)
|
self.A(r, r, cx + r, cy, large_arc=1)
|
||||||
self.A(r, r, cx - r, cy, large_arc=1)
|
self.A(r, r, cx - r, cy, large_arc=1)
|
||||||
|
|
||||||
|
def _parse_ellipse(self, ellipse):
|
||||||
|
cx = float(ellipse.attrib.get('cx', 0))
|
||||||
|
cy = float(ellipse.attrib.get('cy', 0))
|
||||||
|
rx = float(ellipse.attrib.get('rx'))
|
||||||
|
ry = float(ellipse.attrib.get('ry'))
|
||||||
|
|
||||||
|
# arc doesn't seem to like being a complete shape, draw two halves
|
||||||
|
self._start_path()
|
||||||
|
self.M(cx - rx, cy)
|
||||||
|
self.A(rx, ry, cx + rx, cy, large_arc=1)
|
||||||
|
self.A(rx, ry, cx - rx, cy, large_arc=1)
|
||||||
|
|
||||||
def add_path_from_element(self, el):
|
def add_path_from_element(self, el):
|
||||||
tag = _strip_xml_ns(el.tag)
|
tag = _strip_xml_ns(el.tag)
|
||||||
parse_fn = getattr(self, '_parse_%s' % tag.lower(), None)
|
parse_fn = getattr(self, '_parse_%s' % tag.lower(), None)
|
||||||
|
@ -1,7 +1,6 @@
|
|||||||
from __future__ import print_function, absolute_import, division
|
from __future__ import print_function, absolute_import, division
|
||||||
|
|
||||||
from fontTools.misc.py23 import *
|
from fontTools.misc.py23 import *
|
||||||
from fontTools.pens.recordingPen import RecordingPen
|
|
||||||
from fontTools.svgLib.path import shapes
|
from fontTools.svgLib.path import shapes
|
||||||
from fontTools.misc import etree
|
from fontTools.misc import etree
|
||||||
import pytest
|
import pytest
|
||||||
@ -55,7 +54,17 @@ import pytest
|
|||||||
(
|
(
|
||||||
"<circle cx='12' cy='6.5' r='1.5'></circle>",
|
"<circle cx='12' cy='6.5' r='1.5'></circle>",
|
||||||
"M10.5,6.5 A1.5,1.5 0 1 1 13.5,6.5 A1.5,1.5 0 1 1 10.5,6.5"
|
"M10.5,6.5 A1.5,1.5 0 1 1 13.5,6.5 A1.5,1.5 0 1 1 10.5,6.5"
|
||||||
)
|
),
|
||||||
|
# ellipse
|
||||||
|
(
|
||||||
|
'<ellipse cx="100" cy="50" rx="100" ry="50"/>',
|
||||||
|
'M0,50 A100,50 0 1 1 200,50 A100,50 0 1 1 0,50'
|
||||||
|
),
|
||||||
|
# ellipse, decimal positioning
|
||||||
|
(
|
||||||
|
'<ellipse cx="100.5" cy="50" rx="10" ry="50.5"/>',
|
||||||
|
'M90.5,50 A10,50.5 0 1 1 110.5,50 A10,50.5 0 1 1 90.5,50'
|
||||||
|
),
|
||||||
]
|
]
|
||||||
)
|
)
|
||||||
def test_el_to_path(svg_xml, expected_path):
|
def test_el_to_path(svg_xml, expected_path):
|
||||||
|
Loading…
x
Reference in New Issue
Block a user