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 hibcdatamatrix--
35
% --REQUIRES preamble raiseerror renmatrix datamatrix--
36
% --DESC: HIBC Data Matrix
37
% --EXAM: A123BJC5D6E71
40
/setpacking where {pop currentpacking true setpacking} if
42
dup /raiseerror dup /uk.co.terryburton.bwipp findresource put
43
dup /renmatrix dup /uk.co.terryburton.bwipp findresource put
44
dup /datamatrix 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
/validatecheck false def
56
% Parse the input options
57
options type /stringtype eq {
60
token false eq {exit} if dup length string cvs (=) search
61
true eq {cvlit exch pop exch def} {cvlit true def} ifelse
63
currentdict end /options exch def
67
% Create a string of the available characters
68
/barchars (0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ-. $/+%) def
70
0 1 42 {charvals exch dup barchars exch 1 getinterval exch put} for
73
0 1 barcode length 1 sub {
74
barcode exch 1 getinterval charvals exch known not {
75
/bwipp.hibcdatamatrixBadCharacter (HIBC Data Matrix must contain only digits, capital letters, spaces and the symbols -.$/+%) //raiseerror exec
79
/barlen barcode length validatecheck {1 sub} if def
83
barcode exch 1 getinterval charvals exch get
84
checksum add /checksum exch def
86
/checksum checksum 43 mod def
88
barcode barlen get barchars checksum get ne {
89
/bwipp.hibcdatamatrixBadCheckDigit (Incorrect HIBC Data Matrix check digit provided) //raiseerror exec
91
/barcode barcode 0 barlen getinterval def
94
/barcode barlen 2 add string dup 1 barcode putinterval def
96
barcode barlen 1 add barchars checksum get put
98
% Get the result of encoding with datamatrix
99
options (dontdraw) true put
100
options (validatecheck) false put
101
/args barcode options //datamatrix exec def
103
args (opt) options put
106
dontdraw not //renmatrix if
111
/hibcdatamatrix dup load /uk.co.terryburton.bwipp defineresource pop
113
/setpacking where {pop setpacking} if
114
% --END ENCODER hibcdatamatrix--