reportlab/demos/colors/colortest.py
author rgbecker
Wed, 25 Oct 2000 08:57:46 +0000
changeset 494 54257447cfe9
parent 50 61a65ebe894d
child 1683 7fa753e4420a
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: 50
diff changeset
     1
#copyright ReportLab Inc. 2000
54257447cfe9 Changed to indirect copyright
rgbecker
parents: 50
diff changeset
     2
#see license.txt for license details
54257447cfe9 Changed to indirect copyright
rgbecker
parents: 50
diff changeset
     3
#history http://cvs.sourceforge.net/cgi-bin/cvsweb.cgi/reportlab/demos/colors/colortest.py?cvsroot=reportlab
54257447cfe9 Changed to indirect copyright
rgbecker
parents: 50
diff changeset
     4
#$Header: /tmp/reportlab/reportlab/demos/colors/colortest.py,v 1.2 2000/10/25 08:57:44 rgbecker Exp $
50
61a65ebe894d Initial checkin
andy_robinson
parents:
diff changeset
     5
import reportlab.pdfgen.canvas
61a65ebe894d Initial checkin
andy_robinson
parents:
diff changeset
     6
from reportlab.lib import colors
61a65ebe894d Initial checkin
andy_robinson
parents:
diff changeset
     7
from reportlab.lib.units import inch
61a65ebe894d Initial checkin
andy_robinson
parents:
diff changeset
     8
61a65ebe894d Initial checkin
andy_robinson
parents:
diff changeset
     9
61a65ebe894d Initial checkin
andy_robinson
parents:
diff changeset
    10
def run():
61a65ebe894d Initial checkin
andy_robinson
parents:
diff changeset
    11
    c = reportlab.pdfgen.canvas.Canvas('colortest.pdf')
61a65ebe894d Initial checkin
andy_robinson
parents:
diff changeset
    12
61a65ebe894d Initial checkin
andy_robinson
parents:
diff changeset
    13
    #do a test of CMYK interspersed with RGB
61a65ebe894d Initial checkin
andy_robinson
parents:
diff changeset
    14
61a65ebe894d Initial checkin
andy_robinson
parents:
diff changeset
    15
    #first do RGB values
61a65ebe894d Initial checkin
andy_robinson
parents:
diff changeset
    16
    framePage(c, 'Color Demo - RGB Space and CMYK spaces interspersed' )
61a65ebe894d Initial checkin
andy_robinson
parents:
diff changeset
    17
61a65ebe894d Initial checkin
andy_robinson
parents:
diff changeset
    18
    y = 700
61a65ebe894d Initial checkin
andy_robinson
parents:
diff changeset
    19
61a65ebe894d Initial checkin
andy_robinson
parents:
diff changeset
    20
    c.setFillColorRGB(0,0,0)
61a65ebe894d Initial checkin
andy_robinson
parents:
diff changeset
    21
    c.drawString(100, y, 'cyan')
61a65ebe894d Initial checkin
andy_robinson
parents:
diff changeset
    22
    c.setFillColorCMYK(1,0,0,0)
61a65ebe894d Initial checkin
andy_robinson
parents:
diff changeset
    23
    c.rect(200, y, 300, 30, fill=1)
61a65ebe894d Initial checkin
andy_robinson
parents:
diff changeset
    24
    y = y - 40
61a65ebe894d Initial checkin
andy_robinson
parents:
diff changeset
    25
61a65ebe894d Initial checkin
andy_robinson
parents:
diff changeset
    26
    c.setFillColorRGB(0,0,0)
61a65ebe894d Initial checkin
andy_robinson
parents:
diff changeset
    27
    c.drawString(100, y, 'red')
61a65ebe894d Initial checkin
andy_robinson
parents:
diff changeset
    28
    c.setFillColorRGB(1,0,0)
61a65ebe894d Initial checkin
andy_robinson
parents:
diff changeset
    29
    c.rect(200, y, 300, 30, fill=1)
61a65ebe894d Initial checkin
andy_robinson
parents:
diff changeset
    30
    y = y - 40
61a65ebe894d Initial checkin
andy_robinson
parents:
diff changeset
    31
    
61a65ebe894d Initial checkin
andy_robinson
parents:
diff changeset
    32
    c.setFillColorRGB(0,0,0)
61a65ebe894d Initial checkin
andy_robinson
parents:
diff changeset
    33
    c.drawString(100, y, 'magenta')
61a65ebe894d Initial checkin
andy_robinson
parents:
diff changeset
    34
    c.setFillColorCMYK(0,1,0,0)
