Skip to content

Commit 7687c57

Browse files
committed
rationalizedCodabar: Uplift
1 parent 5236aa8 commit 7687c57

1 file changed

Lines changed: 32 additions & 30 deletions

File tree

src/rationalizedCodabar.ps.src

Lines changed: 32 additions & 30 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,18 +38,28 @@
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+
/rationalizedCodabar.encs [
48+
(11111331) (11113311) (11131131) (33111111) (11311311)
49+
(31111311) (13111131) (13113111) (13311111) (31131111)
50+
(11133111) (11331111) (31113131) (31311131) (31313111)
51+
(11313131) (11331311) (13131131) (11131331) (11133311)
52+
] readonly def
53+
54+
/rationalizedCodabar.barchars (0123456789-$:/.+ABCD) readonly def
55+
/rationalizedCodabar.barcharsalt (0123456789-$:/.+TN*E) readonly def
56+
4857
/rationalizedCodabar {
4958

50-
20 dict begin % Confine variables to local scope
59+
20 dict begin
5160

5261
/ctx null def
62+
5363
/dontdraw false def
5464
/altstartstop false def
5565
/includecheck false def % Enable/disable checkdigit
@@ -68,23 +78,7 @@ begin
6878
/bwipp.rationalizedCodabarBadLength (Codabar must be at least 2 characters in length excluding any check digit) //raiseerror exec
6979
} if
7080

71-
/rationalizedCodabar //loadctx exec
72-
73-
{
74-
% Create an array containing the character mappings
75-
/encs
76-
[ (11111331) (11113311) (11131131) (33111111) (11311311)
77-
(31111311) (13111131) (13113111) (13311111) (31131111)
78-
(11133111) (11331111) (31113131) (31311131) (31313111)
79-
(11313131) (11331311) (13131131) (11131331) (11133311)
80-
] def
81-
82-
% Create a string of the available characters
83-
/barcharsnormal (0123456789-$:/.+ABCD) def
84-
/barcharsalt (0123456789-$:/.+TN*E) def
85-
} ctxdef
86-
87-
/barchars altstartstop {barcharsalt} {barcharsnormal} ifelse def
81+
/barchars altstartstop {//rationalizedCodabar.barcharsalt} {//rationalizedCodabar.barchars} ifelse def
8882

8983
/charvals 20 dict def
9084
0 1 19 {charvals exch dup barchars exch 1 getinterval exch put} for
@@ -93,7 +87,9 @@ begin
9387
/ssvals 4 dict def
9488
16 1 19 {ssvals exch dup barchars exch 1 getinterval exch put} for
9589

90+
%
9691
% Validate the input
92+
%
9793
barcode 0 1 getinterval ssvals exch known not
9894
barcode barcode length 1 sub 1 getinterval ssvals exch known not or {
9995
altstartstop {
@@ -136,40 +132,48 @@ begin
136132
0 1 barlen 2 sub {
137133
/i exch def
138134
/indx charvals barcode i 1 getinterval get def
139-
/enc encs indx get def
135+
/enc //rationalizedCodabar.encs indx get def
140136
sbs i 8 mul enc putinterval % Put encoded digit into sbs
141137
txt i [barcode i 1 getinterval xpos textyoffset textfont textsize] put
142138
0 1 7 { % xpos+=width of the character
143139
/xpos exch enc exch get 48 sub xpos add def
144140
} for
145141
} for
146142

143+
%
147144
% Put the checksum character and stop character
145+
%
148146
includecheck {
147+
%
149148
% Put the checksum character
150-
sbs barlen 8 mul 8 sub encs checksum get putinterval
149+
%
150+
sbs barlen 8 mul 8 sub //rationalizedCodabar.encs checksum get putinterval
151151
includecheckintext {
152152
txt barlen 1 sub [barchars checksum 1 getinterval xpos textyoffset textfont textsize] put
153153
} {
154154
txt barlen 1 sub [( ) xpos textyoffset textfont textsize] put
155155
} ifelse
156156
0 1 7 { % xpos+=width of the character
157-
/xpos exch encs checksum get exch get 48 sub xpos add def
157+
/xpos exch //rationalizedCodabar.encs checksum get exch get 48 sub xpos add def
158158
} for
159+
160+
%
159161
% Put the end character
162+
%
160163
/indx charvals barcode barlen 1 sub 1 getinterval get def
161-
/enc encs indx get def % Get the indxth encoding
164+
/enc //rationalizedCodabar.encs indx get def % Get the indxth encoding
162165
sbs barlen 8 mul enc putinterval % Put encoded digit into sbs
163166
txt barlen [barcode barlen 1 sub 1 getinterval xpos textyoffset textfont textsize] put
164167
} {
168+
%
165169
% Put the end character
170+
%
166171
/indx charvals barcode barlen 1 sub 1 getinterval get def
167-
/enc encs indx get def % Get the indxth encoding
172+
/enc //rationalizedCodabar.encs indx get def % Get the indxth encoding
168173
sbs barlen 8 mul 8 sub enc putinterval % Put encoded digit into sbs
169174
txt barlen 1 sub [barcode barlen 1 sub 1 getinterval xpos textyoffset textfont textsize] put
170175
} ifelse
171176

172-
% Return the arguments
173177
<<
174178
/ren /renlinear
175179
/sbs [sbs {48 sub} forall]
@@ -183,8 +187,6 @@ begin
183187

184188
dontdraw not //renlinear if
185189

186-
//unloadctx exec
187-
188190
end
189191

190192
}

0 commit comments

Comments
 (0)