当前位置: 首页>>代码示例>>Python>>正文


Python simplepath.formatPath函数代码示例

本文整理汇总了Python中simplepath.formatPath函数的典型用法代码示例。如果您正苦于以下问题:Python formatPath函数的具体用法?Python formatPath怎么用?Python formatPath使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了formatPath函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: inkscape

def inkscape(hpgl,svg,inkex):
	layer = inkex.etree.SubElement(svg, 'g')
	layer.set(inkex.addNS('label', 'inkscape'), 'InkCut Preview Layer')
	layer.set(inkex.addNS('groupmode', 'inkscape'), 'layer')
	spPU = [['M',[0,0]]]
	spPD = []
	for c in hpgl.split(';'):
		if c[:2] == "PU":
			p = map(int,c[2:].split(','))
			spPD.append(['M',p])
			spPU.append(['L',p])
		elif c[:2] == "PD":
			p = map(int,c[2:].split(','))
			spPU.append(['M',p])
			spPD.append(['L',p])		
	
	pu = inkex.etree.Element(inkex.addNS('path','svg'))
	
	simplepath.scalePath(spPU,0.088582677,-0.088582677)
	simplepath.translatePath(spPU,0,float(svg.get('height')))
	
	style = {'fill' : 'none','stroke-opacity': '.8','stroke':'#116AAB'}
	pu.set('style', simplestyle.formatStyle(style))
	pu.set('d',simplepath.formatPath(spPU))
	
	
	pd = inkex.etree.Element(inkex.addNS('path','svg'))
	
	style = {'fill' : 'none','stroke-opacity': '.8','stroke':'#AB3011'}
	pd.set('style', simplestyle.formatStyle(style))
	pd.set('d',simplepath.formatPath(spPD))
	
	# Connect elements together.
	layer.append(pu)
	layer.append(pd)
开发者ID:shackspace,项目名称:inkcut_dmpl,代码行数:35,代码来源:preview.py

示例2: effect

    def effect(self):
        paths = []
        for id, node in self.selected.iteritems():
            if node.tag == '{http://www.w3.org/2000/svg}path':
                paths.append(node)
                if len(paths) == 2:
                    break
        else:
            sys.stderr.write('Need 2 paths selected\n')
            return


        pts = [cubicsuperpath.parsePath(paths[i].get('d'))
               for i in (0,1)]

        for i in (0,1):
            if 'transform' in paths[i].keys():
                trans = paths[i].get('transform')
                trans = simpletransform.parseTransform(trans)
                simpletransform.applyTransformToPath(trans, pts[i])

        verts = []
        for i in range(0, min(map(len, pts))):
            comp = []
            for j in range(0, min(len(pts[0][i]), len(pts[1][i]))):
                comp.append([pts[0][i][j][1][-2:], pts[1][i][j][1][-2:]])
            verts.append(comp)

        if self.options.mode.lower() == 'lines':
            line = []
            for comp in verts:
                for n,v in enumerate(comp):
                  line += [('M', v[0])]
                  line += [('L', v[1])]
            ele = inkex.etree.Element('{http://www.w3.org/2000/svg}path')
            paths[0].xpath('..')[0].append(ele)
            ele.set('d', simplepath.formatPath(line))
            ele.set('style', 'fill:none;stroke:#000000;stroke-opacity:1;stroke-width:1;')
        elif self.options.mode.lower() == 'polygons':
            g = inkex.etree.Element('{http://www.w3.org/2000/svg}g')
            g.set('style', 'fill:#000000;stroke:#000000;fill-opacity:0.3;stroke-width:2;stroke-opacity:0.6;')   
            paths[0].xpath('..')[0].append(g)
            for comp in verts:
                for n,v in enumerate(comp):
                    nn = n+1
                    if nn == len(comp): nn = 0
                    line = []
                    line += [('M', comp[n][0])]
                    line += [('L', comp[n][1])]
                    line += [('L', comp[nn][1])]
                    line += [('L', comp[nn][0])]
                    line += [('L', comp[n][0])]
                    ele = inkex.etree.Element('{http://www.w3.org/2000/svg}path')
                    g.append(ele)
                    ele.set('d', simplepath.formatPath(line))
开发者ID:step21,项目名称:inkscape-osx-packaging-native,代码行数:55,代码来源:extrude.py

