def writeToFile(self, outfile):
        """write svg image to file.
        """
        self.finalizePlot()

        self.mRoot = SVGdraw.drawing()
        self.mDraw = SVGdraw.svg( (0, 0, self.mPageWidth, self.mPageHeight ) , "100%", "100%" )

        kk = self.mElements.keys()
        kk.sort()
        kk.reverse()
        for k in kk:
            for e in self.mElements[k]:
                self.mDraw.addElement( e )
            
        self.mRoot.setSVG(self.mDraw)

        tfile = tempfile.mktemp()
        
        self.mRoot.toXml( tfile )

        lines = open(tfile,"r").readlines()
        
        outfile.write(string.join(lines,""))
        outfile.write("\n")
        
        os.remove(tfile)
示例#2
0
文件: knots.py 项目: clsn/THexplorer
def errorsvg(msg):
    s = SVGdraw.svg(width='5cm', height='1cm')
    s.addElement(SVGdraw.text(0, 0, msg))
    d = SVGdraw.drawing()
    d.svg = s
    print d.toXml()
    return s
示例#3
0
文件: knots.py 项目: clsn/THexplorer
def errorsvg(msg):
    s=SVGdraw.svg(width='5cm', height='1cm')
    s.addElement(SVGdraw.text(0,0,msg))
    d=SVGdraw.drawing()
    d.svg=s
    print d.toXml()
    return s
示例#4
0
 def fill(self,elt):
     pattern=SVGdraw.SVGelement('pattern',attributes=
                                {"height":"20", "width":"20",
                                 "patternUnits":"userSpaceOnUse",
                                 "patternContentUnits":"userSpaceOnUse",
                                 "id": "maso%04d"%blazon.Ordinary.id})
     blazon.Ordinary.id+=1
     group=SVGdraw.group()
     group.addElement(self.color2.fill(SVGdraw.rect(x="0",y="9",width="20",height="2")))
     group.addElement(self.color2.fill(SVGdraw.rect(x="0",y="10",width="1",height="10")))
     group.addElement(self.color2.fill(SVGdraw.rect(x="19",y="10",width="1",height="10")))
     group.addElement(self.color2.fill(SVGdraw.rect(x="9",y="0",width="2", height="10")))
     group.addElement(self.color2.fill(SVGdraw.rect(x="0",y="0",width="20",height="1")))
     group.addElement(self.color2.fill(SVGdraw.rect(x="0",y="19",width="20",height="1")))
     pattern.addElement(group)
     blazon.Ordinary.defs.append(pattern)
     elt=self.color1.fill(elt)
     newelt=SVGdraw.group()
     newelt.addElement(elt)
     newbase=SVGdraw.rect(x=-blazon.Ordinary.FESSPTX,
                          y=-blazon.Ordinary.FESSPTY,
                          width=blazon.Ordinary.WIDTH,
                          height=blazon.Ordinary.HEIGHT,
                          fill="url(#%s)"%pattern.attributes["id"])
     newelt.addElement(newbase)
     return newelt                               
示例#5
0
 def fill(self, elt):
     VIPpattern = self.VairPattern()
     blazon.Ordinary.defs.append(VIPpattern)
     pattern = SVGdraw.SVGelement('pattern',
                                  attributes={
                                      "width": "16",
                                      "height": "16",
                                      "patternUnits": "userSpaceOnUse",
                                      "patternContentUnits":
                                      "userSpaceOnUse",
                                      "id": "vair%04d" % blazon.Ordinary.id
                                  })
     self.color = "vair%04d" % blazon.Ordinary.id
     blazon.Ordinary.id += 1
     pattern.addElement(
         SVGdraw.rect(x="0",
                      y="0",
                      width="16",
                      height="8",
                      fill="url(#%s)" % VIPpattern.attributes["id"]))
     pattern.addElement(
         SVGdraw.rect(x="0",
                      y="8",
                      width="20",
                      height="8",
                      fill="url(#%s)" % VIPpattern.attributes["id"],
                      transform="translate(-4,0)"))
     blazon.Ordinary.defs.append(pattern)
     elt.attributes["fill"] = "url(#%s)" % pattern.attributes["id"]
     return elt
示例#6
0
   def fill(self,elt):
      pattern=SVGdraw.SVGelement('pattern',attributes=
                                 {"height":"15","width":"15",
                                  "patternUnits":"userSpaceOnUse",
                                  "patternContentUnits":"userSpaceOnUse",
                                  "id":"ermine%04d"%blazon.Ordinary.id})
      blazon.Ordinary.id+=1
      pattern.addElement(self.color1.fill(SVGdraw.rect(x="0",y="0",width="15",height="15")))
      pattern.addElement(self.color2.fill(SVGdraw.SVGelement('path',
                                                             attributes={"d":
                                                        "M1,5 c1,-1 1.5,-4 1.5,-4 c0,0 .5,3 1.5,4 l-1.5,1.5 z"})))
      pattern.addElement(self.color2.fill(SVGdraw.circle(cx="1.5",cy="2",
                                                         r=".5")))
      pattern.addElement(self.color2.fill(SVGdraw.circle(cx="2.5",cy="1",
                                                         r=".5")))
      pattern.addElement(self.color2.fill(SVGdraw.circle(cx="3.5",cy="2",
                                                         r=".5")))
      pattern.addElement(self.color2.fill(SVGdraw.SVGelement('path',
                                            attributes={"d":
                                                        "M8.5,12.5 c1,-1 1.5,-4 1.5,-4 c0,0 .5,3 1.5,4 l-1.5,1.5 z"})))
      pattern.addElement(self.color2.fill(SVGdraw.circle(cx="9",cy="9.5",
                                                         r=".5")))
      pattern.addElement(self.color2.fill(SVGdraw.circle(cx="10",cy="8.5",
                                                         r=".5")))
      pattern.addElement(self.color2.fill(SVGdraw.circle(cx="11",cy="9.5",
                                                         r=".5")))

      blazon.Ordinary.defs.append(pattern)
      elt.attributes["fill"]="url(#%s)"%pattern.attributes["id"]
      return elt
