[380] | 1 | #! /usr/bin/env python |
---|
[564] | 2 | # -*- coding: UTF-8 -*- |
---|
[380] | 3 | # |
---|
| 4 | # pkpgcounter : a generic Page Description Language parser |
---|
| 5 | # |
---|
[564] | 6 | # (c) 2003, 2004, 2005, 2006, 2007, 2008 Jerome Alet <alet@librelogiciel.com> |
---|
[463] | 7 | # This program is free software: you can redistribute it and/or modify |
---|
[380] | 8 | # it under the terms of the GNU General Public License as published by |
---|
[463] | 9 | # the Free Software Foundation, either version 3 of the License, or |
---|
[380] | 10 | # (at your option) any later version. |
---|
[463] | 11 | # |
---|
[380] | 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 |
---|
[463] | 18 | # along with this program. If not, see <http://www.gnu.org/licenses/>. |
---|
[380] | 19 | # |
---|
| 20 | # $Id$ |
---|
| 21 | # |
---|
| 22 | # |
---|
| 23 | |
---|
[405] | 24 | """This document was created with the help of the ReportLab |
---|
| 25 | ToolKit (tm) available as Free Software from : |
---|
[380] | 26 | |
---|
[405] | 27 | http://www.reportlab.org |
---|
[380] | 28 | |
---|
[405] | 29 | It contains 10 pages, including this one. |
---|
[380] | 30 | |
---|
[405] | 31 | Each page after this one is entirely filled with 100% |
---|
| 32 | of a particular color, as described below : |
---|
[380] | 33 | |
---|
[405] | 34 | Page 1 ====> This notice |
---|
| 35 | Page 2 ====> Red |
---|
| 36 | Page 3 ====> Green |
---|
| 37 | Page 4 ====> Blue |
---|
| 38 | Page 5 ====> Cyan |
---|
| 39 | Page 6 ====> Magenta |
---|
| 40 | Page 7 ====> Yellow |
---|
| 41 | Page 8 ====> Black |
---|
| 42 | Page 9 ====> White |
---|
| 43 | Page 10 ====> The expected results. |
---|
[380] | 44 | |
---|
[405] | 45 | This document helps to ensure that the computation of |
---|
| 46 | ink coverage made by pkpgcounter works as expected. |
---|
| 47 | |
---|
[380] | 48 | To 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 | |
---|
| 56 | Please report any problem to : alet@librelogiciel.com |
---|
| 57 | """ |
---|
| 58 | |
---|
[405] | 59 | lastpage = """For each colorspace, the results for the last page will differ a bit from what is below. |
---|
| 60 | The important values are the one for pages 2 to 9 included. |
---|
| 61 | |
---|
| 62 | Colorspace : BW |
---|
| 63 | B : 2.355336% |
---|
| 64 | B : 70.196078% |
---|
| 65 | B : 41.568627% |
---|
| 66 | B : 88.627451% |
---|
| 67 | B : 30.196078% |
---|
| 68 | B : 58.823529% |
---|
| 69 | B : 11.764706% |
---|
| 70 | B : 100.000000% |
---|
| 71 | B : 0.000000% |
---|
| 72 | B : 3.500669% |
---|
| 73 | |
---|
| 74 | Colorspace : RGB |
---|
| 75 | R : 97.644664% G : 97.644664% B : 97.644664% |
---|
| 76 | R : 100.000000% G : 0.000000% B : 0.000000% |
---|
| 77 | R : 0.000000% G : 100.000000% B : 0.000000% |
---|
| 78 | R : 0.000000% G : 0.000000% B : 100.000000% |
---|
| 79 | R : 0.000000% G : 100.000000% B : 100.000000% |
---|
| 80 | R : 100.000000% G : 0.000000% B : 100.000000% |
---|
| 81 | R : 100.000000% G : 100.000000% B : 0.000000% |
---|
| 82 | R : 0.000000% G : 0.000000% B : 0.000000% |
---|
| 83 | R : 100.000000% G : 100.000000% B : 100.000000% |
---|
| 84 | R : 96.499331% G : 96.499331% B : 96.499331% |
---|
| 85 | |
---|
| 86 | Colorspace : CMY |
---|
| 87 | C : 2.355336% M : 2.355336% Y : 2.355336% |
---|
| 88 | C : 0.000000% M : 100.000000% Y : 100.000000% |
---|
| 89 | C : 100.000000% M : 0.000000% Y : 100.000000% |
---|
| 90 | C : 100.000000% M : 100.000000% Y : 0.000000% |
---|
| 91 | C : 100.000000% M : 0.000000% Y : 0.000000% |
---|
| 92 | C : 0.000000% M : 100.000000% Y : 0.000000% |
---|
| 93 | C : 0.000000% M : 0.000000% Y : 100.000000% |
---|
| 94 | C : 100.000000% M : 100.000000% Y : 100.000000% |
---|
| 95 | C : 0.000000% M : 0.000000% Y : 0.000000% |
---|
| 96 | C : 3.500669% M : 3.500669% Y : 3.500669% |
---|
| 97 | |
---|
| 98 | Colorspace : CMYK |
---|
| 99 | C : 0.000000% M : 0.000000% Y : 0.000000% K : 2.355336% |
---|
| 100 | C : 0.000000% M : 100.000000% Y : 100.000000% K : 0.000000% |
---|
| 101 | C : 100.000000% M : 0.000000% Y : 100.000000% K : 0.000000% |
---|
| 102 | C : 100.000000% M : 100.000000% Y : 0.000000% K : 0.000000% |
---|
| 103 | C : 100.000000% M : 0.000000% Y : 0.000000% K : 0.000000% |
---|
| 104 | C : 0.000000% M : 100.000000% Y : 0.000000% K : 0.000000% |
---|
| 105 | C : 0.000000% M : 0.000000% Y : 100.000000% K : 0.000000% |
---|
| 106 | C : 0.000000% M : 0.000000% Y : 0.000000% K : 100.000000% |
---|
| 107 | C : 0.000000% M : 0.000000% Y : 0.000000% K : 0.000000% |
---|
| 108 | C : 0.000000% M : 0.000000% Y : 0.000000% K : 3.500669% |
---|
| 109 | """ |
---|
| 110 | |
---|
[380] | 111 | import sys |
---|
| 112 | try : |
---|
| 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 |
---|
| 117 | except ImportError : |
---|
| 118 | sys.stderr.write("Please download and install ReportLab\n\tfrom http://www.reportlab.org\n") |
---|
| 119 | sys.exit(-1) |
---|
| 120 | |
---|
| 121 | if __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. |
---|
[405] | 128 | canv.setFont("Courier", 14) |
---|
[380] | 129 | for line in __doc__.split("\n") : |
---|
| 130 | canv.drawString(xbase, ybase, line) |
---|
[405] | 131 | ybase -= 18 |
---|
[380] | 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() |
---|
[405] | 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 | |
---|
[380] | 163 | canv.save() |
---|