summaryrefslogtreecommitdiff
path: root/tex/context/base/m-zint.mkiv
diff options
context:
space:
mode:
authorMarius <mariausol@gmail.com>2011-01-31 00:20:51 +0200
committerMarius <mariausol@gmail.com>2011-01-31 00:20:51 +0200
commit91675d8e11906bc15351278f8865d41de6bcc06d (patch)
treeda027e5dd2b69bb8f0b19c774c222c098bbfc4b7 /tex/context/base/m-zint.mkiv
parent3019c4ccfb0d984b45670a86d2400a6aacfbaa68 (diff)
downloadcontext-91675d8e11906bc15351278f8865d41de6bcc06d.tar.gz
beta 2011.01.23 20:36
Diffstat (limited to 'tex/context/base/m-zint.mkiv')
-rw-r--r--tex/context/base/m-zint.mkiv78
1 files changed, 78 insertions, 0 deletions
diff --git a/tex/context/base/m-zint.mkiv b/tex/context/base/m-zint.mkiv
new file mode 100644
index 000000000..815d83fab
--- /dev/null
+++ b/tex/context/base/m-zint.mkiv
@@ -0,0 +1,78 @@
+%D \module
+%D [ file=m-zint,
+%D version=2010.12.07,
+%D title=\CONTEXT\ Extra Modules,
+%D subtitle=Zint Barcode Generator,
+%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.
+
+%D Using \type {zint} seems to be the easiest way to generate
+%D (PDF417) barcodes so therefore we now have this module. There
+%D are proper (also windows) binaries at:
+%D
+%D \starttyping
+%D http://www.zint.org.uk
+%D \stoptyping
+%D
+%D There is a bit more code than needed as we want to be able to
+%D feed names.
+
+\startluacode
+
+moduledata.zint = { }
+
+local format, lower, gsub = string.format, string.lower, string.gsub
+local patterns = lpeg.patterns
+
+local zint = "zint" -- '"c:/program files/zint/zint.exe"'
+
+local whitespace = patterns.whitespace
+local spaces = whitespace^0
+local key = (spaces / "") * patterns.digit^0 * (patterns.colon * spaces / "")
+local value = (whitespace / "" + (1 - key))^1
+local pattern = lpeg.Cf(lpeg.Ct("") * (lpeg.Cg((lpeg.Cs(key) / tonumber) * (lpeg.Cs(value) / lower)) + patterns.anything)^0,rawset)
+
+local reverse
+
+local function cleancode(code)
+ return lower(gsub(code," ",""))
+end
+
+local function numberofcode(code)
+ if not reverse then
+ local types = os.resultof(format("%s --types",zint)) or ""
+ local formats = lpeg.match(pattern,types)
+ reverse = table.swapped(formats) or { }
+ end
+ code = cleancode(code)
+ return reverse[code] or code
+end
+
+function moduledata.zint.generate(code,data,suffix,options)
+ local code = cleancode(code)
+ local name = format("zint-%s-%s.%s",code,md5.hex(data),suffix or "eps")
+ if not lfs.isfile(name) then
+ local code = numberofcode(code)
+ os.spawn(format('%s --barcode=%s --output="%s" %s --data="%s"',zint,code,name,options or "",data))
+ end
+ return name
+end
+
+\stopluacode
+
+\doifnotmode{demo}{\endinput}
+
+\starttext
+
+ \externalfigure[\cldcontext{moduledata.zint.generate("PDF417","Ton Otten")}]
+ \blank
+ \externalfigure[\cldcontext{moduledata.zint.generate("ISBN","9789490688011")}]
+
+\stoptext
+
+