Code

Add unit conversion.
authoracspike <acspike@users.sourceforge.net>
Wed, 8 Feb 2006 13:54:22 +0000 (13:54 +0000)
committeracspike <acspike@users.sourceforge.net>
Wed, 8 Feb 2006 13:54:22 +0000 (13:54 +0000)
share/extensions/dxf_outlines.py

index a23949ee8f5cb01910c651d7897d7379286ed6e4..cb68ef4d6c9eed9c6e99c81d323e6f49becceaee 100755 (executable)
@@ -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
+\r
+uuconv = {'in':90.0, 'pt':1.25, 'px':1, 'mm':3.5433070866, 'cm':35.433070866, 'pc':15.0}\r
+def unittouu(string):\r
+       unit = re.compile('(%s)$' % '|'.join(uuconv.keys()))\r
+       param = re.compile(r'(([-+]?[0-9]+(\.[0-9]*)?|[-+]?\.[0-9]+)([eE][-+]?[0-9]+)?)')\r
+\r
+       p = param.match(string)\r
+       u = unit.search(string) \r
+       if p:\r
+               retval = float(p.string[p.start():p.end()])\r
+       else:\r
+               retval = 0.0\r
+       if u:\r
+               try:\r
+                       return retval * uuconv[u.string[u.start():u.end()]]\r
+               except KeyError:\r
+                       pass\r
+       return retval\r
 
 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")\r
         \r
         scale = 5.0/18.0
-        h = float(inkex.xml.xpath.Evaluate('/svg/@height',self.document)[0].value)\r
+        h = unittouu(inkex.xml.xpath.Evaluate('/svg/@height',self.document)[0].value)\r
 
         path = '//path'
         for node in inkex.xml.xpath.Evaluate(path,self.document):\r