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

Revision 443, 5.9 kB (checked in by jerome, 16 years ago)

Changed copyright years.

  • 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, 2007 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
26ToolKit (tm) available as Free Software from :
27
28        http://www.reportlab.org
29
30It contains 10 pages, including this one.
31
32Each page after this one is entirely filled with 100%
33of a particular color, as described below :
34
35Page  1 ====> This notice
36Page  2 ====> Red
37Page  3 ====> Green
38Page  4 ====> Blue
39Page  5 ====> Cyan
40Page  6 ====> Magenta
41Page  7 ====> Yellow
42Page  8 ====> Black
43Page  9 ====> White
44Page 10 ====> The expected results.
45
46This document helps to ensure that the computation of
47ink coverage made by pkpgcounter works as expected.
48
49To check by yourself :
50
51  $ for cspace in BW RGB CMY CMYK ; do
52        echo "Colorspace : $cspace" ;
53        pkpgcounter --colorspace $cspace colors.pdf ;
54        echo ;
55    done   
56
57Please report any problem to : alet@librelogiciel.com
58"""
59
60lastpage = """For each colorspace, the results for the last page will differ a bit from what is below.
61The important values are the one for pages 2 to 9 included.
62
63Colorspace : BW
64B :   2.355336%
65B :  70.196078%
66B :  41.568627%
67B :  88.627451%
68B :  30.196078%
69B :  58.823529%
70B :  11.764706%
71B : 100.000000%
72B :   0.000000%
73B :   3.500669%
74
75Colorspace : RGB
76R :  97.644664%      G :  97.644664%      B :  97.644664%
77R : 100.000000%      G :   0.000000%      B :   0.000000%
78R :   0.000000%      G : 100.000000%      B :   0.000000%
79R :   0.000000%      G :   0.000000%      B : 100.000000%
80R :   0.000000%      G : 100.000000%      B : 100.000000%
81R : 100.000000%      G :   0.000000%      B : 100.000000%
82R : 100.000000%      G : 100.000000%      B :   0.000000%
83R :   0.000000%      G :   0.000000%      B :   0.000000%
84R : 100.000000%      G : 100.000000%      B : 100.000000%
85R :  96.499331%      G :  96.499331%      B :  96.499331%
86
87Colorspace : CMY
88C :   2.355336%      M :   2.355336%      Y :   2.355336%
89C :   0.000000%      M : 100.000000%      Y : 100.000000%
90C : 100.000000%      M :   0.000000%      Y : 100.000000%
91C : 100.000000%      M : 100.000000%      Y :   0.000000%
92C : 100.000000%      M :   0.000000%      Y :   0.000000%
93C :   0.000000%      M : 100.000000%      Y :   0.000000%
94C :   0.000000%      M :   0.000000%      Y : 100.000000%
95C : 100.000000%      M : 100.000000%      Y : 100.000000%
96C :   0.000000%      M :   0.000000%      Y :   0.000000%
97C :   3.500669%      M :   3.500669%      Y :   3.500669%
98
99Colorspace : CMYK
100C :   0.000000%      M :   0.000000%      Y :   0.000000%      K :   2.355336%
101C :   0.000000%      M : 100.000000%      Y : 100.000000%      K :   0.000000%
102C : 100.000000%      M :   0.000000%      Y : 100.000000%      K :   0.000000%
103C : 100.000000%      M : 100.000000%      Y :   0.000000%      K :   0.000000%
104C : 100.000000%      M :   0.000000%      Y :   0.000000%      K :   0.000000%
105C :   0.000000%      M : 100.000000%      Y :   0.000000%      K :   0.000000%
106C :   0.000000%      M :   0.000000%      Y : 100.000000%      K :   0.000000%
107C :   0.000000%      M :   0.000000%      Y :   0.000000%      K : 100.000000%
108C :   0.000000%      M :   0.000000%      Y :   0.000000%      K :   0.000000%
109C :   0.000000%      M :   0.000000%      Y :   0.000000%      K :   3.500669%
110"""
111
112import sys
113try :
114    from reportlab.lib import colors
115    from reportlab.lib import pagesizes
116    from reportlab.lib.units import cm
117    from reportlab.pdfgen import canvas
118except ImportError :   
119    sys.stderr.write("Please download and install ReportLab\n\tfrom http://www.reportlab.org\n")
120    sys.exit(-1)
121
122if __name__ == "__main__" :
123    canv = canvas.Canvas("colors.pdf", pagesize=pagesizes.A4)
124    (width, height) = pagesizes.A4
125    xbase = 2*cm
126    ybase = height - 2*cm
127   
128    # First we output the explanations on the first page.
129    canv.setFont("Courier", 14)
130    for line in __doc__.split("\n") :
131        canv.drawString(xbase, ybase, line)
132        ybase -= 18
133    canv.showPage()
134   
135    # Then we output each page
136    for color in (colors.Color(1, 0, 0),        # Red
137                  colors.Color(0, 1, 0),        # Green
138                  colors.Color(0, 0, 1)) :      # Blue
139        canv.setStrokeColorRGB(*color.rgb())         
140        canv.setFillColorRGB(*color.rgb())         
141        canv.rect(0, 0, width, height, fill=1)
142        canv.showPage()
143       
144    for color in (colors.CMYKColor(1, 0, 0, 0), # Cyan
145                  colors.CMYKColor(0, 1, 0, 0), # Magenta
146                  colors.CMYKColor(0, 0, 1, 0), # Yellow
147                  colors.CMYKColor(0, 0, 0, 1), # Black
148                  colors.CMYKColor(0, 0, 0, 0)) : # White
149        canv.setStrokeColorCMYK(*color.cmyk())         
150        canv.setFillColorCMYK(*color.cmyk())         
151        canv.rect(0, 0, width, height, fill=1)
152        canv.showPage()
153       
154    # Finally outputs the expected results.
155    canv.setFont("Helvetica-Bold", 16)
156    canv.drawCentredString(width/2.0, height-1.5*cm, "Expected Results :")
157    ybase = height - 3*cm
158    canv.setFont("Courier", 10)
159    for line in lastpage.split("\n") :
160        canv.drawString(xbase, ybase, line)
161        ybase -= 14
162    canv.showPage()
163       
164    canv.save()       
Note: See TracBrowser for help on using the browser.