示例3: effect

    def effect(self):
        paths = []
        for id, node in self.selected.iteritems():
            if node.tag == "{http://www.w3.org/2000/svg}path":
                paths.append(node)
                if len(paths) == 2:
                    break
        else:
            sys.stderr.write("Need 2 paths selected\n")
            return

        pts = [cubicsuperpath.parsePath(paths[i].get("d")) for i in (0, 1)]

        for i in (0, 1):
            if "transform" in paths[i].keys():
                trans = paths[i].get("transform")
                trans = simpletransform.parseTransform(trans)
                simpletransform.applyTransformToPath(trans, pts[i])

        verts = []
        for i in range(0, min(map(len, pts))):
            comp = []
            for j in range(0, min(len(pts[0][i]), len(pts[1][i]))):
                comp.append([pts[0][i][j][1][-2:], pts[1][i][j][1][-2:]])
            verts.append(comp)

        if self.options.mode.lower() == "lines":
            line = []
            for comp in verts:
                for n, v in enumerate(comp):
                    line += [("M", v[0])]
                    line += [("L", v[1])]
            ele = inkex.etree.Element("{http://www.w3.org/2000/svg}path")
            paths[0].xpath("..")[0].append(ele)
            ele.set("d", simplepath.formatPath(line))
            ele.set("style", "fill:none;stroke:#000000;stroke-opacity:1;stroke-width:1;")
        elif self.options.mode.lower() == "polygons":
            g = inkex.etree.Element("{http://www.w3.org/2000/svg}g")
            g.set("style", "fill:#000000;stroke:#000000;fill-opacity:0.3;stroke-width:2;stroke-opacity:0.6;")
            paths[0].xpath("..")[0].append(g)
            for comp in verts:
                for n, v in enumerate(comp):
                    nn = n + 1
                    if nn == len(comp):
                        nn = 0
                    line = []
                    line += [("M", comp[n][0])]
                    line += [("L", comp[n][1])]
                    line += [("L", comp[nn][1])]
                    line += [("L", comp[nn][0])]
                    line += [("L", comp[n][0])]
                    ele = inkex.etree.Element("{http://www.w3.org/2000/svg}path")
                    g.append(ele)
                    ele.set("d", simplepath.formatPath(line))
开发者ID:wdmchaft,项目名称:DoonSketch,代码行数:54,代码来源:extrude.py

示例4: hpgl

def hpgl(plot):
	#create a preview svg
	svg = etree.Element(inkex.addNS('svg','svg'))
	svg.set('height',str(plot.dimensions[1]))
	svg.set('width',str(plot.getSize()[0]+plot.startPosition[0]+plot.finishPosition[0]))
	svg.set('version','1.1')
	"""
	bg = inkex.etree.Element(inkex.addNS('rect','svg'))
	style = {'fill' : 'none','stroke-opacity': '.8','stroke':'#212425','stroke-width':'10'}
	bg.set('style', simplestyle.formatStyle(style))
	bg.set('x','0')
	bg.set('y','0')
	bg.set('width',str(plot.dimensions[0]))
	bg.set('height',svg.get('height'))
	svg.append(bg)
	"""
	spPU = [['M',[0,0]]]
	spPD = []
	for c in plot.toHPGL().split(';'):
		if c[:2] == "PU":
			p = map(int,c[2:].split(','))
			spPD.append(['M',p])
			spPU.append(['L',p])
		elif c[:2] == "PD":
			p = map(int,c[2:].split(','))
			spPU.append(['M',p])
			spPD.append(['L',p])		
	
	pu = inkex.etree.Element(inkex.addNS('path','svg'))
	
	simplepath.scalePath(spPU,0.088582677,-0.088582677)
	simplepath.translatePath(spPU,0,float(svg.get('height')))
	
	style = {'fill' : 'none','stroke-opacity': '.8','stroke':'#116AAB'}
	pu.set('style', simplestyle.formatStyle(style))
	pu.set('d',simplepath.formatPath(spPU))
	
	
	pd = inkex.etree.Element(inkex.addNS('path','svg'))
	
	style = {'fill' : 'none','stroke-opacity': '.8','stroke':'#AB3011'}
	pd.set('style', simplestyle.formatStyle(style))
	pd.set('d',simplepath.formatPath(spPD))
	
	# Connect elements together.
	svg.append(pu)
	svg.append(pd)
	return svg
开发者ID:shackspace,项目名称:inkcut_dmpl,代码行数:48,代码来源:preview.py

