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

« back to all changes in this revision

Viewing changes to src/code39.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 code39--
 
35
% --REQUIRES preamble raiseerror renlinear--
 
36
% --DESC: Code 39
 
37
% --EXAM: THIS IS CODE 39
 
38
% --EXOP: includetext includecheck 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
/code39 {
 
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
    /hidestars false def
 
58
    /textfont /Courier def
 
59
    /textsize 10 def
 
60
    /textyoffset -7 def
 
61
    /height 1 def
 
62
    
 
63
    % Parse the input options
 
64
    options type /stringtype eq {
 
65
        1 dict begin
 
66
        options {
 
67
            token false eq {exit} if dup length string cvs (=) search
 
68
            true eq {cvlit exch pop exch def} {cvlit true def} ifelse
 
69
        } loop
 
70
        currentdict end /options exch def
 
71
    } if
 
72
    options {def} forall
 
73
 
 
74
    /textfont textfont cvlit def
 
75
    /textsize textsize cvr def
 
76
    /textyoffset textyoffset cvr def
 
77
    /height height cvr def
 
78
 
 
79
    % Create a string of the available characters
 
80
    /barchars (0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ-. $/+%) def
 
81
    /charvals 43 dict def
 
82
    0 1 42 {charvals exch dup barchars exch 1 getinterval exch put} for
 
83
 
 
84
    % Validate the input
 
85
    0 1 barcode length 1 sub {
 
86
        barcode exch 1 getinterval charvals exch known not {
 
87
            /bwipp.code39badCharacter (Code 39 must contain only digits, capital letters, spaces and the symbols -.$/+%) //raiseerror exec
 
88
        } if
 
89
    } for
 
90
 
 
91
    /barlen barcode length validatecheck {1 sub} if def
 
92
 
 
93
    /checksum 0 def
 
94
    0 1 barlen 1 sub {
 
95
        barcode exch 1 getinterval charvals exch get
 
96
        checksum add /checksum exch def
 
97
    } for
 
98
    /checksum checksum 43 mod def
 
99
    validatecheck {
 
100
        barcode barlen get barchars checksum get ne {
 
101
            /bwipp.code39badCheckDigit (Incorrect Code 39 check digit provided) //raiseerror exec
 
102
        } if
 
103
        /barcode barcode 0 barlen getinterval def
 
104
        /includecheck true def
 
105
    } if
 
106
 
 
107
    % Create an array containing the character mappings
 
108
    /encs
 
109
    [ (1113313111) (3113111131) (1133111131) (3133111111) (1113311131)
 
110
      (3113311111) (1133311111) (1113113131) (3113113111) (1133113111)
 
111
      (3111131131) (1131131131) (3131131111) (1111331131) (3111331111)
 
112
      (1131331111) (1111133131) (3111133111) (1131133111) (1111333111)
 
113
      (3111111331) (1131111331) (3131111311) (1111311331) (3111311311)
 
114
      (1131311311) (1111113331) (3111113311) (1131113311) (1111313311)
 
115
      (3311111131) (1331111131) (3331111111) (1311311131) (3311311111)
 
116
      (1331311111) (1311113131) (3311113111) (1331113111) (1313131111)
 
117
      (1313111311) (1311131311) (1113131311) (1311313111)
 
118
    ] def
 
119
 
 
120
    /sbs barlen includecheck {3} {2} ifelse add 10 mul string def
 
121
    /txt barlen includecheck {3} {2} ifelse add array def
 
122
 
 
123
    % Put the start character
 
124
    sbs 0 encs 43 get putinterval
 
125
    hidestars not {
 
126
        txt 0 [(*) 0 textyoffset textfont textsize] put
 
127
    } {
 
128
        txt 0 [() 0 textyoffset textfont textsize] put
 
129
    } ifelse
 
130
 
 
131
    0 1 barlen 1 sub {
 
132
        /i exch def
 
133
        /indx charvals barcode i 1 getinterval get def
 
134
        sbs i 10 mul 10 add encs indx get putinterval
 
135
        txt i 1 add [barcode i 1 getinterval i 1 add 16 mul textyoffset textfont textsize] put
 
136
    } for
 
137
 
 
138
    % Put the checksum and end characters
 
139
    includecheck {
 
140
        sbs barlen 10 mul 10 add encs checksum get putinterval
 
141
        includecheckintext {
 
142
            txt barlen 1 add [barchars checksum 1 getinterval barlen 1 add 16 mul textyoffset textfont textsize] put
 
143
        } {
 
144
            txt barlen 1 add [() barlen 1 add 16 mul textyoffset textfont textsize] put
 
145
        } ifelse
 
146
        sbs barlen 10 mul 20 add encs 43 get putinterval
 
147
        hidestars not {
 
148
            txt barlen 2 add [(*) barlen 2 add 16 mul textyoffset textfont textsize] put
 
149
        } {
 
150
            txt barlen 2 add [() barlen 2 add 16 mul textyoffset textfont textsize] put
 
151
        } ifelse
 
152
    } {
 
153
        sbs barlen 10 mul 10 add encs 43 get putinterval
 
154
        hidestars not {
 
155
            txt barlen 1 add [(*) barlen 1 add 16 mul textyoffset textfont textsize] put
 
156
        } {
 
157
            txt barlen 1 add [() barlen 1 add 16 mul textyoffset textfont textsize] put
 
158
        } ifelse
 
159
    } ifelse
 
160
    
 
161
    % Return the arguments
 
162
    <<
 
163
    /ren //renlinear
 
164
    /sbs [sbs {48 sub} forall]
 
165
    /bhs [sbs length 1 add 2 idiv {height} repeat]
 
166
    /bbs [sbs length 1 add 2 idiv {0} repeat]
 
167
    includetext {
 
168
        /txt txt
 
169
    } if
 
170
    /opt options
 
171
    >>
 
172
 
 
173
    dontdraw not //renlinear if
 
174
 
 
175
    end
 
176
 
 
177
} bind def
 
178
/code39 dup load /uk.co.terryburton.bwipp defineresource pop
 
179
end
 
180
/setpacking where {pop setpacking} if
 
181
% --END ENCODER code39--