3
% Barcode Writer in Pure PostScript
4
% http://www.terryburton.co.uk/barcodewriter/
6
% Copyright (c) 2004-2014 Terry Burton
10
% Permission is hereby granted, free of charge, to any
11
% person obtaining a copy of this software and associated
12
% documentation files (the "Software"), to deal in the
13
% Software without restriction, including without
14
% limitation the rights to use, copy, modify, merge,
15
% publish, distribute, sublicense, and/or sell copies of
16
% the Software, and to permit persons to whom the Software
17
% is furnished to do so, subject to the following
20
% The above copyright notice and this permission notice
21
% shall be included in all copies or substantial portions
24
% THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY
25
% KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO
26
% THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A
27
% PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
28
% THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
29
% DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF
30
% CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
31
% CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
34
% --BEGIN ENCODER hibccode39--
35
% --REQUIRES preamble raiseerror renlinear code39--
36
% --DESC: HIBC Code 39
37
% --EXAM: A123BJC5D6E71
40
/setpacking where {pop currentpacking true setpacking} if
42
dup /raiseerror dup /uk.co.terryburton.bwipp findresource put
43
dup /renlinear dup /uk.co.terryburton.bwipp findresource put
44
dup /code39 dup /uk.co.terryburton.bwipp findresource put
48
20 dict begin % Confine variables to local scope
50
/options exch def % We are given an option string
51
/barcode exch def % We are given a barcode string
54
/textfont /Courier def
58
/validatecheck false def
60
% Parse the input options
61
options type /stringtype eq {
64
token false eq {exit} if dup length string cvs (=) search
65
true eq {cvlit exch pop exch def} {cvlit true def} ifelse
67
currentdict end /options exch def
71
/textfont textfont cvlit def
72
/textsize textsize cvr def
73
/textyoffset textyoffset cvr def
74
/textxoffset textxoffset cvr def
76
% Create a string of the available characters
77
/barchars (0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ-. $/+%) def
79
0 1 42 {charvals exch dup barchars exch 1 getinterval exch put} for
82
0 1 barcode length 1 sub {
83
barcode exch 1 getinterval charvals exch known not {
84
/bwipp.hibccode39badCharacter (HIBC Code 39 must contain only digits, capital letters, spaces and the symbols -.$/+%) //raiseerror exec
88
/barlen barcode length validatecheck {1 sub} if def
92
barcode exch 1 getinterval charvals exch get
93
checksum add /checksum exch def
95
/checksum checksum 43 mod def
97
barcode barlen get barchars checksum get ne {
98
/bwipp.hibccode39badCheckDigit (Incorrect HIBC Code 39 check digit provided) //raiseerror exec
100
/barcode barcode 0 barlen getinterval def
103
/barcode barlen 2 add string dup 1 barcode putinterval def
105
barcode barlen 1 add barchars checksum get put
107
/text barlen 4 add string def
109
text 1 barcode putinterval
110
text barlen 2 add barcode barlen 1 add get dup 32 eq {pop 95} if put
111
text barlen 3 add 42 put
113
% Get the result of encoding with code39
114
options (dontdraw) true put
115
options (includecheck) false put
116
options (validatecheck) false put
117
/args barcode options //code39 exec def
119
args (txt) [ [text textxoffset textyoffset textfont textsize] ] put
120
args (textxalign) (center) put
121
args (opt) options put
124
dontdraw not //renlinear if
129
/hibccode39 dup load /uk.co.terryburton.bwipp defineresource pop
131
/setpacking where {pop setpacking} if
132
% --END ENCODER hibccode39--