File: runcolors.py

package info (click to toggle)
pkpgcounter 3.50-7.1
  • links: PTS, VCS
  • area: main
  • in suites: stretch
  • size: 544 kB
  • ctags: 295
  • sloc: python: 2,934; makefile: 39; sh: 37
file content (163 lines) | stat: -rwxr-xr-x 6,026 bytes parent folder | download | duplicates (4)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
#! /usr/bin/env python
# -*- coding: ISO-8859-15 -*-
#
# pkpgcounter : a generic Page Description Language parser
#
# (c) 2003, 2004, 2005, 2006, 2007 Jerome Alet <alet@librelogiciel.com>
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
# 
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
# 
# You should have received a copy of the GNU General Public License
# along with this program.  If not, see <http://www.gnu.org/licenses/>.
#
# $Id: runcolors.py 282 2007-09-10 20:47:40Z jerome $
#
#

"""This document was created with the help of the ReportLab
ToolKit (tm) available as Free Software from :

        http://www.reportlab.org

It contains 10 pages, including this one.

Each page after this one is entirely filled with 100%
of a particular color, as described below :

Page  1 ====> This notice
Page  2 ====> Red
Page  3 ====> Green
Page  4 ====> Blue
Page  5 ====> Cyan
Page  6 ====> Magenta
Page  7 ====> Yellow
Page  8 ====> Black
Page  9 ====> White
Page 10 ====> The expected results.

This document helps to ensure that the computation of
ink coverage made by pkpgcounter works as expected.

To check by yourself :

  $ for cspace in BW RGB CMY CMYK ; do
        echo "Colorspace : $cspace" ;
        pkpgcounter --colorspace $cspace colors.pdf ;
        echo ;
    done    

Please report any problem to : alet@librelogiciel.com
"""

lastpage = """For each colorspace, the results for the last page will differ a bit from what is below.
The important values are the one for pages 2 to 9 included.

Colorspace : BW
B :   2.355336%
B :  70.196078%
B :  41.568627%
B :  88.627451%
B :  30.196078%
B :  58.823529%
B :  11.764706%
B : 100.000000%
B :   0.000000%
B :   3.500669%

Colorspace : RGB
R :  97.644664%      G :  97.644664%      B :  97.644664%
R : 100.000000%      G :   0.000000%      B :   0.000000%
R :   0.000000%      G : 100.000000%      B :   0.000000%
R :   0.000000%      G :   0.000000%      B : 100.000000%
R :   0.000000%      G : 100.000000%      B : 100.000000%
R : 100.000000%      G :   0.000000%      B : 100.000000%
R : 100.000000%      G : 100.000000%      B :   0.000000%
R :   0.000000%      G :   0.000000%      B :   0.000000%
R : 100.000000%      G : 100.000000%      B : 100.000000%
R :  96.499331%      G :  96.499331%      B :  96.499331%

Colorspace : CMY
C :   2.355336%      M :   2.355336%      Y :   2.355336%
C :   0.000000%      M : 100.000000%      Y : 100.000000%
C : 100.000000%      M :   0.000000%      Y : 100.000000%
C : 100.000000%      M : 100.000000%      Y :   0.000000%
C : 100.000000%      M :   0.000000%      Y :   0.000000%
C :   0.000000%      M : 100.000000%      Y :   0.000000%
C :   0.000000%      M :   0.000000%      Y : 100.000000%
C : 100.000000%      M : 100.000000%      Y : 100.000000%
C :   0.000000%      M :   0.000000%      Y :   0.000000%
C :   3.500669%      M :   3.500669%      Y :   3.500669%

Colorspace : CMYK
C :   0.000000%      M :   0.000000%      Y :   0.000000%      K :   2.355336%
C :   0.000000%      M : 100.000000%      Y : 100.000000%      K :   0.000000%
C : 100.000000%      M :   0.000000%      Y : 100.000000%      K :   0.000000%
C : 100.000000%      M : 100.000000%      Y :   0.000000%      K :   0.000000%
C : 100.000000%      M :   0.000000%      Y :   0.000000%      K :   0.000000%
C :   0.000000%      M : 100.000000%      Y :   0.000000%      K :   0.000000%
C :   0.000000%      M :   0.000000%      Y : 100.000000%      K :   0.000000%
C :   0.000000%      M :   0.000000%      Y :   0.000000%      K : 100.000000%
C :   0.000000%      M :   0.000000%      Y :   0.000000%      K :   0.000000%
C :   0.000000%      M :   0.000000%      Y :   0.000000%      K :   3.500669%
"""

import sys
try :
    from reportlab.lib import colors
    from reportlab.lib import pagesizes
    from reportlab.lib.units import cm
    from reportlab.pdfgen import canvas
except ImportError :    
    sys.stderr.write("Please download and install ReportLab\n\tfrom http://www.reportlab.org\n")
    sys.exit(-1)

if __name__ == "__main__" :
    canv = canvas.Canvas("colors.pdf", pagesize=pagesizes.A4)
    (width, height) = pagesizes.A4
    xbase = 2*cm
    ybase = height - 2*cm
    
    # First we output the explanations on the first page.
    canv.setFont("Courier", 14)
    for line in __doc__.split("\n") :
        canv.drawString(xbase, ybase, line)
        ybase -= 18
    canv.showPage()
    
    # Then we output each page
    for color in (colors.Color(1, 0, 0),        # Red
                  colors.Color(0, 1, 0),        # Green
                  colors.Color(0, 0, 1)) :      # Blue
        canv.setStrokeColorRGB(*color.rgb())          
        canv.setFillColorRGB(*color.rgb())          
        canv.rect(0, 0, width, height, fill=1)
        canv.showPage()
        
    for color in (colors.CMYKColor(1, 0, 0, 0), # Cyan
                  colors.CMYKColor(0, 1, 0, 0), # Magenta
                  colors.CMYKColor(0, 0, 1, 0), # Yellow
                  colors.CMYKColor(0, 0, 0, 1), # Black
                  colors.CMYKColor(0, 0, 0, 0)) : # White
        canv.setStrokeColorCMYK(*color.cmyk())          
        canv.setFillColorCMYK(*color.cmyk())          
        canv.rect(0, 0, width, height, fill=1)
        canv.showPage()
        
    # Finally outputs the expected results.
    canv.setFont("Helvetica-Bold", 16)
    canv.drawCentredString(width/2.0, height-1.5*cm, "Expected Results :")
    ybase = height - 3*cm
    canv.setFont("Courier", 10)
    for line in lastpage.split("\n") :
        canv.drawString(xbase, ybase, line)
        ybase -= 14
    canv.showPage()
        
    canv.save()