Skip to content

Commit 910ecd3

Browse files
committed
ISBN variant: Comments
1 parent 30e3561 commit 910ecd3

3 files changed

Lines changed: 66 additions & 3 deletions

File tree

src/isbn.ps.src

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
% Barcode Writer in Pure PostScript
22
% https://bwipp.terryburton.co.uk
33
%
4-
% Copyright (c) 2004-2024 Terry Burton
4+
% Copyright (c) 2004-2025 Terry Burton
55
%
66
% $Id$
77
%
@@ -49,6 +49,7 @@ begin
4949
20 dict begin
5050

5151
/ctx null def
52+
5253
/dontdraw false def
5354
/includetext false def % Enable/disable ISBN text
5455
/isbntextfont /Courier def
@@ -62,7 +63,9 @@ begin
6263
//processoptions exec /options exch def
6364
/barcode exch def
6465

66+
%
6567
% Split off the addon
68+
%
6669
barcode ( ) search {
6770
/barcode exch def
6871
pop
@@ -72,7 +75,9 @@ begin
7275
/addon () def
7376
} ifelse
7477

78+
%
7579
% Validate the input
80+
%
7681
barcode length 15 ne barcode length 17 ne and
7782
barcode length 11 ne barcode length 13 ne and and {
7883
/bwipp.isbnBadLength (ISBN-13 must be 15 or 17 characters including dashes. ISBN-10 must be 11 or 13 characters including dashes) //raiseerror exec
@@ -150,7 +155,9 @@ begin
150155

151156
/isbntxt barcode def
152157

158+
%
153159
% Read the digits from isbntxt and validate checksum for ISBN-10
160+
%
154161
isbntxt length 13 le {
155162
/isbn 10 string def
156163
/checksum 0 def
@@ -178,15 +185,19 @@ begin
178185

179186
legacy not isbntxt length 15 ge or {
180187

188+
%
181189
% Convert ISBN-10 to ISBN-13
190+
%
182191
isbntxt length 13 le {
183192
/pad 15 string def
184193
pad 0 (978-) putinterval
185194
pad 4 isbntxt 0 11 getinterval putinterval
186195
/isbntxt pad def
187196
} if
188197

198+
%
189199
% Read the digits from isbntxt and validate checksum for ISBN-13
200+
%
190201
/isbn 13 string def
191202
/checksum 0 def
192203
/i 0 def /n 0 def
@@ -212,15 +223,19 @@ begin
212223

213224
} if
214225

226+
%
215227
% Add the ISBN header to the isbntxt
228+
%
216229
/pad isbn length 12 eq {22} {18} ifelse string def
217230
pad 0 (ISBN ) putinterval
218231
pad 5 isbntxt putinterval
219232
pad pad length 2 sub 45 put
220233
pad pad length 1 sub checksum put
221234
/isbntxt pad def
222235

236+
%
223237
% Convert ISBN digits to EAN-13
238+
%
224239
/barcode 12 string def
225240
isbn length 9 eq {
226241
barcode 0 (978) putinterval
@@ -229,7 +244,9 @@ begin
229244
barcode 0 isbn putinterval
230245
} ifelse
231246

247+
%
232248
% Append the addon
249+
%
233250
addon () ne {
234251
12 addon length add 1 add string
235252
dup 0 barcode putinterval
@@ -238,12 +255,16 @@ begin
238255
/barcode exch def
239256
} if
240257

258+
%
241259
% Get the result of encoding with ean13
260+
%
242261
options (dontdraw) true put
243262
options (addongap) addongap put
244263
/args barcode options //ean13 exec def
245264

265+
%
246266
% Add the ISBN text
267+
%
247268
includetext {
248269
isbntextxoffset null eq {
249270
/isbntextxoffset isbn length 9 eq {-1.0} {-12.0} ifelse def

src/ismn.ps.src

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
% Barcode Writer in Pure PostScript
22
% https://bwipp.terryburton.co.uk
33
%
4-
% Copyright (c) 2004-2024 Terry Burton
4+
% Copyright (c) 2004-2025 Terry Burton
55
%
66
% $Id$
77
%
@@ -49,6 +49,7 @@ begin
4949
20 dict begin
5050

5151
/ctx null def
52+
5253
/dontdraw false def
5354
/includetext false def
5455
/ismntextfont /Courier def
@@ -62,7 +63,9 @@ begin
6263
//processoptions exec /options exch def
6364
/barcode exch def
6465

66+
%
6567
% Split off the addon
68+
%
6669
barcode ( ) search {
6770
/barcode exch def
6871
pop
@@ -72,7 +75,9 @@ begin
7275
/addon () def
7376
} ifelse
7477

78+
%
7579
% Validate the input
80+
%
7681
barcode length 15 ne barcode length 17 ne and
7782
barcode length 11 ne barcode length 13 ne and and {
7883
/bwipp.ismnBadLength (ISMN-13 must be 15 or 17 characters including dashes. ISMN-10 must be 11 or 13 characters including dashes) //raiseerror exec
@@ -153,7 +158,9 @@ begin
153158

154159
/ismntxt barcode def
155160

161+
%
156162
% Convert old ISMN to ISMN-13
163+
%
157164
/legacytxt () def
158165
ismntxt length 13 le {
159166
/legacytxt ismntxt def
@@ -163,7 +170,9 @@ begin
163170
/ismntxt pad def
164171
} if
165172

173+
%
166174
% Read the digits from ismntxt and calculate checksums
175+
%
167176
/ismn 13 string def
168177
/checksum 0 def
169178
/i 0 def /n 0 def
@@ -185,14 +194,18 @@ begin
185194
} loop
186195
/checksum 10 checksum 10 mod sub 10 mod 48 add def
187196

197+
%
188198
% Validate the checksum
199+
%
189200
barcode length 13 eq barcode length 17 eq or {
190201
barcode dup length 1 sub get checksum ne {
191202
/bwipp.ismnBadCheckDigit (Incorrect ISMN check digit provided) //raiseerror exec
192203
} if
193204
} if
194205

206+
%
195207
% Add the ISMN header and checksum to the ismntxt
208+
%
196209
legacy legacytxt () ne and {
197210
/ismntxt legacytxt def
198211
/pad 18 string def
@@ -205,10 +218,14 @@ begin
205218
pad pad length 1 sub checksum put
206219
/ismntxt pad def
207220

221+
%
208222
% Convert ISMN digits to EAN-13
223+
%
209224
/barcode ismn 0 12 getinterval def
210225

226+
%
211227
% Append the addon
228+
%
212229
addon () ne {
213230
12 addon length add 1 add string
214231
dup 0 barcode putinterval
@@ -217,12 +234,16 @@ begin
217234
/barcode exch def
218235
} if
219236

237+
%
220238
% Get the result of encoding with ean13
239+
%
221240
options (dontdraw) true put
222241
options (addongap) addongap put
223242
/args barcode options //ean13 exec def
224243

244+
%
225245
% Add the ISMN text
246+
%
226247
includetext {
227248
ismntextxoffset null eq {
228249
/ismntextxoffset ismntxt length 18 eq {-1.0} {-12.0} ifelse def

src/issn.ps.src

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
% Barcode Writer in Pure PostScript
22
% https://bwipp.terryburton.co.uk
33
%
4-
% Copyright (c) 2004-2024 Terry Burton
4+
% Copyright (c) 2004-2025 Terry Burton
55
%
66
% $Id$
77
%
@@ -49,6 +49,7 @@ begin
4949
20 dict begin
5050

5151
/ctx null def
52+
5253
/dontdraw false def
5354
/includetext false def
5455
/issntextfont /Courier def
@@ -61,7 +62,9 @@ begin
6162
//processoptions exec /options exch def
6263
/issntxt exch def
6364

65+
%
6466
% Split off the ISSN
67+
%
6568
issntxt ( ) search {
6669
/issntxt exch def
6770
pop
@@ -71,7 +74,9 @@ begin
7174
/seqvar (00) def
7275
} ifelse
7376

77+
%
7478
% Split off the sequence variant and addon
79+
%
7580
seqvar ( ) search {
7681
/seqvar exch def
7782
pop
@@ -81,7 +86,9 @@ begin
8186
/addon () def
8287
} ifelse
8388

89+
%
8490
% Validate the input
91+
%
8592
issntxt length 8 ne issntxt length 9 ne and {
8693
/bwipp.issnBadLength (ISSN must be 8 or 9 characters including dash, in the format XXXX-XXXX) //raiseerror exec
8794
} if
@@ -115,7 +122,9 @@ begin
115122
/bwipp.issnBadAddOnLength (Add-on for ISSN must be 2 or 5 digits) //raiseerror exec
116123
} if
117124

125+
%
118126
% Read the digits from issntxt and calculate checksums
127+
%
119128
/issn 8 string def
120129
/checksum 0 def
121130
/i 0 def /n 0 def
@@ -139,23 +148,31 @@ begin
139148
} if
140149
} if
141150

151+
%
142152
% Add the ISSN header and checksum to the issntxt
153+
%
143154
/pad 14 string def
144155
pad 0 (ISSN ) putinterval
145156
pad 5 issntxt putinterval % Add issntxt to the pad
146157
pad 13 checksum put
147158
/issntxt pad def
148159

160+
%
149161
% Convert ISSN digits to EAN-13
162+
%
150163
/barcode issn 0 7 getinterval def
151164

165+
%
152166
% Append the sequence variant
167+
%
153168
/barcode 12 string def
154169
barcode 0 (977) putinterval
155170
barcode 3 issn putinterval
156171
barcode 10 seqvar putinterval
157172

173+
%
158174
% Append the addon
175+
%
159176
addon () ne {
160177
12 addon length add 1 add string
161178
dup 0 barcode putinterval
@@ -164,12 +181,16 @@ begin
164181
/barcode exch def
165182
} if
166183

184+
%
167185
% Get the result of encoding with ean13
186+
%
168187
options (dontdraw) true put
169188
options (addongap) addongap put
170189
/args barcode options //ean13 exec def
171190

191+
%
172192
% Add the ISSN text
193+
%
173194
includetext {
174195
issntextxoffset null eq {/issntextxoffset 10.0 def} if
175196
issntextyoffset null eq {/issntextyoffset height 72 mul 3 add def} if

0 commit comments

Comments
 (0)