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

« back to all changes in this revision

Viewing changes to src/hibccode39.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 hibccode39--
 
35
% --REQUIRES preamble raiseerror renlinear code39--
 
36
% --DESC: HIBC Code 39
 
37
% --EXAM: A123BJC5D6E71
 
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 /code39 dup /uk.co.terryburton.bwipp findresource put
 
45
begin
 
46
/hibccode39 {
 
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
    /textfont /Courier def
 
55
    /textsize 10 def
 
56
    /textyoffset -7 def
 
57
    /textxoffset 0 def
 
58
    /validatecheck false def
 
59
 
 
60
    % Parse the input options
 
61
    options type /stringtype eq {
 
62
        1 dict begin
 
63
        options {
 
64
            token false eq {exit} if dup length string cvs (=) search
 
65
            true eq {cvlit exch pop exch def} {cvlit true def} ifelse
 
66
        } loop
 
67
        currentdict end /options exch def
 
68
    } if
 
69
    options {def} forall
 
70
 
 
71
    /textfont textfont cvlit def
 
72
    /textsize textsize cvr def
 
73
    /textyoffset textyoffset cvr def
 
74
    /textxoffset textxoffset cvr def
 
75
 
 
76
    % Create a string of the available characters
 
77
    /barchars (0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ-. $/+%) def
 
78
    /charvals 43 dict def
 
79
    0 1 42 {charvals exch dup barchars exch 1 getinterval exch put} for
 
80
 
 
81
    % Validate the input
 
82
    0 1 barcode length 1 sub {
 
83
        barcode exch 1 getinterval charvals exch known not {
 
84
            /bwipp.hibccode39badCharacter (HIBC Code 39 must contain only digits, capital letters, spaces and the symbols -.$/+%) //raiseerror exec
 
85
        } if
 
86
    } for
 
87
 
 
88
    /barlen barcode length validatecheck {1 sub} if def
 
89
 
 
90
    /checksum 41 def
 
91
    0 1 barlen 1 sub {
 
92
        barcode exch 1 getinterval charvals exch get
 
93
        checksum add /checksum exch def
 
94
    } for
 
95
    /checksum checksum 43 mod def
 
96
    validatecheck {
 
97
        barcode barlen get barchars checksum get ne {
 
98
            /bwipp.hibccode39badCheckDigit (Incorrect HIBC Code 39 check digit provided) //raiseerror exec
 
99
        } if
 
100
        /barcode barcode 0 barlen getinterval def
 
101
    } if
 
102
 
 
103
    /barcode barlen 2 add string dup 1 barcode putinterval def
 
104
    barcode 0 43 put
 
105
    barcode barlen 1 add barchars checksum get put
 
106
 
 
107
    /text barlen 4 add string def
 
108
    text 0 42 put
 
109
    text 1 barcode putinterval
 
110
    text barlen 2 add barcode barlen 1 add get dup 32 eq {pop 95} if put
 
111
    text barlen 3 add 42 put
 
112
 
 
113
    % Get the result of encoding with code39
 
114
    options (dontdraw) true put
 
115
    options (includecheck) false put
 
116
    options (validatecheck) false put
 
117
    /args barcode options //code39 exec def
 
118
 
 
119
    args (txt) [ [text textxoffset textyoffset textfont textsize] ] put
 
120
    args (textxalign) (center) put
 
121
    args (opt) options put
 
122
    args
 
123
 
 
124
    dontdraw not //renlinear if
 
125
 
 
126
    end
 
127
 
 
128
} bind def
 
129
/hibccode39 dup load /uk.co.terryburton.bwipp defineresource pop
 
130
end
 
131
/setpacking where {pop setpacking} if
 
132
% --END ENCODER hibccode39--