support for viewbox in importsvg
This commit is contained in:
parent
3cef66aa85
commit
fbe8671542
1 changed files with 7 additions and 0 deletions
|
@ -156,6 +156,12 @@ class Command(BaseCommand):
|
||||||
svg = ElementTree.fromstring(options['svgfile'].read())
|
svg = ElementTree.fromstring(options['svgfile'].read())
|
||||||
svg_width = float(svg.attrib['width'])
|
svg_width = float(svg.attrib['width'])
|
||||||
svg_height = float(svg.attrib['height'])
|
svg_height = float(svg.attrib['height'])
|
||||||
|
svg_viewbox = svg.attrib.get('viewBox')
|
||||||
|
|
||||||
|
if svg_viewbox:
|
||||||
|
offset_x, offset_y, svg_width, svg_height = [float(i) for i in svg_viewbox.split(' ')]
|
||||||
|
else:
|
||||||
|
offset_x, offset_y = 0, 0
|
||||||
|
|
||||||
for element in svg.findall('.//svg:clipPath/..', namespaces):
|
for element in svg.findall('.//svg:clipPath/..', namespaces):
|
||||||
for clippath in element.findall('./svg:clipPath', namespaces):
|
for clippath in element.findall('./svg:clipPath', namespaces):
|
||||||
|
@ -178,6 +184,7 @@ class Command(BaseCommand):
|
||||||
if len(polygon) < 3:
|
if len(polygon) < 3:
|
||||||
continue
|
continue
|
||||||
polygon = Polygon(polygon)
|
polygon = Polygon(polygon)
|
||||||
|
polygon = translate(polygon, xoff=-offset_x, yoff=-offset_y)
|
||||||
polygon = scale(polygon, xfact=1, yfact=-1, origin=(0, svg_height/2))
|
polygon = scale(polygon, xfact=1, yfact=-1, origin=(0, svg_height/2))
|
||||||
polygon = scale(polygon, xfact=width / svg_width, yfact=height / svg_height, origin=(0, 0))
|
polygon = scale(polygon, xfact=width / svg_width, yfact=height / svg_height, origin=(0, 0))
|
||||||
polygon = translate(polygon, xoff=minx, yoff=miny)
|
polygon = translate(polygon, xoff=minx, yoff=miny)
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue