%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 ADE \& \CONTEXT\ Development Team}]
%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 (PDF417) barcodes so
%D therefore we now have this module. There 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 feed names.
%D
%D % e:\tex-context\tex\texmf-win64\bin\lib\luametatex\zint\libzint.dll

% \enabletrackers[*res*]

\registerctxluafile{libs-imp-zint}{autosuffix}

\unprotect

\definefont[usedzintfont][dejavusansmono at 10bp]

\permanent\protected\def\barcode[#S#1]% [alternative=,text=]
  {\bgroup
   \usedzintfont
   \getdummyparameters
     [\c!alternative=,\c!text=,\c!option=,#1]%
   \scale
     [#1]%
     {\clf_zint
         code   {\dummyparameter\c!alternative}
         text   {\dummyparameter\c!text}
         option {\dummyparameter\c!option}
      \relax}%
   \egroup}

\protect

\continueifinputfile{libs-imp-zint.mkxl}

\starttext

\dontcomplain

% \dorecurse{1}{
%     \startTEXpage
%         \barcode[alternative=PDF417,text={Hans Hagen}]%
%         \blank
%         \barcode[alternative=PDF417,text={Ton Otten}]%
%         \blank
%         \barcode[alternative=ISBN,text=9789490688011]%
%         \blank
%         \barcode[alternative=isbn,text=9789490688011,width=3cm]%
%         \blank
%         \dontleavehmode
%         \barcode[alternative=qr code,text={This is ConTeXt MKIV : #1}]
%         \barcode[alternative=qr code,text={This is ConTeXt LMTX}]
%         \barcode[alternative=qr code,text={\cldloadfile{tufte}},width=3cm]
%         \blank
%         \barcode[alternative=datamatrix,text=whatever,width=3cm,option=square]
%         \scale[width=3cm,height=3cm]{\barcode[alternative=datamatrix,text=whatever,width=3cm,option=square]}
%         \barcode[alternative=datamatrix,text={helloworld}]
%         \barcode[alternative=datamatrix,text={hello world}]
%     \stopTEXpage
% }

    \startTEXpage
        \startluacode
            for i=1,100 do
                context.dontleavehmode()
                context.barcode {
                    alternative = "datamatrix",
                    text        = string.rep("!",i),
                }
                context.space()
                context.allowbreak()
            end
        \stopluacode
    \stopTEXpage

    \startTEXpage
        \startluacode
            for i=1,100 do
                context.dontleavehmode()
                context.barcode {
                    alternative = "datamatrix",
                    text        = string.rep("!",i),
                    option      = "square",
                }
                context.space()
                context.allowbreak()
            end
        \stopluacode
    \stopTEXpage

        \startluacode
            for i=1,25 do
                context.startTEXpage()
                context.dontleavehmode()
                context(i)
                context.space()
                context.barcode {
                    alternative = "datamatrix",
                    text        = string.rep("!",i),
                }
                context.space()
                context.barcode {
                    alternative = "datamatrix",
                    text        = string.rep("!",i),
                    option      = "square",
                }
                context.stopTEXpage()
            end
        \stopluacode
\stoptext

