Skip to content

Commit bc735d5

Browse files
committed
japanpost: Uplift
1 parent 31cfbd0 commit bc735d5

1 file changed

Lines changed: 33 additions & 30 deletions

File tree

src/japanpost.ps.src

Lines changed: 33 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,26 @@
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+
/japanpost.encs [
48+
(300) (330) (312) (132) (321) (303) (123) (231) (213) (033) (030) % 0-9 and "-"
49+
(120) (102) (210) (012) (201) (021) (003) (333) % C1-C8
50+
(31) (13) % ST EN
51+
] readonly def
52+
53+
/japanpost.barchars (0123456789-ABCDEFGHIJKLMNOPQRSTUVWXYZ) readonly def
54+
4855
/japanpost {
4956

5057
20 dict begin
5158

5259
/ctx null def
60+
5361
/dontdraw false def
5462
/includetext false def % Enable/disable text
5563
/includecheckintext false def
@@ -65,9 +73,9 @@ begin
6573
/bwipp.japanpostEmptyData (The data must not be empty) //raiseerror exec
6674
} if
6775

68-
/japanpost //loadctx exec
69-
76+
%
7077
% Validate the input
78+
%
7179
barcode {
7280
dup dup 48 ge exch 57 le and exch % 0-9
7381
dup dup 65 ge exch 90 le and exch % A-Z
@@ -76,33 +84,23 @@ begin
7684
} if
7785
} forall
7886

79-
{
80-
% Create an array containing the character mappings
81-
/encs
82-
[ (300) (330) (312) (132) (321) (303) (123) (231) (213) (033) (030) % 0-9 and "-"
83-
(120) (102) (210) (012) (201) (021) (003) (333) % C1-C8
84-
(31) (13) % ST EN
85-
] def
86-
87-
% Create a string of the available characters
88-
/barchars (0123456789-ABCDEFGHIJKLMNOPQRSTUVWXYZ) def
89-
} ctxdef
90-
9187
/barlen barcode length def
9288

9389
/encstr 20 1 add 3 mul 4 add string def
9490
/digits 20 array def
9591
/txt barlen 1 add array def
9692

93+
%
9794
% Put start character
98-
encstr 0 encs 19 get putinterval
95+
%
96+
encstr 0 //japanpost.encs 19 get putinterval
9997

10098
/checksum 0 def
10199
/j 0 def /i 0 def
102100
true
103101
0 1 barlen 1 sub {
104102
/i exch def
105-
barcode i 1 getinterval barchars exch search
103+
barcode i 1 getinterval //japanpost.barchars exch search
106104
pop % Discard true leaving pre
107105
length /indx exch def % indx is the length of pre
108106
pop pop % Discard match and post
@@ -112,7 +110,7 @@ begin
112110
% 21-30: C2 (12)
113111
% 31-36: C3 (13)
114112
/digit indx 1 sub 10 idiv 10 add def
115-
encstr j 3 mul 2 add encs digit get putinterval
113+
encstr j 3 mul 2 add //japanpost.encs digit get putinterval
116114
/checksum checksum digit add def
117115
digits j digit put
118116
/j j 1 add def
@@ -128,7 +126,7 @@ begin
128126
indx 11 lt {
129127
/digit indx def
130128
} if
131-
encstr j 3 mul 2 add encs digit get putinterval % space
129+
encstr j 3 mul 2 add //japanpost.encs digit get putinterval % space
132130
/checksum checksum digit add def
133131
digits j digit put
134132
txt i [barcode i 1 getinterval j 3 mul 2 add 3.312 mul textyoffset textfont textsize] put
@@ -139,28 +137,36 @@ begin
139137
/bwipp.japanpostTooLong (The input is too long) //raiseerror exec
140138
} if
141139

140+
%
142141
% Fill spaces (c14) at right end
142+
%
143143
j 1 20 1 sub {
144144
/k exch def
145-
encstr k 3 mul 2 add encs 14 get putinterval
145+
encstr k 3 mul 2 add //japanpost.encs 14 get putinterval
146146
/checksum checksum 14 add def
147147
digits k 14 put
148148
} for
149149

150+
%
150151
% Put the checksum character
152+
%
151153
/checksum checksum 19 mod 19 exch sub def
152-
encstr 2 20 3 mul add encs checksum get putinterval
154+
encstr 2 20 3 mul add //japanpost.encs checksum get putinterval
153155

156+
%
154157
% Put end character
155-
encstr 2 21 3 mul add encs 20 get putinterval
158+
%
159+
encstr 2 21 3 mul add //japanpost.encs 20 get putinterval
156160
/checkdigit ( ) def
157161
includecheckintext {
158-
/checkdigit barchars checksum 1 getinterval def
162+
/checkdigit //japanpost.barchars checksum 1 getinterval def
159163
} if
160164
txt i 1 add [ checkdigit 20 3 mul 2 add 3.312 mul textyoffset textfont textsize] put
161165

166+
%
162167
% Put end character
163-
encstr 20 1 add 3 mul 2 add encs 20 get putinterval
168+
%
169+
encstr 20 1 add 3 mul 2 add //japanpost.encs 20 get putinterval
164170

165171
/bbs 21 3 mul 4 add array def
166172
/bhs bbs length array def
@@ -189,7 +195,6 @@ begin
189195
bhs i hunit height mul 8 div put
190196
} for
191197

192-
% Return the arguments
193198
<<
194199
/ren /renlinear
195200
/bbs bbs
@@ -203,8 +208,6 @@ begin
203208

204209
dontdraw not //renlinear if
205210

206-
//unloadctx exec
207-
208211
end
209212

210213
}

0 commit comments

Comments
 (0)