Code

fix bug with implicit paths
[inkscape.git] / share / extensions / dxf_outlines.py
index a23949ee8f5cb01910c651d7897d7379286ed6e4..176412ea3e279195606c14fc6fb6c447f22b38b7 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):
@@ -44,8 +62,8 @@ class MyEffect(inkex.Effect):
         #              NURB Curves: A Guide for the Uninitiated By Philip J. Schneider
         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
+        scale = 25.4/90.0
+        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