示例5: effect

    def effect(self):
        for id, node in self.selected.iteritems():
            if node.tag == inkex.addNS('path','svg'):
                p = simplepath.parsePath(node.get('d'))
                a =[]
                pen = None
                subPathStart = None
                for cmd,params in p:
                    if cmd == 'C':
                        a.extend([['M', params[:2]], ['L', pen],
                            ['M', params[2:4]], ['L', params[-2:]]])
                    if cmd == 'Q':
                        a.extend([['M', params[:2]], ['L', pen],
                            ['M', params[:2]], ['L', params[-2:]]])
                    
                    if cmd == 'M':
                        subPathStart = params

                    if cmd == 'Z':
                        pen = subPathStart
                    else:
                        pen = params[-2:]
                    
                if len(a) > 0:
                    s = {'stroke-linejoin': 'miter', 'stroke-width': '1.0px', 
                        'stroke-opacity': '1.0', 'fill-opacity': '1.0', 
                        'stroke': '#000000', 'stroke-linecap': 'butt', 
                        'fill': 'none'}
                    attribs = {'style':simplestyle.formatStyle(s),'d':simplepath.formatPath(a)}
                    inkex.etree.SubElement(node.getparent(), inkex.addNS('path','svg'), attribs)
开发者ID:AakashDabas,项目名称:inkscape,代码行数:30,代码来源:handles.py

示例6: effect

    def effect(self):
        for id, node in self.selected.iteritems():
            if node.tagName == 'path':
                self.group = self.document.createElement('svg:g')
                node.parentNode.appendChild(self.group)
                new = self.document.createElement('svg:path')
                
                try:
                    t = node.attributes.getNamedItem('transform').value
                    self.group.setAttribute('transform', t)
                except AttributeError:
                    pass

                s = simplestyle.parseStyle(node.attributes.getNamedItem('style').value)
                s['stroke-linecap']='round'
                s['stroke-width']=self.options.dotsize
                new.setAttribute('style', simplestyle.formatStyle(s))

                a =[]
                p = simplepath.parsePath(node.attributes.getNamedItem('d').value)
                num = 1
                for cmd,params in p:
                    if cmd != 'Z':
                        a.append(['M',params[-2:]])
                        a.append(['L',params[-2:]])
                        self.addText(self.group,params[-2],params[-1],num)
                        num += 1
                new.setAttribute('d', simplepath.formatPath(a))
                self.group.appendChild(new)
                node.parentNode.removeChild(node)
开发者ID:NirBenTalLab,项目名称:find_motif,代码行数:30,代码来源:dots.py

示例7: effect

    def effect(self):
        for id, node in self.selected.iteritems():
            if node.tagName == 'path':
                p = simplepath.parsePath(node.attributes.getNamedItem('d').value)
                a =[]
                pen = None
                subPathStart = None
                for cmd,params in p:
                    if cmd == 'C':
                        a.extend([['M', params[:2]], ['L', pen],
                            ['M', params[2:4]], ['L', params[-2:]]])
                    if cmd == 'Q':
                        a.extend([['M', params[:2]], ['L', pen],
                            ['M', params[:2]], ['L', params[-2:]]])
                    
                    if cmd == 'M':
                        subPathStart = params

                    if cmd == 'Z':
                        pen = subPathStart
                    else:
                        pen = params[-2:]
                    
                if len(a) > 0:
                    new = self.document.createElement('svg:path')
                    s = {'stroke-linejoin': 'miter', 'stroke-width': '1.0px', 
                        'stroke-opacity': '1.0', 'fill-opacity': '1.0', 
                        'stroke': '#000000', 'stroke-linecap': 'butt', 
                        'fill': 'none'}
                    new.setAttribute('style', simplestyle.formatStyle(s))
                    new.setAttribute('d', simplepath.formatPath(a))
                    node.parentNode.appendChild(new)
开发者ID:NirBenTalLab,项目名称:find_motif,代码行数:32,代码来源:handles.py

示例8: effect

    def effect(self):
        for id, node in self.selected.iteritems():
            if node.tag == inkex.addNS('path','svg'):
                self.group = inkex.etree.SubElement(node.getparent(),inkex.addNS('g','svg'))
                new = inkex.etree.SubElement(self.group,inkex.addNS('path','svg'))
                
                try:
                    t = node.get('transform')
                    self.group.set('transform', t)
                except:
                    pass

                s = simplestyle.parseStyle(node.get('style'))
                s['stroke-linecap']='round'
                s['stroke-width']=self.options.dotsize
                new.set('style', simplestyle.formatStyle(s))

                a =[]
                p = simplepath.parsePath(node.get('d'))
                num = 1
                for cmd,params in p:
                    if cmd != 'Z':
                        a.append(['M',params[-2:]])
                        a.append(['L',params[-2:]])
                        self.addText(self.group,params[-2],params[-1],num)
                        num += 1
                new.set('d', simplepath.formatPath(a))
                node.clear()
开发者ID:step21,项目名称:inkscape-osx-packaging-native,代码行数:28,代码来源:dots.py

