Skip to content

Commit 6d33e2b

Browse files
committed
hibccodablockf: Uplift
1 parent fba55f0 commit 6d33e2b

1 file changed

Lines changed: 36 additions & 17 deletions

File tree

src/hibccodablockf.ps.src

Lines changed: 36 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -38,17 +38,41 @@
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 /renmatrix dup /uk.co.terryburton.bwipp findresource put
4745
dup /codablockf dup /uk.co.terryburton.bwipp findresource put
4846
begin
47+
48+
/hibccodablockf.barchars (0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ-. $/+%) readonly def
49+
50+
/hibccodablockf.latevars dup 1 dict def load /init {
51+
52+
currentglobal
53+
true setglobal
54+
55+
//hibccodablockf.latevars begin
56+
57+
/charvals 43 dict def
58+
0 1 42 {
59+
charvals exch dup //hibccodablockf.barchars exch 1 getinterval exch put
60+
} for
61+
/charvals charvals readonly def
62+
63+
/init { //hibccodablockf.latevars {def} forall } def
64+
65+
end
66+
67+
//hibccodablockf.latevars /init get exec
68+
69+
setglobal
70+
71+
} bind put
72+
4973
/hibccodablockf {
5074

51-
20 dict begin % Confine variables to local scope
75+
20 dict begin
5276

5377
/ctx null def
5478
/dontdraw false def
@@ -57,20 +81,15 @@ begin
5781
//processoptions exec /options exch def
5882
/barcode exch def
5983

84+
//hibccodablockf.latevars /init get exec
85+
6086
barcode () eq {
6187
/bwipp.hibccodablockfEmptyData (The data must not be empty) //raiseerror exec
6288
} if
6389

64-
/hibccodablockf //loadctx exec
65-
66-
% Create a string of the available characters
67-
{
68-
/barchars (0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ-. $/+%) def
69-
/charvals 43 dict def
70-
0 1 42 {charvals exch dup barchars exch 1 getinterval exch put} for
71-
} ctxdef
72-
90+
%
7391
% Validate the input
92+
%
7493
0 1 barcode length 1 sub {
7594
barcode exch 1 getinterval charvals exch known not {
7695
/bwipp.hibccodablockfBadCharacter (HIBC Codablock F must contain only digits, capital letters, spaces and the symbols -.$/+%) //raiseerror exec
@@ -86,17 +105,19 @@ begin
86105
} for
87106
/checksum checksum 43 mod def
88107
validatecheck {
89-
barcode barlen get barchars checksum get ne {
108+
barcode barlen get //hibccodablockf.barchars checksum get ne {
90109
/bwipp.hibccodablockfBadCheckDigit (Incorrect HIBC Codablock F check digit provided) //raiseerror exec
91110
} if
92111
/barcode barcode 0 barlen getinterval def
93112
} if
94113

95114
/barcode barlen 2 add string dup 1 barcode putinterval def
96115
barcode 0 43 put
97-
barcode barlen 1 add barchars checksum get put
116+
barcode barlen 1 add //hibccodablockf.barchars checksum get put
98117

118+
%
99119
% Get the result of encoding with codablockf
120+
%
100121
options (dontdraw) true put
101122
options (validatecheck) false put
102123
/args barcode options //codablockf exec def
@@ -106,8 +127,6 @@ begin
106127

107128
dontdraw not //renmatrix if
108129

109-
//unloadctx exec
110-
111130
end
112131

113132
}

0 commit comments

Comments
 (0)