forked from metafloor/bwip-js
-
Notifications
You must be signed in to change notification settings - Fork 1
/
barcode.ps
executable file
·23285 lines (20935 loc) · 829 KB
/
barcode.ps
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
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
%!PS
% Barcode Writer in Pure PostScript - Version 2016-08-29
% http://bwipp.terryburton.co.uk
%
% Copyright (c) 2004-2014 Terry Burton
%
% 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 TEMPLATE--
% --BEGIN RESOURCE preamble--
%%BeginResource: Category uk.co.terryburton.bwipp 0.0 2016082900 31191 34576
%%BeginData: 6 ASCII Lines
currentglobal
true setglobal
/Generic /Category findresource dup length 1 add dict copy dup
/InstanceType /setpacking where {pop /packedarraytype} {/arraytype} ifelse put
/uk.co.terryburton.bwipp exch /Category defineresource pop
setglobal
%%EndData
%%EndResource
% --END RESOURCE preamble--
% --BEGIN RESOURCE raiseerror--
% --REQUIRES preamble--
%%BeginResource: uk.co.terryburton.bwipp raiseerror 0.0 2016082900 44890 44440
%%BeginData: 13 ASCII Lines
/setpacking where {pop currentpacking true setpacking} if
1 dict
begin
/raiseerror {
$error exch /errorinfo exch put
$error exch /errorname exch put
$error /command null put
$error /newerror true put
handleerror quit
} bind def
/raiseerror dup load /uk.co.terryburton.bwipp defineresource pop
end
/setpacking where {pop setpacking} if
%%EndData
%%EndResource
% --END RESOURCE raiseerror--
% --BEGIN RENDERER renlinear--
% --REQUIRES preamble raiseerror--
%%BeginResource: uk.co.terryburton.bwipp renlinear 0.0 2016082900 76684 76278
%%BeginData: 237 ASCII Lines
/setpacking where {pop currentpacking true setpacking} if
1 dict
dup /raiseerror dup /uk.co.terryburton.bwipp findresource put
begin
/renlinear {
20 dict begin % Confine variables to local scope
/args exch def % We are given some arguments
% Default options
/sbs [] def
/bhs [] def
/bbs [] def
/txt [] def
/barcolor (unset) def
/includetext false def
/textcolor (unset) def
/textxalign (unset) def
/textyalign (unset) def
/textfont (Courier) def
/textsize 10 def
/textxoffset 0 def
/textyoffset 0 def
/textgaps 0 def
/alttext () def
/bordercolor (unset) def
/backgroundcolor (unset) def
/inkspread 0.15 def
/width 0 def
/barratio 1 def
/spaceratio 1 def
/showborder false def
/borderleft 10 def
/borderright 10 def
/bordertop 1 def
/borderbottom 1 def
/borderwidth 0.5 def
/guardwhitespace false def
/guardleftpos 0 def
/guardleftypos 0 def
/guardrightpos 0 def
/guardrightypos 0 def
/guardwidth 6 def
/guardheight 7 def
% Apply the renderer options and the user options
args {def} forall
opt {def} forall
/barcolor barcolor cvlit def
/textcolor textcolor cvlit def
/textxalign textxalign cvlit def
/textyalign textyalign cvlit def
/textfont textfont cvlit def
/textsize textsize cvr def
/textxoffset textxoffset cvr def
/textyoffset textyoffset cvr def
/textgaps textgaps cvr def
/alttext alttext cvlit def
/bordercolor bordercolor cvlit def
/backgroundcolor backgroundcolor cvlit def
/inkspread inkspread cvr def
/width width cvr def
/barratio barratio cvr def
/spaceratio spaceratio cvr def
/borderleft borderleft cvr def
/borderright borderright cvr def
/bordertop bordertop cvr def
/borderbottom borderbottom cvr def
/borderwidth borderwidth cvr def
/guardleftpos guardleftpos cvr def
/guardleftypos guardleftypos cvr def
/guardrightpos guardrightpos cvr def
/guardrightypos guardrightypos cvr def
/guardwidth guardwidth cvr def
/guardheight guardheight cvr def
% Create bar elements and put them into the bars array
/bars sbs length 1 add 2 idiv array def
/x 0.00 def /maxh 0 def
0 1 sbs length 1 add 2 idiv 2 mul 2 sub {
/i exch def
i 2 mod 0 eq { % i is even
/d sbs i get barratio mul barratio sub 1 add def % d=digit*r-r+1
sbs i get 0 ne {
/h bhs i 2 idiv get 72 mul def % Height from bhs
/c d 2 div x add def % Centre of the bar = x + d/2
/y bbs i 2 idiv get 72 mul def % Baseline from bbs
/w d inkspread sub def % bar width = digit - inkspread
bars i 2 idiv [h c y w] put % Add the bar entry
h y add maxh gt {/maxh h y add def} if
} {
bars i 2 idiv -1 put % Dummy entry
} ifelse
} {
/d sbs i get spaceratio mul spaceratio sub 1 add def % d=digit*r-r+1
} ifelse
/x x d add def % x+=d
} for
gsave
currentpoint translate
% Force symbol to given width
width 0 ne {
width 72 mul x div 1 scale
} if
% Set RGB or CMYK color depending on length of given hex string
/setanycolor {
/anycolor exch def
anycolor length 6 eq {
(< >) 8 string copy dup 1 anycolor putinterval cvx exec {255 div} forall setrgbcolor
} if
anycolor length 8 eq {
(< >) 10 string copy dup 1 anycolor putinterval cvx exec {255 div} forall setcmykcolor
} if
} bind def
% Display the border and background
newpath
borderleft neg borderbottom neg moveto
x borderleft add borderright add 0 rlineto
0 maxh borderbottom add bordertop add rlineto
x borderleft add borderright add neg 0 rlineto
0 maxh borderbottom add bordertop add neg rlineto
closepath
backgroundcolor (unset) ne { gsave backgroundcolor setanycolor fill grestore } if
showborder {
gsave
bordercolor (unset) ne { bordercolor setanycolor } if
borderwidth setlinewidth stroke
grestore
} if
% Display the bars for elements in the bars array
gsave
0 setlinecap
barcolor (unset) ne { barcolor setanycolor } if
bars {
dup -1 ne {
aload pop newpath setlinewidth moveto 0 exch rlineto stroke
} {
pop
} ifelse
} forall
grestore
% Display the text for elements in the text array
textcolor (unset) ne { textcolor setanycolor } if
includetext {
textxalign (unset) eq textyalign (unset) eq and alttext () eq and {
/s 0 def /fn () def
txt {
{} forall
2 copy s ne exch fn ne or {
2 copy /s exch def /fn exch def
selectfont
} {
pop pop
} ifelse
moveto show
} forall
} {
textfont textsize selectfont
alttext () eq {
/txt [ txt { 0 get {} forall } forall ] def
/tstr txt length string def
0 1 txt length 1 sub { dup txt exch get tstr 3 1 roll put } for
} {
/tstr alttext def
} ifelse
% Find true ascent of font
tstr length 0 eq {
0
} {
gsave
newpath 0 0 moveto (0) false charpath pathbbox
4 1 roll pop pop pop
grestore
currentfont /PaintType known {currentfont /PaintType get 2 eq} {false} ifelse
currentfont /StrokeWidth known and {
currentfont /StrokeWidth get 2 div 0 exch
currentfont /FontMatrix get dtransform
dup mul exch dup mul add sqrt
add
} if
} ifelse
/textascent exch def
/textwidth tstr stringwidth pop tstr length 1 sub textgaps mul add def
/textxpos textxoffset x textwidth sub 2 div add def
textxalign (left) eq { /textxpos textxoffset def } if
textxalign (right) eq { /textxpos x textxoffset sub textwidth sub def } if
textxalign (offleft) eq { /textxpos textwidth textxoffset add neg def } if
textxalign (offright) eq { /textxpos x textxoffset add def } if
textxalign (justify) eq textwidth x lt and {
/textxpos 0 def
/textgaps x textwidth sub tstr length 1 sub div def
} if
/textypos textyoffset textascent add 1 add neg def
textyalign (above) eq { /textypos textyoffset maxh add 1 add def } if
textyalign (center) eq { /textypos textyoffset maxh textascent sub 2 div add def } if
textxpos textypos moveto textgaps 0 tstr ashow
} ifelse
} if
% Display the guard elements
guardwhitespace {
0.75 setlinewidth
guardleftpos 0 ne {
newpath
guardleftpos neg guardwidth add guardleftypos guardwidth 2 div add moveto
guardwidth neg guardheight -2 div rlineto
guardwidth guardheight -2 div rlineto
stroke
} if
guardrightpos 0 ne {
newpath
guardrightpos x add guardwidth sub guardrightypos guardheight 2 div add moveto
guardwidth guardheight -2 div rlineto
guardwidth neg guardheight -2 div rlineto
stroke
} if
} if
grestore
end
} bind def
/renlinear dup load /uk.co.terryburton.bwipp defineresource pop
end
/setpacking where {pop setpacking} if
%%EndData
%%EndResource
% --END RENDERER renlinear--
% --BEGIN RENDERER renmatrix--
% --REQUIRES preamble raiseerror--
%%BeginResource: uk.co.terryburton.bwipp renmatrix 0.0 2016082900 80252 80028
%%BeginData: 227 ASCII Lines
/setpacking where {pop currentpacking true setpacking} if
1 dict
dup /raiseerror dup /uk.co.terryburton.bwipp findresource put
begin
/renmatrix {
20 dict begin
/args exch def
% Default options
/width 1 def
/height 1 def
/barcolor (unset) def
/backgroundcolor (unset) def
/inkspread 0 def
/inkspreadh 0 def
/inkspreadv 0 def
% Apply the renderer options and the user options
args {def} forall
opt {def} forall
/width width cvr def
/height height cvr def
/barcolor barcolor cvlit def
/backgroundcolor backgroundcolor cvlit def
/inkspread inkspread cvr def
/inkspreadh inkspreadh cvr def
/inkspreadv inkspreadv cvr def
inkspread 0 ne {/inkspreadh inkspread def} if
inkspread 0 ne {/inkspreadv inkspread def} if
/xyget { pixx mul add pixs exch get } bind def
/xyinvert { pixx mul add pixs exch 2 copy get 1 xor put } bind def
/mxyget { pixx mul add m exch get 2#001 and } bind def
/mxyset { pixx mul add m exch 3 -1 roll put } bind def
/msetborder { pixx mul add m exch 2 copy get 2#010 or put } bind def
/mborderoff { pixx mul add m exch 2 copy get 2#100 or put } bind def
/misborder { pixx mul add m exch get 2#110 and 2#010 eq } bind def
/mclear { pixx mul add m exch 2 copy get 2#001 and put } bind def
/mclear4 {
2 copy mclear
2 copy 1 add mclear
2 copy exch 1 add exch mclear
2 copy exch 1 add exch mclear
1 add exch 1 add exch mclear
} bind def
/trace {
% Walk the outline of a region emitting edge coordinates of the path
/y exch def /x exch def
% dir 0:right 1:down 2:left 3:up
% hug 0:right 1:left
/dir x 1 add y 1 add mxyget def /hug dir def
/sx x def /sy y def /sdir dir def
mark [x y] {
x 1 add y
x 1 add y 1 add
x y 1 add
x y
8 dir 2 mul neg roll
/Dy exch def /Dx exch def /D Dx Dy xyget def
/Cy exch def /Cx exch def /C Cx Cy xyget def
/By exch def /Bx exch def /B Bx By xyget def
/Ay exch def /Ax exch def /A Ax Ay xyget def
A B eq {
A C eq {/L} {/R} ifelse
} {
A C eq B D eq and {
A 0 eq hug 0 eq xor {/R} {/F} ifelse
} {
/F
} ifelse
} ifelse
dup /F eq {
pop
dir 0 eq {/x x 1 add def} if
dir 1 eq {/y y 1 add def} if
dir 2 eq {/x x 1 sub def} if
dir 3 eq {/y y 1 sub def} if
hug 0 eq {
Ax Ay msetborder
} {
Bx By msetborder
} ifelse
} {
/L eq {
/dir dir 3 add 4 mod def
hug 1 eq {
Bx By msetborder
Dx Dy mborderoff
} if
} { % R
/dir dir 1 add 4 mod def
hug 0 eq {
Ax Ay msetborder
Cx Cy mborderoff
} if
} ifelse
[x y]
} ifelse
x sx eq y sy eq and dir sdir eq and {exit} if
} loop
counttomark array astore exch pop
% Invert the interior of the path
/x x 1 add def /y y 1 add def
/t x y mxyget 1 xor def
mark x y {
counttomark 0 eq {exit} if
/y exch def /x exch def
x y mxyget t ne {
0 x 1 sub -1 0 {dup y misborder {exch pop exit} if pop} for
pixx 1 sub x 1 add 1 pixx 1 sub {dup y misborder {exch pop exit} if pop} for
1 exch { % From left to right border
/i exch def
i y misborder not {
t i y mxyset
i y xyinvert
} if
i y 1 sub mxyget t ne i y 1 sub misborder not and {i y 1 sub} if
i y 1 add mxyget t ne i y 1 add misborder not and {i y 1 add} if
} for
} if
} loop
pop
% Walk the path to clear the border information
dup 0 get aload pop /y1 exch def /x1 exch def
dup dup length 1 sub 1 exch getinterval {
aload pop /y2 exch def /x2 exch def
x2 x1 gt { x1 2 x2 1 sub {y1 mclear4} for } if
y2 y1 gt { y1 2 y2 1 sub {x1 exch mclear4} for } if
x2 x1 lt { x1 -2 x2 1 add {y1 mclear4} for } if
y2 y1 lt { y1 -2 y2 1 add {x1 exch mclear4} for } if
/x1 x2 def /y1 y2 def
} forall
% Discard duplicate final point
dup length 1 sub 0 exch getinterval
} bind def
% Pad the bitmap on all sides
/pixs [
pixx 2 add {0} repeat
0 pixx pixs length 1 sub {
0 exch
pixs exch pixx getinterval aload pop
0
} for
pixx 2 add {0} repeat
] def
/pixx pixx 2 add def
/pixy pixy 2 add def
% Track inverted regions and working space
/m [ pixs length {0} repeat ] def
% Construct paths by tracing and inverting each dark region
/paths [
0 1 pixy 1 sub {
/j exch def
0 1 pixx 1 sub {
/i exch def
i j xyget 1 eq {
i 1 sub j 1 sub trace
} if
} for
} for
] def
% Revert the bitmap size
/pixx pixx 2 sub def
/pixy pixy 2 sub def
% Set RGB or CMYK color depending on length of given hex string
/setanycolor {
/anycolor exch def
anycolor length 6 eq {
(< >) 8 string copy dup 1 anycolor putinterval cvx exec {255 div} forall setrgbcolor
} if
anycolor length 8 eq {
(< >) 10 string copy dup 1 anycolor putinterval cvx exec {255 div} forall setcmykcolor
} if
} bind def
% Draw the image
/inkspreadh inkspreadh 2 div def
/inkspreadv inkspreadv 2 div def
gsave
currentpoint translate
width pixx div 72 mul height pixy div 72 mul scale
0 0 moveto pixx 0 lineto pixx pixy lineto 0 pixy lineto closepath
backgroundcolor (unset) ne { gsave backgroundcolor setanycolor fill grestore } if
barcolor (unset) ne { barcolor setanycolor } if
newpath
paths {
/p exch def
/len p length def
p len 1 sub get aload pop
p 0 get aload pop
0 1 len 1 sub { % x1 y1 x2 y2
/i exch def
p i 1 add len mod get aload pop 6 -2 roll % x3 y3 x1 y1 x2 y2
5 index inkspreadh
4 index 4 -1 roll lt {add} {sub} ifelse % y3<y1 ? x2+i : x2-i
4 1 roll
4 index inkspreadv
4 index 4 -1 roll gt {add} {sub} ifelse % x3>x1 ? y2+i : y2-i
4 -1 roll exch pixy exch sub
i 0 eq {moveto} {lineto} ifelse
} for % x2 y2 x3 y3
closepath
pop pop pop pop
} forall
fill
grestore
end
} bind def
/renmatrix dup load /uk.co.terryburton.bwipp defineresource pop
end
/setpacking where {pop setpacking} if
%%EndData
%%EndResource
% --END RENDERER renmatrix--
% --BEGIN RENDERER renmaximatrix--
% --REQUIRES preamble raiseerror--
%%BeginResource: uk.co.terryburton.bwipp renmaximatrix 0.0 2016082900 55426 55272
%%BeginData: 79 ASCII Lines
/setpacking where {pop currentpacking true setpacking} if
1 dict
dup /raiseerror dup /uk.co.terryburton.bwipp findresource put
begin
/renmaximatrix {
20 dict begin
/args exch def % We are given some arguments
% Default options
/barcolor (unset) def
/backgroundcolor (unset) def
% Apply the renderer options and the user options
args {def} forall
opt {def} forall
/barcolor barcolor cvlit def
/backgroundcolor backgroundcolor cvlit def
% Set RGB or CMYK color depending on length of given hex string
/setanycolor {
/anycolor exch def
anycolor length 6 eq {
(< >) 8 string copy dup 1 anycolor putinterval cvx exec {255 div} forall setrgbcolor
} if
anycolor length 8 eq {
(< >) 10 string copy dup 1 anycolor putinterval cvx exec {255 div} forall setcmykcolor
} if
} bind def
gsave
currentpoint translate
2.4945 dup scale % from 1pt to 1.88mm
0 0 moveto 30 0 lineto 30 29 lineto 0 29 lineto closepath
backgroundcolor (unset) ne { gsave backgroundcolor setanycolor fill grestore } if
barcolor (unset) ne { barcolor setanycolor } if
0.5 0.5774 translate
newpath
pixs {
dup
/x exch 30 mod def
/y exch 30 idiv def
y 2 mod 0 eq {x} {x 0.5 add} ifelse
32 y sub 0.8661 mul
moveto
0 0.5774 rmoveto
-0.5 -0.2887 rlineto
0 -0.5774 rlineto
0.5 -0.2887 rlineto
0.5 0.2887 rlineto
0 0.5774 rlineto
-0.5 0.2887 rlineto
closepath
} forall
fill
% Plot the locator symbol
newpath 14 13.8576 0.5774 0 360 arc closepath
14 13.8576 1.3359 360 0 arcn closepath fill
newpath 14 13.8576 2.1058 0 360 arc closepath
14 13.8576 2.8644 360 0 arcn closepath fill
newpath 14 13.8576 3.6229 0 360 arc closepath
14 13.8576 4.3814 360 0 arcn closepath fill
grestore
end
} bind def
/renmaximatrix dup load /uk.co.terryburton.bwipp defineresource pop
end
/setpacking where {pop setpacking} if
%%EndData
%%EndResource
% --END RENDERER renmaximatrix--
% --BEGIN ENCODER ean5--
% --REQUIRES preamble raiseerror renlinear--
% --DESC: EAN-5 (5 digit addon)
% --EXAM: 90200
% --EXOP: includetext guardwhitespace
% --RNDR: renlinear
%%BeginResource: uk.co.terryburton.bwipp ean5 0.0 2016082900 62897 62576
%%BeginData: 135 ASCII Lines
/setpacking where {pop currentpacking true setpacking} if
1 dict
dup /raiseerror dup /uk.co.terryburton.bwipp findresource put
dup /renlinear dup /uk.co.terryburton.bwipp findresource put
begin
/ean5 {
20 dict begin
/options exch def % We are given an option string
/barcode exch def % We are given a barcode string
/dontdraw false def
/includetext false def % Enable/disable text
/textfont /Helvetica def
/textsize 12 def
/textxoffset 0 def
/textyoffset (unset) def
/height 0.7 def
% Parse the input options
options type /stringtype eq {
1 dict begin
options {
token false eq {exit} if dup length string cvs (=) search
true eq {cvlit exch pop exch def} {cvlit true def} ifelse
} loop
currentdict end /options exch def
} if
options {def} forall
/textfont textfont cvlit def
/textsize textsize cvr def
/height height cvr def
/textxoffset textxoffset cvr def
textyoffset (unset) eq {
/textyoffset height 72 mul 1 add def
} {
/textyoffset textyoffset cvr def
} ifelse
% Validate input
barcode length 5 ne {
/bwipp.ean5badLength (EAN-5 add-on must be 5 digits) //raiseerror exec
} if
barcode {
dup 48 lt exch 57 gt or {
/bwipp.ean5badCharacter (EAN-5 add-on must contain only digits) //raiseerror exec
} if
} forall
% Create an array containing the character mappings
/encs
[ (3211) (2221) (2122) (1411) (1132)
(1231) (1114) (1312) (1213) (3112)
(112) (11)
] def
% Create a string of the available characters
/barchars (0123456789) def
% Determine the mirror map based on mod 10 checksum
/mirrormaps
[ (11000) (10100) (10010) (10001) (01100)
(00110) (00011) (01010) (01001) (00101)
] def
/checksum 0 def
0 1 4 {
/i exch def
/barchar barcode i get 48 sub def
i 2 mod 0 eq {
/checksum barchar 3 mul checksum add def
} {
/checksum barchar 9 mul checksum add def
} ifelse
} for
/checksum checksum 10 mod def
/mirrormap mirrormaps checksum get def
/sbs 31 string def
/txt 5 array def
0 1 4 {
/i exch def
% Prefix with either a start character or separator character
i 0 eq {
sbs 0 encs 10 get putinterval
} {
sbs i 1 sub 6 mul 7 add encs 11 get putinterval
} ifelse
% Lookup the encoding for the barcode character
barcode i 1 getinterval barchars exch search
pop % Discard true leaving pre
length /indx exch def % indx is the length of pre
pop pop % Discard seek and post
/enc encs indx get def % Get the indxth encoding
mirrormap i get 49 eq { % Reverse enc if 1 in this position in mirrormap
/enclen enc length def
/revenc enclen string def
0 1 enclen 1 sub {
/j exch def
/char enc j get def
revenc enclen j sub 1 sub char put
} for
/enc revenc def
} if
sbs i 6 mul 3 add enc putinterval % Put encoded digit into sbs
txt i [barcode i 1 getinterval i 1 sub 9 mul 13 add textxoffset add textyoffset textfont textsize] put
} for
% Return the arguments
<<
/ren //renlinear
/sbs [sbs {48 sub} forall]
/bhs [16{height}repeat]
/bbs [16{0}repeat]
includetext {
/txt txt
} if
/opt options
/guardrightpos 10
/guardrightypos textyoffset 4 add
/bordertop 10
>>
dontdraw not //renlinear if
end
} bind def
/ean5 dup load /uk.co.terryburton.bwipp defineresource pop
end
/setpacking where {pop setpacking} if
%%EndData
%%EndResource
% --END ENCODER ean5--
% --BEGIN ENCODER ean2--
% --REQUIRES preamble raiseerror renlinear--
% --DESC: EAN-2 (2 digit addon)
% --EXAM: 05
% --EXOP: includetext guardwhitespace
% --RNDR: renlinear
%%BeginResource: uk.co.terryburton.bwipp ean2 0.0 2016082900 61678 61382
%%BeginData: 120 ASCII Lines
/setpacking where {pop currentpacking true setpacking} if
1 dict
dup /raiseerror dup /uk.co.terryburton.bwipp findresource put
dup /renlinear dup /uk.co.terryburton.bwipp findresource put
begin
/ean2 {
20 dict begin
/options exch def % We are given an options string
/barcode exch def % We are given a barcode string
/dontdraw false def
/includetext false def % Enable/disable text
/textfont /Helvetica def
/textsize 12 def
/textxoffset 0 def
/textyoffset (unset) def
/height 0.7 def
% Parse the input options
options type /stringtype eq {
1 dict begin
options {
token false eq {exit} if dup length string cvs (=) search
true eq {cvlit exch pop exch def} {cvlit true def} ifelse
} loop
currentdict end /options exch def
} if
options {def} forall
/textfont textfont cvlit def
/textsize textsize cvr def
/height height cvr def
/textxoffset textxoffset cvr def
textyoffset (unset) eq {
/textyoffset height 72 mul 1 add def
} {
/textyoffset textyoffset cvr def
} ifelse
% Validate input
barcode length 2 ne {
/bwipp.ean2badLength (EAN-2 add-on must be 2 digits) //raiseerror exec
} if
barcode {
dup 48 lt exch 57 gt or {
/bwipp.ean2badCharacter (EAN-2 add-on must contain only digits) //raiseerror exec
} if
} forall
% Create an array containing the character mappings
/encs
[ (3211) (2221) (2122) (1411) (1132)
(1231) (1114) (1312) (1213) (3112)
(112) (11)
] def
% Create a string of the available characters
/barchars (0123456789) def
% Determine the mirror map based on mod 4 checksum
/mirrormap [(00) (01) (10) (11)] barcode 0 2 getinterval cvi 4 mod get def
/sbs 13 string def
/txt 2 array def
0 1 1 {
/i exch def
% Prefix with either a start character or separator character
i 0 eq {
sbs 0 encs 10 get putinterval
} {
sbs i 1 sub 6 mul 7 add encs 11 get putinterval
} ifelse
% Lookup the encoding for the barcode character
barcode i 1 getinterval barchars exch search
pop % Discard true leaving pre
length /indx exch def % indx is the length of pre
pop pop % Discard seek and post
/enc encs indx get def % Get the indxth encoding
mirrormap i get 49 eq { % Reverse enc if 1 in this position in mirrormap
/enclen enc length def
/revenc enclen string def
0 1 enclen 1 sub {
/j exch def
/char enc j get def
revenc enclen j sub 1 sub char put
} for
/enc revenc def
} if
sbs i 6 mul 3 add enc putinterval % Put encoded digit into sbs
txt i [barcode i 1 getinterval i 1 sub 9 mul 13 add textxoffset add textyoffset textfont textsize] put
} for
% Return the arguments
<<
/ren //renlinear
/sbs [sbs {48 sub} forall]
/bhs [12{height}repeat]
/bbs [12{0}repeat]
includetext {
/txt txt
} if
/opt options
/guardrightpos 10
/guardrightypos textyoffset 4 add
/bordertop 10
>>
dontdraw not //renlinear if
end
} bind def
/ean2 dup load /uk.co.terryburton.bwipp defineresource pop
end
/setpacking where {pop setpacking} if
%%EndData
%%EndResource
% --END ENCODER ean2--
% --BEGIN ENCODER ean13--
% --REQUIRES preamble raiseerror renlinear ean5 ean2--
% --DESC: EAN-13
% --EXAM: 2112345678900
% --EXOP: includetext guardwhitespace
% --RNDR: renlinear
%%BeginResource: uk.co.terryburton.bwipp ean13 0.0 2016082900 84460 87603
%%BeginData: 215 ASCII Lines
/setpacking where {pop currentpacking true setpacking} if
1 dict
dup /raiseerror dup /uk.co.terryburton.bwipp findresource put
dup /renlinear dup /uk.co.terryburton.bwipp findresource put
dup /ean2 dup /uk.co.terryburton.bwipp findresource put
dup /ean5 dup /uk.co.terryburton.bwipp findresource put
begin
/ean13 {
20 dict begin
/options exch def % We are given an option string
/barcode exch def % We are given a barcode string
/dontdraw false def
/includetext false def % Enable/disable text
/textfont /Helvetica def
/textsize 12 def
/textxoffset -10 def
/textyoffset -4 def
/height 1 def
/addongap 12 def
/addontextfont (unset) def
/addontextsize (unset) def
/addontextxoffset (unset) def
/addontextyoffset (unset) def
% Parse the input options, either a string or a dict
options type /stringtype eq {
1 dict begin
options {
token false eq {exit} if dup length string cvs (=) search
true eq {cvlit exch pop exch def} {cvlit true def} ifelse
} loop
currentdict end /options exch def
} if
options {def} forall
/textfont textfont cvlit def
/textsize textsize cvr def
/textxoffset textxoffset cvr def
/textyoffset textyoffset cvr def
/height height cvr def
/addongap addongap cvr def
addontextfont (unset) ne {/addontextfont addontextfont cvlit def} if
addontextsize (unset) ne {/addontextsize addontextsize cvr def} if
addontextxoffset (unset) ne {/addontextxoffset addontextxoffset cvr def} if
addontextyoffset (unset) ne {/addontextyoffset addontextyoffset cvr def} if
% Split off the addon
barcode ( ) search {
/barcode exch def
pop
/addon exch def
} {
pop
/addon () def
} ifelse
% Validate the input
barcode length 12 ne barcode length 13 ne and {
/bwipp.ean13badLength (EAN-13 must be 12 or 13 digits) //raiseerror exec
} if
barcode {
dup 48 lt exch 57 gt or {
/bwipp.ean13badCharacter (EAN-13 must contain only digits) //raiseerror exec
} if
} forall
addon length 0 ne addon length 2 ne and addon length 5 ne and {
/bwipp.ean13badAddOnLength (Add-on for EAN-13 must be 2 or 5 digits) //raiseerror exec
} if
% Add checksum digit
/pad 13 string def
/checksum 0 def
0 1 11 {
/i exch def
/barchar barcode i get 48 sub def
i 2 mod 0 eq {