示例#7
0
 def build(self):
     (sx, sy) = self._srcchgset.position()
     h_offset = self._srcchgset.tag_offset(self._h)
     self._position = (sx + (self._srcchgset.extent()[0])/2,
                       sy - (3*self._h)/2 + h_offset)
     x = self._position[0]+(self._w-self._tw)/2
     y = self._position[1]
     r = UNIT/2
     rect = SVG.rect(x,y,self._tw,self._h,
                     self._srcchgset.strokecolor(),
                     self._srcchgset.fillcolor(), 
                     self._srcchgset.strokewidth())
     rect.attributes['rx'] = r
     rect.attributes['ry'] = r        
     rect.attributes['opacity'] = str(self._opacity/100.0) 
     text = SVG.text(self._position[0]+self._w/2, 
                     self._position[1]+self._h/2+UNIT/4,
                     "%s" % self._title.encode('utf-8'), 
                     self._srcchgset.fontsize(), 
                     self._srcchgset.fontname())
     txc = SvgColor('white')
     text.attributes['style'] = 'fill:%s; text-anchor: middle' % txc.rgb()
     name = self._title.encode('utf-8').replace('/','')
     g = SVG.group('grp%d' % self._revision, elements=[rect, text])
     link = "%s/changeset/%d" % (self._parent.urlbase(), self._revision)
     self._link = SVG.link(link, elements=[g])
     self._link.attributes['id'] = 'rev%d' % self._revision
     self._link.attributes['style'] = \
         'color: %s; background-color: %s' % \
             (self._srcchgset.fillcolor(), self._srcchgset.strokecolor())
示例#8
0
 def fill(self, elt):
     pattern = SVGdraw.SVGelement('pattern',
                                  attributes={
                                      "width":
                                      "8",
                                      "height":
                                      "16",
                                      "patternUnits":
                                      "userSpaceOnUse",
                                      "patternContentUnits":
                                      "userSpaceOnUse",
                                      "id":
                                      "counter-vair%04d" %
                                      blazon.Ordinary.id
                                  })
     blazon.Ordinary.id += 1
     pattern.addElement(
         self.color1.fill(SVGdraw.rect(x="0", y="0", width="8",
                                       height="18")))
     pattern.addElement(
         self.color2.fill(
             SVGdraw.SVGelement(
                 'path',
                 attributes={
                     "d":
                     "M0,8 l2,-2 l0,-4 l2,-2 l2,2 l0,4 l2,2 l-2,2 l0,4 l-2,2 l-2,-2 l0,-4 z"
                 })))
     elt.attributes["fill"] = "url(#%s)" % pattern.attributes["id"]
     blazon.Ordinary.defs.append(pattern)
     return elt
示例#9
0
 def create(self, color, head):
     name = self._get_name(color, head)
     if not self._markers.has_key(name):
         if head:
             marker = SVG.marker(name, (0, 0, 10, 8),
                                 0,
                                 4,
                                 UNIT / 4,
                                 UNIT / 4,
                                 fill=SvgColor(color),
                                 orient='auto')
             marker.addElement(
                 SVG.polyline(((0, 4), (10, 0), (10, 8), (0, 4))))
         else:
             marker = SVG.marker(name, (0, 0, 10, 8),
                                 10,
                                 4,
                                 UNIT / 4,
                                 UNIT / 4,
                                 fill=SvgColor(color),
                                 orient='auto')
             marker.addElement(
                 SVG.polyline(((0, 0), (0, 8), (10, 4), (0, 0))))
         self._markers[name] = marker
     return name
示例#10
0
 def fill(self, elt):
     pattern = SVGdraw.SVGelement('pattern',
                                  attributes={
                                      "height": "20",
                                      "width": "20",
                                      "patternUnits": "userSpaceOnUse",
                                      "patternContentUnits":
                                      "userSpaceOnUse",
                                      "id": "semy%04d" % blazon.Ordinary.id
                                  })
     blazon.Ordinary.id += 1
     # Just in case we try to countercharge it.  It doesn't work anyway.
     self.colors = (self.background, self.charge.tincture)
     charge2 = copy.deepcopy(self.charge)
     self.charge.moveto((5, 15))
     self.charge.scale(.1)
     charge2.moveto((15, 5))
     charge2.scale(.1)
     #pattern.addElement(SVGdraw.rect(0,0,30,30,stroke="black",
     #                                stroke_width=".3",fill="none"))
     pattern.addElement(self.charge.finalizeSVG())
     pattern.addElement(charge2.finalizeSVG())
     blazon.Ordinary.defs.append(pattern)
     newelt = SVGdraw.group()
     elt = self.background.fill(elt)
     newelt.addElement(elt)
     newbase = SVGdraw.rect(x=-blazon.Ordinary.FESSPTX,
                            y=-blazon.Ordinary.FESSPTY,
                            width=blazon.Ordinary.WIDTH,
                            height=blazon.Ordinary.HEIGHT,
                            fill="url(#%s)" % pattern.attributes["id"])
     newelt.addElement(newbase)
     return newelt
示例#11
0
 def VairPattern(self):
     pattern = SVGdraw.SVGelement(type="pattern",
                                  attributes={
                                      "patternContentUnits":
                                      "userSpaceOnUse",
                                      "height":
                                      "8",
                                      "id":
                                      "vair-in-pale%04d" %
                                      blazon.Ordinary.id,
                                      "patternUnits":
                                      "userSpaceOnUse",
                                      "width":
                                      "8"
                                  })
     pattern.addElement(
         self.color1.fill(SVGdraw.rect(x="0", y="0", width="8",
                                       height="8")))
     pattern.addElement(
         self.color2.fill(
             SVGdraw.SVGelement(
                 type='path',
                 attributes={
                     "d": "M0,8 l2,-2 l0,-4 l2,-2 l2,2 l0,4 l2,2 z"
                 })))
     self.color = "vair-in-pale%04d" % blazon.Ordinary.id
     blazon.Ordinary.id += 1
     return pattern
