示例#1
0
def createPaths():
    elements = []
    sh = pysvg.StyleBuilder()
    sh.setFilling('#EEE')
    sh.setStroke('#00F')
    sh.setStrokeWidth('2px')
    path1 = pysvg.Path('M 40,530 L 100,560 L 60,520 Z', style=sh.getStyle())

    sh2 = pysvg.StyleBuilder()
    sh2.setFilling('#FFC')
    sh2.setStroke('#00F')
    sh2.setStrokeWidth('2px')
    path2 = pysvg.Path(style=sh2.getStyle())
    path2.appendMoveToPath(190, 520, False)
    # as you can see we can mix strings and ints without trouble
    path2.appendCubicCurveToPath('+0', '+0', 30, 30, -60, 30, True)
    path2.appendCloseCurve()

    sh3 = pysvg.StyleBuilder()
    sh3.setFilling('none')
    sh3.setStroke('#00F')
    sh3.setStrokeWidth('2px')
    path3 = pysvg.Path('M 230,530', style=sh3.getStyle())
    path3.appendQuadraticCurveToPath(0, 30, 30, 0)
    path3.appendQuadraticCurveToPath(30, -30, 30, 0)
    path3.appendQuadraticCurveToPath(-0, 30, 30, 0)
    path3.appendQuadraticCurveToPath(30, -20, 30, 0)
    elements.append(path1)
    elements.append(path2)
    elements.append(path3)
    return elements
示例#2
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')
示例#3
0
def ComplexShapes():
    oh = pysvg.ShapeBuilder()
    mySVG = pysvg.Svg("test")
    d = pysvg.Defs()
    d.addElement(MyDropShadow())
    mySVG.addElement(d)

    pl = oh.createPolyline(points="50,375 150,375 150,325 250,325 250,375 \
350,375 350,250 450,250 450,375 550,375 550,175 650,175 650,375 750,375 \
750,100 850,100 850,375 950,375 950,25 1050,25 1050,375 1150,375 ",
                           strokewidth=10,
                           stroke='blue')
    mySVG.addElement(pl)

    pointsAsTuples = [(350, 75), (379, 161), (469, 161), (397, 215),
                      (423, 301), (350, 250), (277, 301), (303, 215),
                      (231, 161), (321, 161)]
    pg = oh.createPolygon(points=oh.convertTupleArrayToPoints(pointsAsTuples),
                          strokewidth=10,
                          stroke='blue',
                          fill='red')
    pg.set_filter('url(#MyDropShadow)')
    mySVG.addElement(pg)

    sh = pysvg.StyleBuilder()
    sh.setFilling('#EEE')
    sh.setStroke('#00F')
    sh.setStrokeWidth('2px')
    path1 = pysvg.Path('M 40,530 L 100,560 L 60,520 Z', style=sh.getStyle())
    sh2 = pysvg.StyleBuilder()
    sh2.setFilling('#FFC')
    sh2.setStroke('#00F')
    sh2.setStrokeWidth('2px')
    path2 = pysvg.Path(style=sh2.getStyle())
    path2.appendMoveToPath(190, 520, False)
    # as you can see we can mix strings and ints without trouble
    path2.appendCubicCurveToPath('+0', '+0', 30, 30, -60, 30, True)
    path2.appendCloseCurve()
    sh3 = pysvg.StyleBuilder()
    sh3.setFilling('none')
    sh3.setStroke('#00F')
    sh3.setStrokeWidth('2px')
    path3 = pysvg.Path('M 230,530', style=sh3.getStyle())
    path3.appendQuadraticCurveToPath(0, 30, 30, 0)
    path3.appendQuadraticCurveToPath(30, -30, 30, 0)
    path3.appendQuadraticCurveToPath(-0, 30, 30, 0)
    path3.appendQuadraticCurveToPath(30, -20, 30, 0)
    mySVG.addElement(path1)
    mySVG.addElement(path2)
    mySVG.addElement(path3)
    mySVG.save('./testoutput/6_ComplexShapes.svg')
示例#4
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')
示例#5
0
Created on 25.06.2010

@author: kerim
'''
import pysvg

sh = pysvg.ShapeBuilder()
c1 = sh.createCircle(cx=20, cy=20, r=15, fill="yellow")
c1.set_id("gesicht")
c2 = sh.createCircle(cx=15, cy=15, r=2, fill="black")
c2.set_id("auge-links")
c3 = sh.createCircle(cx=25, cy=15, r=2, fill="black")
c3.set_id("auge-rechts")
l1 = sh.createLine(x1=20, y1=18, x2=20, y2=23, strokewidth=2)
l1.set_id("nase")
p1 = pysvg.Path("M 13 26 A 5 3 0 0 0 27 26")
p1.set_id("mund")
p1.set_stroke("black")
p1.set_stroke_width("2")
p1.set_fill("none")

mySymbol = pysvg.Symbol()
mySymbol.set_id("smilie")
mySymbol.addElement(c1)
mySymbol.addElement(c2)
mySymbol.addElement(c3)
mySymbol.addElement(l1)
mySymbol.addElement(p1)

filter6 = pysvg.Filter(x="-.3", y="-.5", width=1.9, height=1.9)
filtBlur = pysvg.FeGaussianBlur(stdDeviation="4")