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

« back to all changes in this revision

Viewing changes to src/itf14.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 itf14--
 
35
% --REQUIRES preamble raiseerror renlinear interleaved2of5--
 
36
% --DESC: ITF-14
 
37
% --EXAM: 04601234567893
 
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
/itf14 {
 
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
 
55
    /includecheckintext true def
 
56
    /textfont /Courier def
 
57
    /textsize 10 def
 
58
    /textxoffset 0 def
 
59
    /textyoffset -10 def
 
60
    /height 0.5 def
 
61
    /showborder true def
 
62
    /borderwidth 4 def
 
63
    /borderleft 15 def
 
64
    /borderright 15 def
 
65
 
 
66
    % Parse the input options
 
67
    options type /stringtype eq {
 
68
        1 dict begin
 
69
        options {
 
70
            token false eq {exit} if dup length string cvs (=) search
 
71
            true eq {cvlit exch pop exch def} {cvlit true def} ifelse
 
72
        } loop
 
73
        currentdict end /options exch def
 
74
    } if
 
75
    options {def} forall
 
76
 
 
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
 
85
 
 
86
    % Validate the input
 
87
    barcode length 13 ne barcode length 14 ne and {
 
88
        /bwipp.itf14badLength (ITF-14 must be 13 or 14 digits) //raiseerror exec
 
89
    } if
 
90
    barcode {
 
91
        dup 48 lt exch 57 gt or {
 
92
            /bwipp.itf14badCharacter (ITF-14 must contain only digits) //raiseerror exec
 
93
        } if
 
94
    } forall
 
95
 
 
96
    % Calculate ITF checksum and add to end of barcode
 
97
    /checksum 0 def
 
98
    0 1 12 {
 
99
        /i exch def
 
100
        /checksum checksum barcode i get 48 sub i 2 mod 0 eq {3 mul} if add def
 
101
    } for
 
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
 
106
        } if
 
107
    } if
 
108
    14 string
 
109
    dup 0 barcode putinterval
 
110
    dup 13 checksum 48 add put
 
111
    /barcode exch def
 
112
 
 
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
 
123
 
 
124
    args (opt) options put
 
125
    args
 
126
 
 
127
    dontdraw not //renlinear if
 
128
 
 
129
    end
 
130
 
 
131
} bind def
 
132
/itf14 dup load /uk.co.terryburton.bwipp defineresource pop
 
133
end
 
134
/setpacking where {pop setpacking} if
 
135
% --END ENCODER itf14--