示例#12
0
 def fill(self,elt):
     pattern=SVGdraw.SVGelement('pattern',attributes=
                                {"height":"20", "width":"20",
                                 "patternUnits": "userSpaceOnUse",
                                 "patternContentUnits": "userSpaceOnUse",
                                 "id": "semy%04d"%blazon.Ordinary.id})
     blazon.Ordinary.id+=1
     # Just in case we try to countercharge it.  It doesn't work anyway.
     self.colors=(self.background,self.charge.tincture)
     charge2=copy.deepcopy(self.charge)
     self.charge.moveto((5,15))
     self.charge.scale(.1)
     charge2.moveto((15,5))
     charge2.scale(.1)
     #pattern.addElement(SVGdraw.rect(0,0,30,30,stroke="black",
     #                                stroke_width=".3",fill="none"))
     pattern.addElement(self.charge.finalizeSVG())
     pattern.addElement(charge2.finalizeSVG())
     blazon.Ordinary.defs.append(pattern)
     newelt=SVGdraw.group()
     elt=self.background.fill(elt)
     newelt.addElement(elt)
     newbase=SVGdraw.rect(x=-blazon.Ordinary.FESSPTX,
                          y=-blazon.Ordinary.FESSPTY,
                          width=blazon.Ordinary.WIDTH,
                          height=blazon.Ordinary.HEIGHT,
                          fill="url(#%s)"%pattern.attributes["id"])
     newelt.addElement(newbase)
     return newelt
示例#13
0
    def writeToFile(self, outfile):
        """write svg image to file.
        """
        self.finalizePlot()

        kk = self.mElements.keys()
        kk.sort()
        kk.reverse()

        ## make sure the image size is ok
        min_x, min_y, max_x, max_y = 0, 0, 0, 0
        
        for k in kk:
            for e in self.mElements[k]:
                for x in ('x', 'x2', 'x1'):
                    if x in e.attributes:
                        v = e.attributes[x] 
                        min_x = min(min_x, v )
                        max_x = max(max_x, v )
                for y in ('y', 'y2', 'y1'):
                    if y in e.attributes:
                        v = e.attributes[y]
                        min_y = min(min_y, v )
                        max_y = max(max_y, v )

        min_x, min_y = int(math.floor(min_x)), int(math.floor(min_y))
        max_x, max_y = int(math.floor(max_x)), int(math.floor(max_y))        

        for k in kk:
            for e in self.mElements[k]:
                for x in ('x', 'x2', 'x1'):
                    if x in e.attributes:
                        e.attributes[x] -= min_x
                for x in ('y', 'y2', 'y1'):
                    if y in e.attributes:
                        e.attributes[y] -= min_y

        ## now add all the elements
        self.mRoot = SVGdraw.drawing()
        self.mDraw = SVGdraw.svg( (0, 0, self.mPageWidth - min_x, self.mPageHeight - min_y ) , "100%", "100%" )
                        
        for k in kk:
            for e in self.mElements[k]:
                self.mDraw.addElement( e )
            
        self.mRoot.setSVG(self.mDraw)

        tfile = tempfile.mktemp()
        
        self.mRoot.toXml( tfile )

        lines = open(tfile,"r").readlines()
        
        outfile.write(string.join(lines,""))
        outfile.write("\n")
        
        os.remove(tfile)
示例#14
0
 def fill(self,elt):
     pattern=SVGdraw.SVGelement('pattern',attributes=
                                {"height":"20", "width":"20",
                                 "patternUnits":"userSpaceOnUse",
                                 "patternContentUnits":"userSpaceOnUse",
                                 "id": "maso%04d"%blazon.Ordinary.id})
     blazon.Ordinary.id+=1
     group=SVGdraw.group()
     group.addElement(self.color2.fill(SVGdraw.rect(x="0",y="9",width="20",height="2")))
     group.addElement(self.color2.fill(SVGdraw.rect(x="0",y="10",width="1",height="10")))
     group.addElement(self.color2.fill(SVGdraw.rect(x="19",y="10",width="1",height="10")))
     group.addElement(self.color2.fill(SVGdraw.rect(x="9",y="0",width="2", height="10")))
     group.addElement(self.color2.fill(SVGdraw.rect(x="0",y="0",width="20",height="1")))
     group.addElement(self.color2.fill(SVGdraw.rect(x="0",y="19",width="20",height="1")))
     pattern.addElement(group)
     blazon.Ordinary.defs.append(pattern)
     elt=self.color1.fill(elt)
     newelt=SVGdraw.group()
     newelt.addElement(elt)
     newbase=SVGdraw.rect(x=-blazon.Ordinary.FESSPTX,
                          y=-blazon.Ordinary.FESSPTY,
                          width=blazon.Ordinary.WIDTH,
                          height=blazon.Ordinary.HEIGHT,
                          fill="url(#%s)"%pattern.attributes["id"])
     newelt.addElement(newbase)
     return newelt                               
示例#15
0
 def create(self, color, head):
     name = self._get_name(color, head)
     if not self._markers.has_key(name):
         if head:
             marker = SVG.marker(name, (0,0,10,8), 0, 4, UNIT/4, UNIT/4,
                                 fill=SvgColor(color), orient='auto')
             marker.addElement(SVG.polyline(((0,4),(10,0),(10,8),(0,4))))
         else:
             marker = SVG.marker(name, (0,0,10,8), 10, 4, UNIT/4, UNIT/4,
                                 fill=SvgColor(color), orient='auto')
             marker.addElement(SVG.polyline(((0,0),(0,8),(10,4),(0,0))))
         self._markers[name] = marker
     return name
