1.1 --- a/libxml2dom/svg.py Fri Aug 29 00:50:23 2008 +0200
1.2 +++ b/libxml2dom/svg.py Sat Aug 30 00:51:04 2008 +0200
1.3 @@ -261,6 +261,9 @@
1.4 def __init__(self, a=0, b=0, c=0, d=0, e=0, f=0):
1.5 self.matrix = a, b, c, d, e, f
1.6
1.7 + def __repr__(self):
1.8 + return "SVGMatrix(%f, %f, %f, %f, %f, %f)" % self.matrix
1.9 +
1.10 def __eq__(self, other):
1.11 return self.matrix == other.matrix
1.12
1.13 @@ -399,11 +402,11 @@
1.14 def mMultiply(self, secondMatrix):
1.15
1.16 """
1.17 - Multiply this matrix with 'secondMatrix' and update its contents to the
1.18 - result of the multiplication operation defined as follows:
1.19 + Post-multiply this matrix with 'secondMatrix' and update its contents to
1.20 + the result of the multiplication operation defined as follows:
1.21
1.22 - [ a c e ] [ A C E ]
1.23 - [ b d f ] [ B D F ]
1.24 + [ A C E ] [ a c e ]
1.25 + [ B D F ] [ b d f ]
1.26 [ 0 0 1 ] [ 0 0 1 ]
1.27
1.28 Return this object as a result.
1.29 @@ -411,7 +414,7 @@
1.30
1.31 a, b, c, d, e, f = self.matrix
1.32 A, B, C, D, E, F = secondMatrix.matrix
1.33 - self.matrix = a*A + c*B, b*A + d*B, a*C + c*D, b*C + d*D, a*E + c*F + e, b*E + d*F + f
1.34 + self.matrix = A*a + C*b, B*a + D*b, A*c + C*d, B*c + D*d, A*e + C*f + E, B*e + D*f + F
1.35 return self
1.36
1.37 def inverse(self):
1.38 @@ -590,6 +593,9 @@
1.39 self.x = x
1.40 self.y = y
1.41
1.42 + def __repr__(self):
1.43 + return "SVGPoint(%f, %f)" % (self.x, self.y)
1.44 +
1.45 class SVGRect:
1.46
1.47 "A rectangle."
1.48 @@ -632,13 +638,22 @@
1.49 except (IndexError, ValueError):
1.50 raise xml.dom.DOMException(xml.dom.TYPE_MISMATCH_ERR)
1.51
1.52 + def __repr__(self):
1.53 + return "SVGRect(%f, %f, %f, %f)" % (self.x, self.y, self.width, self.height)
1.54 +
1.55 class SVGRGBColor:
1.56
1.57 - "A colour."
1.58 + """
1.59 + A colour.
1.60 + See: http://www.w3.org/TR/SVGMobile12/painting.html#colorSyntax
1.61 + """
1.62
1.63 def __init__(self, red, green, blue):
1.64 self.red, self.green, self.blue = red, green, blue
1.65
1.66 + def __repr__(self):
1.67 + return "SVGRGBColor(%f, %f, %f)" % (self.red, self.green, self.blue)
1.68 +
1.69 class TraitAccess:
1.70
1.71 """
1.72 @@ -663,11 +678,15 @@
1.73 rect.toNode(self, name)
1.74
1.75 def getMatrixTrait(self, name):
1.76 + if name != "transform":
1.77 + raise xml.dom.DOMException(xml.dom.NOT_SUPPORTED_ERR)
1.78 matrix = SVGMatrix()
1.79 matrix.fromNode(self, name)
1.80 return matrix
1.81
1.82 def setMatrixTrait(self, name, matrix):
1.83 + if name != "transform":
1.84 + raise xml.dom.DOMException(xml.dom.NOT_SUPPORTED_ERR)
1.85 matrix.toNode(self, name)
1.86
1.87 # Node classes.
1.88 @@ -773,6 +792,9 @@
1.89 self.rotate = 0
1.90 self.translate = SVGPoint(0, 0)
1.91
1.92 + # NOTE: The scale, rotate and translate properties are not persistent, and
1.93 + # NOTE: are specific to individual objects.
1.94 +
1.95 def _currentScale(self):
1.96 return self.scale
1.97
1.98 @@ -782,8 +804,35 @@
1.99 def _currentTranslate(self):
1.100 return self.translate
1.101
1.102 + def _setCurrentScale(self, scale):
1.103 + if scale == 0:
1.104 + raise xml.dom.DOMException(xml.dom.INVALID_ACCESS_ERR)
1.105 + self.scale = scale
1.106 +
1.107 + def _setCurrentRotate(self, rotate):
1.108 + self.rotate = rotate
1.109 +
1.110 def _viewport(self):
1.111 - return self.getRectTrait("viewBox")
1.112 + if self.hasAttribute("viewBox"):
1.113 + return self.getRectTrait("viewBox")
1.114 + else:
1.115 + return SVGRect(0, 0, self._convertMeasurement(self.getAttribute("width")),
1.116 + self._convertMeasurement(self.getAttribute("height")))
1.117 +
1.118 + # Utility methods.
1.119 +
1.120 + units = ["in", "cm", "mm", "pt", "pc", "px", "%"]
1.121 +
1.122 + def _convertMeasurement(self, value):
1.123 + value = value.strip()
1.124 + for unit in self.units:
1.125 + if value.endswith(unit):
1.126 + # NOTE: No conversion yet!
1.127 + return float(value[:-len(unit)].strip())
1.128 +
1.129 + raise xml.dom.DOMException(xml.dom.TYPE_MISMATCH_ERR)
1.130 +
1.131 + # Standard methods.
1.132
1.133 def getCurrentTime(self):
1.134 return self.document_time
1.135 @@ -812,8 +861,8 @@
1.136 def getCurrentFocusedObject(self):
1.137 raise NotImplementedError, "getCurrentFocusedObject"
1.138
1.139 - currentScale = property(_currentScale)
1.140 - currentRotate = property(_currentRotate)
1.141 + currentScale = property(_currentScale, _setCurrentScale)
1.142 + currentRotate = property(_currentRotate, _setCurrentRotate)
1.143 currentTranslate = property(_currentTranslate)
1.144 viewport = property(_viewport)
1.145