diff options
Diffstat (limited to 'share')
| -rwxr-xr-x | share/extensions/inkex.py | 32 |
1 files changed, 28 insertions, 4 deletions
diff --git a/share/extensions/inkex.py b/share/extensions/inkex.py index 6eb229885..431733f48 100755 --- a/share/extensions/inkex.py +++ b/share/extensions/inkex.py @@ -206,7 +206,7 @@ class Effect: if xattr and yattr: x = self.unittouu( xattr[0] + 'px' ) y = self.unittouu( yattr[0] + 'px') - doc_height = self.unittouu(self.document.getroot().get('height')) + doc_height = self.unittouu(self.getDocumentHeight()) if x and y and doc_height is not None: self.view_center = (float(x), doc_height - float(y)) # FIXME: y-coordinate flip, eliminate it when it's gone in Inkscape @@ -288,6 +288,30 @@ class Effect: __uuconv = {'in':96.0, 'pt':1.33333333333, 'px':1.0, 'mm':3.77952755913, 'cm':37.7952755913, 'm':3779.52755913, 'km':3779527.55913, 'pc':16.0, 'yd':3456.0 , 'ft':1152.0} + # Fault tolerance for lazily defined SVG + def getDocumentWidth(self): + width = self.document.getroot().get('width') + if width: + return width + else: + viewbox = self.document.getroot().get('viewBox') + if viewbox: + return viewbox.split()[2] + else: + return '0' + + # Fault tolerance for lazily defined SVG + def getDocumentHeight(self): + height = self.document.getroot().get('height') + if height: + return height + else: + viewbox = self.document.getroot().get('viewBox') + if viewbox: + return viewbox.split()[3] + else: + return '0' + # Function returns the unit used for the values in SVG. # For lack of an attribute in SVG that explicitly defines what units are used for SVG coordinates, # try to calculate the unit from the SVG width and SVG viewbox. @@ -295,15 +319,15 @@ class Effect: def getDocumentUnit(self): svgunit = 'px' #default to pixels - svgwidth = self.document.getroot().get('width') + svgwidth = self.getDocumentWidth() viewboxstr = self.document.getroot().get('viewBox') if viewboxstr and svgwidth is not None: unitmatch = re.compile('(%s)$' % '|'.join(self.__uuconv.keys())) param = re.compile(r'(([-+]?[0-9]+(\.[0-9]*)?|[-+]?\.[0-9]+)([eE][-+]?[0-9]+)?)') p = param.match(svgwidth) - u = unitmatch.search(svgwidth) - + u = unitmatch.search(svgwidth) + width = 100 #default viewboxwidth = 100 #default svgwidthunit = 'px' #default assume 'px' unit |
