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

Revision 564, 5.8 kB (checked in by jerome, 17 years ago)

Changed copyright years.
Removed unnecessary shebang lines.
Changed default encoding to UTF-8 from ISO-8859-15 (only
ascii is used anyway).

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