示例#16
0
文件: gridmaps.py 项目: vincent/irlig
	def save(self, filename=None):
		document = SVGdraw.drawing()
		width = str(self.width) + self.units
		height = str(self.height) + self.units
		canvas = SVGdraw.svg(None, width, height)

		self.makeGrid(canvas)

		document.setSVG(canvas)

		if filename:
			document.toXml(filename)
		else:
			return document.toXml()
    def writeScale( self ):
        """write scales."""

        current_x = self.mScaleX
        current_y = self.mScaleY + self.mScaleHeight

        nboxes = len(self.mColourThresholds)
        # box size for legend in x-direction
        # subtract size of right-most axis label so that it takes the
        # same width as self.mDataWidth.
        box_size_x = math.ceil( (self.mDataWidth -
                                (self.mScaleFontSize * len(self.mFormatNumberLegend % self.mColourThresholds[-1])))
                                / nboxes )

        # change font size such that it labels will fit between tick-marks
        self.mScaleFontSize = min( self.mScaleFontSize,
                                   (box_size_x * self.mScaleNumTicks * 1.5) / len(self.mFormatNumberLegend % self.mColourThresholds[-1]) )
        
        for x in range(nboxes):

            e = SVGdraw.rect( current_x,
                              current_y,
                              box_size_x,
                              self.mScaleBoxSizeY,                                   
                              fill = "rgb(%i,%i,%i)" % self.mColours[x],
                              stroke = "rgb(%i,%i,%i)" % self.mColours[x])                                   
            
            self.addElement(e)
            
            if x % self.mScaleNumTicks == 0:

                e = SVGdraw.line( current_x,
                                  current_y,
                                  current_x,
                                  current_y + self.mScaleBoxSizeY,
                                  stroke = "rgb(%i,%i,%i)" % BLACK,
                                  stroke_width = 5)
                self.addElement(e)
                
                e = SVGdraw.text( current_x,
                                  current_y - self.mScaleBoxSizeY,
                                  self.mFormatNumberLegend % self.mColourThresholds[x],
                                  self.mScaleFontSize,
                                  self.mScaleFont,
                                  stroke = "rgb(%i,%i,%i)" % BLACK,
                                  text_anchor = "start")
                self.addElement(e)
            
            
            current_x += box_size_x
示例#18
0
 def assemble(self):
     # Yes, everything with HEIGHT, so I'm working in a square.
     # May have the colors backwards.
     p=partLine(linetype=self.lineType)
     if self.pieces == 8:
         # No reason to do this as a special case, but it was working
         # first, so why mess with it.
         p.move(0,-blazon.Ordinary.HEIGHT)
         p.makeline(0,blazon.Ordinary.HEIGHT)
         p.hline(-blazon.Ordinary.HEIGHT)
         p.makeline(blazon.Ordinary.HEIGHT,-blazon.Ordinary.HEIGHT)
         p.closepath()
         p.move(-blazon.Ordinary.HEIGHT,0)
         p.makeline(blazon.Ordinary.HEIGHT,0)
         p.vline(blazon.Ordinary.HEIGHT)
         p.makeline(-blazon.Ordinary.HEIGHT,-blazon.Ordinary.HEIGHT)
         p.closepath()
     else:
         angle=2*math.pi/self.pieces
         pi_2=math.pi/2
         for i in range(0,self.pieces,2):
             p.move(blazon.Ordinary.HEIGHT*math.cos(pi_2+i*angle),
                    blazon.Ordinary.HEIGHT*math.sin(pi_2+i*angle))
             p.makeline(0,0)
             p.makeline(blazon.Ordinary.HEIGHT*math.cos(pi_2+(i+1)*angle),
                        blazon.Ordinary.HEIGHT*math.sin(pi_2+(i+1)*angle))
             p.closepath()
     self.path=SVGdraw.path(p)
     self.path.attributes["fill-rule"]="evenodd"
示例#19
0
文件: gridmaps.py 项目: xytis/GURPS
	def doGrid(self, canvas, rows, verticalOffset, partHeight, columns, horizontalOffset, partWidth, gridsize, lineColor, fillColor, penWidth):
		polySize = str(gridsize) + self.units
		for polyRow in range(0, rows):
			polyTop = verticalOffset + polyRow*partHeight
			polyTopStr = str(polyTop) + self.units

			#do stuff for hexagons
			rowcolumns = columns
			rowoffset = 0
			if self.type == 'hex':
				if polyRow % 2 == 0:
					if (self.width-(horizontalOffset+self.rightMargin-.01)) >= (columns*partWidth + gridsize):
						rowcolumns = columns + 1
				else:
					rowoffset = gridsize/2 + gridsize/4

			for polyColumn in range(0, rowcolumns):
				polyLeft = horizontalOffset + polyColumn*partWidth
				polyLeft += rowoffset
				polyLeftStr = str(polyLeft) + self.units
				
				if self.type == 'hex':
					gridshape = hexagon(gridsize, polyLeft, polyTop, self.units, stroke=lineColor, fill=fillColor, stroke_width=penWidth)
				else:
					gridshape = SVGdraw.rect(polyLeftStr, polyTopStr, polySize, polySize, stroke=lineColor, fill=fillColor, stroke_width=penWidth)
				
				canvas.addElement(gridshape)
		return canvas
示例#20
0
    def save(self, filename=None):
        document = SVGdraw.drawing()
        width = str(self.width) + self.units
        height = str(self.height) + self.units
        canvas = SVGdraw.svg(None, width, height)

        canvas.addElement(SVGdraw.description(self.description))

        self.makeGrid(canvas)

        document.setSVG(canvas)

        if filename:
            document.toXml(filename)
        else:
            return document.toXml()
