merges from rel-1-2. Starting to get a little longer now. Being very
[koha.git] / barcodes.pl
1 #!/usr/bin/perl
2
3
4
5 ####################
6 # Variable Section #
7 ####################
8 my $pretext='T ';
9 my $startnumber=1000;
10 my $pages=2;
11 my $libraryname='Copper Mountain Elementary';
12
13 # Shifts are given in millimeters. Positive numbers move up and to the right.
14 # These variables shift the whole page to account for printer differences.
15 my $shiftx=0;
16 my $shifty=0;
17
18 ####################
19
20
21
22 my $leftmargin=5;
23 my $rightmargin=3;
24 my $topmargin=18;
25 my $botmargin=10;
26
27
28 my $rightside=215;
29 my $topside=280;
30
31
32 my $barcodewidth=length("$pretext$startnumber")+2;
33
34 my $bcwidthfactor=8-$barcodewidth/2;
35 print STDERR "$barcodewidth $bcwidthfactor\n";
36
37 my $width=$rightside-($leftmargin+$rightmargin);
38 my $height=$topside-$topmargin-$botmargin;
39
40 print << "EOF";
41 %!PS-Adobe-2.0
42 %%Title: barcode.ps
43 %%Creator: Willem van Schaik
44 %%CreationDate: aug 1992
45 %%Pages: 1
46 %%DocumentFonts: Helvetica Code39
47 %%BoundingBox: 0 0 595 842
48 %%EndComments
49
50 /newfont 10 dict def
51 newfont begin
52 /FontType 3 def
53 /FontMatrix [0.01 0 0 0.01 0 0] def
54 /FontBBox [0 0 100 100] def
55
56 /Encoding 256 array def
57 0 1 255 {Encoding exch /.notdef put} for
58 Encoding 32 /barSpace put
59 Encoding 36 /barDollar put
60 Encoding 37 /barPercent put
61 Encoding 42 /barAsterisk put
62 Encoding 43 /barPlus put
63 Encoding 45 /barHyphen put
64 Encoding 46 /barPeriod put
65 Encoding 47 /barSlash put
66 Encoding 48 /bar0 put
67 Encoding 49 /bar1 put
68 Encoding 50 /bar2 put
69 Encoding 51 /bar3 put
70 Encoding 52 /bar4 put
71 Encoding 53 /bar5 put
72 Encoding 54 /bar6 put
73 Encoding 55 /bar7 put
74 Encoding 56 /bar8 put
75 Encoding 57 /bar9 put
76 Encoding 65 /barA put
77 Encoding 66 /barB put
78 Encoding 67 /barC put
79 Encoding 68 /barD put
80 Encoding 69 /barE put
81 Encoding 70 /barF put
82 Encoding 71 /barG put
83 Encoding 72 /barH put
84 Encoding 73 /barI put
85 Encoding 74 /barJ put
86 Encoding 75 /barK put
87 Encoding 76 /barL put
88 Encoding 77 /barM put
89 Encoding 78 /barN put
90 Encoding 79 /barO put
91 Encoding 80 /barP put
92 Encoding 81 /barQ put
93 Encoding 82 /barR put
94 Encoding 83 /barS put
95 Encoding 84 /barT put
96 Encoding 85 /barU put
97 Encoding 86 /barV put
98 Encoding 87 /barW put
99 Encoding 88 /barX put
100 Encoding 89 /barY put
101 Encoding 90 /barZ put
102
103 /CharProcs 45 dict def
104 CharProcs begin
105 /.notdef {} def
106 /barSpace {0 7 17 17 7 7 7 17 7 7 newpath 93 0 moveto 5 {dup 0 100 rlineto
107 neg 0 rlineto 0 -100 rlineto closepath add neg 0 rmoveto} repeat fill} def
108 /barDollar {0 7 17 7 17 7 17 7 7 7 newpath 93 0 moveto 5 {dup 0 100 rlineto
109 neg 0 rlineto 0 -100 rlineto closepath add neg 0 rmoveto} repeat fill} def
110 /barPercent {0 7 7 7 17 7 17 7 17 7 newpath 93 0 moveto 5 {dup 0 100 rlineto
111 neg 0 rlineto 0 -100 rlineto closepath add neg 0 rmoveto} repeat fill} def
112 /barAsterisk {0 7 17 7 7 17 7 17 7 7 newpath 93 0 moveto 5 {dup 0 100 rlineto
113 neg 0 rlineto 0 -100 rlineto closepath add neg 0 rmoveto} repeat fill} def
114 /barPlus {0 7 17 7 7 7 17 7 17 7 newpath 93 0 moveto 5 {dup 0 100 rlineto
115 neg 0 rlineto 0 -100 rlineto closepath add neg 0 rmoveto} repeat fill} def
116 /barHyphen {0 7 17 7 7 7 7 17 7 17 newpath 93 0 moveto 5 {dup 0 100 rlineto
117 neg 0 rlineto 0 -100 rlineto closepath add neg 0 rmoveto} repeat fill} def
118 /barPeriod {0 17 17 7 7 7 7 17 7 7 newpath 93 0 moveto 5 {dup 0 100 rlineto
119 neg 0 rlineto 0 -100 rlineto closepath add neg 0 rmoveto} repeat fill} def
120 /barSlash {0 7 17 7 17 7 7 7 17 7 newpath 93 0 moveto 5 {dup 0 100 rlineto
121 neg 0 rlineto 0 -100 rlineto closepath add neg 0 rmoveto} repeat fill} def
122 /bar0 {0 7 7 7 17 17 7 17 7 7 newpath 93 0 moveto 5 {dup 0 100 rlineto
123 neg 0 rlineto 0 -100 rlineto closepath add neg 0 rmoveto} repeat fill} def
124 /bar1 {0 17 7 7 17 7 7 7 7 17 newpath 93 0 moveto 5 {dup 0 100 rlineto
125 neg 0 rlineto 0 -100 rlineto closepath add neg 0 rmoveto} repeat fill} def
126 /bar2 {0 7 7 17 17 7 7 7 7 17 newpath 93 0 moveto 5 {dup 0 100 rlineto
127 neg 0 rlineto 0 -100 rlineto closepath add neg 0 rmoveto} repeat fill} def
128 /bar3 {0 17 7 17 17 7 7 7 7 7 newpath 93 0 moveto 5 {dup 0 100 rlineto
129 neg 0 rlineto 0 -100 rlineto closepath add neg 0 rmoveto} repeat fill} def
130 /bar4 {0 7 7 7 17 17 7 7 7 17 newpath 93 0 moveto 5 {dup 0 100 rlineto
131 neg 0 rlineto 0 -100 rlineto closepath add neg 0 rmoveto} repeat fill} def
132 /bar5 {0 17 7 7 17 17 7 7 7 7 newpath 93 0 moveto 5 {dup 0 100 rlineto
133 neg 0 rlineto 0 -100 rlineto closepath add neg 0 rmoveto} repeat fill} def
134 /bar6 {0 7 7 17 17 17 7 7 7 7 newpath 93 0 moveto 5 {dup 0 100 rlineto
135 neg 0 rlineto 0 -100 rlineto closepath add neg 0 rmoveto} repeat fill} def
136 /bar7 {0 7 7 7 17 7 7 17 7 17 newpath 93 0 moveto 5 {dup 0 100 rlineto
137 neg 0 rlineto 0 -100 rlineto closepath add neg 0 rmoveto} repeat fill} def
138 /bar8 {0 17 7 7 17 7 7 17 7 7 newpath 93 0 moveto 5 {dup 0 100 rlineto
139 neg 0 rlineto 0 -100 rlineto closepath add neg 0 rmoveto} repeat fill} def
140 /bar9 {0 7 7 17 17 7 7 17 7 7 newpath 93 0 moveto 5 {dup 0 100 rlineto
141 neg 0 rlineto 0 -100 rlineto closepath add neg 0 rmoveto} repeat fill} def
142 /barA {0 17 7 7 7 7 17 7 7 17 newpath 93 0 moveto 5 {dup 0 100 rlineto
143 neg 0 rlineto 0 -100 rlineto closepath add neg 0 rmoveto} repeat fill} def
144 /barB {0 7 7 17 7 7 17 7 7 17 newpath 93 0 moveto 5 {dup 0 100 rlineto
145 neg 0 rlineto 0 -100 rlineto closepath add neg 0 rmoveto} repeat fill} def
146 /barC {0 17 7 17 7 7 17 7 7 7 newpath 93 0 moveto 5 {dup 0 100 rlineto
147 neg 0 rlineto 0 -100 rlineto closepath add neg 0 rmoveto} repeat fill} def
148 /barD {0 7 7 7 7 17 17 7 7 17 newpath 93 0 moveto 5 {dup 0 100 rlineto
149 neg 0 rlineto 0 -100 rlineto closepath add neg 0 rmoveto} repeat fill} def
150 /barE {0 17 7 7 7 17 17 7 7 7 newpath 93 0 moveto 5 {dup 0 100 rlineto
151 neg 0 rlineto 0 -100 rlineto closepath add neg 0 rmoveto} repeat fill} def
152 /barF {0 7 7 17 7 17 17 7 7 7 newpath 93 0 moveto 5 {dup 0 100 rlineto
153 neg 0 rlineto 0 -100 rlineto closepath add neg 0 rmoveto} repeat fill} def
154 /barG {0 7 7 7 7 7 17 17 7 17 newpath 93 0 moveto 5 {dup 0 100 rlineto
155 neg 0 rlineto 0 -100 rlineto closepath add neg 0 rmoveto} repeat fill} def
156 /barH {0 17 7 7 7 7 17 17 7 7 newpath 93 0 moveto 5 {dup 0 100 rlineto
157 neg 0 rlineto 0 -100 rlineto closepath add neg 0 rmoveto} repeat fill} def
158 /barI {0 7 7 17 7 7 17 17 7 7 newpath 93 0 moveto 5 {dup 0 100 rlineto
159 neg 0 rlineto 0 -100 rlineto closepath add neg 0 rmoveto} repeat fill} def
160 /barJ {0 7 7 7 7 17 17 17 7 7 newpath 93 0 moveto 5 {dup 0 100 rlineto
161 neg 0 rlineto 0 -100 rlineto closepath add neg 0 rmoveto} repeat fill} def
162 /barK {0 17 7 7 7 7 7 7 17 17 newpath 93 0 moveto 5 {dup 0 100 rlineto
163 neg 0 rlineto 0 -100 rlineto closepath add neg 0 rmoveto} repeat fill} def
164 /barL {0 7 7 17 7 7 7 7 17 17 newpath 93 0 moveto 5 {dup 0 100 rlineto
165 neg 0 rlineto 0 -100 rlineto closepath add neg 0 rmoveto} repeat fill} def
166 /barM {0 17 7 17 7 7 7 7 17 7 newpath 93 0 moveto 5 {dup 0 100 rlineto
167 neg 0 rlineto 0 -100 rlineto closepath add neg 0 rmoveto} repeat fill} def
168 /barN {0 7 7 7 7 17 7 7 17 17 newpath 93 0 moveto 5 {dup 0 100 rlineto
169 neg 0 rlineto 0 -100 rlineto closepath add neg 0 rmoveto} repeat fill} def
170 /barO {0 17 7 7 7 17 7 7 17 7 newpath 93 0 moveto 5 {dup 0 100 rlineto
171 neg 0 rlineto 0 -100 rlineto closepath add neg 0 rmoveto} repeat fill} def
172 /barP {0 7 7 17 7 17 7 7 17 7 newpath 93 0 moveto 5 {dup 0 100 rlineto
173 neg 0 rlineto 0 -100 rlineto closepath add neg 0 rmoveto} repeat fill} def
174 /barQ {0 7 7 7 7 7 7 17 17 17 newpath 93 0 moveto 5 {dup 0 100 rlineto
175 neg 0 rlineto 0 -100 rlineto closepath add neg 0 rmoveto} repeat fill} def
176 /barR {0 17 7 7 7 7 7 17 17 7 newpath 93 0 moveto 5 {dup 0 100 rlineto
177 neg 0 rlineto 0 -100 rlineto closepath add neg 0 rmoveto} repeat fill} def
178 /barS {0 7 7 17 7 7 7 17 17 7 newpath 93 0 moveto 5 {dup 0 100 rlineto
179 neg 0 rlineto 0 -100 rlineto closepath add neg 0 rmoveto} repeat fill} def
180 /barT {0 7 7 7 7 17 7 17 17 7 newpath 93 0 moveto 5 {dup 0 100 rlineto
181 neg 0 rlineto 0 -100 rlineto closepath add neg 0 rmoveto} repeat fill} def
182 /barU {0 17 17 7 7 7 7 7 7 17 newpath 93 0 moveto 5 {dup 0 100 rlineto
183 neg 0 rlineto 0 -100 rlineto closepath add neg 0 rmoveto} repeat fill} def
184 /barV {0 7 17 17 7 7 7 7 7 17 newpath 93 0 moveto 5 {dup 0 100 rlineto
185 neg 0 rlineto 0 -100 rlineto closepath add neg 0 rmoveto} repeat fill} def
186 /barW {0 17 17 17 7 7 7 7 7 7 newpath 93 0 moveto 5 {dup 0 100 rlineto
187 neg 0 rlineto 0 -100 rlineto closepath add neg 0 rmoveto} repeat fill} def
188 /barX {0 7 17 7 7 17 7 7 7 17 newpath 93 0 moveto 5 {dup 0 100 rlineto
189 neg 0 rlineto 0 -100 rlineto closepath add neg 0 rmoveto} repeat fill} def
190 /barY {0 17 17 7 7 17 7 7 7 7 newpath 93 0 moveto 5 {dup 0 100 rlineto
191 neg 0 rlineto 0 -100 rlineto closepath add neg 0 rmoveto} repeat fill} def
192 /barZ {0 7 17 17 7 17 7 7 7 7 newpath 93 0 moveto 5 {dup 0 100 rlineto
193 neg 0 rlineto 0 -100 rlineto closepath add neg 0 rmoveto} repeat fill} def
194 end
195
196 /BuildChar
197 { 100 0 0 0 93 100 setcachedevice
198   exch
199   begin
200     Encoding exch get
201     CharProcs exch get
202     end
203   exec
204 } def
205 end
206
207 /Code39 newfont definefont pop
208
209 %%EndProlog
210
211 EOF
212
213 my $number=$startnumber;
214 while ($page<$pages) {
215     my $data='';
216     for ($i=$leftmargin; $i<$rightside-$rightmargin; $i+=$width/4) {
217         for ($j=$botmargin; $j<$topside-$topmargin-$botmargin; $j+=$height/20) {
218             my $x=$i+$width/8;
219             my $y=$j+$height/40;
220             my $schooly=$y+5.8;
221             my $labely=$y-2.2;
222             my $lox=$x-2;
223             my $hix=$x+2;
224             my $loy=$y-2;
225             my $hiy=$y+2;
226             $data.=<<"EOF";
227 $x $y moveto
228 /Code39 findfont [$bcwidthfactor 0 0 5 0 0] makefont setfont
229 (*$pretext$number*) dup stringwidth pop 2 div neg 0 rmoveto show
230 /Helvetica findfont 1.7 scalefont setfont
231 $x $schooly moveto
232 ($schoolname) dup stringwidth pop 2 div neg 0 rmoveto show
233 /Helvetica findfont 2.3 scalefont setfont
234 $x $labely moveto
235 ($pretext$number) dup stringwidth pop 2 div neg 0 rmoveto show
236
237
238 EOF
239             $number++;
240         }
241     }
242
243
244     $page++;
245     print << "EOF";
246 %%Page: $page $page
247 %%PagerFonts:
248
249 $shiftx $shifty translate
250 72 25.4 div dup scale
251
252 /Code39 findfont [4 0 0 5 0 0] makefont setfont
253 /Times-Roman findfont
254 1 scalefont
255 setfont
256 $data
257
258
259
260
261
262 showpage
263
264
265 EOF
266 }
267 print "%%Trailer\n";