m-barcodes.mkiv /size: 3501 b    last modification: 2020-07-01 14:35
1
%D \module
2
%D [ file=m-barcodes,
3
%D version=2010.03.14,
4
%D title=\CONTEXT\ Extra Modules,
5
%D subtitle=Barcodes,
6
%D author=Hans Hagen,
7
%D date=\currentdate,
8
%D copyright={PRAGMA ADE \& \CONTEXT\ Development Team}]
9
%C
10
%C This module is part of the \CONTEXT\ macro||package and is
11
%C therefore copyrighted by \PRAGMA. See mreadme.pdf for
12
%C details.
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
% \startTEXpage
26
% \startPSTRICKS
27
% \pspicture(-4mm,-1mm)(38mm,26mm)
28
% \psbarcode{9781860742712}{includetext guardwhitespace}{ean13}%
29
% \endpspicture
30
% \stopPSTRICKS
31
% \stopTEXpage
32 33
% 978-94-90688-01-1
34
%
35
% 978 = ean isbn identifier (979 also)
36
% 94 = country code
37
% 90688 = publisher code
38
% 01 = title 1
39
% 1 = checksum
40 41
\usemodule
[
pstricks
]
42 43
\usePSTRICKSmodule
[
pst
-
barcode
]
44 45
\definefont
[
barcodefont
][
file
:
ocrb
1
0
]
46
% \definefont[barcodefont][file:texgyreheros-regular]
47 48
\startluacode
49
moduledata
.
barcodes
=
{
}
50 51
local
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
65
end
66 67
function
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
)
80
end
81 82
function
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
)
89
end
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