Skip to content

Commit 2e5f28f

Browse files
committed
bc412: Uplift
1 parent 7710148 commit 2e5f28f

1 file changed

Lines changed: 59 additions & 38 deletions

File tree

src/bc412.ps.src

Lines changed: 59 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
% Barcode Writer in Pure PostScript
22
% https://bwipp.terryburton.co.uk
33
%
4-
% Copyright (c) 2004-2024 Terry Burton
4+
% Copyright (c) 2004-2025 Terry Burton
55
%
66
% $Id$
77
%
@@ -38,16 +38,51 @@
3838
currentglobal
3939
true setglobal
4040
/setpacking where {pop currentpacking true setpacking} if
41-
10 dict
42-
dup /loadctx dup /uk.co.terryburton.bwipp findresource put
43-
dup /unloadctx dup /uk.co.terryburton.bwipp findresource put
41+
50 dict
4442
dup /raiseerror dup /uk.co.terryburton.bwipp findresource put
4543
dup /processoptions dup /uk.co.terryburton.bwipp findresource put
4644
dup /renlinear dup /uk.co.terryburton.bwipp findresource put
4745
begin
46+
47+
/bc412.barchars (0R9GLVHA8EZ4NTS1J2Q6C7DYKBUIX3FWP5M) readonly def
48+
49+
/bc412.encs [
50+
(11111115) (13111212) (11131113) (12111213) (12121311) % 0R9GL
51+
(13131111) (12111312) (11131212) (11121411) (11151111) % VHA8E
52+
(15111111) (11111511) (12131211) (13121112) (13111311) % Z4NTS
53+
(11111214) (12121113) (11111313) (13111113) (11121213) % 1J2Q6
54+
(11141112) (11121312) (11141211) (14121111) (12121212) % C7DYK
55+
(11131311) (13121211) (12111411) (14111211) (11111412) % BUIX3
56+
(12111114) (14111112) (12141111) (11121114) (12131112) % FWP5M
57+
(12) (111) % Start Stop
58+
] readonly def
59+
60+
/bc412.latevars dup 1 dict def load /init {
61+
62+
currentglobal
63+
true setglobal
64+
65+
//bc412.latevars begin
66+
67+
/charvals 35 dict def
68+
0 1 34 {
69+
charvals exch dup //bc412.barchars exch 1 getinterval exch put
70+
} for
71+
/charvals charvals readonly def
72+
73+
/init { //bc412.latevars {def} forall } def
74+
75+
end
76+
77+
//bc412.latevars /init get exec
78+
79+
setglobal
80+
81+
} bind put
82+
4883
/bc412 {
4984

50-
20 dict begin % Confine variables to local scope
85+
20 dict begin
5186

5287
/ctx null def
5388
/dontdraw false def
@@ -65,6 +100,8 @@ begin
65100
//processoptions exec /options exch def
66101
/barcode exch def
67102

103+
//bc412.latevars /init get exec
104+
68105
barcode () eq {
69106
/bwipp.bc412emptyData (The data must not be empty) //raiseerror exec
70107
} if
@@ -74,24 +111,19 @@ begin
74111
/includestartstop true def
75112
} if
76113

77-
/bc412 //loadctx exec
78-
79-
% Create a string of the available characters
80-
{
81-
/barchars (0R9GLVHA8EZ4NTS1J2Q6C7DYKBUIX3FWP5M) def
82-
/charvals 35 dict def
83-
0 1 34 {charvals exch dup barchars exch 1 getinterval exch put} for
84-
} ctxdef
85-
114+
%
86115
% Validate the input
116+
%
87117
0 1 barcode length 1 sub {
88118
barcode exch 1 getinterval charvals exch known not {
89119
/bwipp.bc412badCharacter (BC412 must contain only digits and capital letters except O) //raiseerror exec
90120
} if
91121
} for
92122

93123
semi {
124+
%
94125
% Validate length
126+
%
95127
validatecheck {
96128
barcode length 8 lt barcode length 19 gt or {
97129
/bwipp.bc412semivalidateBadLength (BC412 semi with check digit must be 8 to 19 characters long) //raiseerror exec
@@ -128,7 +160,7 @@ begin
128160
} if
129161
} {
130162
/checksum checksum 17 mul 35 mod def % CD = Mod35( 17 * F )
131-
barcode 1 barchars checksum get put
163+
barcode 1 //bc412.barchars checksum get put
132164
} ifelse
133165
} {
134166
/barlen barcode length validatecheck {1 sub} if def
@@ -140,38 +172,26 @@ begin
140172
} for
141173
/checksum checksum 35 mod def
142174
validatecheck {
143-
barcode barlen get barchars checksum get ne {
175+
barcode barlen get //bc412.barchars checksum get ne {
144176
/bwipp.bc412badCheckDigit (Incorrect BC412 check digit provided) //raiseerror exec
145177
} if
146178
/barcode barcode 0 barlen getinterval def
147179
/includecheck true def
148180
} if
149181
} ifelse
150182

