docs/userguide/examples.py
author rgbecker
Wed, 25 Oct 2000 08:57:46 +0000
changeset 494 54257447cfe9
parent 381 2ca856765ed1
child 684 2a43c747527a
permissions -rw-r--r--
Changed to indirect copyright
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
494
54257447cfe9 Changed to indirect copyright
rgbecker
parents: 381
diff changeset
     1
#copyright ReportLab Inc. 2000
54257447cfe9 Changed to indirect copyright
rgbecker
parents: 381
diff changeset
     2
#see license.txt for license details
54257447cfe9 Changed to indirect copyright
rgbecker
parents: 381
diff changeset
     3
#history http://cvs.sourceforge.net/cgi-bin/cvsweb.cgi/docs/userguide/examples.py?cvsroot=reportlab
54257447cfe9 Changed to indirect copyright
rgbecker
parents: 381
diff changeset
     4
#$Header: /tmp/reportlab/docs/userguide/Attic/examples.py,v 1.16 2000/10/25 08:57:45 rgbecker Exp $
298
0e23c189f665 colors, line styles, more examples
aaron_watters
parents: 296
diff changeset
     5
import string
274
6cf6b9ecf1f1 initial checkin. examples file for userguide generation
aaron_watters
parents:
diff changeset
     6
374
1342601fdc4a minor edits, filled in some blanks
aaron_watters
parents: 364
diff changeset
     7
testannotations="""
1342601fdc4a minor edits, filled in some blanks
aaron_watters
parents: 364
diff changeset
     8
def annotations(canvas):
1342601fdc4a minor edits, filled in some blanks
aaron_watters
parents: 364
diff changeset
     9
    from reportlab.lib.units import inch
375
301cae28e052 internal annotations (author, etc)
aaron_watters
parents: 374
diff changeset
    10
    canvas.drawString(inch, 2.5*inch, 
301cae28e052 internal annotations (author, etc)
aaron_watters
parents: 374
diff changeset
    11
       "setAuthor, setTitle, setSubject have no visible effect")
374
1342601fdc4a minor edits, filled in some blanks
aaron_watters
parents: 364
diff changeset
    12
    canvas.drawString(inch, inch, "But if you are viewing this document dynamically")
1342601fdc4a minor edits, filled in some blanks
aaron_watters
parents: 364
diff changeset
    13
    canvas.drawString(inch, 0.5*inch, "please look at File/Document Info")
1342601fdc4a minor edits, filled in some blanks
aaron_watters
parents: 364
diff changeset
    14
    canvas.setAuthor("the ReportLab Team")
1342601fdc4a minor edits, filled in some blanks
aaron_watters
parents: 364
diff changeset
    15
    canvas.setTitle("ReportLab PDF Generation User Guide")
1342601fdc4a minor edits, filled in some blanks
aaron_watters
parents: 364
diff changeset
    16
    canvas.setSubject("How to Generate PDF files using the ReportLab modules")
1342601fdc4a minor edits, filled in some blanks
aaron_watters
parents: 364
diff changeset
    17
"""
1342601fdc4a minor edits, filled in some blanks
aaron_watters
parents: 364
diff changeset
    18
274
6cf6b9ecf1f1 initial checkin. examples file for userguide generation
aaron_watters
parents:
diff changeset
    19
# magic function making module
6cf6b9ecf1f1 initial checkin. examples file for userguide generation
aaron_watters
parents:
diff changeset
    20
6cf6b9ecf1f1 initial checkin. examples file for userguide generation
aaron_watters
parents:
diff changeset
    21
test1 = """
6cf6b9ecf1f1 initial checkin. examples file for userguide generation
aaron_watters
parents:
diff changeset
    22
def f(a,b):
6cf6b9ecf1f1 initial checkin. examples file for userguide generation
aaron_watters
parents:
diff changeset
    23
    print "it worked", a, b
6cf6b9ecf1f1 initial checkin. examples file for userguide generation
aaron_watters
parents:
diff changeset
    24
    return a+b
6cf6b9ecf1f1 initial checkin. examples file for userguide generation
aaron_watters
parents:
diff changeset
    25
"""
6cf6b9ecf1f1 initial checkin. examples file for userguide generation
aaron_watters
parents:
diff changeset
    26
6cf6b9ecf1f1 initial checkin. examples file for userguide generation
aaron_watters
parents:
diff changeset
    27
test2 = """
6cf6b9ecf1f1 initial checkin. examples file for userguide generation
aaron_watters
parents:
diff changeset
    28
def g(n):
6cf6b9ecf1f1 initial checkin. examples file for userguide generation
aaron_watters
parents:
diff changeset
    29
    if n==0: return 1
6cf6b9ecf1f1 initial checkin. examples file for userguide generation
aaron_watters
parents:
diff changeset
    30
    else: return n*g(n-1)
6cf6b9ecf1f1 initial checkin. examples file for userguide generation
aaron_watters
parents:
diff changeset
    31
    """
6cf6b9ecf1f1 initial checkin. examples file for userguide generation
aaron_watters
parents:
diff changeset
    32
    
6cf6b9ecf1f1 initial checkin. examples file for userguide generation
aaron_watters
parents:
diff changeset
    33
testhello = """
6cf6b9ecf1f1 initial checkin. examples file for userguide generation
aaron_watters
parents:
diff changeset
    34
def hello(c):
275
652c5c4b78ca Example had a reference to layout.py, removed
andy_robinson
parents: 274
diff changeset
    35
    from reportlab.lib.units import inch
274
6cf6b9ecf1f1 initial checkin. examples file for userguide generation
aaron_watters
parents:
diff changeset
    36
    # move the origin up and to the left
6cf6b9ecf1f1 initial checkin. examples file for userguide generation
aaron_watters
parents:
diff changeset
    37
    c.translate(inch,inch) 
6cf6b9ecf1f1 initial checkin. examples file for userguide generation
aaron_watters
parents:
diff changeset
    38
    # define a large font
6cf6b9ecf1f1 initial checkin. examples file for userguide generation
aaron_watters
parents:
diff changeset
    39
    c.setFont("Helvetica", 14)
6cf6b9ecf1f1 initial checkin. examples file for userguide generation
aaron_watters
parents:
diff changeset
    40
    # choose some colors
6cf6b9ecf1f1 initial checkin. examples file for userguide generation
aaron_watters
parents:
diff changeset
    41
    c.setStrokeColorRGB(0.2,0.5,0.3)
6cf6b9ecf1f1 initial checkin. examples file for userguide generation
aaron_watters
parents:
diff changeset
    42
    c.setFillColorRGB(1,0,1)
6cf6b9ecf1f1 initial checkin. examples file for userguide generation
aaron_watters
parents:
diff changeset
    43
    # draw some lines
283
50f6c1be3e51 2nd try. more text
aaron_watters
parents: 275
diff changeset
    44
    c.line(0,0,0,1.7*inch)
274
6cf6b9ecf1f1 initial checkin. examples file for userguide generation
aaron_watters
parents:
diff changeset
    45
    c.line(0,0,1*inch,0)
6cf6b9ecf1f1 initial checkin. examples file for userguide generation
aaron_watters
parents:
diff changeset
    46
    # draw a rectangle
6cf6b9ecf1f1 initial checkin. examples file for userguide generation
aaron_watters
parents:
diff changeset
    47
    c.rect(0.2*inch,0.2*inch,1*inch,1.5*inch, fill=1)
6cf6b9ecf1f1 initial checkin. examples file for userguide generation
aaron_watters
parents:
diff changeset
    48
    # make text go straight up
6cf6b9ecf1f1 initial checkin. examples file for userguide generation
aaron_watters
parents:
diff changeset
    49
    c.rotate(90)
6cf6b9ecf1f1 initial checkin. examples file for userguide generation
aaron_watters
parents:
diff changeset
    50
    # change color
6cf6b9ecf1f1 initial checkin. examples file for userguide generation
aaron_watters
parents:
diff changeset
    51
    c.setFillColorRGB(0,0,0.77)
6cf6b9ecf1f1 initial checkin. examples file for userguide generation
aaron_watters
parents:
diff changeset
    52
    # say hello (note after rotate the y coord needs to be negative!)
6cf6b9ecf1f1 initial checkin. examples file for userguide generation
aaron_watters
parents:
diff changeset
    53
    c.drawString(0.3*inch, -inch, "Hello World")
6cf6b9ecf1f1 initial checkin. examples file for userguide generation
aaron_watters
parents:
diff changeset
    54
"""
6cf6b9ecf1f1 initial checkin. examples file for userguide generation
aaron_watters
parents:
diff changeset
    55
283
50f6c1be3e51 2nd try. more text
aaron_watters
parents: 275
diff changeset
    56
testcoords = """
50f6c1be3e51 2nd try. more text
aaron_watters
parents: 275
diff changeset
    57
def coords(canvas):
50f6c1be3e51 2nd try. more text
aaron_watters
parents: 275
diff changeset
    58
    from reportlab.lib.units import inch
50f6c1be3e51 2nd try. more text
aaron_watters
parents: 275
diff changeset
    59
    from reportlab.lib.colors import pink, black, red, blue, green
50f6c1be3e51 2nd try. more text
aaron_watters
parents: 275
diff changeset
    60
    c = canvas
50f6c1be3e51 2nd try. more text
aaron_watters
parents: 275
diff changeset
    61
    c.setStrokeColor(pink)
50f6c1be3e51 2nd try. more text
aaron_watters
parents: 275
diff changeset
    62
    c.grid([inch, 2*inch, 3*inch, 4*inch], [0.5*inch, inch, 1.5*inch, 2*inch, 2.5*inch])
50f6c1be3e51 2nd try. more text
aaron_watters
parents: 275
diff changeset
    63
    c.setStrokeColor(black)
50f6c1be3e51 2nd try. more text
aaron_watters
parents: 275
diff changeset
    64
    c.setFont("Times-Roman", 20)
50f6c1be3e51 2nd try. more text
aaron_watters
parents: 275
diff changeset
    65
    c.drawString(0,0, "(0,0) the Origin")
50f6c1be3e51 2nd try. more text
aaron_watters
parents: 275
diff changeset
    66
    c.drawString(2.5*inch, inch, "(2.5,1) in inches")
50f6c1be3e51 2nd try. more text
aaron_watters
parents: 275
diff changeset
    67
    c.drawString(4*inch, 2.5*inch, "(4, 2.5)")
50f6c1be3e51 2nd try. more text
aaron_watters
parents: 275
diff changeset
    68
    c.setFillColor(red)
50f6c1be3e51 2nd try. more text
aaron_watters
parents: 275
diff changeset
    69
    c.rect(0,2*inch,0.2*inch,0.3*inch, fill=1)
50f6c1be3e51 2nd try. more text
aaron_watters
parents: 275
diff changeset
    70
    c.setFillColor(green)
50f6c1be3e51 2nd try. more text
aaron_watters
parents: 275
diff changeset
    71
    c.circle(4.5*inch, 0.4*inch, 0.2*inch, fill=1)
50f6c1be3e51 2nd try. more text
aaron_watters
parents: 275
diff changeset
    72
"""
50f6c1be3e51 2nd try. more text
aaron_watters
parents: 275
diff changeset
    73
50f6c1be3e51 2nd try. more text
aaron_watters
parents: 275
diff changeset
    74
testtranslate = """
50f6c1be3e51 2nd try. more text
aaron_watters
parents: 275
diff changeset
    75
def translate(canvas):
50f6c1be3e51 2nd try. more text
aaron_watters
parents: 275
diff changeset
    76
    from reportlab.lib.units import cm
50f6c1be3e51 2nd try. more text
aaron_watters
parents: 275
diff changeset
    77
    canvas.translate(2.3*cm, 0.3*cm)
50f6c1be3e51 2nd try. more text
aaron_watters
parents: 275
diff changeset
    78
    coords(canvas)
50f6c1be3e51 2nd try. more text
aaron_watters
parents: 275
diff changeset
    79
    """
50f6c1be3e51 2nd try. more text
aaron_watters
parents: 275
diff changeset
    80
    
50f6c1be3e51 2nd try. more text
aaron_watters
parents: 275
diff changeset
    81
testscale = """
50f6c1be3e51 2nd try. more text
aaron_watters
parents: 275
diff changeset
    82
def scale(canvas):
50f6c1be3e51 2nd try. more text
aaron_watters
parents: 275
diff changeset
    83
    canvas.scale(0.75, 0.5)
50f6c1be3e51 2nd try. more text
aaron_watters
parents: 275
diff changeset
    84
    coords(canvas)
50f6c1be3e51 2nd try. more text
aaron_watters
parents: 275
diff changeset
    85
"""
50f6c1be3e51 2nd try. more text
aaron_watters
parents: 275
diff changeset
    86
50f6c1be3e51 2nd try. more text
aaron_watters
parents: 275
diff changeset
    87
testscaletranslate = """
50f6c1be3e51 2nd try. more text
aaron_watters
parents: 275
diff changeset
    88
def scaletranslate(canvas):
50f6c1be3e51 2nd try. more text
aaron_watters
parents: 275
diff changeset
    89
    from reportlab.lib.units import inch
50f6c1be3e51 2nd try. more text
aaron_watters
parents: 275
diff changeset
    90
    canvas.setFont("Courier-BoldOblique", 12)
50f6c1be3e51 2nd try. more text
aaron_watters
parents: 275
diff changeset
    91
    # save the state
50f6c1be3e51 2nd try. more text
aaron_watters
parents: 275
diff changeset
    92
    canvas.saveState()
50f6c1be3e51 2nd try. more text
aaron_watters
parents: 275
diff changeset
    93
    # scale then translate
50f6c1be3e51 2nd try. more text
aaron_watters
parents: 275
diff changeset
    94
    canvas.scale(0.3, 0.5)
50f6c1be3e51 2nd try. more text
aaron_watters
parents: 275
diff changeset
    95
    canvas.translate(2.4*inch, 1.5*inch)
50f6c1be3e51 2nd try. more text
aaron_watters
parents: 275
diff changeset
    96
    canvas.drawString(0, 2.7*inch, "Scale then translate")
50f6c1be3e51 2nd try. more text
aaron_watters
parents: 275
diff changeset
    97
    coords(canvas)
50f6c1be3e51 2nd try. more text
aaron_watters
parents: 275
diff changeset
    98
    # forget the scale and translate...
50f6c1be3e51 2nd try. more text
aaron_watters
parents: 275
diff changeset
    99
    canvas.restoreState()
50f6c1be3e51 2nd try. more text
aaron_watters
parents: 275
diff changeset
   100
    # translate then scale
50f6c1be3e51 2nd try. more text
aaron_watters
parents: 275
diff changeset
   101
    canvas.translate(2.4*inch, 1.5*inch)
50f6c1be3e51 2nd try. more text
aaron_watters
parents: 275
diff changeset
   102
    canvas.scale(0.3, 0.5)
50f6c1be3e51 2nd try. more text
aaron_watters
parents: 275
diff changeset
   103
    canvas.drawString(0, 2.7*inch, "Translate then scale")
50f6c1be3e51 2nd try. more text
aaron_watters
parents: 275
diff changeset
   104
    coords(canvas)
50f6c1be3e51 2nd try. more text
aaron_watters
parents: 275
diff changeset
   105
"""
50f6c1be3e51 2nd try. more text
aaron_watters
parents: 275
diff changeset
   106
