# HG changeset patch # User Paul Boddie # Date 1220050264 -7200 # Node ID 250a286e47eca819e3aa47d62a4bb7c34f1329d1 # Parent 639a06cd1da8ebbc412885a3eaab4d877725e63c Fixed matrix operations, using post-multiplication of matrices. Added a test of SVG rotation using the existing example file. Updated release notes. diff -r 639a06cd1da8 -r 250a286e47ec README.txt --- a/README.txt Fri Aug 29 00:50:23 2008 +0200 +++ b/README.txt Sat Aug 30 00:51:04 2008 +0200 @@ -70,10 +70,13 @@ * Fixed the ownerElement of attributes created by XPath queries, and in all other situations involving the implementation's get_node method. + * Fixed SVG matrix operations which should have involved matrix + post-multiplication. * Replaced the getElementById implementation with one based on libxml2's own support for finding attributes declared as identifiers. * Introduced support for validation, together with the libxml2dom.errors module. + * Improved error messages related to parsing. New in libxml2dom 0.4.6 (Changes since libxml2dom 0.4.5) -------------------------------------------------------- diff -r 639a06cd1da8 -r 250a286e47ec libxml2dom/svg.py --- a/libxml2dom/svg.py Fri Aug 29 00:50:23 2008 +0200 +++ b/libxml2dom/svg.py Sat Aug 30 00:51:04 2008 +0200 @@ -261,6 +261,9 @@ def __init__(self, a=0, b=0, c=0, d=0, e=0, f=0): self.matrix = a, b, c, d, e, f + def __repr__(self): + return "SVGMatrix(%f, %f, %f, %f, %f, %f)" % self.matrix + def __eq__(self, other): return self.matrix == other.matrix @@ -399,11 +402,11 @@ def mMultiply(self, secondMatrix): """ - Multiply this matrix with 'secondMatrix' and update its contents to the - result of the multiplication operation defined as follows: + Post-multiply this matrix with 'secondMatrix' and update its contents to + the result of the multiplication operation defined as follows: - [ a c e ] [ A C E ] - [ b d f ] [ B D F ] + [ A C E ] [ a c e ] + [ B D F ] [ b d f ] [ 0 0 1 ] [ 0 0 1 ] Return this object as a result. @@ -411,7 +414,7 @@ a, b, c, d, e, f = self.matrix A, B, C, D, E, F = secondMatrix.matrix - 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 + 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 return self def inverse(self): @@ -590,6 +593,9 @@ self.x = x self.y = y + def __repr__(self): + return "SVGPoint(%f, %f)" % (self.x, self.y) + class SVGRect: "A rectangle." @@ -632,13 +638,22 @@ except (IndexError, ValueError): raise xml.dom.DOMException(xml.dom.TYPE_MISMATCH_ERR) + def __repr__(self): + return "SVGRect(%f, %f, %f, %f)" % (self.x, self.y, self.width, self.height) + class SVGRGBColor: - "A colour." + """ + A colour. + See: http://www.w3.org/TR/SVGMobile12/painting.html#colorSyntax + """ def __init__(self, red, green, blue): self.red, self.green, self.blue = red, green, blue + def __repr__(self): + return "SVGRGBColor(%f, %f, %f)" % (self.red, self.green, self.blue) + class TraitAccess: """ @@ -663,11 +678,15 @@ rect.toNode(self, name) def getMatrixTrait(self, name): + if name != "transform": + raise xml.dom.DOMException(xml.dom.NOT_SUPPORTED_ERR) matrix = SVGMatrix() matrix.fromNode(self, name) return matrix def setMatrixTrait(self, name, matrix): + if name != "transform": + raise xml.dom.DOMException(xml.dom.NOT_SUPPORTED_ERR) matrix.toNode(self, name) # Node classes. @@ -773,6 +792,9 @@ self.rotate = 0 self.translate = SVGPoint(0, 0) + # NOTE: The scale, rotate and translate properties are not persistent, and + # NOTE: are specific to individual objects. + def _currentScale(self): return self.scale @@ -782,8 +804,35 @@ def _currentTranslate(self): return self.translate + def _setCurrentScale(self, scale): + if scale == 0: + raise xml.dom.DOMException(xml.dom.INVALID_ACCESS_ERR) + self.scale = scale + + def _setCurrentRotate(self, rotate): + self.rotate = rotate + def _viewport(self): - return self.getRectTrait("viewBox") + if self.hasAttribute("viewBox"): + return self.getRectTrait("viewBox") + else: + return SVGRect(0, 0, self._convertMeasurement(self.getAttribute("width")), + self._convertMeasurement(self.getAttribute("height"))) + + # Utility methods. + + units = ["in", "cm", "mm", "pt", "pc", "px", "%"] + + def _convertMeasurement(self, value): + value = value.strip() + for unit in self.units: + if value.endswith(unit): + # NOTE: No conversion yet! + return float(value[:-len(unit)].strip()) + + raise xml.dom.DOMException(xml.dom.TYPE_MISMATCH_ERR) + + # Standard methods. def getCurrentTime(self): return self.document_time @@ -812,8 +861,8 @@ def getCurrentFocusedObject(self): raise NotImplementedError, "getCurrentFocusedObject" - currentScale = property(_currentScale) - currentRotate = property(_currentRotate) + currentScale = property(_currentScale, _setCurrentScale) + currentRotate = property(_currentRotate, _setCurrentRotate) currentTranslate = property(_currentTranslate) viewport = property(_viewport) diff -r 639a06cd1da8 -r 250a286e47ec packages/debian-etch/python-libxml2dom/debian/changelog --- a/packages/debian-etch/python-libxml2dom/debian/changelog Fri Aug 29 00:50:23 2008 +0200 +++ b/packages/debian-etch/python-libxml2dom/debian/changelog Sat Aug 30 00:51:04 2008 +0200 @@ -3,11 +3,14 @@ * Fixed the ownerElement of attributes created by XPath queries, and in all other situations involving the implementation's get_node method. + * Fixed SVG matrix operations which should have involved + matrix post-multiplication. * Replaced the getElementById implementation with one based on libxml2's own support for finding attributes declared as identifiers. * Introduced support for validation, together with the libxml2dom.errors module. + * Improved error messages related to parsing. -- Paul Boddie Tue, 26 Aug 2008 00:12:15 +0200 diff -r 639a06cd1da8 -r 250a286e47ec packages/debian-sarge/python2.3-libxml2dom/debian/changelog --- a/packages/debian-sarge/python2.3-libxml2dom/debian/changelog Fri Aug 29 00:50:23 2008 +0200 +++ b/packages/debian-sarge/python2.3-libxml2dom/debian/changelog Sat Aug 30 00:51:04 2008 +0200 @@ -3,11 +3,14 @@ * Fixed the ownerElement of attributes created by XPath queries, and in all other situations involving the implementation's get_node method. + * Fixed SVG matrix operations which should have involved + matrix post-multiplication. * Replaced the getElementById implementation with one based on libxml2's own support for finding attributes declared as identifiers. * Introduced support for validation, together with the libxml2dom.errors module. + * Improved error messages related to parsing. -- Paul Boddie Tue, 26 Aug 2008 00:12:33 +0200 diff -r 639a06cd1da8 -r 250a286e47ec packages/ubuntu-feisty/python-libxml2dom/debian/changelog --- a/packages/ubuntu-feisty/python-libxml2dom/debian/changelog Fri Aug 29 00:50:23 2008 +0200 +++ b/packages/ubuntu-feisty/python-libxml2dom/debian/changelog Sat Aug 30 00:51:04 2008 +0200 @@ -3,11 +3,14 @@ * Fixed the ownerElement of attributes created by XPath queries, and in all other situations involving the implementation's get_node method. + * Fixed SVG matrix operations which should have involved + matrix post-multiplication. * Replaced the getElementById implementation with one based on libxml2's own support for finding attributes declared as identifiers. * Introduced support for validation, together with the libxml2dom.errors module. + * Improved error messages related to parsing. -- Paul Boddie Tue, 26 Aug 2008 00:11:32 +0200 diff -r 639a06cd1da8 -r 250a286e47ec packages/ubuntu-hoary/python2.4-libxml2dom/debian/changelog --- a/packages/ubuntu-hoary/python2.4-libxml2dom/debian/changelog Fri Aug 29 00:50:23 2008 +0200 +++ b/packages/ubuntu-hoary/python2.4-libxml2dom/debian/changelog Sat Aug 30 00:51:04 2008 +0200 @@ -3,11 +3,14 @@ * Fixed the ownerElement of attributes created by XPath queries, and in all other situations involving the implementation's get_node method. + * Fixed SVG matrix operations which should have involved + matrix post-multiplication. * Replaced the getElementById implementation with one based on libxml2's own support for finding attributes declared as identifiers. * Introduced support for validation, together with the libxml2dom.errors module. + * Improved error messages related to parsing. -- Paul Boddie Tue, 26 Aug 2008 00:10:37 +0200 diff -r 639a06cd1da8 -r 250a286e47ec tests/test_svg_matrix_rotation.py --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/tests/test_svg_matrix_rotation.py Sat Aug 30 00:51:04 2008 +0200 @@ -0,0 +1,19 @@ +#!/usr/bin/env python + +import libxml2dom.svg + +# NOTE: Need to incorporate unit conversion. + +xscale, yscale = 3.75, 3.75 + +d = libxml2dom.svg.parse("tests/test_svg.xml") +svg = d.documentElement +path = svg.xpath(".//svg:path")[0] +m = svg.createSVGMatrixComponents(1, 0, 0, 1, 0, 0) +m.mTranslate(-20 * xscale, -30 * yscale) +m.mRotate(60) +m.mTranslate(20 * xscale, 30 * yscale) +path.setMatrixTrait("transform", m) +d.toFile(open("tmp_test.svg", "wb")) + +# vim: tabstop=4 expandtab shiftwidth=4