151-
% Create an array containing the character mappings
152-
{
153-
/encs
154-
[ (11111115) (13111212) (11131113) (12111213) (12121311) % 0R9GL
155-
(13131111) (12111312) (11131212) (11121411) (11151111) % VHA8E
156-
(15111111) (11111511) (12131211) (13121112) (13111311) % Z4NTS
157-
(11111214) (12121113) (11111313) (13111113) (11121213) % 1J2Q6
158-
(11141112) (11121312) (11141211) (14121111) (12121212) % C7DYK
159-
(11131311) (13121211) (12111411) (14111211) (11111412) % BUIX3
160-
(12111114) (14111112) (12141111) (11121114) (12131112) % FWP5M
161-
(12) (111) % Start Stop
162-
] def
163-
} ctxdef
164-
165183
/sbs barlen 1 add 8 mul 5 add string def
166184
includecheck {
167185
/txt barlen 1 add array def
168186
} {
169187
/txt barlen array def
170188
} ifelse
171189

190+
%
172191
% Put the start character
192+
%
173193
includestartstop {
174-
sbs 0 encs 35 get putinterval
194+
sbs 0 //bc412.encs 35 get putinterval
175195
/pos 2 def
176196
/txtpos 3.0 def
177197
} {
@@ -182,29 +202,32 @@ begin
182202
0 1 barlen 1 sub {
183203
/i exch def
184204
/indx charvals barcode i 1 getinterval get def
185-
sbs pos encs indx get putinterval
205+
sbs pos //bc412.encs indx get putinterval
186206
txt i [barcode i 1 getinterval i 12 mul txtpos add textyoffset textfont textsize] put
187207
/pos pos 8 add def
188208
} for
189209

210+
%
190211
% Put the checksum
212+
%
191213
includecheck {
192-
sbs pos encs checksum get putinterval
214+
sbs pos //bc412.encs checksum get putinterval
193215
includecheckintext {
194-
txt barlen [barchars checksum 1 getinterval barlen 12 mul txtpos add textyoffset textfont textsize] put
216+
txt barlen [//bc412.barchars checksum 1 getinterval barlen 12 mul txtpos add textyoffset textfont textsize] put
195217
} {
196218
txt barlen [() barlen 12 mul txtpos add textyoffset textfont textsize] put
197219
} ifelse
198220
/pos pos 8 add def
199221
} if
200222

223+
%
201224
% Put the stop character
225+
%
202226
includestartstop {
203-
sbs pos encs 36 get putinterval
227+
sbs pos //bc412.encs 36 get putinterval
204228
/pos pos 3 add def
205229
} if
206230

207-
% Return the arguments
208231
/sbs sbs 0 pos getinterval def
209232
<<
210233
/ren /renlinear
@@ -219,8 +242,6 @@ begin
219242

220243
dontdraw not //renlinear if
221244

222-
//unloadctx exec
223-
224245
end
225246

226247
}

0 commit comments

Comments
 (0)