-
-
Notifications
You must be signed in to change notification settings - Fork 67
/
Copy pathinterleaved2of5.ps.src
185 lines (162 loc) · 6.29 KB
/
interleaved2of5.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
% 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 interleaved2of5--
% --REQUIRES preamble loadctx unloadctx raiseerror processoptions renlinear--
% --DESC: Interleaved 2 of 5 (ITF)
% --EXAM: 2401234567
% --EXOP: height=0.5 includecheck includetext 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
/interleaved2of5 {
20 dict begin % Confine variables to local scope
/ctx null def
/dontdraw false def
/includecheck false def % Enable/disable checkdigit
/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
/interleaved2of5 //loadctx exec
% Validate the input
barcode {
dup 48 lt exch 57 gt or {
/bwipp.interleaved2of5badCharacter (Interleaved 2 of 5 must contain only digits) //raiseerror exec
} if
} forall
/barlen barcode length def % Length of the code
% Prefix 0 to barcode if length is even and including checkdigit
% or length is odd and not including checkdigit
barlen 2 mod 0 eq includecheck and % even & includecheck
barlen 2 mod 0 ne includecheck not and or { % odd & !includecheck
/pad barlen 1 add string def % Create pad one bigger than barcode
pad 0 48 put % Put ascii 0 at start of pad
pad 1 barcode putinterval % Add barcode to the end of pad
/barcode pad def % barcode=pad
/barlen barlen 1 add def % barlen++
} if
% Add checksum to end of barcode
includecheck {
/checksum 0 def
0 1 barlen 1 sub {
/i exch def
i 2 mod 0 eq {
/checksum checksum barcode i get 48 sub 3 mul add def
} {
/checksum checksum barcode i get 48 sub add def
} ifelse
} for
/checksum 10 checksum 10 mod sub 10 mod def
/pad barlen 1 add string def % Create pad one bigger than barcode
pad 0 barcode putinterval % Add barcode to the start of pad
pad barlen checksum 48 add put % Add checksum to end of pad
/barcode pad def % barcode=pad
/barlen barlen 1 add def % barlen++
} if
% Create an array containing the character mappings
{
/encs
[ (11221) (21112) (12112) (22111) (11212)
(21211) (12211) (11122) (21121) (12121)
(1111) (2111)
] def
% Create a string of the available characters
/barchars (0123456789) def
} ctxdef
/sbs barlen 5 mul 8 add string def
/txt barlen array def
% Put the start character
sbs 0 encs 10 get putinterval
0 2 barlen 1 sub {
/i exch def
% Lookup the encodings for two consecutive barcode characters
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
/enca encs indx get def % Get the indxth encoding
barcode i 1 add 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
/encb encs indx get def % Get the indxth encoding
% Interleave the two character encodings
/intl enca length 2 mul string def
0 1 enca length 1 sub {
/j exch def
/achar enca j get def
/bchar encb j get def
intl j 2 mul achar put
intl j 2 mul 1 add bchar put
} for
sbs i 5 mul 4 add intl putinterval % Put encoded digit into sbs
txt i [barcode i 1 getinterval i 9 mul 4 add textyoffset textfont textsize] put
includecheck includecheckintext not and barlen 2 sub i eq and {
txt i 1 add [( ) i 1 add 9 mul 4 add textyoffset textfont textsize] put
} {
txt i 1 add [barcode i 1 add 1 getinterval i 1 add 9 mul 4 add textyoffset textfont textsize] put
} ifelse
} for
% Put the end character
sbs barlen 5 mul 4 add encs 11 get putinterval
% 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
/barratio 2.0
/spaceratio 2.0
/opt options
>>
dontdraw not //renlinear if
//unloadctx exec
end
}
[/barcode] {null def} forall
bind def
/interleaved2of5 dup load /uk.co.terryburton.bwipp defineresource pop
end
/setpacking where {pop setpacking} if
% --END ENCODER interleaved2of5--