Пример #1
0
def Grouping():
    s = pysvg.Svg()

    # testing container
    myStyle = pysvg.StyleBuilder()
    myStyle.setStrokeWidth(2)
    myStyle.setStroke("green")

    group = pysvg.G()
    group.set_style(myStyle.getStyle())
    group.addElement(pysvg.Line(300, 300, 600, 600))
    group.addElement(pysvg.Circle(500, 500, 50))
    s.addElement(group)

    group = pysvg.G()
    group.set_style(myStyle.getStyle())
    style_dict = {
        "stroke": "#000000",
        "fill": "none",
        "stroke-width": "49",
        "stroke-opacity": "0.027276"
    }
    p = pysvg.Path(pathData="M 300 100 A 1,1 0 0 1 802,800")
    p.set_style(pysvg.StyleBuilder(style_dict).getStyle())
    p2 = pysvg.Path(pathData="M 100 300 A 1,1 0 0 1 802,800")
    p2.set_style(pysvg.StyleBuilder(style_dict).getStyle())
    group.addElement(p)
    group.addElement(p2)
    s.addElement(group)
    print s.getXML()
    s.save('./testoutput/7_Grouping.svg')
Пример #2
0
def testClipPath():
    mySVG = pysvg.Svg("a spiral with clipping")
    group = pysvg.G()
    pathId = "pathTriangle"
    myPath = pysvg.Path(pathData="M 0 0 L 450 450 L 900 0")
    clip = pysvg.ClipPath(id="pathTriangle")
    clip.addElement(myPath)
    clip.set_id(pathId)
    myDef = pysvg.Defs()
    myDef.addElement(clip)
    mySVG.addElement(myDef)
    group.set_clip_path("url(#%s)" % pathId)
    for i in range(1, 200):
        x = 2 * i * math.cos(2 * math.pi * i / 40.5) + 450
        y = 2 * i * math.sin(2 * math.pi * i / 40.5) + 450
        # print 'color: rgb(%s,%s,%s)' % (i, 200-i, i*(200-i)/50)
        c = pysvg.Circle(x, y, 0.2 * i)
        fill = 'none'
        strokewidth = 5
        stroke = 'rgb(%s,%s,%s)' % (i, 200 - i, i * (200 - i) / 50)
        myStyle = 'fill:%s;stroke-width:%s; stroke:%s' % (fill, strokewidth,
                                                          stroke)
        c.set_style(myStyle)
        group.addElement(c)
    mySVG.addElement(group)
    mySVG.save('./testoutput/spiralClipped.svg')
Пример #3
0
def main():
    mySVG = pysvg.Svg(0, 0, width="100%", height="100%")
    t = pysvg.Text("pySVG", x=0, y=100)
    group = pysvg.G()
    group.set_transform("rotate(-30)")
    t.set_stroke_width('1px')
    t.set_stroke('#00C')
    t.set_fill('none')
    t.set_font_size("36")
    group.addElement(t)

    mySVG.addElement(group)

    print mySVG.getXML()
    mySVG.save('./testoutput/pySVGLogo.svg')
