From: acspike Date: Fri, 24 Nov 2006 18:53:21 +0000 (+0000) Subject: move user unit conversion into inkex.py X-Git-Url: https://git.tokkee.org/?a=commitdiff_plain;h=01c0726c10a74120718bd28a49664782f4137d06;p=inkscape.git move user unit conversion into inkex.py --- diff --git a/share/extensions/dxf_outlines.py b/share/extensions/dxf_outlines.py index 176412ea3..e8eff2c01 100755 --- a/share/extensions/dxf_outlines.py +++ b/share/extensions/dxf_outlines.py @@ -16,25 +16,7 @@ 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, 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 +import inkex, simplepath, cubicsuperpath class MyEffect(inkex.Effect): def __init__(self): @@ -63,7 +45,7 @@ class MyEffect(inkex.Effect): self.dxf_add("999\nDXF created by Inkscape\n0\nSECTION\n2\nENTITIES") scale = 25.4/90.0 - h = unittouu(inkex.xml.xpath.Evaluate('/svg/@height',self.document)[0].value) + h = inkex.unittouu(inkex.xml.xpath.Evaluate('/svg/@height',self.document)[0].value) path = '//path' for node in inkex.xml.xpath.Evaluate(path,self.document): diff --git a/share/extensions/inkex.py b/share/extensions/inkex.py index 1ce58d741..4bf977b9b 100755 --- a/share/extensions/inkex.py +++ b/share/extensions/inkex.py @@ -32,6 +32,26 @@ u'inkscape' :u'http://www.inkscape.org/namespaces/inkscape', u'xlink' :u'http://www.w3.org/1999/xlink' } +#a dictionary of unit to user unit conversion factors +uuconv = {'in':90.0, 'pt':1.25, 'px':1, 'mm':3.5433070866, 'cm':35.433070866, 'pc':15.0} +def unittouu(string): + '''Returns returns userunits given a string representation of units in another system''' + 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 + try: import xml.dom.ext import xml.dom.minidom diff --git a/share/extensions/interp.py b/share/extensions/interp.py index ba8d8d7f4..f0ba8f26c 100755 --- a/share/extensions/interp.py +++ b/share/extensions/interp.py @@ -16,9 +16,8 @@ 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, cubicsuperpath, simplestyle, copy, math, re, bezmisc +import inkex, cubicsuperpath, simplestyle, copy, math, bezmisc -uuconv = {'in':90.0, 'pt':1.25, 'px':1, 'mm':3.5433070866, 'cm':35.433070866, 'pc':15.0} def numsegs(csp): return sum([len(p)-1 for p in csp]) def interpcoord(v1,v2,p): @@ -56,30 +55,14 @@ def csplength(csp): lengths[-1].append(l) total += l return lengths, total -def styleunittouu(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 def tweenstylefloat(property, start, end, time): sp = float(start[property]) ep = float(end[property]) return str(sp + (time * (ep - sp))) def tweenstyleunit(property, start, end, time): - sp = styleunittouu(start[property]) - ep = styleunittouu(end[property]) + sp = inkex.unittouu(start[property]) + ep = inkex.unittouu(end[property]) return str(sp + (time * (ep - sp))) def tweenstylecolor(property, start, end, time): sr,sg,sb = parsecolor(start[property]) diff --git a/share/extensions/summersnight.py b/share/extensions/summersnight.py index b94d2b9b7..2fca74a50 100755 --- a/share/extensions/summersnight.py +++ b/share/extensions/summersnight.py @@ -17,27 +17,9 @@ 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, os, re, simplepath, cubicsuperpath +import inkex, os, simplepath, cubicsuperpath from ffgeom import * -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 Project(inkex.Effect): def __init__(self): inkex.Effect.__init__(self) @@ -69,7 +51,7 @@ class Project(inkex.Effect): self.q[query] = float(f.read()) f.close() #glean document height from the SVG - docheight = unittouu(inkex.xml.xpath.Evaluate('/svg/@height',self.document)[0].value) + docheight = inkex.unittouu(inkex.xml.xpath.Evaluate('/svg/@height',self.document)[0].value) #Flip inkscapes transposed renderer coords self.q['y'] = docheight - self.q['y'] - self.q['height']