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