-
-
Notifications
You must be signed in to change notification settings - Fork 67
/
Copy pathismn.ps.src
255 lines (236 loc) · 8.51 KB
/
ismn.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
247
248
249
250
251
252
253
254
255
% 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 ismn--
% --REQUIRES preamble loadctx unloadctx raiseerror processoptions renlinear ean5 ean2 ean13--
% --DESC: ISMN
% --EXAM: 979-0-2605-3211-3
% --EXOP: includetext guardwhitespace
% --RNDR: renlinear
/setpacking where {pop currentpacking true setpacking} if
10 dict
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 /ean13 dup /uk.co.terryburton.bwipp findresource put
begin
/ismn {
20 dict begin
/ctx null def
/dontdraw false def
/includetext false def
/ismntextfont /Courier def
/ismntextsize 9.0 def
/ismntextxoffset null def % sentinal realtype
/ismntextyoffset null def % sentinal realtype
/height 1.0 def
/addongap 12.0 def
/legacy false def
//processoptions exec /options exch def
/barcode exch def
% Split off the addon
barcode ( ) search {
/barcode exch def
pop
/addon exch def
} {
pop
/addon () def
} ifelse
% Validate the input
barcode length 15 ne barcode length 17 ne and
barcode length 11 ne barcode length 13 ne and and {
/bwipp.ismnBadLength (ISMN-13 must be 15 or 17 characters including dashes. ISMN-10 must be 11 or 13 characters including dashes) //raiseerror exec
} if
addon length 0 ne addon length 2 ne and addon length 5 ne and {
/bwipp.ismnBadAddOnLength (Add-on for ISMN must be 2 or 5 digits) //raiseerror exec
} if
barcode length 15 ge { % ISMN-13
barcode 0 4 getinterval (979-) ne {
/bwipp.ismn13badPrefix (ISMN-13 prefix must be 979-) //raiseerror exec
} if
/wasdash false def /numdash 0 def /numdigit 0 def
barcode 5 9 getinterval {
dup
45 eq {
wasdash {
/bwipp.ismn13adjacentDashes (ISMN-13 does not permit adjacent dashes) //raiseerror exec
} if
/wasdash true def
/numdash numdash 1 add def
} if
dup 48 ge exch 57 le and {
/wasdash false def
/numdigit numdigit 1 add def
} if
} forall
numdash 2 ne numdigit 7 ne or {
/bwipp.ismn13numDashesDigits (Incorrect number of dashes and digits for ISMN-13) //raiseerror exec
} if
barcode 14 get dup 48 lt exch 57 gt or {
/bwipp.ismn13character15 (ISMN-13 character 15 must be a digit) //raiseerror exec
} if
barcode length 17 eq {
barcode 15 1 getinterval (-) ne {
/bwipp.ismn13character16 (ISMN-13 penultimate character must be a dash) //raiseerror exec
} if
barcode 16 get dup 48 lt exch 57 gt or {
/bwipp.ismn13character17 (ISMN-13 final character must be a digit) //raiseerror exec
} if
} if
} { % ISMN-10
barcode 0 2 getinterval (M-) ne {
/bwipp.ismn10badPrefix (ISMN-10 prefix must be M-) //raiseerror exec
} if
barcode 2 get dup 48 lt exch 57 gt or {
/bwipp.ismn10character3 (ISMN-10 character 3 must be a digit) //raiseerror exec
} if
/wasdash false def /numdash 0 def /numdigit 0 def
barcode 3 7 getinterval {
dup
45 eq {
wasdash {
/bwipp.ismn10adjacentDashes (ISMN-10 does not permit adjacent dashes) //raiseerror exec
} if
/wasdash true def
/numdash numdash 1 add def
} if
dup 48 ge exch 57 le and {
/wasdash false def
/numdigit numdigit 1 add def
} if
} forall
numdash 1 ne numdigit 6 ne or {
/bwipp.ismn10numDashesDigits (Incorrect number of dashes and digits for ISMN-10) //raiseerror exec
} if
barcode 10 get dup 48 lt exch 57 gt or {
/bwipp.ismn10character11 (ISMN-10 character 11 must be a digit) //raiseerror exec
} if
barcode length 13 eq {
barcode 11 1 getinterval (-) ne {
/bwipp.ismn10character12 (ISMN-10 penultimate character must be a dash) //raiseerror exec
} if
barcode 12 get dup dup 48 lt exch 57 gt or exch 88 ne and {
/bwipp.ismn10character13 (ISMN-10 final character must be a digit or X) //raiseerror exec
} if
} if
} ifelse
/ismntxt barcode def
% Convert old ISMN to ISMN-13
/legacytxt () def
ismntxt length 13 le {
/legacytxt ismntxt def
/pad ismntxt length 4 add string def
pad 0 (979-0-) putinterval
pad 6 ismntxt 2 ismntxt length 2 sub getinterval putinterval
/ismntxt pad def
} if
% Read the digits from ismntxt and calculate checksums
/ismn 13 string def
/checksum 0 def
/i 0 def /n 0 def
{ % loop
/ismnchar ismntxt i get 48 sub def
ismnchar -3 ne { % Ignore dashes
ismn n ismnchar 48 add put
n 12 lt {
n 2 mod 0 eq {
/checksum ismnchar checksum add def
} {
/checksum ismnchar 3 mul checksum add def
} ifelse
} if
/n n 1 add def
} if
/i i 1 add def
i ismntxt length eq {exit} if
} loop
/checksum 10 checksum 10 mod sub 10 mod 48 add def
% Validate the checksum
barcode length 13 eq barcode length 17 eq or {
barcode dup length 1 sub get checksum ne {
/bwipp.ismnBadCheckDigit (Incorrect ISMN check digit provided) //raiseerror exec
} if
} if
% Add the ISMN header and checksum to the ismntxt
legacy legacytxt () ne and {
/ismntxt legacytxt def
/pad 18 string def
} {
/pad 22 string def
} ifelse
pad 0 (ISMN ) putinterval
pad 5 ismntxt putinterval
pad pad length 2 sub 45 put
pad pad length 1 sub checksum put
/ismntxt pad def
% Convert ISMN digits to EAN-13
/barcode ismn 0 12 getinterval def
% Append the addon
addon () ne {
12 addon length add 1 add string
dup 0 barcode putinterval
dup 12 ( ) putinterval
dup 13 addon putinterval
/barcode exch def
} if
% Get the result of encoding with ean13
options (dontdraw) true put
options (addongap) addongap put
/args barcode options //ean13 exec def
% Add the ISMN text
includetext {
ismntextxoffset null eq {
/ismntextxoffset ismntxt length 18 eq {-1.0} {-12.0} ifelse def
} if
ismntextyoffset null eq {
/ismntextyoffset height 72 mul 3 add def
} if
args (txt) known {
/txt args (txt) get def
/newtxt txt length 1 add array def
newtxt 0 txt putinterval
newtxt newtxt length 1 sub [ismntxt ismntextxoffset ismntextyoffset ismntextfont ismntextsize] put
args (txt) newtxt put
} {
args (txt) [ [ismntxt ismntextxoffset ismntextyoffset ismntextfont ismntextsize] ] put
} ifelse
} if
args (opt) options put
args
dontdraw not //renlinear if
end
}
[/barcode] {null def} forall
bind def
/ismn dup load /uk.co.terryburton.bwipp defineresource pop
end
/setpacking where {pop setpacking} if
% --END ENCODER ismn--