root / pkpgcounter / trunk / tests / runcolors.py @ 381

Revision 381, 3.2 kB (checked in by jerome, 18 years ago)

Added svn:keywords property.

  • Property svn:eol-style set to native
  • Property svn:executable set to *
  • Property svn:keywords set to Author Date Id Revision
Line 
1#! /usr/bin/env python
2# -*- coding: ISO-8859-15 -*-
3#
4# pkpgcounter : a generic Page Description Language parser
5#
6# (c) 2003, 2004, 2005, 2006 Jerome Alet <alet@librelogiciel.com>
7# This program is free software; you can redistribute it and/or modify
8# it under the terms of the GNU General Public License as published by
9# the Free Software Foundation; either version 2 of the License, or
10# (at your option) any later version.
11#
12# This program is distributed in the hope that it will be useful,
13# but WITHOUT ANY WARRANTY; without even the implied warranty of
14# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15# GNU General Public License for more details.
16#
17# You should have received a copy of the GNU General Public License
18# along with this program; if not, write to the Free Software
19# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
20#
21# $Id$
22#
23#
24
25"""This document was created with the help of the ReportLab ToolKit (tm)
26available as Free Software from http://www.reportlab.org
27
28It contains 9 pages, including this one.
29
30Each page after this one is entirely filled with 100% of a particular
31color, as described below :
32
33Page 1 ====> This notice
34Page 2 ====> Red
35Page 3 ====> Green
36Page 4 ====> Blue
37Page 5 ====> Cyan
38Page 6 ====> Magenta
39Page 7 ====> Yellow
40Page 8 ====> Black
41Page 9 ====> White
42
43This document helps to ensure that the computation of ink coverage
44made by pkpgcounter works as expected.
45
46To check by yourself :
47
48  $ for cspace in BW RGB CMY CMYK ; do
49        echo "Colorspace : $cspace" ;
50        pkpgcounter --colorspace $cspace colors.pdf ;
51        echo ;
52    done   
53
54Please report any problem to : alet@librelogiciel.com
55"""
56
57import sys
58try :
59    from reportlab.lib import colors
60    from reportlab.lib import pagesizes
61    from reportlab.lib.units import cm
62    from reportlab.pdfgen import canvas
63except ImportError :   
64    sys.stderr.write("Please download and install ReportLab\n\tfrom http://www.reportlab.org\n")
65    sys.exit(-1)
66
67if __name__ == "__main__" :
68    canv = canvas.Canvas("colors.pdf", pagesize=pagesizes.A4)
69    (width, height) = pagesizes.A4
70    xbase = 2*cm
71    ybase = height - 2*cm
72   
73    # First we output the explanations on the first page.
74    canv.setFont("Helvetica", 16)
75    for line in __doc__.split("\n") :
76        canv.drawString(xbase, ybase, line)
77        ybase -= 24
78    canv.showPage()
79   
80    # Then we output each page
81    for color in (colors.Color(1, 0, 0),        # Red
82                  colors.Color(0, 1, 0),        # Green
83                  colors.Color(0, 0, 1)) :      # Blue
84        canv.setStrokeColorRGB(*color.rgb())         
85        canv.setFillColorRGB(*color.rgb())         
86        canv.rect(0, 0, width, height, fill=1)
87        canv.showPage()
88       
89    for color in (colors.CMYKColor(1, 0, 0, 0), # Cyan
90                  colors.CMYKColor(0, 1, 0, 0), # Magenta
91                  colors.CMYKColor(0, 0, 1, 0), # Yellow
92                  colors.CMYKColor(0, 0, 0, 1), # Black
93                  colors.CMYKColor(0, 0, 0, 0)) : # White
94        canv.setStrokeColorCMYK(*color.cmyk())         
95        canv.setFillColorCMYK(*color.cmyk())         
96        canv.rect(0, 0, width, height, fill=1)
97        canv.showPage()
98    canv.save()       
Note: See TracBrowser for help on using the browser.