293
84a2635a8c30 typos and more examples
aaron_watters
parents: 283
diff changeset
   107
testmirror = """
84a2635a8c30 typos and more examples
aaron_watters
parents: 283
diff changeset
   108
def mirror(canvas):
84a2635a8c30 typos and more examples
aaron_watters
parents: 283
diff changeset
   109
    from reportlab.lib.units import inch
84a2635a8c30 typos and more examples
aaron_watters
parents: 283
diff changeset
   110
    canvas.translate(5.5*inch, 0)
84a2635a8c30 typos and more examples
aaron_watters
parents: 283
diff changeset
   111
    canvas.scale(-1.0, 1.0)
84a2635a8c30 typos and more examples
aaron_watters
parents: 283
diff changeset
   112
    coords(canvas)
84a2635a8c30 typos and more examples
aaron_watters
parents: 283
diff changeset
   113
"""
84a2635a8c30 typos and more examples
aaron_watters
parents: 283
diff changeset
   114
298
0e23c189f665 colors, line styles, more examples
aaron_watters
parents: 296
diff changeset
   115
testcolors = """
0e23c189f665 colors, line styles, more examples
aaron_watters
parents: 296
diff changeset
   116
def colors(canvas):
0e23c189f665 colors, line styles, more examples
aaron_watters
parents: 296
diff changeset
   117
    from reportlab.lib import colors
0e23c189f665 colors, line styles, more examples
aaron_watters
parents: 296
diff changeset
   118
    from reportlab.lib.units import inch
0e23c189f665 colors, line styles, more examples
aaron_watters
parents: 296
diff changeset
   119
    black = colors.black
364
21f5c8641230 more text, more pdfgen examples
aaron_watters
parents: 320
diff changeset
   120
    y = x = 0; dy=inch*3/4.0; dx=inch*5.5/5; w=h=dy/2; rdx=(dx-w)/2
21f5c8641230 more text, more pdfgen examples
aaron_watters
parents: 320
diff changeset
   121
    rdy=h/5.0; texty=h+2*rdy
298
0e23c189f665 colors, line styles, more examples
aaron_watters
parents: 296
diff changeset
   122
    canvas.setFont("Helvetica",10)
364
21f5c8641230 more text, more pdfgen examples
aaron_watters
parents: 320
diff changeset
   123
    for [namedcolor, name] in (
21f5c8641230 more text, more pdfgen examples
aaron_watters
parents: 320
diff changeset
   124
           [colors.lavenderblush, "lavenderblush"], 
21f5c8641230 more text, more pdfgen examples
aaron_watters
parents: 320
diff changeset
   125
           [colors.lawngreen, "lawngreen"],
21f5c8641230 more text, more pdfgen examples
aaron_watters
parents: 320
diff changeset
   126
           [colors.lemonchiffon, "lemonchiffon"],
21f5c8641230 more text, more pdfgen examples
aaron_watters
parents: 320
diff changeset
   127
           [colors.lightblue, "lightblue"],
21f5c8641230 more text, more pdfgen examples
aaron_watters
parents: 320
diff changeset
   128
           [colors.lightcoral, "lightcoral"]):
21f5c8641230 more text, more pdfgen examples
aaron_watters
parents: 320
diff changeset
   129
        canvas.setFillColor(namedcolor)
298
0e23c189f665 colors, line styles, more examples
aaron_watters
parents: 296
diff changeset
   130
        canvas.rect(x+rdx, y+rdy, w, h, fill=1)
0e23c189f665 colors, line styles, more examples
aaron_watters
parents: 296
diff changeset
   131
        canvas.setFillColor(black)
0e23c189f665 colors, line styles, more examples
aaron_watters
parents: 296
diff changeset
   132
        canvas.drawCentredString(x+dx/2, y+texty, name)
0e23c189f665 colors, line styles, more examples
aaron_watters
parents: 296
diff changeset
   133
        x = x+dx
0e23c189f665 colors, line styles, more examples
aaron_watters
parents: 296
diff changeset
   134
    y = y + dy; x = 0
364
21f5c8641230 more text, more pdfgen examples
aaron_watters
parents: 320
diff changeset
   135
    for rgb in [(1,0,0), (0,1,0), (0,0,1), (0.5,0.3,0.1), (0.4,0.5,0.3)]:
298
0e23c189f665 colors, line styles, more examples
aaron_watters
parents: 296
diff changeset
   136
        r,g,b = rgb
0e23c189f665 colors, line styles, more examples
aaron_watters
parents: 296
diff changeset
   137
        canvas.setFillColorRGB(r,g,b)
0e23c189f665 colors, line styles, more examples
aaron_watters
parents: 296
diff changeset
   138
        canvas.rect(x+rdx, y+rdy, w, h, fill=1)
0e23c189f665 colors, line styles, more examples
aaron_watters
parents: 296
diff changeset
   139
        canvas.setFillColor(black)
0e23c189f665 colors, line styles, more examples
aaron_watters
parents: 296
diff changeset
   140
        canvas.drawCentredString(x+dx/2, y+texty, "r%s g%s b%s"%rgb)
0e23c189f665 colors, line styles, more examples
aaron_watters
parents: 296
diff changeset
   141
        x = x+dx
0e23c189f665 colors, line styles, more examples
aaron_watters
parents: 296
diff changeset
   142
    y = y + dy; x = 0
301
5ad57f31ae75 added quickhack for font changes in paragraphs and lots of new text
aaron_watters
parents: 299
diff changeset
   143
    for cmyk in [(1,0,0,0), (0,1,0,0), (0,0,1,0), (0,0,0,1), (0,0,0,0)]:
298
0e23c189f665 colors, line styles, more examples
aaron_watters
parents: 296
diff changeset
   144
        c,m,y1,k = cmyk
0e23c189f665 colors, line styles, more examples
aaron_watters
parents: 296
diff changeset
   145
        canvas.setFillColorCMYK(c,m,y1,k)
0e23c189f665 colors, line styles, more examples
aaron_watters
parents: 296
diff changeset
   146
        canvas.rect(x+rdx, y+rdy, w, h, fill=1)
0e23c189f665 colors, line styles, more examples
aaron_watters
parents: 296
diff changeset
   147
        canvas.setFillColor(black)
0e23c189f665 colors, line styles, more examples
aaron_watters
parents: 296
diff changeset
   148
        canvas.drawCentredString(x+dx/2, y+texty, "c%s m%s y%s k%s"%cmyk)
0e23c189f665 colors, line styles, more examples
aaron_watters
parents: 296
diff changeset
   149
        x = x+dx
0e23c189f665 colors, line styles, more examples
aaron_watters
parents: 296
diff changeset
   150
    y = y + dy; x = 0
364
21f5c8641230 more text, more pdfgen examples
aaron_watters
parents: 320
diff changeset
   151
    for gray in (0.0, 0.25, 0.50, 0.75, 1.0):
298
0e23c189f665 colors, line styles, more examples
aaron_watters
parents: 296
diff changeset
   152
        canvas.setFillGray(gray)
0e23c189f665 colors, line styles, more examples
aaron_watters
parents: 296
diff changeset
   153
        canvas.rect(x+rdx, y+rdy, w, h, fill=1)
0e23c189f665 colors, line styles, more examples
aaron_watters
parents: 296
diff changeset
   154
        canvas.setFillColor(black)
0e23c189f665 colors, line styles, more examples
aaron_watters
parents: 296
diff changeset
   155
        canvas.drawCentredString(x+dx/2, y+texty, "gray: %s"%gray)
0e23c189f665 colors, line styles, more examples
aaron_watters
parents: 296
diff changeset
   156
        x = x+dx
0e23c189f665 colors, line styles, more examples
aaron_watters
parents: 296
diff changeset
   157
"""
0e23c189f665 colors, line styles, more examples
aaron_watters
parents: 296
diff changeset
   158
283
50f6c1be3e51 2nd try. more text
aaron_watters
parents: 275
diff changeset
   159
testspumoni = """
50f6c1be3e51 2nd try. more text
aaron_watters
parents: 275
diff changeset
   160
def spumoni(canvas):
50f6c1be3e51 2nd try. more text
aaron_watters
parents: 275
diff changeset
   161
    from reportlab.lib.units import inch
50f6c1be3e51 2nd try. more text
aaron_watters
parents: 275
diff changeset
   162
    from reportlab.lib.colors import pink, green, brown, white
50f6c1be3e51 2nd try. more text
aaron_watters
parents: 275
diff changeset
   163
    x = 0; dx = 0.4*inch
50f6c1be3e51 2nd try. more text
aaron_watters
parents: 275
diff changeset
   164
    for i in range(4):
50f6c1be3e51 2nd try. more text
aaron_watters
parents: 275
diff changeset
   165
        for color in (pink, green, brown):
50f6c1be3e51 2nd try. more text
aaron_watters
parents: 275
diff changeset
   166
            canvas.setFillColor(color)
50f6c1be3e51 2nd try. more text
aaron_watters
parents: 275
diff changeset
   167
            canvas.rect(x,0,dx,3*inch,stroke=0,fill=1)
50f6c1be3e51 2nd try. more text
aaron_watters
parents: 275
diff changeset
   168
            x = x+dx
50f6c1be3e51 2nd try. more text
aaron_watters
parents: 275
diff changeset
   169
    canvas.setFillColor(white)
50f6c1be3e51 2nd try. more text
aaron_watters
parents: 275
diff changeset
   170
    canvas.setStrokeColor(white)
50f6c1be3e51 2nd try. more text
aaron_watters
parents: 275
diff changeset
   171
    canvas.setFont("Helvetica-Bold", 85)
50f6c1be3e51 2nd try. more text
aaron_watters
parents: 275
diff changeset
   172
    canvas.drawCentredString(2.75*inch, 1.3*inch, "SPUMONI")
50f6c1be3e51 2nd try. more text
aaron_watters
parents: 275
diff changeset
   173
"""
50f6c1be3e51 2nd try. more text
aaron_watters
parents: 275
diff changeset
   174
50f6c1be3e51 2nd try. more text
aaron_watters
parents: 275
diff changeset
   175
testspumoni2 = """
50f6c1be3e51 2nd try. more text
aaron_watters
parents: 275
diff changeset
   176
def spumoni2(canvas):
50f6c1be3e51 2nd try. more text
aaron_watters
parents: 275
diff changeset
   177
    from reportlab.lib.units import inch
50f6c1be3e51 2nd try. more text
aaron_watters
parents: 275
diff changeset
   178
    from reportlab.lib.colors import pink, green, brown, white, black
50f6c1be3e51 2nd try. more text
aaron_watters
parents: 275
diff changeset
   179
    # draw the previous drawing
50f6c1be3e51 2nd try. more text
aaron_watters
parents: 275
diff changeset
   180
    spumoni(canvas)
50f6c1be3e51 2nd try. more text
aaron_watters
parents: 275
diff changeset
   181
    # now put an ice cream cone on top of it:
50f6c1be3e51 2nd try. more text
aaron_watters
parents: 275
diff changeset
   182
    # first draw a triangle (ice cream cone)
50f6c1be3e51 2nd try. more text
aaron_watters
parents: 275
diff changeset
   183
    p = canvas.beginPath()
50f6c1be3e51 2nd try. more text
aaron_watters
parents: 275
diff changeset
   184
    xcenter = 2.75*inch
50f6c1be3e51 2nd try. more text
aaron_watters
parents: 275
diff changeset
   185
    radius = 0.45*inch
50f6c1be3e51 2nd try. more text
aaron_watters
parents: 275
diff changeset
   186
    p.moveTo(xcenter-radius, 1.5*inch)
50f6c1be3e51 2nd try. more text
aaron_watters
parents: 275
diff changeset
   187
    p.lineTo(xcenter+radius, 1.5*inch)
50f6c1be3e51 2nd try. more text
aaron_watters
parents: 275
diff changeset
   188
    p.lineTo(xcenter, 0)
50f6c1be3e51 2nd try. more text
aaron_watters
parents: 275
diff changeset
   189
    canvas.setFillColor(brown)
50f6c1be3e51 2nd try. more text
aaron_watters
parents: 275
diff changeset
   190
    canvas.setStrokeColor(black)
50f6c1be3e51 2nd try. more text
aaron_watters
parents: 275
diff changeset
   191
    canvas.drawPath(p, fill=1)
50f6c1be3e51 2nd try. more text
aaron_watters
parents: 275
diff changeset
   192
    # draw some circles (scoops)
50f6c1be3e51 2nd try. more text
aaron_watters
parents: 275
diff changeset
   193
    y = 1.5*inch
50f6c1be3e51 2nd try. more text
aaron_watters
parents: 275
diff changeset
   194
    for color in (pink, green, brown):
50f6c1be3e51 2nd try. more text
aaron_watters
parents: 275
diff changeset
   195
        canvas.setFillColor(color)
50f6c1be3e51 2nd try. more text
aaron_watters
parents: 275
diff changeset
   196
        canvas.circle(xcenter, y, radius, fill=1)
50f6c1be3e51 2nd try. more text
aaron_watters
parents: 275
diff changeset
   197
        y = y+radius
50f6c1be3e51 2nd try. more text
aaron_watters
parents: 275
diff changeset
   198
"""
50f6c1be3e51 2nd try. more text
aaron_watters
parents: 275
diff changeset
   199
293
84a2635a8c30 typos and more examples
aaron_watters
parents: 283
diff changeset
   200