示例9: snap_path_scale

    def snap_path_scale(self, elem, parent_transform=None):
        # If we have a Live Path Effect, modify original-d. If anyone clamours
        # for it, we could make an option to ignore paths with Live Path Effects
        original_d = '{%s}original-d' % inkex.NSS['inkscape']
        path = simplepath.parsePath(elem.attrib.get(original_d, elem.attrib['d']))
        transform = self.transform(elem, parent_transform=parent_transform)
        min_xy, max_xy = self.path_bounding_box(elem, parent_transform)
        
        width = max_xy[0] - min_xy[0]
        height = max_xy[1] - min_xy[1]
        rescale = round(width)/width, round(height)/height

        min_xy = transform_point(transform, min_xy, inverse=True)
        max_xy = transform_point(transform, max_xy, inverse=True)

        for i in range(len(path)):
            self.transform_path_node([[1, 0, -min_xy[0]], [0, 1, -min_xy[1]]], path, i)     # center transform
            self.transform_path_node([[rescale[0], 0, 0],
                                       [0, rescale[1], 0]],
                                       path, i)
            self.transform_path_node([[1, 0, +min_xy[0]], [0, 1, +min_xy[1]]], path, i)     # uncenter transform
        
        path = simplepath.formatPath(path)
        if original_d in elem.attrib: elem.attrib[original_d] = path
        else: elem.attrib['d'] = path
开发者ID:gaffel85,项目名称:notification-agenda,代码行数:25,代码来源:pixelsnap.py

示例10: movePath

    def movePath(self, node, x, y, origin):
        tagName = self.getTagName(node)

        if tagName != "path":
            inkex.debug('movePath only works on SVG Path elements. Argument was of type "' + tagName + '"')
            return False

        path = simplepath.parsePath(node.get("d"))
        id = node.get("id")

        box = list(simpletransform.computeBBox([node]))

        offset_x = box[0] - x
        offset_y = box[2] - (y)

        for cmd in path:
            params = cmd[1]
            i = 0

            while i < len(params):
                if i % 2 == 0:
                    # inkex.debug('x point at ' + str( round( params[i] )))
                    params[i] = params[i] - offset_x
                    # inkex.debug('moved to ' + str( round( params[i] )))
                else:
                    # inkex.debug('y point at ' + str( round( params[i]) ))
                    params[i] = params[i] - offset_y
                    # inkex.debug('moved to ' + str( round( params[i] )))
                i = i + 1

        return simplepath.formatPath(path)
开发者ID:brentini,项目名称:ExtractElements,代码行数:31,代码来源:larscwallin.inx.extractelements.py

示例11: effect

 def effect(self):
     for id, node in self.selected.iteritems():
         if node.tag == inkex.addNS('path', 'svg'):
             d = node.get('d')
             p = simplepath.parsePath(d)
             last = []
             subPathStart = []
             for cmd,params in p:
                 if cmd == 'C':
                     if self.options.behave <= 1:
                         #shorten handles towards end points
                         params[:2] = pointAtPercent(params[:2],last[:],self.options.percent)    
                         params[2:4] = pointAtPercent(params[2:4],params[-2:],self.options.percent)
                     else:
                         #shorten handles towards thirds of the segment                            
                         dest1 = pointAtPercent(last[:],params[-2:],33.3)
                         dest2 = pointAtPercent(params[-2:],last[:],33.3)
                         params[:2] = pointAtPercent(params[:2],dest1[:],self.options.percent)    
                         params[2:4] = pointAtPercent(params[2:4],dest2[:],self.options.percent)
                 elif cmd == 'Q':
                     dest = pointAtPercent(last[:],params[-2:],50)
                     params[:2] = pointAtPercent(params[:2],dest,self.options.percent)
                 if cmd == 'M':
                     subPathStart = params[-2:]
                 if cmd == 'Z':
                     last = subPathStart[:]
                 else:
                     last = params[-2:]
             node.set('d',simplepath.formatPath(p))
开发者ID:AakashDabas,项目名称:inkscape,代码行数:29,代码来源:straightseg.py

