def test(outDir='out-svg'): # print all drawings and their doc strings from the test # file if not os.path.isdir(outDir): os.mkdir(outDir) #grab all drawings from the test module from reportlab.graphics import testshapes drawings = [] for funcname in dir(testshapes): #if funcname[0:11] == 'getDrawing2': # print 'hacked to only show drawing 2' if funcname[0:10] == 'getDrawing': drawing = eval('testshapes.' + funcname + '()') docstring = eval('testshapes.' + funcname + '.__doc__') drawings.append((drawing, docstring)) i = 0 for (d, docstring) in drawings: filename = os.path.join(outDir, 'renderSVG_%d.svg' % i) drawToFile(d, filename) i += 1 from reportlab.graphics.testshapes import getDrawing01 d = getDrawing01() drawToFile(d, os.path.join(outDir, "test.svg")) from reportlab.lib.corp import RL_CorpLogo from reportlab.graphics.shapes import Drawing rl = RL_CorpLogo() d = Drawing(rl.width, rl.height) d.add(rl) drawToFile(d, os.path.join(outDir, "corplogo.svg"))
def test(outDir='out-svg'): # print all drawings and their doc strings from the test # file if not os.path.isdir(outDir): os.mkdir(outDir) #grab all drawings from the test module from reportlab.graphics import testshapes drawings = [] for funcname in dir(testshapes): #if funcname[0:11] == 'getDrawing2': # print 'hacked to only show drawing 2' if funcname[0:10] == 'getDrawing': drawing = eval('testshapes.' + funcname + '()') docstring = eval('testshapes.' + funcname + '.__doc__') drawings.append((drawing, docstring)) i = 0 for (d, docstring) in drawings: filename = os.path.join(outDir,'renderSVG_%d.svg' % i) drawToFile(d, filename) i += 1 from reportlab.graphics.testshapes import getDrawing01 d = getDrawing01() drawToFile(d, os.path.join(outDir,"test.svg")) from reportlab.lib.corp import RL_CorpLogo from reportlab.graphics.shapes import Drawing rl = RL_CorpLogo() d = Drawing(rl.width,rl.height) d.add(rl) drawToFile(d, os.path.join(outDir,"corplogo.svg"))
def test1(): from reportlab.graphics.testshapes import getDrawing01 d = getDrawing01() drawToFile(d, "svgout/test.svg")
d = Drawing(400, 200) d.add(Rect(50, 50, 300, 100, fillColor=colors.yellow)) d.add(String(150,100, 'Hello World', fontSize=18, fillColor=colors.red)) d.add(String(180,86, 'Special characters \\ \\xc2\\xa2\\xc2\\xa9\\xc2\\xae\\xc2\\xa3\\xce\\xb1\\xce\\xb2', fillColor=colors.red)) from reportlab.graphics import renderPDF renderPDF.drawToFile(d, 'example1.pdf', 'My First Drawing') """) disc("This will produce a PDF file containing the following graphic:") from reportlab.graphics.shapes import * from reportlab.graphics import testshapes t = testshapes.getDrawing01() draw(t, "'Hello World'") disc(""" Each renderer is allowed to do whatever is appropriate for its format, and may have whatever API is needed. If it refers to a file format, it usually has a $drawToFile$ function, and that's all you need to know about the renderer. Let's save the same drawing in Encapsulated Postscript format: """) ##eg(""" ## from reportlab.graphics import renderPS ## renderPS.drawToFile(D, 'example1.eps', 'My First Drawing') ##""") eg("""