~ubuntu-branches/ubuntu/wily/libpostscriptbarcode/wily

« back to all changes in this revision

Viewing changes to src/hibcdatamatrix.ps

  • Committer: Package Import Robot
  • Author(s): Alexander List
  • Date: 2014-06-06 17:37:19 UTC
  • mfrom: (1.1.2)
  • Revision ID: package-import@ubuntu.com-20140606173719-rvjku8todk2j353x
Tags: 20140312-2
* acknowledge package from maintainer
* debian/control: Use latest Standards-Version

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
%!PS
 
2
 
 
3
% Barcode Writer in Pure PostScript
 
4
% http://www.terryburton.co.uk/barcodewriter/
 
5
%
 
6
% Copyright (c) 2004-2014 Terry Burton
 
7
%
 
8
% $Id$
 
9
%
 
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
 
18
% conditions:
 
19
%
 
20
% The above copyright notice and this permission notice
 
21
% shall be included in all copies or substantial portions
 
22
% of the Software.
 
23
%
 
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
 
32
% IN THE SOFTWARE.
 
33
 
 
34
% --BEGIN ENCODER hibcdatamatrix--
 
35
% --REQUIRES preamble raiseerror renmatrix datamatrix--
 
36
% --DESC: HIBC Data Matrix
 
37
% --EXAM: A123BJC5D6E71
 
38
% --EXOP:
 
39
% --RNDR: renmatrix
 
40
/setpacking where {pop currentpacking true setpacking} if
 
41
1 dict
 
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
 
45
begin
 
46
/hibcdatamatrix {
 
47
 
 
48
    20 dict begin                 % Confine variables to local scope
 
49
 
 
50
    /options exch def       % We are given an option string
 
51
    /barcode exch def       % We are given a barcode string
 
52
 
 
53
    /dontdraw false def
 
54
    /validatecheck false def
 
55
 
 
56
    % Parse the input options
 
57
    options type /stringtype eq {
 
58
        1 dict begin
 
59
        options {
 
60
            token false eq {exit} if dup length string cvs (=) search
 
61
            true eq {cvlit exch pop exch def} {cvlit true def} ifelse
 
62
        } loop
 
63
        currentdict end /options exch def
 
64
    } if
 
65
    options {def} forall
 
66
 
 
67
    % Create a string of the available characters
 
68
    /barchars (0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ-. $/+%) def
 
69
    /charvals 43 dict def
 
70
    0 1 42 {charvals exch dup barchars exch 1 getinterval exch put} for
 
71
 
 
72
    % Validate the input
 
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
 
76
        } if
 
77
    } for
 
78
 
 
79
    /barlen barcode length validatecheck {1 sub} if def
 
80
 
 
81
    /checksum 41 def
 
82
    0 1 barlen 1 sub {
 
83
        barcode exch 1 getinterval charvals exch get
 
84
        checksum add /checksum exch def
 
85
    } for
 
86
    /checksum checksum 43 mod def
 
87
    validatecheck {
 
88
        barcode barlen get barchars checksum get ne {
 
89
            /bwipp.hibcdatamatrixBadCheckDigit (Incorrect HIBC Data Matrix check digit provided) //raiseerror exec
 
90
        } if
 
91
        /barcode barcode 0 barlen getinterval def
 
92
    } if
 
93
 
 
94
    /barcode barlen 2 add string dup 1 barcode putinterval def
 
95
    barcode 0 43 put
 
96
    barcode barlen 1 add barchars checksum get put
 
97
 
 
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
 
102
 
 
103
    args (opt) options put
 
104
    args
 
105
 
 
106
    dontdraw not //renmatrix if
 
107
 
 
108
    end
 
109
 
 
110
} bind def
 
111
/hibcdatamatrix dup load /uk.co.terryburton.bwipp defineresource pop
 
112
end
 
113
/setpacking where {pop setpacking} if
 
114
% --END ENCODER hibcdatamatrix--