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

« back to all changes in this revision

Viewing changes to src/bc412.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 bc412--
 
35
% --REQUIRES preamble raiseerror renlinear--
 
36
% --DESC: BC412
 
37
% --EXAM: BC412
 
38
% --EXOP: semi includetext includecheckintext
 
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
begin
 
45
/bc412 {
 
46
 
 
47
    20 dict begin                 % Confine variables to local scope
 
48
 
 
49
    /options exch def       % We are given an option string
 
50
    /barcode exch def       % We are given a barcode string
 
51
 
 
52
    /dontdraw false def
 
53
    /includecheck false def
 
54
    /validatecheck false def
 
55
    /includetext false def
 
56
    /includecheckintext false def
 
57
    /includestartstop false def
 
58
    /semi false def
 
59
    /textfont /Courier def
 
60
    /textsize 10 def
 
61
    /textyoffset -7 def
 
62
    /height 1 def
 
63
    
 
64
    % Parse the input options
 
65
    options type /stringtype eq {
 
66
        1 dict begin
 
67
        options {
 
68
            token false eq {exit} if dup length string cvs (=) search
 
69
            true eq {cvlit exch pop exch def} {cvlit true def} ifelse
 
70
        } loop
 
71
        currentdict end /options exch def
 
72
    } if
 
73
    options {def} forall
 
74
 
 
75
    /textfont textfont cvlit def
 
76
    /textsize textsize cvr def
 
77
    /textyoffset textyoffset cvr def
 
78
    /height height cvr def
 
79
   
 
80
    semi {
 
81
        /includecheck true def
 
82
        /includestartstop true def
 
83
    } if
 
84
 
 
85
    % Create a string of the available characters
 
86
    /barchars (0R9GLVHA8EZ4NTS1J2Q6C7DYKBUIX3FWP5M) def
 
87
    /charvals 35 dict def
 
88
    0 1 34 {charvals exch dup barchars exch 1 getinterval exch put} for
 
89
 
 
90
    % Validate the input
 
91
    0 1 barcode length 1 sub {
 
92
        barcode exch 1 getinterval charvals exch known not {
 
93
            /bwipp.bc412badCharacter (BC412 must contain only digits and capital letters except O) //raiseerror exec
 
94
        } if
 
95
    } for
 
96
 
 
97
    /barlen barcode length validatecheck {1 sub} if def
 
98
 
 
99
    /checksum 0 def
 
100
    0 1 barlen 1 sub {
 
101
        barcode exch 1 getinterval charvals exch get
 
102
        checksum add /checksum exch def
 
103
    } for
 
104
    /checksum checksum 35 mod def
 
105
    validatecheck {
 
106
        barcode barlen get barchars checksum get ne {
 
107
            /bwipp.bc412badCheckDigit (Incorrect BC412 check digit provided) //raiseerror exec
 
108
        } if
 
109
        /barcode barcode 0 barlen getinterval def
 
110
        /includecheck true def
 
111
    } if
 
112
 
 
113
    % Create an array containing the character mappings
 
114
    /encs
 
115
    [ (11111115) (13111212) (11131113) (12111213) (12121311)
 
116
      (13131111) (12111312) (11131212) (11121411) (11151111)
 
117
      (15111111) (11111511) (12131211) (13121112) (13111212)
 
118
      (11111214) (12121113) (11111313) (13111113) (11121213)
 
119
      (11141112) (11121312) (11141211) (14121111) (12121212)
 
120
      (11131311) (13121211) (12111411) (14111211) (11111412)
 
121
      (12111114) (14111112) (12141111) (11121114) (12131112)
 
122
      (12) (111)
 
123
    ] def
 
124
 
 
125
    /sbs barlen 1 add 8 mul 5 add string def
 
126
    includecheck {
 
127
        /txt barlen 1 add array def
 
128
    } {
 
129
        /txt barlen array def
 
130
    } ifelse
 
131
 
 
132
    % Put the start character
 
133
    includestartstop {
 
134
        sbs 0 encs 35 get putinterval
 
135
        /pos 2 def
 
136
        /txtpos 3 def
 
137
    } {
 
138
        /pos 0 def
 
139
        /txtpos 0 def
 
140
    } ifelse
 
141
 
 
142
    0 1 barlen 1 sub {
 
143
        /i exch def
 
144
        /indx charvals barcode i 1 getinterval get def
 
145
        sbs pos encs indx get putinterval
 
146
        txt i [barcode i 1 getinterval i 12 mul txtpos add textyoffset textfont textsize] put
 
147
        /pos pos 8 add def
 
148
    } for
 
149
 
 
150
    % Put the checksum
 
151
    includecheck {
 
152
        sbs pos encs checksum get putinterval
 
153
        includecheckintext {
 
154
            txt barlen [barchars checksum 1 getinterval barlen 12 mul txtpos add textyoffset textfont textsize] put
 
155
        } {
 
156
            txt barlen [() barlen 12 mul txtpos add textyoffset textfont textsize] put
 
157
        } ifelse
 
158
        /pos pos 8 add def
 
159
    } if 
 
160
 
 
161
    % Put the stop character
 
162
    includestartstop { 
 
163
        sbs pos encs 36 get putinterval
 
164
        /pos pos 2 add def
 
165
    } if
 
166
 
 
167
    % Return the arguments
 
168
    /sbs sbs 0 pos getinterval def 
 
169
    <<
 
170
    /ren //renlinear
 
171
    /sbs [sbs {48 sub} forall]
 
172
    /bhs [sbs length 1 add 2 idiv {height} repeat]
 
173
    /bbs [sbs length 1 add 2 idiv {0} repeat]
 
174
    includetext {
 
175
        /txt txt
 
176
    } if
 
177
    /opt options
 
178
    >>
 
179
 
 
180
    dontdraw not //renlinear if
 
181
 
 
182
    end
 
183
 
 
184
} bind def
 
185
/bc412 dup load /uk.co.terryburton.bwipp defineresource pop
 
186
end
 
187
/setpacking where {pop setpacking} if
 
188
% --END ENCODER bc412--