Repository navigation
Expand file tree
/
Copy pathposicode.ps.src
More file actions
713 lines (641 loc) · 23.7 KB
/
Copy pathposicode.ps.src
File metadata and controls
713 lines (641 loc) · 23.7 KB
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
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
% Barcode Writer in Pure PostScript
% https://bwipp.terryburton.co.uk
%
% vim: set sw=4 sts=4 et:
%
% Copyright (c) 2004-2026 Terry Burton
%
% $Id$
%
% Permission is hereby granted, free of charge, to any
% person obtaining a copy of this software and associated
% documentation files (the "Software"), to deal in the
% Software without restriction, including without
% limitation the rights to use, copy, modify, merge,
% publish, distribute, sublicense, and/or sell copies of
% the Software, and to permit persons to whom the Software
% is furnished to do so, subject to the following
% conditions:
%
% The above copyright notice and this permission notice
% shall be included in all copies or substantial portions
% of the Software.
%
% THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY
% KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO
% THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A
% PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
% THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
% DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF
% CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
% CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
% IN THE SOFTWARE.
% --BEGIN ENCODER posicode--
% --REQUIRES preamble raiseerror setuphooks processoptions parseinput setanycolor render renlinear renmatrix--
% --DESC: PosiCode
% --EXAM: ABC123
% --EXOP: version=b inkspread=-0.5 parsefnc includetext
% --RNDR: renlinear
% --FMLY: Less-used Symbols
currentglobal
true setglobal
/setpacking where {pop currentpacking true setpacking} if
18 dict
dup /raiseerror dup /uk.co.terryburton.bwipp findresource put
dup /processoptions dup /uk.co.terryburton.bwipp findresource put
dup /parseinput dup /uk.co.terryburton.bwipp findresource put
dup /render dup /uk.co.terryburton.bwipp findresource put
dup /renlinear dup /uk.co.terryburton.bwipp findresource put
dup /renmatrix dup /uk.co.terryburton.bwipp findresource put
begin
%
% Special function characters
%
/posicode.la0 -1 def /posicode.la1 -2 def /posicode.la2 -3 def
/posicode.sf0 -4 def /posicode.sf1 -5 def /posicode.sf2 -6 def
/posicode.fn1 -7 def /posicode.fn2 -8 def /posicode.fn3 -9 def /posicode.fn4 -10 def
/posicode.fna -11 def % FNC1 in second position, after an AIM application indicator
/la0 //posicode.la0 def /la1 //posicode.la1 def /la2 //posicode.la2 def
/sf0 //posicode.sf0 def /sf1 //posicode.sf1 def /sf2 //posicode.sf2 def
/fn1 //posicode.fn1 def /fn2 //posicode.fn2 def /fn3 //posicode.fn3 def /fn4 //posicode.fn4 def
%
% Character maps for each state
%
/posicode.charmapsnormal [
% 0 1 2 0 1 2 0 1 2
[ (0) (^) (') ] [ (1) (;) 27 ] [ (2) (<) 28 ] % 0-2
[ (3) (=) 29 ] [ (4) (>) 30 ] [ (5) (?) 31 ] % 3-5
[ (6) (@) (!) ] [ (7) ([) (") ] [ (8) 92 (#) ] % 6-8
[ (9) (]) (&) ] [ (A) (a) 1 ] [ (B) (b) 2 ] % 9-11
[ (C) (c) 3 ] [ (D) (d) 4 ] [ (E) (e) 5 ] % 12-14
[ (F) (f) 6 ] [ (G) (g) 7 ] [ (H) (h) 8 ] % 15-17
[ (I) (i) 9 ] [ (J) (j) 10 ] [ (K) (k) 11 ] % 18-20
[ (L) (l) 12 ] [ (M) (m) 13 ] [ (N) (n) 14 ] % 21-23
[ (O) (o) 15 ] [ (P) (p) 16 ] [ (Q) (q) 17 ] % 24-26
[ (R) (r) 18 ] [ (S) (s) 19 ] [ (T) (t) 20 ] % 27-29
[ (U) (u) 21 ] [ (V) (v) 22 ] [ (W) (w) 23 ] % 30-32
[ (X) (x) 24 ] [ (Y) (y) 25 ] [ (Z) (z) 26 ] % 33-35
[ (-) (_) 40 ] [ (.) (`) 41 ] [ ( ) 127 0 ] % 36-38
[ ($) ({) (*) ] [ (/) (|) (,) ] [ (+) (}) (:) ] % 39-41
[ (%) (~) fn1 ] [ la1 la0 fn2 ] [ sf1 sf0 fn3 ] % 42-44
[ sf2 sf2 fn4 ] % 45
] readonly def
/posicode.charmapslimited [
[ (0) -98 -98 ] [ (1) -98 -98 ] [ (2) -98 -98 ] % 0-2
[ (3) -98 -98 ] [ (4) -98 -98 ] [ (5) -98 -98 ] % 3-5
[ (6) -98 -98 ] [ (7) -98 -98 ] [ (8) -98 -98 ] % 6-8
[ (9) -98 -98 ] [ (A) -98 -98 ] [ (B) -98 -98 ] % 9-11
[ (C) -98 -98 ] [ (D) -98 -98 ] [ (E) -98 -98 ] % 12-14
[ (F) -98 -98 ] [ (G) -98 -98 ] [ (H) -98 -98 ] % 15-17
[ (I) -98 -98 ] [ (J) -98 -98 ] [ (K) -98 -98 ] % 18-20
[ (L) -98 -98 ] [ (M) -98 -98 ] [ (N) -98 -98 ] % 21-23
[ (O) -98 -98 ] [ (P) -98 -98 ] [ (Q) -98 -98 ] % 24-26
[ (R) -98 -98 ] [ (S) -98 -98 ] [ (T) -98 -98 ] % 27-29
[ (U) -98 -98 ] [ (V) -98 -98 ] [ (W) -98 -98 ] % 30-32
[ (X) -98 -98 ] [ (Y) -98 -98 ] [ (Z) -98 -98 ] % 33-35
[ (-) -98 -98 ] [ (.) -98 -98 ] % 36-37
] readonly def
/posicode.encmaps << % ";"=11, "<"=12
/a
[ (141111) (131211) (121311) (111411) (131112)
(121212) (111312) (121113) (111213) (111114)
(181111) (171211) (161311) (151411) (141511)
(131611) (121711) (111811) (171112) (161212)
(151312) (141412) (131512) (121612) (111712)
(161113) (151213) (141313) (131413) (121513)
(111613) (151114) (141214) (131314) (121414)
(111514) (141115) (131215) (121315) (111415)
(131116) (121216) (111316) (121117) (111217)
(111118) (1;111112) (111111111;1)
]
/b
[ (151212) (141312) (131412) (121512) (141213)
(131313) (121413) (131214) (121314) (121215)
(191212) (181312) (171412) (161512) (151612)
(141712) (131812) (121912) (181213) (171313)
(161413) (151513) (141613) (131713) (121813)
(171214) (161314) (151414) (141514) (131614)
(121714) (161215) (151315) (141415) (131515)
(121615) (151216) (141316) (131416) (121516)
(141217) (131317) (121417) (131218) (121318)
(121219) (1<121312) (121212121<1)
]
/limiteda
[ (111411) (111312) (111213) (111114) (121311)
(121212) (121113) (141111) (131211) (131112)
(171111) (161211) (151311) (141411) (131511)
(121611) (111711) (161112) (151212) (141312)
(131412) (121512) (111612) (151113) (141213)
(131313) (121413) (111513) (141114) (131214)
(121314) (111414) (131115) (121215) (111315)
(121116) (111216) (111117) (151111) (1)
]
/limitedb
[ (121512) (121413) (121314) (121215) (131412)
(131313) (131214) (151212) (141312) (141213)
(181212) (171312) (161412) (151512) (141612)
(131712) (121812) (171213) (161313) (151413)
(141513) (131613) (121713) (161214) (151314)
(141414) (131514) (121614) (151215) (141315)
(131415) (121515) (141216) (131316) (121416)
(131217) (121317) (121218) (141212) (1)
]
>> readonly def
/posicode.c2w [
[ 495 330 210 126 70 35 15 5 ]
[ 165 120 84 56 35 20 10 4 ]
[ 45 36 28 21 15 10 6 3 ]
[ 9 8 7 6 5 4 3 2 ]
[ 1 1 1 1 1 1 1 1 ]
] readonly def
/posicode.latevars dup 8 dict def load /init {
currentglobal
true setglobal
//posicode.latevars begin
%
% Pre-compute charvals for normal charmaps
%
/charvals_normal [
//posicode.charmapsnormal length dict
//posicode.charmapsnormal length dict
//posicode.charmapsnormal length dict
] def
0 1 //posicode.charmapsnormal length 1 sub {
/i exch def
/encs //posicode.charmapsnormal i get def
0 1 2 {
/j exch def
encs j get dup type /stringtype eq {0 get} if
charvals_normal j get exch i put
} for
} for
/charvals_normal charvals_normal readonly def
%
% Pre-compute charvals for limited charmaps
%
/charvals_limited [
//posicode.charmapslimited length dict
//posicode.charmapslimited length dict
//posicode.charmapslimited length dict
] def
0 1 //posicode.charmapslimited length 1 sub {
/i exch def
/encs //posicode.charmapslimited i get def
0 1 2 {
/j exch def
encs j get dup type /stringtype eq {0 get} if
charvals_limited j get exch i put
} for
} for
/charvals_limited charvals_limited readonly def
/init { //posicode.latevars {def} forall } def
end
//posicode.latevars /init get exec
setglobal
} bind put
/uk.co.terryburton.bwipp.global_ctx dup where {
exch get /preload known {//posicode.latevars /init get exec} if
} {pop} ifelse
/posicode {
82 dict begin
{
/dontdraw false def
/includetext false def % Enable/disable text
/text1font /Courier def
/text1size 10.0 def
/text1xoffset 0.0 def
/text1yoffset -7.0 def
/height -1.0 def
/width 0 def
/encoding (auto) def
/version (a) def
/checkoffset 0 def
/rows 1 def
/rowheight -1 def
/sepheight 2 def
/raw false def
/parse false def
/parsefnc false def
/readerinit false def
/propspec false def
/loosespec false def
/strictspec false def
/mag 1.0 def
/xdim -1.0 def
/hdim -1.0 def
/ast (default) def
/xmin -1.0 def /xnom -1.0 def /xmax -1.0 def
/hnom -1.0 def
/modunit 1 def
{null /apply //processoptions exec} stopped {pop stop} if
/options exch def
/global_encoder_defaults //render exec
/barcode exch def
barcode length 500 gt {
/bwipp.posicodeinputTooLong (The input data is too long) //raiseerror exec
} if
%
% Apply AST spec overrides and resolve physical specification
%
/posicode ast /apply_ast //render exec not { //raiseerror exec } if
/resolve_strictspec //render exec
/_render
dontdraw /uk.co.terryburton.bwipp.global_ctx dup where {exch get /enabledontdraw known} {pop false} ifelse and
/uk.co.terryburton.bwipp._dontdraw dup where {exch get} {pop false} ifelse or not
def
//posicode.latevars /init get exec
version (a) ne version (b) ne and version (limiteda) ne and version (limitedb) ne and {
/bwipp.posicodeInvalidVersion (The version must be either a, b, limiteda or limitedb) //raiseerror exec
} if
rows 1 lt rows 5 gt or {
/bwipp.posicodeBadRows (The number of rows must be from 1 to 5) //raiseerror exec
} if
rowheight -1 ne rowheight 1 lt and {
/bwipp.posicodeBadRowHeight (The rowheight must be at least 1) //raiseerror exec
} if
sepheight 1 lt {
/bwipp.posicodeBadSepHeight (The sepheight must be at least 1) //raiseerror exec
} if
/charmaps version (a) eq version (b) eq or {//posicode.charmapsnormal} {//posicode.charmapslimited} ifelse def
%
% Select the pre-computed charvals for the selected version
%
/charvals version (a) eq version (b) eq or {charvals_normal} {charvals_limited} ifelse def
/set0 charvals 0 get def
/set1 charvals 1 get def
/set2 charvals 2 get def
%
% Validate the input if limited
%
version (limiteda) eq version (limitedb) eq or {
0 1 barcode length 1 sub {
barcode exch 1 getinterval 0 get set0 exch known not {
/bwipp.posicodeBadCharacter (Posicode limited must contain only digits, capital letters, and the symbols - and .) //raiseerror exec
} if
} for
} if
raw {/encoding (raw) def} if
encoding (raw) ne encoding (auto) ne and {
/bwipp.posicodeBadEncoding (The encoding must be auto or raw) //raiseerror exec
} if
readerinit {
encoding (raw) eq {
/bwipp.posicodeReaderinitRaw (Reader initialisation is not available with raw codewords, which can include FNC3 directly) //raiseerror exec
} if
version (limiteda) eq version (limitedb) eq or {
/bwipp.posicodeReaderinitLimited (Reader initialisation is not available for Posicode limited) //raiseerror exec
} if
} if
encoding (raw) eq {
/cws barcode length array def
/i 0 def /j 0 def
{ % loop
i barcode length 3 sub ge {exit} if
barcode i get 94 ne {exit} if
barcode i 1 add 3 getinterval false 1 index {
dup 48 lt exch 57 gt or { pop true } if
} forall { pop exit } if
cvi /cw exch def
cw 45 gt {
/bwipp.posicodeBadRawCodeword (Raw codewords must be 0 to 45) //raiseerror exec
} if
cws j cw put
/i i 4 add def
/j j 1 add def
} loop
i barcode length ne {
/bwipp.posicodeBadRawFormat (Raw codewords must be formatted as ^NNN) //raiseerror exec
} if
/cws cws 0 j getinterval def
/text () def
} if
encoding (auto) eq {
%
% Parse the input
%
/fncvals <<
/parse parse
/parsefnc parsefnc
(FNC1) //posicode.fn1
(FNC2) //posicode.fn2
(FNC3) //posicode.fn3
(FNC@) //posicode.fna
% (FNC4) fn4 Not user accessible as encoded automatically
>> def
barcode fncvals //parseinput exec /msg exch def
/msglen msg length def
%
% Reader initialisation leads with FNC3. Readers do not transmit the data, so FNC1 in first
% or second position would declare a format that is never received
%
readerinit {
msglen 0 gt { msg 0 get dup //posicode.fn1 eq exch //posicode.fna eq or } { false } ifelse {
/bwipp.posicodeReaderinitFNC1 (Reader initialisation is not available with FNC1 in first or second position) //raiseerror exec
} if
/msg msglen 1 add array dup 0 //posicode.fn3 put dup 1 msg putinterval def
/msglen msg length def
} if
%
% FNC1 in second position follows an AIM application indicator of one letter or two digits
%
/fnc1second msglen 0 gt { msg 0 get //posicode.fna eq } { false } ifelse def
fnc1second {
/appindlen msg 1 get dup 48 ge exch 57 le and { 2 } { 1 } ifelse def
/msg [
msg 1 appindlen getinterval aload pop
//posicode.fn1
msg appindlen 1 add msglen appindlen sub 1 sub getinterval aload pop
] def
} if
parsefnc { % Function characters only come from parsefnc
msg {
//posicode.fna eq {
/bwipp.posicodeFNC1secondNotFirst (FNC1 in second position must be declared at the start of the data) //raiseerror exec
} if
} forall
} if
/text msglen string def
0 1 msglen 1 sub {
/i exch def
text i msg i get dup 0 lt { pop 32 } if put
} for
readerinit { % The leading FNC3 is not shown
/text text 1 msglen 1 sub getinterval def
} if
fnc1second { % FNC1 in second position is not shown
msglen 1 sub string
dup 0 text 0 appindlen getinterval putinterval
dup appindlen text appindlen 1 add msglen appindlen sub 1 sub getinterval putinterval
/text exch def
} if
%
% Standard and extended ASCII runlength at position
%
/numSA [ msglen {0} repeat 0 ] def
/numEA [ msglen {0} repeat 0 ] def
msglen 1 sub -1 0 {
/i exch def
msg i get 0 ge {
msg i get 128 ge {
numEA i numEA i 1 add get 1 add put
} {
numSA i numSA i 1 add get 1 add put
} ifelse
} if
} for
%
% FNC4 codeword insertion for extended ASCII
%
/ea false def
mark
0 1 msglen 1 sub {
/i exch def
/c msg i get def
ea c 128 lt xor not c 0 ge and { % Other mode required
ea {numSA} {numEA} ifelse i get dup % Runlength of other mode
i add msglen eq {3} {5} ifelse % Does run terminate symbol
lt { % Shift
//posicode.fn4
} { % Latch
//posicode.fn4 //posicode.fn4
/ea ea not def
} ifelse
} if
c 0 ge {c 127 and} {c} ifelse
} for
counttomark array astore /msg exch def pop
/msglen msg length def
%
% Convert the input message to codewords
%
/enc {
exch get cws exch j exch put
/j j 1 add def
} def
/cws msglen 2 mul array def
/i 0 def /j 0 def /cset (set0) def
{
i msglen eq {exit} if
{ % common exit
%
% Read next two characters
%
/char1 msg i get def
/char2 i 1 add msglen lt {msg i 1 add get} {-99} ifelse def
%
% If current mode is sufficient then directly encode
%
cset load char1 known {
char1 cset load enc
/i i 1 add def
exit
} if
%
% If char1 is in set2 then shift encode
%
set2 char1 known {
//posicode.sf2 cset load enc
char1 set2 enc
/i i 1 add def
exit
} if
%
% If char2 is also not in this set then latch else shift encode
%
cset load char2 known not {
cset (set0) eq {
//posicode.la1 cset load enc
/cset (set1) def
} {
//posicode.la0 cset load enc
/cset (set0) def
} ifelse
exit
} {
cset (set0) eq {
//posicode.sf1 cset load enc
char1 set1 enc
} {
//posicode.sf0 cset load enc
char1 set0 enc
} ifelse
/i i 1 add def
exit
} ifelse
exit
} loop
} loop
/cws cws 0 j getinterval def
} if % auto encoding
%
% Create an array containing the character mappings
%
//posicode.encmaps version get /encs exch def
%
% The space bar successions of a row, whose check value is raised by
% the sequence indicator m + 10n of a stacked row, otherwise zero
%
/rowsbs { % rcws seq -> sbs
/seq exch def /rcws exch def
/v 0 def
rcws {
/cw exch def
6 {
cw v xor 1 and 0 ne {
/v v 7682 xor def
} if
/v v -1 bitshift def
/cw cw -1 bitshift def
} repeat
} forall
/v v checkoffset add seq add def
version (limiteda) eq version (limitedb) eq or {
/v v 1023 and def
v 824 gt v 853 lt and {
/v v 292 add def
} if
} {
/v v 1023 and 45 add def
} ifelse
/d [ 2 2 2 2 2 2 ] def
/r 0 def /c 0 def /w 0 def /sum 0 def
{
sum v eq {exit} if
/t sum //posicode.c2w r get c get add def
t v eq {
/w w 1 add def
d r w 2 add put
/sum t def
} if
t v gt {
d r w 2 add put
/r r 1 add def
/w 0 def
} if
t v lt {
/c c 1 add def
/w w 1 add def
/sum t def
} if
} loop
20 0 1 4 {d exch get sub} for
d exch 5 exch put
version (b) eq version (limitedb) eq or {
/d [ d {1 add} forall ] def
} if
/cbs (111111111111) 12 string copy def
5 -1 0 {
/i exch def
cbs 5 i sub 2 mul 1 add d i get 47 add put
} for
%
% Concatenate the space bar successions
%
/sbs rcws length 6 mul 31 add string def
encs encs length 2 sub get dup
sbs exch 0 exch putinterval
length /j exch def
0 1 rcws length 1 sub {
/i exch def
sbs j encs rcws i get get putinterval
/j j 6 add def
} for
sbs j cbs putinterval
/j j 12 add def
encs encs length 1 sub get dup
sbs exch j exch putinterval
length j add /j exch def
sbs 0 j getinterval
} def
rows 1 eq {
cws 0 rowsbs /sbs exch def
/resolve_height //render exec dup -1 eq { pop 1.0 } if /height exch def
<<
/ren /renlinear
/sbs [sbs {48 sub} forall]
/bhs [sbs length 1 add 2 idiv {height} repeat]
/bbs [sbs length 1 add 2 idiv {0} repeat]
/txt [ [text text1xoffset text1yoffset text1font text1size] ]
/text1xalign (center)
/borderleft << /a 0.0 /b 0.0 /limiteda 12.0 /limitedb 13.0 >> version get
/borderright << /a 0.0 /b 0.0 /limiteda 12.0 /limitedb 13.0 >> version get
/strictspec strictspec
/loosespec loosespec
/xdim xdim
/xmin xmin
/xmax xmax
/modunit modunit
/opt options
>>
_render //renlinear if
} {
%
% Stacked PosiCode: rows of equal length, the last taking any
% remainder, each a complete symbol whose check character
% identifies the row m of n
%
cws length rows lt {
/bwipp.posicodeTooFewCharacters (Each row must contain at least one symbol character) //raiseerror exec
} if
/rowlen cws length rows idiv def
/rowbits rows array def
/symwid 0 def
0 1 rows 1 sub {
/m exch def
cws m rowlen mul m rows 1 sub eq { cws length m rowlen mul sub } { rowlen } ifelse getinterval
m 1 add rows 10 mul add rowsbs
mark 0 3 -1 roll { 48 sub 1 index 1 eq { {0} } { {1} } ifelse repeat } forall % Each run the opposite colour of the last, from a bar
counttomark 1 sub array astore exch pop exch pop
dup length symwid gt { /symwid 1 index length def } if
rowbits m 3 -1 roll put
} for
%
% Bars approximately 15% of the length of the row
%
/rowheight rowheight -1 eq { symwid 0.15 mul round cvi dup 1 lt { pop 1 } if } { rowheight } ifelse def
/seprow [ symwid {0} repeat ] def
/pixy rowheight rows mul sepheight rows 1 sub mul add def
/numcomprows rows 2 mul 1 sub def
/pixs symwid numcomprows mul array def
/rowheights numcomprows array def
/pos 0 def /ri 0 def
0 1 rows 1 sub {
/m exch def
m 0 gt {
pixs pos seprow putinterval /pos pos symwid add def
rowheights ri sepheight put /ri ri 1 add def
} if
pixs pos seprow putinterval % Rows aligned left, shorter rows ending in space
pixs pos rowbits m get putinterval /pos pos symwid add def
rowheights ri rowheight put /ri ri 1 add def
} for
<<
/ren /renmatrix
/pixs pixs
/pixx symwid
/pixy pixy
/rowheights rowheights
/height pixy 72 div
/width symwid 72 div
/borderleft << /a 0.0 /b 0.0 /limiteda 12.0 /limitedb 13.0 >> version get
/borderright << /a 0.0 /b 0.0 /limiteda 12.0 /limitedb 13.0 >> version get
/strictspec strictspec
/loosespec loosespec
/xdim xdim
/xmin xmin
/xmax xmax
/modunit modunit
/opt options
>>
_render //renmatrix if
} ifelse
} stopped {end stop} if
end
}
[/barcode] {null def} forall
bind def
/posicode dup load executeonly /uk.co.terryburton.bwipp defineresource pop
end
/setpacking where {pop setpacking} if
setglobal
% --END ENCODER posicode--