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


Python simplestyle.parseStyle函数代码示例

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


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

示例1: expandGroupsUnlinkClones

    def expandGroupsUnlinkClones(self,aList,transferTransform=True,doReplace=True):
        for id in aList.keys()[:]:     
            node=aList[id]
            if node.tagName == 'g':
                self.expandGroups(aList,transferTransform)
                self.expandGroupsUnlinkClones(aList,transferTransform,doReplace)
		#Hum... not very efficient if there are many clones of groups...
            elif node.tagName == 'use':
                refid=node.getAttributeNS(inkex.NSS[u'xlink'],'href')
                path = '//*[@id="%s"]' % refid[1:]
                refnode = xml.xpath.Evaluate(path,self.document)[0]
                newnode=refnode.cloneNode(True)
		self.recursNewIds(newnode)

		if node.hasAttributeNS(None,u'style'):
		    style=simplestyle.parseStyle(node.getAttributeNS(None,u'style'))
		    refstyle=simplestyle.parseStyle(refnode.getAttributeNS(None,u'style'))
		    style.update(refstyle)
		    newnode.setAttributeNS(None,'style',simplestyle.formatStyle(style))
                applyTransformToNode(parseTransform(node.getAttributeNS(None,'transform')),newnode)
                if doReplace:
                    parent=node.parentNode
                    parent.insertBefore(newnode,node)
                    parent.removeChild(node)
                del aList[id]
		newid=newnode.getAttributeNS(None,'id')
                aList.update(self.expandGroupsUnlinkClones({newid:newnode},transferTransform,doReplace))
        return aList
开发者ID:NirBenTalLab,项目名称:find_motif,代码行数:28,代码来源:pathmodifier.py

示例2: decode_vector

	def decode_vector(self, img):
		self.data = [None] * (self.size ** 2)
		self.transform = img.attrib['transform']
		self.pos = (float('inf'), float('inf'))

		pixels = img.xpath('//svg:rect', namespaces=inkex.NSS)
		paths = img.xpath('//svg:path', namespaces=inkex.NSS)

		# Because svg groups have no set x,y coords we have to decern the
		# position from the contents which we can then use as an offset when
		# reconstructing the image.
		for pixel in pixels + paths:
			pos = (inkex.unittouu(pixel.attrib['x']),
				   inkex.unittouu(pixel.attrib['y']))
			self.pos[0] = self.pos[0] if self.pos[0] < pos[0] else pos[0]
			self.pos[1] = self.pos[1] if self.pos[1] < pos[1] else pos[1]

		for pixel in pixels:
			style = simplestyle.parseStyle(pixel.attrib['style'])
			pos = (inkex.unittouu(pixel.attrib['x']) - self.pos[0],
				   inkex.unittouu(pixel.attrib['y']) - self.pos[1])
			index = pos2index(self.size, *pos)
			self.data[index] = simplestyle.parseColor(style['fill'])

		last_point = (0, 0)
		for path in paths:
			for offset in re.findall('m\s(?P<x>-?\d+),(?P<y>-?\d+).*?z'):
				style = simplestyle.parseStyle(pixel.attrib['style'])
				pos = (inkex.unittouu(path.attrib['x']) - self.pos[0] + last_point[0],
					   inkex.unittouu(path.attrib['y']) - self.pos[1] + last_point[1])
				index = pos2index(self.size, *pos)
				self.data[index] = simplestyle.parseColor(style['fill'])

				last_point[0] += offset[0]
				last_point[1] += offset[1]
开发者ID:PatrickKennedy,项目名称:tileset-tools,代码行数:35,代码来源:tti_tools.py