testbezier = """
84a2635a8c30 typos and more examples
aaron_watters
parents: 283
diff changeset
   201
def bezier(canvas):
84a2635a8c30 typos and more examples
aaron_watters
parents: 283
diff changeset
   202
    from reportlab.lib.colors import yellow, green, red, black
84a2635a8c30 typos and more examples
aaron_watters
parents: 283
diff changeset
   203
    from reportlab.lib.units import inch
84a2635a8c30 typos and more examples
aaron_watters
parents: 283
diff changeset
   204
    i = inch
84a2635a8c30 typos and more examples
aaron_watters
parents: 283
diff changeset
   205
    d = i/4
84a2635a8c30 typos and more examples
aaron_watters
parents: 283
diff changeset
   206
    # define the bezier curve control points
84a2635a8c30 typos and more examples
aaron_watters
parents: 283
diff changeset
   207
    x1,y1, x2,y2, x3,y3, x4,y4 = d,1.5*i, 1.5*i,d, 3*i,d, 5.5*i-d,3*i-d
84a2635a8c30 typos and more examples
aaron_watters
parents: 283
diff changeset
   208
    # draw a figure enclosing the control points
84a2635a8c30 typos and more examples
aaron_watters
parents: 283
diff changeset
   209
    canvas.setFillColor(yellow)
84a2635a8c30 typos and more examples
aaron_watters
parents: 283
diff changeset
   210
    p = canvas.beginPath()
84a2635a8c30 typos and more examples
aaron_watters
parents: 283
diff changeset
   211
    p.moveTo(x1,y1)
84a2635a8c30 typos and more examples
aaron_watters
parents: 283
diff changeset
   212
    for (x,y) in [(x2,y2), (x3,y3), (x4,y4)]:
84a2635a8c30 typos and more examples
aaron_watters
parents: 283
diff changeset
   213
        p.lineTo(x,y)
84a2635a8c30 typos and more examples
aaron_watters
parents: 283
diff changeset
   214
    canvas.drawPath(p, fill=1, stroke=0)
84a2635a8c30 typos and more examples
aaron_watters
parents: 283
diff changeset
   215
    # draw the tangent lines
84a2635a8c30 typos and more examples
aaron_watters
parents: 283
diff changeset
   216
    canvas.setLineWidth(inch*0.1)
84a2635a8c30 typos and more examples
aaron_watters
parents: 283
diff changeset
   217
    canvas.setStrokeColor(green)
84a2635a8c30 typos and more examples
aaron_watters
parents: 283
diff changeset
   218
    canvas.line(x1,y1,x2,y2)
84a2635a8c30 typos and more examples
aaron_watters
parents: 283
diff changeset
   219
    canvas.setStrokeColor(red)
84a2635a8c30 typos and more examples
aaron_watters
parents: 283
diff changeset
   220
    canvas.line(x3,y3,x4,y4)
84a2635a8c30 typos and more examples
aaron_watters
parents: 283
diff changeset
   221
    # finally draw the curve
84a2635a8c30 typos and more examples
aaron_watters
parents: 283
diff changeset
   222
    canvas.setStrokeColor(black)
84a2635a8c30 typos and more examples
aaron_watters
parents: 283
diff changeset
   223
    canvas.bezier(x1,y1, x2,y2, x3,y3, x4,y4)
84a2635a8c30 typos and more examples
aaron_watters
parents: 283
diff changeset
   224
"""
84a2635a8c30 typos and more examples
aaron_watters
parents: 283
diff changeset
   225
84a2635a8c30 typos and more examples
aaron_watters
parents: 283
diff changeset
   226
testbezier2 = """
84a2635a8c30 typos and more examples
aaron_watters
parents: 283
diff changeset
   227
def bezier2(canvas):
84a2635a8c30 typos and more examples
aaron_watters
parents: 283
diff changeset
   228
    from reportlab.lib.colors import yellow, green, red, black
84a2635a8c30 typos and more examples
aaron_watters
parents: 283
diff changeset
   229
    from reportlab.lib.units import inch
84a2635a8c30 typos and more examples
aaron_watters
parents: 283
diff changeset
   230
    # make a sequence of control points
84a2635a8c30 typos and more examples
aaron_watters
parents: 283
diff changeset
   231
    xd,yd = 5.5*inch/2, 3*inch/2
84a2635a8c30 typos and more examples
aaron_watters
parents: 283
diff changeset
   232
    xc,yc = xd,yd
84a2635a8c30 typos and more examples
aaron_watters
parents: 283
diff changeset
   233
    dxdy = [(0,0.33), (0.33,0.33), (0.75,1), (0.875,0.875), 
84a2635a8c30 typos and more examples
aaron_watters
parents: 283
diff changeset
   234
            (0.875,0.875), (1,0.75), (0.33,0.33), (0.33,0)]
84a2635a8c30 typos and more examples
aaron_watters
parents: 283
diff changeset
   235
    pointlist = []
84a2635a8c30 typos and more examples
aaron_watters
parents: 283
diff changeset
   236
    for xoffset in (1,-1):
84a2635a8c30 typos and more examples
aaron_watters
parents: 283
diff changeset
   237
        yoffset = xoffset
84a2635a8c30 typos and more examples
aaron_watters
parents: 283
diff changeset
   238
        for (dx,dy) in dxdy:
84a2635a8c30 typos and more examples
aaron_watters
parents: 283
diff changeset
   239
            px = xc + xd*xoffset*dx
84a2635a8c30 typos and more examples
aaron_watters
parents: 283
diff changeset
   240
            py = yc + yd*yoffset*dy
84a2635a8c30 typos and more examples
aaron_watters
parents: 283
diff changeset
   241
            pointlist.append((px,py))
84a2635a8c30 typos and more examples
aaron_watters
parents: 283
diff changeset
   242
        yoffset = -xoffset
84a2635a8c30 typos and more examples
aaron_watters
parents: 283
diff changeset
   243
        for (dy,dx) in dxdy:
84a2635a8c30 typos and more examples
aaron_watters
parents: 283
diff changeset
   244
            px = xc + xd*xoffset*dx
84a2635a8c30 typos and more examples
aaron_watters
parents: 283
diff changeset
   245
            py = yc + yd*yoffset*dy
84a2635a8c30 typos and more examples
aaron_watters
parents: 283
diff changeset
   246
            pointlist.append((px,py))
84a2635a8c30 typos and more examples
aaron_watters
parents: 283
diff changeset
   247
    # draw tangent lines and curves
84a2635a8c30 typos and more examples
aaron_watters
parents: 283
diff changeset
   248
    canvas.setLineWidth(inch*0.1)
84a2635a8c30 typos and more examples
aaron_watters
parents: 283
diff changeset
   249
    while pointlist:
84a2635a8c30 typos and more examples
aaron_watters
parents: 283
diff changeset
   250
        [(x1,y1),(x2,y2),(x3,y3),(x4,y4)] = pointlist[:4]
84a2635a8c30 typos and more examples
aaron_watters
parents: 283
diff changeset
   251
        del pointlist[:4]
84a2635a8c30 typos and more examples
aaron_watters
parents: 283
diff changeset
   252
        canvas.setLineWidth(inch*0.1)
84a2635a8c30 typos and more examples
aaron_watters
parents: 283
diff changeset
   253
        canvas.setStrokeColor(green)
84a2635a8c30 typos and more examples
aaron_watters
parents: 283
diff changeset
   254
        canvas.line(x1,y1,x2,y2)
84a2635a8c30 typos and more examples
aaron_watters
parents: 283
diff changeset
   255
        canvas.setStrokeColor(red)
84a2635a8c30 typos and more examples
aaron_watters
parents: 283
diff changeset
   256
        canvas.line(x3,y3,x4,y4)
84a2635a8c30 typos and more examples
aaron_watters
parents: 283
diff changeset
   257
        # finally draw the curve
84a2635a8c30 typos and more examples
aaron_watters
parents: 283
diff changeset
   258
        canvas.setStrokeColor(black)
84a2635a8c30 typos and more examples
aaron_watters
parents: 283
diff changeset
   259
        canvas.bezier(x1,y1, x2,y2, x3,y3, x4,y4)
84a2635a8c30 typos and more examples
aaron_watters
parents: 283
diff changeset
   260
"""
84a2635a8c30 typos and more examples
aaron_watters
parents: 283
diff changeset
   261
296
a5e584b6d61b Lots of graphical examples added
aaron_watters
parents: 293
diff changeset
   262
testpencil = """
a5e584b6d61b Lots of graphical examples added
aaron_watters
parents: 293
diff changeset
   263
def pencil(canvas, text="No.2"):
a5e584b6d61b Lots of graphical examples added
aaron_watters
parents: 293
diff changeset
   264
    from reportlab.lib.colors import yellow, red, black,white
a5e584b6d61b Lots of graphical examples added
aaron_watters
parents: 293
diff changeset
   265
    from reportlab.lib.units import inch
a5e584b6d61b Lots of graphical examples added
aaron_watters
parents: 293
diff changeset
   266
    u = inch/10.0
a5e584b6d61b Lots of graphical examples added
aaron_watters
parents: 293
diff changeset
   267
    canvas.setStrokeColor(black)
a5e584b6d61b Lots of graphical examples added
aaron_watters
parents: 293
diff changeset
   268
    canvas.setLineWidth(4)
a5e584b6d61b Lots of graphical examples added
aaron_watters
parents: 293
diff changeset
   269
    # draw erasor
a5e584b6d61b Lots of graphical examples added
aaron_watters
parents: 293
diff changeset
   270
    canvas.setFillColor(red)
a5e584b6d61b Lots of graphical examples added
aaron_watters
parents: 293
diff changeset
   271
    canvas.circle(30*u, 5*u, 5*u, stroke=1, fill=1)
a5e584b6d61b Lots of graphical examples added
aaron_watters
parents: 293
diff changeset
   272
    # draw all else but the tip (mainly rectangles with different fills)
a5e584b6d61b Lots of graphical examples added
aaron_watters
parents: 293
diff changeset
   273
    canvas.setFillColor(yellow)
a5e584b6d61b Lots of graphical examples added
aaron_watters
parents: 293
diff changeset
   274
    canvas.rect(10*u,0,20*u,10*u, stroke=1, fill=1)
a5e584b6d61b Lots of graphical examples added
aaron_watters
parents: 293
diff changeset
   275
    canvas.setFillColor(black)
a5e584b6d61b Lots of graphical examples added
aaron_watters
parents: 293
diff changeset
   276
    canvas.rect(23*u,0,8*u,10*u,fill=1)
a5e584b6d61b Lots of graphical examples added
aaron_watters
parents: 293
diff changeset
   277
    canvas.roundRect(14*u, 3.5*u, 8*u, 3*u, 1.5*u, stroke=1, fill=1)
a5e584b6d61b Lots of graphical examples added
aaron_watters
parents: 293
diff changeset
   278
    canvas.setFillColor(white)
a5e584b6d61b Lots of graphical examples added
aaron_watters
parents: 293
diff changeset
   279
    canvas.rect(25*u,u,1.2*u,8*u, fill=1,stroke=0)
a5e584b6d61b Lots of graphical examples added
aaron_watters
parents: 293
diff changeset
   280
    canvas.rect(27.5*u,u,1.2*u,8*u, fill=1, stroke=0)
a5e584b6d61b Lots of graphical examples added
aaron_watters
parents: 293
diff changeset
   281
    canvas.setFont("Times-Roman", 3*u)
a5e584b6d61b Lots of graphical examples added
aaron_watters
parents: 293
diff changeset
   282
    canvas.drawCentredString(18*u, 4*u, text)
a5e584b6d61b Lots of graphical examples added
aaron_watters
parents: 293
diff changeset
   283
    # now draw the tip
a5e584b6d61b Lots of graphical examples added
aaron_watters
parents: 293
diff changeset
   284
    penciltip(canvas,debug=0)
a5e584b6d61b Lots of graphical examples added
aaron_watters
parents: 293
diff changeset
   285
    # draw broken lines across the body.
a5e584b6d61b Lots of graphical examples added
aaron_watters
parents: 293
diff changeset
   286
    canvas.setDash([10,5,16,10],0)
a5e584b6d61b Lots of graphical examples added
aaron_watters
parents: 293
diff changeset
   287
    canvas.line(11*u,2.5*u,22*u,2.5*u)
a5e584b6d61b Lots of graphical examples added
aaron_watters
parents: 293
diff changeset
   288
    canvas.line(22*u,7.5*u,12*u,7.5*u)
a5e584b6d61b Lots of graphical examples added
aaron_watters
parents: 293
diff changeset
   289
    """
a5e584b6d61b Lots of graphical examples added
aaron_watters
parents: 293
diff changeset
   290
    
a5e584b6d61b Lots of graphical examples added
aaron_watters
parents: 293
diff changeset
   291
testpenciltip = """
a5e584b6d61b Lots of graphical examples added
aaron_watters
parents: 293
diff changeset
   292
def penciltip(canvas, debug=1):
a5e584b6d61b Lots of graphical examples added
aaron_watters
parents: 293
diff changeset
   293
    from reportlab.lib.colors import tan, black, green
a5e584b6d61b Lots of graphical examples added
aaron_watters
parents: 293
diff changeset
   294
    from reportlab.lib.units import inch
a5e584b6d61b Lots of graphical examples added
aaron_watters
parents: 293
diff changeset
   295
    u = inch/10.0
a5e584b6d61b Lots of graphical examples added
aaron_watters
parents: 293
diff changeset
   296
    canvas.setLineWidth(4)
a5e584b6d61b Lots of graphical examples added
aaron_watters
parents: 293
diff changeset
   297
    if debug:
a5e584b6d61b Lots of graphical examples added
aaron_watters
parents: 293
diff changeset
   298
        canvas.scale(2.8,2.8) # make it big
a5e584b6d61b Lots of graphical examples added
aaron_watters
parents: 293
diff changeset
   299
        canvas.setLineWidth(1) # small lines
a5e584b6d61b Lots of graphical examples added
aaron_watters
parents: 293
diff changeset
   300
    canvas.setStrokeColor(black)
a5e584b6d61b Lots of graphical examples added
aaron_watters
parents: 293
diff changeset
   301
    canvas.setFillColor(tan)
a5e584b6d61b Lots of graphical examples added
aaron_watters
parents: 293
diff changeset
   302
    p = canvas.beginPath()
a5e584b6d61b Lots of graphical examples added
aaron_watters
parents: 293
diff changeset
   303
    p.moveTo(10*u,0)
a5e584b6d61b Lots of graphical examples added
aaron_watters
parents: 293
diff changeset
   304
    p.lineTo(0,5*u)
a5e584b6d61b Lots of graphical examples added
aaron_watters
parents: 293
diff changeset
   305
    p.lineTo(10*u,10*u)
a5e584b6d61b Lots of graphical examples added
aaron_watters
parents: 293
diff changeset
   306
    p.curveTo(11.5*u,10*u, 11.5*u,7.5*u, 10*u,7.5*u)
a5e584b6d61b Lots of graphical examples added
aaron_watters
parents: 293
diff changeset
   307
    p.curveTo(12*u,7.5*u, 11*u,2.5*u, 9.7*u,2.5*u)
a5e584b6d61b Lots of graphical examples added
aaron_watters
parents: 293
diff changeset
   308
    p.curveTo(10.5*u,2.5*u, 11*u,0, 10*u,0)
a5e584b6d61b Lots of graphical examples added
aaron_watters
parents: 293
diff changeset
   309
    canvas.drawPath(p, stroke=1, fill=1)
a5e584b6d61b Lots of graphical examples added
aaron_watters
parents: 293
diff changeset
   310
    canvas.setFillColor(black)
a5e584b6d61b Lots of graphical examples added
aaron_watters
parents: 293
diff changeset
   311
    p = canvas.beginPath()
a5e584b6d61b Lots of graphical examples added
aaron_watters
parents: 293
diff changeset
   312
    p.moveTo(0,5*u)
a5e584b6d61b Lots of graphical examples added
aaron_watters
parents: 293
diff changeset
   313
    p.lineTo(4*u,3*u)
a5e584b6d61b Lots of graphical examples added
aaron_watters
parents: 293
diff changeset
   314
    p.lineTo(5*u,4.5*u)
a5e584b6d61b Lots of graphical examples added
aaron_watters
parents: 293
diff changeset
   315
    p.lineTo(3*u,6.5*u)
a5e584b6d61b Lots of graphical examples added
aaron_watters
parents: 293
diff changeset
   316
    canvas.drawPath(p, stroke=1, fill=1)
a5e584b6d61b Lots of graphical examples added
aaron_watters
parents: 293
diff changeset
   317
    if debug:
a5e584b6d61b Lots of graphical examples added
aaron_watters
parents: 293
diff changeset
   318
        canvas.setStrokeColor(green) # put in a frame of reference
a5e584b6d61b Lots of graphical examples added
aaron_watters
parents: 293
diff changeset
   319
        canvas.grid([0,5*u,10*u,15*u], [0,5*u,10*u])
a5e584b6d61b Lots of graphical examples added
aaron_watters
parents: 293
diff changeset
   320
"""
a5e584b6d61b Lots of graphical examples added
aaron_watters
parents: 293
diff changeset
   321