示例#21
0
 def assemble(self):
     # Yes, everything with HEIGHT, so I'm working in a square.
     # May have the colors backwards.
     p = partLine(linetype=self.lineType)
     if self.pieces == 8:
         # No reason to do this as a special case, but it was working
         # first, so why mess with it.
         p.move(0, -blazon.Ordinary.HEIGHT)
         p.makeline(0, blazon.Ordinary.HEIGHT)
         p.hline(-blazon.Ordinary.HEIGHT)
         p.makeline(blazon.Ordinary.HEIGHT, -blazon.Ordinary.HEIGHT)
         p.closepath()
         p.move(-blazon.Ordinary.HEIGHT, 0)
         p.makeline(blazon.Ordinary.HEIGHT, 0)
         p.vline(blazon.Ordinary.HEIGHT)
         p.makeline(-blazon.Ordinary.HEIGHT, -blazon.Ordinary.HEIGHT)
         p.closepath()
     else:
         angle = 2 * math.pi / self.pieces
         pi_2 = math.pi / 2
         for i in range(0, self.pieces, 2):
             p.move(blazon.Ordinary.HEIGHT * math.cos(pi_2 + i * angle),
                    blazon.Ordinary.HEIGHT * math.sin(pi_2 + i * angle))
             p.makeline(0, 0)
             p.makeline(
                 blazon.Ordinary.HEIGHT * math.cos(pi_2 + (i + 1) * angle),
                 blazon.Ordinary.HEIGHT * math.sin(pi_2 + (i + 1) * angle))
             p.closepath()
     self.path = SVGdraw.path(p)
     self.path.attributes["fill-rule"] = "evenodd"
示例#22
0
 def build(self):
     sp = self._head.position('s')
     dp = self._tail.position('n')
     self._extent = (abs(dp[0]-sp[0]),abs(dp[1]-sp[1]))
     self._widget = SVG.line(sp[0], sp[1], dp[0], dp[1], self._color, 
                             self._parent.strokewidth())
     self._widget.attributes['stroke-dasharray']='4,4'
示例#23
0
    def getElements( self, node_id, x, y1, y2 ):

        e = []
        e.append(SVGdraw.line( x, y1, x, y2,
                                stroke = "rgb(%i,%i,%i)" % BLACK,
                                stroke_width = 1 ))
        return e
示例#24
0
 def build(self):
     sp = self._dest.position('n')
     dp = self._source.position('s')
     self._extent = (abs(dp[0]-sp[0]),abs(dp[1]-sp[1]))
     self._widget = SVG.line(sp[0], sp[1], dp[0], dp[1], self._color, 
                             self._parent.strokewidth())
     self._widget.attributes['marker-end'] = \
         self._parent.svgarrow(self._color, False)
 def addSeparator( self ):
     """add separator on circles."""
     if self.mRadius not in self.mSeparators:
         e = SVGdraw.circle( self.mDataMiddleX, self.mDataMiddleY, self.mRadius, fill="none",
                             stroke = "rgb(%i,%i,%i)" % self.mGridColour,
                             stroke_width = self.mGridStrokeWidth )
         self.addWheelElement( e, self.mPlaneGrid )
     self.mSeparators[self.mRadius] = 1
示例#26
0
    def getElements( self, node_id, x1, x2, y ):

        e = []
        if not self.mNoBranch:
            e.append(SVGdraw.line( x1, y, x2, y,
                                   stroke = "rgb(%i,%i,%i)" % BLACK,
                                   stroke_width = 1 ) )
        return e
示例#27
0
   def fill(self,elt):
      pattern=SVGdraw.SVGelement('pattern',attributes=
                                 {"height":"15","width":"15",
                                  "patternUnits":"userSpaceOnUse",
                                  "patternContentUnits":"userSpaceOnUse",
                                  "id":"ermine%04d"%blazon.Ordinary.id})
      blazon.Ordinary.id+=1
      pattern.addElement(self.color1.fill(SVGdraw.rect(x="0",y="0",width="15",height="15")))
      pattern.addElement(self.color2.fill(SVGdraw.SVGelement('path',
                                                             attributes={"d":
                                                        "M1,5 c1,-1 1.5,-4 1.5,-4 c0,0 .5,3 1.5,4 l-1.5,1.5 z"})))
      pattern.addElement(self.color2.fill(SVGdraw.circle(cx="1.5",cy="2",
                                                         r=".5")))
      pattern.addElement(self.color2.fill(SVGdraw.circle(cx="2.5",cy="1",
                                                         r=".5")))
      pattern.addElement(self.color2.fill(SVGdraw.circle(cx="3.5",cy="2",
                                                         r=".5")))
      pattern.addElement(self.color2.fill(SVGdraw.SVGelement('path',
                                            attributes={"d":
                                                        "M8.5,12.5 c1,-1 1.5,-4 1.5,-4 c0,0 .5,3 1.5,4 l-1.5,1.5 z"})))
      pattern.addElement(self.color2.fill(SVGdraw.circle(cx="9",cy="9.5",
                                                         r=".5")))
      pattern.addElement(self.color2.fill(SVGdraw.circle(cx="10",cy="8.5",
                                                         r=".5")))
      pattern.addElement(self.color2.fill(SVGdraw.circle(cx="11",cy="9.5",
                                                         r=".5")))

      blazon.Ordinary.defs.append(pattern)
      elt.attributes["fill"]="url(#%s)"%pattern.attributes["id"]
      return elt
示例#28
0
 def render(self, scale=1, width=None, height=None, linkparent=False):
     """Render the revision tree"""
     self._svg = SVG.svg((0,0,self._extent[0],self._extent[1]),
                         scale*self._extent[0], scale*self._extent[1])
     self._arrows.render()
     # FIXME: only two levels for enhancers (background, foreground)
     map(lambda e: e.render(self._addons[e], 1), self.enhancers)
     map(lambda b: b.render(), self._svgbranches.values())
     map(lambda e: e.render(self._addons[e], 2), self.enhancers)
