コード例 #1
0
 def process_shape(self, node, mat):
     rgb = (0, 0, 0)
     style = node.get('style')
     if style:
         style = simplestyle.parseStyle(style)
         if style.has_key('stroke'):
             if style['stroke'] and style['stroke'] != 'none' and style[
                     'stroke'][0:3] != 'url':
                 rgb = simplestyle.parseColor(style['stroke'])
     hsl = coloreffect.ColorEffect.rgb_to_hsl(coloreffect.ColorEffect(),
                                              rgb[0] / 255.0,
                                              rgb[1] / 255.0,
                                              rgb[2] / 255.0)
     self.closed = 0  # only for LWPOLYLINE
     self.color = 7  # default is black
     if hsl[2]:
         self.color = 1 + (int(6 * hsl[0] + 0.5) % 6)  # use 6 hues
     if node.tag == inkex.addNS('path', 'svg'):
         d = node.get('d')
         if not d:
             return
         if (d[-1] == 'z' or d[-1] == 'Z'):
             self.closed = 1
         p = cubicsuperpath.parsePath(d)
     elif node.tag == inkex.addNS('rect', 'svg'):
         self.closed = 1
         x = float(node.get('x'))
         y = float(node.get('y'))
         width = float(node.get('width'))
         height = float(node.get('height'))
         p = [[[x, y], [x, y], [x, y]]]
         p.append([[x + width, y], [x + width, y], [x + width, y]])
         p.append([[x + width, y + height], [x + width, y + height],
                   [x + width, y + height]])
         p.append([[x, y + height], [x, y + height], [x, y + height]])
         p.append([[x, y], [x, y], [x, y]])
         p = [p]
     else:
         return
     trans = node.get('transform')
     if trans:
         mat = simpletransform.composeTransform(
             mat, simpletransform.parseTransform(trans))
     simpletransform.applyTransformToPath(mat, p)
     for sub in p:
         for i in range(len(sub) - 1):
             s = sub[i]
             e = sub[i + 1]
             if s[1] == s[2] and e[0] == e[1]:
                 if (self.options.POLY == 'true'):
                     self.LWPOLY_line([s[1], e[1]])
                 else:
                     self.dxf_line([s[1], e[1]])
             elif (self.options.ROBO == 'true'):
                 self.ROBO_spline([s[1], s[2], e[0], e[1]])
             else:
                 self.dxf_spline([s[1], s[2], e[0], e[1]])
コード例 #2
0
 def process_path(self, node, mat):
     rgb = (0, 0, 0)
     style = node.get('style')
     if style:
         style = simplestyle.parseStyle(style)
         if style.has_key('stroke'):
             if style['stroke'] and style['stroke'] != 'none':
                 rgb = simplestyle.parseColor(style['stroke'])
     hsl = coloreffect.ColorEffect.rgb_to_hsl(coloreffect.ColorEffect(),
                                              rgb[0] / 255.0,
                                              rgb[1] / 255.0,
                                              rgb[2] / 255.0)
     self.color = 7  # default is black
     if hsl[2]:
         self.color = 1 + (int(6 * hsl[0] + 0.5) % 6)  # use 6 hues
     d = node.get('d')
     if d:
         p = cubicsuperpath.parsePath(d)
         trans = node.get('transform')
         if trans:
             mat = simpletransform.composeTransform(
                 mat, simpletransform.parseTransform(trans))
         simpletransform.applyTransformToPath(mat, p)
         for sub in p:
             for i in range(len(sub) - 1):
                 s = sub[i]
                 e = sub[i + 1]
                 if s[1] == s[2] and e[0] == e[1]:
                     if (self.options.POLY == 'true'):
                         self.LWPOLY_line([s[1], e[1]])
                     else:
                         self.dxf_line([s[1], e[1]])
                 elif (self.options.ROBO == 'true'):
                     self.ROBO_spline([s[1], s[2], e[0], e[1]])
                 else:
                     self.dxf_spline([s[1], s[2], e[0], e[1]])
コード例 #3
0
 def process_shape(self, node, mat):
     rgb = (0, 0, 0)
     style = node.get('style')
     if style:
         style = simplestyle.parseStyle(style)
         if style.has_key('stroke'):
             if style['stroke'] and style['stroke'] != 'none' and style[
                     'stroke'][0:3] != 'url':
                 rgb = simplestyle.parseColor(style['stroke'])
     hsl = coloreffect.ColorEffect.rgb_to_hsl(coloreffect.ColorEffect(),
                                              rgb[0] / 255.0,
                                              rgb[1] / 255.0,
                                              rgb[2] / 255.0)
     self.color = 7  # default is black
     if hsl[2]:
         self.color = 1 + (int(6 * hsl[0] + 0.5) % 6)  # use 6 hues
     if node.tag == inkex.addNS('path', 'svg'):
         d = node.get('d')
         if not d:
             return
         p = cubicsuperpath.parsePath(d)
     elif node.tag == inkex.addNS('rect', 'svg'):
         x = float(node.get('x', 0))
         y = float(node.get('y', 0))
         width = float(node.get('width'))
         height = float(node.get('height'))
         d = "m %s,%s %s,%s %s,%s %s,%s z" % (x, y, width, 0, 0, height,
                                              -width, 0)
         p = cubicsuperpath.parsePath(d)
     elif node.tag == inkex.addNS('line', 'svg'):
         x1 = float(node.get('x1', 0))
         x2 = float(node.get('x2', 0))
         y1 = float(node.get('y1', 0))
         y2 = float(node.get('y2', 0))
         d = "M %s,%s L %s,%s" % (x1, y1, x2, y2)
         p = cubicsuperpath.parsePath(d)
     elif node.tag == inkex.addNS('circle', 'svg'):
         cx = float(node.get('cx', 0))
         cy = float(node.get('cy', 0))
         r = float(node.get('r'))
         d = "m %s,%s a %s,%s 0 0 1 %s,%s %s,%s 0 0 1 %s,%s z" % (
             cx + r, cy, r, r, -2 * r, 0, r, r, 2 * r, 0)
         p = cubicsuperpath.parsePath(d)
     elif node.tag == inkex.addNS('ellipse', 'svg'):
         cx = float(node.get('cx', 0))
         cy = float(node.get('cy', 0))
         rx = float(node.get('rx'))
         ry = float(node.get('ry'))
         d = "m %s,%s a %s,%s 0 0 1 %s,%s %s,%s 0 0 1 %s,%s z" % (
             cx + rx, cy, rx, ry, -2 * rx, 0, rx, ry, 2 * rx, 0)
         p = cubicsuperpath.parsePath(d)
     else:
         return
     trans = node.get('transform')
     if trans:
         mat = simpletransform.composeTransform(
             mat, simpletransform.parseTransform(trans))
     simpletransform.applyTransformToPath(mat, p)
     for sub in p:
         for i in range(len(sub) - 1):
             s = sub[i]
             e = sub[i + 1]
             if s[1] == s[2] and e[0] == e[1]:
                 if (self.options.POLY == 'true'):
                     self.LWPOLY_line([s[1], e[1]])
                 else:
                     self.dxf_line([s[1], e[1]])
             elif (self.options.ROBO == 'true'):
                 self.ROBO_spline([s[1], s[2], e[0], e[1]])
             else:
                 self.dxf_spline([s[1], s[2], e[0], e[1]])