Skip to content

Commit ffbb3e2

Browse files
committed
code93: Uplift
1 parent ee009bc commit ffbb3e2

1 file changed

Lines changed: 68 additions & 47 deletions

File tree

src/code93.ps.src

Lines changed: 68 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -38,19 +38,61 @@
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 /parseinput dup /uk.co.terryburton.bwipp findresource put
4745
dup /renlinear dup /uk.co.terryburton.bwipp findresource put
4846
begin
47+
48+
/code93.encs [
49+
(131112) (111213) (111312) (111411) (121113) % 0-4
50+
(121212) (121311) (111114) (131211) (141111) % 5-9
51+
(211113) (211212) (211311) (221112) (221211) % A-E
52+
(231111) (112113) (112212) (112311) (122112) % F-J
53+
(132111) (111123) (111222) (111321) (121122) % K-O
54+
(131121) (212112) (212211) (211122) (211221) % P-T
55+
(221121) (222111) (112122) (112221) (122121) % U-Y
56+
(123111) (121131) (311112) (311211) (321111) % "Z" "-" "." " " "$"
57+
(112131) (113121) (211131) (121221) (312111) % "/" "+" "%" ($) (%)
58+
(311121) (122211) (111141) (1111411) % (/) (+) STA END
59+
] readonly def
60+
61+
/code93.barchars (0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ-. $/+%) readonly def
62+
63+
/code93.sft1 -1 def /code93.sft2 -2 def /code93.sft3 -3 def /code93.sft4 -4 def
64+
65+
/code93.latevars dup 1 dict def load /init {
66+
67+
currentglobal
68+
true setglobal
69+
70+
//code93.latevars begin
71+
72+
/charvals 47 dict def
73+
0 1 42 {
74+
charvals exch dup //code93.barchars exch get exch put
75+
} for
76+
charvals //code93.sft1 43 put
77+
charvals //code93.sft2 44 put
78+
charvals //code93.sft3 45 put
79+
charvals //code93.sft4 46 put
80+
/charvals charvals readonly def
81+
82+
/init { //code93.latevars {def} forall } def
83+
84+
end
85+
86+
//code93.latevars /init get exec
87+
88+
setglobal
89+
90+
} bind put
91+
4992
/code93 {
5093

51-
20 dict begin % Confine variables to local scope
94+
20 dict begin
5295

53-
/ctx null def
5496
/dontdraw false def
5597
/includecheck false def % Enable/disable checkdigit
5698
/includetext false def % Enable/disable text
@@ -64,49 +106,25 @@ begin
64106
//processoptions exec /options exch def
65107
/barcode exch def
66108

67-
/code93 //loadctx exec
68-
69-
{
70-
/encs
71-
[ (131112) (111213) (111312) (111411) (121113) % 0-4
72-
(121212) (121311) (111114) (131211) (141111) % 5-9
73-
(211113) (211212) (211311) (221112) (221211) % A-E
74-
(231111) (112113) (112212) (112311) (122112) % F-J
75-
(132111) (111123) (111222) (111321) (121122) % K-O
76-
(131121) (212112) (212211) (211122) (211221) % P-T
77-
(221121) (222111) (112122) (112221) (122121) % U-Y
78-
(123111) (121131) (311112) (311211) (321111) % "Z" "-" "." " " "$"
79-
(112131) (113121) (211131) (121221) (312111) % "/" "+" "%" ($) (%)
80-
(311121) (122211) (111141) (1111411) % (/) (+) STA END
81-
] def
82-
83-
% Create a string of the available characters
84-
/barchars (0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ-. $/+%) def
85-
/charvals 47 dict def
86-
0 1 42 {charvals exch dup barchars exch get exch put} for
87-
88-
/sft1 -1 def /sft2 -2 def /sft3 -3 def /sft4 -4 def
89-
90-
charvals sft1 43 put
91-
charvals sft2 44 put
92-
charvals sft3 45 put
93-
charvals sft4 46 put
94-
95-
} ctxdef
109+
//code93.latevars /init get exec
96110

111+
%
97112
% Special function characters
113+
%
98114
/fncvals <<
99115
/parse parse
100116
/parsefnc parsefnc
101-
(SFT$) sft1
102-
(SFT%) sft2
103-
(SFT/) sft3
104-
(SFT+) sft4
117+
(SFT$) //code93.sft1
118+
(SFT%) //code93.sft2
119+
(SFT/) //code93.sft3
120+
(SFT+) //code93.sft4
105121
>> def
106122
/msg barcode fncvals //parseinput exec def
107123
/msglen msg length def
108124

125+
%
109126
% Validate the input
127+
%
110128
msg {
111129
charvals exch known not {
112130
/bwipp.code93BadCharacter (Code 93 must only contain digits, capital letters, spaces, the symbols -.$/+ and shift non-data characters) //raiseerror exec
@@ -120,14 +138,16 @@ begin
120138
} ifelse
121139
/txt msglen array def
122140

141+
%
123142
% Put the start character
124-
sbs 0 encs 47 get putinterval
143+
%
144+
sbs 0 //code93.encs 47 get putinterval
125145

126146
/checksum1 0 def /checksum2 0 def
127147
0 1 msglen 1 sub {
128148
/i exch def
129149
/indx charvals msg i get get def
130-
sbs i 6 mul 6 add encs indx get putinterval
150+
sbs i 6 mul 6 add //code93.encs indx get putinterval
131151
/char msg i get dup 0 lt { pop ( ) } { 1 string dup 0 4 -1 roll put } ifelse def
132152
txt i [char i 9 mul 9 add textyoffset textfont textsize] put
133153
/checksum1 checksum1 msglen i sub 1 sub 20 mod 1 add indx mul add def
@@ -138,16 +158,19 @@ begin
138158
% Put the first checksum character
139159
/checksum1 checksum1 47 mod def
140160
/checksum2 checksum2 checksum1 add 47 mod def
141-
sbs msglen 6 mul 6 add encs checksum1 get putinterval
142-
sbs msglen 6 mul 12 add encs checksum2 get putinterval
161+
sbs msglen 6 mul 6 add //code93.encs checksum1 get putinterval
162+
sbs msglen 6 mul 12 add //code93.encs checksum2 get putinterval
163+
%
143164
% Put the end character
144-
sbs msglen 6 mul 18 add encs 48 get putinterval
165+
%
166+
sbs msglen 6 mul 18 add //code93.encs 48 get putinterval
145167
} {
168+
%
146169
% Put the end character
147-
sbs msglen 6 mul 6 add encs 48 get putinterval
170+
%
171+
sbs msglen 6 mul 6 add //code93.encs 48 get putinterval
148172
} ifelse
149173

150-
% Return the arguments
151174
<<
152175
/ren /renlinear
153176
/sbs [sbs {48 sub} forall]
@@ -161,8 +184,6 @@ begin
161184

162185
dontdraw not //renlinear if
163186

164-
//unloadctx exec
165-
166187
end
167188

168189
}

0 commit comments

Comments
 (0)