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 /parseinput dup /uk.co.terryburton.bwipp findresource put
4745dup /renlinear dup /uk.co.terryburton.bwipp findresource put
4846dup /code39 dup /uk.co.terryburton.bwipp findresource put
4947begin
48+
49+ % Extended alphabet to non-extended alphabet
50+ /code39ext.extencs [
51+ (%U) ($A) ($B) ($C) ($D) ($E) ($F) ($G) ($H) ($I) ($J) ($K) ($L) ($M) ($N) ($O)
52+ ($P) ($Q) ($R) ($S) ($T) ($U) ($V) ($W) ($X) ($Y) ($Z) (%A) (%B) (%C) (%D) (%E)
53+ ( ) (/A) (/B) (/C) (/D) (/E) (/F) (/G) (/H) (/I) (/J) (/K) (/L) (-) (.) (/O)
54+ (0) (1) (2) (3) (4) (5) (6) (7) (8) (9) (/Z) (%F) (%G) (%H) (%I) (%J)
55+ (%V) (A) (B) (C) (D) (E) (F) (G) (H) (I) (J) (K) (L) (M) (N) (O)
56+ (P) (Q) (R) (S) (T) (U) (V) (W) (X) (Y) (Z) (%K) (%L) (%M) (%N) (%O)
57+ (%W) (+A) (+B) (+C) (+D) (+E) (+F) (+G) (+H) (+I) (+J) (+K) (+L) (+M) (+N) (+O)
58+ (+P) (+Q) (+R) (+S) (+T) (+U) (+V) (+W) (+X) (+Y) (+Z) (%P) (%Q) (%R) (%S) (%T)
59+ ] readonly def
60+
5061/code39ext {
5162
5263 20 dict begin
@@ -59,45 +70,35 @@ begin
5970 //processoptions exec /options exch def
6071 /barcode exch def
6172
62- /code39ext //loadctx exec
63-
73+ %
6474 % Parse ordinals of the form ^NNN to ASCII
75+ %
6576 /fncvals <<
6677 /parse parse
6778 /parseonly true
6879 /parsefnc false
6980 >> def
7081 /barcode barcode fncvals //parseinput exec def
82+
7183 /barlen barcode length def
84+
7285 options (parse) undef
7386
87+ %
7488 % Validate the input
89+ %
7590 barcode {
7691 128 ge {
7792 /bwipp.code39extBadCharacter (Code 39 Extended must contain only ASCII characters) //raiseerror exec
7893 } if
7994 } forall
8095
81- % Extended alphabet to non-extended alphabet
82- {
83- /extencs
84- [ (%U) ($A) ($B) ($C) ($D) ($E) ($F) ($G) ($H) ($I) ($J) ($K) ($L) ($M) ($N) ($O)
85- ($P) ($Q) ($R) ($S) ($T) ($U) ($V) ($W) ($X) ($Y) ($Z) (%A) (%B) (%C) (%D) (%E)
86- ( ) (/A) (/B) (/C) (/D) (/E) (/F) (/G) (/H) (/I) (/J) (/K) (/L) (-) (.) (/O)
87- (0) (1) (2) (3) (4) (5) (6) (7) (8) (9) (/Z) (%F) (%G) (%H) (%I) (%J)
88- (%V) (A) (B) (C) (D) (E) (F) (G) (H) (I) (J) (K) (L) (M) (N) (O)
89- (P) (Q) (R) (S) (T) (U) (V) (W) (X) (Y) (Z) (%K) (%L) (%M) (%N) (%O)
90- (%W) (+A) (+B) (+C) (+D) (+E) (+F) (+G) (+H) (+I) (+J) (+K) (+L) (+M) (+N) (+O)
91- (+P) (+Q) (+R) (+S) (+T) (+U) (+V) (+W) (+X) (+Y) (+Z) (%P) (%Q) (%R) (%S) (%T)
92- ] def
93- } ctxdef
94-
9596 /newcode barlen 2 mul string def
9697 /newtext barlen 2 mul string def
9798 /j 0 def
9899 0 1 barlen 1 sub {
99100 /i exch def
100- /extchar extencs barcode i get get def
101+ /extchar //code39ext. extencs barcode i get get def
101102 newcode j extchar putinterval
102103 newtext j barcode i get dup dup 32 lt exch 127 eq or { pop 32 } if put
103104 extchar length 1 ne { newtext j 1 add 32 put } if
@@ -106,11 +107,15 @@ begin
106107 /newcode newcode 0 j getinterval def
107108 /newtext newtext 0 j getinterval def
108109
110+ %
109111 % Get the result of encoding with code39
112+ %
110113 options (dontdraw) true put
111114 /args newcode options //code39 exec def
112115
116+ %
113117 % Replace chars in /txt with chars in newtext
118+ %
114119 includetext {
115120 /txt args (txt) get def
116121 0 1 newtext length 1 sub {
@@ -126,8 +131,6 @@ begin
126131
127132 dontdraw not //renlinear if
128133
129- //unloadctx exec
130-
131134 end
132135
133136}
0 commit comments