Пример #4
0
def createShapes():
    oh = pysvg.ShapeBuilder()

    elements = []
    # rectangles
    r = oh.createRect(30, 70, 80, 30, strokewidth='0', fill='#090')
    elements.append(r)
    r = oh.createRect(120,
                      70,
                      80,
                      30,
                      strokewidth='2px',
                      stroke='#00C',
                      fill='#FFC')
    elements.append(r)

    # circles
    c = oh.createCircle(60, 170, 30, strokewidth='0', fill='#F00')
    # <circle id="kreis1" cx="60" cy="170" r="30" style="fill: #F00" onmouseover="FillHover('kreis1','#FF0','#00C','5px')" onmouseout="FillHover('kreis1','#F00','none','0px')"/>
    elements.append(c)
    c = oh.createCircle(150,
                        170,
                        30,
                        strokewidth='2px',
                        stroke='#000',
                        fill='#FF0')
    elements.append(c)

    # ellipse
    e = oh.createEllipse(60, 270, 30, 15, strokewidth='0', fill='#F00')
    # <circle id="kreis1" cx="60" cy="170" r="30" style="fill: #F00" onmouseover="FillHover('kreis1','#FF0','#00C','5px')" onmouseout="FillHover('kreis1','#F00','none','0px')"/>
    elements.append(e)
    e = oh.createEllipse(150,
                         270,
                         30,
                         15,
                         strokewidth='2px',
                         stroke='#000',
                         fill='#CCC')
    elements.append(e)

    # polygon
    p = oh.createPolygon('60,370, 70,360, 80,400, 50,440, 40,330',
                         strokewidth='2px',
                         stroke='#000',
                         fill='#FFF')
    elements.append(p)

    # line
    l = oh.createLine(60, 470, 180, 470, strokewidth='2px', stroke='#00C')
    elements.append(l)
    l = oh.createLine(200, 470, 260, 400, strokewidth='2px', stroke='#F00')
    elements.append(l)

    # path
    p = createPaths()
    for e in p:
        elements.append(e)

    # polyline
    p = oh.createPolyline('250,325 200,345 250,365',
                          strokewidth='2px',
                          stroke='#090')
    elements.append(p)

    # opacity
    sh = pysvg.StyleBuilder()
    sh.setFilling('#00C')
    sh.setFillOpacity(0.5)
    c = pysvg.Circle(450, 290, 50)
    c.set_style(sh.getStyle())
    elements.append(c)
    sh = pysvg.StyleBuilder()
    sh.setFilling('#00C')
    sh.setFillOpacity(0.2)
    sh.setStroke('#00C')
    sh.setStrokeOpacity(0.3)
    c = pysvg.Circle(475, 325, 50)
    c.set_style(sh.getStyle())
    elements.append(c)

    # group + transform
    th = pysvg.TransformBuilder()
    th.setRotation('-30')
    group = pysvg.G()
    group.set_transform(th.getTransform())
    r = oh.createRect(620,
                      500,
                      width='100',
                      height='50',
                      rx=10,
                      ry=10,
                      stroke='#F00',
                      strokewidth='2px',
                      fill='none')
    group.addElement(r)

    sh = pysvg.StyleBuilder()
    sh.setFilling('none')
    sh.setFontSize('36px')
    sh.setStrokeWidth('1px')
    sh.setStroke('#00C')
    t = pysvg.Text('Text', 635, 537)
    t.set_style(sh.getStyle())
    group.addElement(t)
    elements.append(group)

    return elements
Пример #5
0
def createShapes():
    oh = pysvg.ShapeBuilder()
    elements = []

    # skewX
    th = pysvg.TransformBuilder()
    th.setSkewX('-40.0')
    group = pysvg.G()
    group.set_transform(th.getTransform())
    r = oh.createRect(620,
                      300,
                      width='100',
                      height='50',
                      rx=10,
                      ry=10,
                      stroke='#F00',
                      strokewidth='2px',
                      fill='none')
    group.addElement(r)

    sh = pysvg.StyleBuilder()
    sh.setFilling('none')
    sh.setFontSize('36px')
    sh.setStrokeWidth('1px')
    sh.setStroke('#00C')
    t = pysvg.Text('Text', 635, 337)
    t.set_style(sh.getStyle())
    group.addElement(t)
    elements.append(group)

    # scaling
    th = pysvg.TransformBuilder()
    th.setScaling('1.0', '0.5')
    group = pysvg.G()
    group.set_transform(th.getTransform())
    r = oh.createRect(620,
                      300,
                      width='100',
                      height='50',
                      rx=10,
                      ry=10,
                      stroke='#F00',
                      strokewidth='2px',
                      fill='none')
    group.addElement(r)

    sh = pysvg.StyleBuilder()
    sh.setFilling('none')
    sh.setFontSize('36px')
    sh.setStrokeWidth('1px')
    sh.setStroke('#00C')
    t = pysvg.Text('Text', 635, 337)
    t.set_style(sh.getStyle())
    group.addElement(t)
    elements.append(group)

    # matrix
    th = pysvg.TransformBuilder()
    th.setMatrix('0.866', '0.5', '-0.5', '0.866', '-300.0', '-200.0')
    group = pysvg.G()
    group.set_transform(th.getTransform())
    r = oh.createRect(620,
                      300,
                      width='100',
                      height='50',
                      rx=10,
                      ry=10,
                      stroke='#F00',
                      strokewidth='2px',
                      fill='none')
    group.addElement(r)

    sh = pysvg.StyleBuilder()
    sh.setFilling('none')
    sh.setFontSize('36px')
    sh.setStrokeWidth('1px')
    sh.setStroke('#00C')
    t = pysvg.Text('Text', 635, 337)
    t.set_style(sh.getStyle())
    group.addElement(t)
    elements.append(group)

    return elements