a5e584b6d61b Lots of graphical examples added
aaron_watters
parents: 293
diff changeset
   322
testnoteannotation = """
a5e584b6d61b Lots of graphical examples added
aaron_watters
parents: 293
diff changeset
   323
from reportlab.platypus.flowables import Flowable
a5e584b6d61b Lots of graphical examples added
aaron_watters
parents: 293
diff changeset
   324
class NoteAnnotation(Flowable):
a5e584b6d61b Lots of graphical examples added
aaron_watters
parents: 293
diff changeset
   325
    '''put a pencil in the margin.'''
a5e584b6d61b Lots of graphical examples added
aaron_watters
parents: 293
diff changeset
   326
    def wrap(self, *args):
a5e584b6d61b Lots of graphical examples added
aaron_watters
parents: 293
diff changeset
   327
        return (1,10) # I take up very little space! (?)
a5e584b6d61b Lots of graphical examples added
aaron_watters
parents: 293
diff changeset
   328
    def draw(self):
a5e584b6d61b Lots of graphical examples added
aaron_watters
parents: 293
diff changeset
   329
        canvas = self.canv
a5e584b6d61b Lots of graphical examples added
aaron_watters
parents: 293
diff changeset
   330
        canvas.translate(-10,-10)
a5e584b6d61b Lots of graphical examples added
aaron_watters
parents: 293
diff changeset
   331
        canvas.rotate(180)
a5e584b6d61b Lots of graphical examples added
aaron_watters
parents: 293
diff changeset
   332
        canvas.scale(0.2,0.2)
a5e584b6d61b Lots of graphical examples added
aaron_watters
parents: 293
diff changeset
   333
        pencil(canvas, text="NOTE")
a5e584b6d61b Lots of graphical examples added
aaron_watters
parents: 293
diff changeset
   334
"""
a5e584b6d61b Lots of graphical examples added
aaron_watters
parents: 293
diff changeset
   335
381
2ca856765ed1 various mods
aaron_watters
parents: 375
diff changeset
   336
testhandannotation = """
2ca856765ed1 various mods
aaron_watters
parents: 375
diff changeset
   337
from reportlab.platypus.flowables import Flowable
2ca856765ed1 various mods
aaron_watters
parents: 375
diff changeset
   338
from reportlab.lib.colors import tan, green
2ca856765ed1 various mods
aaron_watters
parents: 375
diff changeset
   339
class HandAnnotation(Flowable):
2ca856765ed1 various mods
aaron_watters
parents: 375
diff changeset
   340
    '''A hand flowable.'''
2ca856765ed1 various mods
aaron_watters
parents: 375
diff changeset
   341
    def __init__(self, xoffset=0, size=None, fillcolor=tan, strokecolor=green):
2ca856765ed1 various mods
aaron_watters
parents: 375
diff changeset
   342
        from reportlab.lib.units import inch
2ca856765ed1 various mods
aaron_watters
parents: 375
diff changeset
   343
        if size is None: size=4*inch
2ca856765ed1 various mods
aaron_watters
parents: 375
diff changeset
   344
        self.fillcolor, self.strokecolor = fillcolor, strokecolor
2ca856765ed1 various mods
aaron_watters
parents: 375
diff changeset
   345
        self.xoffset = xoffset
2ca856765ed1 various mods
aaron_watters
parents: 375
diff changeset
   346
        self.size = size
2ca856765ed1 various mods
aaron_watters
parents: 375
diff changeset
   347
        # normal size is 4 inches
2ca856765ed1 various mods
aaron_watters
parents: 375
diff changeset
   348
        self.scale = size/(4.0*inch)
2ca856765ed1 various mods
aaron_watters
parents: 375
diff changeset
   349
    def wrap(self, *args):
2ca856765ed1 various mods
aaron_watters
parents: 375
diff changeset
   350
        return (self.xoffset, self.size)
2ca856765ed1 various mods
aaron_watters
parents: 375
diff changeset
   351
    def draw(self):
2ca856765ed1 various mods
aaron_watters
parents: 375
diff changeset
   352
        canvas = self.canv
2ca856765ed1 various mods
aaron_watters
parents: 375
diff changeset
   353
        canvas.setLineWidth(6)
2ca856765ed1 various mods
aaron_watters
parents: 375
diff changeset
   354
        canvas.setFillColor(self.fillcolor)
2ca856765ed1 various mods
aaron_watters
parents: 375
diff changeset
   355
        canvas.setStrokeColor(self.strokecolor)
2ca856765ed1 various mods
aaron_watters
parents: 375
diff changeset
   356
        canvas.translate(self.xoffset+self.size,0)
2ca856765ed1 various mods
aaron_watters
parents: 375
diff changeset
   357
        canvas.rotate(90)
2ca856765ed1 various mods
aaron_watters
parents: 375
diff changeset
   358
        canvas.scale(self.scale, self.scale)
2ca856765ed1 various mods
aaron_watters
parents: 375
diff changeset
   359
        hand(canvas, debug=0, fill=1)
2ca856765ed1 various mods
aaron_watters
parents: 375
diff changeset
   360
"""
2ca856765ed1 various mods
aaron_watters
parents: 375
diff changeset
   361
298
0e23c189f665 colors, line styles, more examples
aaron_watters
parents: 296
diff changeset
   362
lyrics = '''\
0e23c189f665 colors, line styles, more examples
aaron_watters
parents: 296
diff changeset
   363
well she hit Net Solutions 
0e23c189f665 colors, line styles, more examples
aaron_watters
parents: 296
diff changeset
   364
and she registered her own .com site now
0e23c189f665 colors, line styles, more examples
aaron_watters
parents: 296
diff changeset
   365
and filled it up with yahoo profile pics 
0e23c189f665 colors, line styles, more examples
aaron_watters
parents: 296
diff changeset
   366
she snarfed in one night now
317
fce6dad947c3 Pushed down most existing lessons one level; added
andy_robinson
parents: 308
diff changeset
   367
and she made 50 million when Hugh Hefner
298
0e23c189f665 colors, line styles, more examples
aaron_watters
parents: 296
diff changeset
   368
bought up the rights now
0e23c189f665 colors, line styles, more examples
aaron_watters
parents: 296
diff changeset
   369
and she'll have fun fun fun
0e23c189f665 colors, line styles, more examples
aaron_watters
parents: 296
diff changeset
   370
til her Daddy takes the keyboard away'''
296
a5e584b6d61b Lots of graphical examples added
aaron_watters
parents: 293
diff changeset
   371
298
0e23c189f665 colors, line styles, more examples
aaron_watters
parents: 296
diff changeset
   372
lyrics = string.split(lyrics, "\n")
0e23c189f665 colors, line styles, more examples
aaron_watters
parents: 296
diff changeset
   373
testtextsize = """
0e23c189f665 colors, line styles, more examples
aaron_watters
parents: 296
diff changeset
   374
def textsize(canvas):
0e23c189f665 colors, line styles, more examples
aaron_watters
parents: 296
diff changeset
   375
    from reportlab.lib.units import inch
0e23c189f665 colors, line styles, more examples
aaron_watters
parents: 296
diff changeset
   376
    from reportlab.lib.colors import magenta, red
0e23c189f665 colors, line styles, more examples
aaron_watters
parents: 296
diff changeset
   377
    canvas.setFont("Times-Roman", 20)
0e23c189f665 colors, line styles, more examples
aaron_watters
parents: 296
diff changeset
   378
    canvas.setFillColor(red)
299
909b83ce750c textobject and pathobject methods, among other things
aaron_watters
parents: 298
diff changeset
   379
    canvas.drawCentredString(2.75*inch, 2.5*inch, "Font size examples")
298
0e23c189f665 colors, line styles, more examples
aaron_watters
parents: 296
diff changeset
   380
    canvas.setFillColor(magenta)
0e23c189f665 colors, line styles, more examples
aaron_watters
parents: 296
diff changeset
   381
    size = 7
0e23c189f665 colors, line styles, more examples
aaron_watters
parents: 296
diff changeset
   382
    y = 2.3*inch
0e23c189f665 colors, line styles, more examples
aaron_watters
parents: 296
diff changeset
   383
    x = 1.3*inch
0e23c189f665 colors, line styles, more examples
aaron_watters
parents: 296
diff changeset
   384
    for line in lyrics:
0e23c189f665 colors, line styles, more examples
aaron_watters
parents: 296
diff changeset
   385
        canvas.setFont("Helvetica", size)
0e23c189f665 colors, line styles, more examples
aaron_watters
parents: 296
diff changeset
   386
        canvas.drawRightString(x,y,"%s points: " % size)
0e23c189f665 colors, line styles, more examples
aaron_watters
parents: 296
diff changeset
   387
        canvas.drawString(x,y, line)
299
909b83ce750c textobject and pathobject methods, among other things
aaron_watters
parents: 298
diff changeset
   388
        y = y-size*1.2
298
0e23c189f665 colors, line styles, more examples
aaron_watters
parents: 296
diff changeset
   389
        size = size+1.5
0e23c189f665 colors, line styles, more examples
aaron_watters
parents: 296
diff changeset
   390
"""
0e23c189f665 colors, line styles, more examples
aaron_watters
parents: 296
diff changeset
   391
0e23c189f665 colors, line styles, more examples
aaron_watters
parents: 296
diff changeset
   392
teststar = """
364
21f5c8641230 more text, more pdfgen examples
aaron_watters
parents: 320
diff changeset
   393
def star(canvas, title="Title Here", aka="Comment here.", 
21f5c8641230 more text, more pdfgen examples
aaron_watters
parents: 320
diff changeset
   394
         xcenter=None, ycenter=None, nvertices=5):
298
0e23c189f665 colors, line styles, more examples
aaron_watters
parents: 296
diff changeset
   395
    from math import pi
0e23c189f665 colors, line styles, more examples
aaron_watters
parents: 296
diff changeset
   396
    from reportlab.lib.units import inch
0e23c189f665 colors, line styles, more examples
aaron_watters
parents: 296
diff changeset
   397
    radius=inch/3.0
0e23c189f665 colors, line styles, more examples
aaron_watters
parents: 296
diff changeset
   398
    if xcenter is None: xcenter=2.75*inch
0e23c189f665 colors, line styles, more examples
aaron_watters
parents: 296
diff changeset
   399
    if ycenter is None: ycenter=1.5*inch
0e23c189f665 colors, line styles, more examples
aaron_watters
parents: 296
diff changeset
   400
    canvas.drawCentredString(xcenter, ycenter+1.3*radius, title)
0e23c189f665 colors, line styles, more examples
aaron_watters
parents: 296
diff changeset
   401
    canvas.drawCentredString(xcenter, ycenter-1.4*radius, aka)
0e23c189f665 colors, line styles, more examples
aaron_watters
parents: 296
diff changeset
   402
    p = canvas.beginPath()
0e23c189f665 colors, line styles, more examples
aaron_watters
parents: 296
diff changeset
   403
    p.moveTo(xcenter,ycenter+radius)
0e23c189f665 colors, line styles, more examples
aaron_watters
parents: 296
diff changeset
   404
    from math import pi, cos, sin
0e23c189f665 colors, line styles, more examples
aaron_watters
parents: 296
diff changeset
   405
    angle = (2*pi)*2/5.0
0e23c189f665 colors, line styles, more examples
aaron_watters
parents: 296
diff changeset
   406
    startangle = pi/2.0
0e23c189f665 colors, line styles, more examples
aaron_watters
parents: 296
diff changeset
   407
    for vertex in range(nvertices-1):
0e23c189f665 colors, line styles, more examples
aaron_watters
parents: 296
diff changeset
   408
        nextangle = angle*(vertex+1)+startangle
0e23c189f665 colors, line styles, more examples
aaron_watters
parents: 296
diff changeset
   409
        x = xcenter + radius*cos(nextangle)
0e23c189f665 colors, line styles, more examples
aaron_watters
parents: 296
diff changeset
   410
        y = ycenter + radius*sin(nextangle)
0e23c189f665 colors, line styles, more examples
aaron_watters
parents: 296
diff changeset
   411
        p.lineTo(x,y)
0e23c189f665 colors, line styles, more examples
aaron_watters
parents: 296
diff changeset
   412
    if nvertices==5:
0e23c189f665 colors, line styles, more examples
aaron_watters
parents: 296
diff changeset
   413
       p.close()
0e23c189f665 colors, line styles, more examples
aaron_watters
parents: 296
diff changeset
   414
    canvas.drawPath(p)
0e23c189f665 colors, line styles, more examples
aaron_watters
parents: 296
diff changeset
   415
"""
0e23c189f665 colors, line styles, more examples
aaron_watters
parents: 296
diff changeset
   416