示例3: effect

    def effect(self):
        defs = self.xpathSingle('/svg//defs')
        if not defs:
            defs = self.document.createElement('svg:defs')
            self.document.documentElement.appendChile(defs)

        for id, node in self.selected.iteritems():
            mprops = ['marker', 'marker-start', 'marker-mid', 'marker-end']
            try:
                style = simplestyle.parseStyle(
                    node.attributes.getNamedItem('style').value)
            except:
                inkex.debug("No style attribute found for id: %s" % id)
                continue

            stroke = style.get('stroke', '#000000')

            for mprop in mprops:
                if style.has_key(mprop) and style[mprop] != 'none' and style[
                        mprop][:5] == 'url(#':
                    marker_id = style[mprop][5:-1]
                    try:
                        old_mnode = self.xpathSingle(
                            '/svg//marker[@id="%s"]' % marker_id)
                        if not self.options.modify:
                            mnode = old_mnode.cloneNode(True)
                        else:
                            mnode = old_mnode
                    except:
                        inkex.debug("unable to locate marker: %s" % marker_id)
                        continue

                    new_id = self.uniqueId(marker_id, not self.options.modify)

                    style[mprop] = "url(#%s)" % new_id
                    mnode.attributes.getNamedItem('id').value = new_id
                    mnode.attributes.getNamedItemNS(inkex.NSS['inkscape'],
                                                    'stockid').value = new_id
                    defs.appendChild(mnode)

                    children = inkex.xml.xpath.Evaluate(
                        '/svg//marker[@id="%s"]//*[@style]' % new_id,
                        self.document,
                        context=self.ctx)
                    for child in children:
                        cstyle = simplestyle.parseStyle(
                            child.attributes.getNamedItem('style').value)
                        if ('stroke' in cstyle and cstyle['stroke'] != 'none'
                            ) or 'stroke' not in cstyle:
                            cstyle['stroke'] = stroke
                        if ('fill' in cstyle and cstyle['fill'] != 'none'
                            ) or 'fill' not in cstyle:
                            cstyle['fill'] = stroke
                        child.attributes.getNamedItem(
                            'style').value = simplestyle.formatStyle(cstyle)
            node.attributes.getNamedItem(
                'style').value = simplestyle.formatStyle(style)
开发者ID:NirBenTalLab,项目名称:proorigami-cde-package,代码行数:57,代码来源:markers_strokepaint.py

示例4: __call__

 def __call__(self, elem):
     style = elem.get("style")
     if style is None:
         return
     parsed = simplestyle.parseStyle(style)
     if "stroke" in parsed and parsed["stroke"] != "none":
         yield CheckerResult("element with stroke found", elem)
开发者ID:starshipfactory,项目名称:precut,代码行数:7,代码来源:precut.py

示例5: 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

示例6: change_attribute

 def change_attribute(self, node, attribute):
     for key, value in attribute.items():
         if key == 'preserveAspectRatio':
             # set presentation attribute
             if value != "unset":
                 node.set(key, str(value))
             else:
                 if node.get(key):
                     del node.attrib[key]
         elif key == 'image-rendering':
             node_style = simplestyle.parseStyle(node.get('style'))
             if key not in node_style:
                 # set presentation attribute
                 if value != "unset":
                     node.set(key, str(value))
                 else:
                     if node.get(key):
                         del node.attrib[key]
             else:
                 # set style property
                 if value != "unset":
                     node_style[key] = str(value)
                 else:
                     del node_style[key]
                 node.set('style', simplestyle.formatStyle(node_style))
         else:
             pass
开发者ID:Drooids,项目名称:inkscape,代码行数:27,代码来源:image_attributes.py

示例7: 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

示例8: setGradient

    def setGradient(self, href):
        try:
            g = self.svg.xpath("//*[@id='%s']" % href, namespaces=inkex.NSS)[0]
        except:
            return

        if g.get("r"):
            cx = float(g.get("cx"))
            cy = float(g.get("cy"))
            r = float(g.get("r"))
            self.createRadialGradient(href, cx, cy, r, cx, cy, r)
        else:
            x1 = float(g.get("x1"))
            y1 = float(g.get("y1"))
            x2 = float(g.get("x2"))
            y2 = float(g.get("y2"))
            self.createLinearGradient(href, x1, y1, x2, y2)

        #get gradient color stops
        gstops = g.get(inkex.addNS("href", "xlink"))
        gstops = self.svg.xpath("//svg:linearGradient[@id='%s']" % gstops[1:], namespaces=inkex.NSS)[0]
        for stop in gstops:
            style = simplestyle.parseStyle(stop.get("style"))
            stop_color = style["stop-color"]
            opacity = style["stop-opacity"]
            color = self.getColor(stop_color, opacity)
            pos = float(stop.get("offset"))
            self.addColorStop(href, pos, color)
        return href
