-
-
Notifications
You must be signed in to change notification settings - Fork 67
/
Copy pathrationalizedCodabar.ps.src
194 lines (173 loc) · 7.02 KB
/
rationalizedCodabar.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
% 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 rationalizedCodabar--
% --REQUIRES preamble loadctx unloadctx raiseerror processoptions renlinear--
% --DESC: Codabar
% --EXAM: A0123456789B
% --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
/rationalizedCodabar {
20 dict begin % Confine variables to local scope
/ctx null def
/dontdraw false def
/altstartstop false def
/includecheck false def % Enable/disable checkdigit
/validatecheck false def
/includetext false def % Enable/disable text
/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 length 2 lt barcode length 3 lt validatecheck and or {
/bwipp.rationalizedCodabarBadLength (Codabar must be at least 2 characters in length excluding any check digit) //raiseerror exec
} if
/rationalizedCodabar //loadctx exec
{
% Create an array containing the character mappings
/encs
[ (11111331) (11113311) (11131131) (33111111) (11311311)
(31111311) (13111131) (13113111) (13311111) (31131111)
(11133111) (11331111) (31113131) (31311131) (31313111)
(11313131) (11331311) (13131131) (11131331) (11133311)
] def
% Create a string of the available characters
/barcharsnormal (0123456789-$:/.+ABCD) def
/barcharsalt (0123456789-$:/.+TN*E) def
} ctxdef
/barchars altstartstop {barcharsalt} {barcharsnormal} ifelse def
/charvals 20 dict def
0 1 19 {charvals exch dup barchars exch 1 getinterval exch put} for
/bodyvals 16 dict def
0 1 15 {bodyvals exch dup barchars exch 1 getinterval exch put} for
/ssvals 4 dict def
16 1 19 {ssvals exch dup barchars exch 1 getinterval exch put} for
% Validate the input
barcode 0 1 getinterval ssvals exch known not
barcode barcode length 1 sub 1 getinterval ssvals exch known not or {
altstartstop {
/bwipp.rationalizedCodabarBadAltStartStop (Codabar start and stop characters must be one of E N T or *) //raiseerror exec
} {
/bwipp.rationalizedCodabarBadStartStop (Codabar start and stop characters must be one of A B C or D) //raiseerror exec
} ifelse
} if
1 1 barcode length 2 sub {
barcode exch 1 getinterval bodyvals exch known not {
/bwipp.rationalizedCodabarBadCharacter (Codabar body must contain only digits and symbols - $ : / . +) //raiseerror exec
} if
} for
/barlen barcode length validatecheck {1 sub} if def
/checksum 0 def
0 1 barlen 2 sub {
barcode exch 1 getinterval charvals exch get
checksum add /checksum exch def
} for
barcode barcode length 1 sub 1 getinterval charvals exch get
checksum add /checksum exch def
/checksum 16 checksum 16 mod sub 16 mod def
validatecheck {
barcode barlen 1 sub get barchars checksum get ne {
/bwipp.rationalizedCodabarBadCheckDigit (Incorrect Codabar check digit provided) //raiseerror exec
} if
barlen string
dup 0 barcode 0 barlen 1 sub getinterval putinterval
dup barlen 1 sub barcode barlen 1 getinterval putinterval
/barcode exch def
/includecheck true def
} if
/sbs barlen includecheck {1 add} if 8 mul string def
/txt barlen includecheck {1 add} if array def
/xpos 0 def
0 1 barlen 2 sub {
/i exch def
/indx charvals barcode i 1 getinterval get def
/enc encs indx get def
sbs i 8 mul enc putinterval % Put encoded digit into sbs
txt i [barcode i 1 getinterval xpos textyoffset textfont textsize] put
0 1 7 { % xpos+=width of the character
/xpos exch enc exch get 48 sub xpos add def
} for
} for
% Put the checksum character and stop character
includecheck {
% Put the checksum character
sbs barlen 8 mul 8 sub encs checksum get putinterval
includecheckintext {
txt barlen 1 sub [barchars checksum 1 getinterval xpos textyoffset textfont textsize] put
} {
txt barlen 1 sub [( ) xpos textyoffset textfont textsize] put
} ifelse
0 1 7 { % xpos+=width of the character
/xpos exch encs checksum get exch get 48 sub xpos add def
} for
% Put the end character
/indx charvals barcode barlen 1 sub 1 getinterval get def
/enc encs indx get def % Get the indxth encoding
sbs barlen 8 mul enc putinterval % Put encoded digit into sbs
txt barlen [barcode barlen 1 sub 1 getinterval xpos textyoffset textfont textsize] put
} {
% Put the end character
/indx charvals barcode barlen 1 sub 1 getinterval get def
/enc encs indx get def % Get the indxth encoding
sbs barlen 8 mul 8 sub enc putinterval % Put encoded digit into sbs
txt barlen 1 sub [barcode barlen 1 sub 1 getinterval xpos textyoffset textfont textsize] put
} 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
/rationalizedCodabar dup load /uk.co.terryburton.bwipp defineresource pop
end
/setpacking where {pop setpacking} if
% --END ENCODER rationalizedCodabar--