示例#29
0
 def assemble(self):
     p=partLine(linetype=self.lineType)
     width=float(blazon.Ordinary.WIDTH)/self.pieces
     for i in range(0,self.pieces):
         p.move(-blazon.Ordinary.FESSPTX+i*width,-blazon.Ordinary.FESSPTY)
         p.makelinerel(width/2,blazon.Ordinary.HEIGHT)
         p.makelinerel(width/2,-blazon.Ordinary.HEIGHT)
         p.closepath()
     self.path=SVGdraw.path(p)
示例#30
0
 def render(self, scale=1, width=None, height=None, linkparent=False):
     """Render the revision tree"""
     self._svg = SVG.svg((0, 0, self._extent[0], self._extent[1]),
                         scale * self._extent[0], scale * self._extent[1])
     self._arrows.render()
     # FIXME: only two levels for enhancers (background, foreground)
     map(lambda e: e.render(self._addons[e], 1), self.enhancers)
     map(lambda b: b.render(), self._svgbranches.values())
     map(lambda e: e.render(self._addons[e], 2), self.enhancers)
示例#31
0
 def assemble(self):
     p=partLine(linetype=self.lineType)
     height=float(blazon.Ordinary.HEIGHT)/self.pieces
     for i in range(0,self.pieces):
         p.move(-blazon.Ordinary.FESSPTX,-blazon.Ordinary.FESSPTY+i*height)
         p.makelinerel(blazon.Ordinary.WIDTH,height/2)
         p.makelinerel(-blazon.Ordinary.WIDTH,height/2)
         p.closepath()
     self.path=SVGdraw.path(p)
示例#32
0
 def build(self):
     self._position = self._parent.position()
     x = self._position[0] + (self._w - self._tw) / 2
     y = self._position[1]
     r = UNIT / 2
     rect = SVG.rect(x, y, self._tw, self._h, self._parent.fillcolor(),
                     self._parent.strokecolor(), self._parent.strokewidth())
     rect.attributes['rx'] = r
     rect.attributes['ry'] = r
     text = SVG.text(self._position[0] + +self._w / 2,
                     self._position[1] + self._h / 2 + UNIT / 6,
                     "/%s" % self._title.encode('utf-8'),
                     self._parent.fontsize(), self._parent.fontname())
     text.attributes['style'] = 'text-anchor: middle'
     name = self._title.encode('utf-8').replace('/', '')
     g = SVG.group('grp%s' % name, elements=[rect, text])
     href = Href(self._parent.urlbase())
     self._link = SVG.link(plink(href.browser(self._title)), elements=[g])
示例#33
0
 def fill(self, elt,symbol=False):
    self.assemble()
    self.foreground=blazon.Ordinary()        # treat it like an blazon.Ordinary
    self.foreground.clipPath=self.path
    self.foreground.clipPathElt.addElement(self.path)
    self.foreground.tincture=self.colors[1]
    #self.background=SVGdraw.rect(-blazon.Ordinary.FESSPTX,
    #                             -blazon.Ordinary.FESSPTY,
    #                             blazon.Ordinary.WIDTH,
    #                             blazon.Ordinary.HEIGHT)
    #self.background=self.colors[0].fill(self.background)
    self.background=self.colors[0].fill(elt)
    if symbol:
        self.foreground.clipPathElt.addElement(SVGdraw.use(symbol))
    g=SVGdraw.group()
    g.addElement(self.background)
    g.addElement(self.foreground.finalizeSVG())
    return g
示例#34
0
 def fill(self, elt, symbol=False):
     self.assemble()
     self.foreground = blazon.Ordinary()  # treat it like an blazon.Ordinary
     self.foreground.clipPath = self.path
     self.foreground.clipPathElt.addElement(self.path)
     self.foreground.tincture = self.colors[1]
     #self.background=SVGdraw.rect(-blazon.Ordinary.FESSPTX,
     #                             -blazon.Ordinary.FESSPTY,
     #                             blazon.Ordinary.WIDTH,
     #                             blazon.Ordinary.HEIGHT)
     #self.background=self.colors[0].fill(self.background)
     self.background = self.colors[0].fill(elt)
     if symbol:
         self.foreground.clipPathElt.addElement(SVGdraw.use(symbol))
     g = SVGdraw.group()
     g.addElement(self.background)
     g.addElement(self.foreground.finalizeSVG())
     return g
示例#35
0
 def fill(self,elt):
    VIPpattern=self.VairPattern()
    blazon.Ordinary.defs.append(VIPpattern)
    pattern=SVGdraw.SVGelement('pattern',attributes=
                               {"width":"16", "height":"16",
                                "patternUnits":"userSpaceOnUse",
                                "patternContentUnits":"userSpaceOnUse",
                                "id":"vair%04d"%blazon.Ordinary.id})
    self.color="vair%04d"%blazon.Ordinary.id
    blazon.Ordinary.id+=1
    pattern.addElement(SVGdraw.rect(x="0", y="0", width="16", height="8",
                                    fill="url(#%s)"%VIPpattern.attributes["id"]))
    pattern.addElement(SVGdraw.rect(x="0", y="8", width="20", height="8",
                                    fill="url(#%s)"%VIPpattern.attributes["id"],
                                    transform="translate(-4,0)"))
    blazon.Ordinary.defs.append(pattern)
    elt.attributes["fill"]="url(#%s)"%pattern.attributes["id"]
    return elt