0e23c189f665 colors, line styles, more examples
aaron_watters
parents: 296
diff changeset
   417
testjoins = """
0e23c189f665 colors, line styles, more examples
aaron_watters
parents: 296
diff changeset
   418
def joins(canvas):
0e23c189f665 colors, line styles, more examples
aaron_watters
parents: 296
diff changeset
   419
    from reportlab.lib.units import inch
0e23c189f665 colors, line styles, more examples
aaron_watters
parents: 296
diff changeset
   420
    # make lines big
0e23c189f665 colors, line styles, more examples
aaron_watters
parents: 296
diff changeset
   421
    canvas.setLineWidth(5)
0e23c189f665 colors, line styles, more examples
aaron_watters
parents: 296
diff changeset
   422
    star(canvas, "Default: mitered join", "0: pointed", xcenter = 1*inch)
0e23c189f665 colors, line styles, more examples
aaron_watters
parents: 296
diff changeset
   423
    canvas.setLineJoin(1)
0e23c189f665 colors, line styles, more examples
aaron_watters
parents: 296
diff changeset
   424
    star(canvas, "Round join", "1: rounded")
0e23c189f665 colors, line styles, more examples
aaron_watters
parents: 296
diff changeset
   425
    canvas.setLineJoin(2)
0e23c189f665 colors, line styles, more examples
aaron_watters
parents: 296
diff changeset
   426
    star(canvas, "Bevelled join", "2: square", xcenter=4.5*inch)
0e23c189f665 colors, line styles, more examples
aaron_watters
parents: 296
diff changeset
   427
"""
0e23c189f665 colors, line styles, more examples
aaron_watters
parents: 296
diff changeset
   428
0e23c189f665 colors, line styles, more examples
aaron_watters
parents: 296
diff changeset
   429
testcaps = """
0e23c189f665 colors, line styles, more examples
aaron_watters
parents: 296
diff changeset
   430
def caps(canvas):
0e23c189f665 colors, line styles, more examples
aaron_watters
parents: 296
diff changeset
   431
    from reportlab.lib.units import inch
0e23c189f665 colors, line styles, more examples
aaron_watters
parents: 296
diff changeset
   432
    # make lines big
0e23c189f665 colors, line styles, more examples
aaron_watters
parents: 296
diff changeset
   433
    canvas.setLineWidth(5)
0e23c189f665 colors, line styles, more examples
aaron_watters
parents: 296
diff changeset
   434
    star(canvas, "Default", "no projection",xcenter = 1*inch,
0e23c189f665 colors, line styles, more examples
aaron_watters
parents: 296
diff changeset
   435
         nvertices=4)
0e23c189f665 colors, line styles, more examples
aaron_watters
parents: 296
diff changeset
   436
    canvas.setLineCap(1)
0e23c189f665 colors, line styles, more examples
aaron_watters
parents: 296
diff changeset
   437
    star(canvas, "Round cap", "1: ends in half circle", nvertices=4)
0e23c189f665 colors, line styles, more examples
aaron_watters
parents: 296
diff changeset
   438
    canvas.setLineCap(2)
0e23c189f665 colors, line styles, more examples
aaron_watters
parents: 296
diff changeset
   439
    star(canvas, "Square cap", "2: projects out half a width", xcenter=4.5*inch,
0e23c189f665 colors, line styles, more examples
aaron_watters
parents: 296
diff changeset
   440
       nvertices=4)
0e23c189f665 colors, line styles, more examples
aaron_watters
parents: 296
diff changeset
   441
"""
0e23c189f665 colors, line styles, more examples
aaron_watters
parents: 296
diff changeset
   442
0e23c189f665 colors, line styles, more examples
aaron_watters
parents: 296
diff changeset
   443
testdashes = """
0e23c189f665 colors, line styles, more examples
aaron_watters
parents: 296
diff changeset
   444
def dashes(canvas):
0e23c189f665 colors, line styles, more examples
aaron_watters
parents: 296
diff changeset
   445
    from reportlab.lib.units import inch
0e23c189f665 colors, line styles, more examples
aaron_watters
parents: 296
diff changeset
   446
    # make lines big
0e23c189f665 colors, line styles, more examples
aaron_watters
parents: 296
diff changeset
   447
    canvas.setDash(6,3)
0e23c189f665 colors, line styles, more examples
aaron_watters
parents: 296
diff changeset
   448
    star(canvas, "Simple dashes", "6 points on, 3 off", xcenter = 1*inch)
0e23c189f665 colors, line styles, more examples
aaron_watters
parents: 296
diff changeset
   449
    canvas.setDash(1,2)
0e23c189f665 colors, line styles, more examples
aaron_watters
parents: 296
diff changeset
   450
    star(canvas, "Dots", "One on, two off")
0e23c189f665 colors, line styles, more examples
aaron_watters
parents: 296
diff changeset
   451
    canvas.setDash([1,1,3,3,1,4,4,1], 0)
0e23c189f665 colors, line styles, more examples
aaron_watters
parents: 296
diff changeset
   452
    star(canvas, "Complex Pattern", "[1,1,3,3,1,4,4,1]", xcenter=4.5*inch)
0e23c189f665 colors, line styles, more examples
aaron_watters
parents: 296
diff changeset
   453
"""
296
a5e584b6d61b Lots of graphical examples added
aaron_watters
parents: 293
diff changeset
   454
299
909b83ce750c textobject and pathobject methods, among other things
aaron_watters
parents: 298
diff changeset
   455
testcursormoves1 = """
909b83ce750c textobject and pathobject methods, among other things
aaron_watters
parents: 298
diff changeset
   456
def cursormoves1(canvas):
909b83ce750c textobject and pathobject methods, among other things
aaron_watters
parents: 298
diff changeset
   457
    from reportlab.lib.units import inch
909b83ce750c textobject and pathobject methods, among other things
aaron_watters
parents: 298
diff changeset
   458
    textobject = canvas.beginText()
909b83ce750c textobject and pathobject methods, among other things
aaron_watters
parents: 298
diff changeset
   459
    textobject.setTextOrigin(inch, 2.5*inch)
909b83ce750c textobject and pathobject methods, among other things
aaron_watters
parents: 298
diff changeset
   460
    textobject.setFont("Helvetica-Oblique", 14)
909b83ce750c textobject and pathobject methods, among other things
aaron_watters
parents: 298
diff changeset
   461
    for line in lyrics:
909b83ce750c textobject and pathobject methods, among other things
aaron_watters
parents: 298
diff changeset
   462
        textobject.textLine(line)
909b83ce750c textobject and pathobject methods, among other things
aaron_watters
parents: 298
diff changeset
   463
    textobject.setFillGray(0.4)
909b83ce750c textobject and pathobject methods, among other things
aaron_watters
parents: 298
diff changeset
   464
    textobject.textLines('''
308
a09abac33167 Minor cosmetic changes
rgbecker
parents: 301
diff changeset
   465
    With many apologies to the Beach Boys
299
909b83ce750c textobject and pathobject methods, among other things
aaron_watters
parents: 298
diff changeset
   466
    and anyone else who finds this objectionable
909b83ce750c textobject and pathobject methods, among other things
aaron_watters
parents: 298
diff changeset
   467
    ''')
909b83ce750c textobject and pathobject methods, among other things
aaron_watters
parents: 298
diff changeset
   468
    canvas.drawText(textobject)
909b83ce750c textobject and pathobject methods, among other things
aaron_watters
parents: 298
diff changeset
   469
"""
909b83ce750c textobject and pathobject methods, among other things
aaron_watters
parents: 298
diff changeset
   470
909b83ce750c textobject and pathobject methods, among other things
aaron_watters
parents: 298
diff changeset
   471
testcursormoves2 = """
909b83ce750c textobject and pathobject methods, among other things
aaron_watters
parents: 298
diff changeset
   472
def cursormoves2(canvas):
909b83ce750c textobject and pathobject methods, among other things
aaron_watters
parents: 298
diff changeset
   473
    from reportlab.lib.units import inch
909b83ce750c textobject and pathobject methods, among other things
aaron_watters
parents: 298
diff changeset
   474
    textobject = canvas.beginText()
909b83ce750c textobject and pathobject methods, among other things
aaron_watters
parents: 298
diff changeset
   475
    textobject.setTextOrigin(2, 2.5*inch)
909b83ce750c textobject and pathobject methods, among other things
aaron_watters
parents: 298
diff changeset
   476
    textobject.setFont("Helvetica-Oblique", 14)
909b83ce750c textobject and pathobject methods, among other things
aaron_watters
parents: 298
diff changeset
   477
    for line in lyrics:
909b83ce750c textobject and pathobject methods, among other things
aaron_watters
parents: 298
diff changeset
   478
        textobject.textOut(line)
909b83ce750c textobject and pathobject methods, among other things
aaron_watters
parents: 298
diff changeset
   479
        textobject.moveCursor(14,14) # POSITIVE Y moves down!!!
909b83ce750c textobject and pathobject methods, among other things
aaron_watters
parents: 298
diff changeset
   480
    textobject.setFillColorRGB(0.4,0,1)
909b83ce750c textobject and pathobject methods, among other things
aaron_watters
parents: 298
diff changeset
   481
    textobject.textLines('''
308
a09abac33167 Minor cosmetic changes
rgbecker
parents: 301
diff changeset
   482
    With many apologies to the Beach Boys
299
909b83ce750c textobject and pathobject methods, among other things
aaron_watters
parents: 298
diff changeset
   483
    and anyone else who finds this objectionable
909b83ce750c textobject and pathobject methods, among other things
aaron_watters
parents: 298
diff changeset
   484
    ''')
909b83ce750c textobject and pathobject methods, among other things
aaron_watters
parents: 298
diff changeset
   485
    canvas.drawText(textobject)
909b83ce750c textobject and pathobject methods, among other things
aaron_watters
parents: 298
diff changeset
   486
"""
909b83ce750c textobject and pathobject methods, among other things
aaron_watters
parents: 298
diff changeset
   487
909b83ce750c textobject and pathobject methods, among other things
aaron_watters
parents: 298
diff changeset
   488
testcharspace = """
909b83ce750c textobject and pathobject methods, among other things
aaron_watters
parents: 298
diff changeset
   489
def charspace(canvas):
909b83ce750c textobject and pathobject methods, among other things
aaron_watters
parents: 298
diff changeset
   490
    from reportlab.lib.units import inch
909b83ce750c textobject and pathobject methods, among other things
aaron_watters
parents: 298
diff changeset
   491
    textobject = canvas.beginText()
909b83ce750c textobject and pathobject methods, among other things
aaron_watters
parents: 298
diff changeset
   492
    textobject.setTextOrigin(3, 2.5*inch)
909b83ce750c textobject and pathobject methods, among other things
aaron_watters
parents: 298
diff changeset
   493
    textobject.setFont("Helvetica-Oblique", 10)
909b83ce750c textobject and pathobject methods, among other things
aaron_watters
parents: 298
diff changeset
   494
    charspace = 0
909b83ce750c textobject and pathobject methods, among other things
aaron_watters
parents: 298
diff changeset
   495
    for line in lyrics:
909b83ce750c textobject and pathobject methods, among other things
aaron_watters
parents: 298
diff changeset
   496
        textobject.setCharSpace(charspace)
909b83ce750c textobject and pathobject methods, among other things
aaron_watters
parents: 298
diff changeset
   497
        textobject.textLine("%s: %s" %(charspace,line))
909b83ce750c textobject and pathobject methods, among other things
aaron_watters
parents: 298
diff changeset
   498
        charspace = charspace+0.5
909b83ce750c textobject and pathobject methods, among other things
aaron_watters
parents: 298
diff changeset
   499
    textobject.setFillGray(0.4)
909b83ce750c textobject and pathobject methods, among other things
aaron_watters
parents: 298
diff changeset
   500
    textobject.textLines('''
308
a09abac33167 Minor cosmetic changes
rgbecker
parents: 301
diff changeset
   501
    With many apologies to the Beach Boys
299
909b83ce750c textobject and pathobject methods, among other things
aaron_watters
parents: 298
diff changeset
   502
    and anyone else who finds this objectionable
909b83ce750c textobject and pathobject methods, among other things
aaron_watters
parents: 298
diff changeset
   503
    ''')
909b83ce750c textobject and pathobject methods, among other things
aaron_watters
parents: 298
diff changeset
   504
    canvas.drawText(textobject)
909b83ce750c textobject and pathobject methods, among other things
aaron_watters
parents: 298
diff changeset
   505
"""
909b83ce750c textobject and pathobject methods, among other things
aaron_watters
parents: 298
diff changeset
   506
909b83ce750c textobject and pathobject methods, among other things
aaron_watters
parents: 298
diff changeset
   507
testwordspace = """
909b83ce750c textobject and pathobject methods, among other things
aaron_watters
parents: 298
diff changeset
   508
def wordspace(canvas):
909b83ce750c textobject and pathobject methods, among other things
aaron_watters
parents: 298
diff changeset
   509
    from reportlab.lib.units import inch
909b83ce750c textobject and pathobject methods, among other things
aaron_watters
parents: 298
diff changeset
   510
    textobject = canvas.beginText()
909b83ce750c textobject and pathobject methods, among other things
aaron_watters
parents: 298
diff changeset
   511
    textobject.setTextOrigin(3, 2.5*inch)
909b83ce750c textobject and pathobject methods, among other things
aaron_watters
parents: 298
diff changeset
   512
    textobject.setFont("Helvetica-Oblique", 12)
909b83ce750c textobject and pathobject methods, among other things
aaron_watters
parents: 298
diff changeset
   513
    wordspace = 0
909b83ce750c textobject and pathobject methods, among other things
aaron_watters
parents: 298
diff changeset
   514
    for line in lyrics:
909b83ce750c textobject and pathobject methods, among other things
aaron_watters
parents: 298
diff changeset
   515
        textobject.setWordSpace(wordspace)
909b83ce750c textobject and pathobject methods, among other things
aaron_watters
parents: 298
diff changeset
   516
        textobject.textLine("%s: %s" %(wordspace,line))
909b83ce750c textobject and pathobject methods, among other things
aaron_watters
parents: 298
diff changeset
   517
        wordspace = wordspace+2.5
909b83ce750c textobject and pathobject methods, among other things
aaron_watters
parents: 298
diff changeset
   518
    textobject.setFillColorCMYK(0.4,0,0.4,0.2)
909b83ce750c textobject and pathobject methods, among other things
aaron_watters
parents: 298
diff changeset
   519
    textobject.textLines('''
308
a09abac33167 Minor cosmetic changes
rgbecker
parents: 301
diff changeset
   520
    With many apologies to the Beach Boys
299
909b83ce750c textobject and pathobject methods, among other things
aaron_watters
parents: 298
diff changeset
   521
    and anyone else who finds this objectionable
909b83ce750c textobject and pathobject methods, among other things
aaron_watters
parents: 298
diff changeset
   522
    ''')
909b83ce750c textobject and pathobject methods, among other things
aaron_watters
parents: 298
diff changeset
   523
    canvas.drawText(textobject)
909b83ce750c textobject and pathobject methods, among other things
aaron_watters
parents: 298
diff changeset
   524
"""
909b83ce750c textobject and pathobject methods, among other things
aaron_watters
parents: 298
diff changeset
   525