开发者ID:wickedtribe,项目名称:Ink2canvas,代码行数:29,代码来源:canvas.py

示例9: isGroupVisible

 def isGroupVisible(self, group):
     style = group.get('style')
     if style:
         style = simplestyle.parseStyle(style)
         if 'display' in style and style['display'] == 'none':
             return False
     return True
开发者ID:AakashDabas,项目名称:inkscape,代码行数:7,代码来源:hpgl_encoder.py

示例10: process_group

 def process_group(self, group):
     if group.get(inkex.addNS('groupmode', 'inkscape')) == 'layer':
         style = group.get('style')
         if style:
             style = simplestyle.parseStyle(style)
             if style.has_key('display'):
                 if style['display'] == 'none' and self.options.layer_option and self.options.layer_option=='visible':
                     return
         layer = group.get(inkex.addNS('label', 'inkscape'))
         if self.options.layer_name and self.options.layer_option and self.options.layer_option=='name' and not layer.lower() in self.options.layer_name:
             return
           
         layer = layer.replace(' ', '_')
         if layer in self.layers:
             self.layer = layer
     trans = group.get('transform')
     if trans:
         self.groupmat.append(simpletransform.composeTransform(self.groupmat[-1], simpletransform.parseTransform(trans)))
     for node in group:
         if node.tag == inkex.addNS('g','svg'):
             self.process_group(node)
         elif node.tag == inkex.addNS('use', 'svg'):
             self.process_clone(node)
         else:
             self.process_shape(node, self.groupmat[-1])
     if trans:
         self.groupmat.pop()
开发者ID:AakashDabas,项目名称:inkscape,代码行数:27,代码来源:dxf_outlines.py

示例11: plotPath

   def plotPath(self, node, matTransform):
      """ Plot the path while applying the transformation defined by the matrix matTransform. """

      filledPath = (simplestyle.parseStyle(node.get("style")).get("fill", "none") != "none")

      # Plan: Turn this path into a cubicsuperpath (list of beziers)...
      d = node.get("d")
      if len(simplepath.parsePath(d)) == 0:
         return
      p = cubicsuperpath.parsePath(d)

      # ... and apply the transformation to each point.
      simpletransform.applyTransformToPath(matTransform, p)

      # p is now a list of lists of cubic beziers [cp1, cp2, endp]
      # where the start-point is the last point of the previous segment.
      # For some reason the inkscape extensions uses csp[1] as the coordinates of each point,
      # but that makes it seem like they are using control point 2 as line points.
      # Maybe that is a side-effect of the CSP subdivion process? TODO
      realPoints = []
      for sp in p:
         cspsubdiv.subdiv(sp, self.smoothness)
         for csp in sp:
            realPoints.append( (csp[1][0], csp[1][1]) )

      self.rawObjects.append( (filledPath, realPoints) )
开发者ID:wayneandlayne,项目名称:svg2kicadmod,代码行数:26,代码来源:SvgParser.py

示例12: split_letters

    def split_letters(self, node):
        """Returns a list of letters"""

        letters = []
        
        words = self.split_words(node)
        if not words:
            return letters

        for word in words:
            
            x = float(word.get("x"))
            y = word.get("y")
           
            #gets the font size. If element doesn't have a style attribute, it assumes font-size = 12px
            try:
                import simplestyle
                fontsize = simplestyle.parseStyle(word.get("style"))["font-size"]
            except:
                fontsize = "12px"
            fs = self.unittouu(fontsize)

            #for each letter in element string
            for letter in word[0].text:
                tspan = inkex.etree.Element(inkex.addNS("tspan", "svg"))
                tspan.text = letter

                text = inkex.etree.Element(inkex.addNS("text", "svg"), node.attrib)
                text.set("x", str(x))
                text.set("y", str(y))
                x += fs
                
                text.append(tspan)
                letters.append(text)
        return letters
