-
-
Notifications
You must be signed in to change notification settings - Fork 67
/
Copy pathean13.ps.src
246 lines (221 loc) · 8.05 KB
/
ean13.ps.src
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
% Barcode Writer in Pure PostScript
% https://bwipp.terryburton.co.uk
%
% Copyright (c) 2004-2024 Terry Burton
%
% $Id$
%
% Permission is hereby granted, free of charge, to any
% person obtaining a copy of this software and associated
% documentation files (the "Software"), to deal in the
% Software without restriction, including without
% limitation the rights to use, copy, modify, merge,
% publish, distribute, sublicense, and/or sell copies of
% the Software, and to permit persons to whom the Software
% is furnished to do so, subject to the following
% conditions:
%
% The above copyright notice and this permission notice
% shall be included in all copies or substantial portions
% of the Software.
%
% THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY
% KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO
% THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A
% PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
% THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
% DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF
% CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
% CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
% IN THE SOFTWARE.
% --BEGIN ENCODER ean13--
% --REQUIRES preamble loadctx unloadctx raiseerror processoptions renlinear ean5 ean2--
% --DESC: EAN-13
% --EXAM: 9520123456788
% --EXOP: includetext guardwhitespace
% --RNDR: renlinear
/setpacking where {pop currentpacking true setpacking} if
10 dict
dup /loadctx dup /uk.co.terryburton.bwipp findresource put
dup /unloadctx dup /uk.co.terryburton.bwipp findresource put
dup /raiseerror dup /uk.co.terryburton.bwipp findresource put
dup /processoptions dup /uk.co.terryburton.bwipp findresource put
dup /renlinear dup /uk.co.terryburton.bwipp findresource put
dup /ean2 dup /uk.co.terryburton.bwipp findresource put
dup /ean5 dup /uk.co.terryburton.bwipp findresource put
begin
/ean13 {
20 dict begin
/ctx null def
/dontdraw false def
/includetext false def
/textfont /Helvetica def
/textsize 12.0 def
/textxoffset -11.0 def
/textyoffset -4.0 def
/height 1.0 def
/addongap 12.0 def
/addontextfont (unset) def
/addontextsize null def % realtype sentinal
/addontextxoffset null def % realtype sentinal
/addontextyoffset null def % realtype sentinal
//processoptions exec /options exch def
/barcode exch def
/ean13 //loadctx exec
% Split off the addon
barcode ( ) search {
/barcode exch def
pop
/addon exch def
} {
pop
/addon () def
} ifelse
% Validate the input
barcode length 12 ne barcode length 13 ne and {
/bwipp.ean13badLength (EAN-13 must be 12 or 13 digits) //raiseerror exec
} if
barcode {
dup 48 lt exch 57 gt or {
/bwipp.ean13badCharacter (EAN-13 must contain only digits) //raiseerror exec
} if
} forall
addon length 0 ne addon length 2 ne and addon length 5 ne and {
/bwipp.ean13badAddOnLength (Add-on for EAN-13 must be 2 or 5 digits) //raiseerror exec
} if
% Add checksum digit
/pad 13 string def
/checksum 0 def
0 1 11 {
/i exch def
/barchar barcode i get 48 sub def
i 2 mod 0 eq {
/checksum barchar checksum add def
} {
/checksum barchar 3 mul checksum add def
} ifelse
} for
/checksum 10 checksum 10 mod sub 10 mod def
barcode length 13 eq {
barcode 12 get checksum 48 add ne {
/bwipp.ean13badCheckDigit (Incorrect EAN-13 check digit provided) //raiseerror exec
} if
} if
pad 0 barcode putinterval % Add barcode to the start of the pad
pad 12 checksum 48 add put % Put ascii for checksum at end of pad
/barcode pad def
{
% Create an array containing the character mappings
/encs
[ (3211) (2221) (2122) (1411) (1132)
(1231) (1114) (1312) (1213) (3112)
(111) (11111) (111)
] def
% Create a string of the available characters
/barchars (0123456789) def
% Digits to mirror on left side
/mirrormaps
[ (000000) (001011) (001101) (001110) (010011)
(011001) (011100) (010101) (010110) (011010)
] def
} ctxdef
/sbs 59 string def
/txt 13 array def
% Put the start character
sbs 0 encs 10 get putinterval
% First digit - determine mirrormap by this and show before guard bars
/mirrormap mirrormaps barcode 0 get 48 sub get def
txt 0 [barcode 0 1 getinterval textxoffset textyoffset textfont textsize] put
% Left side - performs mirroring
1 1 6 {
% Lookup the encoding for the each barcode character
/i exch def
barcode i 1 getinterval barchars exch search
pop % Discard true leaving pre
length /indx exch def % indx is the length of pre
pop pop % Discard seek and post
/enc encs indx get def % Get the indxth encoding
mirrormap i 1 sub get 49 eq { % Reverse enc if 1 in this position in mirrormap
/enclen enc length def
/revenc enclen string def
0 1 enclen 1 sub {
/j exch def
/char enc j get def
revenc enclen j sub 1 sub char put
} for
/enc revenc def
} if
sbs i 1 sub 4 mul 3 add enc putinterval % Put encoded digit into sbs
txt i [barcode i 1 getinterval i 1 sub 7 mul 15 add textxoffset add textyoffset textfont textsize] put
} for
% Put the middle character
sbs 7 1 sub 4 mul 3 add encs 11 get putinterval
% Right side
7 1 12 {
% Lookup the encoding for the each barcode character
/i exch def
barcode i 1 getinterval barchars exch search
pop % Discard true leaving pre
length /indx exch def % indx is the length of pre
pop pop % Discard seek and post
/enc encs indx get def % Get the indxth encoding
sbs i 1 sub 4 mul 8 add enc putinterval % Put encoded digit into sbs
txt i [barcode i 1 getinterval i 1 sub 7 mul 19 add textxoffset add textyoffset textfont textsize] put
} for
% Put the end character
sbs 56 encs 12 get putinterval
/sbs [sbs {48 sub} forall] def
includetext {
/bhs [height height 12{height .075 sub}repeat height height 12{height .075 sub}repeat height height] def
/bbs [0 0 12{.075}repeat 0 0 12{.075}repeat 0 0] def
} {
/bhs [30{height}repeat] def
/bbs [30{0}repeat] def
/txt [] def
} ifelse
/guardrightypos 0.0 def
% Append the addon
addon () ne {
/addopts <<
/dontdraw true
/includetext true
/height height includetext { 0.15 sub } if
/textxoffset addontextxoffset null ne {addontextxoffset} {95 addongap add} ifelse
addontextyoffset null ne {/textyoffset addontextyoffset} if
/textsize addontextsize null ne {addontextsize} {textsize} ifelse
/textfont addontextfont (unset) ne {addontextfont} {textfont} ifelse
>> def
addon length 2 eq {addon addopts //ean2 exec} if
addon length 5 eq {addon addopts //ean5 exec} if
/addcode exch def
/sbs [sbs aload pop addongap addcode (sbs) get aload pop] def
/bhs [bhs aload pop addcode (bhs) get aload pop] def
/bbs [bbs aload pop addcode (bbs) get aload pop] def
/txt [txt aload pop addcode (txt) get aload pop] def
/guardrightypos height 72 mul 6 sub def
} if
% Return the arguments
<<
/ren /renlinear
/sbs sbs
/bhs bhs
/bbs bbs
/txt txt
/opt options
/guardrightpos addon () eq {7.0} {5.0} ifelse
/guardrightypos guardrightypos
/borderleft 11.0
/borderright addon () eq {7.0} {5.0} ifelse
/bordertop 0.0
/borderbottom 5.0
>>
dontdraw not //renlinear if
//unloadctx exec
end
}
[/barcode] {null def} forall
bind def
/ean13 dup load /uk.co.terryburton.bwipp defineresource pop
end
/setpacking where {pop setpacking} if
% --END ENCODER ean13--