File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -33,13 +33,28 @@ def default_ext(self):
3333 """
3434 return "svg"
3535
36+ @classmethod
37+ def _parse_svg_dims (cls , value ):
38+ svg_dims_dict = {
39+ 'px' : 1 ,
40+ 'cm' : 37.7952755906 ,
41+ 'pt' : 1 / 0.75 ,
42+ 'in' : 96 ,
43+ 'mm' : 3.77952755906 ,
44+ }
45+ try :
46+ return int (value )
47+ except ValueError :
48+ for unit , factor in svg_dims_dict .items ():
49+ if value .endswith (unit ):
50+ return int (float (value [:- len (unit )]) * factor )
51+
3652 @classmethod
3753 def _dimensions_from_stream (cls , stream ):
3854 stream .seek (0 )
3955 data = stream .read ()
4056 root = ET .fromstring (data )
41- # FIXME: The width could be expressed as '4cm'
4257 # See https://www.w3.org/TR/SVG11/struct.html#NewDocument
43- width = int (root .attrib ["width" ])
44- height = int (root .attrib ["height" ])
58+ width = cls . _parse_svg_dims (root .attrib ["width" ])
59+ height = cls . _parse_svg_dims (root .attrib ["height" ])
4560 return width , height
You can’t perform that action at this time.
0 commit comments