Skip to content

Commit 07731b2

Browse files
committed
parser fix
1 parent 9ad986f commit 07731b2

File tree

1 file changed

+17
-2
lines changed

1 file changed

+17
-2
lines changed

svgpath/parser.py

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -618,14 +618,29 @@ def scale(width, height, viewBox, z):
618618
return complex(x,y)
619619

620620
paths = []
621+
622+
try:
623+
width = sizeFromString(svg.attrib['width'].strip())
624+
except KeyError:
625+
width = None
626+
try:
627+
height = sizeFromString(svg.attrib['height'].strip())
628+
except KeyError:
629+
height = None
621630

622-
width = sizeFromString(svg.attrib['width'].strip())
623-
height = sizeFromString(svg.attrib['height'].strip())
624631
try:
625632
viewBox = list(map(float, re.split(r'[\s,]+', svg.attrib['viewBox'].strip())))
626633
except KeyError:
634+
if width is None or height is None:
635+
raise KeyError
627636
viewBox = [0, 0, width*96/25.4, height*96/25.4]
628637

638+
if width is None:
639+
width = viewBox[2] * 25.4/96
640+
641+
if height is None:
642+
height = viewBox[3] * 25.4/96
643+
629644
viewBox[2] += viewBox[0]
630645
viewBox[3] += viewBox[1]
631646

0 commit comments

Comments
 (0)