diff options
author | Hans Hagen <pragma@wxs.nl> | 2010-03-18 14:42:00 +0100 |
---|---|---|
committer | Hans Hagen <pragma@wxs.nl> | 2010-03-18 14:42:00 +0100 |
commit | 66a814af45f6ebe7ff0210238b2b9eba7dd3a499 (patch) | |
tree | c227b9351820db8c6084b82777c60b4367c80dd8 /tex/context/base/m-barcodes.mkiv | |
parent | f8583123d8e264910387d015f4d6576551fe0ee4 (diff) | |
download | context-66a814af45f6ebe7ff0210238b2b9eba7dd3a499.tar.gz |
beta 2010.03.18 14:42
Diffstat (limited to 'tex/context/base/m-barcodes.mkiv')
-rw-r--r-- | tex/context/base/m-barcodes.mkiv | 96 |
1 files changed, 96 insertions, 0 deletions
diff --git a/tex/context/base/m-barcodes.mkiv b/tex/context/base/m-barcodes.mkiv new file mode 100644 index 000000000..1c352dd54 --- /dev/null +++ b/tex/context/base/m-barcodes.mkiv @@ -0,0 +1,96 @@ +%D \module +%D [ file=m-pstricks, +%D version=2010.03.14, +%D title=\CONTEXT\ Extra Modules, +%D subtitle=Barcodes, +%D author=Hans Hagen, +%D date=\currentdate, +%D copyright=PRAGMA] +%C +%C This module is part of the \CONTEXT\ macro||package and is +%C therefore copyrighted by \PRAGMA. See mreadme.pdf for +%C details. + +% \startTEXpage +% \startPSTRICKS +% \pspicture(-4mm,-1mm)(38mm,26mm) +% \psbarcode{9781860742712}{includetext guardwhitespace}{ean13}% +% \endpspicture +% \stopPSTRICKS +% \stopTEXpage + +% 978-94-90688-01-1 +% +% 978 = ean isbn identifier (979 also) +% 94 = country code +% 90688 = publisher code +% 01 = title 1 +% 1 = checksum + +\usemodule[pstricks] + +\usePSTRICKSmodule[pst-barcode] + +\startluacode +plugins.barcodes = { } + +function plugins.barcodes.strip(original) + local code = string.gsub(original,"%-","") + local t = { string.byte(code,1,#code) } + if #t >= 12 then + local s = 0 + for i=1,11,2 do + s = s + (t[i]-48) + end + for i=2,12,2 do + s = s + 3 * (t[i]-48) + end + local m = s % 10 + local c = (m > 0 and (10 - m)) or 0 + if #t == 13 then + local e = ((c == t[13] - 48) and "correct") or "wrong" + logs.report("isbn code","code=%s, sum=%s, checksum=%s, modulo=%s, status=%s",original,s,m,c,e) + else + logs.report("isbn code","code=%s, sum=%s, checksum=%s, modulo=%s",original,s,m,c) + code= code .. c + end + end + tex.sprint(code) +end +\stopluacode + +\startsetups barcode:isbn + \scale + [width=5cm] + { + \normalexpanded { \noexpand \setPSTRICKS { + \noexpand \pspicture(-4mm,-1mm)(38mm,26mm) + \noexpand \psbarcode { + \ctxlua{plugins.barcodes.strip("\getvariable{barcode}{code}")} + } { + includetext guardwhitespace + } { + ean13 + } + \noexpand \endpspicture + } + \noexpand \processPSTRICKS } + } +\stopsetups + +\def\barcode[#1]% + {\bgroup + \setvariables[barcode][type=isbn,#1]% + \directsetup{barcode:\getvariable{barcode}{type}}% + \egroup} + +% \usemodule[barcodes] +% +% \starttext +% \startTEXpage +% \barcode[type=isbn,code=978-94-90688-01-1] +% \stopTEXpage +% \stoptext + +\endinput + |