testhorizontalscale = """
909b83ce750c textobject and pathobject methods, among other things
aaron_watters
parents: 298
diff changeset
   526
def horizontalscale(canvas):
909b83ce750c textobject and pathobject methods, among other things
aaron_watters
parents: 298
diff changeset
   527
    from reportlab.lib.units import inch
909b83ce750c textobject and pathobject methods, among other things
aaron_watters
parents: 298
diff changeset
   528
    textobject = canvas.beginText()
909b83ce750c textobject and pathobject methods, among other things
aaron_watters
parents: 298
diff changeset
   529
    textobject.setTextOrigin(3, 2.5*inch)
909b83ce750c textobject and pathobject methods, among other things
aaron_watters
parents: 298
diff changeset
   530
    textobject.setFont("Helvetica-Oblique", 12)
909b83ce750c textobject and pathobject methods, among other things
aaron_watters
parents: 298
diff changeset
   531
    horizontalscale = 80 # 100 is default
909b83ce750c textobject and pathobject methods, among other things
aaron_watters
parents: 298
diff changeset
   532
    for line in lyrics:
909b83ce750c textobject and pathobject methods, among other things
aaron_watters
parents: 298
diff changeset
   533
        textobject.setHorizScale(horizontalscale)
909b83ce750c textobject and pathobject methods, among other things
aaron_watters
parents: 298
diff changeset
   534
        textobject.textLine("%s: %s" %(horizontalscale,line))
909b83ce750c textobject and pathobject methods, among other things
aaron_watters
parents: 298
diff changeset
   535
        horizontalscale = horizontalscale+10
909b83ce750c textobject and pathobject methods, among other things
aaron_watters
parents: 298
diff changeset
   536
    textobject.setFillColorCMYK(0.0,0.4,0.4,0.2)
909b83ce750c textobject and pathobject methods, among other things
aaron_watters
parents: 298
diff changeset
   537
    textobject.textLines('''
308
a09abac33167 Minor cosmetic changes
rgbecker
parents: 301
diff changeset
   538
    With many apologies to the Beach Boys
299
909b83ce750c textobject and pathobject methods, among other things
aaron_watters
parents: 298
diff changeset
   539
    and anyone else who finds this objectionable
909b83ce750c textobject and pathobject methods, among other things
aaron_watters
parents: 298
diff changeset
   540
    ''')
909b83ce750c textobject and pathobject methods, among other things
aaron_watters
parents: 298
diff changeset
   541
    canvas.drawText(textobject)
909b83ce750c textobject and pathobject methods, among other things
aaron_watters
parents: 298
diff changeset
   542
"""
909b83ce750c textobject and pathobject methods, among other things
aaron_watters
parents: 298
diff changeset
   543
testleading = """
909b83ce750c textobject and pathobject methods, among other things
aaron_watters
parents: 298
diff changeset
   544
def leading(canvas):
909b83ce750c textobject and pathobject methods, among other things
aaron_watters
parents: 298
diff changeset
   545
    from reportlab.lib.units import inch
909b83ce750c textobject and pathobject methods, among other things
aaron_watters
parents: 298
diff changeset
   546
    textobject = canvas.beginText()
909b83ce750c textobject and pathobject methods, among other things
aaron_watters
parents: 298
diff changeset
   547
    textobject.setTextOrigin(3, 2.5*inch)
909b83ce750c textobject and pathobject methods, among other things
aaron_watters
parents: 298
diff changeset
   548
    textobject.setFont("Helvetica-Oblique", 14)
909b83ce750c textobject and pathobject methods, among other things
aaron_watters
parents: 298
diff changeset
   549
    leading = 8
909b83ce750c textobject and pathobject methods, among other things
aaron_watters
parents: 298
diff changeset
   550
    for line in lyrics:
909b83ce750c textobject and pathobject methods, among other things
aaron_watters
parents: 298
diff changeset
   551
        textobject.setLeading(leading)
909b83ce750c textobject and pathobject methods, among other things
aaron_watters
parents: 298
diff changeset
   552
        textobject.textLine("%s: %s" %(leading,line))
909b83ce750c textobject and pathobject methods, among other things
aaron_watters
parents: 298
diff changeset
   553
        leading = leading+2.5
909b83ce750c textobject and pathobject methods, among other things
aaron_watters
parents: 298
diff changeset
   554
    textobject.setFillColorCMYK(0.8,0,0,0.3)
909b83ce750c textobject and pathobject methods, among other things
aaron_watters
parents: 298
diff changeset
   555
    textobject.textLines('''
308
a09abac33167 Minor cosmetic changes
rgbecker
parents: 301
diff changeset
   556
    With many apologies to the Beach Boys
299
909b83ce750c textobject and pathobject methods, among other things
aaron_watters
parents: 298
diff changeset
   557
    and anyone else who finds this objectionable
909b83ce750c textobject and pathobject methods, among other things
aaron_watters
parents: 298
diff changeset
   558
    ''')
909b83ce750c textobject and pathobject methods, among other things
aaron_watters
parents: 298
diff changeset
   559
    canvas.drawText(textobject)
909b83ce750c textobject and pathobject methods, among other things
aaron_watters
parents: 298
diff changeset
   560
"""
301
5ad57f31ae75 added quickhack for font changes in paragraphs and lots of new text
aaron_watters
parents: 299
diff changeset
   561
5ad57f31ae75 added quickhack for font changes in paragraphs and lots of new text
aaron_watters
parents: 299
diff changeset
   562
testhand = """
5ad57f31ae75 added quickhack for font changes in paragraphs and lots of new text
aaron_watters
parents: 299
diff changeset
   563
def hand(canvas, debug=1, fill=0):
5ad57f31ae75 added quickhack for font changes in paragraphs and lots of new text
aaron_watters
parents: 299
diff changeset
   564
    (startx, starty) = (0,0)
5ad57f31ae75 added quickhack for font changes in paragraphs and lots of new text
aaron_watters
parents: 299
diff changeset
   565
    curves = [
5ad57f31ae75 added quickhack for font changes in paragraphs and lots of new text
aaron_watters
parents: 299
diff changeset
   566
      ( 0, 2), ( 0, 4), ( 0, 8), # back of hand
5ad57f31ae75 added quickhack for font changes in paragraphs and lots of new text
aaron_watters
parents: 299
diff changeset
   567
      ( 5, 8), ( 7,10), ( 7,14),
5ad57f31ae75 added quickhack for font changes in paragraphs and lots of new text
aaron_watters
parents: 299
diff changeset
   568
      (10,14), (10,13), ( 7.5, 8), # thumb
5ad57f31ae75 added quickhack for font changes in paragraphs and lots of new text
aaron_watters
parents: 299
diff changeset
   569
      (13, 8), (14, 8), (17, 8),
5ad57f31ae75 added quickhack for font changes in paragraphs and lots of new text
aaron_watters
parents: 299
diff changeset
   570
      (19, 8), (19, 6), (17, 6),
5ad57f31ae75 added quickhack for font changes in paragraphs and lots of new text
aaron_watters
parents: 299
diff changeset
   571
      (15, 6), (13, 6), (11, 6), # index, pointing
5ad57f31ae75 added quickhack for font changes in paragraphs and lots of new text
aaron_watters
parents: 299
diff changeset
   572
      (12, 6), (13, 6), (14, 6),
5ad57f31ae75 added quickhack for font changes in paragraphs and lots of new text
aaron_watters
parents: 299
diff changeset
   573
      (16, 6), (16, 4), (14, 4),
5ad57f31ae75 added quickhack for font changes in paragraphs and lots of new text
aaron_watters
parents: 299
diff changeset
   574
      (13, 4), (12, 4), (11, 4), # middle
5ad57f31ae75 added quickhack for font changes in paragraphs and lots of new text
aaron_watters
parents: 299
diff changeset
   575
      (11.5, 4), (12, 4), (13, 4),
5ad57f31ae75 added quickhack for font changes in paragraphs and lots of new text
aaron_watters
parents: 299
diff changeset
   576
      (15, 4), (15, 2), (13, 2),
5ad57f31ae75 added quickhack for font changes in paragraphs and lots of new text
aaron_watters
parents: 299
diff changeset
   577
      (12.5, 2), (11.5, 2), (11, 2), # ring
5ad57f31ae75 added quickhack for font changes in paragraphs and lots of new text
aaron_watters
parents: 299
diff changeset
   578
      (11.5, 2), (12, 2), (12.5, 2),
5ad57f31ae75 added quickhack for font changes in paragraphs and lots of new text
aaron_watters
parents: 299
diff changeset
   579
      (14, 2), (14, 0), (12.5, 0),
5ad57f31ae75 added quickhack for font changes in paragraphs and lots of new text
aaron_watters
parents: 299
diff changeset
   580
      (10, 0), (8, 0), (6, 0), # pinky, then close
5ad57f31ae75 added quickhack for font changes in paragraphs and lots of new text
aaron_watters
parents: 299
diff changeset
   581
      ]
5ad57f31ae75 added quickhack for font changes in paragraphs and lots of new text
aaron_watters
parents: 299
diff changeset
   582
    from reportlab.lib.units import inch
5ad57f31ae75 added quickhack for font changes in paragraphs and lots of new text
aaron_watters
parents: 299
diff changeset
   583
    if debug: canvas.setLineWidth(6)
5ad57f31ae75 added quickhack for font changes in paragraphs and lots of new text
aaron_watters
parents: 299
diff changeset
   584
    u = inch*0.2
5ad57f31ae75 added quickhack for font changes in paragraphs and lots of new text
aaron_watters
parents: 299
diff changeset
   585
    p = canvas.beginPath()
5ad57f31ae75 added quickhack for font changes in paragraphs and lots of new text
aaron_watters
parents: 299
diff changeset
   586
    p.moveTo(startx, starty)
5ad57f31ae75 added quickhack for font changes in paragraphs and lots of new text
aaron_watters
parents: 299
diff changeset
   587
    ccopy = list(curves)
5ad57f31ae75 added quickhack for font changes in paragraphs and lots of new text
aaron_watters
parents: 299
diff changeset
   588
    while ccopy:
5ad57f31ae75 added quickhack for font changes in paragraphs and lots of new text
aaron_watters
parents: 299
diff changeset
   589
        [(x1,y1), (x2,y2), (x3,y3)] = ccopy[:3]
5ad57f31ae75 added quickhack for font changes in paragraphs and lots of new text
aaron_watters
parents: 299
diff changeset
   590
        del ccopy[:3]
5ad57f31ae75 added quickhack for font changes in paragraphs and lots of new text
aaron_watters
parents: 299
diff changeset
   591
        p.curveTo(x1*u,y1*u,x2*u,y2*u,x3*u,y3*u)
5ad57f31ae75 added quickhack for font changes in paragraphs and lots of new text
aaron_watters
parents: 299
diff changeset
   592
    p.close()
5ad57f31ae75 added quickhack for font changes in paragraphs and lots of new text
aaron_watters
parents: 299
diff changeset
   593
    canvas.drawPath(p, fill=fill)
5ad57f31ae75 added quickhack for font changes in paragraphs and lots of new text
aaron_watters
parents: 299
diff changeset
   594
    if debug:
5ad57f31ae75 added quickhack for font changes in paragraphs and lots of new text
aaron_watters
parents: 299
diff changeset
   595
        from reportlab.lib.colors import red, green
5ad57f31ae75 added quickhack for font changes in paragraphs and lots of new text
aaron_watters
parents: 299
diff changeset
   596
        (lastx, lasty) = (startx, starty)
5ad57f31ae75 added quickhack for font changes in paragraphs and lots of new text
aaron_watters
parents: 299
diff changeset
   597
        ccopy = list(curves)
5ad57f31ae75 added quickhack for font changes in paragraphs and lots of new text
aaron_watters
parents: 299
diff changeset
   598
        while ccopy:
5ad57f31ae75 added quickhack for font changes in paragraphs and lots of new text
aaron_watters
parents: 299
diff changeset
   599
            [(x1,y1), (x2,y2), (x3,y3)] = ccopy[:3]
5ad57f31ae75 added quickhack for font changes in paragraphs and lots of new text
aaron_watters
parents: 299
diff changeset
   600
            del ccopy[:3]
5ad57f31ae75 added quickhack for font changes in paragraphs and lots of new text
aaron_watters
parents: 299
diff changeset
   601
            canvas.setStrokeColor(red)
5ad57f31ae75 added quickhack for font changes in paragraphs and lots of new text
aaron_watters
parents: 299
diff changeset
   602
            canvas.line(lastx*u,lasty*u, x1*u,y1*u)
5ad57f31ae75 added quickhack for font changes in paragraphs and lots of new text
aaron_watters
parents: 299
diff changeset
   603
            canvas.setStrokeColor(green)
5ad57f31ae75 added quickhack for font changes in paragraphs and lots of new text
aaron_watters
parents: 299
diff changeset
   604
            canvas.line(x2*u,y2*u, x3*u,y3*u)
5ad57f31ae75 added quickhack for font changes in paragraphs and lots of new text
aaron_watters
parents: 299
diff changeset
   605
            (lastx,lasty) = (x3,y3)
5ad57f31ae75 added quickhack for font changes in paragraphs and lots of new text
aaron_watters
parents: 299
diff changeset
   606
"""
5ad57f31ae75 added quickhack for font changes in paragraphs and lots of new text
aaron_watters
parents: 299
diff changeset
   607
5ad57f31ae75 added quickhack for font changes in paragraphs and lots of new text
aaron_watters
parents: 299
diff changeset
   608
