simpletransform.py revision 6a39552e18be9951d0468bcad8778110999245ca
0ba2cbe97e0678a691742f98d2532caed0a2c4aaxcCopyright (C) 2006 Jean-Francois Barraud, barraud@math.univ-lille1.fr
0ba2cbe97e0678a691742f98d2532caed0a2c4aaxcThis program is free software; you can redistribute it and/or modify
0ba2cbe97e0678a691742f98d2532caed0a2c4aaxcit under the terms of the GNU General Public License as published by
0ba2cbe97e0678a691742f98d2532caed0a2c4aaxcthe Free Software Foundation; either version 2 of the License, or
0ba2cbe97e0678a691742f98d2532caed0a2c4aaxc(at your option) any later version.
0ba2cbe97e0678a691742f98d2532caed0a2c4aaxcThis program is distributed in the hope that it will be useful,
0ba2cbe97e0678a691742f98d2532caed0a2c4aaxcbut WITHOUT ANY WARRANTY; without even the implied warranty of
0ba2cbe97e0678a691742f98d2532caed0a2c4aaxcMERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
0ba2cbe97e0678a691742f98d2532caed0a2c4aaxcGNU General Public License for more details.
0ba2cbe97e0678a691742f98d2532caed0a2c4aaxcYou should have received a copy of the GNU General Public License
0ba2cbe97e0678a691742f98d2532caed0a2c4aaxcalong with this program; if not, write to the Free Software
0ba2cbe97e0678a691742f98d2532caed0a2c4aaxcFoundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
0ba2cbe97e0678a691742f98d2532caed0a2c4aaxcbarraud@math.univ-lille1.fr
0ba2cbe97e0678a691742f98d2532caed0a2c4aaxcThis code defines several functions to make handling of transform
0ba2cbe97e0678a691742f98d2532caed0a2c4aaxcattribute easier.
0ba2cbe97e0678a691742f98d2532caed0a2c4aaxcdef parseTransform(transf,mat=[[1.0, 0.0, 0.0], [0.0, 1.0, 0.0]]):
d62bc4badc1c1f1549c961cfb8b420e650e1272byz result=re.match("(translate|scale|rotate|skewX|skewY|matrix)\s*\(([^)]*)\)\s*,?",stransf)
f4b3ec61df05330d25f55a36b975b4d7519fdeb1dh#-- translate --
0ba2cbe97e0678a691742f98d2532caed0a2c4aaxc#-- scale --
e7801d59e8ceda0cde8ebdfdddd7582ee2ea96efsowmini#-- rotate --
bcb5c89da22515e2ccf139578bad3caebcd716adSowmini Varadhan args=result.group(2).replace(',',' ').split()
afdda45f890ee5dfc86e5131a30b11b354d51633Vasumathi Sundaram - Sun Microsystems cx,cy=map(float,args[1:])
d62bc4badc1c1f1549c961cfb8b420e650e1272byz matrix=[[math.cos(a),-math.sin(a),cx],[math.sin(a),math.cos(a),cy]]
e7801d59e8ceda0cde8ebdfdddd7582ee2ea96efsowmini#-- skewX --
d62bc4badc1c1f1549c961cfb8b420e650e1272byz#-- skewY --
e7801d59e8ceda0cde8ebdfdddd7582ee2ea96efsowmini#-- matrix --
afdda45f890ee5dfc86e5131a30b11b354d51633Vasumathi Sundaram - Sun Microsystems a11,a21,a12,a22,v1,v2=result.group(2).replace(',',' ').split()
f4b3ec61df05330d25f55a36b975b4d7519fdeb1dh matrix=[[float(a11),float(a12),float(v1)], [float(a21),float(a22),float(v2)]]
e7801d59e8ceda0cde8ebdfdddd7582ee2ea96efsowmini return ("matrix(%f,%f,%f,%f,%f,%f)" % (mat[0][0], mat[1][0], mat[0][1], mat[1][1], mat[0][2], mat[1][2]))
bcb5c89da22515e2ccf139578bad3caebcd716adSowmini Varadhan #FIXME: how do you raise errors?
e7801d59e8ceda0cde8ebdfdddd7582ee2ea96efsowmini raise AssertionError, 'can not fuse "transform" of elements that have no "d" attribute'
bcb5c89da22515e2ccf139578bad3caebcd716adSowmini Varadhan if t == None:
3bc21d0a9c7b31b1132c254e389a4114c23bcf00Aruna Ramakrishna - Sun Microsystems p = cubicsuperpath.parsePath(d)
3bc21d0a9c7b31b1132c254e389a4114c23bcf00Aruna Ramakrishna - Sun Microsystems node.set('d', cubicsuperpath.formatPath(p))
bcb5c89da22515e2ccf139578bad3caebcd716adSowmini Varadhan####################################################################
3bc21d0a9c7b31b1132c254e389a4114c23bcf00Aruna Ramakrishna - Sun Microsystems##-- Some functions to compute a rough bbox of a given list of objects.
3bc21d0a9c7b31b1132c254e389a4114c23bcf00Aruna Ramakrishna - Sun Microsystems##-- this should be shipped out in an separate file...
e7801d59e8ceda0cde8ebdfdddd7582ee2ea96efsowmini if b1 is None:
e7801d59e8ceda0cde8ebdfdddd7582ee2ea96efsowmini return((min(b1[0],b2[0]), max(b1[1],b2[1]), min(b1[2],b2[2]), max(b1[3],b2[3])))
3bc21d0a9c7b31b1132c254e389a4114c23bcf00Aruna Ramakrishna - Sun Microsystems xmin,xMax,ymin,yMax = path[0][0][0][0],path[0][0][0][0],path[0][0][0][1],path[0][0][0][1]
d62bc4badc1c1f1549c961cfb8b420e650e1272byz #TODO: text not supported!
d62bc4badc1c1f1549c961cfb8b420e650e1272byz d = 'M' + node.get('x', '0') + ',' + node.get('y', '0') + \
d62bc4badc1c1f1549c961cfb8b420e650e1272byz elif node.tag in [ inkex.addNS('circle','svg'), 'circle', \
d62bc4badc1c1f1549c961cfb8b420e650e1272byz if rx is not None:
d62bc4badc1c1f1549c961cfb8b420e650e1272byz if d is not None:
d62bc4badc1c1f1549c961cfb8b420e650e1272byz elif node.tag == inkex.addNS('use','svg') or node.tag=='use':
e7801d59e8ceda0cde8ebdfdddd7582ee2ea96efsowmini# vim: expandtab shiftwidth=4 tabstop=8 softtabstop=4 encoding=utf-8 textwidth=99