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 itf14--
35
% --REQUIRES preamble raiseerror renlinear interleaved2of5--
37
% --EXAM: 04601234567893
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 /interleaved2of5 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
/includetext false def
55
/includecheckintext true def
56
/textfont /Courier def
66
% Parse the input options
67
options type /stringtype eq {
70
token false eq {exit} if dup length string cvs (=) search
71
true eq {cvlit exch pop exch def} {cvlit true def} ifelse
73
currentdict end /options exch def
77
/textfont textfont cvlit def
78
/textsize textsize cvr def
79
/textxoffset textxoffset cvr def
80
/textyoffset textyoffset cvr def
81
/height height cvr def
82
/borderwidth borderwidth cvr def
83
/borderleft borderleft cvr def
84
/borderright borderright cvr def
87
barcode length 13 ne barcode length 14 ne and {
88
/bwipp.itf14badLength (ITF-14 must be 13 or 14 digits) //raiseerror exec
91
dup 48 lt exch 57 gt or {
92
/bwipp.itf14badCharacter (ITF-14 must contain only digits) //raiseerror exec
96
% Calculate ITF checksum and add to end of barcode
100
/checksum checksum barcode i get 48 sub i 2 mod 0 eq {3 mul} if add def
102
/checksum 10 checksum 10 mod sub 10 mod def
103
barcode length 14 eq {
104
barcode 13 get checksum 48 add ne {
105
/bwipp.itf14badCheckDigit (Incorrect ITF-14 check digit provided) //raiseerror exec
109
dup 0 barcode putinterval
110
dup 13 checksum 48 add put
113
% Get the result of encoding with interleaved2of5
114
options (dontdraw) true put
115
options (showborder) showborder put
116
options (borderwidth) borderwidth put
117
options (borderleft) borderleft put
118
options (borderright) borderright put
119
options (height) height put
120
options (textyoffset) textyoffset put
121
options (includecheckintext) includecheckintext put
122
/args barcode options //interleaved2of5 exec def
124
args (opt) options put
127
dontdraw not //renlinear if
132
/itf14 dup load /uk.co.terryburton.bwipp defineresource pop
134
/setpacking where {pop setpacking} if
135
% --END ENCODER itf14--