testhand2 = """
5ad57f31ae75 added quickhack for font changes in paragraphs and lots of new text
aaron_watters
parents: 299
diff changeset
   609
def hand2(canvas):
5ad57f31ae75 added quickhack for font changes in paragraphs and lots of new text
aaron_watters
parents: 299
diff changeset
   610
    canvas.translate(20,10)
5ad57f31ae75 added quickhack for font changes in paragraphs and lots of new text
aaron_watters
parents: 299
diff changeset
   611
    canvas.setLineWidth(3)
5ad57f31ae75 added quickhack for font changes in paragraphs and lots of new text
aaron_watters
parents: 299
diff changeset
   612
    canvas.setFillColorRGB(0.1, 0.3, 0.9)
5ad57f31ae75 added quickhack for font changes in paragraphs and lots of new text
aaron_watters
parents: 299
diff changeset
   613
    canvas.setStrokeGray(0.5)
5ad57f31ae75 added quickhack for font changes in paragraphs and lots of new text
aaron_watters
parents: 299
diff changeset
   614
    hand(canvas, debug=0, fill=1)
5ad57f31ae75 added quickhack for font changes in paragraphs and lots of new text
aaron_watters
parents: 299
diff changeset
   615
"""
5ad57f31ae75 added quickhack for font changes in paragraphs and lots of new text
aaron_watters
parents: 299
diff changeset
   616
5ad57f31ae75 added quickhack for font changes in paragraphs and lots of new text
aaron_watters
parents: 299
diff changeset
   617
testfonts = """
5ad57f31ae75 added quickhack for font changes in paragraphs and lots of new text
aaron_watters
parents: 299
diff changeset
   618
def fonts(canvas):
5ad57f31ae75 added quickhack for font changes in paragraphs and lots of new text
aaron_watters
parents: 299
diff changeset
   619
    from reportlab.lib.units import inch
5ad57f31ae75 added quickhack for font changes in paragraphs and lots of new text
aaron_watters
parents: 299
diff changeset
   620
    text = "Now is the time for all good men to..."
5ad57f31ae75 added quickhack for font changes in paragraphs and lots of new text
aaron_watters
parents: 299
diff changeset
   621
    x = 1.8*inch
5ad57f31ae75 added quickhack for font changes in paragraphs and lots of new text
aaron_watters
parents: 299
diff changeset
   622
    y = 2.7*inch
5ad57f31ae75 added quickhack for font changes in paragraphs and lots of new text
aaron_watters
parents: 299
diff changeset
   623
    for font in canvas.getAvailableFonts():
5ad57f31ae75 added quickhack for font changes in paragraphs and lots of new text
aaron_watters
parents: 299
diff changeset
   624
        canvas.setFont(font, 10)
5ad57f31ae75 added quickhack for font changes in paragraphs and lots of new text
aaron_watters
parents: 299
diff changeset
   625
        canvas.drawString(x,y,text)
5ad57f31ae75 added quickhack for font changes in paragraphs and lots of new text
aaron_watters
parents: 299
diff changeset
   626
        canvas.setFont("Helvetica", 10)
5ad57f31ae75 added quickhack for font changes in paragraphs and lots of new text
aaron_watters
parents: 299
diff changeset
   627
        canvas.drawRightString(x-10,y, font+":")
5ad57f31ae75 added quickhack for font changes in paragraphs and lots of new text
aaron_watters
parents: 299
diff changeset
   628
        y = y-13
5ad57f31ae75 added quickhack for font changes in paragraphs and lots of new text
aaron_watters
parents: 299
diff changeset
   629
"""
5ad57f31ae75 added quickhack for font changes in paragraphs and lots of new text
aaron_watters
parents: 299
diff changeset
   630
364
21f5c8641230 more text, more pdfgen examples
aaron_watters
parents: 320
diff changeset
   631
testarcs = """
21f5c8641230 more text, more pdfgen examples
aaron_watters
parents: 320
diff changeset
   632
def arcs(canvas):
21f5c8641230 more text, more pdfgen examples
aaron_watters
parents: 320
diff changeset
   633
    from reportlab.lib.units import inch
21f5c8641230 more text, more pdfgen examples
aaron_watters
parents: 320
diff changeset
   634
    canvas.setLineWidth(4)
21f5c8641230 more text, more pdfgen examples
aaron_watters
parents: 320
diff changeset
   635
    canvas.setStrokeColorRGB(0.8, 1, 0.6)
21f5c8641230 more text, more pdfgen examples
aaron_watters
parents: 320
diff changeset
   636
    # draw rectangles enclosing the arcs
21f5c8641230 more text, more pdfgen examples
aaron_watters
parents: 320
diff changeset
   637
    canvas.rect(inch, inch, 1.5*inch, inch)
21f5c8641230 more text, more pdfgen examples
aaron_watters
parents: 320
diff changeset
   638
    canvas.rect(3*inch, inch, inch, 1.5*inch)
21f5c8641230 more text, more pdfgen examples
aaron_watters
parents: 320
diff changeset
   639
    canvas.setStrokeColorRGB(0, 0.2, 0.4)
21f5c8641230 more text, more pdfgen examples
aaron_watters
parents: 320
diff changeset
   640
    canvas.setFillColorRGB(1, 0.6, 0.8)
21f5c8641230 more text, more pdfgen examples
aaron_watters
parents: 320
diff changeset
   641
    p = canvas.beginPath()
21f5c8641230 more text, more pdfgen examples
aaron_watters
parents: 320
diff changeset
   642
    p.moveTo(0.2*inch, 0.2*inch)
21f5c8641230 more text, more pdfgen examples
aaron_watters
parents: 320
diff changeset
   643
    p.arcTo(inch, inch, 2.5*inch,2*inch, startAng=-30, extent=135)
21f5c8641230 more text, more pdfgen examples
aaron_watters
parents: 320
diff changeset
   644
    p.arc(3*inch, inch, 4*inch, 2.5*inch, startAng=-45, extent=270)
21f5c8641230 more text, more pdfgen examples
aaron_watters
parents: 320
diff changeset
   645
    canvas.drawPath(p, fill=1, stroke=1)
21f5c8641230 more text, more pdfgen examples
aaron_watters
parents: 320
diff changeset
   646
"""
21f5c8641230 more text, more pdfgen examples
aaron_watters
parents: 320
diff changeset
   647
testvariousshapes = """
21f5c8641230 more text, more pdfgen examples
aaron_watters
parents: 320
diff changeset
   648
def variousshapes(canvas):
21f5c8641230 more text, more pdfgen examples
aaron_watters
parents: 320
diff changeset
   649
    from reportlab.lib.units import inch
21f5c8641230 more text, more pdfgen examples
aaron_watters
parents: 320
diff changeset
   650
    inch = int(inch)
21f5c8641230 more text, more pdfgen examples
aaron_watters
parents: 320
diff changeset
   651
    canvas.setStrokeGray(0.5)
21f5c8641230 more text, more pdfgen examples
aaron_watters
parents: 320
diff changeset
   652
    canvas.grid(range(0,11*inch/2,inch/2), range(0,7*inch/2,inch/2))
21f5c8641230 more text, more pdfgen examples
aaron_watters
parents: 320
diff changeset
   653
    canvas.setLineWidth(4)
21f5c8641230 more text, more pdfgen examples
aaron_watters
parents: 320
diff changeset
   654
    canvas.setStrokeColorRGB(0, 0.2, 0.7)
21f5c8641230 more text, more pdfgen examples
aaron_watters
parents: 320
diff changeset
   655
    canvas.setFillColorRGB(1, 0.6, 0.8)
21f5c8641230 more text, more pdfgen examples
aaron_watters
parents: 320
diff changeset
   656
    p = canvas.beginPath()
21f5c8641230 more text, more pdfgen examples
aaron_watters
parents: 320
diff changeset
   657
    p.rect(0.5*inch, 0.5*inch, 0.5*inch, 2*inch)
21f5c8641230 more text, more pdfgen examples
aaron_watters
parents: 320
diff changeset
   658
    p.circle(2.75*inch, 1.5*inch, 0.3*inch)
21f5c8641230 more text, more pdfgen examples
aaron_watters
parents: 320
diff changeset
   659
    p.ellipse(3.5*inch, 0.5*inch, 1.2*inch, 2*inch)
21f5c8641230 more text, more pdfgen examples
aaron_watters
parents: 320
diff changeset
   660
    canvas.drawPath(p, fill=1, stroke=1)
21f5c8641230 more text, more pdfgen examples
aaron_watters
parents: 320
diff changeset
   661
"""
21f5c8641230 more text, more pdfgen examples
aaron_watters
parents: 320
diff changeset
   662
21f5c8641230 more text, more pdfgen examples
aaron_watters
parents: 320
diff changeset
   663
testclosingfigures = """
21f5c8641230 more text, more pdfgen examples
aaron_watters
parents: 320
diff changeset
   664
def closingfigures(canvas):
21f5c8641230 more text, more pdfgen examples
aaron_watters
parents: 320
diff changeset
   665
    from reportlab.lib.units import inch
21f5c8641230 more text, more pdfgen examples
aaron_watters
parents: 320
diff changeset
   666
    h = inch/3.0; k = inch/2.0
21f5c8641230 more text, more pdfgen examples
aaron_watters
parents: 320
diff changeset
   667
    canvas.setStrokeColorRGB(0.2,0.3,0.5)
21f5c8641230 more text, more pdfgen examples
aaron_watters
parents: 320
diff changeset
   668
    canvas.setFillColorRGB(0.8,0.6,0.2)
21f5c8641230 more text, more pdfgen examples
aaron_watters
parents: 320
diff changeset
   669
    canvas.setLineWidth(4)
21f5c8641230 more text, more pdfgen examples
aaron_watters
parents: 320
diff changeset
   670
    p = canvas.beginPath()
21f5c8641230 more text, more pdfgen examples
aaron_watters
parents: 320
diff changeset
   671
    for i in (1,2,3,4):
21f5c8641230 more text, more pdfgen examples
aaron_watters
parents: 320
diff changeset
   672
        for j in (1,2):
21f5c8641230 more text, more pdfgen examples
aaron_watters
parents: 320
diff changeset
   673
            xc,yc = inch*i, inch*j
21f5c8641230 more text, more pdfgen examples
aaron_watters
parents: 320
diff changeset
   674
            p.moveTo(xc,yc)
21f5c8641230 more text, more pdfgen examples
aaron_watters
parents: 320
diff changeset
   675
            p.arcTo(xc-h, yc-k, xc+h, yc+k, startAng=0, extent=60*i)
21f5c8641230 more text, more pdfgen examples
aaron_watters
parents: 320
diff changeset
   676
            # close only the first one, not the second one
21f5c8641230 more text, more pdfgen examples
aaron_watters
parents: 320
diff changeset
   677
            if j==1:
21f5c8641230 more text, more pdfgen examples
aaron_watters
parents: 320
diff changeset
   678
                p.close()
21f5c8641230 more text, more pdfgen examples
aaron_watters
parents: 320
diff changeset
   679
    canvas.drawPath(p, fill=1, stroke=1)
21f5c8641230 more text, more pdfgen examples
aaron_watters
parents: 320
diff changeset
   680
"""
21f5c8641230 more text, more pdfgen examples
aaron_watters
parents: 320
diff changeset
   681
320
7a4ca2b5bb89 Tidied up genuserguide.py, especially figure handling; began
andy_robinson
parents: 317
diff changeset
   682
testforms = """
7a4ca2b5bb89 Tidied up genuserguide.py, especially figure handling; began
andy_robinson
parents: 317
diff changeset
   683
def forms(canvas):
7a4ca2b5bb89 Tidied up genuserguide.py, especially figure handling; began
andy_robinson
parents: 317
diff changeset
   684
    #first create a form...
7a4ca2b5bb89 Tidied up genuserguide.py, especially figure handling; began
andy_robinson
parents: 317
diff changeset
   685
    canvas.beginForm("SpumoniForm")
7a4ca2b5bb89 Tidied up genuserguide.py, especially figure handling; began
andy_robinson
parents: 317
diff changeset
   686
    #re-use some drawing functions from earlier
7a4ca2b5bb89 Tidied up genuserguide.py, especially figure handling; began
andy_robinson
parents: 317
diff changeset
   687
    spumoni(canvas)
7a4ca2b5bb89 Tidied up genuserguide.py, especially figure handling; began
andy_robinson
parents: 317
diff changeset
   688
    canvas.endForm()
7a4ca2b5bb89 Tidied up genuserguide.py, especially figure handling; began
andy_robinson
parents: 317
diff changeset
   689
7a4ca2b5bb89 Tidied up genuserguide.py, especially figure handling; began
andy_robinson
parents: 317
diff changeset
   690
    #then draw it
7a4ca2b5bb89 Tidied up genuserguide.py, especially figure handling; began
andy_robinson
parents: 317
diff changeset
   691
    canvas.doForm("SpumoniForm")    
7a4ca2b5bb89 Tidied up genuserguide.py, especially figure handling; began
andy_robinson
parents: 317
diff changeset
   692
"""
7a4ca2b5bb89 Tidied up genuserguide.py, especially figure handling; began
andy_robinson
parents: 317
diff changeset
   693
381
2ca856765ed1 various mods
aaron_watters
parents: 375
diff changeset
   694
def doctemplateillustration(canvas):
2ca856765ed1 various mods
aaron_watters
parents: 375
diff changeset
   695
    from reportlab.lib.units import inch
2ca856765ed1 various mods
aaron_watters
parents: 375
diff changeset
   696
    canvas.setFont("Helvetica", 10)
2ca856765ed1 various mods
aaron_watters
parents: 375
diff changeset
   697
    canvas.drawString(inch/4.0, 2.75*inch, "DocTemplate")
2ca856765ed1 various mods
aaron_watters
parents: 375
diff changeset
   698
    W = 4/3.0*inch
2ca856765ed1 various mods
aaron_watters
parents: 375
diff changeset
   699
    H = 2*inch
2ca856765ed1 various mods
aaron_watters
parents: 375
diff changeset
   700
    Wd = x = inch/4.0
2ca856765ed1 various mods
aaron_watters
parents: 375
diff changeset
   701
    Hd =y = inch/2.0
2ca856765ed1 various mods
aaron_watters
parents: 375
diff changeset
   702
    for name in ("two column", "chapter page", "title page"):
2ca856765ed1 various mods
aaron_watters
parents: 375
diff changeset
   703
        canvas.setFillColorRGB(0.5,1.0,1.0)
2ca856765ed1 various mods
aaron_watters
parents: 375
diff changeset
   704
        canvas.rect(x,y,W,H, fill=1)
2ca856765ed1 various mods
aaron_watters
parents: 375
diff changeset
   705
        canvas.setFillColorRGB(0,0,0)