示例12: effect

  def effect(self):
    clippingLineSegments = None
    pathTag = inkex.addNS('path','svg')
    groupTag = inkex.addNS('g','svg')
    error_messages = []
    for id in self.options.ids:  # the selection, top-down
      node = self.selected[id]
      if node.tag == pathTag:
        if clippingLineSegments is None: # first path is the clipper
          (clippingLineSegments, errors) = self.simplepathToLineSegments(simplepath.parsePath(node.get('d')))
          error_messages.extend(['{}: {}'.format(id, err) for err in errors])
        else:
          # do all the work!
          segmentsToClip, errors = self.simplepathToLineSegments(simplepath.parsePath(node.get('d')))
          error_messages.extend(['{}: {}'.format(id, err) for err in errors])
          clippedSegments = self.clipLineSegments(segmentsToClip, clippingLineSegments)
          if len(clippedSegments) != 0:
            # replace the path
            node.set('d', simplepath.formatPath(self.linesgmentsToSimplePath(clippedSegments)))
          else:
            # don't put back an empty path(?)  could perhaps put move, move?
            inkex.debug('Object {} clipped to nothing, will not be updated.'.format(node.get('id')))
      elif node.tag == groupTag:  # we don't look inside groups for paths
        inkex.debug('Group object {} will be ignored. Please ungroup before running the script.'.format(id))
      else: # something else
        inkex.debug('Object {} is not of type path ({}), and will be ignored. Current type "{}".'.format(id, pathTag, node.tag))

    for error in error_messages:
        inkex.debug(error)
开发者ID:funnypolynomial,项目名称:DestructiveClip,代码行数:29,代码来源:destructiveclip.py

示例13: snap_path_scale

    def snap_path_scale(self, elem, parent_transform=None):
        # If we have a Live Path Effect, modify original-d. If anyone clamours
        # for it, we could make an option to ignore paths with Live Path Effects
        original_d = "{%s}original-d" % inkex.NSS["inkscape"]
        path = simplepath.parsePath(elem.attrib.get(original_d, elem.attrib["d"]))
        transform = self.transform(elem, parent_transform=parent_transform)
        min_xy, max_xy = self.path_bounding_box(elem, parent_transform)

        width = max_xy[0] - min_xy[0]
        height = max_xy[1] - min_xy[1]

        # In case somebody tries to snap a 0-high element,
        # or a curve/arc with all nodes in a line, and of course
        # because we should always check for divide-by-zero!
        if width == 0 or height == 0:
            return

        rescale = round(width) / width, round(height) / height

        min_xy = transform_point(transform, min_xy, inverse=True)
        max_xy = transform_point(transform, max_xy, inverse=True)

        for i in range(len(path)):
            self.transform_path_node([[1, 0, -min_xy[0]], [0, 1, -min_xy[1]]], path, i)  # center transform
            self.transform_path_node([[rescale[0], 0, 0], [0, rescale[1], 0]], path, i)
            self.transform_path_node([[1, 0, +min_xy[0]], [0, 1, +min_xy[1]]], path, i)  # uncenter transform

        path = simplepath.formatPath(path)
        if original_d in elem.attrib:
            elem.attrib[original_d] = path
        else:
            elem.attrib["d"] = path
开发者ID:Grandrogue,项目名称:inkscape_metal,代码行数:32,代码来源:pixelsnap.py

示例14: movePath

    def movePath(self,node,x,y,origin):
        path = node.get('path')
        box = node.get('box')

        #inkex.debug(box)

        offset_x = (box[0] - x)
        offset_y = (box[2] - (y))

        #inkex.debug('Will move path "'+id+'" from x, y ' + str(box[0]) + ', ' + str(box[2]))
        #inkex.debug('to x, y ' + str(x) + ', ' + str(y))

        #inkex.debug('The x offset is ' + str(offset_x))
        #inkex.debug('The y offset is = ' + str(offset_y))


        for cmd in path:
            params = cmd[1]
            i = 0

            while(i < len(params)):
                if(i % 2 == 0):
                    #inkex.debug('x point at ' + str( round( params[i] )))
                    params[i] = (params[i] - offset_x)
                    #inkex.debug('moved to ' + str( round( params[i] )))
                else:
                    #inkex.debug('y point at ' + str( round( params[i]) ))
                    params[i] = (params[i] - offset_y)
                    #inkex.debug('moved to ' + str( round( params[i] )))
                i = i + 1


        #inkex.debug(simplepath.formatPath(path))
        return simplepath.formatPath(path)
开发者ID:larscwallin,项目名称:bansai,代码行数:34,代码来源:larscwallin.inx.bansai.py

示例15: d_path

 def d_path(self):
     a = list()
     a.append( ['M ', [self.x, self.y]] )
     a.append( [' l ', [self.width, 0]] )
     a.append( [' l ', [0, self.height]] )
     a.append( [' l ', [-self.width, 0]] )
     a.append( [' Z', []] )
     return simplepath.formatPath(a)     
开发者ID:vishpat,项目名称:Practice,代码行数:8,代码来源:shapes.py


注:本文中的simplepath.formatPath函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。