-
-
Notifications
You must be signed in to change notification settings - Fork 67
/
Copy pathcode11.ps.src
196 lines (176 loc) · 6.54 KB
/
code11.ps.src
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
% Barcode Writer in Pure PostScript
% https://bwipp.terryburton.co.uk
%
% Copyright (c) 2004-2024 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 code11--
% --REQUIRES preamble loadctx unloadctx raiseerror processoptions renlinear--
% --DESC: Code 11
% --EXAM: 0123456789
% --EXOP: includetext includecheck includecheckintext
% --RNDR: renlinear
/setpacking where {pop currentpacking true setpacking} if
10 dict
dup /loadctx dup /uk.co.terryburton.bwipp findresource put
dup /unloadctx dup /uk.co.terryburton.bwipp findresource put
dup /raiseerror dup /uk.co.terryburton.bwipp findresource put
dup /processoptions dup /uk.co.terryburton.bwipp findresource put
dup /renlinear dup /uk.co.terryburton.bwipp findresource put
begin
/code11 {
20 dict begin % Confine variables to local scope
/ctx null def
/dontdraw false def
/includecheck false def
/validatecheck false def
/includetext false def
/includecheckintext false def
/textfont /Courier def
/textsize 10.0 def
/textyoffset -7.0 def
/height 1.0 def
//processoptions exec /options exch def
/barcode exch def
barcode () eq {
/bwipp.code11emptyData (The data must not be empty) //raiseerror exec
} if
/code11 //loadctx exec
% Create an array containing the character mappings
{
/encs
[ (111131) (311131) (131131) (331111) (113131)
(313111) (133111) (111331) (311311) (311111)
(113111) (113311)
] def
% Create a string of the available characters
/barchars (0123456789-) def
/charvals 11 dict def
0 1 10 {charvals exch dup barchars exch 1 getinterval exch put} for
} ctxdef
% Validate the input
0 1 barcode length 1 sub {
barcode exch 1 getinterval charvals exch known not {
/bwipp.code11badCharacter (Code 11 must contain only digits and dashes) //raiseerror exec
} if
} for
/barlen barcode length def
validatecheck {
barlen 11 eq {
/bwipp.code11badLength (Code 11 cannot be 11 characters using check digits) //raiseerror exec
} if
/barlen barlen barlen 10 le {1} {2} ifelse sub def
} if
/numchecks includecheck validatecheck or {barlen 10 ge {2} {1} ifelse} {0} ifelse def
/checksum1 0 def /checksum2 0 def
0 1 barlen 1 sub {
/i exch def
/indx charvals barcode i 1 getinterval get def
/checksum1 checksum1 barlen i sub 1 sub 10 mod 1 add indx mul add def
/checksum2 checksum2 barlen i sub 9 mod 1 add indx mul add def
} for
/checksum1 checksum1 11 mod def
/checksum2 checksum2 checksum1 add 11 mod def
validatecheck {
numchecks 1 eq {
barcode barlen get barchars checksum1 get ne {
/bwipp.code11badCheckDigit (Incorrect Code 11 check digit provided) //raiseerror exec
} if
} {
barcode barlen get barchars checksum1 get ne
barcode barlen 1 add get barchars checksum2 get ne or {
/bwipp.code11badCheckDigits (Incorrect Code 11 check digits provided) //raiseerror exec
} if
} ifelse
/barcode barcode 0 barlen getinterval def
/includecheck true def
} if
/sbs barlen numchecks add 6 mul 12 add string def
/txt barlen numchecks add array def
% Put the start character
sbs 0 encs 11 get putinterval
/xpos 8 def
0 1 barlen 1 sub {
/i exch def
/indx charvals barcode i 1 getinterval get def
/enc encs indx get def
sbs i 6 mul 6 add enc putinterval
txt i [barcode i 1 getinterval xpos textyoffset textfont textsize] put
0 1 5 { % xpos+=width of the character
/xpos exch enc exch get 48 sub xpos add def
} for
} for
% Put the checksum and end characters
includecheck {
barlen 10 ge {
sbs barlen 6 mul 6 add encs checksum1 get putinterval
sbs barlen 6 mul 12 add encs checksum2 get putinterval
includecheckintext {
txt barlen [barchars checksum1 1 getinterval xpos textyoffset textfont textsize] put
/enc encs checksum1 get def
0 1 5 { % xpos+=width of the character
/xpos exch enc exch get 48 sub xpos add def
} for
txt barlen 1 add [barchars checksum2 1 getinterval xpos textyoffset textfont textsize] put
} {
txt barlen [() xpos textyoffset textfont textsize] put
txt barlen 1 add [() xpos textyoffset textfont textsize] put
} ifelse
sbs barlen 6 mul 18 add encs 11 get putinterval
} {
sbs barlen 6 mul 6 add encs checksum1 get putinterval
includecheckintext {
txt barlen [barchars checksum1 1 getinterval xpos textyoffset textfont textsize] put
} {
txt barlen [() xpos textyoffset textfont textsize] put
} ifelse
sbs barlen 6 mul 12 add encs 11 get putinterval
} ifelse
} {
sbs barlen 6 mul 6 add encs 11 get putinterval
} ifelse
% Return the arguments
<<
/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]
includetext {
/txt txt
} if
/opt options
>>
dontdraw not //renlinear if
//unloadctx exec
end
}
[/barcode] {null def} forall
bind def
/code11 dup load /uk.co.terryburton.bwipp defineresource pop
end
/setpacking where {pop setpacking} if
% --END ENCODER code11--