示例#36
0
 def assemble(self):
     p=partLine(linetype=self.lineType)
     height=float(blazon.Ordinary.HEIGHT)/self.pieces
     for i in range(0,self.pieces):
         p.move(-blazon.Ordinary.FESSPTX,-blazon.Ordinary.FESSPTY+i*height)
         p.makelinerel(blazon.Ordinary.WIDTH,height/2)
         p.makelinerel(-blazon.Ordinary.WIDTH,height/2)
         p.closepath()
     self.path=SVGdraw.path(p)
示例#37
0
 def assemble(self):
     p=partLine(linetype=self.lineType)
     width=float(blazon.Ordinary.WIDTH)/self.pieces
     for i in range(0,self.pieces):
         p.move(-blazon.Ordinary.FESSPTX+i*width,-blazon.Ordinary.FESSPTY)
         p.makelinerel(width/2,blazon.Ordinary.HEIGHT)
         p.makelinerel(width/2,-blazon.Ordinary.HEIGHT)
         p.closepath()
     self.path=SVGdraw.path(p)
    def writeGrid( self ):
        """add grid lines."""

        middlex = self.mDataMiddleX
        middley = self.mDataMiddleY

        ## print separators
        for c in range(len(self.contigs)):

            contig = self.contigs[c]
            
            pos = self.getPosition( contig, "+", 0)
            angle = self.getAngle( pos )

            x,y = self.getPosOnArc( angle, self.mRadius )
            
            e = SVGdraw.line( middlex,
                              middley,
                              x, 
                              y,
                              stroke = "rgb(%i,%i,%i)" % BLACK,
                              stroke_width = self.mGridStrokeWidth )

            self.addElement(e, self.mPlaneGrid )

            if c < len(self.contigs) - 1:
                next_angle = self.getAngle(self.getPosition( self.contigs[c+1], "+", 0 ) )
            else:
                next_angle = 360
            
            x,y = self.getPosOnArc( angle + float(next_angle - angle) / 2, self.mRadiusStart / 2)
            
            e = SVGdraw.text( x,
                              y,
                              contig,
                              self.mGridFontSize,
                              self.mGridFont,
                              stroke = "rgb(%i,%i,%i)" % BLACK,
                              text_anchor = "start" )
            # do not rotate text:
            # transform="rotate(%i,%i,%i)" % ( angle, x, y ))

            self.addElement(e)
示例#39
0
 def build(self):
     (x0,y0) = self._source.position('se')
     (x5,y5) = self._dest.position('ne')
     pd = SVG.pathdata()
     pd.move(x0,y0)
     (x1,y1) = (x0+UNIT,y0+UNIT)
     (x2,y2) = (x0+UNIT,y0+2*UNIT)
     (x3,y3) = (x5+UNIT,y5-2*UNIT)
     (x4,y4) = (x5+UNIT,y5-UNIT)
     if x2 < x4:
         pd.qbezier(x1,y1,x2,y2)
         pd.line(x3,y3)
         pd.qbezier(x4,y4,x5,y5)
     else:
         pd.qbezier(x0+UNIT,(y5+y0)/2,x5,y5)
     self._extent = (abs(x5-x0),abs(y5-y0))
     self._widget = SVG.path(pd, 'none', self._color, 
                             self._parent.strokewidth())
     self._widget.attributes['stroke-dasharray']='5, 5'
示例#40
0
 def build(self):
     (x0, y0) = self._source.position('se')
     (x5, y5) = self._dest.position('ne')
     pd = SVG.pathdata()
     pd.move(x0, y0)
     (x1, y1) = (x0 + UNIT, y0 + UNIT)
     (x2, y2) = (x0 + UNIT, y0 + 2 * UNIT)
     (x3, y3) = (x5 + UNIT, y5 - 2 * UNIT)
     (x4, y4) = (x5 + UNIT, y5 - UNIT)
     if x2 < x4:
         pd.qbezier(x1, y1, x2, y2)
         pd.line(x3, y3)
         pd.qbezier(x4, y4, x5, y5)
     else:
         pd.qbezier(x0 + UNIT, (y5 + y0) / 2, x5, y5)
     self._extent = (abs(x5 - x0), abs(y5 - y0))
     self._widget = SVG.path(pd, 'none', self._color,
                             self._parent.strokewidth())
     self._widget.attributes['stroke-dasharray'] = '5, 5'
示例#41
0
    def plot(self,
             filename,
             segments,
             workspace,
             samples):
        nlines = 2 + len(samples)

        height = nlines * self.linewidth * self.linespace

        width = workspace.max()

        print(height, width)

        root = SVGdraw.drawing()
        canvas = SVGdraw.svg((0, 0, width, heigh), "100%", "100%")

        root.setSVG(canvas)

        root.toXml(filename)
示例#42
0
    def plot(self, 
             filename,
             segments,
             workspace,
             samples ):
        nlines = 2 + len(samples)
        
        height = nlines * self.linewidth * self.linespace

        width = workspace.max()
        
        print height, width
    
        root = SVGdraw.drawing()
        canvas = SVGdraw.svg( (0, 0, width, heigh), "100%", "100%")

        root.setSVG( canvas )

        root.toXml( filename )
示例#43
0
    def getElements( self, node_id, x1, x2, y ):

        e = []
        e.append(SVGdraw.line( x1, y, x2, y,
                               stroke = "rgb(%i,%i,%i)" % BLACK,
                               stroke_width = 1 ) )
        
        e += self.mDecorator1.getElements( node_id, x1, x2, y )
        e += self.mDecorator2.getElements( node_id, x1, x2, y + self.mFontSize )        
        
        return e
示例#44
0
 def assemble(self):
     p = partLine(linetype=self.lineType)
     p.move(-blazon.Ordinary.FESSPTX, 35)
     p.makeline(0, -5, 1)
     p.makeline(blazon.Ordinary.FESSPTX, 35, shift=-1)
     p.relvline(blazon.Ordinary.FESSPTY)
     p.relhline(-blazon.Ordinary.WIDTH)
     p.closepath()
     self.path = SVGdraw.path(p)
     if self.inverted:
         self.path.attributes["transform"] = "rotate(180)"