61a65ebe894d Initial checkin
andy_robinson
parents:
diff changeset
    35
    c.rect(200, y, 300, 30, fill=1)
61a65ebe894d Initial checkin
andy_robinson
parents:
diff changeset
    36
    y = y - 40
61a65ebe894d Initial checkin
andy_robinson
parents:
diff changeset
    37
61a65ebe894d Initial checkin
andy_robinson
parents:
diff changeset
    38
    c.setFillColorRGB(0,0,0)
61a65ebe894d Initial checkin
andy_robinson
parents:
diff changeset
    39
    c.drawString(100, y, 'green')
61a65ebe894d Initial checkin
andy_robinson
parents:
diff changeset
    40
    c.setFillColorRGB(0,1,0)
61a65ebe894d Initial checkin
andy_robinson
parents:
diff changeset
    41
    c.rect(200, y, 300, 30, fill=1)
61a65ebe894d Initial checkin
andy_robinson
parents:
diff changeset
    42
    y = y - 40
61a65ebe894d Initial checkin
andy_robinson
parents:
diff changeset
    43
61a65ebe894d Initial checkin
andy_robinson
parents:
diff changeset
    44
    c.setFillColorRGB(0,0,0)
61a65ebe894d Initial checkin
andy_robinson
parents:
diff changeset
    45
    c.drawString(100, y, 'yellow')
61a65ebe894d Initial checkin
andy_robinson
parents:
diff changeset
    46
    c.setFillColorCMYK(0,0,1,0)
61a65ebe894d Initial checkin
andy_robinson
parents:
diff changeset
    47
    c.rect(200, y, 300, 30, fill=1)
61a65ebe894d Initial checkin
andy_robinson
parents:
diff changeset
    48
    y = y - 40
61a65ebe894d Initial checkin
andy_robinson
parents:
diff changeset
    49
    
61a65ebe894d Initial checkin
andy_robinson
parents:
diff changeset
    50
    c.setFillColorRGB(0,0,0)
61a65ebe894d Initial checkin
andy_robinson
parents:
diff changeset
    51
    c.drawString(100, y, 'blue')
61a65ebe894d Initial checkin
andy_robinson
parents:
diff changeset
    52
    c.setFillColorRGB(0,0,1)
61a65ebe894d Initial checkin
andy_robinson
parents:
diff changeset
    53
    c.rect(200, y, 300, 30, fill=1)
61a65ebe894d Initial checkin
andy_robinson
parents:
diff changeset
    54
    y = y - 40
61a65ebe894d Initial checkin
andy_robinson
parents:
diff changeset
    55
        
61a65ebe894d Initial checkin
andy_robinson
parents:
diff changeset
    56
    c.setFillColorRGB(0,0,0)
61a65ebe894d Initial checkin
andy_robinson
parents:
diff changeset
    57
    c.drawString(100, y, 'black')
61a65ebe894d Initial checkin
andy_robinson
parents:
diff changeset
    58
    c.setFillColorCMYK(0,0,0,1)
61a65ebe894d Initial checkin
andy_robinson
parents:
diff changeset
    59
    c.rect(200, y, 300, 30, fill=1)
61a65ebe894d Initial checkin
andy_robinson
parents:
diff changeset
    60
    y = y - 40
61a65ebe894d Initial checkin
andy_robinson
parents:
diff changeset
    61
61a65ebe894d Initial checkin
andy_robinson
parents:
diff changeset
    62
61a65ebe894d Initial checkin
andy_robinson
parents:
diff changeset
    63
    c.showPage()
61a65ebe894d Initial checkin
andy_robinson
parents:
diff changeset
    64
    
61a65ebe894d Initial checkin
andy_robinson
parents:
diff changeset
    65
    #do all named colors
61a65ebe894d Initial checkin
andy_robinson
parents:
diff changeset
    66
    framePage(c, 'Color Demo - RGB Space - page %d' % c.getPageNumber())
61a65ebe894d Initial checkin
andy_robinson
parents:
diff changeset
    67
61a65ebe894d Initial checkin
andy_robinson
parents:
diff changeset
    68
    all_colors = reportlab.lib.colors.getAllNamedColors().items()
61a65ebe894d Initial checkin
andy_robinson
parents:
diff changeset
    69
    all_colors.sort() # alpha order by name
61a65ebe894d Initial checkin
andy_robinson
parents:
diff changeset
    70
    c.setFont('Times-Roman', 12)
