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 leitcode--
35
% --REQUIRES preamble raiseerror renlinear interleaved2of5--
36
% --DESC: Deutsche Post Leitcode
37
% --EXAM: 21348075016401
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 % Enable/disable text
55
/textfont /Courier def
61
% Parse the input options
62
options type /stringtype eq {
65
token false eq {exit} if dup length string cvs (=) search
66
true eq {cvlit exch pop exch def} {cvlit true def} ifelse
68
currentdict end /options exch def
72
/textfont textfont cvlit def
73
/textsize textsize cvr def
74
/textxoffset textxoffset cvr def
75
/textyoffset textyoffset cvr def
76
/height height cvr def
79
barcode length 13 ne barcode length 14 ne and {
80
/bwipp.leitcodeBadLength (Deutsche Post Leitcode must be 13 or 14 digits) //raiseerror exec
83
dup 48 lt exch 57 gt or {
84
/bwipp.leitcodeBadCharacter (Deutsche Post Leitcode must contain only digits) //raiseerror exec
88
% Calculate checksum and add to end of barcode
92
/checksum checksum barcode i get 48 sub i 2 mod 0 eq {4 mul} {9 mul} ifelse add def
94
/checksum 10 checksum 10 mod sub 10 mod def
95
barcode length 14 eq {
96
barcode 13 get checksum 48 add ne {
97
/bwipp.leitcodeBadCheckDigit (Incorrect Deutsche Post Leitcode check digit provided) //raiseerror exec
101
dup 0 barcode putinterval
102
dup 13 checksum 48 add put
105
% Compose the human readable text
106
/text ( . . . ) 18 string copy def
107
text 0 barcode 0 5 getinterval putinterval
108
text 6 barcode 5 3 getinterval putinterval
109
text 10 barcode 8 3 getinterval putinterval
110
text 14 barcode 11 2 getinterval putinterval
111
text 17 barcode 13 1 getinterval putinterval
113
% Get the result of encoding with interleaved2of5
114
options (dontdraw) true put
115
options (includecheck) false put
116
/args barcode options //interleaved2of5 exec def
118
args (txt) [ [text textxoffset textyoffset textfont textsize] ] put
119
args (textxalign) (center) put
120
args (opt) options put
123
dontdraw not //renlinear if
128
/leitcode dup load /uk.co.terryburton.bwipp defineresource pop
130
/setpacking where {pop setpacking} if
131
% --END ENCODER leitcode--