bugfixes

Sun, 08 Nov 2015 05:03:45 +0100

author
mbayer
date
Sun, 08 Nov 2015 05:03:45 +0100
changeset 12
a90b8113be25
parent 11
e7feabe18234
child 13
e2fd4d7b3cb6

bugfixes

svg2gcode/svg/svg.py file | annotate | diff | comparison | revisions
svg2gcode/svg2gcode.py file | annotate | diff | comparison | revisions
--- a/svg2gcode/svg/svg.py	Sun Nov 08 04:18:58 2015 +0100
+++ b/svg2gcode/svg/svg.py	Sun Nov 08 05:03:45 2015 +0100
@@ -248,6 +248,10 @@
 
     def __init__(self, elt=None):
         Transformable.__init__(self, elt)
+        if elt is not None:
+            self.style = elt.get('style')
+        else:
+            self.style = ''
 
     def append(self, element):
         for elt in element:
@@ -261,6 +265,10 @@
             item.matrix = self.matrix * item.matrix
             item.viewport = self.viewport
 
+            # inherit style from group
+            if item.style == '':
+                item.style = self.style
+
             self.items.append(item)
             # Recursively append if elt is a <g> (group)
             if elt.tag == svg_ns + 'g':
--- a/svg2gcode/svg2gcode.py	Sun Nov 08 04:18:58 2015 +0100
+++ b/svg2gcode/svg2gcode.py	Sun Nov 08 05:03:45 2015 +0100
@@ -73,7 +73,7 @@
     Parse the given string containing CSS2.1 syntax
     Returns a dict with the keys/values
     """
-    if stylestr.strip() == '':
+    if not stylestr or stylestr.strip() == '':
         return None
     parser = CSS21Parser()
     style = parser.parse_style_attr(stylestr)
@@ -228,16 +228,26 @@
                 for pnt in l:
                     segments.append(pnt.coord())
                 shape = Polygon(segments)
-                if shape.is_valid:
-                    if not poly:
-                        poly = shape
-                    else:
+                #if shape.is_valid:
+                if not poly:
+                    poly = shape
+                else:
+                    try:
                         if shape.within(poly):
                             poly = poly.difference(shape)
                         else:
                             poly = poly.union(shape)
+                    except Exception:
+                        pass
 
-            lines = poly.intersection(image.infill)
+            if not poly:
+                continue
+
+            try:
+                lines = poly.intersection(image.infill)
+            except Exception:
+                lines = None
+
             if lines:
                 #pprint (dir(lines))
                 # THE INFILL

mercurial