tests/test_pdfgen_general.py
branchpy33
changeset 3721 0c93dd8ff567
parent 3680 cbfd10f961b0
child 3794 398ea04239b5
equal deleted inserted replaced
3720:7a059dde5bf5 3721:0c93dd8ff567
   131         canvas.rect(x + 9, y - height + 9, 198, height - 18)
   131         canvas.rect(x + 9, y - height + 9, 198, height - 18)
   132         #boundary:
   132         #boundary:
   133         self.namespace = {'canvas':canvas,'cm': cm,'inch':inch}
   133         self.namespace = {'canvas':canvas,'cm': cm,'inch':inch}
   134         canvas.translate(x+9, y - height + 9)
   134         canvas.translate(x+9, y - height + 9)
   135         codeObj = compile(self.code, '<sample>','exec')
   135         codeObj = compile(self.code, '<sample>','exec')
   136         exec codeObj in self.namespace
   136         exec(codeObj, self.namespace)
   137 
   137 
   138         canvas.restoreState()
   138         canvas.restoreState()
   139 
   139 
   140 
   140 
   141 def drawAxes(canvas, label):
   141 def drawAxes(canvas, label):
   202     framePage(c, 'PDFgen graphics API test script')
   202     framePage(c, 'PDFgen graphics API test script')
   203     makesubsection(c, "PDFgen", 10*inch)
   203     makesubsection(c, "PDFgen", 10*inch)
   204 
   204 
   205     #quickie encoding test: when canvas encoding not set,
   205     #quickie encoding test: when canvas encoding not set,
   206     #the following should do (tm), (r) and (c)
   206     #the following should do (tm), (r) and (c)
   207     msg_uni = u'copyright\u00A9 trademark\u2122 registered\u00AE scissors\u2702: ReportLab in unicode!'
   207     msg_uni = 'copyright\u00A9 trademark\u2122 registered\u00AE scissors\u2702: ReportLab in unicode!'
   208     msg_utf8 = msg_uni.replace('unicode','utf8').encode('utf8')
   208     msg_utf8 = msg_uni.replace('unicode','utf8').encode('utf8')
   209     c.drawString(100, 100, msg_uni)
   209     c.drawString(100, 100, msg_uni)
   210     c.drawString(100, 80, msg_utf8)
   210     c.drawString(100, 80, msg_utf8)
   211 
   211 
   212     
   212     
   722     c.drawString(1*inch, 10.25*inch, "For rgba type images we can use the alpha channel if we set mask='auto'.")
   722     c.drawString(1*inch, 10.25*inch, "For rgba type images we can use the alpha channel if we set mask='auto'.")
   723     c.drawString(1*inch, 10.25*inch-14.4, "The first image is solid red with variable alpha.")
   723     c.drawString(1*inch, 10.25*inch-14.4, "The first image is solid red with variable alpha.")
   724     c.drawString(1*inch, 10.25*inch-2*14.4, "The second image is white alpha=0% to purple=100%")
   724     c.drawString(1*inch, 10.25*inch-2*14.4, "The second image is white alpha=0% to purple=100%")
   725 
   725 
   726 
   726 
   727     for i in xrange(8):
   727     for i in range(8):
   728         c.drawString(1*inch,8*inch+i*14.4,"mask=None   Line %d"%i)
   728         c.drawString(1*inch,8*inch+i*14.4,"mask=None   Line %d"%i)
   729         c.drawString(3*inch,8*inch+i*14.4,"mask='auto' Line %d"%i)
   729         c.drawString(3*inch,8*inch+i*14.4,"mask='auto' Line %d"%i)
   730         c.drawString(1*inch,6*inch+i*14.4,"mask=None   Line %d"%i)
   730         c.drawString(1*inch,6*inch+i*14.4,"mask=None   Line %d"%i)
   731         c.drawString(3*inch,6*inch+i*14.4,"mask='auto' Line %d"%i)
   731         c.drawString(3*inch,6*inch+i*14.4,"mask='auto' Line %d"%i)
   732     w = 100
   732     w = 100
   908     return c
   908     return c
   909 
   909 
   910 
   910 
   911 def run(filename):
   911 def run(filename):
   912     c = makeDocument(filename)
   912     c = makeDocument(filename)
   913     c.setAuthor(u'R\xfcp\xe9rt B\xe8\xe4r')
   913     c.setAuthor('R\xfcp\xe9rt B\xe8\xe4r')
   914     c.setTitle('R\xc3\xbcp\xc3\xa9rt B\xc3\xa8\xc3\xa4r\'s Book')
   914     c.setTitle('R\xc3\xbcp\xc3\xa9rt B\xc3\xa8\xc3\xa4r\'s Book')
   915     c.setCreator(u'Some Creator')
   915     c.setCreator('Some Creator')
   916     c.setSubject(u'Some Subject')
   916     c.setSubject('Some Subject')
   917     c.save()
   917     c.save()
   918     c = makeDocument(filename)
   918     c = makeDocument(filename)
   919     import os
   919     import os
   920     f = os.path.splitext(filename)
   920     f = os.path.splitext(filename)
   921     f = open('%sm%s' % (f[0],f[1]),'wb')
   921     f = open('%sm%s' % (f[0],f[1]),'wb')
   934 
   934 
   935     y = 9 * inch
   935     y = 9 * inch
   936     d = DocBlock()
   936     d = DocBlock()
   937     d.comment1 = 'Lesson one'
   937     d.comment1 = 'Lesson one'
   938     d.code = "canvas.textOut('hello, world')"
   938     d.code = "canvas.textOut('hello, world')"
   939     print d.code
   939     print(d.code)
   940 
   940 
   941     d.comment2 = 'Lesson two'
   941     d.comment2 = 'Lesson two'
   942 
   942 
   943     d.draw(c, inch, 9 * inch)
   943     d.draw(c, inch, 9 * inch)
   944 
   944 
   964         c.addPageLabel(21, style='ARABIC', start=22)
   964         c.addPageLabel(21, style='ARABIC', start=22)
   965         c.addPageLabel(99, style='LETTERS_UPPER')
   965         c.addPageLabel(99, style='LETTERS_UPPER')
   966         c.addPageLabel(102, prefix="Back",start=1)
   966         c.addPageLabel(102, prefix="Back",start=1)
   967 
   967 
   968         # Make some (mostly) empty pages
   968         # Make some (mostly) empty pages
   969         for i in xrange(113):
   969         for i in range(113):
   970             c.drawString(100, 100, 'Tis is page '+str(i))
   970             c.drawString(100, 100, 'Tis is page '+str(i))
   971             c.showPage()
   971             c.showPage()
   972 
   972 
   973         # Output the PDF
   973         # Output the PDF
   974         c.save()    
   974         c.save()    
  1097         #multiple calls to save / getpdfdata used to cause errors
  1097         #multiple calls to save / getpdfdata used to cause errors
  1098         stuff = c.getpdfdata()    
  1098         stuff = c.getpdfdata()    
  1099 
  1099 
  1100 
  1100 
  1101 def trySomeColors(C,enforceColorSpace=None):
  1101 def trySomeColors(C,enforceColorSpace=None):
  1102     from StringIO import StringIO
  1102     from io import StringIO
  1103     out=StringIO()
  1103     out=StringIO()
  1104     canv = canvas.Canvas(out,enforceColorSpace=enforceColorSpace)
  1104     canv = canvas.Canvas(out,enforceColorSpace=enforceColorSpace)
  1105     canv.setFont('Helvetica',10)
  1105     canv.setFont('Helvetica',10)
  1106     x = 0
  1106     x = 0
  1107     y = 0
  1107     y = 0