From: acspike Date: Wed, 8 Feb 2006 13:54:22 +0000 (+0000) Subject: Add unit conversion. X-Git-Url: https://git.tokkee.org/?a=commitdiff_plain;h=4197d99c29cdbf6d0eb84306890af8f0e2ecf005;p=inkscape.git Add unit conversion. --- diff --git a/share/extensions/dxf_outlines.py b/share/extensions/dxf_outlines.py index a23949ee8..cb68ef4d6 100755 --- a/share/extensions/dxf_outlines.py +++ b/share/extensions/dxf_outlines.py @@ -16,7 +16,25 @@ You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA ''' -import inkex, simplepath, cubicsuperpath +import inkex, simplepath, cubicsuperpath, re + +uuconv = {'in':90.0, 'pt':1.25, 'px':1, 'mm':3.5433070866, 'cm':35.433070866, 'pc':15.0} +def unittouu(string): + unit = re.compile('(%s)$' % '|'.join(uuconv.keys())) + param = re.compile(r'(([-+]?[0-9]+(\.[0-9]*)?|[-+]?\.[0-9]+)([eE][-+]?[0-9]+)?)') + + p = param.match(string) + u = unit.search(string) + if p: + retval = float(p.string[p.start():p.end()]) + else: + retval = 0.0 + if u: + try: + return retval * uuconv[u.string[u.start():u.end()]] + except KeyError: + pass + return retval class MyEffect(inkex.Effect): def __init__(self): @@ -45,7 +63,7 @@ class MyEffect(inkex.Effect): self.dxf_add("999\nDXF created by Inkscape\n0\nSECTION\n2\nENTITIES") scale = 5.0/18.0 - h = float(inkex.xml.xpath.Evaluate('/svg/@height',self.document)[0].value) + h = unittouu(inkex.xml.xpath.Evaluate('/svg/@height',self.document)[0].value) path = '//path' for node in inkex.xml.xpath.Evaluate(path,self.document):