1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16\writestatus{barcodes}{the zint module is a better choice}
17
18\usemodule[zint]
19
20\let\normalbarcode\barcode
21
22\unexpanded\def\barcode[#1]
23 {\normalbarcode[\c!text=\dummyparameter\c!code,\c!alternative=\dummyparameter\c!type,#1]}
24
25
26
27
28
29
30\iffalse
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48\usemodule[pstricks]
49
50\usePSTRICKSmodule[pstbarcode]
51
52\definefont[barcodefont][file:ocrb10]
53
54
55\startluacode
56moduledata.barcodes = { }
57
58local function split(code)
59 local t = { string.byte(code,1,#code) }
60 if #t >= 12 then
61 local s = 0
62 for i=1,11,2 do
63 s = s + (t[i]-48)
64 end
65 for i=2,12,2 do
66 s = s + 3 * (t[i]-48)
67 end
68 local m = s % 10
69 local c = (m > 0 and (10 - m)) or 0
70 return t, s, m, c
71 end
72end
73
74function moduledata.barcodes.isbn_1(original)
75 local code = string.gsub(original,"%-","")
76 local t, s, m, c = split(code)
77 if t then
78 if #t == 13 then
79 local e = ((c == t[13] - 48) and "correct") or "wrong"
80 logs.report("isbn code","code=%s, sum=%s, checksum=%s, modulo=%s, status=%s",original,s,m,c,e)
81 else
82 logs.report("isbn code","code=%s, sum=%s, checksum=%s, modulo=%s",original,s,m,c)
83 code= code .. c
84 end
85 end
86 context(code)
87end
88
89function moduledata.barcodes.isbn_2(original)
90 local code = string.gsub(original,"%-","")
91 local t, s, m, c = split(code)
92 if t and #t == 12 then
93 original = original .. "-" .. c
94 end
95 context(original)
96end
97\stopluacode
98
99\startsetups barcode:isbn
100 \scale
101 [width=5cm]
102 {
103 \vbox {
104 \hbox {
105 \hskip3.7mm
106 \scale[width=34mm]{\barcodefont ISBN \ctxlua{moduledata.barcodes.isbn_2("\getvariable{barcode}{code}")}}
107 }
108 \par
109 \normalexpanded { \noexpand \setPSTRICKS {
110 \noexpand \pspicture(4mm,1mm)(38mm,26mm)
111 \noexpand \psbarcode {
112 \ctxlua{moduledata.barcodes.isbn_1("\getvariable{barcode}{code}")}
113 } {
114 includetext guardwhitespace
115 } {
116 ean13
117 }
118 \noexpand \endpspicture
119 }
120 \noexpand \processPSTRICKS }
121 }
122 }
123\stopsetups
124
125\unexpanded\def\barcode[#1]
126 {\bgroup
127 \setvariables[barcode][type=isbn,#1]
128 \directsetup{barcode:\getvariable{barcode}{type}}
129 \egroup}
130
131\fi
132
133\continueifinputfile{mbarcodes.mkiv}
134
135\starttext
136 \startTEXpage
137 \barcode[type=isbn,code=9789490688011]
138 \stopTEXpage
139\stoptext
140
141 |