Exemplo n.º 1
0
    def effect(self):
        id = self.options.ids[0]
        
        #query inkscape about the bounding box of obj
        bb = {'x':0,'y':0,'width':0,'height':0}
        file = self.args[-1]
        for query in bb.keys():
            _,f,err = os.popen3("inkscape --query-%s --query-id=%s %s" % (query,id,file))
            bb[query] = float(f.read())
            f.close()
            err.close()
           
        
       
        grid = None
        envCord = None
        rangeEnd = None
        numGridLayers = None
        
   

        obj = self.selected[self.options.ids[0]]
        box = self.selected[self.options.ids[1]]
        objCopy = deepcopy(obj)
        new = inkex.etree.Element('g')
        new.append(objCopy)
        objCopy.set('id' , objCopy.get('id')+'copy')
        new.append(objCopy)
        
        
        selectedObjectPaths = objCopy.iter()
        selectedObjectPaths = [i for i in selectedObjectPaths if (inkex.etree.QName(i).localname   == 'path')]
        envPts = playsvg.path.PathData(text = box.get('d')).getNodes()
        
        for path in selectedObjectPaths:
            
            pathData = playsvg.path.PathData(text=path.get('d'))
            pathData.transformPoints(getTransformLambda(bb, envPts))
            path.set('d', str(pathData))
Exemplo n.º 2
0
    def effect(self):
        id = self.options.ids[0]
        
        #query inkscape about the bounding box of obj
        bb = {'x':0,'y':0,'width':0,'height':0}
        file = self.args[-1]
        for query in bb.keys():
            _,f,err = os.popen3("inkscape --query-%s --query-id=%s %s" % (query,id,file))
            bb[query] = float(f.read())
            f.close()
            err.close()
           
        
       
        grid = None
        envCord = None
        rangeEnd = None
        numGridLayers = None
        idCounter = 1
        
        #initialized values based on offset option
        if self.options.offset:
            numGridLayers =  self.options.layers +3
            grid = playsvg.geom.createOffsetRadialGrid(numGridLayers, self.options.spokes,  self.options.layerradius, self.options.beginradius)
            envCord = [(0,0), (-1, 1), (-2, 1), (-1, 0)]
            rangeEnd =  1 
            
        else:
            numGridLayers =  self.options.layers +1
            grid = playsvg.geom.createRadialGrid(numGridLayers, self.options.spokes,  self.options.layerradius, self.options.beginradius)
            envCord = [(0,0), (-1, 0), (-1, 1), (0, 1)]
            rangeEnd = 0 
                         


        obj = self.selected[self.options.ids[0]]
        
        tileGroup = inkex.etree.SubElement(self.current_layer, 'g')
        
        envPts = None
        
        #create copies of the tile enveloped to the grid
        for layer in range(numGridLayers-1,rangeEnd,-1):
            for spoke in range(self.options.spokes):
                
                #inkex.debug("Length of duplicate list:" + len(self.duplicateNodes({obj.attributes.getNamedItem('id').value:obj})))
                #pathmodifier.fuseTransform(obj)
                
                objCopy = deepcopy(obj)
                tileGroup.append(objCopy)
                
                #FIXME: add support for gradients
                
##                #check if fill is gradient
##                styleDict = simplestyle.parseStyle(objCopy.attributes.getNamedItem('style').value)
##                gradre= re.compile('url\(*\)')
##                if gradre.match(styleDict['fill']) != None:
##                    
##                    #get url of gradient
##                    #duplicate gradient in defs
##                    #transform control points in new gradient (control points likely outside of bounding box ????)
##                    #set color to new gradient
                #FIXME: only paths and not convertible objects get selected and properly tiled
                selectedObjectPaths = objCopy.iter()
                
                selectedObjectPaths = [i for i in selectedObjectPaths if (inkex.etree.QName(i).localname   == 'path')]
                
                #inkex.debug("objectPathsLen"+str(len(selectedObjectPaths)))
                
                
                envPts = []
                for i in range(4):
                    envPts.append(grid[(layer+envCord[i][0])][(spoke+envCord[i][1])%self.options.spokes ] )
                    
                for path in selectedObjectPaths:
                    
                    pathData = playsvg.path.PathData(text=path.get('d'))
                    pathData.transformPoints(getTransformLambda(bb, envPts))
                    inkex.debug("this"+str(pathData))
                    path.set('d',str(pathData))