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

« back to all changes in this revision

Viewing changes to src/code93.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 code93--
 
35
% --REQUIRES preamble raiseerror renlinear--
 
36
% --DESC: Code 93
 
37
% --EXAM: THIS IS CODE 93
 
38
% --EXOP: includetext includecheck
 
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
/code93 {
 
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  % Enable/disable checkdigit
 
54
    /includetext false def   % Enable/disable text
 
55
    /textfont /Courier def
 
56
    /textsize 10 def
 
57
    /textyoffset -7 def
 
58
    /height 1 def
 
59
    /parsefnc false 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
    /textyoffset textyoffset cvr def
 
75
    /height height cvr def
 
76
    
 
77
    /encs
 
78
    [ (131112) (111213) (111312) (111411) (121113)
 
79
      (121212) (121311) (111114) (131211) (141111)
 
80
      (211113) (211212) (211311) (221112) (221211)
 
81
      (231111) (112113) (112212) (112311) (122112)
 
82
      (132111) (111123) (111222) (111321) (121122)
 
83
      (131121) (212112) (212211) (211122) (211221)
 
84
      (221121) (222111) (112122) (112221) (122121)
 
85
      (123111) (121131) (311112) (311211) (321111)
 
86
      (112131) (113121) (211131) (121221) (312111)
 
87
      (311121) (122211) (111141) (1111411)
 
88
    ] def
 
89
 
 
90
    % Create a string of the available characters
 
91
    /barchars (0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ-. $/+%) def
 
92
 
 
93
    /barlen barcode length def
 
94
 
 
95
    % Special function characters
 
96
    /sft1 -1 def  /sft2 -2 def  /sft3 -3 def  /sft4 -4 def
 
97
    /fncvals <<
 
98
        (SFT$) sft1
 
99
        (SFT%) sft2
 
100
        (SFT/) sft3
 
101
        (SFT+) sft4
 
102
    >> def
 
103
 
 
104
    % Convert input into bytes accounting for shift characters 
 
105
    /msg barlen array def
 
106
    /i 0 def /j 0 def {
 
107
        i barlen eq {exit} if
 
108
        /char barcode i get def
 
109
        parsefnc char 94 eq and i barlen 4 sub lt and {
 
110
            barcode i 1 add get 94 ne {
 
111
                /char fncvals barcode i 1 add 4 getinterval get def
 
112
                /i i 4 add def
 
113
            } {
 
114
                /i i 1 add def
 
115
            } ifelse
 
116
        } if
 
117
        msg j char put
 
118
        /i i 1 add def
 
119
        /j j 1 add def
 
120
    } loop
 
121
    /msg msg 0 j getinterval def
 
122
    /msglen msg length def
 
123
 
 
124
    includecheck {
 
125
        /sbs msglen 6 mul 25 add string def
 
126
    } {
 
127
        /sbs msglen 6 mul 13 add string def
 
128
    } ifelse
 
129
    /txt msglen array def
 
130
 
 
131
    % Put the start character
 
132
    sbs 0 encs 47 get putinterval
 
133
    
 
134
    /checksum1 0 def /checksum2 0 def
 
135
    0 1 msglen 1 sub {
 
136
        /i exch def
 
137
        % Lookup the encoding for the each barcode character
 
138
        msg i get dup 0 lt { 
 
139
            42 exch sub /indx exch def
 
140
            /char ( ) def
 
141
        } {
 
142
            1 string dup 0 4 -1 roll put /char exch def
 
143
            barchars char search
 
144
            pop                                  % Discard true leaving pre
 
145
            length /indx exch def                % indx is the length of pre
 
146
            pop pop                              % Discard seek and post
 
147
        } ifelse
 
148
        /enc encs indx get def                   % Get the indxth encoding
 
149
        sbs i 6 mul 6 add enc putinterval        % Put encoded digit into sbs
 
150
        txt i [char i 9 mul 9 add textyoffset textfont textsize] put
 
151
        /checksum1 checksum1 msglen i sub 1 sub 20 mod 1 add indx mul add def
 
152
        /checksum2 checksum2 msglen i sub 15 mod 1 add indx mul add def
 
153
    } for
 
154
 
 
155
    includecheck {
 
156
        % Put the first checksum character
 
157
        /checksum1 checksum1 47 mod def
 
158
        /checksum2 checksum2 checksum1 add 47 mod def
 
159
        sbs msglen 6 mul 6 add encs checksum1 get putinterval
 
160
        sbs msglen 6 mul 12 add encs checksum2 get putinterval
 
161
        % Put the end character
 
162
        sbs msglen 6 mul 18 add encs 48 get putinterval
 
163
    } {
 
164
        % Put the end character
 
165
        sbs msglen 6 mul 6 add encs 48 get putinterval      
 
166
    } ifelse
 
167
 
 
168
    % Return the arguments
 
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
/code93 dup load /uk.co.terryburton.bwipp defineresource pop
 
186
end
 
187
/setpacking where {pop setpacking} if
 
188
% --END ENCODER code93--