2ca856765ed1 various mods
aaron_watters
parents: 375
diff changeset
   706
        canvas.drawString(x+inch/8, y+H-Wd, "PageTemplate")
2ca856765ed1 various mods
aaron_watters
parents: 375
diff changeset
   707
        canvas.drawCentredString(x+W/2.0, y-Wd, name)
2ca856765ed1 various mods
aaron_watters
parents: 375
diff changeset
   708
        x = x+W+Wd
2ca856765ed1 various mods
aaron_watters
parents: 375
diff changeset
   709
    canvas.saveState()
2ca856765ed1 various mods
aaron_watters
parents: 375
diff changeset
   710
    d = inch/16
2ca856765ed1 various mods
aaron_watters
parents: 375
diff changeset
   711
    dW = (W-3*d)/2.0
2ca856765ed1 various mods
aaron_watters
parents: 375
diff changeset
   712
    hD = H -2*d-Wd
2ca856765ed1 various mods
aaron_watters
parents: 375
diff changeset
   713
    canvas.translate(Wd+d, Hd+d)
2ca856765ed1 various mods
aaron_watters
parents: 375
diff changeset
   714
    for name in ("left Frame", "right Frame"):
2ca856765ed1 various mods
aaron_watters
parents: 375
diff changeset
   715
        canvas.setFillColorRGB(1.0,0.5,1.0)
2ca856765ed1 various mods
aaron_watters
parents: 375
diff changeset
   716
        canvas.rect(0,0, dW,hD, fill=1)
2ca856765ed1 various mods
aaron_watters
parents: 375
diff changeset
   717
        canvas.setFillGray(0.7)
2ca856765ed1 various mods
aaron_watters
parents: 375
diff changeset
   718
        dd= d/2.0
2ca856765ed1 various mods
aaron_watters
parents: 375
diff changeset
   719
        ddH = (hD-6*dd)/5.0
2ca856765ed1 various mods
aaron_watters
parents: 375
diff changeset
   720
        ddW = dW-2*dd
2ca856765ed1 various mods
aaron_watters
parents: 375
diff changeset
   721
        yy = dd
2ca856765ed1 various mods
aaron_watters
parents: 375
diff changeset
   722
        xx = dd
2ca856765ed1 various mods
aaron_watters
parents: 375
diff changeset
   723
        for i in range(5):
2ca856765ed1 various mods
aaron_watters
parents: 375
diff changeset
   724
            canvas.rect(xx,yy,ddW,ddH, fill=1, stroke=0)
2ca856765ed1 various mods
aaron_watters
parents: 375
diff changeset
   725
            yy = yy+ddH+dd
2ca856765ed1 various mods
aaron_watters
parents: 375
diff changeset
   726
        canvas.setFillColorRGB(0,0,0)
2ca856765ed1 various mods
aaron_watters
parents: 375
diff changeset
   727
        canvas.saveState()
2ca856765ed1 various mods
aaron_watters
parents: 375
diff changeset
   728
        canvas.rotate(90)
2ca856765ed1 various mods
aaron_watters
parents: 375
diff changeset
   729
        canvas.drawString(d,-dW/2, name)
2ca856765ed1 various mods
aaron_watters
parents: 375
diff changeset
   730
        canvas.restoreState()
2ca856765ed1 various mods
aaron_watters
parents: 375
diff changeset
   731
        canvas.translate(dW+d,0)
2ca856765ed1 various mods
aaron_watters
parents: 375
diff changeset
   732
    canvas.restoreState()
2ca856765ed1 various mods
aaron_watters
parents: 375
diff changeset
   733
    canvas.setFillColorRGB(1.0, 0.5, 1.0)
2ca856765ed1 various mods
aaron_watters
parents: 375
diff changeset
   734
    mx = Wd+W+Wd+d
2ca856765ed1 various mods
aaron_watters
parents: 375
diff changeset
   735
    my = Hd+d
2ca856765ed1 various mods
aaron_watters
parents: 375
diff changeset
   736
    mW = W-2*d
2ca856765ed1 various mods
aaron_watters
parents: 375
diff changeset
   737
    mH = H-d-Hd
2ca856765ed1 various mods
aaron_watters
parents: 375
diff changeset
   738
    canvas.rect(mx, my, mW, mH, fill=1)
2ca856765ed1 various mods
aaron_watters
parents: 375
diff changeset
   739
    canvas.rect(Wd+2*(W+Wd)+d, Hd+3*d, W-2*d, H/2.0, fill=1)
2ca856765ed1 various mods
aaron_watters
parents: 375
diff changeset
   740
    canvas.setFillGray(0.7)
2ca856765ed1 various mods
aaron_watters
parents: 375
diff changeset
   741
    canvas.rect(Wd+2*(W+Wd)+d+dd, Hd+5*d, W-2*d-2*dd, H/2.0-2*d-dd, fill=1)
2ca856765ed1 various mods
aaron_watters
parents: 375
diff changeset
   742
    xx = mx+dd
2ca856765ed1 various mods
aaron_watters
parents: 375
diff changeset
   743
    yy = my+mH/5.0
2ca856765ed1 various mods
aaron_watters
parents: 375
diff changeset
   744
    ddH = (mH-6*dd-mH/5.0)/3.0
2ca856765ed1 various mods
aaron_watters
parents: 375
diff changeset
   745
    ddW = mW - 2*dd
2ca856765ed1 various mods
aaron_watters
parents: 375
diff changeset
   746
    for i in range(3):
2ca856765ed1 various mods
aaron_watters
parents: 375
diff changeset
   747
        canvas.setFillGray(0.7)
2ca856765ed1 various mods
aaron_watters
parents: 375
diff changeset
   748
        canvas.rect(xx,yy,ddW,ddH, fill=1, stroke=1)
2ca856765ed1 various mods
aaron_watters
parents: 375
diff changeset
   749
        canvas.setFillGray(0)
2ca856765ed1 various mods
aaron_watters
parents: 375
diff changeset
   750
        canvas.drawString(xx+dd/2.0,yy+dd/2.0, "flowable %s" %(157-i))
2ca856765ed1 various mods
aaron_watters
parents: 375
diff changeset
   751
        yy = yy+ddH+dd
2ca856765ed1 various mods
aaron_watters
parents: 375
diff changeset
   752
    canvas.drawCentredString(3*Wd+2*W+W/2, Hd+H/2.0, "First Flowable")
2ca856765ed1 various mods
aaron_watters
parents: 375
diff changeset
   753
    canvas.setFont("Times-BoldItalic", 8)
2ca856765ed1 various mods
aaron_watters
parents: 375
diff changeset
   754
    canvas.setFillGray(0)
2ca856765ed1 various mods
aaron_watters
parents: 375
diff changeset
   755
    canvas.drawCentredString(mx+mW/2.0, my+mH+3*dd, "Chapter 6: Lubricants")
2ca856765ed1 various mods
aaron_watters
parents: 375
diff changeset
   756
    canvas.setFont("Times-BoldItalic", 10)
2ca856765ed1 various mods
aaron_watters
parents: 375
diff changeset
   757
    canvas.drawCentredString(3*Wd+2*W+W/2, Hd+H-H/4, "College Life")
2ca856765ed1 various mods
aaron_watters
parents: 375
diff changeset
   758
274
6cf6b9ecf1f1 initial checkin. examples file for userguide generation
aaron_watters
parents:
diff changeset
   759
# D = dir()
6cf6b9ecf1f1 initial checkin. examples file for userguide generation
aaron_watters
parents:
diff changeset
   760
g = globals()
6cf6b9ecf1f1 initial checkin. examples file for userguide generation
aaron_watters
parents:
diff changeset
   761
Dprime = {}
6cf6b9ecf1f1 initial checkin. examples file for userguide generation
aaron_watters
parents:
diff changeset
   762
from types import StringType
6cf6b9ecf1f1 initial checkin. examples file for userguide generation
aaron_watters
parents:
diff changeset
   763
from string import strip
6cf6b9ecf1f1 initial checkin. examples file for userguide generation
aaron_watters
parents:
diff changeset
   764
for (a,b) in g.items():
6cf6b9ecf1f1 initial checkin. examples file for userguide generation
aaron_watters
parents:
diff changeset
   765
    if a[:4]=="test" and type(b) is StringType:
6cf6b9ecf1f1 initial checkin. examples file for userguide generation
aaron_watters
parents:
diff changeset
   766
        #print 'for', a
6cf6b9ecf1f1 initial checkin. examples file for userguide generation
aaron_watters
parents:
diff changeset
   767
        #print b
6cf6b9ecf1f1 initial checkin. examples file for userguide generation
aaron_watters
parents:
diff changeset
   768
        b = strip(b)
308
a09abac33167 Minor cosmetic changes
rgbecker
parents: 301
diff changeset
   769
        exec(b+'\n')
381
2ca856765ed1 various mods
aaron_watters
parents: 375
diff changeset
   770
        
2ca856765ed1 various mods
aaron_watters
parents: 375
diff changeset
   771
platypussetup = """
2ca856765ed1 various mods
aaron_watters
parents: 375
diff changeset
   772
from reportlab.platypus import SimpleDocTemplate, Paragraph, Spacer
2ca856765ed1 various mods
aaron_watters
parents: 375
diff changeset
   773
from reportlab.lib.styles import getSampleStyleSheet
2ca856765ed1 various mods
aaron_watters
parents: 375
diff changeset
   774
from reportlab.lib.pagesizes import DEFAULT_PAGE_SIZE
2ca856765ed1 various mods
aaron_watters
parents: 375
diff changeset
   775
from reportlab.lib.units import inch
2ca856765ed1 various mods
aaron_watters
parents: 375
diff changeset
   776
PAGE_HEIGHT=DEFAULT_PAGE_SIZE[1]; PAGE_WIDTH=DEFAULT_PAGE_SIZE[0]
2ca856765ed1 various mods
aaron_watters
parents: 375
diff changeset
   777
styles = getSampleStyleSheet()
2ca856765ed1 various mods
aaron_watters
parents: 375
diff changeset
   778
"""
2ca856765ed1 various mods
aaron_watters
parents: 375
diff changeset
   779
platypusfirstpage = """
2ca856765ed1 various mods
aaron_watters
parents: 375
diff changeset
   780
Title = "Hello world"
2ca856765ed1 various mods
aaron_watters
parents: 375
diff changeset
   781
pageinfo = "platypus example"
2ca856765ed1 various mods
aaron_watters
parents: 375
diff changeset
   782
def myFirstPage(canvas, doc):
2ca856765ed1 various mods
aaron_watters
parents: 375
diff changeset
   783
    canvas.saveState()
2ca856765ed1 various mods
aaron_watters
parents: 375
diff changeset
   784
    canvas.setFont('Times-Bold',16)
2ca856765ed1 various mods
aaron_watters
parents: 375
diff changeset
   785
    canvas.drawCentredString(PAGE_WIDTH/2.0, PAGE_HEIGHT-108, Title)
2ca856765ed1 various mods
aaron_watters
parents: 375
diff changeset
   786
    canvas.setFont('Times-Roman',9)
2ca856765ed1 various mods
aaron_watters
parents: 375
diff changeset
   787
    canvas.drawString(inch, 0.75 * inch, "First Page / %s" % pageinfo)
2ca856765ed1 various mods
aaron_watters
parents: 375
diff changeset
   788
    canvas.restoreState()
2ca856765ed1 various mods
aaron_watters
parents: 375
diff changeset
   789
"""
2ca856765ed1 various mods
aaron_watters
parents: 375
diff changeset
   790
platypusnextpage = """
2ca856765ed1 various mods
aaron_watters
parents: 375
diff changeset
   791
def myLaterPages(canvas, doc):
2ca856765ed1 various mods
aaron_watters
parents: 375
diff changeset
   792
    canvas.saveState()
2ca856765ed1 various mods
aaron_watters
parents: 375
diff changeset
   793
    canvas.setFont('Times-Roman',9)
2ca856765ed1 various mods
aaron_watters
parents: 375
diff changeset
   794
    canvas.drawString(inch, 0.75 * inch, "Page %d %s" % (doc.page, pageinfo))
2ca856765ed1 various mods
aaron_watters
parents: 375
diff changeset
   795
    canvas.restoreState()
2ca856765ed1 various mods
aaron_watters
parents: 375
diff changeset
   796
"""
2ca856765ed1 various mods
aaron_watters
parents: 375
diff changeset
   797
platypusgo = """
2ca856765ed1 various mods
aaron_watters
parents: 375
diff changeset
   798
def go():
2ca856765ed1 various mods
aaron_watters
parents: 375
diff changeset
   799
    doc = SimpleDocTemplate("phello.pdf")
2ca856765ed1 various mods
aaron_watters
parents: 375
diff changeset
   800
    Story = [Spacer(1,2*inch)]
2ca856765ed1 various mods
aaron_watters
parents: 375
diff changeset
   801
    style = styles["Normal"]
2ca856765ed1 various mods
aaron_watters
parents: 375
diff changeset
   802
    for i in range(100):
2ca856765ed1 various mods
aaron_watters
parents: 375
diff changeset
   803
        bogustext = ("This is Paragraph number %s.  " % i) *20
2ca856765ed1 various mods
aaron_watters
parents: 375
diff changeset
   804
        p = Paragraph(bogustext, style)
2ca856765ed1 various mods
aaron_watters
parents: 375
diff changeset
   805
        Story.append(p)
2ca856765ed1 various mods
aaron_watters
parents: 375
diff changeset
   806
        Story.append(Spacer(1,0.2*inch))
2ca856765ed1 various mods
aaron_watters
parents: 375
diff changeset
   807
    doc.build(Story, onFirstPage=myFirstPage, onLaterPages=myLaterPages)
2ca856765ed1 various mods
aaron_watters
parents: 375
diff changeset
   808
"""
2ca856765ed1 various mods
aaron_watters
parents: 375
diff changeset
   809
2ca856765ed1 various mods
aaron_watters
parents: 375
diff changeset
   810
if __name__=="__main__":
2ca856765ed1 various mods
aaron_watters
parents: 375
diff changeset
   811
    # then do the platypus hello world
2ca856765ed1 various mods
aaron_watters
parents: 375
diff changeset
   812
    for b in platypussetup, platypusfirstpage, platypusnextpage, platypusgo:
2ca856765ed1 various mods
aaron_watters
parents: 375
diff changeset
   813
        b = strip(b)
2ca856765ed1 various mods
aaron_watters
parents: 375
diff changeset
   814
        exec(b+'\n')
2ca856765ed1 various mods
aaron_watters
parents: 375
diff changeset
   815
    go()
2ca856765ed1 various mods
aaron_watters
parents: 375
diff changeset
   816