开发者ID:Drooids,项目名称:inkscape,代码行数:35,代码来源:split.py

示例13: effect

    def effect(self):
        object2path.ObjectToPath.effect(self)

        transformMatrix = [[1,0,0],[0,1,0]]
        dims = self.determine_dims(transformMatrix)

        [x,y,X,Y] = dims
        width = X - x
        height = Y - y

        # Longest side is vertical
        if width > height:
            scale = 480.0 / height
            if scale * width > 999.0:
                inkex.errormsg("Plot area is to large (%f > 999)." % scale*height)
                exit()
            transformMatrix = parseTransform('translate(%f,%f)' % (-x,-y))
            transformMatrix = composeTransform(parseTransform('rotate(-90)'), transformMatrix)
            transformMatrix = composeTransform(parseTransform('scale(%f,%f)' % (scale,scale)), transformMatrix)
        else:
            scale = 480.0 / width
            if scale * height > 999.0:
                inkex.errormsg("Plot area is to large (%f > 999)." % scale*height)
                exit()
            transformMatrix = parseTransform('translate(%f,%f)' % (-x,-y))
            transformMatrix = composeTransform(parseTransform('rotate(180)'), transformMatrix)
            transformMatrix = composeTransform(parseTransform('translate(%f,0)' % width), transformMatrix)
            transformMatrix = composeTransform(parseTransform('scale(%f,%f)' % (-scale,scale)), transformMatrix)
            transformMatrix = composeTransform(parseTransform('translate(480,0)'), transformMatrix)

        paths = []
        for [path, node] in self.processPaths(transformMatrix):
            color = (0, 0, 0)
            style = node.get('style')
            if style:
                style = simplestyle.parseStyle(style)
                if 'stroke' in style:
                    if style['stroke'] and style['stroke'] != 'none':
                        color = simplestyle.parseColor(style['stroke'])
            points = []
            for point in self.processPath(path):
                points.append(point)
            paths.append({'color':color, 'points':points})

        dims = self.determine_dims(transformMatrix)
        if self.options.debug:
            print >>sys.stderr, "VC1520 debug info"
            print >>sys.stderr, "-----------------"
            print >>sys.stderr, "plot area: minX:%d, minY:%d, maxX:%d, maxY:%d" % tuple(dims)
            print >>sys.stderr, "nr paths: %d" % len(paths)
            i = 0
            print >>sys.stderr, "path;color;points"
            for path in paths:
                print >>sys.stderr, "%d;%s;%d" % (i,self.find_color(path['color']),len(path['points']))
                i += 1
            for path in paths:
                print >>sys.stderr, path
        else:
            self.plot(paths, dims[1])
开发者ID:nanoflite,项目名称:inkscape-VC1520,代码行数:59,代码来源:sendto_vc1520.py

示例14: checkStyle

def checkStyle(node):
    if node.hasAttributes():
        sa=node.getAttribute('style')
        if sa!='':
            styles=simplestyle.parseStyle(sa)
            for c in range(len(colortags)):
                if colortags[c] in styles.keys():
                    addColor(styles[colortags[c]])
开发者ID:NirBenTalLab,项目名称:find_motif,代码行数:8,代码来源:export_gimp_palette.py

示例15: checkStyle

def checkStyle(node):
    if hasattr(node, "hasAttributes") and node.hasAttributes():
        sa = node.getAttribute("style")
        if sa != "":
            styles = simplestyle.parseStyle(sa)
            for c in range(len(colortags)):
                if colortags[c] in styles.keys():
                    addColor(styles[colortags[c]])
开发者ID:step21,项目名称:inkscape-osx-packaging-native,代码行数:8,代码来源:export_gimp_palette.py


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