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%
3838currentglobal
3939true 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
4442dup /raiseerror dup /uk.co.terryburton.bwipp findresource put
4543dup /processoptions dup /uk.co.terryburton.bwipp findresource put
4644dup /renlinear dup /uk.co.terryburton.bwipp findresource put
4745begin
46+
47+ /planet.barchars (0123456789) readonly def
48+
49+ /planet.encs [
50+ (22555) (55522) (55252) (55225) (52552)
51+ (52525) (52255) (25552) (25525) (25255)
52+ (5) (5)
53+ ] readonly def
54+
4855/planet {
4956
5057 20 dict begin
@@ -62,11 +69,11 @@ begin
6269 //processoptions exec /options exch def
6370 /barcode exch def
6471
65- /planet //loadctx exec
66-
6772 /barlen barcode length validatecheck {1 sub} if def
6873
74+ %
6975 % Validate the input
76+ %
7077 barlen 11 ne barlen 13 ne and {
7178 /bwipp.planetBadLength (USPS PLANET must be 11 or 13 digits excluding check digit) //raiseerror exec
7279 } if
@@ -76,27 +83,17 @@ begin
7683 } if
7784 } forall
7885
79- {
80- % Create a string of the available characters
81- /barchars (0123456789) def
82-
83- % Create an array containing the character mappings
84- /encs
85- [ (22555) (55522) (55252) (55225) (52552)
86- (52525) (52255) (25552) (25525) (25255)
87- (5) (5)
88- ] def
89- } ctxdef
90-
86+ %
9187 % Calculate the checksum
88+ %
9289 /checksum 0 def
9390 0 1 barlen 1 sub {
9491 /i exch def
9592 /checksum checksum barcode i get 48 sub add def
9693 } for
9794 /checksum 10 checksum 10 mod sub 10 mod def
9895 validatecheck {
99- barcode barlen get barchars checksum get ne {
96+ barcode barlen get //planet. barchars checksum get ne {
10097 /bwipp.planetBadCheckDigit (Incorrect USPS PLANET check digit provided) //raiseerror exec
10198 } if
10299 /barcode barcode 0 barlen getinterval def
@@ -105,8 +102,10 @@ begin
105102 /bhs barlen 5 mul 7 add array def
106103 /txt barlen 1 add array def
107104
105+ %
108106 % Put start character
109- /enc encs 10 get def
107+ %
108+ /enc //planet.encs 10 get def
110109 /heights enc length array def
111110 0 1 enc length 1 sub {
112111 /j exch def
@@ -116,7 +115,7 @@ begin
116115
117116 0 1 barlen 1 sub {
118117 /i exch def
119- /enc encs barcode i get 48 sub get def
118+ /enc //planet. encs barcode i get 48 sub get def
120119 /heights enc length array def
121120 0 1 enc length 1 sub {
122121 /j exch def
@@ -126,8 +125,10 @@ begin
126125 txt i [barcode i 1 getinterval i 5 mul 1 add 3.312 mul textyoffset textfont textsize] put
127126 } for
128127
128+ %
129129 % Put the checksum character
130- /enc encs checksum get def
130+ %
131+ /enc //planet.encs checksum get def
131132 /heights enc length array def
132133 0 1 enc length 1 sub {
133134 /j exch def
@@ -136,21 +137,22 @@ begin
136137 bhs barlen 5 mul 1 add heights putinterval
137138
138139 includecheckintext {
139- txt barlen [barchars checksum 1 getinterval barlen 5 mul 1 add 3.312 mul textyoffset textfont textsize] put
140+ txt barlen [//planet. barchars checksum 1 getinterval barlen 5 mul 1 add 3.312 mul textyoffset textfont textsize] put
140141 } {
141142 txt barlen [( ) barlen 5 mul 1 add 72 mul 25 div textyoffset textfont textsize] put
142143 } ifelse
143144
145+ %
144146 % Put end character
145- /enc encs 11 get def
147+ %
148+ /enc //planet.encs 11 get def
146149 /heights enc length array def
147150 0 1 enc length 1 sub {
148151 /j exch def
149152 heights j enc j 1 getinterval cvi height mul 5 div put
150153 } for
151154 bhs barlen 5 mul 6 add heights putinterval
152155
153- % Return the arguments
154156 <<
155157 /ren /renlinear
156158 /bhs bhs
@@ -164,8 +166,6 @@ begin
164166
165167 dontdraw not //renlinear if
166168
167- //unloadctx exec
168-
169169 end
170170
171171}
0 commit comments