61a65ebe894d Initial checkin
andy_robinson
parents:
diff changeset
    71
    c.drawString(72,730, 'This shows all the named colors in the HTML standard.')
61a65ebe894d Initial checkin
andy_robinson
parents:
diff changeset
    72
    y = 700
61a65ebe894d Initial checkin
andy_robinson
parents:
diff changeset
    73
    for (name, color) in all_colors:
61a65ebe894d Initial checkin
andy_robinson
parents:
diff changeset
    74
        c.setFillColor(colors.black)
61a65ebe894d Initial checkin
andy_robinson
parents:
diff changeset
    75
        c.drawString(100, y, name)
61a65ebe894d Initial checkin
andy_robinson
parents:
diff changeset
    76
        c.setFillColor(color)
61a65ebe894d Initial checkin
andy_robinson
parents:
diff changeset
    77
        c.rect(200, y-10, 300, 30, fill=1)
61a65ebe894d Initial checkin
andy_robinson
parents:
diff changeset
    78
        y = y - 40
61a65ebe894d Initial checkin
andy_robinson
parents:
diff changeset
    79
        if y < 100:
61a65ebe894d Initial checkin
andy_robinson
parents:
diff changeset
    80
            c.showPage()
61a65ebe894d Initial checkin
andy_robinson
parents:
diff changeset
    81
            framePage(c, 'Color Demo - RGB Space - page %d' % c.getPageNumber())
61a65ebe894d Initial checkin
andy_robinson
parents:
diff changeset
    82
            y = 700
61a65ebe894d Initial checkin
andy_robinson
parents:
diff changeset
    83
61a65ebe894d Initial checkin
andy_robinson
parents:
diff changeset
    84
61a65ebe894d Initial checkin
andy_robinson
parents:
diff changeset
    85
61a65ebe894d Initial checkin
andy_robinson
parents:
diff changeset
    86
            
61a65ebe894d Initial checkin
andy_robinson
parents:
diff changeset
    87
    c.save()
61a65ebe894d Initial checkin
andy_robinson
parents:
diff changeset
    88
61a65ebe894d Initial checkin
andy_robinson
parents:
diff changeset
    89
def framePage(canvas, title):
61a65ebe894d Initial checkin
andy_robinson
parents:
diff changeset
    90
    canvas.setFont('Times-BoldItalic',20)
61a65ebe894d Initial checkin
andy_robinson
parents:
diff changeset
    91
    canvas.drawString(inch, 10.5 * inch, title)
61a65ebe894d Initial checkin
andy_robinson
parents:
diff changeset
    92
                            
61a65ebe894d Initial checkin
andy_robinson
parents:
diff changeset
    93
    canvas.setFont('Times-Roman',10)
61a65ebe894d Initial checkin
andy_robinson
parents:
diff changeset
    94
    canvas.drawCentredString(4.135 * inch, 0.75 * inch,
61a65ebe894d Initial checkin
andy_robinson
parents:
diff changeset
    95
                            'Page %d' % canvas.getPageNumber())
61a65ebe894d Initial checkin
andy_robinson
parents:
diff changeset
    96
    
61a65ebe894d Initial checkin
andy_robinson
parents:
diff changeset
    97
    #draw a border
61a65ebe894d Initial checkin
andy_robinson
parents:
diff changeset
    98
    canvas.setStrokeColorRGB(1,0,0)
61a65ebe894d Initial checkin
andy_robinson
parents:
diff changeset
    99
    canvas.setLineWidth(5)
61a65ebe894d Initial checkin
andy_robinson
parents:
diff changeset
   100
    canvas.line(0.8 * inch, inch, 0.8 * inch, 10.75 * inch)
61a65ebe894d Initial checkin
andy_robinson
parents:
diff changeset
   101
    #reset carefully afterwards
61a65ebe894d Initial checkin
andy_robinson
parents:
diff changeset
   102
    canvas.setLineWidth(1)
61a65ebe894d Initial checkin
andy_robinson
parents:
diff changeset
   103
    canvas.setStrokeColorRGB(0,0,0)
61a65ebe894d Initial checkin
andy_robinson
parents:
diff changeset
   104
61a65ebe894d Initial checkin
andy_robinson
parents:
diff changeset
   105
if __name__ == '__main__':
61a65ebe894d Initial checkin
andy_robinson
parents:
diff changeset
   106
    run()
494
54257447cfe9 Changed to indirect copyright
rgbecker
parents: 50
diff changeset
   107