svg2gcode/svg2gcode.py

changeset 12
a90b8113be25
parent 11
e7feabe18234
child 13
e2fd4d7b3cb6
equal deleted inserted replaced
11:e7feabe18234 12:a90b8113be25
71 def parse_style(stylestr): 71 def parse_style(stylestr):
72 """ 72 """
73 Parse the given string containing CSS2.1 syntax 73 Parse the given string containing CSS2.1 syntax
74 Returns a dict with the keys/values 74 Returns a dict with the keys/values
75 """ 75 """
76 if stylestr.strip() == '': 76 if not stylestr or stylestr.strip() == '':
77 return None 77 return None
78 parser = CSS21Parser() 78 parser = CSS21Parser()
79 style = parser.parse_style_attr(stylestr) 79 style = parser.parse_style_attr(stylestr)
80 data = {} 80 data = {}
81 for obj in style[0]: 81 for obj in style[0]:
226 for l in dwg.segments(1): 226 for l in dwg.segments(1):
227 segments = [] 227 segments = []
228 for pnt in l: 228 for pnt in l:
229 segments.append(pnt.coord()) 229 segments.append(pnt.coord())
230 shape = Polygon(segments) 230 shape = Polygon(segments)
231 if shape.is_valid: 231 #if shape.is_valid:
232 if not poly: 232 if not poly:
233 poly = shape 233 poly = shape
234 else: 234 else:
235 try:
235 if shape.within(poly): 236 if shape.within(poly):
236 poly = poly.difference(shape) 237 poly = poly.difference(shape)
237 else: 238 else:
238 poly = poly.union(shape) 239 poly = poly.union(shape)
239 240 except Exception:
240 lines = poly.intersection(image.infill) 241 pass
242
243 if not poly:
244 continue
245
246 try:
247 lines = poly.intersection(image.infill)
248 except Exception:
249 lines = None
250
241 if lines: 251 if lines:
242 #pprint (dir(lines)) 252 #pprint (dir(lines))
243 # THE INFILL 253 # THE INFILL
244 prev_end = None 254 prev_end = None
245 # sort lines by nearest 255 # sort lines by nearest

mercurial