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

« back to all changes in this revision

Viewing changes to src/leitcode.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 leitcode--
 
35
% --REQUIRES preamble raiseerror renlinear interleaved2of5--
 
36
% --DESC: Deutsche Post Leitcode
 
37
% --EXAM: 21348075016401
 
38
% --EXOP: includetext
 
39
% --RNDR: renlinear
 
40
/setpacking where {pop currentpacking true setpacking} if
 
41
1 dict
 
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
 
45
begin
 
46
/leitcode {
 
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
    /includetext false def    % Enable/disable text
 
55
    /textfont /Courier def
 
56
    /textsize 10 def
 
57
    /textxoffset 0 def
 
58
    /textyoffset -7 def
 
59
    /height 1 def
 
60
 
 
61
    % Parse the input options
 
62
    options type /stringtype eq {
 
63
        1 dict begin
 
64
        options {
 
65
            token false eq {exit} if dup length string cvs (=) search
 
66
            true eq {cvlit exch pop exch def} {cvlit true def} ifelse
 
67
        } loop
 
68
        currentdict end /options exch def
 
69
    } if
 
70
    options {def} forall
 
71
 
 
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 
 
77
 
 
78
    % Validate the input
 
79
    barcode length 13 ne barcode length 14 ne and {
 
80
        /bwipp.leitcodeBadLength (Deutsche Post Leitcode must be 13 or 14 digits) //raiseerror exec
 
81
    } if
 
82
    barcode {
 
83
        dup 48 lt exch 57 gt or {
 
84
            /bwipp.leitcodeBadCharacter (Deutsche Post Leitcode must contain only digits) //raiseerror exec
 
85
        } if
 
86
    } forall
 
87
 
 
88
    % Calculate checksum and add to end of barcode
 
89
    /checksum 0 def
 
90
    0 1 12 {
 
91
        /i exch def
 
92
        /checksum checksum barcode i get 48 sub i 2 mod 0 eq {4 mul} {9 mul} ifelse add def
 
93
    } for 
 
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
 
98
        } if
 
99
    } if
 
100
    14 string
 
101
    dup 0 barcode putinterval
 
102
    dup 13 checksum 48 add put
 
103
    /barcode exch def
 
104
 
 
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
 
112
 
 
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
 
117
 
 
118
    args (txt) [ [text textxoffset textyoffset textfont textsize] ] put
 
119
    args (textxalign) (center) put
 
120
    args (opt) options put
 
121
    args
 
122
 
 
123
    dontdraw not //renlinear if
 
124
 
 
125
    end
 
126
 
 
127
} bind def
 
128
/leitcode dup load /uk.co.terryburton.bwipp defineresource pop
 
129
end
 
130
/setpacking where {pop setpacking} if
 
131
% --END ENCODER leitcode--