示例#45
0
    def getElements( self, node_id, x, y ):

        e = []
        colour = self.getColour( node_id, x, y )
        
        if self.mPlotSymbol == "circle":
            e.append( SVGdraw.circle( x + self.mFontSize / 2,
                                      y,
                                      self.mFontSize/2,
                                      stroke = "rgb(%i,%i,%i)" % BLACK,
                                      fill = "rgb(%i,%i,%i)" % colour) )

        elif self.mPlotSymbol == "square":
            e.append( SVGdraw.rect( x, y-self.mFontSize/2,
                                    self.mFontSize,
                                    self.mFontSize,
                                    stroke = "rgb(%i,%i,%i)" % BLACK,
                                    fill = "rgb(%i,%i,%i)" % colour) )
            
        return e
示例#46
0
 def assemble(self):
     p=partLine(linetype=self.lineType)
     p.move(-blazon.Ordinary.FESSPTX,35)
     p.makeline(0,-5,1)
     p.makeline(blazon.Ordinary.FESSPTX,35,shift=-1)
     p.relvline(blazon.Ordinary.FESSPTY)
     p.relhline(-blazon.Ordinary.WIDTH)
     p.closepath()
     self.path=SVGdraw.path(p)
     if self.inverted:
         self.path.attributes["transform"]="rotate(180)"
示例#47
0
 def build(self):
     self._position = self._parent.position()
     x = self._position[0]+(self._w-self._tw)/2
     y = self._position[1]
     r = UNIT/2
     rect = SVG.rect(x,y,self._tw,self._h,
                     self._parent.fillcolor(), 
                     self._parent.strokecolor(), 
                     self._parent.strokewidth())
     rect.attributes['rx'] = r
     rect.attributes['ry'] = r        
     text = SVG.text(self._position[0]++self._w/2, 
                     self._position[1]+self._h/2+UNIT/6,
                     "/%s" % self._title.encode('utf-8'), 
                     self._parent.fontsize(), self._parent.fontname())
     text.attributes['style'] = 'text-anchor: middle'
     name = self._title.encode('utf-8').replace('/','')
     g = SVG.group('grp%s' % name, elements=[rect, text])
     href = Href(self._parent.urlbase())
     self._link = SVG.link(plink(href.browser(self._title)), elements=[g])
示例#48
0
 def assemble(self):
     p = partLine(linetype=self.lineType)
     breadth = math.sqrt(blazon.Ordinary.HEIGHT**2 +
                         blazon.Ordinary.WIDTH**2)
     unit = breadth / self.pieces
     for i in range(0, self.pieces):
         p.move(-breadth / 2 + i * unit, -breadth / 2)
         p.makelinerel(unit / 2, breadth)
         p.makelinerel(unit / 2, -breadth)
         p.closepath()
     self.path = SVGdraw.path(p)
     self.path.attributes["transform"] = " rotate(45)"
示例#49
0
 def create(self, color, head):
     name = self._get_name(color, head)
     if not self._markers.has_key(name):
         # It seems that WebKit needs some adjustements ...
         # xos = (3.0*UNIT/100)
         # yos = (3.0*UNIT/100)
         # ... but Gecko does not
         xos = 0
         yos = 0
         if head:
             marker = SVG.marker(name, (0,0,10,8), 0, 4, UNIT/4, UNIT/4,
                                 fill=SvgColor(color), orient='auto')
             marker.addElement(SVG.polyline(((0-xos,4-yos),(10-xos,0-yos),
                                             (10-xos,8-yos),(0-xos,4-yos))))
         else:
             marker = SVG.marker(name, (0,0,10,8), 10, 4, UNIT/4, UNIT/4,
                                 fill=SvgColor(color), orient='auto')
             marker.addElement(SVG.polyline(((0+xos,0-yos),(0+xos,8-yos),
                                             (10+xos,4-yos),(0+xos,0-yos))))
         self._markers[name] = marker
     return name
示例#50
0
 def assemble(self):
     p = partLine()
     p.lineType = self.lineType
     p.move(0, blazon.Ordinary.HEIGHT)
     p.makeline(0, 0, align=1)
     p.makeline(-blazon.Ordinary.WIDTH, -blazon.Ordinary.WIDTH)
     p.vline(blazon.Ordinary.HEIGHT)
     p.closepath()
     self.path1 = SVGdraw.path(p)
     p = partLine()
     p.lineType = self.lineType
     p.move(0, blazon.Ordinary.HEIGHT)
     p.makeline(0, 0, align=1, shift=1)
     p.makeline(blazon.Ordinary.WIDTH, -blazon.Ordinary.WIDTH)
     p.vline(blazon.Ordinary.HEIGHT)
     p.closepath()
     self.path2 = SVGdraw.path(p)
     if self.inverted:
         # Have to rearrange the colors too
         self.colors = (self.colors[2], self.colors[1], self.colors[0])
         self.path1.attributes["transform"] = "rotate(180)"
         self.path2.attributes["transform"] = "rotate(180)"
示例#51
0
 def assemble(self):
     p = partLine()
     p.lineType = self.lineType
     p.move(-blazon.Ordinary.WIDTH - blazon.Ordinary.FESSPTX,
            -blazon.Ordinary.HEIGHT - blazon.Ordinary.FESSPTY)
     p.hline(0)
     p.makeline(0, blazon.Ordinary.HEIGHT)
     p.hline(blazon.Ordinary.WIDTH)
     p.vline(0)
     p.makeline(-blazon.Ordinary.WIDTH, 0)
     p.closepath()
     self.path = SVGdraw.path(p)
     self.path.attributes["fill-rule"] = "evenodd"