From 7a3496f52bec1e6180c3cb18503b4038b2d89735 Mon Sep 17 00:00:00 2001 From: Karl Berry Date: Mon, 14 Mar 2011 23:44:19 +0000 Subject: pst-barcode 0.08 (12mar11) git-svn-id: svn://tug.org/texlive/trunk@21716 c570f23f-e606-0410-a88d-b1316a301751 --- Master/texmf-dist/doc/generic/pst-barcode/Changes | 127 + .../doc/generic/pst-barcode/pst-barcode-doc.bib | 6 +- .../doc/generic/pst-barcode/pst-barcode-doc.pdf | Bin 228146 -> 229501 bytes .../doc/generic/pst-barcode/pst-barcode-doc.tex | 265 +- .../texmf-dist/dvips/pst-barcode/pst-barcode.pro | 19865 ++++++++++++++----- .../tex/generic/pst-barcode/pst-barcode.tex | 7 +- .../tex/latex/pst-barcode/pst-barcode.sty | 2 +- 7 files changed, 14694 insertions(+), 5578 deletions(-) (limited to 'Master') diff --git a/Master/texmf-dist/doc/generic/pst-barcode/Changes b/Master/texmf-dist/doc/generic/pst-barcode/Changes index c7d8f012ea8..d49c293519b 100644 --- a/Master/texmf-dist/doc/generic/pst-barcode/Changes +++ b/Master/texmf-dist/doc/generic/pst-barcode/Changes @@ -1,4 +1,5 @@ ----- pst-barcode.tex +0.08 2011-03-10 - take care of the function interface of the pro file 0.07 2009-08-12 - take care of the function interface of the pro file 0.04 2006-07-23 - adding support for the ISBN-13 code - printing the code from the current point and @@ -13,6 +14,132 @@ ----- pst-barcode.pro +2011-03-12 - The error correction code for Maxicode symbols was improved. + - Codablock F was fixed for short data inputs. + - Support for the Codablock F symbology was added. + - Support for the HIBC Codablock F symbology was added. + - The optimised encoding of Code 16K symbols was simplified. + - The optimised encoding of Code 128 symbols was simplified and + improved. + - The optimised encoding of Code 128 symbols was improved. + - Support for the extended datalength option was added to the Code + 16K symbology. + - Support for the Code 16K symbology was added. + - The optimal start character selection for Code 128 symbols was + improved. + - Support for the Code 49 symbology was added. + - Support for the Code One symbology was added. + - The GS1 DataBar Expanded Composite and GS1 DataBar Expanded + Stacked Composite symbologies were amended so that their separator + patterns are correctly generated. + - The GS1 DataBar Omnidirectional Composite, GS1 DataBar Stacked + Composite, GS1 DataBar Stacked Omnidirectional Composite, GS1 + DataBar Truncated symbologies were amended so that their separator + patterns are correctly generated. + - GS1-128 Composite was fixed so that the 2D component is correctly + aligned. + - Preliminary support for the GS1 DataBar Omnidirectional Composite, + GS1 DataBar Stacked Composite, GS1 DataBar Stacked Omnidirectional + Composite, GS1 DataBar Truncated, GS1 DataBar Limited, GS1 DataBar + Expanded, GS1 DataBar Expanded Stacked symbologies were added. + - The default height for the GS1-128 symbologies was changed. + - Preliminary support for the GS1 DataBar Limited Composite + symbology was added. + - Preliminary support for the EAN-8 Composite, UPC-A Composite and + UPC-E Composite symbologies was added. + - Support for the GS1 Composite 2D components was added. + - Preliminary support for the EAN-13 Composite symbology was added. + - Renamed rss14 to databaromni, rsslimited to databarlimited, + rssexpanded to databarexpanded. + - Added convenience encoders for GS1 DataBar Stacked, GS1 DataBar + Stacked Omnidirectional, GS1 DataBar Truncated and GS1 DataBar + Expanded Stacked. + - Support for the HIBC MicroPDF417 symbology was added. + - Support for the MicroPDF417 symbology was added. + - Support for CC-A/B amd CC-C composite linkage was added to the + GS1-128 symbology. + - The Code 128 symbology was extended with support for composite + linkage pseudo characters. + - PDF417 was amended to automatically select an appropriate number + of columns when not provided. + - The default error correction levels for PDF417 symbols were updated. + - A bug in the encoding of the general purpose field ending in + numeric mode of GS1 DataBar expanded symbols was fixed. + - Renamed occurrences of alpha mode to alphanumeric in GS1 Databar + Expanded symbology to disambiguate from the standard GS1 alpha + encoding. + - The list of FNC1 exempt GS-1 application identifiers was fixed in + the GS1-128 and GS1 DataBar symbologies. + - Fixed occurances of a bad programming paradigm that could result + in the incorrect generation of certain symbols when including + multiple instances. + - Support for the Deutsche Post Leitcode Symbology was added. + - Support for the Deutsche Post Identcode Symbology was added. + - A checkoffset option was added to the posicode encoder to + facilitate multirow symbols. + - Support for the Flattermarken symbology was added. + - Checksum support for the Channel Code encoder was added. + - Support for the PosiCode symbology was added. + - An option to use a short finder pattern was added to the Channel + Code encoder. + - Support for the Channel Code symbology was added. + - Support for the HIBC Code 39, HIBC Code 128, HIBC Data Matrix, + HIBC PDF417 and HIBC QR Code symbologies was added. + - The efficiency of the Two-Track Pharmacode encoder was improved. + - The escape sequences for the special shift characters were changed. + - Support for the Code 93 Extended symbology was added. + - Support for the Code 39 Extended symbology was added. + - Support for the ITF-14 symbology was added. + - Support for the SSCC-18 symbology was added. + - Support for the GS1-14 symbology was added. + - Support for the GS1-128 symbology was added. + - The code128 encoder was modified to automatically encode the input. + - Support for the Pharmazentralnummer (PZN) symbology was added. + - The text parameters for EAN an UPC symbols are now applied to the addons. + - A bug in the display of the ISSN check digit was fixed. + - Support for Code 32 (Italian Pharmacode) was added. + - Added daft encoder to make it easier to create miscellaneous + symbols in a custom 4 state symbology. + - Support was added to the Plessey symbology for the unidirectional + variant. + - Support for the BC412 symbology was added. + - A bug in the calculation of the border height was fixed. + - The example for Two-track Pharmacode was changes to display a border. + - Support for the Two-track Pharmacode symbology was added. + - Support for the ISSN symbology was added. + - Support for the ISMN symbology was added. + - The ISBN encoder was improved to upgrade ISBN-10 input to ISBN-13. + - The code2of5 encoder was improved to support the IATA, matrix, + COOP, and Datalogic versions of the symbology. + - A bug was fixed that could allow the generation of invalid MSI + symbols when using a modulus 11 check digit. + - Support for the Telepen symbology was added. + - A bug in the placement of human readable text for Plessey and MSI + symbols was fixed. + - The bar-space widths were amended for Plessey and MSI symbols were + amended to better conform to their specifications. + - A bug in the calculation of the checksum of Plessey symbols was fixed. + - A bug in the calculation of the checksum of MSI symbols was fixed. + - Additional checksum types where added to the MSI symbology. + - A bug in the determination of the error correction level of PDF417 + symbols was fixed. + - A bug in QR Code mask evaluation was fixed. + - Support for the USPS PLANET symbology was added. + - An input handling bug in the USPS POSTNET encoder was fixed. + - The list of FNC1 exempt application identifiers in GS1 DataBar + Expanded was fixed. + - A bug in the numeric encoding of the general purpose field of GS1 + DataBar Expanded symbols was fixed. + - Support for UPC-E1 was added to the upce encoder. + - Converted to a set of PostScript named resources rather than a + procedure list. + - A bug in the symbol selection algorithm for QR Code was fixed. + - Ensure that auto-encoding a micro-format QR Code symbol fails + rather than produces a full-format symbol. + - Convert interleaved2of5 encoder to use barratio and spaceratio to + set the narrow to wide bar ratio. + - Ensure that the UPC-E encoder does not fail silently when an + invalid input is given. 2009-08-13 - Added support for pdf417 2009-08-06 - Added support for several 2D matrix codes 2007-07-10 - Added QR code, Aztex code. diff --git a/Master/texmf-dist/doc/generic/pst-barcode/pst-barcode-doc.bib b/Master/texmf-dist/doc/generic/pst-barcode/pst-barcode-doc.bib index cb8f1f164c5..f54f7347dfb 100644 --- a/Master/texmf-dist/doc/generic/pst-barcode/pst-barcode-doc.bib +++ b/Master/texmf-dist/doc/generic/pst-barcode/pst-barcode-doc.bib @@ -17,9 +17,9 @@ @Book{PSTricks2, author = {Herbert Vo\ss}, title = {{\PST} {G}rafik f\"ur \TeX{} und \LaTeX}, - edition = {fifth}, - publisher = {DANTE -- Lob.media}, - year = {2008}, + edition = {6.}, + publisher = {DANTE -- lehmanns media}, + year = {2010}, address = {Heidelberg/Hamburg} } diff --git a/Master/texmf-dist/doc/generic/pst-barcode/pst-barcode-doc.pdf b/Master/texmf-dist/doc/generic/pst-barcode/pst-barcode-doc.pdf index 68c4e233836..ac10b110f50 100644 Binary files a/Master/texmf-dist/doc/generic/pst-barcode/pst-barcode-doc.pdf and b/Master/texmf-dist/doc/generic/pst-barcode/pst-barcode-doc.pdf differ diff --git a/Master/texmf-dist/doc/generic/pst-barcode/pst-barcode-doc.tex b/Master/texmf-dist/doc/generic/pst-barcode/pst-barcode-doc.tex index 4c83feb1440..28b2a05fce7 100644 --- a/Master/texmf-dist/doc/generic/pst-barcode/pst-barcode-doc.tex +++ b/Master/texmf-dist/doc/generic/pst-barcode/pst-barcode-doc.tex @@ -4,11 +4,11 @@ \usepackage[utf8]{inputenc} \usepackage{pst-barcode} \let\pstBarcodeFV\fileversion -\lstset{pos=l,wide=false,language=PSTricks, +\lstset{preset=\centering,pos=l,wide=false,vsep=5mm,language=PSTricks,%width=0.5\linewidth, morekeywords={multidipole,parallel},basicstyle=\footnotesize\ttfamily} % \def\bgImage{\begin{pspicture}(1in,1in) -%\psbarcode{Herbert Voss Freie Universitaet Berlin}{rows=52 columns=52}{datamatrix} +\psbarcode{Herbert Voss Freie Universitaet Berlin}{rows=52 columns=52}{datamatrix} \end{pspicture}} \begin{document} @@ -45,14 +45,14 @@ To install the package put the three files in a place, where \TeX{} will search for the files: \bigskip\noindent -\begin{tabular}{@{} l l l @{}} +\begin{tabular}{@{} l l l @{}}\hline \emph{name} & \emph{meaning}& \emph{target dir} \\\hline \verb+pst-barcode.tex+ & \LaTeX\ style file -- wrapper & \verb+$LOCALTEXMF/tex/generic/pstricks/+\\ \verb+pst-barcode.sty+ & \TeX\ file -- PS interface &\verb+$LOCALTEXMF/tex/latex/pstricks/+\\ \verb+pst-barcode.pro+ & PostScript file & \verb+$LOCALTEXMF/dvips/pstricks/+ \\ \verb+pst-barcode-doc.tex+ & documentation source & \verb+$LOCALTEXMF/doc/pstricks/+\\ \verb+pst-barcode-doc.bib+ & bibliography source & \verb+$LOCALTEXMF/doc/pstricks/+\\ -\verb+pst-barcode-doc.pdf+ & documentation & \verb+$LOCALTEXMF/doc/pstricks/+ %$ +\verb+pst-barcode-doc.pdf+ & documentation & \verb+$LOCALTEXMF/doc/pstricks/+ \\\hline%$ \end{tabular} \bigskip @@ -70,18 +70,18 @@ or the \Lcs{makebox} macro. \section{The options} \subsection{The \TeX\ options} -\begin{tabular}{@{}lll@{}} +\begin{tabular}{@{}lll@{}}\hline \emph{name} & \emph{default} & \emph{remarks}\\\hline \Lkeyword{transx} & 0 & horizontal shift\\ \Lkeyword{transy} & 0 & vertical shift\\ \Lkeyword{scalex} & 1 & horizontal scaling\\ \Lkeyword{scaley} & 1 & vertical scaling\\ -\Lkeyword{rotate} & 0 & rotating angle in degrees +\Lkeyword{rotate} & 0 & rotating angle in degrees\\\hline \end{tabular} \subsection{The PostScript options} -\begin{tabularx}{\textwidth}{@{}llX@{}} +\begin{tabularx}{\textwidth}{@{}llX@{}}\hline \emph{name} & \emph{default} & \emph{remarks}\\\hline \Lps{height} & 1 & dimension is inch\\ \Lps{textsize} & 10 & dimension is pt\\ @@ -100,25 +100,26 @@ or the \Lcs{makebox} macro. \Lps{includetext} & -- & enable human readable text \\ \Lps{includecheck} & -- & enable check digit \\ \Lps{includecheckintext} & -- & check digit visible in text\\ -\Lps{parse} & -- & parse variable field für decimal values, like \^{}032 for space, and convert them to ASCII +\Lps{parse} & -- & parse variable field für decimal values, like \^{}032 for space, and convert them to ASCII\\\hline \end{tabularx} \subsection{Examples for the TeX options} -\begin{LTXexample}[pos=t,preset=\centering] -\begin{pspicture}(3.5,1.2in) +\begin{LTXexample}[pos=t,preset=\centering,wide] +\psframebox{\begin{pspicture}(2.5,1in) \psbarcode{12345678}{includetext}{ean8} -\end{pspicture} -\begin{pspicture}(-2,-1.5)(0.5,0.2in) +\end{pspicture}}\quad +\psframebox{\begin{pspicture}(-2.6,-1.5)(0.4,0.2in) \psbarcode[rotate=180,linecolor=red]{12345678}{includetext guardwhitespace height=0.6}{ean8} -\end{pspicture} -\begin{pspicture}(3.5,1.2in) -\psbarcode[scalex=1.5,scaley=0.5,transy=20]{12345678}{includetext inkspread=0.5}{ean8} -\end{pspicture} +\end{pspicture}}\quad +\psframebox{\begin{pspicture}(3.8,1in) +\psbarcode[scalex=1.5,scaley=0.5,transy=1]{12345678}{includetext inkspread=0.5}{ean8} +\end{pspicture}} \end{LTXexample} + \newpage \subsection{Examples for the PostScript options} @@ -163,7 +164,7 @@ bar \xLps{code39} \bigskip -\begin{LTXexample}[width=.5\linewidth] +\begin{LTXexample}[pos=l,width=.5\linewidth] foo \fbox{% \begin{pspicture}(0,-8pt)(1.5in,1in) @@ -238,7 +239,7 @@ try the support mailing list. \end{description} \xLps{upca} -\begin{LTXexample}[width=.3\linewidth] +\begin{LTXexample}[pos=l,width=.3\linewidth,wide] \begin{pspicture}(3,1.2in) \psbarcode[transx=15pt,transy=10pt]{78858101497}{includetext}{upca} \qdisk(0,0){3pt}\rput[lb](5pt,-10pt){Origin} @@ -260,7 +261,7 @@ try the support mailing list. \end{description} \xLps{upce} -\begin{LTXexample}[width=.3\linewidth] +\begin{LTXexample}[pos=l,width=.3\linewidth] \begin{pspicture}(1.5,1.2in) \psbarcode{0123456}{includetext}{upce} \end{pspicture} @@ -279,7 +280,7 @@ try the support mailing list. \end{description} \xLps{ean5} -\begin{LTXexample}[width=.3\linewidth] +\begin{LTXexample}[pos=l,width=.3\linewidth] \begin{pspicture}(2,1in) \psbarcode{90200}{includetext guardwhitespace}{ean5} \end{pspicture} @@ -298,35 +299,13 @@ try the support mailing list. \end{description} \xLps{ean2} -\begin{LTXexample}[width=.3\linewidth] +\begin{LTXexample}[pos=l,width=.3\linewidth] \begin{pspicture}(1,1in) \psbarcode{38}{includetext guardwhitespace}{ean2} \end{pspicture} \end{LTXexample} -\subsection{onecode} - -\begin{description} -\item[Characters] \verb+0123456789+ -\item[Data] Variable -\item[Options]~\\ - \begin{tabular}{l|l} - Option & Feature\\\hline - \texttt{includetext} & Enable human readable text\\ - \end{tabular} -\end{description} - -\xLps{onecode} -\begin{LTXexample}[pos=t] -\begin{pspicture}(0,-5mm)(2.5in,0.3in) -\psbarcode{0123456709498765432101234567891}{includetext}{onecode} -\end{pspicture} -\end{LTXexample} - - - -\newpage \subsection{ISBN} An ISBN symbol is really an EAN-13 with a particular prefix, 978 for the older ISBN-10 format, and others for the new ISBN-13 format. @@ -345,14 +324,14 @@ An ISBN symbol is really an EAN-13 with a particular prefix, 978 for the older I \xLps{isbn} \smallskip -\begin{LTXexample}[width=.3\linewidth] +\begin{LTXexample}[pos=l,width=.3\linewidth] \begin{pspicture}(3,1in) \psbarcode{3-86541-114}{includetext guardwhitespace}{isbn} \end{pspicture} \end{LTXexample} \bigskip\enlargethispage{2ex} -\begin{LTXexample}[width=.3\linewidth] +\begin{LTXexample}[pos=l,width=.3\linewidth] \begin{pspicture}(3,1in) \psbarcode{978-3-86541-114}{includetext guardwhitespace}{isbn} \end{pspicture} @@ -374,7 +353,7 @@ An ISBN symbol is really an EAN-13 with a particular prefix, 978 for the older I \end{description} -\begin{LTXexample}[width=.5\linewidth] +\begin{LTXexample}[pos=l,width=.4\linewidth,wide] \begin{pspicture}(5,1in) \psbarcode{CODE-39}{includecheck includetext}{code39} \end{pspicture} @@ -421,7 +400,7 @@ for the initial character set. UCC/EAN-128s must have a manditory \end{tabular} \end{description} -\begin{LTXexample}[width=.5\linewidth] +\begin{LTXexample}[pos=l,width=.4\linewidth] \begin{pspicture}(4,1in) \psbarcode{0123456789}{includetext}{rationalizedCodabar} \end{pspicture} @@ -471,6 +450,8 @@ for the initial character set. UCC/EAN-128s must have a manditory \end{LTXexample} +\clearpage + \subsection{Postnet} \begin{description} @@ -506,7 +487,7 @@ for the initial character set. UCC/EAN-128s must have a manditory \item[Notes] Check digit is always added automatically \end{description} -\begin{LTXexample}[width=.5\linewidth] +\begin{LTXexample}[pos=l,width=.4\linewidth] \begin{pspicture}(5,0.5in) \psbarcode{LE28HS9Z}{includetext}{royalmail} \end{pspicture} @@ -526,7 +507,7 @@ for the initial character set. UCC/EAN-128s must have a manditory \item[Notes] Check digit is always added automatically \end{description} -\begin{LTXexample}[width=.5\linewidth] +\begin{LTXexample}[pos=l,width=.4\linewidth] \begin{pspicture}(5,0.3in) \psbarcode{1203AA12}{includetext}{kix} \end{pspicture} @@ -547,7 +528,7 @@ for the initial character set. UCC/EAN-128s must have a manditory %\item[Notes] Check digit is always added automatically \end{description} -\begin{LTXexample}[width=.5\linewidth] +\begin{LTXexample}[pos=l,width=.4\linewidth] \begin{pspicture}(5,0.3in) \psbarcode{1139549554}{includetext}{auspost} \end{pspicture} @@ -601,25 +582,25 @@ The purpose of the symbol encoder is to store the definitions of miscellaneous b symbols such as the FIM symbols used by the US Postal Service on their reply mail. -\begin{LTXexample}[width=.4\linewidth] +\begin{LTXexample}[pos=l,width=.4\linewidth] \begin{pspicture}(1cm,1.5cm) \psbarcode{fima}{}{symbol} \end{pspicture} \end{LTXexample} -\begin{LTXexample}[width=.4\linewidth] +\begin{LTXexample}[pos=l,width=.4\linewidth] \begin{pspicture}(1cm,1.5cm) \psbarcode{fimb}{}{symbol} \end{pspicture} \end{LTXexample} -\begin{LTXexample}[width=.4\linewidth] +\begin{LTXexample}[pos=l,width=.4\linewidth] \begin{pspicture}(1cm,1.5cm) \psbarcode{fimc}{}{symbol} \end{pspicture} \end{LTXexample} -\begin{LTXexample}[width=.4\linewidth] +\begin{LTXexample}[pos=l,width=.4\linewidth] \begin{pspicture}(1cm,1.5cm) \psbarcode{fimd}{}{symbol} \end{pspicture} @@ -640,7 +621,7 @@ symbols such as the FIM symbols used by the US Postal Service on their reply mai \end{tabular} \end{description} -\begin{LTXexample}[width=.5\linewidth] +\begin{LTXexample}[pos=l,width=.5\linewidth,wide] \begin{pspicture}(6,1in) \psbarcode{0123456789}{includecheck includetext}{msi} \end{pspicture} @@ -668,7 +649,8 @@ symbols such as the FIM symbols used by the US Postal Service on their reply mai \subsection{Reduced Space Symbology (RSS)} This is a family that includes RSS-14\textregistered, RSS Limited\textregistered, -and RSS Expanded\textregistered{} (\url{http://www.gs1.org/productssolutions/barcodes/technical/rss.html}). RSS-14 and RSS Limited encode Global Trade Item +and RSS Expanded\textregistered{} (\url{http://www.gs1.org/productssolutions/barcodes/technical/rss.html}). +RSS-14 and RSS Limited encode Global Trade Item Numbers (GTINs). RSS Expanded will encode any of the GS1 System identification numbers as well as all other Application Identifiers. RSS is used in the healthcare industry. @@ -678,25 +660,25 @@ RSS is used in the healthcare industry. \item[Data] Variable number digits \end{description} -\subsubsection{rss14} +\subsubsection{rss14 (databaromni)} \begin{LTXexample}[width=.3\linewidth] \begin{pspicture}(12,.3in) -\psbarcode{(01)24012345678905}{format=truncated includetext height=0.3}{rss14} +\psbarcode{(01)24012345678905}{format=truncated includetext height=0.3}{databaromni} \end{pspicture} \end{LTXexample} -\subsubsection{rsslimited} -\begin{LTXexample}[width=.3\linewidth] +\subsubsection{rsslimited (databarlimited)} +\begin{LTXexample}[pos=l,width=.3\linewidth] \begin{pspicture}(12,.3in) -\psbarcode{(01)15012345678907}{height=0.3}{rsslimited} +\psbarcode{(01)15012345678907}{height=0.3}{databarlimited} \end{pspicture} \end{LTXexample} -\subsubsection{rssexpanded} -\begin{LTXexample}[width=.3\linewidth] +\subsubsection{rssexpanded (databarexpanded)} +\begin{LTXexample}[pos=l,width=.3\linewidth] \begin{pspicture}(12,.3in) -\psbarcode{(10)12A}{height=0.3}{rssexpanded} +\psbarcode{(10)12A}{height=0.3}{databarexpanded} \end{pspicture} \end{LTXexample} @@ -709,7 +691,7 @@ For a documentation see \url{http://www.laetus.com/laetus.php?request=file&id=69 \item[Data] Variable number digits \end{description} -\begin{LTXexample}[width=.3\linewidth] +\begin{LTXexample}[pos=l,width=.3\linewidth] \begin{pspicture}(12,.3in) \psbarcode{117480}{}{pharmacode} \end{pspicture} @@ -723,7 +705,7 @@ For a documentation see \url{http://de.wikipedia.org/wiki/Strichcode#PDF417}. \item[Data] Variable number characters \end{description} -\begin{LTXexample}[width=2in,wide] +\begin{LTXexample}[pos=l,width=2in,wide] \begin{pspicture}(2in,0.3in) \psbarcode{^453^178^121^239}{columns=2 rows=10}{pdf417} \end{pspicture} @@ -738,7 +720,7 @@ It is used for the german post company DHL. \item[Data] Variable number characters \end{description} -\begin{LTXexample}[width=1in,wide] +\begin{LTXexample}[pos=l,width=1in,wide] \begin{pspicture}(1in,1in) \psbarcode{Herbert Voss ^142^164^186}{rows=48 columns=48 parse}{datamatrix} \end{pspicture} @@ -804,7 +786,7 @@ corporation Denso-Wave in 1994 (\url{http://de.wikipedia.org/wiki/QR_Code}). \item[Data] Variable number characters \end{description} -\begin{LTXexample}[width=1in,wide] +\begin{LTXexample}[pos=l,width=1in,wide] \begin{pspicture}(1in,1in) \psbarcode{http://www.dante.de}{}{qrcode} \end{pspicture} @@ -822,7 +804,7 @@ Aztec Code was invented by Andrew Longacre (USA) in 1995 \item[Data] Variable number characters \end{description} -\begin{LTXexample}[width=1in,wide] +\begin{LTXexample}[pos=l,width=1in,wide] \begin{pspicture}(1in,1in) \psbarcode{0123456789}% {format=compact layers=3}{azteccode} @@ -868,27 +850,6 @@ Aztec Code was invented by Andrew Longacre (USA) in 1995 \end{pspicture} \end{LTXexample} -%\psbarcode{000100000010000000001100010101100110000110000}{version=1 eclevel=M}{qrcode} - - -\subsection{PDF417} -%Aztec Code is a 2 dimensional matrix style bar code symbology. -%Aztec Code was invented by Andrew Longacre (USA) in 1995 -%(\url{http://de.wikipedia.org/wiki/Aztec_Code}). - - -\begin{description} -\item[Characters] \verb!0123456789! -\item[Data] Variable number characters -\end{description} - -\begin{LTXexample}[width=1.5in,wide] -\begin{pspicture}(1in,1in) -\psbarcode{^453^178^121^239}% - {columns=2 rows=10}{pdf417} -\end{pspicture} -\end{LTXexample} - \section{Code Commentary} This commentary assumes familiarity with the PostScript @@ -928,9 +889,8 @@ dictionary when the PostScript is executed. \begin{center} -\begin{tabular}{l|c|p{6.5cm}} -Element & Key & Value \\ -\hline +\begin{tabular}{l|c|p{6.5cm}}\hline +\emph{Element} & \emph{Key} & \emph{Value} \\\hline Space bar succession & \texttt{sbs} & String containing the integer widths, in points, of each bar and space, starting with the leftmost bar.\\ @@ -946,7 +906,7 @@ starting with the leftmost bar.\\ Human readable text & \texttt{txt} & Array of arrays that contain the character, position, height, font and scale factor (font size), in points, for each of the visible -text characters. +text characters.\\\hline \end{tabular} \end{center} @@ -1301,58 +1261,103 @@ serverdict begin 0 exitserver systemdict /quit get exec \iffalse -30 500 moveto (CODE 39) (includecheck includetext) code39 barcode +30 500 moveto (CODE 39) (includecheck includetext) /code39 /uk.co.terryburton.bwipp findresource exec 0 -17 rmoveto (Code 39) show -390 200 moveto (THIS IS CODE 93) (includecheck includetext) code93 barcode + +385 200 moveto (THIS IS CODE 93) (includecheck includetext) /code93 /uk.co.terryburton.bwipp findresource exec 0 -17 rmoveto (Code 93) show -400 600 moveto (^104^102Abc^09912345678^101!) (includetext) code128 barcode -0 -17 rmoveto (Code 128) show -150 700 moveto (0123456789) (includecheck includetext) interleaved2of5 barcode + +375 400 moveto (\(00\)030123456789012340|\(02\)13012345678909\(37\)24\(10\)1234567ABCDEFG) (ccversion=c includetext) /gs1-128composite /uk.co.terryburton.bwipp findresource exec +0 -17 rmoveto (GS1-128 Composite) show + +150 700 moveto (0123456789) (includecheck includetext) /interleaved2of5 /uk.co.terryburton.bwipp findresource exec 0 -17 rmoveto (Interleaved 2 of 5) show -215 300 moveto (24012345678905) (height=0.3 includetext) rss14 barcode -0 -17 rmoveto (RSS-14) show -220 550 moveto (00978186074271) (height=0.3 includetext) rsslimited barcode -0 -17 rmoveto (RSS Limited) show -220 500 moveto (000000010011001010100001000000010000) (height=0.3) rssexpanded barcode -0 -10 rmoveto (RSS Expanded) show -215 348 moveto (117480) (includetext) pharmacode barcode + +215 300 moveto ((01)24012345678905) (includetext) /databartruncated /uk.co.terryburton.bwipp findresource exec +0 -17 rmoveto (DataBar Truncated) show + +250 250 moveto ((01)24012345678905) () /databarstacked /uk.co.terryburton.bwipp findresource exec +0 -10 rmoveto (DataBar Stacked) show + +220 560 moveto ((01)15012345678907) () /databarlimited /uk.co.terryburton.bwipp findresource exec +0 -10 rmoveto (DataBar Limited) show + +220 500 moveto ((10)12A) () /databarexpanded /uk.co.terryburton.bwipp findresource exec +0 -10 rmoveto (DataBar Expanded) show + +215 348 moveto (117480) (includetext) /pharmacode /uk.co.terryburton.bwipp findresource exec 0 -17 rmoveto (Pharmacode) show -30 300 moveto (01234567) (includetext includecheck) code2of5 barcode + +30 300 moveto (01234567) (includetext includecheck) /code2of5 /uk.co.terryburton.bwipp findresource exec 0 -17 rmoveto (Code 2 of 5) show -165 600 moveto (0124589) (includetext includecheck barcolor=AA0000 textyoffset=-8 textcolor=008888 backgroundcolor=2020FF0F showborder bordercolor=0000FF) code11 barcode + +165 600 moveto (0124589) << + /includetext true + /includecheck true + /barcolor (AA0000) + /textyoffset -8 + /textcolor (008888) + /backgroundcolor (2020FF0F) + /showborder true + /bordercolor (0000FF) +>> /code11 /uk.co.terryburton.bwipp findresource exec 0 -17 rmoveto (Code 11) show -30 400 moveto (A0123456789B) (includecheck includetext) rationalizedCodabar barcode + +30 400 moveto (A0123456789B) (includecheck includetext) /rationalizedCodabar /uk.co.terryburton.bwipp findresource exec 0 -17 rmoveto (Rationalized Codabar) show -430 700 moveto (977147396801) (includetext) ean13 barcode + +420 700 moveto (977147396801 05) (includetext guardwhitespace) /ean13 /uk.co.terryburton.bwipp findresource exec 0 -17 rmoveto (EAN-13) show -535 705.4 moveto (05) (includetext guardwhitespace) ean2 barcode -0 -17 rmoveto (EAN-2) show -30 700 moveto (01335583) (includetext guardwhitespace) ean8 barcode + +41 700 moveto (01335583) (includetext guardwhitespace) /ean8 /uk.co.terryburton.bwipp findresource exec 0 -17 rmoveto (EAN-8) show -30 600 moveto (78858101497) (includetext) upca barcode + +37 600 moveto (78858101497) (includetext) /upca /uk.co.terryburton.bwipp findresource exec 0 -17 rmoveto (UPC-A) show -320 700 moveto (0425261) (includetext) upce barcode + +315 700 moveto (0425261) (includetext) /upce /uk.co.terryburton.bwipp findresource exec 0 -17 rmoveto (UPC-E) show -405 400 moveto (978-1-86074-271) (includetext) isbn barcode + +405 600 moveto (978-1-86074-271 54495) (includetext) /isbn /uk.co.terryburton.bwipp findresource exec 0 -17 rmoveto (ISBN) show -510 405.4 moveto (90200) (includetext) ean5 barcode -0 -17 rmoveto (EAN-5) show -240 455 moveto (012345) (includetext) postnet barcode + +345 515 moveto (0123456709498765432101234567891) (includetext) /onecode /uk.co.terryburton.bwipp findresource exec +0 -17 rmoveto (OneCode) show + +215 455 moveto (01234) (includetext) /postnet /uk.co.terryburton.bwipp findresource exec 0 -17 rmoveto (Postnet) show -240 410 moveto (LE28HS9Z) (includetext) royalmail barcode + +215 410 moveto (LE28HS9Z) (includetext) /royalmail /uk.co.terryburton.bwipp findresource exec 0 -17 rmoveto (Royal Mail) show -410 145 moveto (1231FZ13XHS) (includetext) kix barcode + +400 165 moveto (1231FZ13XHS) (includetext) /kix /uk.co.terryburton.bwipp findresource exec 0 -17 rmoveto (KIX) show -385 515 moveto (5956439111ABA 9) (includetext) auspost barcode + +335 555 moveto (6540123789-A-K-Z) (includetext textxalign=center) /japanpost /uk.co.terryburton.bwipp findresource exec +0 -17 rmoveto (JapanPost) show + +385 132 moveto (5956439111ABA 9) (includetext) /auspost /uk.co.terryburton.bwipp findresource exec 0 -17 rmoveto (AusPost) show -350 300 moveto (12345) (includecheck includetext) msi barcode + +348 300 moveto (123456) (includecheck includetext) /msi /uk.co.terryburton.bwipp findresource exec 0 -17 rmoveto (MSI) show -30 200 moveto (123ABCD) (includetext) plessey barcode + +30 200 moveto (123AB) (includetext) /plessey /uk.co.terryburton.bwipp findresource exec 0 -17 rmoveto (Plessey) show -47 135 moveto (1001234567890) (showborder borderwidth=4 borderleft=15 borderright=15 height=0.5 includecheck includetext includecheckintext textyoffset=-10) interleaved2of5 barcode + +47 135 moveto (10012345678902) (includetext) /itf14 /uk.co.terryburton.bwipp findresource exec -15 -20 rmoveto (ITF-14) show -485 300 moveto (^059^042^041^059^040^03001^02996152382802^029840^029001^0291Z00004951^029UPSN^02906X610^029159^0291234567^0291^0471^029^029Y^029634 ALPHA DR^029PITTSBURGH^029PA^030^062^004^063) (mode=2) maxicode barcode -0 -10 rmoveto (MaxiCode) show -%300 600 moveto (^142^164^186) (rows=48 columns=48) datamatrix barcode -%0 -10 rmoveto (Data Matrix) show -\fi \ No newline at end of file + +245 125 moveto (http://lwn.net) () /qrcode /uk.co.terryburton.bwipp findresource exec +0 -10 rmoveto (QR Code) show + +245 190 moveto (This is PDF417) (columns=2 color=442222 backgroundcolor=AABBCC) /pdf417 /uk.co.terryburton.bwipp findresource exec +0 -10 rmoveto (PDF417) show + +300 600 moveto (http://www.terryburton.co.uk/barcodewriter/) (rows=48 columns=48) /datamatrix /uk.co.terryburton.bwipp findresource exec +0 -10 rmoveto (Data Matrix) show + +315 125 moveto (This is Aztec Code) (format=compact layers=3) /azteccode /uk.co.terryburton.bwipp findresource exec +0 -10 rmoveto (Aztec Code) show + +\fi diff --git a/Master/texmf-dist/dvips/pst-barcode/pst-barcode.pro b/Master/texmf-dist/dvips/pst-barcode/pst-barcode.pro index 4e7442342b0..57ac6956c5b 100644 --- a/Master/texmf-dist/dvips/pst-barcode/pst-barcode.pro +++ b/Master/texmf-dist/dvips/pst-barcode/pst-barcode.pro @@ -3,10 +3,10 @@ %%DocumentPaperSizes: a4 %%EndComments -% Barcode Writer in Pure PostScript - Version 2009-08-12 +% Barcode Writer in Pure PostScript - Version 2011-03-09 % http://www.terryburton.co.uk/barcodewriter/ % -% Copyright (c) 2004-2009 Terry Burton +% Copyright (c) 2004-2011 Terry Burton % % Permission is hereby granted, free of charge, to any % person obtaining a copy of this software and associated @@ -32,15 +32,29 @@ % CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS % IN THE SOFTWARE. -% Uncomment this next line to allow these procedure definitions to -% remain resident within a printer's PostScript virtual machine -% so that the barcode generation capability persists between jobs. +% Uncomment this next line to allow these named resource +% definitions to remain resident within a printer's +% PostScript virtual machine so that the barcode generation +% capability persists between jobs. % serverdict begin 0 exitserver % --BEGIN TEMPLATE-- +% --BEGIN PREAMBLE-- +currentglobal +true setglobal +/Generic /Category findresource +dup length 1 add dict copy +dup /InstanceType /packedarraytype put +/uk.co.terryburton.bwipp exch /Category defineresource pop +setglobal +% --END PREAMBLE-- + % --BEGIN RENDERER renlinear-- +/setpacking where {pop currentpacking true setpacking} if +1 dict +begin /renlinear { 20 dict begin % Confine variables to local scope @@ -121,13 +135,17 @@ 0 1 sbs length 1 add 2 idiv 2 mul 2 sub { /i exch def i 2 mod 0 eq { % i is even - /d sbs i get barratio mul barratio sub 1 add def % d=digit*r-r+1 - /h bhs i 2 idiv get 72 mul def % Height from bhs - /c d 2 div x add def % Centre of the bar = x + d/2 - /y bbs i 2 idiv get 72 mul def % Baseline from bbs - /w d inkspread sub def % bar width = digit - inkspread - bars i 2 idiv [h c y w] put % Add the bar entry - h maxh gt {/maxh h def} if + /d sbs i get barratio mul barratio sub 1 add def % d=digit*r-r+1 + sbs i get 0 ne { + /h bhs i 2 idiv get 72 mul def % Height from bhs + /c d 2 div x add def % Centre of the bar = x + d/2 + /y bbs i 2 idiv get 72 mul def % Baseline from bbs + /w d inkspread sub def % bar width = digit - inkspread + bars i 2 idiv [h c y w] put % Add the bar entry + h y add maxh gt {/maxh h y add def} if + } { + bars i 2 idiv -1 put % Dummy entry + } ifelse } { /d sbs i get spaceratio mul spaceratio sub 1 add def % d=digit*r-r+1 } ifelse @@ -175,8 +193,11 @@ 0 setlinecap barcolor (unset) ne { barcolor setanycolor } if bars { - {} forall - newpath setlinewidth moveto 0 exch rlineto stroke + dup -1 ne { + aload pop newpath setlinewidth moveto 0 exch rlineto stroke + } { + pop + } ifelse } forall grestore @@ -264,9 +285,15 @@ end } bind def +/renlinear dup load /uk.co.terryburton.bwipp defineresource pop +end +/setpacking where {pop setpacking} if % --END RENDERER renlinear-- % --BEGIN RENDERER renmatrix-- +/setpacking where {pop currentpacking true setpacking} if +1 dict +begin /renmatrix { 20 dict begin @@ -328,9 +355,15 @@ end } bind def +/renmatrix dup load /uk.co.terryburton.bwipp defineresource pop +end +/setpacking where {pop setpacking} if % --END RENDERER renmatrix-- % --BEGIN RENDERER renmaximatrix-- +/setpacking where {pop currentpacking true setpacking} if +1 dict +begin /renmaximatrix { 20 dict begin @@ -378,6 +411,9 @@ end } bind def +/renmaximatrix dup load /uk.co.terryburton.bwipp defineresource pop +end +/setpacking where {pop setpacking} if % --END RENDERER renmaximatrix-- % --BEGIN ENCODER ean5-- @@ -385,6 +421,10 @@ % --EXAM: 90200 % --EXOP: includetext guardwhitespace % --RNDR: renlinear +/setpacking where {pop currentpacking true setpacking} if +1 dict +dup /renlinear dup /uk.co.terryburton.bwipp findresource put +begin /ean5 { 20 dict begin @@ -484,7 +524,7 @@ % Return the arguments << - /ren (renlinear) + /ren //renlinear /sbs [sbs {48 sub} forall] /bhs [16{height}repeat] /bbs [16{0}repeat] @@ -502,6 +542,9 @@ end } bind def +/ean5 dup load /uk.co.terryburton.bwipp defineresource pop +end +/setpacking where {pop setpacking} if % --END ENCODER ean5-- % --BEGIN ENCODER ean2-- @@ -509,6 +552,10 @@ % --EXAM: 05 % --EXOP: includetext guardwhitespace % --RNDR: renlinear +/setpacking where {pop currentpacking true setpacking} if +1 dict +dup /renlinear dup /uk.co.terryburton.bwipp findresource put +begin /ean2 { 20 dict begin @@ -593,7 +640,7 @@ % Return the arguments << - /ren (renlinear) + /ren //renlinear /sbs [sbs {48 sub} forall] /bhs [12{height}repeat] /bbs [12{0}repeat] @@ -611,6 +658,9 @@ end } bind def +/ean2 dup load /uk.co.terryburton.bwipp defineresource pop +end +/setpacking where {pop setpacking} if % --END ENCODER ean2-- % --BEGIN ENCODER ean13-- @@ -619,6 +669,12 @@ % --EXAM: 977147396801 % --EXOP: includetext guardwhitespace % --RNDR: renlinear +/setpacking where {pop currentpacking true setpacking} if +1 dict +dup /renlinear dup /uk.co.terryburton.bwipp findresource put +dup /ean2 dup /uk.co.terryburton.bwipp findresource put +dup /ean5 dup /uk.co.terryburton.bwipp findresource put +begin /ean13 { 20 dict begin @@ -764,6 +820,8 @@ /includetext true /height height 0.15 sub /textxoffset 95 addongap add + /textsize textsize + /textfont textfont >> def addon length 2 eq {addon addopts //ean2 exec} if addon length 5 eq {addon addopts //ean5 exec} if @@ -777,7 +835,7 @@ % Return the arguments << - /ren (renlinear) + /ren //renlinear /sbs sbs /bhs bhs /bbs bbs @@ -793,6 +851,9 @@ end } bind def +/ean13 dup load /uk.co.terryburton.bwipp defineresource pop +end +/setpacking where {pop setpacking} if % --END ENCODER ean13-- % --BEGIN ENCODER ean8-- @@ -801,6 +862,12 @@ % --EXAM: 01335583 % --EXOP: includetext guardwhitespace height=0.5 % --RNDR: renlinear +/setpacking where {pop currentpacking true setpacking} if +1 dict +dup /renlinear dup /uk.co.terryburton.bwipp findresource put +dup /ean2 dup /uk.co.terryburton.bwipp findresource put +dup /ean5 dup /uk.co.terryburton.bwipp findresource put +begin /ean8 { 20 dict begin @@ -926,6 +993,8 @@ /includetext true /height height 0.15 sub /textxoffset 67 addongap add + /textsize textsize + /textfont textfont >> def addon length 2 eq {addon addopts //ean2 exec} if addon length 5 eq {addon addopts //ean5 exec} if @@ -939,7 +1008,7 @@ % Return the arguments << - /ren (renlinear) + /ren //renlinear /sbs sbs /bhs bhs /bbs bbs @@ -956,6 +1025,9 @@ end } bind def +/ean8 dup load /uk.co.terryburton.bwipp defineresource pop +end +/setpacking where {pop setpacking} if % --END ENCODER ean8-- % --BEGIN ENCODER upca-- @@ -964,6 +1036,12 @@ % --EXAM: 78858101497 % --EXOP: includetext % --RNDR: renlinear +/setpacking where {pop currentpacking true setpacking} if +1 dict +dup /renlinear dup /uk.co.terryburton.bwipp findresource put +dup /ean2 dup /uk.co.terryburton.bwipp findresource put +dup /ean5 dup /uk.co.terryburton.bwipp findresource put +begin /upca { 20 dict begin @@ -1097,6 +1175,8 @@ /includetext true /height height 0.15 sub /textxoffset 95 addongap add + /textsize textsize + /textfont textfont >> def addon length 2 eq {addon addopts //ean2 exec} if addon length 5 eq {addon addopts //ean5 exec} if @@ -1110,7 +1190,7 @@ % Return the arguments << - /ren (renlinear) + /ren //renlinear /sbs sbs /bhs bhs /bbs bbs @@ -1126,6 +1206,9 @@ end } bind def +/upca dup load /uk.co.terryburton.bwipp defineresource pop +end +/setpacking where {pop setpacking} if % --END ENCODER upca-- % --BEGIN ENCODER upce-- @@ -1134,6 +1217,12 @@ % --EXAM: 0123456 % --EXOP: includetext height=0.4 % --RNDR: renlinear +/setpacking where {pop currentpacking true setpacking} if +1 dict +dup /renlinear dup /uk.co.terryburton.bwipp findresource put +dup /ean2 dup /uk.co.terryburton.bwipp findresource put +dup /ean5 dup /uk.co.terryburton.bwipp findresource put +begin /upce { 20 dict begin @@ -1166,6 +1255,11 @@ /height height cvr def /addongap addongap cvr def + % Ensure 0 or 1 number systems + barcode 0 get dup 48 ne exch 49 ne and { + /barcode () def + } if + % Split off the addon barcode ( ) search { /barcode exch def @@ -1193,6 +1287,7 @@ % Derive the equivalent UPC-A for its checksum /upcacode (00000000000) 11 string copy def + upcacode 0 barcode 0 get put barcode 6 get 48 sub 2 le { upcacode 1 barcode 1 2 getinterval putinterval upcacode 3 barcode 6 1 getinterval putinterval @@ -1295,6 +1390,8 @@ /includetext true /height height 0.15 sub /textxoffset 51 addongap add + /textsize textsize + /textfont textfont >> def addon length 2 eq {addon addopts //ean2 exec} if addon length 5 eq {addon addopts //ean5 exec} if @@ -1308,7 +1405,7 @@ % Return the arguments << - /ren (renlinear) + /ren //renlinear /sbs sbs /bhs bhs /bbs bbs @@ -1324,6 +1421,9 @@ end } bind def +/upce dup load /uk.co.terryburton.bwipp defineresource pop +end +/setpacking where {pop setpacking} if % --END ENCODER upce-- % --BEGIN ENCODER isbn-- @@ -1333,6 +1433,11 @@ % --EXAM: 978-1-56592-479 54495 % --EXOP: includetext guardwhitespace % --RNDR: renlinear +/setpacking where {pop currentpacking true setpacking} if +1 dict +dup /renlinear dup /uk.co.terryburton.bwipp findresource put +dup /ean13 dup /uk.co.terryburton.bwipp findresource put +begin /isbn { 20 dict begin @@ -1347,6 +1452,7 @@ /isbnpos (unset) def /height 1 def /addongap 12 def + /legacy false def % Parse the input options options type /stringtype eq { @@ -1368,7 +1474,7 @@ } { /isbnpos isbnpos cvr def } ifelse - + % Split off the addon isbntxt ( ) search { /isbntxt exch def @@ -1379,6 +1485,14 @@ /addon () def } ifelse + % Convert ISBN-10 to ISBN-13 + legacy not isbntxt length 13 le and { + /pad isbntxt length 4 add string def + pad 0 (978-) putinterval + pad 4 isbntxt putinterval + /isbntxt pad def + } if + % Read the digits from isbntxt and calculate checksums /isbn 13 string def /checksum10 0 def @@ -1475,27 +1589,39 @@ end } bind def +/isbn dup load /uk.co.terryburton.bwipp defineresource pop +end +/setpacking where {pop setpacking} if % --END ENCODER isbn-- -% --BEGIN ENCODER code128-- -% --DESC: Code 128 -% --EXAM: ^104^102Count^0990123456789^101! -% --EXOP: includetext +% --BEGIN ENCODER ismn-- +% --REQUIRES ean13-- +% --SUGGESTS ean5 ean2-- +% --DESC: ISMN +% --EXAM: 979-0-2600-0043 +% --EXOP: includetext guardwhitespace % --RNDR: renlinear -/code128 { +/setpacking where {pop currentpacking true setpacking} if +1 dict +dup /renlinear dup /uk.co.terryburton.bwipp findresource put +dup /ean13 dup /uk.co.terryburton.bwipp findresource put +begin +/ismn { - 20 dict begin % Confine variables to local scope + 20 dict begin - /options exch def % We are given an option string - /barcode exch def % We are given a barcode string + /options exch def % We are given an options string + /ismntxt exch def % We are given the ismn text with dashes /dontdraw false def - /includetext false def % Enable/disable text - /textfont /Courier def - /textsize 10 def - /textyoffset -7 def + /includetext false def % Enable/disable ISMN text + /ismnfont /Courier def + /ismnsize 9 def + /ismnpos (unset) def /height 1 def - + /addongap 12 def + /legacy false def + % Parse the input options options type /stringtype eq { 1 dict begin @@ -1506,128 +1632,149 @@ currentdict end /options exch def } if options {def} forall - - /textfont textfont cvlit def - /textsize textsize cvr def - /textyoffset textyoffset cvr def - /height height cvr def - % Create an array containing the character mappings - /encs - [ (212222) (222122) (222221) (121223) (121322) (131222) (122213) - (122312) (132212) (221213) (221312) (231212) (112232) (122132) - (122231) (113222) (123122) (123221) (223211) (221132) (221231) - (213212) (223112) (312131) (311222) (321122) (321221) (312212) - (322112) (322211) (212123) (212321) (232121) (111323) (131123) - (131321) (112313) (132113) (132311) (211313) (231113) (231311) - (112133) (112331) (132131) (113123) (113321) (133121) (313121) - (211331) (231131) (213113) (213311) (213131) (311123) (311321) - (331121) (312113) (312311) (332111) (314111) (221411) (431111) - (111224) (111422) (121124) (121421) (141122) (141221) (112214) - (112412) (122114) (122411) (142112) (142211) (241211) (221114) - (413111) (241112) (134111) (111242) (121142) (121241) (114212) - (124112) (124211) (411212) (421112) (421211) (212141) (214121) - (412121) (111143) (111341) (131141) (114113) (114311) (411113) - (411311) (113141) (114131) (311141) (411131) (211412) (211214) - (211232) (2331112) - ] def - - % Create a string of the available characters for alphabets A and B - /barchars ( !"#$%&'\(\)*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\\]^_`abcdefghijklmnopqrstuvwxyz{|}~) def - /barlen barcode length def % Length of the code - /sbs barlen 6 mul string def % sbs is 6 times length of barcode - /txt barlen array def + /ismnfont ismnfont cvlit def + /ismnsize ismnsize cvr def + /height height cvr def + /addongap addongap cvr def + ismnpos (unset) eq { + /ismnpos height 72 mul 3 add def + } { + /ismnpos ismnpos cvr def + } ifelse + + % Split off the addon + ismntxt ( ) search { + /ismntxt exch def + pop + /addon exch def + } { + pop + /addon () def + } ifelse - /mode -1 def % A=0, B=1, C=2 - /checksum barcode 1 3 getinterval cvi def % Initialise the checksum + % Convert old ISMN to ISMN-13 + /legacytxt () def + ismntxt 0 1 getinterval (M) eq ismntxt length 13 le and { + /legacytxt ismntxt def + /pad ismntxt length 4 add string def + pad 0 (979-0-) putinterval + pad 6 ismntxt 2 ismntxt length 2 sub getinterval putinterval + /ismntxt pad def + } if - /i 0 def /j 0 def + % Read the digits from ismntxt and calculate checksums + /ismn 13 string def + /checksum 0 def + /i 0 def /n 0 def { % loop - i barlen eq {exit} if - barcode i 1 getinterval (^) eq { - % indx is given by the next three characters - /indx barcode i 1 add 3 getinterval cvi def - txt j [( ) j 11 mul textyoffset textfont textsize] put - /i i 4 add def - } { - % indx depends on the mode - mode 2 eq { - /indx barcode i 2 getinterval cvi def - txt j [barcode i 2 getinterval j 11 mul textyoffset textfont textsize] put - /i i 2 add def - } { - barchars barcode i 1 getinterval search - pop % Discard true leaving pre - length /indx exch def % indx is the length of pre - pop pop % Discard seek and post - txt j [barchars indx 1 getinterval j 11 mul textyoffset textfont textsize] put - /i i 1 add def - } ifelse - } ifelse - /enc encs indx get def % Get the indxth encoding - sbs j 6 mul enc putinterval % Put encoded digit into sbs + /ismnchar ismntxt i get 48 sub def + ismnchar -3 ne { % Ignore dashes + ismn n ismnchar 48 add put + n 12 lt { + n 2 mod 0 eq { + /checksum ismnchar checksum add def + } { + /checksum ismnchar 3 mul checksum add def + } ifelse + } if + /n n 1 add def + } if + /i i 1 add def + i ismntxt length eq {exit} if + } loop + /checksum 10 checksum 10 mod sub 10 mod def - % Update the mode - indx 101 eq indx 103 eq or {/mode 0 def} if - indx 100 eq indx 104 eq or {/mode 1 def} if - indx 99 eq indx 105 eq or {/mode 2 def} if + % Add the ISMN header to the ismntxt + legacy legacytxt () ne and { + /ismntxt legacytxt def + /pad 18 string def + } { + /pad 22 string def + } ifelse + pad 0 (ISMN ) putinterval + pad 5 ismntxt putinterval % Add ismntxt to the pad - /checksum indx j mul checksum add def % checksum+=indx*j - /j j 1 add def - } loop + % Add checksum digit + pad pad length 2 sub 45 put % Put a dash + pad pad length 1 sub checksum 48 add put % Put check digit + /ismntxt pad def - % Put the checksum character - /checksum checksum 103 mod def - sbs j 6 mul encs checksum get putinterval + % Convert ISMN digits to EAN-13 + /barcode ismn 0 12 getinterval def - % Put the end character - sbs j 6 mul 6 add encs 106 get putinterval + % Append the addon + addon () ne { + 12 addon length add 1 add string + dup 0 barcode putinterval + dup 12 ( ) putinterval + dup 13 addon putinterval + /barcode exch def + } if - % Shrink sbs and txt to fit exactly - /sbs sbs 0 j 6 mul 13 add getinterval def - /txt txt 0 j getinterval def + % Get the result of encoding with ean13 + options (dontdraw) true put + options (addongap) addongap put + /args barcode options //ean13 exec def - % Return the arguments - << - /ren (renlinear) - /sbs [sbs {48 sub} forall] - /bhs [sbs length 1 add 2 idiv {height} repeat] - /bbs [sbs length 1 add 2 idiv {0} repeat] + % Add the ISMN text includetext { - /txt txt + ismntxt length 18 eq { + /ismnxpos -1 def + } { + /ismnxpos -12 def + } ifelse + args (txt) known { + /txt args (txt) get def + /newtxt txt length 1 add array def + newtxt 0 txt putinterval + newtxt newtxt length 1 sub [ismntxt ismnxpos ismnpos ismnfont ismnsize] put + args (txt) newtxt put + } { + args (txt) [ [ismntxt ismnxpos ismnpos ismnfont ismnsize] ] put + } ifelse } if - /opt options - >> + + args (opt) options put + args dontdraw not //renlinear if end - + } bind def -% --END ENCODER code128-- +/ismn dup load /uk.co.terryburton.bwipp defineresource pop +end +/setpacking where {pop setpacking} if +% --END ENCODER ismn-- -% --BEGIN ENCODER code39-- -% --DESC: Code 39 -% --EXAM: THIS IS CODE 39 -% --EXOP: includetext includecheck includecheckintext +% --BEGIN ENCODER issn-- +% --REQUIRES ean13-- +% --SUGGESTS ean2 ean5-- +% --DESC: ISSN +% --EXAM: 0317-8471 00 05 +% --EXOP: includetext guardwhitespace % --RNDR: renlinear -/code39 { +/setpacking where {pop currentpacking true setpacking} if +1 dict +dup /renlinear dup /uk.co.terryburton.bwipp findresource put +dup /ean13 dup /uk.co.terryburton.bwipp findresource put +begin +/issn { - 20 dict begin % Confine variables to local scope + 20 dict begin - /options exch def % We are given an option string - /barcode exch def % We are given a barcode string + /options exch def % We are given an options string + /issntxt exch def % We are given the issn text with dashes /dontdraw false def - /includecheck false def % Enable/disable checkdigit - /includetext false def - /includecheckintext false def - /hidestars false def - /textfont /Courier def - /textsize 10 def - /textyoffset -7 def + /includetext false def % Enable/disable ISSN text + /issnfont /Courier def + /issnsize 9 def + /issnpos (unset) def /height 1 def - + /addongap 12 def + % Parse the input options options type /stringtype eq { 1 dict begin @@ -1638,124 +1785,139 @@ currentdict end /options exch def } if options {def} forall - - /textfont textfont cvlit def - /textsize textsize cvr def - /textyoffset textyoffset cvr def - /height height cvr def - % Create an array containing the character mappings - /encs - [ (1113313111) (3113111131) (1133111131) (3133111111) (1113311131) - (3113311111) (1133311111) (1113113131) (3113113111) (1133113111) - (3111131131) (1131131131) (3131131111) (1111331131) (3111331111) - (1131331111) (1111133131) (3111133111) (1131133111) (1111333111) - (3111111331) (1131111331) (3131111311) (1111311331) (3111311311) - (1131311311) (1111113331) (3111113311) (1131113311) (1111313311) - (3311111131) (1331111131) (3331111111) (1311311131) (3311311111) - (1331311111) (1311113131) (3311113111) (1331113111) (1313131111) - (1313111311) (1311131311) (1113131311) (1311313111) - ] def - - % Create a string of the available characters - /barchars (0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ-. $/+%*) def - - /barlen barcode length def % Length of the code + /issnfont issnfont cvlit def + /issnsize issnsize cvr def + /height height cvr def + /addongap addongap cvr def + issnpos (unset) eq { + /issnpos height 72 mul 3 add def + } { + /issnpos issnpos cvr def + } ifelse + + % Split off the ISSN + issntxt ( ) search { + /issntxt exch def + pop + /seqvar exch def + } if - includecheck { - /sbs barlen 10 mul 30 add string def - /txt barlen 3 add array def + % Split off the sequence variant and 2 digit addon + seqvar ( ) search { + /seqvar exch def + pop + 2 string dup exch 0 4 -1 roll putinterval /addon exch def } { - /sbs barlen 10 mul 20 add string def - /txt barlen 2 add array def + pop + /addon () def } ifelse + % Read the digits from issntxt and calculate checksums + /issn 8 string def /checksum 0 def + /i 0 def /n 0 def + { % loop + /issnchar issntxt i get 48 sub def + issnchar -3 ne { % Ignore dashes + issn n issnchar 48 add put + n 7 lt { + /checksum checksum issnchar 8 n sub mul add def + } if + /n n 1 add def + } if + /i i 1 add def + i issntxt length eq {exit} if + } loop + /checksum 11 checksum 11 mod sub 11 mod def - % Put the start character - sbs 0 encs 43 get putinterval - hidestars not { - txt 0 [(*) 0 textyoffset textfont textsize] put - } { - txt 0 [() 0 textyoffset textfont textsize] put - } ifelse + % Add the ISSN header to the issntxt + /pad 14 string def + pad 0 (ISSN ) putinterval + pad 5 issntxt putinterval % Add issntxt to the pad - 0 1 barlen 1 sub { - /i exch def - % Lookup the encoding for the each barcode character - barcode i 1 getinterval barchars exch search - pop % Discard true leaving pre - length /indx exch def % indx is the length of pre - pop pop % Discard seek and post - /enc encs indx get def % Get the indxth encoding - sbs i 10 mul 10 add enc putinterval % Put encoded digit into sbs - txt i 1 add [barcode i 1 getinterval i 1 add 16 mul textyoffset textfont textsize] put - /checksum checksum indx add def - } for + % Add checksum digit + pad 13 checksum 48 add dup 58 eq {pop 88} if put % Put check digit + /issntxt pad def - % Put the checksum and end characters - includecheck { - /checksum checksum 43 mod def - sbs barlen 10 mul 10 add encs checksum get putinterval - includecheckintext { - txt barlen 1 add [barchars checksum 1 getinterval barlen 1 add 16 mul textyoffset textfont textsize] put + % Convert ISSN digits to EAN-13 + /barcode issn 0 7 getinterval def + + % Append the sequence variant + /barcode 12 string def + barcode 0 (977) putinterval + barcode 3 issn putinterval + barcode 10 seqvar putinterval + + % Append the addon + addon () ne { + 12 addon length add 1 add string + dup 0 barcode putinterval + dup 12 ( ) putinterval + dup 13 addon putinterval + /barcode exch def + } if + + % Get the result of encoding with ean13 + options (dontdraw) true put + options (addongap) addongap put + /args barcode options //ean13 exec def + + % Add the ISSN text + includetext { + /issnxpos 10 def + args (txt) known { + /txt args (txt) get def + /newtxt txt length 1 add array def + newtxt 0 txt putinterval + newtxt newtxt length 1 sub [issntxt issnxpos issnpos issnfont issnsize] put + args (txt) newtxt put } { - txt barlen 1 add [() barlen 1 add 16 mul textyoffset textfont textsize] put + args (txt) [ [issntxt issnxpos issnpos issnfont issnsize] ] put } ifelse - sbs barlen 10 mul 20 add encs 43 get putinterval - hidestars not { - txt barlen 2 add [(*) barlen 2 add 16 mul textyoffset textfont textsize] put - } { - txt barlen 2 add [() barlen 2 add 16 mul textyoffset textfont textsize] put - } ifelse - } { - sbs barlen 10 mul 10 add encs 43 get putinterval - hidestars not { - txt barlen 1 add [(*) barlen 1 add 16 mul textyoffset textfont textsize] put - } { - txt barlen 1 add [() barlen 1 add 16 mul textyoffset textfont textsize] put - } ifelse - } ifelse - - % Return the arguments - << - /ren (renlinear) - /sbs [sbs {48 sub} forall] - /bhs [sbs length 1 add 2 idiv {height} repeat] - /bbs [sbs length 1 add 2 idiv {0} repeat] - includetext { - /txt txt } if - /opt options - >> + + args (opt) options put + args dontdraw not //renlinear if end - + } bind def -% --END ENCODER code39-- +/issn dup load /uk.co.terryburton.bwipp defineresource pop +end +/setpacking where {pop setpacking} if +% --END ENCODER issn-- -% --BEGIN ENCODER code93-- -% --DESC: Code 93 -% --EXAM: THIS IS CODE 93 -% --EXOP: includetext includecheck +% --BEGIN ENCODER code128-- +% --DESC: Code 128 +% --EXAM: Count01234567^FNC2! +% --EXOP: includetext parsefnc % --RNDR: renlinear -/code93 { +/setpacking where {pop currentpacking true setpacking} if +1 dict +dup /renlinear dup /uk.co.terryburton.bwipp findresource put +begin +/code128 { - 20 dict begin % Confine variables to local scope + 20 dict begin % Confine variables to local scope - /options exch def % We are given an option string - /barcode exch def % We are given a barcode string + /options exch def % We are given an option string + /barcode exch def % We are given a barcode string /dontdraw false def - /includecheck false def % Enable/disable checkdigit - /includetext false def % Enable/disable text + /includetext false def % Enable/disable text /textfont /Courier def /textsize 10 def + /textxoffset 0 def /textyoffset -7 def /height 1 def - + /encoding (auto) def + /raw false def + /parse false def + /parsefnc false def + % Parse the input options options type /stringtype eq { 1 dict begin @@ -1766,231 +1928,382 @@ currentdict end /options exch def } if options {def} forall - + /textfont textfont cvlit def /textsize textsize cvr def + /textxoffset textxoffset cvr def /textyoffset textyoffset cvr def /height height cvr def - - /encs - [ (131112) (111213) (111312) (111411) (121113) - (121212) (121311) (111114) (131211) (141111) - (211113) (211212) (211311) (221112) (221211) - (231111) (112113) (112212) (112311) (122112) - (132111) (111123) (111222) (111321) (121122) - (131121) (212112) (212211) (211122) (211221) - (221121) (222111) (112122) (112221) (122121) - (123111) (121131) (311112) (311211) (321111) - (112131) (113121) (211131) (121221) (312111) - (311121) (122211) (111141) (1111411) - ] def - % Create a string of the available characters - /barchars (0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ-. $/+%) def + % Parse ordinals of the form ^NNN to ASCII + parse { + /msg barcode length string def + /j 0 def + barcode + { % loop + (^) search { + dup msg exch j exch putinterval + length j add 1 add /j exch def + pop + dup 0 3 getinterval cvi msg exch j 1 sub exch put + dup length 3 sub 3 exch getinterval + } { + dup msg exch j exch putinterval + length j add /j exch def + /barcode msg 0 j getinterval def + exit + } ifelse + } loop + } if - /barlen barcode length def % Length of the code - barcode { - (^) search false eq {pop exit} if - pop pop /barlen barlen 3 sub def - } loop + /barlen barcode length def - includecheck { - /sbs barlen 6 mul 25 add string def - } { - /sbs barlen 6 mul 13 add string def - } ifelse - /txt barlen array def - - % Put the start character - sbs 0 encs 47 get putinterval - - /checksum1 0 def /checksum2 0 def + % Special function characters + /sta -1 def /stb -2 def /stc -3 def + /swa -4 def /swb -5 def /swc -6 def + /fn1 -7 def /fn2 -8 def /fn3 -9 def + /fn4 -10 def /sft -11 def /stp -12 def + /lka -13 def /lkc -14 def % CC-A/B and CC-C linkage - /i 0 def /j 0 def - { % loop - j barlen eq {exit} if - barcode i 1 getinterval (^) eq { - % indx is given by the next three characters - /indx barcode i 1 add 3 getinterval cvi def - txt j [( ) j 9 mul 9 add textyoffset textfont textsize] put - /i i 4 add def - } { - barchars barcode i 1 getinterval search - pop % Discard true leaving pre - length /indx exch def % indx is the length of pre - pop pop % Discard seek and post - txt j [barchars indx 1 getinterval j 9 mul 9 add textyoffset textfont textsize] put - /i i 1 add def - } ifelse - /enc encs indx get def % Get the indxth encoding - sbs j 6 mul 6 add enc putinterval % Put encoded digit into sbs - /checksum1 checksum1 barlen j sub 1 sub 20 mod 1 add indx mul add def - /checksum2 checksum2 barlen j sub 15 mod 1 add indx mul add def - /j j 1 add def - } loop + % Character maps for each state + /charmaps [ + % A B C A B C A B C + [ 32 32 (00) ] [ (!) (!) (01) ] [ (") (") (02) ] % 0-2 + [ (#) (#) (03) ] [ ($) ($) (04) ] [ (%) (%) (05) ] % 3-5 + [ (&) (&) (06) ] [ (') (') (07) ] [ 40 40 (08) ] % 6-8 + [ 41 41 (09) ] [ (*) (*) (10) ] [ (+) (+) (11) ] % 9-11 + [ (,) (,) (12) ] [ (-) (-) (13) ] [ (.) (.) (14) ] % 12-14 + [ (/) (/) (15) ] [ (0) (0) (16) ] [ (1) (1) (17) ] % 15-17 + [ (2) (2) (18) ] [ (3) (3) (19) ] [ (4) (4) (20) ] % 18-20 + [ (5) (5) (21) ] [ (6) (6) (22) ] [ (7) (7) (23) ] % 21-23 + [ (8) (8) (24) ] [ (9) (9) (25) ] [ (:) (:) (26) ] % 24-26 + [ (;) (;) (27) ] [ (<) (<) (28) ] [ (=) (=) (29) ] % 27-29 + [ (>) (>) (30) ] [ (?) (?) (31) ] [ (@) (@) (32) ] % 30-32 + [ (A) (A) (33) ] [ (B) (B) (34) ] [ (C) (C) (35) ] % 33-35 + [ (D) (D) (36) ] [ (E) (E) (37) ] [ (F) (F) (38) ] % 36-38 + [ (G) (G) (39) ] [ (H) (H) (40) ] [ (I) (I) (41) ] % 39-41 + [ (J) (J) (42) ] [ (K) (K) (43) ] [ (L) (L) (44) ] % 42-44 + [ (M) (M) (45) ] [ (N) (N) (46) ] [ (O) (O) (47) ] % 45-47 + [ (P) (P) (48) ] [ (Q) (Q) (49) ] [ (R) (R) (50) ] % 48-50 + [ (S) (S) (51) ] [ (T) (T) (52) ] [ (U) (U) (53) ] % 51-53 + [ (V) (V) (54) ] [ (W) (W) (55) ] [ (X) (X) (56) ] % 54-56 + [ (Y) (Y) (57) ] [ (Z) (Z) (58) ] [ ([) ([) (59) ] % 57-59 + [ 92 92 (60) ] [ (]) (]) (61) ] [ (^) (^) (62) ] % 60-62 + [ (_) (_) (63) ] [ 0 (`) (64) ] [ 1 (a) (65) ] % 63-65 + [ 2 (b) (66) ] [ 3 (c) (67) ] [ 4 (d) (68) ] % 66-68 + [ 5 (e) (69) ] [ 6 (f) (70) ] [ 7 (g) (71) ] % 69-71 + [ 8 (h) (72) ] [ 9 (i) (73) ] [ 10 (j) (74) ] % 72-74 + [ 11 (k) (75) ] [ 12 (l) (76) ] [ 13 (m) (77) ] % 75-77 + [ 14 (n) (78) ] [ 15 (o) (79) ] [ 16 (p) (80) ] % 78-80 + [ 17 (q) (81) ] [ 18 (r) (82) ] [ 19 (s) (83) ] % 81-83 + [ 20 (t) (84) ] [ 21 (u) (85) ] [ 22 (v) (86) ] % 84-86 + [ 23 (w) (87) ] [ 24 (x) (88) ] [ 25 (y) (89) ] % 87-89 + [ 26 (z) (90) ] [ 27 ({) (91) ] [ 28 (|) (92) ] % 90-92 + [ 29 (}) (93) ] [ 30 (~) (94) ] [ 31 127 (95) ] % 93-95 + [ fn3 fn3 (96) ] [ fn2 fn2 (97) ] [ sft sft (98) ] % 96-98 + [ swc swc (99) ] [ swb fn4 swb ] [ fn4 swa swa ] % 99-101 + [ fn1 fn1 fn1 ] [ sta sta sta ] [ stb stb stb ] % 102-104 + [ stc stc stc ] [ stp stp stp ] % 105-106 + ] def - includecheck { - % Put the first checksum character - /checksum1 checksum1 47 mod def - /checksum2 checksum2 checksum1 add 47 mod def - sbs j 6 mul 6 add encs checksum1 get putinterval - sbs j 6 mul 12 add encs checksum2 get putinterval - % Put the end character - sbs j 6 mul 18 add encs 48 get putinterval - } { - % Put the end character - sbs j 6 mul 6 add encs 48 get putinterval - } ifelse - - % Return the arguments - << - /ren (renlinear) - /sbs [sbs {48 sub} forall] - /bhs [sbs length 1 add 2 idiv {height} repeat] - /bbs [sbs length 1 add 2 idiv {0} repeat] - includetext { - /txt txt - } if - /opt options - >> - - dontdraw not //renlinear if + % Invert charmaps to give character to value maps for each state + /charvals [ 109 dict 109 dict 109 dict ] def + 0 1 charmaps length 1 sub { + /i exch def + /encs charmaps i get def + 0 1 2 { + /j exch def + encs j get dup type /stringtype eq {0 get} if % convert string to ASCII if required + charvals j get exch i put + } for + } for + /seta charvals 0 get def + /setb charvals 1 get def + /setc charvals 2 get def - end + % Include pseudo characters for GS1-128 Composite linkage identifiers + seta lka seta swb get put seta lkc seta swc get put + setb lka setb swc get put setb lkc setb swa get put + setc lka setc swa get put setc lkc setc swb get put -} bind def -% --END ENCODER code93-- + raw {/encoding (raw) def} if -% --BEGIN ENCODER interleaved2of5-- -% --DESC: Interleaved 2 of 5 (ITF) -% --EXAM: 24012345678905 -% --EXOP: showborder borderwidth=4 borderleft=15 borderright=15 height=0.5 includecheck includetext includecheckintext textyoffset=-10 -% --RNDR: renlinear -/interleaved2of5 { + encoding (raw) eq { + /cws barlen array def + /i 0 def /j 0 def + { % loop + i barlen eq {exit} if + /cw barcode i 1 add 3 getinterval cvi def + cws j cw put + /i i 4 add def + /j j 1 add def + } loop + /cws cws 0 j getinterval def + /text () def + } if - 20 dict begin % Confine variables to local scope + encoding (auto) eq { - /options exch def % We are given an option string - /barcode exch def % We are given a barcode string + /fncvals << + (FNC1) fn1 + (FNC2) fn2 + (FNC3) fn3 + (FNC4) fn4 + (LNKA) lka + (LNKC) lkc + >> def - /dontdraw false def - /includecheck false def % Enable/disable checkdigit - /includetext false def % Enable/disable text - /includecheckintext false def - /textfont /Courier def - /textsize 10 def - /textyoffset -7 def - /height 1 def - - % Parse the input options - options type /stringtype eq { - 1 dict begin - options { - token false eq {exit} if dup length string cvs (=) search - true eq {cvlit exch pop exch def} {cvlit true def} ifelse + % Convert input into bytes accounting for FNC and LNK characters + /msg barlen array def + /text barlen string def + /i 0 def /j 0 def { + i barlen eq {exit} if + /char barcode i get def + text j char put + parsefnc char 94 eq and i barlen 4 sub lt and { + barcode i 1 add get 94 ne { + /char fncvals barcode i 1 add 4 getinterval get def + text j ( ) putinterval + /i i 4 add def + } { + /i i 1 add def + } ifelse + } if + msg j char put + /i i 1 add def + /j j 1 add def } loop - currentdict end /options exch def - } if - options {def} forall - - /textfont textfont cvlit def - /textsize textsize cvr def - /textyoffset textyoffset cvr def - /height height cvr def - - /barlen barcode length def % Length of the code + /msg msg 0 j getinterval def + /msglen msg length def + /text text 0 j getinterval def + + % Determine digit runlength and characters from given position + /numsscr { + /n 0 def /s 0 def + /p exch def { + p msglen ge {exit} if + msg p get + dup setc exch known not {pop exit} if + fn1 eq { + % FNC1 in odd position of run like two digits + s 2 mod 0 eq {/s s 1 add def} {exit} ifelse + } if + /n n 1 add def + /s s 1 add def + /p p 1 add def + } loop + n s + } bind def - % Prefix 0 to barcode if length is even and including checkdigit - % or length is odd and not including checkdigit - barlen 2 mod 0 eq includecheck and % even & includecheck - barlen 2 mod 0 ne includecheck not and or { % odd & !includecheck - /pad barlen 1 add string def % Create pad one bigger than barcode - pad 0 48 put % Put ascii 0 at start of pad - pad 1 barcode putinterval % Add barcode to the end of pad - /barcode pad def % barcode=pad - /barlen barlen 1 add def % barlen++ - } if + % Encoding for each alphabet + /enca { + seta exch get cws exch j exch put + /j j 1 add def + } bind def + /encb { + setb exch get cws exch j exch put + /j j 1 add def + } bind def + /encc { + dup type /arraytype ne { + setc exch get + } { + aload pop 48 sub exch 48 sub 10 mul add + } ifelse + cws exch j exch put + /j j 1 add def + } bind def - % Add checksum to end of barcode - includecheck { - /checksum 0 def - 0 1 barlen 1 sub { + % Character exclusively in either alphabet A or B + /anotb {dup seta exch known exch setb exch known not and} bind def + /bnota {dup setb exch known exch seta exch known not and} bind def + + % Pre-compute relative position of next anotb and next bnota characters + /nextanotb [ msg length {0} repeat 9999 ] def + /nextbnota [ msg length {0} repeat 9999 ] def + msg length 1 sub -1 0 { /i exch def - i 2 mod 0 eq { - /checksum checksum barcode i get 48 sub 3 mul add def + msg i get anotb { + nextanotb i 0 put } { - /checksum checksum barcode i get 48 sub add def + nextanotb i nextanotb i 1 add get 1 add put + } ifelse + msg i get bnota { + nextbnota i 0 put + } { + nextbnota i nextbnota i 1 add get 1 add put } ifelse } for - /checksum 10 checksum 10 mod sub 10 mod def - /pad barlen 1 add string def % Create pad one bigger than barcode - pad 0 barcode putinterval % Add barcode to the start of pad - pad barlen checksum 48 add put % Add checksum to end of pad - /barcode pad def % barcode=pad - /barlen barlen 1 add def % barlen++ - } if - - % Create an array containing the character mappings - /encs - [ (11331) (31113) (13113) (33111) (11313) - (31311) (13311) (11133) (31131) (13131) - (1111) (3111) - ] def - - % Create a string of the available characters - /barchars (0123456789) def - /sbs barlen 5 mul 8 add string def - /txt barlen array def - % Put the start character - sbs 0 encs 10 get putinterval + % Does a-only come before b-only after given position and vice versa + /abeforeb {dup nextanotb exch get exch nextbnota exch get lt} bind def + /bbeforea {dup nextbnota exch get exch nextanotb exch get lt} bind def + + /cws barcode length 2 mul 3 add array def - 0 2 barlen 1 sub { - /i exch def - % Lookup the encodings for two consecutive barcode characters - barcode i 1 getinterval barchars exch search - pop % Discard true leaving pre - length /indx exch def % indx is the length of pre - pop pop % Discard seek and post - /enca encs indx get def % Get the indxth encoding - - barcode i 1 add 1 getinterval barchars exch search - pop % Discard true leaving pre - length /indx exch def % indx is the length of pre - pop pop % Discard seek and post - /encb encs indx get def % Get the indxth encoding + % Select start character + /j 0 def + msglen 0 gt {0 numsscr} {-1 -1} ifelse /nums exch def /nchars exch def + { % common exit + msglen 0 eq { + stb enca + /cset (setb) def + exit + } if + msglen 2 eq nums 2 eq and { + stc enca + /cset (setc) def + exit + } if + nums 4 ge { + stc enca + /cset (setc) def + exit + } if + 0 abeforeb { + sta enca + /cset (seta) def + exit + } if + stb enca + /cset (setb) def + exit + } loop - % Interleave the two character encodings - /intl enca length 2 mul string def - 0 1 enca length 1 sub { - /j exch def - /achar enca j get def - /bchar encb j get def - intl j 2 mul achar put - intl j 2 mul 1 add bchar put - } for + % Main encoding loop + /i 0 def { + i msglen eq {exit} if + + i numsscr /nums exch def /nchars exch def + + % Determine switches and shifts + { % common exit + cset (seta) eq cset (setb) eq or nums 4 ge and + msg i get fn1 ne and { + nums 2 mod 0 eq { + swc cset (seta) eq {enca} {encb} ifelse + /cset (setc) def + exit + } { + msg i get cset (seta) eq {enca} {encb} ifelse + /i i 1 add def + swc cset (seta) eq {enca} {encb} ifelse + /cset (setc) def + exit + } ifelse + } if + cset (setb) eq msg i get anotb and { + i msglen 1 sub lt { + i 1 add bbeforea { + sft encb + msg i get enca + /i i 1 add def + exit + } if + } if + swa encb + /cset (seta) def + exit + } if + cset (seta) eq msg i get bnota and { + i msglen 1 sub lt { + i 1 add abeforeb { + sft enca + msg i get encb + /i i 1 add def + exit + } if + } if + swb enca + /cset (setb) def + exit + } if + cset (setc) eq nums 2 lt and { + i abeforeb { + swa encc + /cset (seta) def + exit + } if + swb encc + /cset (setb) def + exit + } if + + % No switches or latches so encode + cset (seta) eq { + msg i get enca + /i i 1 add def + exit + } if + cset (setb) eq { + msg i get encb + /i i 1 add def + exit + } if + cset (setc) eq { + msg i get fn1 eq { + fn1 encc + /i i 1 add def + } { + msg i 2 getinterval encc + /i i 2 add def + } ifelse + exit + } if + + exit + } loop + + } loop + /cws cws 0 j getinterval def + } if % auto encoding - sbs i 5 mul 4 add intl putinterval % Put encoded digit into sbs - txt i [barcode i 1 getinterval i 9 mul 4 add textyoffset textfont textsize] put - includecheck includecheckintext not and barlen 2 sub i eq and { - txt i 1 add [( ) i 1 add 9 mul 4 add textyoffset textfont textsize] put - } { - txt i 1 add [barcode i 1 add 1 getinterval i 1 add 9 mul 4 add textyoffset textfont textsize] put - } ifelse + % Derive checksum and place stop character + /cws j 2 add array dup 0 cws putinterval def + /csum cws 0 get def + 1 1 j 1 sub { + /i exch def + /csum csum cws i get i mul add def } for + /csum csum 103 mod def + cws j csum put + cws j 1 add seta stp get put - % Put the end character - sbs barlen 5 mul 4 add encs 11 get putinterval + % Create an array containing the character mappings + /encs + [ (212222) (222122) (222221) (121223) (121322) (131222) (122213) + (122312) (132212) (221213) (221312) (231212) (112232) (122132) + (122231) (113222) (123122) (123221) (223211) (221132) (221231) + (213212) (223112) (312131) (311222) (321122) (321221) (312212) + (322112) (322211) (212123) (212321) (232121) (111323) (131123) + (131321) (112313) (132113) (132311) (211313) (231113) (231311) + (112133) (112331) (132131) (113123) (113321) (133121) (313121) + (211331) (231131) (213113) (213311) (213131) (311123) (311321) + (331121) (312113) (312311) (332111) (314111) (221411) (431111) + (111224) (111422) (121124) (121421) (141122) (141221) (112214) + (112412) (122114) (122411) (142112) (142211) (241211) (221114) + (413111) (241112) (134111) (111242) (121142) (121241) (114212) + (124112) (124211) (411212) (421112) (421211) (212141) (214121) + (412121) (111143) (111341) (131141) (114113) (114311) (411113) + (411311) (113141) (114131) (311141) (411131) (211412) (211214) + (211232) (2331112) + ] def + + % Derive space bar succession + /sbs cws length 6 mul 1 add string def + 0 1 cws length 1 sub { + /i exch def + sbs i 6 mul encs cws i get get putinterval + } for % Return the arguments << - /ren (renlinear) + /ren //renlinear /sbs [sbs {48 sub} forall] /bhs [sbs length 1 add 2 idiv {height} repeat] /bbs [sbs length 1 add 2 idiv {0} repeat] - includetext { - /txt txt - } if + /txt [ [text textxoffset textyoffset textfont textsize] ] + /textxalign (center) /opt options >> @@ -1999,14 +2312,23 @@ end } bind def -% --END ENCODER interleaved2of5-- +/code128 dup load /uk.co.terryburton.bwipp defineresource pop +end +/setpacking where {pop setpacking} if +% --END ENCODER code128-- -% --BEGIN ENCODER rss14-- -% --DESC: GS1 DataBar Omnidirectional -% --EXAM: (01)24012345678905 -% --EXOP: -% --RNDR: renlinear renmatrix -/rss14 { +% --BEGIN ENCODER gs1-128-- +% --REQUIRES code128-- +% --DESC: GS1-128 +% --EXAM: (01)95012345678903(3103)000123 +% --EXOP: includetext +% --RNDR: renlinear +/setpacking where {pop currentpacking true setpacking} if +1 dict +dup /renlinear dup /uk.co.terryburton.bwipp findresource put +dup /code128 dup /uk.co.terryburton.bwipp findresource put +begin +/gs1-128 { 20 dict begin % Confine variables to local scope @@ -2014,10 +2336,15 @@ /barcode exch def % We are given a barcode string /dontdraw false def - /height 33 72 div def - /linkage false def - /format (omni) def - + /includetext false def % Enable/disable text + /textfont /Courier def + /textsize 10 def + /textxoffset 0 def + /textyoffset -7 def + /height 0.5 def + /linkagea false def + /linkagec false def + % Parse the input options options type /stringtype eq { 1 dict begin @@ -2028,396 +2355,328 @@ currentdict end /options exch def } if options {def} forall - - format (truncated) eq {/height 13 72 div def} if - /height height cvr def - % Strip the AI and optional check digit - barcode length dup 17 eq exch 18 eq or { - barcode 0 4 getinterval (\(01\)) eq { - /binval [ - linkage {1} {0} ifelse - barcode 4 13 getinterval {48 sub} forall - ] def - } if - } if + /textfont textfont cvlit def + /textsize textsize cvr def + /textxoffset textxoffset cvr def + /textyoffset textyoffset cvr def + /height height cvr def + + /text barcode def + + % Expand ordinals of the form ^NNN to ASCII + /expand { + /in exch def + /out in length string def + /j 0 def + in + { % loop + (^) search { + dup out exch j exch putinterval + length j add 1 add /j exch def + pop + dup 0 3 getinterval cvi out exch j 1 sub exch put + dup length 3 sub 3 exch getinterval + } { + dup out exch j exch putinterval + length j add /j exch def + out 0 j getinterval exit + } ifelse + } loop + } bind def + + % Parse out AIs + /ais [] def + /aival 2 dict def + barcode dup length 1 sub 1 exch getinterval + { % loop + dup () eq {exit} if + (\)) search pop + exch pop + exch (\() search { + exch pop exch 3 1 roll + } { + () 3 1 roll + } ifelse + [ ais aload pop counttomark 2 add index ] /ais exch def + aival 3 1 roll expand put + } loop + pop - % Calculate EAN checksum and add to end of barcode - /checksum 0 def - 0 1 12 { - /i exch def - /checksum checksum barcode i 4 add get 48 sub i 2 mod 0 eq {3 mul} if add def - } for - /checksum 10 checksum 10 mod sub 10 mod def - 18 string - dup 0 barcode 0 17 getinterval putinterval - dup 17 checksum 48 add put - /barcode exch def + % Pre-defined fixed length data field AIs + % any AI whose prefix is not included in this table must be + % terminated with "FNC1", even if it's fixed length + /aifixed 23 dict def + [ + 0 1 4 {} for + ] { + (00) 2 string copy dup dup 1 5 -1 roll 48 add put aifixed 3 1 roll put + } forall + [ + 11 1 20 {} for + 23 + 31 1 36 {} for + 41 + ] { + 10 2 string cvrs dup aifixed 3 1 roll put + } forall - % Create the human readable text - /txt barcode length array def - 0 1 barcode length 1 sub { + % Create the code128 data + /fnc1 -1 def + /c128 [ fnc1 ] def + 0 1 ais length 1 sub { /i exch def - txt i [barcode i 1 getinterval 0 0 () 0] put + /ai ais i get def + /val aival ai get def + c128 length ai length add val length add array + dup 0 c128 putinterval + dup c128 length ai [ exch {} forall ] putinterval + dup c128 length ai length add val [ exch {} forall ] putinterval + /c128 exch def + i ais length 1 sub ne aifixed ai 0 2 getinterval known not and { % Append FNC1 + c128 length 1 add array + dup 0 c128 putinterval + dup c128 length fnc1 put + /c128 exch def + } if } for - /ncr { % n r - 2 copy sub 2 copy lt {exch} if % n r maxd mind - 1 1 5 3 roll % mind j=1 v=1 n maxd - 1 add -1 exch { % mind j v n -1 maxd+1 - mul % mind j v*i - 1 index 3 index le { - 1 index idiv exch 1 add exch - } if - } for - { % mind j v - 1 index 3 index gt {exit} if - 1 index idiv exch 1 add exch - } loop - exch pop exch pop - } bind def - - /getRSSwidths { - /oe exch def - /el exch def - /mw exch def - /nm exch def - /val exch def - /out el array def - /mask 0 def - 0 1 el 2 sub { - /bar exch def - /ew 1 def - /mask mask 1 bar bitshift or def { - /sval nm ew sub 1 sub el bar sub 2 sub ncr def - oe mask 0 eq and nm ew sub el 2 mul sub bar 2 mul add -2 ge and { - /sval sval nm ew sub el sub bar add el bar sub 2 sub ncr sub def - } if - el bar sub 2 gt { - /lval 0 def - nm ew sub el sub bar add 2 add -1 mw 1 add { - nm exch sub ew sub 1 sub el bar sub 3 sub ncr - /lval exch lval add def - } for - /sval sval lval el bar sub 1 sub mul sub def - } { - nm ew sub mw gt {/sval sval 1 sub def} if - } ifelse - /val val sval sub def - val 0 lt {exit} if - /ew ew 1 add def - /mask mask 1 bar bitshift not and def - } loop - /val val sval add def - /nm nm ew sub def - out bar ew put - } for - out el 1 sub nm put - out - } bind def - - 0 1 12 { - /i exch def - binval i 1 add 2 copy get binval i get 4537077 mod 10 mul add put - binval i binval i get 4537077 idiv put - } for - /right binval 13 get 4537077 mod def - binval 13 2 copy get 4537077 idiv put - - /left 0 def - /i true def - 0 1 13 { - /j exch def - binval j get - dup 0 eq i and { - pop + % Compose input to code128 + /barcode c128 length 1 add 5 mul string def + /i 0 def /j 0 def { + i c128 length eq {exit} if + c128 i get dup fnc1 eq { + pop barcode j (^FNC1) putinterval + /j j 4 add def } { - /i false def - /left left 3 -1 roll 10 13 j sub exp cvi mul add def + barcode exch j exch put } ifelse - } for - - /d1 left 1597 idiv def - /d2 left 1597 mod def - /d3 right 1597 idiv def - /d4 right 1597 mod def + /i i 1 add def + /j j 1 add def + } loop + linkagea linkagec or { + barcode j linkagea {(^LNKA)} {(^LNKC)} ifelse putinterval + /j j 5 add def + } if + /barcode barcode 0 j getinterval def - /tab164 [ - 160 0 12 4 8 1 161 1 - 960 161 10 6 6 3 80 10 - 2014 961 8 8 4 5 31 34 - 2714 2015 6 10 3 6 10 70 - 2840 2715 4 12 1 8 1 126 - ] def + % Get the result of encoding with code128 + options (height) height put + options (dontdraw) true put + options (parsefnc) true put + /args barcode options //code128 exec def - /tab154 [ - 335 0 5 10 2 7 4 84 - 1035 336 7 8 4 5 20 35 - 1515 1036 9 6 6 3 48 10 - 1596 1516 11 4 8 1 81 1 - ] def + args (txt) [ [text textxoffset textyoffset textfont textsize] ] put + args (textxalign) (center) put + args (opt) options put + args + + dontdraw not //renlinear if + + end - /i 0 def { - d1 tab164 i get le { - tab164 i 1 add 7 getinterval {} forall - /d1te exch def /d1to exch def - /d1mwe exch def /d1mwo exch def - /d1ele exch def /d1elo exch def - /d1gs exch def - exit - } if - /i i 8 add def - } loop +} bind def +/gs1-128 dup load /uk.co.terryburton.bwipp defineresource pop +end +/setpacking where {pop setpacking} if +% --END ENCODER gs1-128-- + +% --BEGIN ENCODER ean14-- +% --REQUIRES code128-- +% --DESC: GS1-14 +% --EXAM: (01)04601234567893 +% --EXOP: includetext +% --RNDR: renlinear +/setpacking where {pop currentpacking true setpacking} if +1 dict +dup /renlinear dup /uk.co.terryburton.bwipp findresource put +dup /code128 dup /uk.co.terryburton.bwipp findresource put +begin +/ean14 { - /i 0 def { - d2 tab154 i get le { - tab154 i 1 add 7 getinterval {} forall - /d2te exch def /d2to exch def - /d2mwe exch def /d2mwo exch def - /d2ele exch def /d2elo exch def - /d2gs exch def - exit - } if - /i i 8 add def - } loop + 20 dict begin % Confine variables to local scope - /i 0 def { - d3 tab164 i get le { - tab164 i 1 add 7 getinterval {} forall - /d3te exch def /d3to exch def - /d3mwe exch def /d3mwo exch def - /d3ele exch def /d3elo exch def - /d3gs exch def - exit - } if - /i i 8 add def - } loop + /options exch def % We are given an option string + /barcode exch def % We are given a barcode string - /i 0 def { - d4 tab154 i get le { - tab154 i 1 add 7 getinterval {} forall - /d4te exch def /d4to exch def - /d4mwe exch def /d4mwo exch def - /d4ele exch def /d4elo exch def - /d4gs exch def - exit - } if - /i i 8 add def - } loop - - /d1wo d1 d1gs sub d1te idiv d1elo d1mwo 4 false getRSSwidths def - /d1we d1 d1gs sub d1te mod d1ele d1mwe 4 true getRSSwidths def - /d2wo d2 d2gs sub d2to mod d2elo d2mwo 4 true getRSSwidths def - /d2we d2 d2gs sub d2to idiv d2ele d2mwe 4 false getRSSwidths def - /d3wo d3 d3gs sub d3te idiv d3elo d3mwo 4 false getRSSwidths def - /d3we d3 d3gs sub d3te mod d3ele d3mwe 4 true getRSSwidths def - /d4wo d4 d4gs sub d4to mod d4elo d4mwo 4 true getRSSwidths def - /d4we d4 d4gs sub d4to idiv d4ele d4mwe 4 false getRSSwidths def + /dontdraw false def + /includetext false def % Enable/disable text + /textfont /Courier def + /textsize 10 def + /textxoffset 0 def + /textyoffset -7 def + /height 1 def + + % Parse the input options + options type /stringtype eq { + 1 dict begin + options { + token false eq {exit} if dup length string cvs (=) search + true eq {cvlit exch pop exch def} {cvlit true def} ifelse + } loop + currentdict end /options exch def + } if + options {def} forall - /d1w 8 array def - 0 1 3 { - /i exch def - d1w i 2 mul d1wo i get put - d1w i 2 mul 1 add d1we i get put - } for + /textfont textfont cvlit def + /textsize textsize cvr def + /textxoffset textxoffset cvr def + /textyoffset textyoffset cvr def + /height height cvr def - /d2w 8 array def - 0 1 3 { - /i exch def - d2w 7 i 2 mul sub d2wo i get put - d2w 6 i 2 mul sub d2we i get put - } for - - /d3w 8 array def - 0 1 3 { - /i exch def - d3w 7 i 2 mul sub d3wo i get put - d3w 6 i 2 mul sub d3we i get put - } for - - /d4w 8 array def - 0 1 3 { - /i exch def - d4w i 2 mul d4wo i get put - d4w i 2 mul 1 add d4we i get put - } for + % Calculate EAN checksum and add to end of barcode + barcode length dup 17 eq exch 18 eq or + barcode 0 4 getinterval (\(01\)) eq and { + /checksum 0 def + 0 1 12 { + /i exch def + /checksum checksum barcode i 4 add get 48 sub i 2 mod 0 eq {3 mul} if add def + } for + /checksum 10 checksum 10 mod sub 10 mod def + 18 string + dup 0 barcode 0 17 getinterval putinterval + dup 17 checksum 48 add put + /barcode exch def + /gtin barcode 4 14 getinterval def + } if - /widths [ - d1w {} forall - d2w {} forall - d3w {} forall - d4w {} forall - ] def - - /checkweights [ - 1 3 9 27 2 6 18 54 - 58 72 24 8 29 36 12 4 - 74 51 17 32 37 65 48 16 - 64 34 23 69 49 68 46 59 - ] def + % Compose input to code128 + /text barcode def + /barcode 21 string def + barcode 0 (^FNC101) putinterval + barcode 7 gtin putinterval - /checkwidths [ - 3 8 2 1 1 3 5 5 1 1 3 3 7 1 1 - 3 1 9 1 1 2 7 4 1 1 2 5 6 1 1 - 2 3 8 1 1 1 5 7 1 1 1 3 9 1 1 - ] def - - /checksum 0 def - 0 1 31 { - /i exch def - /checksum checksum widths i get checkweights i get mul add def - } for - /checksum checksum 79 mod def - checksum 8 ge {/checksum checksum 1 add def} if - checksum 72 ge {/checksum checksum 1 add def} if - /checklt checkwidths checksum 9 idiv 5 mul 5 getinterval def - /checkrtrev checkwidths checksum 9 mod 5 mul 5 getinterval def - /checkrt 5 array def - 0 1 4 { - /i exch def - checkrt i checkrtrev 4 i sub get put - } for + % Get the result of encoding with code128 + options (dontdraw) true put + options (parsefnc) true put + /args barcode options //code128 exec def - % Stacked format - format (omni) eq format (truncated) eq or { % linear + args (txt) [ [text textxoffset textyoffset textfont textsize] ] put + args (textxalign) (center) put + args (opt) options put + args + + dontdraw not //renlinear if + + end - /sbs [ - 1 d1w {} forall checklt {} forall d2w {} forall - d4w {} forall checkrt {} forall d3w {} forall 1 1 - ] def - - << - /ren (renlinear) - /sbs sbs - /bhs [sbs length 1 add 2 idiv {height} repeat] - /bbs [sbs length 1 add 2 idiv {0} repeat] - /txt txt - /textxalign (center) - /opt options - >> - - dontdraw not //renlinear if +} bind def +/ean14 dup load /uk.co.terryburton.bwipp defineresource pop +end +/setpacking where {pop setpacking} if +% --END ENCODER ean14-- + +% --BEGIN ENCODER sscc18-- +% --REQUIRES code128-- +% --DESC: SSCC-18 +% --EXAM: (00)006141411234567890 +% --EXOP: includetext +% --RNDR: renlinear +/setpacking where {pop currentpacking true setpacking} if +1 dict +dup /renlinear dup /uk.co.terryburton.bwipp findresource put +dup /code128 dup /uk.co.terryburton.bwipp findresource put +begin +/sscc18 { - } { % 2D - stacked or stackedomni + 20 dict begin % Confine variables to local scope - /top [ 1 1 d1w {} forall checklt {} forall d2w {} forall 1 1 0 ] def - /bot [ 1 1 d4w {} forall checkrt {} forall d3w {} forall 1 1 0 ] def - 0 2 24 { - /i exch def - top i get {0} repeat - top i 1 add get {1} repeat - } for - 50 array astore /top exch def - 0 2 24 { - /i exch def - bot i get {1} repeat - bot i 1 add get {0} repeat - } for - 50 array astore /bot exch def + /options exch def % We are given an option string + /barcode exch def % We are given a barcode string - % Stacked - format (stacked) eq { - /sep [ 50 {0} repeat ] def - 4 1 45 { - /i exch def - top i get bot i get eq { - sep i 1 top i get sub put - } { - sep i 1 sep i 1 sub get sub put - } ifelse - } for - /pixs [ - 5 {top aload pop} repeat - sep aload pop - 7 {bot aload pop} repeat - ] def - /pixy pixs length 50 idiv def - } if - - % Stacked omnidirectional - format (stackedomni) eq { - /sep1 [ top {1 exch sub} forall ] def - sep1 0 [ 0 0 0 0 ] putinterval - sep1 46 [ 0 0 0 0 ] putinterval - 18 1 30 { - /i exch def - top i get 0 eq { - top i 1 sub get 1 eq { - 1 - } { - sep1 i 1 sub get 0 eq {1} {0} ifelse - } ifelse - } { - 0 - } ifelse - sep1 exch i exch put - } for - /sep2 [ 0 0 0 0 21 { 0 1 } repeat 0 0 0 0 ] def - /sep3 [ bot {1 exch sub} forall ] def - sep3 0 [ 0 0 0 0 ] putinterval - sep3 46 [ 0 0 0 0 ] putinterval - 19 1 31 { - /i exch def - bot i get 0 eq { - bot i 1 sub get 1 eq { - 1 - } { - sep3 i 1 sub get 0 eq {1} {0} ifelse - } ifelse - } { - 0 - } ifelse - sep3 exch i exch put - } for - checksum 9 mod 3 eq { % Right shifted module for value 3 finder - sep3 19 [ 0 0 0 0 0 0 0 0 0 0 1 0 0 ] putinterval - } if - /pixs [ - 33 {top aload pop} repeat - sep1 aload pop - sep2 aload pop - sep3 aload pop - 33 {bot aload pop} repeat - ] def - /pixy pixs length 50 idiv def - } if - - % Return the arguments - << - /ren (renmatrix) - /pixs pixs - /pixx 50 - /pixy pixy - /height pixy 72 div - /width 50 72 div - /opt options - >> - - dontdraw not //renmatrix if - - } ifelse - + /dontdraw false def + /includetext false def % Enable/disable text + /textfont /Courier def + /textsize 10 def + /textxoffset 0 def + /textyoffset -7 def + /height 1 def + + % Parse the input options + options type /stringtype eq { + 1 dict begin + options { + token false eq {exit} if dup length string cvs (=) search + true eq {cvlit exch pop exch def} {cvlit true def} ifelse + } loop + currentdict end /options exch def + } if + options {def} forall + + /textfont textfont cvlit def + /textsize textsize cvr def + /textxoffset textxoffset cvr def + /textyoffset textyoffset cvr def + /height height cvr def + + % Calculate EAN checksum and add to end of barcode + barcode length dup 21 eq exch 22 eq or + barcode 0 4 getinterval (\(00\)) eq and { + /checksum 0 def + 0 1 16 { + /i exch def + /checksum checksum barcode i 4 add get 48 sub i 2 mod 0 eq {3 mul} if add def + } for + /checksum 10 checksum 10 mod sub 10 mod def + 22 string + dup 0 barcode 0 21 getinterval putinterval + dup 21 checksum 48 add put + /barcode exch def + /sscc barcode 4 18 getinterval def + } if + + % Compose input to code128 + /text barcode def + /barcode 25 string def + barcode 0 (^FNC100) putinterval + barcode 7 sscc putinterval + + % Get the result of encoding with code128 + options (dontdraw) true put + options (parsefnc) true put + /args barcode options //code128 exec def + + args (txt) [ [text textxoffset textyoffset textfont textsize] ] put + args (textxalign) (center) put + args (opt) options put + args + + dontdraw not //renlinear if + end } bind def -% --END ENCODER rss14-- +/sscc18 dup load /uk.co.terryburton.bwipp defineresource pop +end +/setpacking where {pop setpacking} if +% --END ENCODER sscc18-- -% --BEGIN ENCODER rsslimited-- -% --DESC: GS1 DataBar Limited -% --EXAM: (01)15012345678907 -% --EXOP: height=0.3 +% --BEGIN ENCODER code39-- +% --DESC: Code 39 +% --EXAM: THIS IS CODE 39 +% --EXOP: includetext includecheck includecheckintext % --RNDR: renlinear -/rsslimited { +/setpacking where {pop currentpacking true setpacking} if +1 dict +dup /renlinear dup /uk.co.terryburton.bwipp findresource put +begin +/code39 { - 20 dict begin % Confine variables to local scope + 20 dict begin % Confine variables to local scope - /options exch def % We are given an option string - /barcode exch def % We are given a barcode string + /options exch def % We are given an option string + /barcode exch def % We are given a barcode string /dontdraw false def - /height 10 72 div def - /linkage false def - + /includecheck false def % Enable/disable checkdigit + /includetext false def + /includecheckintext false def + /hidestars false def + /textfont /Courier def + /textsize 10 def + /textyoffset -7 def + /height 1 def + % Parse the input options options type /stringtype eq { 1 dict begin @@ -2428,228 +2687,94 @@ currentdict end /options exch def } if options {def} forall - + + /textfont textfont cvlit def + /textsize textsize cvr def + /textyoffset textyoffset cvr def /height height cvr def + + % Create an array containing the character mappings + /encs + [ (1113313111) (3113111131) (1133111131) (3133111111) (1113311131) + (3113311111) (1133311111) (1113113131) (3113113111) (1133113111) + (3111131131) (1131131131) (3131131111) (1111331131) (3111331111) + (1131331111) (1111133131) (3111133111) (1131133111) (1111333111) + (3111111331) (1131111331) (3131111311) (1111311331) (3111311311) + (1131311311) (1111113331) (3111113311) (1131113311) (1111313311) + (3311111131) (1331111131) (3331111111) (1311311131) (3311311111) + (1331311111) (1311113131) (3311113111) (1331113111) (1313131111) + (1313111311) (1311131311) (1113131311) (1311313111) + ] def - % Strip the AI and optional check digit - barcode length dup 17 eq exch 18 eq or { - barcode 0 5 getinterval dup (\(01\)0) eq exch (\(01\)1) eq or { - /binval [ - barcode 4 13 getinterval {48 sub} forall - ] def - linkage { - /linkval [ 2 0 1 5 1 3 3 5 3 1 0 9 6 ] def - 0 1 binval length 1 sub { - /i exch def - binval i binval i get linkval i get add put - } for - } if - } if - } if + % Create a string of the available characters + /barchars (0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ-. $/+%*) def + + /barlen barcode length def % Length of the code + + includecheck { + /sbs barlen 10 mul 30 add string def + /txt barlen 3 add array def + } { + /sbs barlen 10 mul 20 add string def + /txt barlen 2 add array def + } ifelse - % Calculate EAN checksum and add to end of barcode /checksum 0 def - 0 1 12 { - /i exch def - /checksum checksum barcode i 4 add get 48 sub i 2 mod 0 eq {3 mul} if add def - } for - /checksum 10 checksum 10 mod sub 10 mod def - 18 string - dup 0 barcode 0 17 getinterval putinterval - dup 17 checksum 48 add put - /barcode exch def - % Create the human readable text - /txt barcode length array def - 0 1 barcode length 1 sub { + % Put the start character + sbs 0 encs 43 get putinterval + hidestars not { + txt 0 [(*) 0 textyoffset textfont textsize] put + } { + txt 0 [() 0 textyoffset textfont textsize] put + } ifelse + + 0 1 barlen 1 sub { /i exch def - txt i [barcode i 1 getinterval 0 0 () 0] put + % Lookup the encoding for the each barcode character + barcode i 1 getinterval barchars exch search + pop % Discard true leaving pre + length /indx exch def % indx is the length of pre + pop pop % Discard seek and post + /enc encs indx get def % Get the indxth encoding + sbs i 10 mul 10 add enc putinterval % Put encoded digit into sbs + txt i 1 add [barcode i 1 getinterval i 1 add 16 mul textyoffset textfont textsize] put + /checksum checksum indx add def } for - /ncr { % n r - 2 copy sub 2 copy lt {exch} if % n r maxd mind - 1 1 5 3 roll % mind j=1 v=1 n maxd - 1 add -1 exch { % mind j v n -1 maxd+1 - mul % mind j v*i - 1 index 3 index le { - 1 index idiv exch 1 add exch - } if - } for - { % mind j v - 1 index 3 index gt {exit} if - 1 index idiv exch 1 add exch - } loop - exch pop exch pop - } bind def - - /getRSSwidths { - /oe exch def - /el exch def - /mw exch def - /nm exch def - /val exch def - /out el array def - /mask 0 def - 0 1 el 2 sub { - /bar exch def - /ew 1 def - /mask mask 1 bar bitshift or def { - /sval nm ew sub 1 sub el bar sub 2 sub ncr def - oe mask 0 eq and nm ew sub el 2 mul sub bar 2 mul add -2 ge and { - /sval sval nm ew sub el sub bar add el bar sub 2 sub ncr sub def - } if - el bar sub 2 gt { - /lval 0 def - nm ew sub el sub bar add 2 add -1 mw 1 add { - nm exch sub ew sub 1 sub el bar sub 3 sub ncr - /lval exch lval add def - } for - /sval sval lval el bar sub 1 sub mul sub def - } { - nm ew sub mw gt {/sval sval 1 sub def} if - } ifelse - /val val sval sub def - val 0 lt {exit} if - /ew ew 1 add def - /mask mask 1 bar bitshift not and def - } loop - /val val sval add def - /nm nm ew sub def - out bar ew put - } for - out el 1 sub nm put - out - } bind def - - 0 1 11 { - /i exch def - binval i 1 add 2 copy get binval i get 2013571 mod 10 mul add put - binval i binval i get 2013571 idiv put - } for - /d2 binval 12 get 2013571 mod def - binval 12 2 copy get 2013571 idiv put - - /d1 0 def - /i true def - 0 1 12 { - /j exch def - binval j get - dup 0 eq i and { - pop - } { - /i false def - /d1 d1 3 -1 roll 10 12 j sub exp cvi mul add def - } ifelse - } for - - /tab267 [ - 183063 0 17 9 6 3 6538 28 - 820063 183064 13 13 5 4 875 728 - 1000775 820064 9 17 3 6 28 6454 - 1491020 1000776 15 11 5 4 2415 203 - 1979844 1491021 11 15 4 5 203 2408 - 1996938 1979845 19 7 8 1 17094 1 - 2013570 1996939 7 19 1 8 1 16632 - ] def - - /i 0 def { - d1 tab267 i get le { - tab267 i 1 add 7 getinterval {} forall - /d1te exch def /d1to exch def - /d1mwe exch def /d1mwo exch def - /d1ele exch def /d1elo exch def - /d1gs exch def - exit - } if - /i i 8 add def - } loop - - /i 0 def { - d2 tab267 i get le { - tab267 i 1 add 7 getinterval {} forall - /d2te exch def /d2to exch def - /d2mwe exch def /d2mwo exch def - /d2ele exch def /d2elo exch def - /d2gs exch def - exit - } if - /i i 8 add def - } loop - - /d1wo d1 d1gs sub d1te idiv d1elo d1mwo 7 false getRSSwidths def - /d1we d1 d1gs sub d1te mod d1ele d1mwe 7 true getRSSwidths def - /d2wo d2 d2gs sub d2te idiv d2elo d2mwo 7 false getRSSwidths def - /d2we d2 d2gs sub d2te mod d2ele d2mwe 7 true getRSSwidths def - - /d1w 14 array def - 0 1 6 { - /i exch def - d1w i 2 mul d1wo i get put - d1w i 2 mul 1 add d1we i get put - } for - - /d2w 14 array def - 0 1 6 { - /i exch def - d2w i 2 mul d2wo i get put - d2w i 2 mul 1 add d2we i get put - } for - - /widths [ - d1w {} forall - d2w {} forall - ] def - - /checkweights [ - 1 3 9 27 81 65 17 51 64 14 42 37 22 66 - 20 60 2 6 18 54 73 41 34 13 39 28 84 74 - ] def - - /checkseq [ - 0 1 43 {} for - 45 52 57 - 63 1 66 {} for - 73 1 79 {} for - 82 - 126 1 130 {} for - 132 - 141 1 146 {} for - 210 1 217 {} for - 220 - 316 1 320 {} for - 322 323 - 326 337 - ] def - - /checksum 0 def - 0 1 27 { - /i exch def - /checksum checksum widths i get checkweights i get mul add def - } for - /checksum checksum 89 mod def - /seq checkseq checksum get def - /swidths seq 21 idiv 8 3 6 false getRSSwidths def - /bwidths seq 21 mod 8 3 6 false getRSSwidths def - - /checkwidths [0 0 0 0 0 0 0 0 0 0 0 0 1 1] def - 0 1 5 { - /i exch def - checkwidths i 2 mul swidths i get put - checkwidths i 2 mul 1 add bwidths i get put - } for - - /sbs [ - 1 d1w {} forall checkwidths {} forall d2w {} forall 1 1 - ] def + % Put the checksum and end characters + includecheck { + /checksum checksum 43 mod def + sbs barlen 10 mul 10 add encs checksum get putinterval + includecheckintext { + txt barlen 1 add [barchars checksum 1 getinterval barlen 1 add 16 mul textyoffset textfont textsize] put + } { + txt barlen 1 add [() barlen 1 add 16 mul textyoffset textfont textsize] put + } ifelse + sbs barlen 10 mul 20 add encs 43 get putinterval + hidestars not { + txt barlen 2 add [(*) barlen 2 add 16 mul textyoffset textfont textsize] put + } { + txt barlen 2 add [() barlen 2 add 16 mul textyoffset textfont textsize] put + } ifelse + } { + sbs barlen 10 mul 10 add encs 43 get putinterval + hidestars not { + txt barlen 1 add [(*) barlen 1 add 16 mul textyoffset textfont textsize] put + } { + txt barlen 1 add [() barlen 1 add 16 mul textyoffset textfont textsize] put + } ifelse + } ifelse % Return the arguments << - /ren (renlinear) - /sbs sbs + /ren //renlinear + /sbs [sbs {48 sub} forall] /bhs [sbs length 1 add 2 idiv {height} repeat] /bbs [sbs length 1 add 2 idiv {0} repeat] - /txt txt - /textxalign (center) + includetext { + /txt txt + } if /opt options >> @@ -2658,25 +2783,33 @@ end } bind def -% --END ENCODER rsslimited-- +/code39 dup load /uk.co.terryburton.bwipp defineresource pop +end +/setpacking where {pop setpacking} if +% --END ENCODER code39-- -% --BEGIN ENCODER rssexpanded-- -% --DESC: GS1 DataBar Expanded -% --EXAM: (01)95012345678903(3103)000123 -% --EXOP: segments=4 -% --RNDR: renlinear renmatrix -/rssexpanded { +% --BEGIN ENCODER code39ext-- +% --REQUIRES code39-- +% --DESC: Code 39 Extended +% --EXAM: Code39 Ext! +% --EXOP: includetext includecheck includecheckintext +% --RNDR: renlinear +/setpacking where {pop currentpacking true setpacking} if +1 dict +dup /renlinear dup /uk.co.terryburton.bwipp findresource put +dup /code39 dup /uk.co.terryburton.bwipp findresource put +begin +/code39ext { - 20 dict begin % Confine variables to local scope + 20 dict begin - /options exch def % We are given an option string - /barcode exch def % We are given a barcode string + /options exch def % We are given an options string + /barcode exch def % We are given the code39extended text /dontdraw false def - /height 34 72 div def - /segments 22 def - /linkage false def - + /includetext false def + /parse false def + % Parse the input options options type /stringtype eq { 1 dict begin @@ -2687,940 +2820,546 @@ currentdict end /options exch def } if options {def} forall - - /height height cvr def - /segments segments cvi def - - % Expand ordinals of the form ^NNN to ASCII - /expand { - /in exch def - /out in length string def + + % Parse ordinals of the form ^NNN to ASCII + parse { + /msg barcode length string def /j 0 def - in + barcode { % loop (^) search { - dup out exch j exch putinterval + dup msg exch j exch putinterval length j add 1 add /j exch def pop - dup 0 3 getinterval cvi out exch j 1 sub exch put + dup 0 3 getinterval cvi msg exch j 1 sub exch put dup length 3 sub 3 exch getinterval } { - dup out exch j exch putinterval + dup msg exch j exch putinterval length j add /j exch def - out 0 j getinterval exit + /barcode msg 0 j getinterval def + exit } ifelse } loop - } bind def - - % Parse out AIs - /ais [] def - /aival 2 dict def - barcode dup length 1 sub 1 exch getinterval - { % loop - dup () eq {exit} if - (\)) search pop - exch pop - exch (\() search { - exch pop exch 3 1 roll - } { - () 3 1 roll - } ifelse - [ ais aload pop counttomark 2 add index ] /ais exch def - aival 3 1 roll expand put - } loop - pop - - % Method selection - { % common exit - - % (01)9...(3103)... - ais length 2 eq { - ais 0 get (01) eq ais 1 get (3103) eq and { - aival (01) get 0 1 getinterval (9) eq aival (3103) get cvi 32767 le and { - (0100) false exit - } if - } if - } if - - % (01)9...(3202)... - ais length 2 eq { - ais 0 get (01) eq ais 1 get (3202) eq and { - aival (01) get 0 1 getinterval (9) eq aival (3202) get cvi 9999 le and { - (0101) false exit - } if - } if - } if - - % (01)9...(3203)... - ais length 2 eq { - ais 0 get (01) eq ais 1 get (3203) eq and { - aival (01) get 0 1 getinterval (9) eq aival (3203) get cvi 22767 le and { - (0101) false exit - } if - } if - } if - - % (01)9...(310x/320x)...[(11/13/15/17)...] - ais length dup 2 eq exch 3 eq or { - /ai310x false 3100 1 3109 {10 4 string cvrs ais 1 get eq or} for def - /ai320x false 3200 1 3209 {10 4 string cvrs ais 1 get eq or} for def - ais length 3 eq { - /aibad true [ (11) (13) (15) (17) ] {ais 2 get ne and} forall def - } { - /aibad false def - } ifelse - ais 0 get (01) eq ai310x ai320x or and aibad not and { - ais length 3 eq { - aival (01) get 0 1 getinterval (9) eq - aival ais 1 get get cvi 99999 le and - aival ais 2 get get cvi 999999 le and { - ai310x ais 2 get (11) eq and { (0111000) false exit } if - ai320x ais 2 get (11) eq and { (0111001) false exit } if - ai310x ais 2 get (13) eq and { (0111010) false exit } if - ai320x ais 2 get (13) eq and { (0111011) false exit } if - ai310x ais 2 get (15) eq and { (0111100) false exit } if - ai320x ais 2 get (15) eq and { (0111101) false exit } if - ai310x ais 2 get (17) eq and { (0111110) false exit } if - ai320x ais 2 get (17) eq and { (0111111) false exit } if - } if - } { - aival (01) get 0 1 getinterval (9) eq - aival ais 1 get get cvi 99999 le and { - ai310x { (0111000) false exit } if - ai320x { (0111001) false exit } if - } if - } ifelse - } if - } if - - % (01)9...(392x)... - ais length 2 ge { - /ai392x false 3920 1 3923 {10 4 string cvrs ais 1 get eq or} for def - ais 0 get (01) eq ai392x and { - aival (01) get 0 1 getinterval (9) eq { (01100) true exit } if - } if - } if - - % (01)9...(393x)... - ais length 2 ge { - /ai393x false 3930 1 3933 {10 4 string cvrs ais 1 get eq or} for def - ais 0 get (01) eq ai393x and { - aival (01) get 0 1 getinterval (9) eq { (01101) true exit } if - } if - } if - - % (01)... - ais 0 get (01) eq { (1) true exit } if - - % Freeform - (00) true exit - - } loop - /gpfallow exch def - /method exch def - - /conv12to40 { - (0000000000000000000000000000000000000000) 40 string copy - 2 copy 0 10 getinterval exch 0 3 getinterval cvi 2 10 string cvrs dup length 10 exch sub exch putinterval - 2 copy 10 10 getinterval exch 3 3 getinterval cvi 2 10 string cvrs dup length 10 exch sub exch putinterval - 2 copy 20 10 getinterval exch 6 3 getinterval cvi 2 10 string cvrs dup length 10 exch sub exch putinterval - 2 copy 30 10 getinterval exch 9 3 getinterval cvi 2 10 string cvrs dup length 10 exch sub exch putinterval - exch pop - } bind def - - /conv13to44 { - (00000000000000000000000000000000000000000000) 44 string copy - 2 copy 0 4 getinterval exch 0 1 getinterval cvi 2 4 string cvrs dup length 4 exch sub exch putinterval - dup 3 -1 roll 1 12 getinterval conv12to40 4 exch putinterval - } bind def - - /tobin { - string dup length 1 sub 0 exch 1 exch {1 index exch 48 put} for - dup 3 -1 roll 2 2 index length string cvrs dup length 2 index length exch sub exch putinterval - } bind def - - method (00) eq { - /cdf [] def - /gpf [] def - } if - - method (1) eq { - /cdf aival (01) get 0 13 getinterval conv13to44 def - /cdf [ cdf {48 sub} forall ] def - /gpf [] def - /ais ais 1 ais length 1 sub getinterval def - } if - - method (0100) eq { - /cdf 55 string def - cdf 0 aival (01) get 1 12 getinterval conv12to40 putinterval - cdf 40 aival (3103) get cvi 15 tobin putinterval - /cdf [ cdf {48 sub} forall ] def - /gpf [] def - /ais [] def - } if - - method (0101) eq { - /cdf 55 string def - cdf 0 aival (01) get 1 12 getinterval conv12to40 putinterval - ais 1 get (3202) eq { - aival (3202) get cvi 15 tobin - } { - aival (3203) get cvi 10000 add 15 tobin - } ifelse - cdf exch 40 exch putinterval - /cdf [ cdf {48 sub} forall ] def - /gpf [] def - /ais [] def } if - - method length 7 eq { - /cdf 76 string def - cdf 0 aival (01) get 1 12 getinterval conv12to40 putinterval - 6 string dup 0 ais 1 get 3 1 getinterval putinterval - dup aival ais 1 get get 1 5 getinterval 1 exch putinterval cvi 20 tobin - cdf exch 40 exch putinterval - ais length 3 eq { - aival ais 2 get get - dup 0 2 getinterval cvi 384 mul exch - dup 2 2 getinterval cvi 1 sub 32 mul exch - 4 2 getinterval cvi add add - } { - 38400 - } ifelse - 16 tobin cdf exch 60 exch putinterval - /cdf [ cdf {48 sub} forall ] def - /gpf [] def - /ais [] def + + /barlen barcode length def + + % Extended alphabet to non-extended alphabet + /extencs + [ (%U) ($A) ($B) ($C) ($D) ($E) ($F) ($G) ($H) ($I) ($J) ($K) ($L) ($M) ($N) ($O) + ($P) ($Q) ($R) ($S) ($T) ($U) ($V) ($W) ($X) ($Y) ($Z) (%A) (%B) (%C) (%D) (%E) + ( ) (/A) (/B) (/C) (/D) (/E) (/F) (/G) (/H) (/I) (/J) (/K) (/L) (-) (.) (/O) + (0) (1) (2) (3) (4) (5) (6) (7) (8) (9) (/Z) (%F) (%G) (%H) (%I) (%J) + (%V) (A) (B) (C) (D) (E) (F) (G) (H) (I) (J) (K) (L) (M) (N) (O) + (P) (Q) (R) (S) (T) (U) (V) (W) (X) (Y) (Z) (%K) (%L) (%M) (%N) (%O) + (%W) (+A) (+B) (+C) (+D) (+E) (+F) (+G) (+H) (+I) (+J) (+K) (+L) (+M) (+N) (+O) + (+P) (+Q) (+R) (+S) (+T) (+U) (+V) (+W) (+X) (+Y) (+Z) (%P) (%Q) (%R) (%S) (%T) + ] def + + /newcode barlen 2 mul string def + /newtext barlen 2 mul string def + /j 0 def + 0 1 barlen 1 sub { + /i exch def + /extchar extencs barcode i get get def + newcode j extchar putinterval + newtext j barcode i get put + extchar length 1 ne {newtext j 1 add ( ) putinterval} if + /j j extchar length add def + } for + /newcode newcode 0 j getinterval def + /newtext newtext 0 j getinterval def + + % Get the result of encoding with code39 + options (dontdraw) true put + /args newcode options //code39 exec def + + % Replace chars in /txt with chars in newtext + includetext { + /txt args (txt) get def + 0 1 newtext length 1 sub { + /i exch def + /txtentry txt i 1 add get def + txtentry 0 newtext i 1 getinterval put + txt i 1 add txtentry put + } for + args (txt) txt put } if - - method (01100) eq { - /cdf 42 string def - cdf 0 aival (01) get 1 12 getinterval conv12to40 putinterval - cdf 40 ais 1 get 3 1 getinterval cvi 2 tobin putinterval - /cdf [ cdf {48 sub} forall ] def - /gpf [ aival ais 1 get get {} forall ] def - /ais ais 2 ais length 2 sub getinterval def + args (opt) options put + args + + dontdraw not //renlinear if + + end + +} bind def +/code39ext dup load /uk.co.terryburton.bwipp defineresource pop +end +/setpacking where {pop setpacking} if +% --END ENCODER code39ext-- + +% --BEGIN ENCODER code32-- +% --REQUIRES code39-- +% --DESC: Italian PharmaCode +% --EXAM: 01234567 +% --EXOP: includetext +% --RNDR: renlinear +/setpacking where {pop currentpacking true setpacking} if +1 dict +dup /renlinear dup /uk.co.terryburton.bwipp findresource put +dup /code39 dup /uk.co.terryburton.bwipp findresource put +begin +/code32 { + + 20 dict begin + + /options exch def % We are given an options string + /barcode exch def % We are given a barcode string + + /dontdraw false def + /includetext false def % Enable/disable code32 text + /textfont /Courier def + /textsize 10 def + /textyoffset -7 def + /textxoffset 0 def + /height 1 def + + % Parse the input options + options type /stringtype eq { + 1 dict begin + options { + token false eq {exit} if dup length string cvs (=) search + true eq {cvlit exch pop exch def} {cvlit true def} ifelse + } loop + currentdict end /options exch def } if - - method (01101) eq { - /cdf 52 string def - cdf 0 aival (01) get 1 12 getinterval conv12to40 putinterval - cdf 40 ais 1 get 3 1 getinterval cvi 2 tobin putinterval - cdf 42 aival ais 1 get get 0 3 getinterval cvi 10 tobin putinterval - /cdf [ cdf {48 sub} forall ] def - /gpf [ aival ais 1 get get dup length 3 sub 3 exch getinterval {} forall ] def - /ais ais 2 ais length 2 sub getinterval def + options {def} forall + + /textfont textfont cvlit def + /textsize textsize cvr def + /textyoffset textyoffset cvr def + /height height cvr def + + /text 10 string def + text 0 barcode 0 8 getinterval putinterval + + % calculate check digit + text 8 0 + 0 1 7 { + dup text exch get 48 sub exch 1 and 1 add mul dup 9 gt {9 sub} if add + } for + 10 mod 48 add put + + % convert number from base10 to base32 + /val text cvi 32 barcode cvrs def + /barcode 6 string def + 0 1 5 {barcode exch 48 put} for + barcode 6 val length sub val putinterval + + % convert base32 number to specified character set + 0 1 5 { + dup barcode exch get + dup (AEIO) {ge {1 add} if dup} forall pop + barcode 3 1 roll put + } for + + % format HRI + text 1 text 0 9 getinterval putinterval + text 0 65 put + + % Get the result of encoding with code39 + options (dontdraw) true put + /args barcode options //code39 exec def + + args (txt) [ [text textxoffset textyoffset textfont textsize] ] put + args (textxalign) (center) put + args (opt) options put + args + + dontdraw not //renlinear if + + end + +} bind def +/code32 dup load /uk.co.terryburton.bwipp defineresource pop +end +/setpacking where {pop setpacking} if +% --END ENCODER code32-- + +% --BEGIN ENCODER pzn-- +% --REQUIRES code39-- +% --DESC: Pharmazentralnummer (PZN) +% --EXAM: 123456 +% --EXOP: includetext +% --RNDR: renlinear +/setpacking where {pop currentpacking true setpacking} if +1 dict +dup /renlinear dup /uk.co.terryburton.bwipp findresource put +dup /code39 dup /uk.co.terryburton.bwipp findresource put +begin +/pzn { + + 20 dict begin + + /options exch def % We are given an options string + /barcode exch def % We are given a barcode string + + /dontdraw false def + /includetext false def % Enable/disable code32 text + /textfont /Courier def + /textsize 10 def + /textyoffset -7 def + /textxoffset 0 def + /height 1 def + + % Parse the input options + options type /stringtype eq { + 1 dict begin + options { + token false eq {exit} if dup length string cvs (=) search + true eq {cvlit exch pop exch def} {cvlit true def} ifelse + } loop + currentdict end /options exch def } if + options {def} forall + + /textfont textfont cvlit def + /textsize textsize cvr def + /textyoffset textyoffset cvr def + /textxoffset textxoffset cvr def + /height height cvr def + + /text 13 string def + text 0 barcode 0 6 getinterval putinterval + + % calculate check digit + text 6 0 + 0 1 5 { + dup text exch get 48 sub exch 2 add mul add + } for + 11 mod 48 add put + + /barcode 8 string def + barcode 1 text 0 7 getinterval putinterval + barcode 0 45 put + + % Get the result of encoding with code39 + options (dontdraw) true put + /args barcode options //code39 exec def + + % format HRI + text 6 text 0 7 getinterval putinterval + text 0 (PZN - ) putinterval + + args (txt) [ [text textxoffset textyoffset textfont textsize] ] put + args (textxalign) (center) put + args (opt) options put + args + + dontdraw not //renlinear if + + end + +} bind def +/pzn dup load /uk.co.terryburton.bwipp defineresource pop +end +/setpacking where {pop setpacking} if +% --END ENCODER pzn-- + +% --BEGIN ENCODER code93-- +% --DESC: Code 93 +% --EXAM: THIS IS CODE 93 +% --EXOP: includetext includecheck +% --RNDR: renlinear +/setpacking where {pop currentpacking true setpacking} if +1 dict +dup /renlinear dup /uk.co.terryburton.bwipp findresource put +begin +/code93 { + + 20 dict begin % Confine variables to local scope + + /options exch def % We are given an option string + /barcode exch def % We are given a barcode string + + /dontdraw false def + /includecheck false def % Enable/disable checkdigit + /includetext false def % Enable/disable text + /textfont /Courier def + /textsize 10 def + /textyoffset -7 def + /height 1 def + /parsefnc false def + + % Parse the input options + options type /stringtype eq { + 1 dict begin + options { + token false eq {exit} if dup length string cvs (=) search + true eq {cvlit exch pop exch def} {cvlit true def} ifelse + } loop + currentdict end /options exch def + } if + options {def} forall + + /textfont textfont cvlit def + /textsize textsize cvr def + /textyoffset textyoffset cvr def + /height height cvr def - % Variable length symbol field - gpfallow { - /vlf 2 array def - } { - /vlf [] def - } ifelse - - % FNC1 terminated AIs - % TODO this list seems wrong - /aifnc1 100 dict def - [ - 10 - 21 22 - 240 241 242 - 250 251 253 254 - 30 37 - 3900 1 3909 {} for - 3910 1 3919 {} for - 3920 1 3929 {} for - 3930 1 3939 {} for - 400 401 402 403 - 420 421 422 423 424 425 426 - 7001 7002 7003 - 7030 1 7039 {} for - 8001 8002 8003 8004 8005 8006 8007 8008 - 8018 8020 - 8100 8101 8102 - 8110 - 90 1 99 {} for - ] { - 10 4 string cvrs dup aifnc1 3 1 roll put - } forall - - /fnc1 -1 def /lnumeric -2 def /lalpha -3 def /liso646 -4 def - - /numeric << - 0 1 119 { - dup (00) 2 string copy dup 3 -1 roll 11 2 string cvrs - dup length 2 exch sub exch putinterval - dup 0 get 65 eq {dup 0 94 put} if - dup 1 get 65 eq {dup 1 94 put} if - exch 8 add - (0000000) 7 string copy dup 3 -1 roll 2 7 string cvrs - dup length 7 exch sub exch putinterval - } for - lalpha (0000) - >> def - - /alpha << - 48 1 57 {dup 43 sub 5 tobin} for - fnc1 (01111) - 65 1 90 {dup 33 sub 6 tobin} for - 42 (111010) - 44 1 47 {dup 15 add 6 tobin} for - lnumeric (000) - liso646 (00100) - >> def - - /iso646 << - 48 1 57 {dup 43 sub 5 tobin} for - fnc1 (01111) - 65 1 90 {dup 1 sub 7 tobin} for - 97 1 122 {dup 7 sub 7 tobin} for - 33 (11101000) - 34 (11101001) - 37 1 47 {dup 197 add 8 tobin} for - 58 1 63 {dup 187 add 8 tobin} for - 95 (11111011) - 32 (11111100) - lnumeric (000) - lalpha (00100) + /encs + [ (131112) (111213) (111312) (111411) (121113) + (121212) (121311) (111114) (131211) (141111) + (211113) (211212) (211311) (221112) (221211) + (231111) (112113) (112212) (112311) (122112) + (132111) (111123) (111222) (111321) (121122) + (131121) (212112) (212211) (211122) (211221) + (221121) (222111) (112122) (112221) (122121) + (123111) (121131) (311112) (311211) (321111) + (112131) (113121) (211131) (121221) (312111) + (311121) (122211) (111141) (1111411) + ] def + + % Create a string of the available characters + /barchars (0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ-. $/+%) def + + /barlen barcode length def + + % Special function characters + /sft1 -1 def /sft2 -2 def /sft3 -3 def /sft4 -4 def + /fncvals << + (SFT$) sft1 + (SFT%) sft2 + (SFT/) sft3 + (SFT+) sft4 >> def - - % Append the remaining AI data - 0 1 ais length 1 sub { - /i exch def - /ai ais i get def - /val aival ai get def - gpf length ai length add val length add array - dup 0 gpf putinterval - dup gpf length ai [ exch {} forall ] putinterval - dup gpf length ai length add val [ exch {} forall ] putinterval - /gpf exch def - i ais length 1 sub ne aifnc1 ai known and { % Append FNC1 - gpf length 1 add array - dup 0 gpf putinterval - dup gpf length fnc1 put - /gpf exch def + + % Convert input into bytes accounting for shift characters + /msg barlen array def + /i 0 def /j 0 def { + i barlen eq {exit} if + /char barcode i get def + parsefnc char 94 eq and i barlen 4 sub lt and { + barcode i 1 add get 94 ne { + /char fncvals barcode i 1 add 4 getinterval get def + /i i 4 add def + } { + /i i 1 add def + } ifelse } if - } for - - % Calculate the number of bits remaining to the next valid symbol size - /rembits { - dup - 12 div ceiling cvi 12 mul % Round up to multiple of 12 - 48 2 copy lt {exch} if pop % At least 4 symbols - dup 12 idiv dup segments mod 1 eq { % At least 2 symbols on last row of stacked symbol - 1 add 12 mul exch pop - } { - pop - } ifelse - exch sub - } bind def + msg j char put + /i i 1 add def + /j j 1 add def + } loop + /msg msg 0 j getinterval def + /msglen msg length def + + includecheck { + /sbs msglen 6 mul 25 add string def + } { + /sbs msglen 6 mul 13 add string def + } ifelse + /txt msglen array def + + % Put the start character + sbs 0 encs 47 get putinterval - /encode { - dup /raw ne {exch get} {pop} ifelse - [ exch {48 sub} forall ] - dup length exch - gpfenc exch j exch putinterval - /j exch j add def - } bind def - - % Pre-compute alpha and numeric runlengths and position of next ISO646-only characters - /numericruns [ gpf length {0} repeat 0 -1 ] def - /alpharuns [ gpf length {0} repeat 0 ] def - /nextiso646only [ gpf length {0} repeat 9999 ] def - gpf length 1 sub -1 0 { + /checksum1 0 def /checksum2 0 def + 0 1 msglen 1 sub { /i exch def - gpf i get - (00) 2 string copy - dup 0 gpf i get dup fnc1 eq {pop 94} if put - i gpf length 1 sub lt {dup 1 gpf i 1 add get dup fnc1 eq {pop 94} if put} if - numeric exch known { - numericruns i numericruns i 2 add get 2 add put - } { - numericruns i 0 put - } ifelse - dup alpha exch known { - alpharuns i alpharuns i 1 add get 1 add put - } { - alpharuns i 0 put - } ifelse - dup iso646 exch known exch alpha exch known not and { - nextiso646only i 0 put + % Lookup the encoding for the each barcode character + msg i get dup 0 lt { + 42 exch sub /indx exch def + /char ( ) def } { - nextiso646only i nextiso646only i 1 add get 1 add put + 1 string dup 0 4 -1 roll put /char exch def + barchars char search + pop % Discard true leaving pre + length /indx exch def % indx is the length of pre + pop pop % Discard seek and post } ifelse + /enc encs indx get def % Get the indxth encoding + sbs i 6 mul 6 add enc putinterval % Put encoded digit into sbs + txt i [char i 9 mul 9 add textyoffset textfont textsize] put + /checksum1 checksum1 msglen i sub 1 sub 20 mod 1 add indx mul add def + /checksum2 checksum2 msglen i sub 15 mod 1 add indx mul add def } for - - % Encode the general purpose field - /gpfenc 252 array def - /i 0 def /j 0 def /mode (numeric) def - { % loop - i gpf length eq {exit} if - { % not a loop but common exit point - - mode (numeric) eq { - i gpf length 2 sub lt { - 2 string - dup 0 gpf i get dup fnc1 eq {pop 94} if put - dup 1 gpf i 1 add get dup fnc1 eq {pop 94} if put - dup numeric exch known { - numeric encode - /i i 2 add def - exit - } if - pop - lalpha numeric encode - /mode (alpha) def - exit - } { - gpf i get dup 48 lt exch 57 gt or { - lalpha numeric encode - /mode (alpha) def - exit - } if - 12 1 add method length add vlf length add cdf length add j add rembits - dup 4 ge exch 6 le and { % C1 + 1 into 4 bits - (0000) 4 string copy dup gpf i get 47 sub 2 4 string cvrs - dup length 4 exch sub exch putinterval /raw encode - /i i 1 add def - exit - } { % C1.FNC1 - 2 string dup 0 gpf i get put dup 1 94 put numeric encode - /i i 1 add def - exit - } ifelse - } ifelse - } if - - mode (alpha) eq { - gpf i get fnc1 eq { - fnc1 alpha encode - /i i 1 add def - exit - } if - gpf i get dup iso646 exch known exch alpha exch known not and { - liso646 alpha encode - /mode (iso646) def - exit - } if - numericruns i get 6 ge { - lnumeric alpha encode - /mode (numeric) def - exit - } if - numericruns i get dup 4 ge exch i add gpf length eq and { - lnumeric alpha encode - /mode (numeric) def - exit - } if - gpf i get alpha encode - /i i 1 add def - exit - } if - - mode (iso646) eq { - gpf i get fnc1 eq { - fnc1 iso646 encode - /i i 1 add def - exit - } if - numericruns i get 4 ge nextiso646only i get 10 ge and { - lnumeric iso646 encode - /mode (numeric) def - exit - } if - alpharuns i get 5 ge nextiso646only i get 10 ge and { - lalpha iso646 encode - /mode (alpha) def - exit - } if - gpf i get iso646 encode - /i i 1 add def - exit - } if - - } loop - } loop - /gpf gpfenc 0 j getinterval def - - % Complete the variable length field and create pad - 1 12 add method length add vlf length add cdf length add gpf length add - dup rembits dup array /pad exch def - vlf length 0 ne { - add 12 idiv - dup 2 mod vlf exch 0 exch put - 14 le {0} {1} ifelse vlf exch 1 exch put + + includecheck { + % Put the first checksum character + /checksum1 checksum1 47 mod def + /checksum2 checksum2 checksum1 add 47 mod def + sbs msglen 6 mul 6 add encs checksum1 get putinterval + sbs msglen 6 mul 12 add encs checksum2 get putinterval + % Put the end character + sbs msglen 6 mul 18 add encs 48 get putinterval } { - pop pop + % Put the end character + sbs msglen 6 mul 6 add encs 48 get putinterval } ifelse - pad length 0 gt { - 0 5 pad length 1 sub { % Fill with 00100 - /i exch def - pad i [ 0 0 1 0 0 ] 0 pad length i sub 5 2 copy gt {exch} if pop getinterval putinterval - } for - mode (numeric) eq { % Prefix shift from numeric to ASCII - /pad [ 0 0 0 0 pad aload pop ] 0 pad length getinterval def - } if - } if - - % Concatinate fields - /binval [ - linkage {1} {0} ifelse - method {48 sub} forall - vlf aload pop - cdf aload pop - gpf aload pop - pad aload pop - ] def - /datalen binval length 12 idiv def - - /ncr { % n r - 2 copy sub 2 copy lt {exch} if % n r maxd mind - 1 1 5 3 roll % mind j=1 v=1 n maxd - 1 add -1 exch { % mind j v n -1 maxd+1 - mul % mind j v*i - 1 index 3 index le { - 1 index idiv exch 1 add exch - } if - } for - { % mind j v - 1 index 3 index gt {exit} if - 1 index idiv exch 1 add exch - } loop - exch pop exch pop - } bind def - - /getRSSwidths { - /oe exch def - /el exch def - /mw exch def - /nm exch def - /val exch def - /out el array def - /mask 0 def - 0 1 el 2 sub { - /bar exch def - /ew 1 def - /mask mask 1 bar bitshift or def { - /sval nm ew sub 1 sub el bar sub 2 sub ncr def - oe mask 0 eq and nm ew sub el 2 mul sub bar 2 mul add -2 ge and { - /sval sval nm ew sub el sub bar add el bar sub 2 sub ncr sub def - } if - el bar sub 2 gt { - /lval 0 def - nm ew sub el sub bar add 2 add -1 mw 1 add { - nm exch sub ew sub 1 sub el bar sub 3 sub ncr - /lval exch lval add def - } for - /sval sval lval el bar sub 1 sub mul sub def - } { - nm ew sub mw gt {/sval sval 1 sub def} if - } ifelse - /val val sval sub def - val 0 lt {exit} if - /ew ew 1 add def - /mask mask 1 bar bitshift not and def - } loop - /val val sval add def - /nm nm ew sub def - out bar ew put - } for - out el 1 sub nm put - out - } bind def - /tab174 [ - 347 0 12 5 7 2 87 4 - 1387 348 10 7 5 4 52 20 - 2947 1388 8 9 4 5 30 52 - 3987 2948 6 11 3 6 10 104 - 4191 3988 4 13 1 8 1 204 - ] def + % Return the arguments + << + /ren //renlinear + /sbs [sbs {48 sub} forall] + /bhs [sbs length 1 add 2 idiv {height} repeat] + /bbs [sbs length 1 add 2 idiv {0} repeat] + includetext { + /txt txt + } if + /opt options + >> - /dxw datalen array def - - 0 1 datalen 1 sub { + dontdraw not //renlinear if - /x exch def + end - /d binval x 12 mul 12 getinterval def - /d 0 0 1 11 {/j exch def 2 11 j sub exp cvi d j get mul add} for def +} bind def +/code93 dup load /uk.co.terryburton.bwipp defineresource pop +end +/setpacking where {pop setpacking} if +% --END ENCODER code93-- - /j 0 def { - d tab174 j get le { - tab174 j 1 add 7 getinterval {} forall - /dte exch def /dto exch def - /dmwe exch def /dmwo exch def - /dele exch def /delo exch def - /dgs exch def - exit - } if - /j j 8 add def - } loop +% --BEGIN ENCODER code93ext-- +% --REQUIRES code93-- +% --DESC: Code 93 Extended +% --EXAM: Code93 Ext! +% --EXOP: includetext includecheck +% --RNDR: renlinear +/setpacking where {pop currentpacking true setpacking} if +1 dict +dup /renlinear dup /uk.co.terryburton.bwipp findresource put +dup /code93 dup /uk.co.terryburton.bwipp findresource put +begin +/code93ext { - /dwo d dgs sub dte idiv delo dmwo 4 true getRSSwidths def - /dwe d dgs sub dte mod dele dmwe 4 false getRSSwidths def + 20 dict begin - /dw 8 array def - x 2 mod 0 eq { - 0 1 3 { - /j exch def - dw 7 j 2 mul sub dwo j get put - dw 6 j 2 mul sub dwe j get put - } for - } { - 0 1 3 { - /j exch def - dw j 2 mul dwo j get put - dw j 2 mul 1 add dwe j get put - } for - } ifelse + /options exch def % We are given an options string + /barcode exch def % We are given the code39extended text - dxw x dw put + /dontdraw false def + /includetext false def + /parse false def - } for - - /finderwidths [ - 1 8 4 1 1 1 1 4 8 1 - 3 6 4 1 1 1 1 4 6 3 - 3 4 6 1 1 1 1 6 4 3 - 3 2 8 1 1 1 1 8 2 3 - 2 6 5 1 1 1 1 5 6 2 - 2 2 9 1 1 1 1 9 2 2 - ] def + % Parse the input options + options type /stringtype eq { + 1 dict begin + options { + token false eq {exit} if dup length string cvs (=) search + true eq {cvlit exch pop exch def} {cvlit true def} ifelse + } loop + currentdict end /options exch def + } if + options {def} forall - /finderseq [ - [0 1] - [0 3 2] - [0 5 2 7] - [0 9 2 7 4] - [0 9 2 7 6 11] - [0 9 2 7 8 11 10] - [0 1 2 3 4 5 6 7] - [0 1 2 3 4 5 6 9 8] - [0 1 2 3 4 5 6 9 10 11] - [0 1 2 3 4 7 6 9 8 11 10] - ] def + % Parse ordinals of the form ^NNN to ASCII + parse { + /msg barcode length string def + /j 0 def + barcode + { % loop + (^) search { + dup msg exch j exch putinterval + length j add 1 add /j exch def + pop + dup 0 3 getinterval cvi msg exch j 1 sub exch put + dup length 3 sub 3 exch getinterval + } { + dup msg exch j exch putinterval + length j add /j exch def + /barcode msg 0 j getinterval def + exit + } ifelse + } loop + } if - /seq finderseq datalen 2 sub 2 idiv get def - /fxw seq length array def - 0 1 seq length 1 sub { - /x exch def - fxw x finderwidths seq x get 5 mul 5 getinterval put - } for + /barlen barcode length def - /checkweights [ - -1 -1 -1 -1 -1 -1 -1 -1 % A1L - 77 96 32 81 27 9 3 1 % A1R - 20 60 180 118 143 7 21 63 % A2L - 205 209 140 117 39 13 145 189 % A2R - 193 157 49 147 19 57 171 91 % B1L - 132 44 85 169 197 136 186 62 % B1R - 185 133 188 142 4 12 36 108 % B2L - 50 87 29 80 97 173 128 113 % B2R - 150 28 84 41 123 158 52 156 % C1L - 166 196 206 139 187 203 138 46 % C1R - 76 17 51 153 37 111 122 155 % C2L - 146 119 110 107 106 176 129 43 % C2R - 16 48 144 10 30 90 59 177 % D1L - 164 125 112 178 200 137 116 109 % D1R - 70 210 208 202 184 130 179 115 % D2L - 190 204 68 93 31 151 191 134 % D2R - 148 22 66 198 172 94 71 2 % E1L - 40 154 192 64 162 54 18 6 % E1R - 120 149 25 75 14 42 126 167 % E2L - 175 199 207 69 23 78 26 79 % E2R - 103 98 83 38 114 131 182 124 % F1L - 159 53 88 170 127 183 61 161 % F1R - 55 165 73 8 24 72 5 15 % F2L - 89 100 174 58 160 194 135 45 % F2R + % Extended alphabet to non-extended alphabet + /extencs + [ (^SFT%U) (^SFT$A) (^SFT$B) (^SFT$C) (^SFT$D) (^SFT$E) (^SFT$F) (^SFT$G) + (^SFT$H) (^SFT$I) (^SFT$J) (^SFT$K) (^SFT$L) (^SFT$M) (^SFT$N) (^SFT$O) + (^SFT$P) (^SFT$Q) (^SFT$R) (^SFT$S) (^SFT$T) (^SFT$U) (^SFT$V) (^SFT$W) + (^SFT$X) (^SFT$Y) (^SFT$Z) (^SFT%A) (^SFT%B) (^SFT%C) (^SFT%D) (^SFT%E) + ( ) (^SFT/A) (^SFT/B) (^SFT/C) (^SFT/D) (^SFT/E) (^SFT/F) (^SFT/G) + (^SFT/H) (^SFT/I) (^SFT/J) (^SFT/K) (^SFT/L) (-) (.) (^SFT/O) + (0) (1) (2) (3) (4) (5) (6) (7) + (8) (9) (^SFT/Z) (^SFT%F) (^SFT%G) (^SFT%H) (^SFT%I) (^SFT%J) + (^SFT%V) (A) (B) (C) (D) (E) (F) (G) + (H) (I) (J) (K) (L) (M) (N) (O) + (P) (Q) (R) (S) (T) (U) (V) (W) + (X) (Y) (Z) (^SFT%K) (^SFT%L) (^SFT%M) (^SFT%N) (^SFT%O) + (^SFT%W) (^SFT+A) (^SFT+B) (^SFT+C) (^SFT+D) (^SFT+E) (^SFT+F) (^SFT+G) + (^SFT+H) (^SFT+I) (^SFT+J) (^SFT+K) (^SFT+L) (^SFT+M) (^SFT+N) (^SFT+O) + (^SFT+P) (^SFT+Q) (^SFT+R) (^SFT+S) (^SFT+T) (^SFT+U) (^SFT+V) (^SFT+W) + (^SFT+X) (^SFT+Y) (^SFT+Z) (^SFT%P) (^SFT%Q) (^SFT%R) (^SFT%S) (^SFT%T) ] def - /checkweightseq [ - seq {16 mul checkweights exch 16 getinterval aload pop} forall - ] dup length 8 sub 8 exch getinterval def - - /widths [ - dxw {{} forall} forall - ] def - - /checksum 0 def - 0 1 widths length 1 sub { + /newcode barlen 6 mul string def + /newtext barlen 6 mul string def + /j 0 def /k 0 def + 0 1 barlen 1 sub { /i exch def - /checksum checksum widths i get checkweightseq i get mul add def + /extchar extencs barcode i get get def + /extlen extchar length def + newcode j extchar putinterval + newtext k barcode i get put + extlen 1 ne {newtext k 1 add ( ) putinterval} if + /j j extlen add def + /k k extlen 1 eq {1} {2} ifelse add def } for - /checksum checksum 211 mod datalen 3 sub 211 mul add def + /newcode newcode 0 j getinterval def + /newtext newtext 0 k getinterval def - /i 0 def { - checksum tab174 i get le { - tab174 i 1 add 7 getinterval {} forall - /cte exch def /cto exch def - /cmwe exch def /cmwo exch def - /cele exch def /celo exch def - /cgs exch def - exit - } if - /i i 8 add def - } loop - - /cwo checksum cgs sub cte idiv celo cmwo 4 true getRSSwidths def - /cwe checksum cgs sub cte mod cele cmwe 4 false getRSSwidths def - - /cw 8 array def - 0 1 3 { - /i exch def - cw i 2 mul cwo i get put - cw i 2 mul 1 add cwe i get put - } for - - 22 array dup dup - 0 cw put 1 dxw putinterval 0 datalen 1 add getinterval - /dxw exch def - /datalen dxw length def - - % Encode row runlengths - /rows datalen segments div ceiling cvi array def - /numrows rows length def - 0 1 numrows 1 sub { - /r exch def - mark - segments 4 mod 0 ne r 2 mod 1 eq and {0} if - 1 1 - 0 1 segments 1 sub { - /pos exch r segments mul add def - pos datalen lt { - dxw pos get {} forall - pos 2 mod 0 eq {fxw pos 2 idiv get {} forall} if - } if - } for - 1 1 - counttomark array astore rows exch r exch put pop - } for - - numrows 1 eq { % Linear - - % Remove leading space - /sbs rows 0 get dup length 1 sub 1 exch getinterval def - - /sbs [ - 1 - 0 1 datalen 1 sub { - /i exch def - dxw i get {} forall - i 2 mod 0 eq {fxw i 2 idiv get {} forall} if - } for - 1 1 - ] def - - << - /ren (renlinear) - /sbs sbs - /bhs [sbs length 1 add 2 idiv {height} repeat] - /bbs [sbs length 1 add 2 idiv {0} repeat] - /opt options - >> - - dontdraw not //renlinear if - - } { % 2D - stacked - - /seps numrows array def - 0 1 numrows 1 sub { - - /r exch def - /row rows r get def - - % Sample runlengths into bitmap - mark - 0 2 row length 1 sub { - /i exch def - row i get {0} repeat - i row length 1 sub lt {row i 1 add get {1} repeat} if - } for - counttomark array astore /row exch def pop - - % Derive the separator pattern - /sep [ row {1 exch sub} forall ] def - sep 0 [ 0 0 0 0 ] putinterval - sep row length 4 sub [ 0 0 0 0 ] putinterval - /finderpos [ % Finder pattern module positions - 19 98 row length 13 sub {} for - 68 98 row length 13 sub {} for - ] def - finderpos { - dup 14 add 1 exch { - /i exch def - row i get 0 eq { - row i 1 sub get 1 eq { - 1 - } { - sep i 1 sub get 0 eq {1} {0} ifelse - } ifelse - } { - 0 - } ifelse - sep exch i exch put - } for - } forall - - % For even segment-pair symbols reverse alternate rows - segments 4 mod 0 eq r 2 mod 1 eq and { - rows r get length rows 0 get length ne % Except partial width last row - finderpos length 2 mod 1 eq and { % with odd finders - /row [ 0 row aload pop ] def - /sep [ 0 sep aload pop ] def - } { - row length 1 sub -1 0 {row exch get} for - row astore pop - sep length 1 sub -1 0 {sep exch get} for - sep astore pop - } ifelse - } if - - rows r row put - seps r sep put + % Get the result of encoding with code93 + options (dontdraw) true put + options (parsefnc) true put + /args newcode options //code93 exec def + % Replace chars in /txt with chars in newtext + includetext { + /txt args (txt) get def + 0 1 newtext length 1 sub { + /i exch def + /txtentry txt i get def + txtentry 0 newtext i 1 getinterval put + txt i txtentry put } for - - % Extend last row and separator to fill width of symbol - /pixx rows 0 get length def - [ pixx {0} repeat ] dup 0 rows numrows 1 sub get putinterval - rows exch numrows 1 sub exch put - [ pixx {0} repeat ] dup 0 seps numrows 1 sub get putinterval - seps exch numrows 1 sub exch put - - % Middle separator pattern - /sep [ pixx 2 idiv 1 add { 0 1 } repeat ] 0 pixx getinterval def - sep 0 [0 0 0 0] putinterval - sep pixx 4 sub [0 0 0 0] putinterval - - % Compose the symbol - /pixs [ - 0 1 numrows 1 sub { - /r exch def - r 0 ne { - seps r get aload pop - } if - 34 {rows r get aload pop} repeat - r numrows 1 sub ne { - seps r get aload pop - sep aload pop - } if - } for - ] def - - << - /ren (renmatrix) - /pixs pixs - /pixx pixx - /pixy pixs length pixx idiv - /height pixs length pixx idiv 72 div - /width pixx 72 div - /opt options - >> - - dontdraw not //renmatrix if - - } ifelse - - end - -} bind def -% --END ENCODER rssexpanded-- - -% --BEGIN ENCODER pharmacode-- -% --DESC: Pharmaceutical Binary Code -% --EXAM: 117480 -% --EXOP: showborder -% --RNDR: renlinear -/pharmacode { - - 20 dict begin % Confine variables to local scope - - /options exch def % We are given an option string - /barcode exch def % We are given a barcode string - - /dontdraw false def - /height 8 2.835 mul 72 div def - /nwidth 0.5 2.835 mul def - /wwidth 1.5 2.835 mul def - /swidth 1.0 2.835 mul def - - % Parse the input options - options type /stringtype eq { - 1 dict begin - options { - token false eq {exit} if dup length string cvs (=) search - true eq {cvlit exch pop exch def} {cvlit true def} ifelse - } loop - currentdict end /options exch def + args (txt) txt put } if - options {def} forall - - /height height cvr def - /nwidth nwidth cvr def - /wwidth wwidth cvr def - /swidth swidth cvr def - - % Create the human readable text - /txt barcode length array def - 0 1 barcode length 1 sub { - /i exch def - txt i [barcode i 1 getinterval 0 0 () 0] put - } for - - % Convert the integer into the paramacode string - /barcode barcode cvi 1 add 2 17 string cvrs def - /barcode barcode 1 barcode length 1 sub getinterval def - - /barlen barcode length def % Length of the code - /sbs barlen 2 mul array def - - 0 1 barlen 1 sub { - /i exch def - /enc barcode i 1 getinterval def - enc (0) eq { - sbs i 2 mul nwidth put - } { - sbs i 2 mul wwidth put - } ifelse - sbs i 2 mul 1 add swidth put - } for - - % Return the arguments - << - /ren (renlinear) - /sbs sbs - /bhs [sbs length 1 add 2 idiv {height} repeat] - /bbs [sbs length 1 add 2 idiv {0} repeat] - /txt txt - /textxalign (center) - /opt options - >> + args (opt) options put + args dontdraw not //renlinear if end } bind def -% --END ENCODER pharmacode-- +/code93ext dup load /uk.co.terryburton.bwipp defineresource pop +end +/setpacking where {pop setpacking} if +% --END ENCODER code93ext-- -% --BEGIN ENCODER code2of5-- -% --DESC: Code 25 -% --EXAM: 01234567 -% --EXOP: includetext includecheck includecheckintext +% --BEGIN ENCODER interleaved2of5-- +% --DESC: Interleaved 2 of 5 (ITF) +% --EXAM: 2401234567 +% --EXOP: height=0.5 includecheck includetext includecheckintext % --RNDR: renlinear -/code2of5 { +/setpacking where {pop currentpacking true setpacking} if +1 dict +dup /renlinear dup /uk.co.terryburton.bwipp findresource put +begin +/interleaved2of5 { - 20 dict begin % Confine variable to local scope + 20 dict begin % Confine variables to local scope - /options exch def % We are given an option string - /barcode exch def % We are given a barcode string + /options exch def % We are given an option string + /barcode exch def % We are given a barcode string /dontdraw false def - /includecheck false def - /includetext false def % Enable/disable text + /includecheck false def % Enable/disable checkdigit + /includetext false def % Enable/disable text /includecheckintext false def /textfont /Courier def /textsize 10 def @@ -3643,71 +3382,101 @@ /textyoffset textyoffset cvr def /height height cvr def - % Create an array containing the character mappings + /barlen barcode length def % Length of the code + + % Prefix 0 to barcode if length is even and including checkdigit + % or length is odd and not including checkdigit + barlen 2 mod 0 eq includecheck and % even & includecheck + barlen 2 mod 0 ne includecheck not and or { % odd & !includecheck + /pad barlen 1 add string def % Create pad one bigger than barcode + pad 0 48 put % Put ascii 0 at start of pad + pad 1 barcode putinterval % Add barcode to the end of pad + /barcode pad def % barcode=pad + /barlen barlen 1 add def % barlen++ + } if + + % Add checksum to end of barcode + includecheck { + /checksum 0 def + 0 1 barlen 1 sub { + /i exch def + i 2 mod 0 eq { + /checksum checksum barcode i get 48 sub 3 mul add def + } { + /checksum checksum barcode i get 48 sub add def + } ifelse + } for + /checksum 10 checksum 10 mod sub 10 mod def + /pad barlen 1 add string def % Create pad one bigger than barcode + pad 0 barcode putinterval % Add barcode to the start of pad + pad barlen checksum 48 add put % Add checksum to end of pad + /barcode pad def % barcode=pad + /barlen barlen 1 add def % barlen++ + } if + + % Create an array containing the character mappings /encs - [ (1111313111) (3111111131) (1131111131) (3131111111) - (1111311131) (3111311111) (1131311111) (1111113131) - (3111113111) (1131113111) (313111) (311131) + [ (11221) (21112) (12112) (22111) (11212) + (21211) (12211) (11122) (21121) (12121) + (1111) (2111) ] def % Create a string of the available characters /barchars (0123456789) def + /sbs barlen 5 mul 8 add string def + /txt barlen array def - /barlen barcode length def % Length of the code - - includecheck { - /sbs barlen 10 mul 22 add string def - /txt barlen 1 add array def - } { - /sbs barlen 10 mul 12 add string def - /txt barlen array def - } ifelse - % Put the start character sbs 0 encs 10 get putinterval - /checksum 0 def - - 0 1 barlen 1 sub { - /i exch def - % Lookup the encoding for the each barcode character + 0 2 barlen 1 sub { + /i exch def + % Lookup the encodings for two consecutive barcode characters barcode i 1 getinterval barchars exch search - pop % Discard true leaving pre - length /indx exch def % indx is the length of pre - pop pop % Discard seek and post - /enc encs indx get def % Get the indxth encoding - sbs i 10 mul 6 add enc putinterval % Put encoded digit into sbs - txt i [barcode i 1 getinterval i 14 mul 10 add textyoffset textfont textsize] put - barlen i sub 2 mod 0 eq { - /checksum checksum indx add def - } { - /checksum checksum indx 3 mul add def - } ifelse - } for - - % Put the checksum and end characters - includecheck { - /checksum 10 checksum 10 mod sub 10 mod def - sbs barlen 10 mul 6 add encs checksum get putinterval - sbs barlen 10 mul 16 add encs 11 get putinterval - includecheckintext { - txt barlen [barchars checksum 1 getinterval barlen 14 mul 10 add textyoffset textfont textsize] put - } { - txt barlen [( ) barlen 14 mul 10 add textyoffset textfont textsize] put + pop % Discard true leaving pre + length /indx exch def % indx is the length of pre + pop pop % Discard seek and post + /enca encs indx get def % Get the indxth encoding + + barcode i 1 add 1 getinterval barchars exch search + pop % Discard true leaving pre + length /indx exch def % indx is the length of pre + pop pop % Discard seek and post + /encb encs indx get def % Get the indxth encoding + + % Interleave the two character encodings + /intl enca length 2 mul string def + 0 1 enca length 1 sub { + /j exch def + /achar enca j get def + /bchar encb j get def + intl j 2 mul achar put + intl j 2 mul 1 add bchar put + } for + + sbs i 5 mul 4 add intl putinterval % Put encoded digit into sbs + txt i [barcode i 1 getinterval i 9 mul 4 add textyoffset textfont textsize] put + includecheck includecheckintext not and barlen 2 sub i eq and { + txt i 1 add [( ) i 1 add 9 mul 4 add textyoffset textfont textsize] put + } { + txt i 1 add [barcode i 1 add 1 getinterval i 1 add 9 mul 4 add textyoffset textfont textsize] put } ifelse - } { - sbs barlen 10 mul 6 add encs 11 get putinterval - } ifelse - + } for + + % Put the end character + sbs barlen 5 mul 4 add encs 11 get putinterval + % Return the arguments << - /ren (renlinear) + /ren //renlinear /sbs [sbs {48 sub} forall] /bhs [sbs length 1 add 2 idiv {height} repeat] /bbs [sbs length 1 add 2 idiv {0} repeat] includetext { /txt txt } if + /barratio 2 + /spaceratio 2 /opt options >> @@ -3716,14 +3485,23 @@ end } bind def -% --END ENCODER code2of5-- +/interleaved2of5 dup load /uk.co.terryburton.bwipp defineresource pop +end +/setpacking where {pop setpacking} if +% --END ENCODER interleaved2of5-- -% --BEGIN ENCODER code11-- -% --DESC: Code 11 -% --EXAM: 0123456789 -% --EXOP: includetext includecheck includecheckintext +% --BEGIN ENCODER itf14-- +% --REQUIRES interleaved2of5-- +% --DESC: ITF-14 +% --EXAM: 04601234567893 +% --EXOP: includetext % --RNDR: renlinear -/code11 { +/setpacking where {pop currentpacking true setpacking} if +1 dict +dup /renlinear dup /uk.co.terryburton.bwipp findresource put +dup /interleaved2of5 dup /uk.co.terryburton.bwipp findresource put +begin +/itf14 { 20 dict begin % Confine variables to local scope @@ -3731,14 +3509,13 @@ /barcode exch def % We are given a barcode string /dontdraw false def - /includecheck false def - /includetext false def - /includecheckintext false def + /includetext false def % Enable/disable text /textfont /Courier def /textsize 10 def + /textxoffset 0 def /textyoffset -7 def /height 1 def - + % Parse the input options options type /stringtype eq { 1 dict begin @@ -3749,132 +3526,69 @@ currentdict end /options exch def } if options {def} forall - + /textfont textfont cvlit def /textsize textsize cvr def + /textxoffset textxoffset cvr def /textyoffset textyoffset cvr def - /height height cvr def - - % Create an array containing the character mappings - /encs - [ (111131) (311131) (131131) (331111) (113131) - (313111) (133111) (111331) (311311) (311111) - (113111) (113311) - ] def - - % Create a string of the available characters - /barchars (0123456789-) def + /height height cvr def - /barlen barcode length def % Length of the code - - includecheck { - barlen 10 ge { - /sbs barlen 6 mul 24 add string def - /txt barlen 2 add array def - } { - /sbs barlen 6 mul 18 add string def - /txt barlen 1 add array def - } ifelse - } { - /sbs barlen 6 mul 12 add string def - /txt barlen array def - } ifelse - - % Put the start character - sbs 0 encs 11 get putinterval - - /checksum1 0 def /checksum2 0 def - - /xpos 8 def - 0 1 barlen 1 sub { - /i exch def - % Lookup the encoding for the each barcode character - barcode i 1 getinterval barchars exch search - pop % Discard true leaving pre - length /indx exch def % indx is the length of pre - pop pop % Discard seek and post - /enc encs indx get def % Get the indxth encoding - sbs i 6 mul 6 add enc putinterval % Put encoded digit into sbs - txt i [barcode i 1 getinterval xpos textyoffset textfont textsize] put - 0 1 5 { % xpos+=width of the character - /xpos exch enc exch get 48 sub xpos add def - } for - /checksum1 checksum1 barlen i sub 1 sub 10 mod 1 add indx mul add def - /checksum2 checksum2 barlen i sub 9 mod 1 add indx mul add def - } for - - % Put the checksum and end characters - includecheck { - /checksum1 checksum1 11 mod def - barlen 10 ge { - /checksum2 checksum2 checksum1 add 11 mod def - sbs barlen 6 mul 6 add encs checksum1 get putinterval - sbs barlen 6 mul 12 add encs checksum2 get putinterval - includecheckintext { - txt barlen [barchars checksum1 1 getinterval xpos textyoffset textfont textsize] put - /enc encs checksum1 get def - 0 1 5 { % xpos+=width of the character - /xpos exch enc exch get 48 sub xpos add def - } for - txt barlen 1 add [barchars checksum2 1 getinterval xpos textyoffset textfont textsize] put - } { - txt barlen [() xpos textyoffset textfont textsize] put - txt barlen 1 add [() xpos textyoffset textfont textsize] put - } ifelse - sbs barlen 6 mul 18 add encs 11 get putinterval - } { - sbs barlen 6 mul 6 add encs checksum1 get putinterval - includecheckintext { - txt barlen [barchars checksum1 1 getinterval xpos textyoffset textfont textsize] put - } { - txt barlen [() xpos textyoffset textfont textsize] put - } ifelse - sbs barlen 6 mul 12 add encs 11 get putinterval - } ifelse - } { - sbs barlen 6 mul 6 add encs 11 get putinterval - } ifelse - - % Return the arguments - << - /ren (renlinear) - /sbs [sbs {48 sub} forall] - /bhs [sbs length 1 add 2 idiv {height} repeat] - /bbs [sbs length 1 add 2 idiv {0} repeat] - includetext { - /txt txt + % Calculate EAN checksum and add to end of barcode + barcode length dup 13 eq exch 14 eq or { + /gtin barcode 0 13 getinterval def } if - /opt options - >> - dontdraw not //renlinear if + % Get the result of encoding with interleaved2of5 + options (dontdraw) true put + options (showborder) true put + options (borderwidth) 4 put + options (borderleft) 15 put + options (borderright) 15 put + options (height) 0.5 put + options (includecheck) true put + options (includecheckintext) true put + options (textyoffset) -10 put + /args gtin options //interleaved2of5 exec def + args (opt) options put + args + + dontdraw not //renlinear if + end } bind def -% --END ENCODER code11-- - -% --BEGIN ENCODER rationalizedCodabar-- -% --DESC: Rationalized Codabar -% --EXAM: A0123456789B -% --EXOP: includetext includecheck includecheckintext +/itf14 dup load /uk.co.terryburton.bwipp defineresource pop +end +/setpacking where {pop setpacking} if +% --END ENCODER itf14-- + +% --BEGIN ENCODER identcode-- +% --REQUIRES interleaved2of5-- +% --DESC: Deutsche Post Identcode +% --EXAM: 563102430313 +% --EXOP: includetext % --RNDR: renlinear -/rationalizedCodabar { +/setpacking where {pop currentpacking true setpacking} if +1 dict +dup /renlinear dup /uk.co.terryburton.bwipp findresource put +dup /interleaved2of5 dup /uk.co.terryburton.bwipp findresource put +begin +/identcode { - 20 dict begin % Confine variables to local scope + 20 dict begin % Confine variables to local scope - /options exch def % We are given an option string - /barcode exch def % We are given a barcode string + /options exch def % We are given an option string + /barcode exch def % We are given a barcode string /dontdraw false def - /includecheck false def % Enable/disable checkdigit - /includetext false def % Enable/disable text - /includecheckintext false def + /includetext false def % Enable/disable text /textfont /Courier def /textsize 10 def + /textxoffset 0 def /textyoffset -7 def /height 1 def - + % Parse the input options options type /stringtype eq { 1 dict begin @@ -3885,114 +3599,163 @@ currentdict end /options exch def } if options {def} forall - + /textfont textfont cvlit def /textsize textsize cvr def + /textxoffset textxoffset cvr def /textyoffset textyoffset cvr def - /height height cvr def - - % Create an array containing the character mappings - /encs - [ (11111331) (11113311) (11131131) (33111111) (11311311) - (31111311) (13111131) (13113111) (13311111) (31131111) - (11133111) (11331111) (31113131) (31311131) (31313111) - (11313131) (11331311) (13131131) (11131331) (11133311) - ] def + /height height cvr def - % Create a string of the available characters - /barchars (0123456789-$:/.+ABCD) def - - /barlen barcode length def % Length of the code - - includecheck { - /sbs barlen 8 mul 8 add string def - /txt barlen 1 add array def - } { - /sbs barlen 8 mul string def - /txt barlen array def - } ifelse + % Calculate checksum and add to end of barcode + barcode length dup 11 eq exch 12 eq or { + /checksum 0 def + 0 1 10 { + /i exch def + /checksum checksum barcode i get 48 sub i 2 mod 0 eq {4 mul} {9 mul} ifelse add def + } for + /checksum 10 checksum 10 mod sub 10 mod def + 12 string + dup 0 barcode 0 11 getinterval putinterval + dup 11 checksum 48 add put + /pad exch def + } if + /barcode pad def - /checksum 0 def - /xpos 0 def - 0 1 barlen 2 sub { - /i exch def - % Lookup the encoding for the each barcode character - barcode i 1 getinterval barchars exch search - pop % Discard true leaving pre - length /indx exch def % indx is the length of pre - pop pop % Discard seek and post - /enc encs indx get def % Get the indxth encoding - sbs i 8 mul enc putinterval % Put encoded digit into sbs - txt i [barcode i 1 getinterval xpos textyoffset textfont textsize] put - 0 1 7 { % xpos+=width of the character - /xpos exch enc exch get 48 sub xpos add def - } for - /checksum checksum indx add def - } for + % Compose the human readable text + /text ( . . ) 16 string copy def + text 0 barcode 0 2 getinterval putinterval + text 3 barcode 2 3 getinterval putinterval + text 7 barcode 5 3 getinterval putinterval + text 11 barcode 8 3 getinterval putinterval + text 15 barcode 11 1 getinterval putinterval - % Find index of last character - barcode barlen 1 sub 1 getinterval barchars exch search - pop % Discard true leaving pre - length /indx exch def % indx is the length of pre - pop pop % Discard seek and post + % Get the result of encoding with interleaved2of5 + options (dontdraw) true put + options (includecheck) false put + /args barcode options //interleaved2of5 exec def - includecheck { - % Put the checksum character - /checksum checksum indx add def - /checksum 16 checksum 16 mod sub 16 mod def - sbs barlen 8 mul 8 sub encs checksum get putinterval - includecheckintext { - txt barlen 1 sub [barchars checksum 1 getinterval xpos textyoffset textfont textsize] put - } { - txt barlen 1 sub [( ) xpos textyoffset textfont textsize] put - } ifelse - 0 1 7 { % xpos+=width of the character - /xpos exch encs checksum get exch get 48 sub xpos add def - } for - % Put the end character - /enc encs indx get def % Get the indxth encoding - sbs barlen 8 mul enc putinterval % Put encoded digit into sbs - txt barlen [barcode barlen 1 sub 1 getinterval xpos textyoffset textfont textsize] put - } { - % Put the end character - /enc encs indx get def % Get the indxth encoding - sbs barlen 8 mul 8 sub enc putinterval % Put encoded digit into sbs - txt barlen 1 sub [barcode barlen 1 sub 1 getinterval xpos textyoffset textfont textsize] put - } ifelse + args (txt) [ [text textxoffset textyoffset textfont textsize] ] put + args (textxalign) (center) put + args (opt) options put + args + + dontdraw not //renlinear if + + end - % Return the arguments - << - /ren (renlinear) - /sbs [sbs {48 sub} forall] - /bhs [sbs length 1 add 2 idiv {height} repeat] - /bbs [sbs length 1 add 2 idiv {0} repeat] - includetext { - /txt txt +} bind def +/identcode dup load /uk.co.terryburton.bwipp defineresource pop +end +/setpacking where {pop setpacking} if +% --END ENCODER identcode-- + +% --BEGIN ENCODER leitcode-- +% --REQUIRES interleaved2of5-- +% --DESC: Deutsche Post Leitcode +% --EXAM: 21348075016401 +% --EXOP: includetext +% --RNDR: renlinear +/setpacking where {pop currentpacking true setpacking} if +1 dict +dup /renlinear dup /uk.co.terryburton.bwipp findresource put +dup /interleaved2of5 dup /uk.co.terryburton.bwipp findresource put +begin +/leitcode { + + 20 dict begin % Confine variables to local scope + + /options exch def % We are given an option string + /barcode exch def % We are given a barcode string + + /dontdraw false def + /includetext false def % Enable/disable text + /textfont /Courier def + /textsize 10 def + /textxoffset 0 def + /textyoffset -7 def + /height 1 def + + % Parse the input options + options type /stringtype eq { + 1 dict begin + options { + token false eq {exit} if dup length string cvs (=) search + true eq {cvlit exch pop exch def} {cvlit true def} ifelse + } loop + currentdict end /options exch def } if - /opt options - >> + options {def} forall - dontdraw not //renlinear if + /textfont textfont cvlit def + /textsize textsize cvr def + /textxoffset textxoffset cvr def + /textyoffset textyoffset cvr def + /height height cvr def + + % Calculate checksum and add to end of barcode + barcode length dup 13 eq exch 14 eq or { + /checksum 0 def + 0 1 12 { + /i exch def + /checksum checksum barcode i get 48 sub i 2 mod 0 eq {4 mul} {9 mul} ifelse add def + } for + /checksum 10 checksum 10 mod sub 10 mod def + 14 string + dup 0 barcode 0 13 getinterval putinterval + dup 13 checksum 48 add put + /pad exch def + } if + /barcode pad def + + % Compose the human readable text + /text ( . . . ) 18 string copy def + text 0 barcode 0 5 getinterval putinterval + text 6 barcode 5 3 getinterval putinterval + text 10 barcode 8 3 getinterval putinterval + text 14 barcode 11 2 getinterval putinterval + text 17 barcode 13 1 getinterval putinterval + + % Get the result of encoding with interleaved2of5 + options (dontdraw) true put + options (includecheck) false put + /args barcode options //interleaved2of5 exec def + args (txt) [ [text textxoffset textyoffset textfont textsize] ] put + args (textxalign) (center) put + args (opt) options put + args + + dontdraw not //renlinear if + end } bind def -% --END ENCODER rationalizedCodabar-- +/leitcode dup load /uk.co.terryburton.bwipp defineresource pop +end +/setpacking where {pop setpacking} if +% --END ENCODER leitcode-- -% --BEGIN ENCODER onecode-- -% --DESC: United States Postal Service OneCode -% --EXAM: 0123456709498765432101234567891 -% --EXOP: barcolor=FF0000 -% --RNDR: renlinear -/onecode { +% --BEGIN ENCODER databaromni-- +% --DESC: GS1 DataBar Omnidirectional +% --EXAM: (01)24012345678905 +% --EXOP: +% --RNDR: renlinear renmatrix +/setpacking where {pop currentpacking true setpacking} if +1 dict +dup /renlinear dup /uk.co.terryburton.bwipp findresource put +dup /renmatrix dup /uk.co.terryburton.bwipp findresource put +begin +/databaromni { - 20 dict begin + 20 dict begin % Confine variables to local scope - /options exch def % We are given an option string - /barcode exch def % We are given a barcode string + /options exch def % We are given an option string + /barcode exch def % We are given a barcode string /dontdraw false def - /height 0.15 def + /height 33 72 div def + /linkage false def + /format (omni) def % Parse the input options options type /stringtype eq { @@ -4004,335 +3767,405 @@ currentdict end /options exch def } if options {def} forall - + + format (truncated) eq {/height 13 72 div def} if /height height cvr def - /barlen barcode length def - + % Strip the AI and optional check digit + barcode length dup 17 eq exch 18 eq or { + barcode 0 4 getinterval (\(01\)) eq { + /binval [ + linkage {1} {0} ifelse + barcode 4 13 getinterval {48 sub} forall + ] def + } if + } if + + % Calculate EAN checksum and add to end of barcode + /checksum 0 def + 0 1 12 { + /i exch def + /checksum checksum barcode i 4 add get 48 sub i 2 mod 0 eq {3 mul} if add def + } for + /checksum 10 checksum 10 mod sub 10 mod def + 18 string + dup 0 barcode 0 17 getinterval putinterval + dup 17 checksum 48 add put + /barcode exch def + % Create the human readable text - /txtdict << - 2 dup - 5 dup - barcode 5 1 getinterval (9) eq {14} {11} ifelse dup - 20 dup - 25 dup - 29 dup - >> def - /txt barlen 6 add array def - /spacecnt 0 def - 0 1 barlen 1 sub { + /txt barcode length array def + 0 1 barcode length 1 sub { /i exch def - txtdict i known { - txt i spacecnt add [( ) 0 0 () 0] put - /spacecnt spacecnt 1 add def - } if - txt i spacecnt add [barcode i 1 getinterval 0 0 () 0] put + txt i [barcode i 1 getinterval 0 0 () 0] put } for - /txt txt 0 barcode length spacecnt add getinterval def - /normalize { - /base exch def - /num exch def - num length 1 sub -1 1 { - /i exch def - num i 1 sub 2 copy get num i get base idiv add put - num i num i get base mod put + /ncr { % n r + 2 copy sub 2 copy lt {exch} if % n r maxd mind + 1 1 5 3 roll % mind j=1 v=1 n maxd + 1 add -1 exch { % mind j v n -1 maxd+1 + mul % mind j v*i + 1 index 3 index le { + 1 index idiv exch 1 add exch + } if } for - { %loop - extend input as necessary - num 0 get base lt {exit} if - /num [0 num {} forall] def - num 0 num 0 get num 1 get base idiv add put - num 1 num 1 get base mod put + { % mind j v + 1 index 3 index gt {exit} if + 1 index idiv exch 1 add exch } loop - % Trim leading zeros - /num [/i true def num {dup 0 eq i and {pop} {/i false def} ifelse} forall] def - num length 0 eq {/num [0] def} if - num + exch pop exch pop } bind def - - /bigadd { - 2 copy length exch length - 2 copy sub abs /offset exch def - lt {exch} if - /a exch def /b exch def - 0 1 b length 1 sub { - dup a exch offset add 2 copy get b 5 -1 roll get add put + + /getRSSwidths { + /oe exch def + /el exch def + /mw exch def + /nm exch def + /val exch def + /out el array def + /mask 0 def + 0 1 el 2 sub { + /bar exch def + /ew 1 def + /mask mask 1 bar bitshift or def { + /sval nm ew sub 1 sub el bar sub 2 sub ncr def + oe mask 0 eq and nm ew sub el 2 mul sub bar 2 mul add -2 ge and { + /sval sval nm ew sub el sub bar add el bar sub 2 sub ncr sub def + } if + el bar sub 2 gt { + /lval 0 def + nm ew sub el sub bar add 2 add -1 mw 1 add { + nm exch sub ew sub 1 sub el bar sub 3 sub ncr + /lval exch lval add def + } for + /sval sval lval el bar sub 1 sub mul sub def + } { + nm ew sub mw gt {/sval sval 1 sub def} if + } ifelse + /val val sval sub def + val 0 lt {exit} if + /ew ew 1 add def + /mask mask 1 bar bitshift not and def + } loop + /val val sval add def + /nm nm ew sub def + out bar ew put } for - a + out el 1 sub nm put + out } bind def - - % Conversion of data fields into binary data - barlen 20 eq {[0]} if - barlen 25 eq {[1]} if - barlen 29 eq {[1 0 0 0 0 1]} if - barlen 31 eq {[1 0 0 0 1 0 0 0 0 1]} if - /binval exch [barcode 20 barlen 20 sub getinterval {48 sub} forall] bigadd def - /binval [binval {} forall barcode 0 get 48 sub] def - /binval [binval {5 mul} forall] [barcode 1 get 48 sub] bigadd 10 normalize def - /binval [binval {} forall barcode 2 18 getinterval {48 sub} forall] def - - % Conversion of binary data into byte array - /bytes 13 array def - /bintmp [binval {} forall] def - 12 -1 0 { + + 0 1 12 { /i exch def - 0 1 bintmp length 2 sub { - /j exch def - bintmp j 1 add 2 copy get bintmp j get 256 mod 10 mul add put - bintmp j bintmp j get 256 idiv put - } for - bytes i bintmp bintmp length 1 sub get 256 mod put - bintmp bintmp length 1 sub 2 copy get 256 idiv put - } for - - % Generation of 11-bit CRC on byte array - /fcs 2047 def - /dat bytes 0 get 5 bitshift def - 6 { - fcs dat xor 1024 and 0 ne { - /fcs fcs 1 bitshift 3893 xor def - } { - /fcs fcs 1 bitshift def - } ifelse - /fcs fcs 2047 and def - /dat dat 1 bitshift def - } repeat - 1 1 12 { - bytes exch get 3 bitshift /dat exch def - 8 { - fcs dat xor 1024 and 0 ne { - /fcs fcs 1 bitshift 3893 xor def - } { - /fcs fcs 1 bitshift def - } ifelse - /fcs fcs 2047 and def - /dat dat 1 bitshift def - } repeat + binval i 1 add 2 copy get binval i get 4537077 mod 10 mul add put + binval i binval i get 4537077 idiv put } for + /right binval 13 get 4537077 mod def + binval 13 2 copy get 4537077 idiv put - % Conversion from binary data to codewords - /codewords 10 array def - 9 -1 0 { - /i exch def - i 9 eq { - /b 636 def + /left 0 def + /i true def + 0 1 13 { + /j exch def + binval j get + dup 0 eq i and { + pop } { - /b 1365 def + /i false def + /left left 3 -1 roll 10 13 j sub exp cvi mul add def } ifelse - 0 1 binval length 2 sub { - /j exch def - binval j 1 add 2 copy get binval j get b mod 10 mul add put - binval j binval j get b idiv put - } for - codewords i binval binval length 1 sub get b mod put - binval binval length 1 sub 2 copy get b idiv put } for + + /d1 left 1597 idiv def + /d2 left 1597 mod def + /d3 right 1597 idiv def + /d4 right 1597 mod def - % Inserting additional information into codewords - codewords 9 codewords 9 get 2 mul put - fcs 1024 and 0 ne { - codewords 0 codewords 0 get 659 add put - } if - - % Conversion from codewords to characters - /tab513 [ - 31 7936 47 7808 55 7552 59 7040 61 6016 62 3968 79 7744 87 - 7488 91 6976 93 5952 94 3904 103 7360 107 6848 109 5824 110 3776 - 115 6592 117 5568 118 3520 121 5056 122 3008 124 1984 143 7712 151 - 7456 155 6944 157 5920 158 3872 167 7328 171 6816 173 5792 174 3744 - 179 6560 181 5536 182 3488 185 5024 186 2976 188 1952 199 7264 203 - 6752 205 5728 206 3680 211 6496 213 5472 214 3424 217 4960 218 2912 - 220 1888 227 6368 229 5344 230 3296 233 4832 234 2784 236 1760 241 - 4576 242 2528 244 1504 248 992 271 7696 279 7440 283 6928 285 5904 - 286 3856 295 7312 299 6800 301 5776 302 3728 307 6544 309 5520 310 - 3472 313 5008 314 2960 316 1936 327 7248 331 6736 333 5712 334 3664 - 339 6480 341 5456 342 3408 345 4944 346 2896 348 1872 355 6352 357 - 5328 358 3280 361 4816 362 2768 364 1744 369 4560 370 2512 372 1488 - 376 976 391 7216 395 6704 397 5680 398 3632 403 6448 405 5424 406 - 3376 409 4912 410 2864 412 1840 419 6320 421 5296 422 3248 425 4784 - 426 2736 428 1712 433 4528 434 2480 436 1456 440 944 451 6256 453 - 5232 454 3184 457 4720 458 2672 460 1648 465 4464 466 2416 468 1392 - 472 880 481 4336 482 2288 484 1264 488 752 527 7688 535 7432 539 - 6920 541 5896 542 3848 551 7304 555 6792 557 5768 558 3720 563 6536 - 565 5512 566 3464 569 5000 570 2952 572 1928 583 7240 587 6728 589 - 5704 590 3656 595 6472 597 5448 598 3400 601 4936 602 2888 604 1864 - 611 6344 613 5320 614 3272 617 4808 618 2760 620 1736 625 4552 626 - 2504 628 1480 632 968 647 7208 651 6696 653 5672 654 3624 659 6440 - 661 5416 662 3368 665 4904 666 2856 668 1832 675 6312 677 5288 678 - 3240 681 4776 682 2728 684 1704 689 4520 690 2472 692 1448 696 936 - 707 6248 709 5224 710 3176 713 4712 714 2664 716 1640 721 4456 722 - 2408 724 1384 728 872 737 4328 738 2280 740 1256 775 7192 779 6680 - 781 5656 782 3608 787 6424 789 5400 790 3352 793 4888 794 2840 796 - 1816 803 6296 805 5272 806 3224 809 4760 810 2712 812 1688 817 4504 - 818 2456 820 1432 824 920 835 6232 837 5208 838 3160 841 4696 842 - 2648 844 1624 849 4440 850 2392 852 1368 865 4312 866 2264 868 1240 - 899 6200 901 5176 902 3128 905 4664 906 2616 908 1592 913 4408 914 - 2360 916 1336 929 4280 930 2232 932 1208 961 4216 962 2168 964 1144 - 1039 7684 1047 7428 1051 6916 1053 5892 1054 3844 1063 7300 1067 6788 1069 - 5764 1070 3716 1075 6532 1077 5508 1078 3460 1081 4996 1082 2948 1084 1924 - 1095 7236 1099 6724 1101 5700 1102 3652 1107 6468 1109 5444 1110 3396 1113 - 4932 1114 2884 1116 1860 1123 6340 1125 5316 1126 3268 1129 4804 1130 2756 - 1132 1732 1137 4548 1138 2500 1140 1476 1159 7204 1163 6692 1165 5668 1166 - 3620 1171 6436 1173 5412 1174 3364 1177 4900 1178 2852 1180 1828 1187 6308 - 1189 5284 1190 3236 1193 4772 1194 2724 1196 1700 1201 4516 1202 2468 1204 - 1444 1219 6244 1221 5220 1222 3172 1225 4708 1226 2660 1228 1636 1233 4452 - 1234 2404 1236 1380 1249 4324 1250 2276 1287 7188 1291 6676 1293 5652 1294 - 3604 1299 6420 1301 5396 1302 3348 1305 4884 1306 2836 1308 1812 1315 6292 - 1317 5268 1318 3220 1321 4756 1322 2708 1324 1684 1329 4500 1330 2452 1332 - 1428 1347 6228 1349 5204 1350 3156 1353 4692 1354 2644 1356 1620 1361 4436 - 1362 2388 1377 4308 1378 2260 1411 6196 1413 5172 1414 3124 1417 4660 1418 - 2612 1420 1588 1425 4404 1426 2356 1441 4276 1442 2228 1473 4212 1474 2164 - 1543 7180 1547 6668 1549 5644 1550 3596 1555 6412 1557 5388 1558 3340 1561 - 4876 1562 2828 1564 1804 1571 6284 1573 5260 1574 3212 1577 4748 1578 2700 - 1580 1676 1585 4492 1586 2444 1603 6220 1605 5196 1606 3148 1609 4684 1610 - 2636 1617 4428 1618 2380 1633 4300 1634 2252 1667 6188 1669 5164 1670 3116 - 1673 4652 1674 2604 1681 4396 1682 2348 1697 4268 1698 2220 1729 4204 1730 - 2156 1795 6172 1797 5148 1798 3100 1801 4636 1802 2588 1809 4380 1810 2332 - 1825 4252 1826 2204 1857 4188 1858 2140 1921 4156 1922 2108 2063 7682 2071 - 7426 2075 6914 2077 5890 2078 3842 2087 7298 2091 6786 2093 5762 2094 3714 - 2099 6530 2101 5506 2102 3458 2105 4994 2106 2946 2119 7234 2123 6722 2125 - 5698 2126 3650 2131 6466 2133 5442 2134 3394 2137 4930 2138 2882 2147 6338 - 2149 5314 2150 3266 2153 4802 2154 2754 2161 4546 2162 2498 2183 7202 2187 - 6690 2189 5666 2190 3618 2195 6434 2197 5410 2198 3362 2201 4898 2202 2850 - 2211 6306 2213 5282 2214 3234 2217 4770 2218 2722 2225 4514 2226 2466 2243 - 6242 2245 5218 2246 3170 2249 4706 2250 2658 2257 4450 2258 2402 2273 4322 - 2311 7186 2315 6674 2317 5650 2318 3602 2323 6418 2325 5394 2326 3346 2329 - 4882 2330 2834 2339 6290 2341 5266 2342 3218 2345 4754 2346 2706 2353 4498 - 2354 2450 2371 6226 2373 5202 2374 3154 2377 4690 2378 2642 2385 4434 2401 - 4306 2435 6194 2437 5170 2438 3122 2441 4658 2442 2610 2449 4402 2465 4274 - 2497 4210 2567 7178 2571 6666 2573 5642 2574 3594 2579 6410 2581 5386 2582 - 3338 2585 4874 2586 2826 2595 6282 2597 5258 2598 3210 2601 4746 2602 2698 - 2609 4490 2627 6218 2629 5194 2630 3146 2633 4682 2641 4426 2657 4298 2691 - 6186 2693 5162 2694 3114 2697 4650 2705 4394 2721 4266 2753 4202 2819 6170 - 2821 5146 2822 3098 2825 4634 2833 4378 2849 4250 2881 4186 2945 4154 3079 - 7174 3083 6662 3085 5638 3086 3590 3091 6406 3093 5382 3094 3334 3097 4870 - 3107 6278 3109 5254 3110 3206 3113 4742 3121 4486 3139 6214 3141 5190 3145 - 4678 3153 4422 3169 4294 3203 6182 3205 5158 3209 4646 3217 4390 3233 4262 - 3265 4198 3331 6166 3333 5142 3337 4630 3345 4374 3361 4246 3393 4182 3457 - 4150 3587 6158 3589 5134 3593 4622 3601 4366 3617 4238 3649 4174 3713 4142 - 3841 4126 4111 7681 4119 7425 4123 6913 4125 5889 4135 7297 4139 6785 4141 - 5761 4147 6529 4149 5505 4153 4993 4167 7233 4171 6721 4173 5697 4179 6465 - 4181 5441 4185 4929 4195 6337 4197 5313 4201 4801 4209 4545 4231 7201 4235 - 6689 4237 5665 4243 6433 4245 5409 4249 4897 4259 6305 4261 5281 4265 4769 - 4273 4513 4291 6241 4293 5217 4297 4705 4305 4449 4359 7185 4363 6673 4365 - 5649 4371 6417 4373 5393 4377 4881 4387 6289 4389 5265 4393 4753 4401 4497 - 4419 6225 4421 5201 4425 4689 4483 6193 4485 5169 4489 4657 4615 7177 4619 - 6665 4621 5641 4627 6409 4629 5385 4633 4873 4643 6281 4645 5257 4649 4745 - 4675 6217 4677 5193 4739 6185 4741 5161 4867 6169 4869 5145 5127 7173 5131 - 6661 5133 5637 5139 6405 5141 5381 5155 6277 5157 5253 5187 6213 5251 6181 - 5379 6165 5635 6157 6151 7171 6155 6659 6163 6403 6179 6275 6211 5189 4681 - 4433 4321 3142 2634 2386 2274 1612 1364 1252 856 744 496 + /tab164 [ + 160 0 12 4 8 1 161 1 + 960 161 10 6 6 3 80 10 + 2014 961 8 8 4 5 31 34 + 2714 2015 6 10 3 6 10 70 + 2840 2715 4 12 1 8 1 126 ] def - /tab213 [ - 3 6144 5 5120 6 3072 9 4608 10 2560 12 1536 17 4352 18 - 2304 20 1280 24 768 33 4224 34 2176 36 1152 40 640 48 384 - 65 4160 66 2112 68 1088 72 576 80 320 96 192 129 4128 130 - 2080 132 1056 136 544 144 288 257 4112 258 2064 260 1040 264 528 - 513 4104 514 2056 516 1032 1025 4100 1026 2052 2049 4098 4097 2050 1028 - 520 272 160 + /tab154 [ + 335 0 5 10 2 7 4 84 + 1035 336 7 8 4 5 20 35 + 1515 1036 9 6 6 3 48 10 + 1596 1516 11 4 8 1 81 1 ] def - /chars 10 array def - 0 1 9 { - /i exch def - codewords i get dup 1286 le { - tab513 exch get - } { - tab213 exch 1287 sub get - } ifelse - chars i 3 -1 roll put - } for - - 9 -1 0 { - /i exch def - 2 i exp cvi fcs and 0 ne { - chars i chars i get 8191 xor put + /i 0 def { + d1 tab164 i get le { + tab164 i 1 add 7 getinterval {} forall + /d1te exch def /d1to exch def + /d1mwe exch def /d1mwo exch def + /d1ele exch def /d1elo exch def + /d1gs exch def + exit } if - } for - - % Conversion from characters to the OneCode encoding - /barmap [ - 7 2 4 3 1 10 0 0 9 12 2 8 5 5 6 11 8 9 3 1 - 0 1 5 12 2 5 1 8 4 4 9 11 6 3 8 10 3 9 7 6 - 5 11 1 4 8 5 2 12 9 10 0 2 7 1 6 7 3 6 4 9 - 0 3 8 6 6 4 2 7 1 1 9 9 7 10 5 2 4 0 3 8 - 6 2 0 4 8 11 1 0 9 8 3 12 2 6 7 7 5 1 4 10 - 1 12 6 9 7 3 8 0 5 8 9 7 4 6 2 10 3 4 0 5 - 8 4 5 7 7 11 1 9 6 0 9 6 0 6 4 8 2 1 3 2 - 5 9 8 12 4 11 6 1 9 5 7 4 3 3 1 2 0 7 2 0 - 1 3 4 1 6 10 3 5 8 7 9 4 2 11 5 6 0 8 7 12 - 4 2 8 1 5 10 3 0 9 3 0 9 6 5 2 4 7 8 1 7 - 5 0 4 5 2 3 0 10 6 12 9 2 3 11 1 6 8 8 7 9 - 5 4 0 11 1 5 2 2 9 1 4 12 8 3 6 6 7 0 3 7 - 4 7 7 5 0 12 1 11 2 9 9 0 6 8 5 3 3 10 8 2 - ] def + /i i 8 add def + } loop - /bbs 65 array def - /bhs 65 array def - 0 1 64 { - /i exch def - /dec chars barmap i 4 mul get get 2 barmap i 4 mul 1 add get exp cvi and 0 ne def - /asc chars barmap i 4 mul 2 add get get 2 barmap i 4 mul 3 add get exp cvi and 0 ne def - dec not asc not and { - bbs i 3 height mul 8 div put - bhs i 2 height mul 8 div put + /i 0 def { + d2 tab154 i get le { + tab154 i 1 add 7 getinterval {} forall + /d2te exch def /d2to exch def + /d2mwe exch def /d2mwo exch def + /d2ele exch def /d2elo exch def + /d2gs exch def + exit } if - dec not asc and { - bbs i 3 height mul 8 div put - bhs i 5 height mul 8 div put - } if - dec asc not and { - bbs i 0 height mul 8 div put - bhs i 5 height mul 8 div put + /i i 8 add def + } loop + + /i 0 def { + d3 tab164 i get le { + tab164 i 1 add 7 getinterval {} forall + /d3te exch def /d3to exch def + /d3mwe exch def /d3mwo exch def + /d3ele exch def /d3elo exch def + /d3gs exch def + exit } if - dec asc and { - bbs i 0 height mul 8 div put - bhs i 8 height mul 8 div put + /i i 8 add def + } loop + + /i 0 def { + d4 tab154 i get le { + tab154 i 1 add 7 getinterval {} forall + /d4te exch def /d4to exch def + /d4mwe exch def /d4mwo exch def + /d4ele exch def /d4elo exch def + /d4gs exch def + exit } if + /i i 8 add def + } loop + + /d1wo d1 d1gs sub d1te idiv d1elo d1mwo 4 false getRSSwidths def + /d1we d1 d1gs sub d1te mod d1ele d1mwe 4 true getRSSwidths def + /d2wo d2 d2gs sub d2to mod d2elo d2mwo 4 true getRSSwidths def + /d2we d2 d2gs sub d2to idiv d2ele d2mwe 4 false getRSSwidths def + /d3wo d3 d3gs sub d3te idiv d3elo d3mwo 4 false getRSSwidths def + /d3we d3 d3gs sub d3te mod d3ele d3mwe 4 true getRSSwidths def + /d4wo d4 d4gs sub d4to mod d4elo d4mwo 4 true getRSSwidths def + /d4we d4 d4gs sub d4to idiv d4ele d4mwe 4 false getRSSwidths def + + /d1w 8 array def + 0 1 3 { + /i exch def + d1w i 2 mul d1wo i get put + d1w i 2 mul 1 add d1we i get put + } for + + /d2w 8 array def + 0 1 3 { + /i exch def + d2w 7 i 2 mul sub d2wo i get put + d2w 6 i 2 mul sub d2we i get put } for - % Return the arguments - << - /ren (renlinear) - /bbs bbs - /bhs bhs - /sbs [bhs length 1 sub {1.44 1.872} repeat 1.44] - /txt txt - /textxalign (left) - /textfont /Helvetica - /textyoffset 1 - /textxoffset -0.3 - /opt options - >> + /d3w 8 array def + 0 1 3 { + /i exch def + d3w 7 i 2 mul sub d3wo i get put + d3w 6 i 2 mul sub d3we i get put + } for + + /d4w 8 array def + 0 1 3 { + /i exch def + d4w i 2 mul d4wo i get put + d4w i 2 mul 1 add d4we i get put + } for - dontdraw not //renlinear if + /widths [ + d1w {} forall + d2w {} forall + d3w {} forall + d4w {} forall + ] def + + /checkweights [ + 1 3 9 27 2 6 18 54 + 58 72 24 8 29 36 12 4 + 74 51 17 32 37 65 48 16 + 64 34 23 69 49 68 46 59 + ] def + + /checkwidths [ + 3 8 2 1 1 3 5 5 1 1 3 3 7 1 1 + 3 1 9 1 1 2 7 4 1 1 2 5 6 1 1 + 2 3 8 1 1 1 5 7 1 1 1 3 9 1 1 + ] def + + /checksum 0 def + 0 1 31 { + /i exch def + /checksum checksum widths i get checkweights i get mul add def + } for + /checksum checksum 79 mod def + checksum 8 ge {/checksum checksum 1 add def} if + checksum 72 ge {/checksum checksum 1 add def} if + /checklt checkwidths checksum 9 idiv 5 mul 5 getinterval def + /checkrtrev checkwidths checksum 9 mod 5 mul 5 getinterval def + /checkrt 5 array def + 0 1 4 { + /i exch def + checkrt i checkrtrev 4 i sub get put + } for + + % Stacked format + format (omni) eq format (truncated) eq or { % linear + + /sbs [ + 1 d1w {} forall checklt {} forall d2w {} forall + d4w {} forall checkrt {} forall d3w {} forall 1 1 + ] def + + << + /ren //renlinear + /sbs sbs + /bhs [sbs length 1 add 2 idiv {height} repeat] + /bbs [sbs length 1 add 2 idiv {0} repeat] + /txt txt + /textxalign (center) + /opt options + >> + + dontdraw not //renlinear if + + } { % 2D - stacked or stackedomni + + /top [ 1 1 d1w {} forall checklt {} forall d2w {} forall 1 1 0 ] def + /bot [ 1 1 d4w {} forall checkrt {} forall d3w {} forall 1 1 0 ] def + 0 2 24 { + /i exch def + top i get {0} repeat + top i 1 add get {1} repeat + } for + 50 array astore /top exch def + 0 2 24 { + /i exch def + bot i get {1} repeat + bot i 1 add get {0} repeat + } for + 50 array astore /bot exch def + % Stacked + format (stacked) eq { + /sep [ 50 {0} repeat ] def + 4 1 45 { + /i exch def + top i get bot i get eq { + sep i 1 top i get sub put + } { + sep i 1 sep i 1 sub get sub put + } ifelse + } for + /pixs [ + 5 {top aload pop} repeat + sep aload pop + 7 {bot aload pop} repeat + ] def + /pixy pixs length 50 idiv def + } if + + % Stacked omnidirectional + format (stackedomni) eq { + /sep1 [ top {1 exch sub} forall ] def + sep1 0 [ 0 0 0 0 ] putinterval + sep1 46 [ 0 0 0 0 ] putinterval + 18 1 30 { + /i exch def + top i get 0 eq { + top i 1 sub get 1 eq { + 1 + } { + sep1 i 1 sub get 0 eq {1} {0} ifelse + } ifelse + } { + 0 + } ifelse + sep1 exch i exch put + } for + /sep2 [ 0 0 0 0 21 { 0 1 } repeat 0 0 0 0 ] def + /sep3 [ bot {1 exch sub} forall ] def + sep3 0 [ 0 0 0 0 ] putinterval + sep3 46 [ 0 0 0 0 ] putinterval + 19 1 31 { + /i exch def + bot i get 0 eq { + bot i 1 sub get 1 eq { + 1 + } { + sep3 i 1 sub get 0 eq {1} {0} ifelse + } ifelse + } { + 0 + } ifelse + sep3 exch i exch put + } for + /f3 [1 1 1 1 1 1 1 1 1 0 1 1 1] def + true 0 1 12 {dup bot exch 19 add get exch f3 exch get eq and} for { + % Right shifted module for value 3 finder + sep3 19 [ 0 0 0 0 0 0 0 0 0 0 1 0 0 ] putinterval + } if + /pixs [ + 33 {top aload pop} repeat + sep1 aload pop + sep2 aload pop + sep3 aload pop + 33 {bot aload pop} repeat + ] def + /pixy pixs length 50 idiv def + } if + + % Return the arguments + << + /ren //renmatrix + /pixs pixs + /pixx 50 + /pixy pixy + /height pixy 72 div + /width 50 72 div + /opt options + >> + + dontdraw not //renmatrix if + + } ifelse + end } bind def -% --END ENCODER onecode-- - -% --BEGIN ENCODER postnet-- -% --DESC: United States Postal Service Postnet -% --EXAM: 012345 -% --EXOP: includetext includecheckintext -% --RNDR: renlinear -/postnet { +/databaromni dup load /uk.co.terryburton.bwipp defineresource pop +end +/setpacking where {pop setpacking} if +% --END ENCODER databaromni-- + +% --BEGIN ENCODER databarstacked-- +% --REQUIRES databaromni-- +% --DESC: GS1 DataBar Stacked +% --EXAM: (01)24012345678905 +% --EXOP: +% --RNDR: renmatrix renlinear +/setpacking where {pop currentpacking true setpacking} if +1 dict +dup /renmatrix dup /uk.co.terryburton.bwipp findresource put +dup /databaromni dup /uk.co.terryburton.bwipp findresource put +begin +/databarstacked { - 20 dict begin + 20 dict begin % Confine variables to local scope - /options exch def % We are given an option string - /barcode exch def % We are given a barcode string + /options exch def % We are given an option string + /barcode exch def % We are given a barcode string /dontdraw false def - /includetext false def % Enable/disable text - /includecheckintext false def - /textfont /Courier def - /textsize 10 def - /textyoffset -7 def - /height 0.125 def - + % Parse the input options options type /stringtype eq { 1 dict begin @@ -4343,119 +4176,96 @@ currentdict end /options exch def } if options {def} forall - - /textfont textfont cvlit def - /textsize textsize cvr def - /textyoffset textyoffset cvr def - /height height cvr def - - /barlen barcode length def - % Create an array containing the character mappings - /encs - [ (55222) (22255) (22525) (22552) (25225) - (25252) (25522) (52225) (52252) (52522) - (5) (5) - ] def + % Get the result of encoding with databaromni with format=stacked + options (dontdraw) true put + options (format) (stacked) put - % Create a string of the available characters - /barchars (0123456789) def + /args barcode options //databaromni exec def - /bhs barlen 5 mul 7 add array def - /txt barlen 1 add array def + args (opt) options put + args + + dontdraw not //renmatrix if - % Put start character - /enc encs 10 get def - /heights enc length array def - 0 1 enc length 1 sub { - /j exch def - heights j enc j 1 getinterval cvi height mul 5 div put - } for - bhs 0 heights putinterval % Put encoded digit into sbs + end - /checksum 0 def - 0 1 barlen 1 sub { - /i exch def - % Lookup the encoding for the each barcode character - barcode i 1 getinterval barchars exch search - pop % Discard true leaving pre - length /indx exch def % indx is the length of pre - pop pop % Discard seek and post - /enc encs indx get def % Get the indxth encoding - /heights enc length array def - 0 1 enc length 1 sub { - /j exch def - heights j enc j 1 getinterval cvi height mul 5 div put - } for - bhs i 5 mul 1 add heights putinterval % Put encoded digit into sbs - txt i [barcode i 1 getinterval i 5 mul 1 add 3.312 mul textyoffset textfont textsize] put - /checksum checksum indx add def % checksum+=indx - } for +} bind def +/databarstacked dup load /uk.co.terryburton.bwipp defineresource pop +end +/setpacking where {pop setpacking} if +% --END ENCODER databarstacked-- + +% --BEGIN ENCODER databarstackedomni-- +% --REQUIRES databaromni-- +% --DESC: GS1 DataBar Stacked Omnidirectional +% --EXAM: (01)24012345678905 +% --EXOP: +% --RNDR: renmatrix renlinear +/setpacking where {pop currentpacking true setpacking} if +1 dict +dup /renmatrix dup /uk.co.terryburton.bwipp findresource put +dup /databaromni dup /uk.co.terryburton.bwipp findresource put +begin +/databarstackedomni { - % Put the checksum character - /checksum 10 checksum 10 mod sub 10 mod def - /enc encs checksum get def - /heights enc length array def - 0 1 enc length 1 sub { - /j exch def - heights j enc j 1 getinterval cvi height mul 5 div put - } for - bhs barlen 5 mul 1 add heights putinterval - - includecheckintext { - txt barlen [barchars checksum 1 getinterval barlen 5 mul 1 add 3.312 mul textyoffset textfont textsize] put - } { - txt barlen [( ) barlen 5 mul 1 add 72 mul 25 div textyoffset textfont textsize] put - } ifelse - - % Put end character - /enc encs 11 get def - /heights enc length array def - 0 1 enc length 1 sub { - /j exch def - heights j enc j 1 getinterval cvi height mul 5 div put - } for - bhs barlen 5 mul 6 add heights putinterval + 20 dict begin % Confine variables to local scope - % Return the arguments - << - /ren (renlinear) - /bhs bhs - /bbs [bhs length {0} repeat] - /sbs [bhs length 1 sub {1.44 1.872} repeat 1.44] - includetext { - /txt txt + /options exch def % We are given an option string + /barcode exch def % We are given a barcode string + + /dontdraw false def + + % Parse the input options + options type /stringtype eq { + 1 dict begin + options { + token false eq {exit} if dup length string cvs (=) search + true eq {cvlit exch pop exch def} {cvlit true def} ifelse + } loop + currentdict end /options exch def } if - /opt options - >> + options {def} forall - dontdraw not //renlinear if + % Get the result of encoding with databaromni with format=stackedomni + options (dontdraw) true put + options (format) (stackedomni) put + + /args barcode options //databaromni exec def + + args (opt) options put + args + + dontdraw not //renmatrix if end } bind def -% --END ENCODER postnet-- - -% --BEGIN ENCODER royalmail-- -% --DESC: Royal Mail 4 State Customer Code (RM4SCC) -% --EXAM: LE28HS9Z -% --EXOP: includetext includecheckintext barcolor=FF0000 -% --RNDR: renlinear -/royalmail { +/databarstackedomni dup load /uk.co.terryburton.bwipp defineresource pop +end +/setpacking where {pop setpacking} if +% --END ENCODER databarstackedomni-- + +% --BEGIN ENCODER databartruncated-- +% --REQUIRES databaromni-- +% --DESC: GS1 DataBar Truncated +% --EXAM: (01)24012345678905 +% --EXOP: +% --RNDR: renlinear renmatrix +/setpacking where {pop currentpacking true setpacking} if +1 dict +dup /renlinear dup /uk.co.terryburton.bwipp findresource put +dup /databaromni dup /uk.co.terryburton.bwipp findresource put +begin +/databartruncated { - 20 dict begin + 20 dict begin % Confine variables to local scope - /options exch def % We are given an option string - /barcode exch def % We are given a barcode string + /options exch def % We are given an option string + /barcode exch def % We are given a barcode string /dontdraw false def - /includetext false def % Enable/disable text - /includecheckintext false def - /textfont /Courier def - /textsize 10 def - /textyoffset -7 def - /height 0.175 def - + % Parse the input options options type /stringtype eq { 1 dict begin @@ -4466,124 +4276,46 @@ currentdict end /options exch def } if options {def} forall - - /textfont textfont cvlit def - /textsize textsize cvr def - /textyoffset textyoffset cvr def - /height height cvr def - - % Create an array containing the character mappings - /encs - [ (3300) (2211) (2301) (2310) (3201) (3210) - (1122) (0033) (0123) (0132) (1023) (1032) - (1302) (0213) (0303) (0312) (1203) (1212) - (1320) (0231) (0321) (0330) (1221) (1230) - (3102) (2013) (2103) (2112) (3003) (3012) - (3120) (2031) (2121) (2130) (3021) (3030) - (2) (3) - ] def - - % Create a string of the available characters - /barchars (ZUVWXY501234B6789AHCDEFGNIJKLMTOPQRS) def - - /barlen barcode length def - /encstr barlen 4 mul 6 add string def - /txt barlen 1 add array def - - % Put start character - encstr 0 encs 36 get putinterval - - /checksumrow 0 def - /checksumcol 0 def - 0 1 barlen 1 sub { - /i exch def - % Lookup the encoding for the each barcode character - barcode i 1 getinterval barchars exch search - pop % Discard true leaving pre - length /indx exch def % indx is the length of pre - pop pop % Discard seek and post - /enc encs indx get def % Get the indxth encoding - encstr i 4 mul 1 add enc putinterval - txt i [barcode i 1 getinterval i 4 mul 1 add 3.312 mul textyoffset textfont textsize] put - /checksumrow checksumrow indx 6 idiv add def - /checksumcol checksumcol indx 6 mod add def - } for - % Put the checksum character - /checksum checksumrow 6 mod 6 mul checksumcol 6 mod add def - /enc encs checksum get def - encstr barlen 4 mul 1 add enc putinterval - includecheckintext { - txt barlen [barchars checksum 1 getinterval barlen 4 mul 1 add 3.312 mul textyoffset textfont textsize] put - } { - txt barlen [( ) barlen 4 mul 1 add 3.312 mul textyoffset textfont textsize] put - } ifelse - - % Put end character - encstr barlen 4 mul 5 add encs 37 get putinterval + % Get the result of encoding with databaromni with format=truncated + options (dontdraw) true put + options (format) (truncated) put - /bbs encstr length array def - /bhs encstr length array def - 0 1 encstr length 1 sub { - /i exch def - /enc encstr i 1 getinterval def - enc (0) eq { - bbs i 3 height mul 8 div put - bhs i 2 height mul 8 div put - } if - enc (1) eq { - bbs i 0 height mul 8 div put - bhs i 5 height mul 8 div put - } if - enc (2) eq { - bbs i 3 height mul 8 div put - bhs i 5 height mul 8 div put - } if - enc (3) eq { - bbs i 0 height mul 8 div put - bhs i 8 height mul 8 div put - } if - } for - - % Return the arguments - << - /ren (renlinear) - /bbs bbs - /bhs bhs - /sbs [bhs length 1 sub {1.44 1.872} repeat 1.44] - includetext { - /txt txt - } if - /opt options - >> + /args barcode options //databaromni exec def + args (opt) options put + args + dontdraw not //renlinear if end } bind def -% --END ENCODER royalmail-- +/databartruncated dup load /uk.co.terryburton.bwipp defineresource pop +end +/setpacking where {pop setpacking} if +% --END ENCODER databartruncated-- -% --BEGIN ENCODER auspost-- -% --DESC: AusPost 4 State Customer Code -% --EXAM: 5956439111ABA 9 -% --EXOP: includetext custinfoenc=character +% --BEGIN ENCODER databarlimited-- +% --DESC: GS1 DataBar Limited +% --EXAM: (01)15012345678907 +% --EXOP: % --RNDR: renlinear -/auspost { +/setpacking where {pop currentpacking true setpacking} if +1 dict +dup /renlinear dup /uk.co.terryburton.bwipp findresource put +begin +/databarlimited { - 20 dict begin + 20 dict begin % Confine variables to local scope - /options exch def % We are given an option string - /barcode exch def % We are given a barcode string + /options exch def % We are given an option string + /barcode exch def % We are given a barcode string /dontdraw false def - /includetext false def % Enable/disable text - /textfont /Courier def - /textsize 10 def - /textyoffset -7 def - /height 0.175 def - /custinfoenc (character) def - + /height 10 72 div def + /linkage false def + % Parse the input options options type /stringtype eq { 1 dict begin @@ -4594,274 +4326,228 @@ currentdict end /options exch def } if options {def} forall - - /textfont textfont cvlit def - /textsize textsize cvr def - /textyoffset textyoffset cvr def + /height height cvr def - % Create an array containing the character mappings - /encs - [ (000) (001) (002) (010) (011) (012) (020) (021) - (022) (100) (101) (102) (110) (111) (112) (120) - (121) (122) (200) (201) (202) (210) (211) (212) - (220) (221) (222) (300) (301) (302) (310) (311) - (312) (320) (321) (322) (023) (030) (031) (032) - (033) (103) (113) (123) (130) (131) (132) (133) - (203) (213) (223) (230) (231) (232) (233) (303) - (313) (323) (330) (331) (332) (333) (003) (013) - (00) (01) (02) (10) (11) (12) (20) (21) (22) (30) - (13) (3) - ] def - - % Create a string of the available characters - /barchars (ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789abcdefghijklmnopqrstuvwxyz #) def - - /barlen barcode length def - barcode 0 2 getinterval (11) eq {37} if - barcode 0 2 getinterval (45) eq {37} if - barcode 0 2 getinterval (59) eq {52} if - barcode 0 2 getinterval (62) eq {67} if - /encstr exch string def - /txt barlen 2 sub array def + % Strip the AI and optional check digit + barcode length dup 17 eq exch 18 eq or { + barcode 0 5 getinterval dup (\(01\)0) eq exch (\(01\)1) eq or { + /binval [ + barcode 4 13 getinterval {48 sub} forall + ] def + linkage { + /linkval [ 2 0 1 5 1 3 3 5 3 1 0 9 6 ] def + 0 1 binval length 1 sub { + /i exch def + binval i binval i get linkval i get add put + } for + } if + } if + } if - % Put start character - encstr 0 encs 74 get putinterval + % Calculate EAN checksum and add to end of barcode + /checksum 0 def + 0 1 12 { + /i exch def + /checksum checksum barcode i 4 add get 48 sub i 2 mod 0 eq {3 mul} if add def + } for + /checksum 10 checksum 10 mod sub 10 mod def + 18 string + dup 0 barcode 0 17 getinterval putinterval + dup 17 checksum 48 add put + /barcode exch def - % Encode the FCC - 0 1 1 { - /i exch def - encs barcode i 1 getinterval cvi 64 add get - encstr i 2 mul 2 add 3 2 roll putinterval - } for - - % Encode the DPID - 2 1 9 { - /i exch def - encs barcode i 1 getinterval cvi 64 add get - encstr i 2 mul 2 add 3 2 roll putinterval - txt i 2 sub [barcode i 1 getinterval i 2 sub 2 mul 6 add 3.312 mul textyoffset textfont textsize] put + % Create the human readable text + /txt barcode length array def + 0 1 barcode length 1 sub { + /i exch def + txt i [barcode i 1 getinterval 0 0 () 0] put } for - - % Encode the customer information - custinfoenc (numeric) eq { - 0 1 barlen 11 sub { - /i exch def - encs barcode i 10 add 1 getinterval cvi 64 add get - encstr i 2 mul 22 add 3 2 roll putinterval - txt i 8 add [barcode i 10 add 1 getinterval i 2 mul 22 add 3.312 mul textyoffset textfont textsize] put - } for - /ciflen barlen 10 sub 2 mul def - } { - 0 1 barlen 11 sub { - /i exch def - barcode i 10 add 1 getinterval barchars exch search - pop - length /indx exch def - pop pop - /enc encs indx get def - encstr i 3 mul 22 add enc putinterval - txt i 8 add [barcode i 10 add 1 getinterval i 3 mul 22 add 3.312 mul textyoffset textfont textsize] put - } for - /ciflen barlen 10 sub 3 mul def - } ifelse - % Add any filler characters - 22 ciflen add 1 encstr length 14 sub { - encstr exch encs 75 get putinterval - } for - - % Create the 64x64 Reed-Solomon table - /rstable 64 64 mul array def - rstable 0 [ 64 {0} repeat ] putinterval - rstable 64 [ 0 1 63 {} for ] putinterval - /prev 1 def - 64 { - /next prev 1 bitshift def - next 64 and 0 ne { - /next next 67 xor def - } if - 0 1 63 { - /j exch def - /nextcell {rstable 64 next mul j add} def - nextcell rstable 64 prev mul j add get 1 bitshift put - nextcell get 64 and 0 ne { - nextcell nextcell get 67 xor put + /ncr { % n r + 2 copy sub 2 copy lt {exch} if % n r maxd mind + 1 1 5 3 roll % mind j=1 v=1 n maxd + 1 add -1 exch { % mind j v n -1 maxd+1 + mul % mind j v*i + 1 index 3 index le { + 1 index idiv exch 1 add exch } if } for - /prev next def - } repeat + { % mind j v + 1 index 3 index gt {exit} if + 1 index idiv exch 1 add exch + } loop + exch pop exch pop + } bind def - % Calculate the Reed-Solomon codes for triples - /rscodes encstr length 16 sub 3 idiv 4 add array def - rscodes 0 [ 4 {0} repeat ] putinterval - 2 3 encstr length 16 sub { + /getRSSwidths { + /oe exch def + /el exch def + /mw exch def + /nm exch def + /val exch def + /out el array def + /mask 0 def + 0 1 el 2 sub { + /bar exch def + /ew 1 def + /mask mask 1 bar bitshift or def { + /sval nm ew sub 1 sub el bar sub 2 sub ncr def + oe mask 0 eq and nm ew sub el 2 mul sub bar 2 mul add -2 ge and { + /sval sval nm ew sub el sub bar add el bar sub 2 sub ncr sub def + } if + el bar sub 2 gt { + /lval 0 def + nm ew sub el sub bar add 2 add -1 mw 1 add { + nm exch sub ew sub 1 sub el bar sub 3 sub ncr + /lval exch lval add def + } for + /sval sval lval el bar sub 1 sub mul sub def + } { + nm ew sub mw gt {/sval sval 1 sub def} if + } ifelse + /val val sval sub def + val 0 lt {exit} if + /ew ew 1 add def + /mask mask 1 bar bitshift not and def + } loop + /val val sval add def + /nm nm ew sub def + out bar ew put + } for + out el 1 sub nm put + out + } bind def + + 0 1 11 { /i exch def - rscodes rscodes length i 2 sub 3 idiv sub 1 sub - encstr i 1 getinterval cvi 16 mul - encstr i 1 add 1 getinterval cvi 4 mul add - encstr i 2 add 1 getinterval cvi add - put - } for - rscodes length 5 sub -1 0 { - /i exch def - 0 1 4 { - /j exch def - rscodes i j add rscodes i j add get - rstable 64 [48 17 29 30 1] j get mul rscodes i 4 add get add get - xor put - } for + binval i 1 add 2 copy get binval i get 2013571 mod 10 mul add put + binval i binval i get 2013571 idiv put } for - /checkcode (000000000000) 12 string copy def - 0 1 3 { - /i exch def - /enc rscodes 3 i sub get 4 3 string cvrs def - checkcode i 3 mul 3 enc length sub add enc putinterval + /d2 binval 12 get 2013571 mod def + binval 12 2 copy get 2013571 idiv put + + /d1 0 def + /i true def + 0 1 12 { + /j exch def + binval j get + dup 0 eq i and { + pop + } { + /i false def + /d1 d1 3 -1 roll 10 12 j sub exp cvi mul add def + } ifelse } for - % Put checkcode and end characters - encstr encstr length 14 sub checkcode putinterval - encstr encstr length 2 sub encs 74 get putinterval + /tab267 [ + 183063 0 17 9 6 3 6538 28 + 820063 183064 13 13 5 4 875 728 + 1000775 820064 9 17 3 6 28 6454 + 1491020 1000776 15 11 5 4 2415 203 + 1979844 1491021 11 15 4 5 203 2408 + 1996938 1979845 19 7 8 1 17094 1 + 2013570 1996939 7 19 1 8 1 16632 + ] def - /bbs encstr length array def - /bhs encstr length array def - 0 1 encstr length 1 sub { - /i exch def - /enc encstr i 1 getinterval def - enc (0) eq { - bbs i 0 height mul 8 div put - bhs i 8 height mul 8 div put - } if - enc (1) eq { - bbs i 3 height mul 8 div put - bhs i 5 height mul 8 div put - } if - enc (2) eq { - bbs i 0 height mul 8 div put - bhs i 5 height mul 8 div put + /i 0 def { + d1 tab267 i get le { + tab267 i 1 add 7 getinterval {} forall + /d1te exch def /d1to exch def + /d1mwe exch def /d1mwo exch def + /d1ele exch def /d1elo exch def + /d1gs exch def + exit } if - enc (3) eq { - bbs i 3 height mul 8 div put - bhs i 2 height mul 8 div put + /i i 8 add def + } loop + + /i 0 def { + d2 tab267 i get le { + tab267 i 1 add 7 getinterval {} forall + /d2te exch def /d2to exch def + /d2mwe exch def /d2mwo exch def + /d2ele exch def /d2elo exch def + /d2gs exch def + exit } if - } for - - % Return the arguments - << - /ren (renlinear) - /bbs bbs - /bhs bhs - /sbs [bhs length 1 sub {1.44 1.872} repeat 1.44] - includetext { - /txt txt - } if - /opt options - >> - - dontdraw not //renlinear if - - end - -} bind def -% --END ENCODER auspost-- + /i i 8 add def + } loop -% --BEGIN ENCODER kix-- -% --DESC: Royal Dutch TPG Post KIX 4-State Barcode -% --EXAM: 1231FZ13XHS -% --EXOP: includetext includecheckintext -% --RNDR: renlinear -/kix { + /d1wo d1 d1gs sub d1te idiv d1elo d1mwo 7 false getRSSwidths def + /d1we d1 d1gs sub d1te mod d1ele d1mwe 7 true getRSSwidths def + /d2wo d2 d2gs sub d2te idiv d2elo d2mwo 7 false getRSSwidths def + /d2we d2 d2gs sub d2te mod d2ele d2mwe 7 true getRSSwidths def - 20 dict begin + /d1w 14 array def + 0 1 6 { + /i exch def + d1w i 2 mul d1wo i get put + d1w i 2 mul 1 add d1we i get put + } for - /options exch def % We are given an option string - /barcode exch def % We are given a barcode string + /d2w 14 array def + 0 1 6 { + /i exch def + d2w i 2 mul d2wo i get put + d2w i 2 mul 1 add d2we i get put + } for - /dontdraw false def - /includetext false def % Enable/disable text - /includecheckintext false def - /textfont /Courier def - /textsize 10 def - /textyoffset -7 def - /height 0.175 def - - % Parse the input options - options type /stringtype eq { - 1 dict begin - options { - token false eq {exit} if dup length string cvs (=) search - true eq {cvlit exch pop exch def} {cvlit true def} ifelse - } loop - currentdict end /options exch def - } if - options {def} forall - - /textfont textfont cvlit def - /textsize textsize cvr def - /textyoffset textyoffset cvr def - /height height cvr def + /widths [ + d1w {} forall + d2w {} forall + ] def - % Create an array containing the character mappings - /encs - [ (0033) (0123) (0132) (1023) (1032) (1122) - (0213) (0303) (0312) (1203) (1212) (1302) - (0231) (0321) (0330) (1221) (1230) (1320) - (2013) (2103) (2112) (3003) (3012) (3102) - (2031) (2121) (2130) (3021) (3030) (3120) - (2211) (2301) (2310) (3201) (3210) (3300) + /checkweights [ + 1 3 9 27 81 65 17 51 64 14 42 37 22 66 + 20 60 2 6 18 54 73 41 34 13 39 28 84 74 ] def - % Create a string of the available characters - /barchars (0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ) def - - /barlen barcode length def - /encstr barlen 4 mul string def - /txt barlen array def - - 0 1 barlen 1 sub { + /checkseq [ + 0 1 43 {} for + 45 52 57 + 63 1 66 {} for + 73 1 79 {} for + 82 + 126 1 130 {} for + 132 + 141 1 146 {} for + 210 1 217 {} for + 220 + 316 1 320 {} for + 322 323 + 326 337 + ] def + + /checksum 0 def + 0 1 27 { /i exch def - % Lookup the encoding for the each barcode character - barcode i 1 getinterval barchars exch search - pop % Discard true leaving pre - length /indx exch def % indx is the length of pre - pop pop % Discard seek and post - /enc encs indx get def % Get the indxth encoding - encstr i 4 mul enc putinterval - txt i [barcode i 1 getinterval i 4 mul 3.312 mul textyoffset textfont textsize] put + /checksum checksum widths i get checkweights i get mul add def } for + /checksum checksum 89 mod def + /seq checkseq checksum get def + /swidths seq 21 idiv 8 3 6 false getRSSwidths def + /bwidths seq 21 mod 8 3 6 false getRSSwidths def - /bbs encstr length array def - /bhs encstr length array def - 0 1 encstr length 1 sub { + /checkwidths [0 0 0 0 0 0 0 0 0 0 0 0 1 1] def + 0 1 5 { /i exch def - /enc encstr i 1 getinterval def - enc (0) eq { - bbs i 3 height mul 8 div put - bhs i 2 height mul 8 div put - } if - enc (1) eq { - bbs i 0 height mul 8 div put - bhs i 5 height mul 8 div put - } if - enc (2) eq { - bbs i 3 height mul 8 div put - bhs i 5 height mul 8 div put - } if - enc (3) eq { - bbs i 0 height mul 8 div put - bhs i 8 height mul 8 div put - } if + checkwidths i 2 mul swidths i get put + checkwidths i 2 mul 1 add bwidths i get put } for + /sbs [ + 1 d1w {} forall checkwidths {} forall d2w {} forall 1 1 + ] def + % Return the arguments << - /ren (renlinear) - /bbs bbs - /bhs bhs - /sbs [bhs length 1 sub {1.44 1.872} repeat 1.44] - includetext { - /txt txt - } if + /ren //renlinear + /sbs sbs + /bhs [sbs length 1 add 2 idiv {height} repeat] + /bbs [sbs length 1 add 2 idiv {0} repeat] + /txt txt + /textxalign (center) /opt options >> @@ -4870,28 +4556,34 @@ end } bind def -% --END ENCODER kix-- +/databarlimited dup load /uk.co.terryburton.bwipp defineresource pop +end +/setpacking where {pop setpacking} if +% --END ENCODER databarlimited-- -% --BEGIN ENCODER japanpost-- -% --DESC: Japan Post 4 State Customer Code -% --EXAM: 6540123789-A-K-Z -% --EXOP: includetext includecheckintext -% --RNDR: renlinear -/japanpost { +% --BEGIN ENCODER databarexpanded-- +% --DESC: GS1 DataBar Expanded +% --EXAM: (01)95012345678903(3103)000123 +% --EXOP: +% --RNDR: renlinear renmatrix +/setpacking where {pop currentpacking true setpacking} if +1 dict +dup /renlinear dup /uk.co.terryburton.bwipp findresource put +dup /renmatrix dup /uk.co.terryburton.bwipp findresource put +begin +/databarexpanded { - 20 dict begin + 20 dict begin % Confine variables to local scope - /options exch def % We are given an option string - /barcode exch def % We are given a barcode string + /options exch def % We are given an option string + /barcode exch def % We are given a barcode string /dontdraw false def - /includetext false def % Enable/disable text - /includecheckintext false def - /textfont /Courier def - /textsize 10 def - /textyoffset -7 def - /height 0.175 def - + /height 34 72 div def + /format (expanded) def + /segments -1 def + /linkage false def + % Parse the input options options type /stringtype eq { 1 dict begin @@ -4903,683 +4595,7263 @@ } if options {def} forall - /textfont textfont cvlit def - /textsize textsize cvr def - /textyoffset textyoffset cvr def /height height cvr def - - % Create an array containing the character mappings - % 0123456789- C1C2C3C4C5C6C7C8 ST EN - /encs - [ (300) (330) (312) (132) (321) (303) (123) (231) (213) (033) (030) - (120) (102) (210) (012) (201) (021) (003) (333) - (31) (13) - ] def - - % Create a string of the available characters - /barchars (0123456789-ABCDEFGHIJKLMNOPQRSTUVWXYZ) def - /barlen barcode length def - - /encstr 20 1 add 3 mul 4 add string def - /digits 20 array def - /txt barlen 1 add array def - - % Put start character - encstr 0 encs 19 get putinterval - - /checksum 0 def - /j 0 def /i 0 def - 0 1 barlen 1 sub { - /i exch def - barcode i 1 getinterval barchars exch search - pop % Discard true leaving pre - length /indx exch def % indx is the length of pre - pop pop % Discard match and post - indx 11 ge indx 37 lt and { % Insert escape - j 18 gt {exit} if % Should fit in 20 chars - % 11-20: C1 (11) - % 21-30: C2 (12) - % 31-36: C3 (13) - /digit indx 1 sub 10 idiv 10 add def - encstr j 3 mul 2 add encs digit get putinterval - /checksum checksum digit add def - digits j digit put - /j j 1 add def - } if - j 19 gt {exit} if % Should fit in 20 chars - /digit 0 def - indx 37 eq { - /digit 14 def % space (C14) - } if - indx 11 ge indx 37 lt and { - /digit indx 1 sub 10 mod def - } if - indx 11 lt { - /digit indx def - } if - encstr j 3 mul 2 add encs digit get putinterval % space - /checksum checksum digit add def - digits j digit put - txt i [barcode i 1 getinterval j 3 mul 2 add 3.312 mul textyoffset textfont textsize] put - /j j 1 add def - } for + /segments segments cvi def - % Fill spaces (c14) at right end - j 1 20 1 sub { - /k exch def - encstr k 3 mul 2 add encs 14 get putinterval - /checksum checksum 14 add def - digits k 14 put - } for + segments -1 eq { + /segments format (expandedstacked) eq {4} {22} ifelse def + } if - % Put the checksum character - /checksum checksum 19 mod 19 exch sub def - encstr 2 20 3 mul add encs checksum get putinterval - - % Put end character - encstr 2 21 3 mul add encs 20 get putinterval - /checkdigit ( ) def - includecheckintext { - /checkdigit barchars checksum 1 getinterval def - } if - txt i 1 add [ checkdigit 20 3 mul 2 add 3.312 mul textyoffset textfont textsize] put - - % Put end character - encstr 20 1 add 3 mul 2 add encs 20 get putinterval - - /bbs 21 3 mul 4 add array def - /bhs bbs length array def - 0 1 bbs length 1 sub { - /i exch def - /enc encstr i 1 getinterval def - /bunit 0 def - /hunit 0 def - enc (0) eq { - /bunit 3 def - /hunit 2 def + % Expand ordinals of the form ^NNN to ASCII + /expand { + /in exch def + /out in length string def + /j 0 def + in + { % loop + (^) search { + dup out exch j exch putinterval + length j add 1 add /j exch def + pop + dup 0 3 getinterval cvi out exch j 1 sub exch put + dup length 3 sub 3 exch getinterval + } { + dup out exch j exch putinterval + length j add /j exch def + out 0 j getinterval exit + } ifelse + } loop + } bind def + + % Parse out AIs + /ais [] def + /aival 2 dict def + barcode dup length 1 sub 1 exch getinterval + { % loop + dup () eq {exit} if + (\)) search pop + exch pop + exch (\() search { + exch pop exch 3 1 roll + } { + () 3 1 roll + } ifelse + [ ais aload pop counttomark 2 add index ] /ais exch def + aival 3 1 roll expand put + } loop + pop + + % Method selection + { % common exit + + % (01)9...(3103)... + ais length 2 eq { + ais 0 get (01) eq ais 1 get (3103) eq and { + aival (01) get 0 1 getinterval (9) eq aival (3103) get cvi 32767 le and { + (0100) false exit + } if + } if } if - enc (1) eq { - /bunit 0 def - /hunit 5 def + + % (01)9...(3202)... + ais length 2 eq { + ais 0 get (01) eq ais 1 get (3202) eq and { + aival (01) get 0 1 getinterval (9) eq aival (3202) get cvi 9999 le and { + (0101) false exit + } if + } if } if - enc (2) eq { - /bunit 3 def - /hunit 5 def + + % (01)9...(3203)... + ais length 2 eq { + ais 0 get (01) eq ais 1 get (3203) eq and { + aival (01) get 0 1 getinterval (9) eq aival (3203) get cvi 22767 le and { + (0101) false exit + } if + } if } if - enc (3) eq { - /bunit 0 def - /hunit 8 def + + % (01)9...(310x/320x)...[(11/13/15/17)...] + ais length dup 2 eq exch 3 eq or { + /ai310x false 3100 1 3109 {10 4 string cvrs ais 1 get eq or} for def + /ai320x false 3200 1 3209 {10 4 string cvrs ais 1 get eq or} for def + ais length 3 eq { + /aibad true [ (11) (13) (15) (17) ] {ais 2 get ne and} forall def + } { + /aibad false def + } ifelse + ais 0 get (01) eq ai310x ai320x or and aibad not and { + ais length 3 eq { + aival (01) get 0 1 getinterval (9) eq + aival ais 1 get get cvi 99999 le and + aival ais 2 get get cvi 999999 le and { + ai310x ais 2 get (11) eq and { (0111000) false exit } if + ai320x ais 2 get (11) eq and { (0111001) false exit } if + ai310x ais 2 get (13) eq and { (0111010) false exit } if + ai320x ais 2 get (13) eq and { (0111011) false exit } if + ai310x ais 2 get (15) eq and { (0111100) false exit } if + ai320x ais 2 get (15) eq and { (0111101) false exit } if + ai310x ais 2 get (17) eq and { (0111110) false exit } if + ai320x ais 2 get (17) eq and { (0111111) false exit } if + } if + } { + aival (01) get 0 1 getinterval (9) eq + aival ais 1 get get cvi 99999 le and { + ai310x { (0111000) false exit } if + ai320x { (0111001) false exit } if + } if + } ifelse + } if } if - bbs i bunit height mul 8 div put - bhs i hunit height mul 8 div put - } for - - % Return the arguments - << - /ren (renlinear) - /bbs bbs - /bhs bhs - /sbs [bhs length 1 sub {1.44 1.872} repeat 1.44] - includetext { - /txt txt + + % (01)9...(392x)... + ais length 2 ge { + /ai392x false 3920 1 3923 {10 4 string cvrs ais 1 get eq or} for def + ais 0 get (01) eq ai392x and { + aival (01) get 0 1 getinterval (9) eq { (01100) true exit } if + } if + } if + + % (01)9...(393x)... + ais length 2 ge { + /ai393x false 3930 1 3933 {10 4 string cvrs ais 1 get eq or} for def + ais 0 get (01) eq ai393x and { + aival (01) get 0 1 getinterval (9) eq { (01101) true exit } if + } if + } if + + % (01)... + ais 0 get (01) eq { (1) true exit } if + + % Freeform + (00) true exit + + } loop + /gpfallow exch def + /method exch def + + /conv12to40 { + (0000000000000000000000000000000000000000) 40 string copy + 2 copy 0 10 getinterval exch 0 3 getinterval cvi 2 10 string cvrs dup length 10 exch sub exch putinterval + 2 copy 10 10 getinterval exch 3 3 getinterval cvi 2 10 string cvrs dup length 10 exch sub exch putinterval + 2 copy 20 10 getinterval exch 6 3 getinterval cvi 2 10 string cvrs dup length 10 exch sub exch putinterval + 2 copy 30 10 getinterval exch 9 3 getinterval cvi 2 10 string cvrs dup length 10 exch sub exch putinterval + exch pop + } bind def + + /conv13to44 { + (00000000000000000000000000000000000000000000) 44 string copy + 2 copy 0 4 getinterval exch 0 1 getinterval cvi 2 4 string cvrs dup length 4 exch sub exch putinterval + dup 3 -1 roll 1 12 getinterval conv12to40 4 exch putinterval + } bind def + + /tobin { + string dup length 1 sub 0 exch 1 exch {1 index exch 48 put} for + dup 3 -1 roll 2 2 index length string cvrs dup length 2 index length exch sub exch putinterval + } bind def + + method (00) eq { + /cdf [] def + /gpf [] def } if - /opt options - >> - - dontdraw not //renlinear if - - end - -} bind def -% --END ENCODER japanpost-- - -% --BEGIN ENCODER msi-- -% --DESC: MSI Modified Plessey -% --EXAM: 0123456789 -% --EXOP: includetext includecheck includecheckintext -% --RNDR: renlinear -/msi { - - 20 dict begin % Confine variables to local scope - - /options exch def % We are given an option string - /barcode exch def % We are given a barcode string - - /dontdraw false def - /includecheck false def % Enable/disable checkdigit - /includetext false def % Enable/disable text - /includecheckintext false def - /textfont /Courier def - /textsize 10 def - /textyoffset -7 def - /height 1 def - % Parse the input options - options type /stringtype eq { - 1 dict begin - options { - token false eq {exit} if dup length string cvs (=) search - true eq {cvlit exch pop exch def} {cvlit true def} ifelse - } loop - currentdict end /options exch def + method (1) eq { + /cdf aival (01) get 0 13 getinterval conv13to44 def + /cdf [ cdf {48 sub} forall ] def + /gpf [] def + /ais ais 1 ais length 1 sub getinterval def } if - options {def} forall - /textfont textfont cvlit def - /textsize textsize cvr def - /textyoffset textyoffset cvr def - /height height cvr def + method (0100) eq { + /cdf 55 string def + cdf 0 aival (01) get 1 12 getinterval conv12to40 putinterval + cdf 40 aival (3103) get cvi 15 tobin putinterval + /cdf [ cdf {48 sub} forall ] def + /gpf [] def + /ais [] def + } if - % Create an array containing the character mappings - /encs - [ (13131313) (13131331) (13133113) (13133131) (13311313) - (13311331) (13313113) (13313131) (31131313) (31131331) - (31) (131) - ] def - - % Create a string of the available characters - /barchars (0123456789) def - - /barlen barcode length def % Length of the code - - includecheck { - /sbs barlen 8 mul 13 add string def - /txt barlen 1 add array def - } { - /sbs barlen 8 mul 5 add string def - /txt barlen array def - } ifelse - - % Put start character - sbs 0 encs 10 get putinterval - /checksum 0 def - - 0 1 barlen 1 sub { - /i exch def - % Lookup the encoding for the each barcode character - barcode i 1 getinterval barchars exch search - pop % Discard true leaving pre - length /indx exch def % indx is the length of pre - pop pop % Discard seek and post - /enc encs indx get def % Get the indxth encoding - sbs i 8 mul 2 add enc putinterval % Put encoded digit into sbs - txt i [barcode i 1 getinterval i 16 mul 4 add textyoffset textfont textsize] put - barlen i sub 2 mod 0 eq { - /checksum indx checksum add def + method (0101) eq { + /cdf 55 string def + cdf 0 aival (01) get 1 12 getinterval conv12to40 putinterval + ais 1 get (3202) eq { + aival (3202) get cvi 15 tobin } { - /checksum indx 2 mul dup 10 idiv add checksum add def + aival (3203) get cvi 10000 add 15 tobin } ifelse - } for - - % Put the checksum and end characters - includecheck { - /checksum 10 checksum 10 mod sub 10 mod def - sbs barlen 8 mul 2 add encs checksum get putinterval - includecheckintext { - txt barlen [barchars checksum 1 getinterval barlen 16 mul 4 add textyoffset textfont textsize] put + cdf exch 40 exch putinterval + /cdf [ cdf {48 sub} forall ] def + /gpf [] def + /ais [] def + } if + + method length 7 eq { + /cdf 76 string def + cdf 0 aival (01) get 1 12 getinterval conv12to40 putinterval + 6 string dup 0 ais 1 get 3 1 getinterval putinterval + dup aival ais 1 get get 1 5 getinterval 1 exch putinterval cvi 20 tobin + cdf exch 40 exch putinterval + ais length 3 eq { + aival ais 2 get get + dup 0 2 getinterval cvi 384 mul exch + dup 2 2 getinterval cvi 1 sub 32 mul exch + 4 2 getinterval cvi add add } { - txt barlen [( ) barlen 16 mul 4 add textyoffset textfont textsize] put + 38400 } ifelse - sbs barlen 8 mul 10 add encs 11 get putinterval - } { - sbs barlen 8 mul 2 add encs 11 get putinterval - } ifelse - - % Return the arguments - << - /ren (renlinear) - /sbs [sbs {48 sub} forall] - /bhs [sbs length 1 add 2 idiv {height} repeat] - /bbs [sbs length 1 add 2 idiv {0} repeat] - includetext { - /txt txt + 16 tobin cdf exch 60 exch putinterval + /cdf [ cdf {48 sub} forall ] def + /gpf [] def + /ais [] def } if - /opt options - >> - - dontdraw not //renlinear if - - end - -} bind def -% --END ENCODER msi-- - -% --BEGIN ENCODER plessey-- -% --DESC: Plessey -% --EXAM: 01234ABCD -% --EXOP: includetext includecheckintext -% --RNDR: renlinear -/plessey { - - 20 dict begin % Confine variables to local scope - - /options exch def % We are given an option string - /barcode exch def % We are given a barcode string - - /dontdraw false def - /includetext false def % Enable/disable text - /includecheckintext false def - /textfont /Courier def - /textsize 10 def - /textyoffset -7 def - /height 1 def - % Parse the input options - options type /stringtype eq { - 1 dict begin - options { - token false eq {exit} if dup length string cvs (=) search - true eq {cvlit exch pop exch def} {cvlit true def} ifelse - } loop - currentdict end /options exch def + method (01100) eq { + /cdf 42 string def + cdf 0 aival (01) get 1 12 getinterval conv12to40 putinterval + cdf 40 ais 1 get 3 1 getinterval cvi 2 tobin putinterval + /cdf [ cdf {48 sub} forall ] def + /gpf [ aival ais 1 get get {} forall ] def + /ais ais 2 ais length 2 sub getinterval def } if - options {def} forall - - /textfont textfont cvlit def - /textsize textsize cvr def - /textyoffset textyoffset cvr def - /height height cvr def - % Create an array containing the character mappings - /encs - [ (13131313) (31131313) (13311313) (31311313) - (13133113) (31133113) (13313113) (31313113) - (13131331) (31131331) (13311331) (31311331) - (13133131) (31133131) (13313131) (31313131) - (31311331) (331311313) - ] def - - % Create a string of the available characters - /barchars (0123456789ABCDEF) def - - /barlen barcode length def % Length of the code - /sbs barlen 8 mul 33 add string def - /txt barlen 2 add array def - /checkbits barlen 4 mul 8 add array def - checkbits barlen 4 mul [ 0 0 0 0 0 0 0 0 ] putinterval - - % Put start character - sbs 0 encs 16 get putinterval - - 0 1 barlen 1 sub { - /i exch def - % Lookup the encoding for the each barcode character - barcode i 1 getinterval barchars exch search - pop % Discard true leaving pre - length /indx exch def % indx is the length of pre - pop pop % Discard seek and post - /enc encs indx get def % Get the indxth encoding - sbs i 8 mul 8 add enc putinterval % Put encoded digit into sbs - txt i [barcode i 1 getinterval i 16 mul 16 add textyoffset textfont textsize] put - checkbits i 4 mul [ - indx 1 and - indx -1 bitshift 1 and - indx -2 bitshift 1 and - indx -3 bitshift - ] putinterval - } for + method (01101) eq { + /cdf 52 string def + cdf 0 aival (01) get 1 12 getinterval conv12to40 putinterval + cdf 40 ais 1 get 3 1 getinterval cvi 2 tobin putinterval + cdf 42 aival ais 1 get get 0 3 getinterval cvi 10 tobin putinterval + /cdf [ cdf {48 sub} forall ] def + /gpf [ aival ais 1 get get dup length 3 sub 3 exch getinterval {} forall ] def + /ais ais 2 ais length 2 sub getinterval def + } if + + % Variable length symbol field + gpfallow { + /vlf 2 array def + } { + /vlf [] def + } ifelse + + % Pre-defined fixed length data field AIs + % any AI whose prefix is not included in this table must be + % terminated with "FNC1", even if it's fixed length + /aifixed 23 dict def + [ + 0 1 4 {} for + ] { + (00) 2 string copy dup dup 1 5 -1 roll 48 add put aifixed 3 1 roll put + } forall + [ + 11 1 20 {} for + 23 + 31 1 36 {} for + 41 + ] { + 10 2 string cvrs dup aifixed 3 1 roll put + } forall - % Checksum is last 8 bits of a CRC using a salt - /checksalt [ 1 1 1 1 0 1 0 0 1 ] def - 0 1 barlen 4 mul 1 sub { + /fnc1 -1 def /lnumeric -2 def /lalphanumeric -3 def /liso646 -4 def + + /numeric << + 0 1 119 { + dup (00) 2 string copy dup 3 -1 roll 11 2 string cvrs + dup length 2 exch sub exch putinterval + dup 0 get 65 eq {dup 0 94 put} if + dup 1 get 65 eq {dup 1 94 put} if + exch 8 add + (0000000) 7 string copy dup 3 -1 roll 2 7 string cvrs + dup length 7 exch sub exch putinterval + } for + lalphanumeric (0000) + >> def + + /alphanumeric << + 48 1 57 {dup 43 sub 5 tobin} for + fnc1 (01111) + 65 1 90 {dup 33 sub 6 tobin} for + 42 (111010) + 44 1 47 {dup 15 add 6 tobin} for + lnumeric (000) + liso646 (00100) + >> def + + /iso646 << + 48 1 57 {dup 43 sub 5 tobin} for + fnc1 (01111) + 65 1 90 {dup 1 sub 7 tobin} for + 97 1 122 {dup 7 sub 7 tobin} for + 33 (11101000) + 34 (11101001) + 37 1 47 {dup 197 add 8 tobin} for + 58 1 63 {dup 187 add 8 tobin} for + 95 (11111011) + 32 (11111100) + lnumeric (000) + lalphanumeric (00100) + >> def + + % Append the remaining AI data + 0 1 ais length 1 sub { /i exch def - checkbits i get 1 eq { - 0 1 8 { - /j exch def - checkbits i j add checkbits i j add get checksalt j get xor put - } for + /ai ais i get def + /val aival ai get def + gpf length ai length add val length add array + dup 0 gpf putinterval + dup gpf length ai [ exch {} forall ] putinterval + dup gpf length ai length add val [ exch {} forall ] putinterval + /gpf exch def + i ais length 1 sub ne aifixed ai 0 2 getinterval known not and { % Append FNC1 + gpf length 1 add array + dup 0 gpf putinterval + dup gpf length fnc1 put + /gpf exch def } if } for - - % Calculate the value of the checksum digits - /checkval 0 def - 0 1 7 { + + % Calculate the number of bits remaining to the next valid symbol size + /rembits { + dup + 12 div ceiling cvi 12 mul % Round up to multiple of 12 + 48 2 copy lt {exch} if pop % At least 4 symbols + dup 12 idiv dup segments mod 1 eq { % At least 2 symbols on last row of stacked symbol + 1 add 12 mul exch pop + } { + pop + } ifelse + exch sub + } bind def + + /encode { + dup /raw ne {exch get} {pop} ifelse + [ exch {48 sub} forall ] + dup length exch + gpfenc exch j exch putinterval + /j exch j add def + } bind def + + % Pre-compute alphanumeric and numeric runlengths and position of next ISO646-only characters + /numericruns [ gpf length {0} repeat 0 -1 ] def + /alphanumericruns [ gpf length {0} repeat 0 ] def + /nextiso646only [ gpf length {0} repeat 9999 ] def + gpf length 1 sub -1 0 { /i exch def - /checkval checkval 2 7 i sub exp cvi checkbits barlen 4 mul i add get mul add def - } for - - % Put the checksum characters - /checksum1 checkval -4 bitshift def - /checksum2 checkval 15 and def - sbs barlen 8 mul 8 add encs checksum1 get putinterval - sbs barlen 8 mul 16 add encs checksum2 get putinterval - includecheckintext { - txt barlen [barchars checksum1 1 getinterval barlen 16 mul 16 add textyoffset textfont textsize] put - txt barlen 1 add [barchars checksum2 1 getinterval barlen 1 add 16 mul 16 add textyoffset textfont textsize] put + gpf i get + (00) 2 string copy + dup 0 gpf i get dup fnc1 eq {pop 94} if put + i gpf length 1 sub lt {dup 1 gpf i 1 add get dup fnc1 eq {pop 94} if put} if + numeric exch known { + numericruns i numericruns i 2 add get 2 add put + } { + numericruns i 0 put + } ifelse + dup alphanumeric exch known { + alphanumericruns i alphanumericruns i 1 add get 1 add put + } { + alphanumericruns i 0 put + } ifelse + dup iso646 exch known exch alphanumeric exch known not and { + nextiso646only i 0 put + } { + nextiso646only i nextiso646only i 1 add get 1 add put + } ifelse + } for + + % Encode the general purpose field + /gpfenc 252 array def + /i 0 def /j 0 def /mode (numeric) def + { % loop + i gpf length eq {exit} if + { % not a loop but common exit point + + mode (numeric) eq { + i gpf length 2 sub le { + 2 string + dup 0 gpf i get dup fnc1 eq {pop 94} if put + dup 1 gpf i 1 add get dup fnc1 eq {pop 94} if put + dup numeric exch known { + numeric encode + /i i 2 add def + exit + } if + pop + lalphanumeric numeric encode + /mode (alphanumeric) def + exit + } { + gpf i get dup 48 lt exch 57 gt or { + lalphanumeric numeric encode + /mode (alphanumeric) def + exit + } if + /rem 12 1 add method length add vlf length add cdf length add j add rembits def + rem 4 ge rem 6 le and { % C1 + 1 into 4 to 6 bits + (000000) 6 string copy 0 rem getinterval + dup gpf i get 47 sub 2 4 string cvrs + dup length 4 exch sub exch putinterval /raw encode + /i i 1 add def + exit + } { % C1.FNC1 + 2 string dup 0 gpf i get put dup 1 94 put numeric encode + /i i 1 add def + exit + } ifelse + } ifelse + } if + + mode (alphanumeric) eq { + gpf i get fnc1 eq { + fnc1 alphanumeric encode + /i i 1 add def + exit + } if + gpf i get dup iso646 exch known exch alphanumeric exch known not and { + liso646 alphanumeric encode + /mode (iso646) def + exit + } if + numericruns i get 6 ge { + lnumeric alphanumeric encode + /mode (numeric) def + exit + } if + numericruns i get dup 4 ge exch i add gpf length eq and { + lnumeric alphanumeric encode + /mode (numeric) def + exit + } if + gpf i get alphanumeric encode + /i i 1 add def + exit + } if + + mode (iso646) eq { + gpf i get fnc1 eq { + fnc1 iso646 encode + /i i 1 add def + exit + } if + numericruns i get 4 ge nextiso646only i get 10 ge and { + lnumeric iso646 encode + /mode (numeric) def + exit + } if + alphanumericruns i get 5 ge nextiso646only i get 10 ge and { + lalphanumeric iso646 encode + /mode (alphanumeric) def + exit + } if + gpf i get iso646 encode + /i i 1 add def + exit + } if + + } loop + } loop + /gpf gpfenc 0 j getinterval def + + % Complete the variable length field and create pad + 1 12 add method length add vlf length add cdf length add gpf length add + dup rembits dup array /pad exch def + vlf length 0 ne { + add 12 idiv + dup 2 mod vlf exch 0 exch put + 14 le {0} {1} ifelse vlf exch 1 exch put } { - txt barlen [( ) barlen 16 mul 16 add textyoffset textfont textsize] put - txt barlen 1 add [( ) barlen 1 add 16 mul 16 add textyoffset textfont textsize] put + pop pop } ifelse - - % Put end character - sbs barlen 8 mul 24 add encs 17 get putinterval - - % Return the arguments - << - /ren (renlinear) - /sbs [sbs {48 sub} forall] - /bhs [sbs length 1 add 2 idiv {height} repeat] - /bbs [sbs length 1 add 2 idiv {0} repeat] - includetext { - /txt txt + pad length 0 gt { + 0 5 pad length 1 sub { % Fill with 00100 + /i exch def + pad i [ 0 0 1 0 0 ] 0 pad length i sub 5 2 copy gt {exch} if pop getinterval putinterval + } for + mode (numeric) eq { % Prefix shift from numeric to ASCII + /pad [ 0 0 0 0 pad aload pop ] 0 pad length getinterval def + } if } if - /opt options - >> + + % Concatinate fields + /binval [ + linkage {1} {0} ifelse + method {48 sub} forall + vlf aload pop + cdf aload pop + gpf aload pop + pad aload pop + ] def + /datalen binval length 12 idiv def + + /ncr { % n r + 2 copy sub 2 copy lt {exch} if % n r maxd mind + 1 1 5 3 roll % mind j=1 v=1 n maxd + 1 add -1 exch { % mind j v n -1 maxd+1 + mul % mind j v*i + 1 index 3 index le { + 1 index idiv exch 1 add exch + } if + } for + { % mind j v + 1 index 3 index gt {exit} if + 1 index idiv exch 1 add exch + } loop + exch pop exch pop + } bind def + + /getRSSwidths { + /oe exch def + /el exch def + /mw exch def + /nm exch def + /val exch def + /out el array def + /mask 0 def + 0 1 el 2 sub { + /bar exch def + /ew 1 def + /mask mask 1 bar bitshift or def { + /sval nm ew sub 1 sub el bar sub 2 sub ncr def + oe mask 0 eq and nm ew sub el 2 mul sub bar 2 mul add -2 ge and { + /sval sval nm ew sub el sub bar add el bar sub 2 sub ncr sub def + } if + el bar sub 2 gt { + /lval 0 def + nm ew sub el sub bar add 2 add -1 mw 1 add { + nm exch sub ew sub 1 sub el bar sub 3 sub ncr + /lval exch lval add def + } for + /sval sval lval el bar sub 1 sub mul sub def + } { + nm ew sub mw gt {/sval sval 1 sub def} if + } ifelse + /val val sval sub def + val 0 lt {exit} if + /ew ew 1 add def + /mask mask 1 bar bitshift not and def + } loop + /val val sval add def + /nm nm ew sub def + out bar ew put + } for + out el 1 sub nm put + out + } bind def - dontdraw not //renlinear if + /tab174 [ + 347 0 12 5 7 2 87 4 + 1387 348 10 7 5 4 52 20 + 2947 1388 8 9 4 5 30 52 + 3987 2948 6 11 3 6 10 104 + 4191 3988 4 13 1 8 1 204 + ] def - end + /dxw datalen array def + + 0 1 datalen 1 sub { -} bind def -% --END ENCODER plessey-- + /x exch def -% --BEGIN ENCODER raw-- -% --DESC: Raw bar space succession for custom symbologies -% --EXAM: 331132131313411122131311333213114131131221323 -% --EXOP: height=0.5 -% --RNDR: renlinear -/raw { + /d binval x 12 mul 12 getinterval def + /d 0 0 1 11 {/j exch def 2 11 j sub exp cvi d j get mul add} for def - 20 dict begin % Confine variables to local scope + /j 0 def { + d tab174 j get le { + tab174 j 1 add 7 getinterval {} forall + /dte exch def /dto exch def + /dmwe exch def /dmwo exch def + /dele exch def /delo exch def + /dgs exch def + exit + } if + /j j 8 add def + } loop - /options exch def % We are given an option string - /sbs exch def % We are given a barcode string + /dwo d dgs sub dte idiv delo dmwo 4 true getRSSwidths def + /dwe d dgs sub dte mod dele dmwe 4 false getRSSwidths def - /dontdraw false def - /height 1 def + /dw 8 array def + x 2 mod 0 eq { + 0 1 3 { + /j exch def + dw 7 j 2 mul sub dwo j get put + dw 6 j 2 mul sub dwe j get put + } for + } { + 0 1 3 { + /j exch def + dw j 2 mul dwo j get put + dw j 2 mul 1 add dwe j get put + } for + } ifelse - % Parse the input options - options type /stringtype eq { - 1 dict begin - options { - token false eq {exit} if dup length string cvs (=) search - true eq {cvlit exch pop exch def} {cvlit true def} ifelse - } loop - currentdict end /options exch def - } if - options {def} forall + dxw x dw put - /height height cvr def + } for + + /finderwidths [ + 1 8 4 1 1 1 1 4 8 1 + 3 6 4 1 1 1 1 4 6 3 + 3 4 6 1 1 1 1 6 4 3 + 3 2 8 1 1 1 1 8 2 3 + 2 6 5 1 1 1 1 5 6 2 + 2 2 9 1 1 1 1 9 2 2 + ] def - % Return the arguments - << - /ren (renlinear) - /sbs [sbs {48 sub} forall] - /bhs [sbs length 1 add 2 idiv {height} repeat] - /bbs [sbs length 1 add 2 idiv {0} repeat] - /opt options - >> + /finderseq [ + [0 1] + [0 3 2] + [0 5 2 7] + [0 9 2 7 4] + [0 9 2 7 6 11] + [0 9 2 7 8 11 10] + [0 1 2 3 4 5 6 7] + [0 1 2 3 4 5 6 9 8] + [0 1 2 3 4 5 6 9 10 11] + [0 1 2 3 4 7 6 9 8 11 10] + ] def - dontdraw not //renlinear if + /seq finderseq datalen 2 sub 2 idiv get def + /fxw seq length array def + 0 1 seq length 1 sub { + /x exch def + fxw x finderwidths seq x get 5 mul 5 getinterval put + } for - end + /checkweights [ + -1 -1 -1 -1 -1 -1 -1 -1 % A1L + 77 96 32 81 27 9 3 1 % A1R + 20 60 180 118 143 7 21 63 % A2L + 205 209 140 117 39 13 145 189 % A2R + 193 157 49 147 19 57 171 91 % B1L + 132 44 85 169 197 136 186 62 % B1R + 185 133 188 142 4 12 36 108 % B2L + 50 87 29 80 97 173 128 113 % B2R + 150 28 84 41 123 158 52 156 % C1L + 166 196 206 139 187 203 138 46 % C1R + 76 17 51 153 37 111 122 155 % C2L + 146 119 110 107 106 176 129 43 % C2R + 16 48 144 10 30 90 59 177 % D1L + 164 125 112 178 200 137 116 109 % D1R + 70 210 208 202 184 130 179 115 % D2L + 190 204 68 93 31 151 191 134 % D2R + 148 22 66 198 172 94 71 2 % E1L + 40 154 192 64 162 54 18 6 % E1R + 120 149 25 75 14 42 126 167 % E2L + 175 199 207 69 23 78 26 79 % E2R + 103 98 83 38 114 131 182 124 % F1L + 159 53 88 170 127 183 61 161 % F1R + 55 165 73 8 24 72 5 15 % F2L + 89 100 174 58 160 194 135 45 % F2R + ] def -} bind def -% --END ENCODER raw-- + /checkweightseq [ + seq {16 mul checkweights exch 16 getinterval aload pop} forall + ] dup length 8 sub 8 exch getinterval def -% --BEGIN ENCODER symbol-- -% --DESC: Miscellaneous symbols -% --EXAM: fima -% --EXOP: backgroundcolor=DD000011 -% --RNDR: renlinear -/symbol { + /widths [ + dxw {{} forall} forall + ] def + + /checksum 0 def + 0 1 widths length 1 sub { + /i exch def + /checksum checksum widths i get checkweightseq i get mul add def + } for + /checksum checksum 211 mod datalen 3 sub 211 mul add def - 20 dict begin % Confine variables to local scope + /i 0 def { + checksum tab174 i get le { + tab174 i 1 add 7 getinterval {} forall + /cte exch def /cto exch def + /cmwe exch def /cmwo exch def + /cele exch def /celo exch def + /cgs exch def + exit + } if + /i i 8 add def + } loop - /options exch def % We are given an option string - /barcode exch def % We are given a barcode string + /cwo checksum cgs sub cte idiv celo cmwo 4 true getRSSwidths def + /cwe checksum cgs sub cte mod cele cmwe 4 false getRSSwidths def - /dontdraw false def + /cw 8 array def + 0 1 3 { + /i exch def + cw i 2 mul cwo i get put + cw i 2 mul 1 add cwe i get put + } for - barcode (fima) eq { - /sbs [2.25 2.25 2.25 11.25 2.25 11.25 2.25 2.25 2.25] def - /bhs [.625 .625 .625 .625 .625] def - /bbs [0 0 0 0 0] def - } if + 22 array dup dup + 0 cw put 1 dxw putinterval 0 datalen 1 add getinterval + /dxw exch def + /datalen dxw length def - barcode (fimb) eq { - /sbs [2.25 6.75 2.25 2.25 2.25 6.25 2.25 2.25 2.25 6.75 2.25] def - /bhs [.625 .625 .625 .625 .625 .625] def - /bbs [0 0 0 0 0 0] def - } if + % Encode row runlengths + /rows datalen segments div ceiling cvi array def + /numrows rows length def + 0 1 numrows 1 sub { + /r exch def + mark + segments 4 mod 0 ne r 2 mod 1 eq and {0} if + 1 1 + 0 1 segments 1 sub { + /pos exch r segments mul add def + pos datalen lt { + dxw pos get {} forall + pos 2 mod 0 eq {fxw pos 2 idiv get {} forall} if + } if + } for + 1 1 + counttomark array astore rows exch r exch put pop + } for - barcode (fimc) eq { - /sbs [2.25 2.25 2.25 6.75 2.25 6.75 2.25 6.75 2.25 2.25 2.25] def - /bhs [.625 .625 .625 .625 .625 .625] def - /bbs [0 0 0 0 0 0] def - } if - - barcode (fimd) eq { - /sbs [2.25 2.25 2.25 2.25 2.25 6.75 2.25 6.75 2.25 2.25 2.25 2.25 2.25] def - /bhs [.625 .625 .625 .625 .625 .625 .625] def - /bbs [0 0 0 0 0 0 0] def - } if - - % Return the arguments - << - /ren (renlinear) - /sbs sbs - /bhs bhs - /bbs bbs - /opt options - >> + format (expandedstacked) ne { % Linear - dontdraw not //renlinear if + % Remove leading space + /sbs rows 0 get dup length 1 sub 1 exch getinterval def - end + /sbs [ + 1 + 0 1 datalen 1 sub { + /i exch def + dxw i get {} forall + i 2 mod 0 eq {fxw i 2 idiv get {} forall} if + } for + 1 1 + ] def -} bind def -% --END ENCODER symbol-- + << + /ren //renlinear + /sbs sbs + /bhs [sbs length 1 add 2 idiv {height} repeat] + /bbs [sbs length 1 add 2 idiv {0} repeat] + /opt options + >> -% --BEGIN ENCODER pdf417-- -% --DESC: PDF417 -% --EXAM: This is PDF417 -% --EXOP: columns=2 -% --RNDR: renmatrix -/pdf417 { + dontdraw not //renlinear if - 20 dict begin + } { % expandedstacked - /options exch def - /barcode exch def + /seps numrows array def + 0 1 numrows 1 sub { - /dontdraw false def - /compact false def - /eclevel -1 def - /columns 0 def - /rows 0 def - /rowmult 3 def - /raw false def - /parse false def + /r exch def + /row rows r get def - % Parse the input options - options type /stringtype eq { - 1 dict begin - options { - token false eq {exit} if dup length string cvs (=) search - true eq {cvlit exch pop exch def} {cvlit true def} ifelse - } loop - currentdict end /options exch def - } if - options {def} forall + % Sample runlengths into bitmap + mark + 0 2 row length 1 sub { + /i exch def + row i get {0} repeat + i row length 1 sub lt {row i 1 add get {1} repeat} if + } for + counttomark array astore /row exch def pop - /eclevel eclevel cvi def - /columns columns cvi def - /rows rows cvi def - /rowmult rowmult cvr def + % Derive the separator pattern + /sep [ row {1 exch sub} forall ] def + sep 0 [ 0 0 0 0 ] putinterval + sep row length 4 sub [ 0 0 0 0 ] putinterval + /finderpos [ % Finder pattern module positions + 19 98 row length 13 sub {} for + 68 98 row length 13 sub {} for + ] def + finderpos { + dup 14 add 1 exch { + /i exch def + row i get 0 eq { + row i 1 sub get 1 eq { + 1 + } { + sep i 1 sub get 0 eq {1} {0} ifelse + } ifelse + } { + 0 + } ifelse + sep exch i exch put + } for + } forall - % Parse ordinals of the form ^NNN to ASCII - parse { - /msg barcode length string def - /j 0 def - barcode - { % loop - (^) search { - dup msg exch j exch putinterval - length j add 1 add /j exch def - pop - dup 0 3 getinterval cvi msg exch j 1 sub exch put - dup length 3 sub 3 exch getinterval - } { - dup msg exch j exch putinterval - length j add /j exch def - /barcode msg 0 j getinterval def - exit - } ifelse - } loop - } if + % For even segment-pair symbols reverse alternate rows + segments 4 mod 0 eq r 2 mod 1 eq and { + rows r get length rows 0 get length ne % Except partial width last row + finderpos length 2 mod 1 eq and { % with odd finders + /row [ 0 row aload pop ] def + /sep [ 0 sep aload pop ] def + } { + row length 1 sub -1 0 {row exch get} for + row astore pop + sep length 1 sub -1 0 {sep exch get} for + sep astore pop + } ifelse + } if - % Convert input into array of codewords - raw { - /datcws barcode length array def - /i 0 def /j 0 def - { % loop - i barcode length eq {exit} if - /cw barcode i 1 add 3 getinterval cvi def - datcws j cw put - /i i 4 add def - /j j 1 add def - } loop - /datcws datcws 0 j getinterval def - } { % Simple autoencoder from input to codewords using byte mode - /barlen barcode length def - barlen 6 mod 0 eq { - /datcws barlen 6 idiv 5 mul 1 add array def - datcws 0 924 put - } { - /datcws barlen 6 idiv 5 mul barlen 6 mod add 1 add array def - datcws 0 901 put - } ifelse + rows r row put + seps r sep put - % Rebase groups of 6 bytes splitting into 3 byte chunks - 0 1 barlen 6 idiv 1 sub { - /i exch def - /msbs [ barcode i 6 mul 3 getinterval {} forall ] def - /mscs [ - msbs aload pop exch 256 mul add exch 65536 mul add - 3 {dup 900 mod exch 900 idiv} repeat - ] def - /lsbs [barcode i 6 mul 3 add 3 getinterval {} forall] def - /lscs [ - lsbs aload pop exch 256 mul add exch 65536 mul add - 3 {dup 900 mod exch 900 idiv} repeat - ] def - /cws 5 array def - lscs 0 get mscs 0 get 316 mul add - cws 4 2 index 900 mod put - 900 idiv lscs 1 get add mscs 0 get 641 mul add mscs 1 get 316 mul add - cws 3 2 index 900 mod put - 900 idiv lscs 2 get add mscs 0 get 20 mul add mscs 1 get 641 mul add mscs 2 get 316 mul add - cws 2 2 index 900 mod put - 900 idiv lscs 3 get add mscs 1 get 20 mul add mscs 2 get 641 mul add - cws 1 2 index 900 mod put - 900 idiv mscs 2 get 20 mul add - cws 0 3 -1 roll 900 mod put - datcws i 5 mul 1 add cws putinterval } for - % Add the remaining bytes to the end of the codewords - /rem barlen 6 mod def - rem 0 ne { - datcws datcws length rem sub - [ barcode barlen rem sub rem getinterval {} forall ] - putinterval - } if + % Extend last row and separator to fill width of symbol + /pixx rows 0 get length def + [ pixx {0} repeat ] dup 0 rows numrows 1 sub get putinterval + rows exch numrows 1 sub exch put + [ pixx {0} repeat ] dup 0 seps numrows 1 sub get putinterval + seps exch numrows 1 sub exch put + + % Middle separator pattern + /sep [ pixx 2 idiv 1 add { 0 1 } repeat ] 0 pixx getinterval def + sep 0 [0 0 0 0] putinterval + sep pixx 4 sub [0 0 0 0] putinterval + + % Compose the symbol + /pixs [ + 0 1 numrows 1 sub { + /r exch def + r 0 ne { + seps r get aload pop + } if + 34 {rows r get aload pop} repeat + r numrows 1 sub ne { + seps r get aload pop + sep aload pop + } if + } for + ] def + + << + /ren //renmatrix + /pixs pixs + /pixx pixx + /pixy pixs length pixx idiv + /height pixs length pixx idiv 72 div + /width pixx 72 div + /opt options + >> + + dontdraw not //renmatrix if } ifelse - % Determine the error correction level if unspecified - /m datcws length def - eclevel -1 eq { - m 40 le {/eclevel 2 def} if - m 41 ge m 160 le and {/eclevel 3 def} if - m 161 ge m 320 le and {/eclevel 4 def} if - m 321 ge {/eclevel 5 def} if - } if + end - % Reduce the error level so that it does not cause an excessive number of codewords - /maxeclevel 928 1 sub m sub ln 2 ln div cvi 1 sub def - eclevel maxeclevel gt {/eclevel maxeclevel def} if - /k 2 eclevel 1 add exp cvi def +} bind def +/databarexpanded dup load /uk.co.terryburton.bwipp defineresource pop +end +/setpacking where {pop setpacking} if +% --END ENCODER databarexpanded-- + +% --BEGIN ENCODER databarexpandedstacked-- +% --REQUIRES databarexpanded-- +% --DESC: GS1 DataBar Expanded Stacked +% --EXAM: (01)95012345678903(3103)000123 +% --EXOP: segments=4 +% --RNDR: renmatrix renlinear +/setpacking where {pop currentpacking true setpacking} if +1 dict +dup /renmatrix dup /uk.co.terryburton.bwipp findresource put +dup /databarexpanded dup /uk.co.terryburton.bwipp findresource put +begin +/databarexpandedstacked { - % To determine size of matrix, number of columns if given by user... - columns 1 ge columns 30 le and {/c columns def} if + 20 dict begin % Confine variables to local scope - % ... and rows is greater of those required and that given by user within limits - /r m k add 1 add columns div ceiling cvi def % Required - r rows lt rows 90 le and {/r rows def} if - r 3 lt {/r 3 def} if + /options exch def % We are given an option string + /barcode exch def % We are given a barcode string - % Opportunistically raise the error level if a better fit to the matrix is possible - /maxeclevel c r mul 1 sub m sub ln 2 ln div cvi 1 sub def - maxeclevel eclevel gt { - /eclevel maxeclevel def - /k 2 eclevel 1 add exp cvi def + /dontdraw false def + + % Parse the input options + options type /stringtype eq { + 1 dict begin + options { + token false eq {exit} if dup length string cvs (=) search + true eq {cvlit exch pop exch def} {cvlit true def} ifelse + } loop + currentdict end /options exch def } if + options {def} forall - % Create codewords array with one extra working space element and add padding - /n c r mul k sub def - /cws c r mul 1 add array def - cws 0 n put - cws 1 datcws putinterval - cws m 1 add [ n m sub 1 sub {900} repeat ] putinterval - cws n [ k {0} repeat 0 ] putinterval + % Get the result of encoding with databarexpanded with format=expandedstacked + options (dontdraw) true put + options (format) (expandedstacked) put - % Calculate the log and anti-log tables - /rsalog [ 1 928 {dup 3 mul 929 mod} repeat ] def - /rslog 929 array def - 1 1 928 {dup rsalog exch get exch rslog 3 1 roll put} for + /args barcode options //databarexpanded exec def - % Function to calculate the product in the field - /rsprod { - 2 copy 0 ne exch 0 ne and { - rslog exch get exch rslog exch get add 928 mod rsalog exch get - } { - pop pop 0 - } ifelse - } bind def + args (opt) options put + args + + dontdraw not //renmatrix if - % Generate the coefficients - /coeffs [ 1 k {0} repeat ] def - 1 1 k { - /i exch def - coeffs i coeffs i 1 sub get put - i 1 sub -1 1 { - /j exch def - coeffs j coeffs j 1 sub get coeffs j get rsalog i get rsprod add 929 mod put - } for - coeffs 0 coeffs 0 get rsalog i get rsprod put - } for - /coeffs coeffs 0 coeffs length 1 sub getinterval def - 1 2 coeffs length 1 sub {coeffs exch 2 copy get 929 exch sub put} for + end - % Derive the error codewords - 0 1 n 1 sub { - /t exch cws exch get cws n get add 929 mod def - 0 1 k 1 sub { - /j exch def - cws n j add cws n j add 1 add get 929 t coeffs k j sub 1 sub get mul 929 mod sub add 929 mod put - } for +} bind def +/databarexpandedstacked dup load /uk.co.terryburton.bwipp defineresource pop +end +/setpacking where {pop setpacking} if +% --END ENCODER databarexpandedstacked-- + +% --BEGIN ENCODER pharmacode-- +% --DESC: Pharmaceutical Binary Code +% --EXAM: 117480 +% --EXOP: showborder +% --RNDR: renlinear +/setpacking where {pop currentpacking true setpacking} if +1 dict +dup /renlinear dup /uk.co.terryburton.bwipp findresource put +begin +/pharmacode { + + 20 dict begin % Confine variables to local scope + + /options exch def % We are given an option string + /barcode exch def % We are given a barcode string + + /dontdraw false def + /height 8 2.835 mul 72 div def + /nwidth 0.5 2.835 mul def + /wwidth 1.5 2.835 mul def + /swidth 1.0 2.835 mul def + + % Parse the input options + options type /stringtype eq { + 1 dict begin + options { + token false eq {exit} if dup length string cvs (=) search + true eq {cvlit exch pop exch def} {cvlit true def} ifelse + } loop + currentdict end /options exch def + } if + options {def} forall + + /height height cvr def + /nwidth nwidth cvr def + /wwidth wwidth cvr def + /swidth swidth cvr def + + % Create the human readable text + /txt barcode length array def + 0 1 barcode length 1 sub { + /i exch def + txt i [barcode i 1 getinterval 0 0 () 0] put } for - n 1 n k add { dup cws exch 929 cws 5 -1 roll get sub 929 mod put } for - % Trim the working space from the end of the codewords - /cws cws 0 cws length 1 sub getinterval def + % Convert the integer into the paramacode string + /barcode barcode cvi 1 add 2 17 string cvrs def + /barcode barcode 1 barcode length 1 sub getinterval def - % Base 10 encoding of the bar space successions for the codewords in each cluster - /clusters [ - [ - 120256 125680 128380 120032 125560 128318 108736 119920 108640 86080 108592 86048 - 110016 120560 125820 109792 120440 125758 88256 109680 88160 89536 110320 120700 - 89312 110200 120638 89200 110140 89840 110460 89720 110398 89980 128506 119520 - 125304 128190 107712 119408 125244 107616 119352 84032 107568 119324 84000 107544 - 83984 108256 119672 125374 85184 108144 119612 85088 108088 119582 85040 108060 - 85728 108408 119742 85616 108348 85560 108318 85880 108478 85820 85790 107200 - 119152 125116 107104 119096 125086 83008 107056 119068 82976 107032 82960 82952 - 83648 107376 119228 83552 107320 119198 83504 107292 83480 83468 83824 107452 - 83768 107422 83740 83900 106848 118968 125022 82496 106800 118940 82464 106776 - 118926 82448 106764 82440 106758 82784 106936 119006 82736 106908 82712 106894 - 82700 82694 106974 82830 82240 106672 118876 82208 106648 118862 82192 106636 + /barlen barcode length def % Length of the code + /sbs barlen 2 mul array def + + 0 1 barlen 1 sub { + /i exch def + /enc barcode i 1 getinterval def + enc (0) eq { + sbs i 2 mul nwidth put + } { + sbs i 2 mul wwidth put + } ifelse + sbs i 2 mul 1 add swidth put + } for + + % Return the arguments + << + /ren //renlinear + /sbs sbs + /bhs [sbs length 1 add 2 idiv {height} repeat] + /bbs [sbs length 1 add 2 idiv {0} repeat] + /txt txt + /textxalign (center) + /opt options + >> + + dontdraw not //renlinear if + + end + +} bind def +/pharmacode dup load /uk.co.terryburton.bwipp defineresource pop +end +/setpacking where {pop setpacking} if +% --END ENCODER pharmacode-- + +% --BEGIN ENCODER pharmacode2-- +% --DESC: Two-track Pharmacode +% --EXAM: 117480 +% --EXOP: includetext showborder +% --RNDR: renlinear +/setpacking where {pop currentpacking true setpacking} if +1 dict +dup /renlinear dup /uk.co.terryburton.bwipp findresource put +begin +/pharmacode2 { + + 20 dict begin + + /options exch def % We are given an option string + /barcode exch def % We are given a barcode string + + /dontdraw false def + /includetext false def % Enable/disable text + /height 4 def % Height of short bars in millimetres + + % Parse the input options + options type /stringtype eq { + 1 dict begin + options { + token false eq {exit} if dup length string cvs (=) search + true eq {cvlit exch pop exch def} {cvlit true def} ifelse + } loop + currentdict end /options exch def + } if + options {def} forall + + /height height cvr def + + % Create the human readable text + /txt barcode length array def + 0 1 barcode length 1 sub { + /i exch def + txt i [barcode i 1 getinterval 0 0 () 0] put + } for + + /encstr 16 string def + /bhs 16 array def + /bbs 16 array def + /sbs 32 array def + /bar 1 25.4 div height mul def % bar height (mm) + /spc 1 25.4 div 72 mul def % bar width & spacing (1mm) + + % Convert number into a base3 representation + /i 15 def + /val barcode cvi def + { % loop + val 0 eq {exit} if + val 3 mod dup + [3 1 2] exch get val exch sub 3 idiv /val exch def + encstr i [2 0 1] 4 -1 roll get put + /i i 1 sub def + } loop + /encstr encstr i 1 add 15 i sub getinterval def + + % Generate the bar pattern + 0 1 encstr length 1 sub { + /i exch def + encstr i get dup + bhs i bar [1 1 2] 5 -1 roll get mul put + bbs i [0 bar 0] 4 -1 roll get put + } for + + % Return the arguments + << + /ren //renlinear + /bhs bhs + /bbs bbs + /sbs [encstr length 2 mul {spc} repeat] + /txt txt + /textxalign (center) + /textyoffset 4 + /opt options + >> + + dontdraw not //renlinear if + + end + +} bind def +/pharmacode2 dup load /uk.co.terryburton.bwipp defineresource pop +end +/setpacking where {pop setpacking} if +% --END ENCODER pharmacode2-- + +% --BEGIN ENCODER code2of5-- +% --DESC: Code 25 +% --EXAM: 01234567 +% --EXOP: version=iata includetext includecheck includecheckintext +% --RNDR: renlinear +/setpacking where {pop currentpacking true setpacking} if +1 dict +dup /renlinear dup /uk.co.terryburton.bwipp findresource put +begin +/code2of5 { + + 20 dict begin % Confine variable to local scope + + /options exch def % We are given an option string + /barcode exch def % We are given a barcode string + + /dontdraw false def + /includecheck false def + /includetext false def % Enable/disable text + /includecheckintext false def + /textfont /Courier def + /textsize 10 def + /textyoffset -7 def + /height 1 def + /version (industrial) def + + % Parse the input options + options type /stringtype eq { + 1 dict begin + options { + token false eq {exit} if dup length string cvs (=) search + true eq {cvlit exch pop exch def} {cvlit true def} ifelse + } loop + currentdict end /options exch def + } if + options {def} forall + + /textfont textfont cvlit def + /textsize textsize cvr def + /textyoffset textyoffset cvr def + /height height cvr def + + % Create an array containing the character mappings + << + /industrial + [ (1111313111) (3111111131) (1131111131) (3131111111) + (1111311131) (3111311111) (1131311111) (1111113131) + (3111113111) (1131113111) (313111) (31113) + ] + /iata + [ (1111313111) (3111111131) (1131111131) (3131111111) + (1111311131) (3111311111) (1131311111) (1111113131) + (3111113111) (1131113111) (1111) (311) + ] + /matrix + [ (113311) (311131) (131131) (331111) (113131) (313111) + (133111) (111331) (311311) (131311) (311111) (31111) + ] + /coop + [ (331111) (111331) (113131) (113311) (131131) (131311) + (133111) (311131) (311311) (313111) (3131) (133) + ] + /datalogic + [ (113311) (311131) (131131) (331111) (113131) (313111) + (133111) (111331) (311311) (131311) (1111) (311) + ] + >> + version get /encs exch def + /cs encs 0 get length def + /cw 0 encs 0 get {48 sub add} forall def + /ss encs dup length 2 sub get length def + /sw 0 encs dup length 2 sub get {48 sub add} forall def + + % Create a string of the available characters + /barchars (0123456789) def + + /barlen barcode length def % Length of the code + + includecheck { + /sbs barlen 1 add cs mul ss add ss add string def + /txt barlen 1 add array def + } { + /sbs barlen cs mul ss add ss add string def + /txt barlen array def + } ifelse + + % Put the start character + sbs 0 encs 10 get putinterval + + /checksum 0 def + + 0 1 barlen 1 sub { + /i exch def + % Lookup the encoding for the each barcode character + barcode i 1 getinterval barchars exch search + pop % Discard true leaving pre + length /indx exch def % indx is the length of pre + pop pop % Discard seek and post + /enc encs indx get def % Get the indxth encoding + sbs i cs mul ss add enc putinterval % Put encoded digit into sbs + txt i [barcode i 1 getinterval i cw mul sw add textyoffset textfont textsize] put + barlen i sub 2 mod 0 eq { + /checksum checksum indx add def + } { + /checksum checksum indx 3 mul add def + } ifelse + } for + + % Put the checksum and end characters + includecheck { + /checksum 10 checksum 10 mod sub 10 mod def + sbs barlen cs mul ss add encs checksum get putinterval + sbs barlen cs mul cs add ss add encs 11 get putinterval + includecheckintext { + txt barlen [barchars checksum 1 getinterval barlen cw mul sw add textyoffset textfont textsize] put + } { + txt barlen [( ) barlen cw mul sw add textyoffset textfont textsize] put + } ifelse + } { + sbs barlen cs mul ss add encs 11 get putinterval + } ifelse + + % Return the arguments + << + /ren //renlinear + /sbs [sbs {48 sub} forall] + /bhs [sbs length 1 add 2 idiv {height} repeat] + /bbs [sbs length 1 add 2 idiv {0} repeat] + includetext { + /txt txt + } if + /opt options + >> + + dontdraw not //renlinear if + + end + +} bind def +/code2of5 dup load /uk.co.terryburton.bwipp defineresource pop +end +/setpacking where {pop setpacking} if +% --END ENCODER code2of5-- + +% --BEGIN ENCODER code11-- +% --DESC: Code 11 +% --EXAM: 0123456789 +% --EXOP: includetext includecheck includecheckintext +% --RNDR: renlinear +/setpacking where {pop currentpacking true setpacking} if +1 dict +dup /renlinear dup /uk.co.terryburton.bwipp findresource put +begin +/code11 { + + 20 dict begin % Confine variables to local scope + + /options exch def % We are given an option string + /barcode exch def % We are given a barcode string + + /dontdraw false def + /includecheck false def + /includetext false def + /includecheckintext false def + /textfont /Courier def + /textsize 10 def + /textyoffset -7 def + /height 1 def + + % Parse the input options + options type /stringtype eq { + 1 dict begin + options { + token false eq {exit} if dup length string cvs (=) search + true eq {cvlit exch pop exch def} {cvlit true def} ifelse + } loop + currentdict end /options exch def + } if + options {def} forall + + /textfont textfont cvlit def + /textsize textsize cvr def + /textyoffset textyoffset cvr def + /height height cvr def + + % Create an array containing the character mappings + /encs + [ (111131) (311131) (131131) (331111) (113131) + (313111) (133111) (111331) (311311) (311111) + (113111) (113311) + ] def + + % Create a string of the available characters + /barchars (0123456789-) def + + /barlen barcode length def % Length of the code + + includecheck { + barlen 10 ge { + /sbs barlen 6 mul 24 add string def + /txt barlen 2 add array def + } { + /sbs barlen 6 mul 18 add string def + /txt barlen 1 add array def + } ifelse + } { + /sbs barlen 6 mul 12 add string def + /txt barlen array def + } ifelse + + % Put the start character + sbs 0 encs 11 get putinterval + + /checksum1 0 def /checksum2 0 def + + /xpos 8 def + 0 1 barlen 1 sub { + /i exch def + % Lookup the encoding for the each barcode character + barcode i 1 getinterval barchars exch search + pop % Discard true leaving pre + length /indx exch def % indx is the length of pre + pop pop % Discard seek and post + /enc encs indx get def % Get the indxth encoding + sbs i 6 mul 6 add enc putinterval % Put encoded digit into sbs + txt i [barcode i 1 getinterval xpos textyoffset textfont textsize] put + 0 1 5 { % xpos+=width of the character + /xpos exch enc exch get 48 sub xpos add def + } for + /checksum1 checksum1 barlen i sub 1 sub 10 mod 1 add indx mul add def + /checksum2 checksum2 barlen i sub 9 mod 1 add indx mul add def + } for + + % Put the checksum and end characters + includecheck { + /checksum1 checksum1 11 mod def + barlen 10 ge { + /checksum2 checksum2 checksum1 add 11 mod def + sbs barlen 6 mul 6 add encs checksum1 get putinterval + sbs barlen 6 mul 12 add encs checksum2 get putinterval + includecheckintext { + txt barlen [barchars checksum1 1 getinterval xpos textyoffset textfont textsize] put + /enc encs checksum1 get def + 0 1 5 { % xpos+=width of the character + /xpos exch enc exch get 48 sub xpos add def + } for + txt barlen 1 add [barchars checksum2 1 getinterval xpos textyoffset textfont textsize] put + } { + txt barlen [() xpos textyoffset textfont textsize] put + txt barlen 1 add [() xpos textyoffset textfont textsize] put + } ifelse + sbs barlen 6 mul 18 add encs 11 get putinterval + } { + sbs barlen 6 mul 6 add encs checksum1 get putinterval + includecheckintext { + txt barlen [barchars checksum1 1 getinterval xpos textyoffset textfont textsize] put + } { + txt barlen [() xpos textyoffset textfont textsize] put + } ifelse + sbs barlen 6 mul 12 add encs 11 get putinterval + } ifelse + } { + sbs barlen 6 mul 6 add encs 11 get putinterval + } ifelse + + % Return the arguments + << + /ren //renlinear + /sbs [sbs {48 sub} forall] + /bhs [sbs length 1 add 2 idiv {height} repeat] + /bbs [sbs length 1 add 2 idiv {0} repeat] + includetext { + /txt txt + } if + /opt options + >> + + dontdraw not //renlinear if + + end + +} bind def +/code11 dup load /uk.co.terryburton.bwipp defineresource pop +end +/setpacking where {pop setpacking} if +% --END ENCODER code11-- + +% --BEGIN ENCODER bc412-- +% --DESC: BC412 +% --EXAM: BC412 +% --EXOP: semi includetext includecheckintext +% --RNDR: renlinear +/setpacking where {pop currentpacking true setpacking} if +1 dict +dup /renlinear dup /uk.co.terryburton.bwipp findresource put +begin +/bc412 { + + 20 dict begin % Confine variables to local scope + + /options exch def % We are given an option string + /barcode exch def % We are given a barcode string + + /dontdraw false def + /includecheck false def % Enable/disable checkdigit + /includetext false def + /includecheckintext false def + /includestartstop false def + /semi false def + /textfont /Courier def + /textsize 10 def + /textyoffset -7 def + /height 1 def + + % Parse the input options + options type /stringtype eq { + 1 dict begin + options { + token false eq {exit} if dup length string cvs (=) search + true eq {cvlit exch pop exch def} {cvlit true def} ifelse + } loop + currentdict end /options exch def + } if + options {def} forall + + /textfont textfont cvlit def + /textsize textsize cvr def + /textyoffset textyoffset cvr def + /height height cvr def + + semi { + /includecheck true def + /includestartstop true def + } if + + % Create an array containing the character mappings + /encs + [ (11111115) (13111212) (11131113) (12111213) (12121311) + (13131111) (12111312) (11131212) (11121411) (11151111) + (15111111) (11111511) (12131211) (13121112) (13111212) + (11111214) (12121113) (11111313) (13111113) (11121213) + (11141112) (11121312) (11141211) (14121111) (12121212) + (11131311) (13121211) (12111411) (14111211) (11111412) + (12111114) (14111112) (12141111) (11121114) (12131112) + (12) (111) + ] def + + % Create a string of the available characters + /barchars (0R9GLVHA8EZ4NTS1J2Q6C7DYKBUIX3FWP5M) def + + /barlen barcode length def % Length of the code + + /sbs barlen 1 add 8 mul 5 add string def + includecheck { + /txt barlen 1 add array def + } { + /txt barlen array def + } ifelse + + % Put the start character + includestartstop { + sbs 0 encs 35 get putinterval + /pos 2 def + /txtpos 3 def + } { + /pos 0 def + /txtpos 0 def + } ifelse + + /checksum 0 def + 0 1 barlen 1 sub { + /i exch def + % Lookup the encoding for the each barcode character + barcode i 1 getinterval barchars exch search + pop % Discard true leaving pre + length /indx exch def % indx is the length of pre + pop pop % Discard seek and post + /enc encs indx get def % Get the indxth encoding + sbs pos enc putinterval % Put encoded digit into sbs + txt i [barcode i 1 getinterval i 12 mul txtpos add textyoffset textfont textsize] put + /checksum checksum indx add def + /pos pos 8 add def + } for + + % Put the checksum + includecheck { + /checksum checksum 35 mod def + sbs pos encs checksum get putinterval + includecheckintext { + txt barlen [barchars checksum 1 getinterval barlen 12 mul txtpos add textyoffset textfont textsize] put + } { + txt barlen [() barlen 12 mul txtpos add textyoffset textfont textsize] put + } ifelse + /pos pos 8 add def + } if + + % Put the stop character + includestartstop { + sbs pos encs 36 get putinterval + /pos pos 2 add def + } if + + % Return the arguments + /sbs sbs 0 pos getinterval def + << + /ren //renlinear + /sbs [sbs {48 sub} forall] + /bhs [sbs length 1 add 2 idiv {height} repeat] + /bbs [sbs length 1 add 2 idiv {0} repeat] + includetext { + /txt txt + } if + /opt options + >> + + dontdraw not //renlinear if + + end + +} bind def +/bc412 dup load /uk.co.terryburton.bwipp defineresource pop +end +/setpacking where {pop setpacking} if +% --END ENCODER bc412-- + +% --BEGIN ENCODER rationalizedCodabar-- +% --DESC: Rationalized Codabar +% --EXAM: A0123456789B +% --EXOP: includetext includecheck includecheckintext +% --RNDR: renlinear +/setpacking where {pop currentpacking true setpacking} if +1 dict +dup /renlinear dup /uk.co.terryburton.bwipp findresource put +begin +/rationalizedCodabar { + + 20 dict begin % Confine variables to local scope + + /options exch def % We are given an option string + /barcode exch def % We are given a barcode string + + /dontdraw false def + /includecheck false def % Enable/disable checkdigit + /includetext false def % Enable/disable text + /includecheckintext false def + /textfont /Courier def + /textsize 10 def + /textyoffset -7 def + /height 1 def + + % Parse the input options + options type /stringtype eq { + 1 dict begin + options { + token false eq {exit} if dup length string cvs (=) search + true eq {cvlit exch pop exch def} {cvlit true def} ifelse + } loop + currentdict end /options exch def + } if + options {def} forall + + /textfont textfont cvlit def + /textsize textsize cvr def + /textyoffset textyoffset cvr def + /height height cvr def + + % Create an array containing the character mappings + /encs + [ (11111331) (11113311) (11131131) (33111111) (11311311) + (31111311) (13111131) (13113111) (13311111) (31131111) + (11133111) (11331111) (31113131) (31311131) (31313111) + (11313131) (11331311) (13131131) (11131331) (11133311) + ] def + + % Create a string of the available characters + /barchars (0123456789-$:/.+ABCD) def + + /barlen barcode length def % Length of the code + + includecheck { + /sbs barlen 8 mul 8 add string def + /txt barlen 1 add array def + } { + /sbs barlen 8 mul string def + /txt barlen array def + } ifelse + + /checksum 0 def + /xpos 0 def + 0 1 barlen 2 sub { + /i exch def + % Lookup the encoding for the each barcode character + barcode i 1 getinterval barchars exch search + pop % Discard true leaving pre + length /indx exch def % indx is the length of pre + pop pop % Discard seek and post + /enc encs indx get def % Get the indxth encoding + sbs i 8 mul enc putinterval % Put encoded digit into sbs + txt i [barcode i 1 getinterval xpos textyoffset textfont textsize] put + 0 1 7 { % xpos+=width of the character + /xpos exch enc exch get 48 sub xpos add def + } for + /checksum checksum indx add def + } for + + % Find index of last character + barcode barlen 1 sub 1 getinterval barchars exch search + pop % Discard true leaving pre + length /indx exch def % indx is the length of pre + pop pop % Discard seek and post + + includecheck { + % Put the checksum character + /checksum checksum indx add def + /checksum 16 checksum 16 mod sub 16 mod def + sbs barlen 8 mul 8 sub encs checksum get putinterval + includecheckintext { + txt barlen 1 sub [barchars checksum 1 getinterval xpos textyoffset textfont textsize] put + } { + txt barlen 1 sub [( ) xpos textyoffset textfont textsize] put + } ifelse + 0 1 7 { % xpos+=width of the character + /xpos exch encs checksum get exch get 48 sub xpos add def + } for + % Put the end character + /enc encs indx get def % Get the indxth encoding + sbs barlen 8 mul enc putinterval % Put encoded digit into sbs + txt barlen [barcode barlen 1 sub 1 getinterval xpos textyoffset textfont textsize] put + } { + % Put the end character + /enc encs indx get def % Get the indxth encoding + sbs barlen 8 mul 8 sub enc putinterval % Put encoded digit into sbs + txt barlen 1 sub [barcode barlen 1 sub 1 getinterval xpos textyoffset textfont textsize] put + } ifelse + + % Return the arguments + << + /ren //renlinear + /sbs [sbs {48 sub} forall] + /bhs [sbs length 1 add 2 idiv {height} repeat] + /bbs [sbs length 1 add 2 idiv {0} repeat] + includetext { + /txt txt + } if + /opt options + >> + + dontdraw not //renlinear if + + end + +} bind def +/rationalizedCodabar dup load /uk.co.terryburton.bwipp defineresource pop +end +/setpacking where {pop setpacking} if +% --END ENCODER rationalizedCodabar-- + +% --BEGIN ENCODER onecode-- +% --DESC: United States Postal Service Intelligent Mail +% --EXAM: 0123456709498765432101234567891 +% --EXOP: barcolor=FF0000 +% --RNDR: renlinear +/setpacking where {pop currentpacking true setpacking} if +1 dict +dup /renlinear dup /uk.co.terryburton.bwipp findresource put +begin +/onecode { + + 20 dict begin + + /options exch def % We are given an option string + /barcode exch def % We are given a barcode string + + /dontdraw false def + /height 0.15 def + + % Parse the input options + options type /stringtype eq { + 1 dict begin + options { + token false eq {exit} if dup length string cvs (=) search + true eq {cvlit exch pop exch def} {cvlit true def} ifelse + } loop + currentdict end /options exch def + } if + options {def} forall + + /height height cvr def + + /barlen barcode length def + + % Create the human readable text + /txtdict << + 2 dup + 5 dup + barcode 5 1 getinterval (9) eq {14} {11} ifelse dup + 20 dup + 25 dup + 29 dup + >> def + /txt barlen 6 add array def + /spacecnt 0 def + 0 1 barlen 1 sub { + /i exch def + txtdict i known { + txt i spacecnt add [( ) 0 0 () 0] put + /spacecnt spacecnt 1 add def + } if + txt i spacecnt add [barcode i 1 getinterval 0 0 () 0] put + } for + /txt txt 0 barcode length spacecnt add getinterval def + + /normalize { + /base exch def + /num exch def + num length 1 sub -1 1 { + /i exch def + num i 1 sub 2 copy get num i get base idiv add put + num i num i get base mod put + } for + { %loop - extend input as necessary + num 0 get base lt {exit} if + /num [0 num {} forall] def + num 0 num 0 get num 1 get base idiv add put + num 1 num 1 get base mod put + } loop + % Trim leading zeros + /num [/i true def num {dup 0 eq i and {pop} {/i false def} ifelse} forall] def + num length 0 eq {/num [0] def} if + num + } bind def + + /bigadd { + 2 copy length exch length + 2 copy sub abs /offset exch def + lt {exch} if + /a exch def /b exch def + 0 1 b length 1 sub { + dup a exch offset add 2 copy get b 5 -1 roll get add put + } for + a + } bind def + + % Conversion of data fields into binary data + barlen 20 eq {[0]} if + barlen 25 eq {[1]} if + barlen 29 eq {[1 0 0 0 0 1]} if + barlen 31 eq {[1 0 0 0 1 0 0 0 0 1]} if + /binval exch [barcode 20 barlen 20 sub getinterval {48 sub} forall] bigadd def + /binval [binval {} forall barcode 0 get 48 sub] def + /binval [binval {5 mul} forall] [barcode 1 get 48 sub] bigadd 10 normalize def + /binval [binval {} forall barcode 2 18 getinterval {48 sub} forall] def + + % Conversion of binary data into byte array + /bytes 13 array def + /bintmp [binval {} forall] def + 12 -1 0 { + /i exch def + 0 1 bintmp length 2 sub { + /j exch def + bintmp j 1 add 2 copy get bintmp j get 256 mod 10 mul add put + bintmp j bintmp j get 256 idiv put + } for + bytes i bintmp bintmp length 1 sub get 256 mod put + bintmp bintmp length 1 sub 2 copy get 256 idiv put + } for + + % Generation of 11-bit CRC on byte array + /fcs 2047 def + /dat bytes 0 get 5 bitshift def + 6 { + fcs dat xor 1024 and 0 ne { + /fcs fcs 1 bitshift 3893 xor def + } { + /fcs fcs 1 bitshift def + } ifelse + /fcs fcs 2047 and def + /dat dat 1 bitshift def + } repeat + 1 1 12 { + bytes exch get 3 bitshift /dat exch def + 8 { + fcs dat xor 1024 and 0 ne { + /fcs fcs 1 bitshift 3893 xor def + } { + /fcs fcs 1 bitshift def + } ifelse + /fcs fcs 2047 and def + /dat dat 1 bitshift def + } repeat + } for + + % Conversion from binary data to codewords + /codewords 10 array def + 9 -1 0 { + /i exch def + i 9 eq { + /b 636 def + } { + /b 1365 def + } ifelse + 0 1 binval length 2 sub { + /j exch def + binval j 1 add 2 copy get binval j get b mod 10 mul add put + binval j binval j get b idiv put + } for + codewords i binval binval length 1 sub get b mod put + binval binval length 1 sub 2 copy get b idiv put + } for + + % Inserting additional information into codewords + codewords 9 codewords 9 get 2 mul put + fcs 1024 and 0 ne { + codewords 0 codewords 0 get 659 add put + } if + + % Conversion from codewords to characters + /tab513 [ + 31 7936 47 7808 55 7552 59 7040 61 6016 62 3968 79 7744 87 + 7488 91 6976 93 5952 94 3904 103 7360 107 6848 109 5824 110 3776 + 115 6592 117 5568 118 3520 121 5056 122 3008 124 1984 143 7712 151 + 7456 155 6944 157 5920 158 3872 167 7328 171 6816 173 5792 174 3744 + 179 6560 181 5536 182 3488 185 5024 186 2976 188 1952 199 7264 203 + 6752 205 5728 206 3680 211 6496 213 5472 214 3424 217 4960 218 2912 + 220 1888 227 6368 229 5344 230 3296 233 4832 234 2784 236 1760 241 + 4576 242 2528 244 1504 248 992 271 7696 279 7440 283 6928 285 5904 + 286 3856 295 7312 299 6800 301 5776 302 3728 307 6544 309 5520 310 + 3472 313 5008 314 2960 316 1936 327 7248 331 6736 333 5712 334 3664 + 339 6480 341 5456 342 3408 345 4944 346 2896 348 1872 355 6352 357 + 5328 358 3280 361 4816 362 2768 364 1744 369 4560 370 2512 372 1488 + 376 976 391 7216 395 6704 397 5680 398 3632 403 6448 405 5424 406 + 3376 409 4912 410 2864 412 1840 419 6320 421 5296 422 3248 425 4784 + 426 2736 428 1712 433 4528 434 2480 436 1456 440 944 451 6256 453 + 5232 454 3184 457 4720 458 2672 460 1648 465 4464 466 2416 468 1392 + 472 880 481 4336 482 2288 484 1264 488 752 527 7688 535 7432 539 + 6920 541 5896 542 3848 551 7304 555 6792 557 5768 558 3720 563 6536 + 565 5512 566 3464 569 5000 570 2952 572 1928 583 7240 587 6728 589 + 5704 590 3656 595 6472 597 5448 598 3400 601 4936 602 2888 604 1864 + 611 6344 613 5320 614 3272 617 4808 618 2760 620 1736 625 4552 626 + 2504 628 1480 632 968 647 7208 651 6696 653 5672 654 3624 659 6440 + 661 5416 662 3368 665 4904 666 2856 668 1832 675 6312 677 5288 678 + 3240 681 4776 682 2728 684 1704 689 4520 690 2472 692 1448 696 936 + 707 6248 709 5224 710 3176 713 4712 714 2664 716 1640 721 4456 722 + 2408 724 1384 728 872 737 4328 738 2280 740 1256 775 7192 779 6680 + 781 5656 782 3608 787 6424 789 5400 790 3352 793 4888 794 2840 796 + 1816 803 6296 805 5272 806 3224 809 4760 810 2712 812 1688 817 4504 + 818 2456 820 1432 824 920 835 6232 837 5208 838 3160 841 4696 842 + 2648 844 1624 849 4440 850 2392 852 1368 865 4312 866 2264 868 1240 + 899 6200 901 5176 902 3128 905 4664 906 2616 908 1592 913 4408 914 + 2360 916 1336 929 4280 930 2232 932 1208 961 4216 962 2168 964 1144 + 1039 7684 1047 7428 1051 6916 1053 5892 1054 3844 1063 7300 1067 6788 1069 + 5764 1070 3716 1075 6532 1077 5508 1078 3460 1081 4996 1082 2948 1084 1924 + 1095 7236 1099 6724 1101 5700 1102 3652 1107 6468 1109 5444 1110 3396 1113 + 4932 1114 2884 1116 1860 1123 6340 1125 5316 1126 3268 1129 4804 1130 2756 + 1132 1732 1137 4548 1138 2500 1140 1476 1159 7204 1163 6692 1165 5668 1166 + 3620 1171 6436 1173 5412 1174 3364 1177 4900 1178 2852 1180 1828 1187 6308 + 1189 5284 1190 3236 1193 4772 1194 2724 1196 1700 1201 4516 1202 2468 1204 + 1444 1219 6244 1221 5220 1222 3172 1225 4708 1226 2660 1228 1636 1233 4452 + 1234 2404 1236 1380 1249 4324 1250 2276 1287 7188 1291 6676 1293 5652 1294 + 3604 1299 6420 1301 5396 1302 3348 1305 4884 1306 2836 1308 1812 1315 6292 + 1317 5268 1318 3220 1321 4756 1322 2708 1324 1684 1329 4500 1330 2452 1332 + 1428 1347 6228 1349 5204 1350 3156 1353 4692 1354 2644 1356 1620 1361 4436 + 1362 2388 1377 4308 1378 2260 1411 6196 1413 5172 1414 3124 1417 4660 1418 + 2612 1420 1588 1425 4404 1426 2356 1441 4276 1442 2228 1473 4212 1474 2164 + 1543 7180 1547 6668 1549 5644 1550 3596 1555 6412 1557 5388 1558 3340 1561 + 4876 1562 2828 1564 1804 1571 6284 1573 5260 1574 3212 1577 4748 1578 2700 + 1580 1676 1585 4492 1586 2444 1603 6220 1605 5196 1606 3148 1609 4684 1610 + 2636 1617 4428 1618 2380 1633 4300 1634 2252 1667 6188 1669 5164 1670 3116 + 1673 4652 1674 2604 1681 4396 1682 2348 1697 4268 1698 2220 1729 4204 1730 + 2156 1795 6172 1797 5148 1798 3100 1801 4636 1802 2588 1809 4380 1810 2332 + 1825 4252 1826 2204 1857 4188 1858 2140 1921 4156 1922 2108 2063 7682 2071 + 7426 2075 6914 2077 5890 2078 3842 2087 7298 2091 6786 2093 5762 2094 3714 + 2099 6530 2101 5506 2102 3458 2105 4994 2106 2946 2119 7234 2123 6722 2125 + 5698 2126 3650 2131 6466 2133 5442 2134 3394 2137 4930 2138 2882 2147 6338 + 2149 5314 2150 3266 2153 4802 2154 2754 2161 4546 2162 2498 2183 7202 2187 + 6690 2189 5666 2190 3618 2195 6434 2197 5410 2198 3362 2201 4898 2202 2850 + 2211 6306 2213 5282 2214 3234 2217 4770 2218 2722 2225 4514 2226 2466 2243 + 6242 2245 5218 2246 3170 2249 4706 2250 2658 2257 4450 2258 2402 2273 4322 + 2311 7186 2315 6674 2317 5650 2318 3602 2323 6418 2325 5394 2326 3346 2329 + 4882 2330 2834 2339 6290 2341 5266 2342 3218 2345 4754 2346 2706 2353 4498 + 2354 2450 2371 6226 2373 5202 2374 3154 2377 4690 2378 2642 2385 4434 2401 + 4306 2435 6194 2437 5170 2438 3122 2441 4658 2442 2610 2449 4402 2465 4274 + 2497 4210 2567 7178 2571 6666 2573 5642 2574 3594 2579 6410 2581 5386 2582 + 3338 2585 4874 2586 2826 2595 6282 2597 5258 2598 3210 2601 4746 2602 2698 + 2609 4490 2627 6218 2629 5194 2630 3146 2633 4682 2641 4426 2657 4298 2691 + 6186 2693 5162 2694 3114 2697 4650 2705 4394 2721 4266 2753 4202 2819 6170 + 2821 5146 2822 3098 2825 4634 2833 4378 2849 4250 2881 4186 2945 4154 3079 + 7174 3083 6662 3085 5638 3086 3590 3091 6406 3093 5382 3094 3334 3097 4870 + 3107 6278 3109 5254 3110 3206 3113 4742 3121 4486 3139 6214 3141 5190 3145 + 4678 3153 4422 3169 4294 3203 6182 3205 5158 3209 4646 3217 4390 3233 4262 + 3265 4198 3331 6166 3333 5142 3337 4630 3345 4374 3361 4246 3393 4182 3457 + 4150 3587 6158 3589 5134 3593 4622 3601 4366 3617 4238 3649 4174 3713 4142 + 3841 4126 4111 7681 4119 7425 4123 6913 4125 5889 4135 7297 4139 6785 4141 + 5761 4147 6529 4149 5505 4153 4993 4167 7233 4171 6721 4173 5697 4179 6465 + 4181 5441 4185 4929 4195 6337 4197 5313 4201 4801 4209 4545 4231 7201 4235 + 6689 4237 5665 4243 6433 4245 5409 4249 4897 4259 6305 4261 5281 4265 4769 + 4273 4513 4291 6241 4293 5217 4297 4705 4305 4449 4359 7185 4363 6673 4365 + 5649 4371 6417 4373 5393 4377 4881 4387 6289 4389 5265 4393 4753 4401 4497 + 4419 6225 4421 5201 4425 4689 4483 6193 4485 5169 4489 4657 4615 7177 4619 + 6665 4621 5641 4627 6409 4629 5385 4633 4873 4643 6281 4645 5257 4649 4745 + 4675 6217 4677 5193 4739 6185 4741 5161 4867 6169 4869 5145 5127 7173 5131 + 6661 5133 5637 5139 6405 5141 5381 5155 6277 5157 5253 5187 6213 5251 6181 + 5379 6165 5635 6157 6151 7171 6155 6659 6163 6403 6179 6275 6211 5189 4681 + 4433 4321 3142 2634 2386 2274 1612 1364 1252 856 744 496 + ] def + + /tab213 [ + 3 6144 5 5120 6 3072 9 4608 10 2560 12 1536 17 4352 18 + 2304 20 1280 24 768 33 4224 34 2176 36 1152 40 640 48 384 + 65 4160 66 2112 68 1088 72 576 80 320 96 192 129 4128 130 + 2080 132 1056 136 544 144 288 257 4112 258 2064 260 1040 264 528 + 513 4104 514 2056 516 1032 1025 4100 1026 2052 2049 4098 4097 2050 1028 + 520 272 160 + ] def + + /chars 10 array def + 0 1 9 { + /i exch def + codewords i get dup 1286 le { + tab513 exch get + } { + tab213 exch 1287 sub get + } ifelse + chars i 3 -1 roll put + } for + + 9 -1 0 { + /i exch def + 2 i exp cvi fcs and 0 ne { + chars i chars i get 8191 xor put + } if + } for + + % Conversion from characters to the OneCode encoding + /barmap [ + 7 2 4 3 1 10 0 0 9 12 2 8 5 5 6 11 8 9 3 1 + 0 1 5 12 2 5 1 8 4 4 9 11 6 3 8 10 3 9 7 6 + 5 11 1 4 8 5 2 12 9 10 0 2 7 1 6 7 3 6 4 9 + 0 3 8 6 6 4 2 7 1 1 9 9 7 10 5 2 4 0 3 8 + 6 2 0 4 8 11 1 0 9 8 3 12 2 6 7 7 5 1 4 10 + 1 12 6 9 7 3 8 0 5 8 9 7 4 6 2 10 3 4 0 5 + 8 4 5 7 7 11 1 9 6 0 9 6 0 6 4 8 2 1 3 2 + 5 9 8 12 4 11 6 1 9 5 7 4 3 3 1 2 0 7 2 0 + 1 3 4 1 6 10 3 5 8 7 9 4 2 11 5 6 0 8 7 12 + 4 2 8 1 5 10 3 0 9 3 0 9 6 5 2 4 7 8 1 7 + 5 0 4 5 2 3 0 10 6 12 9 2 3 11 1 6 8 8 7 9 + 5 4 0 11 1 5 2 2 9 1 4 12 8 3 6 6 7 0 3 7 + 4 7 7 5 0 12 1 11 2 9 9 0 6 8 5 3 3 10 8 2 + ] def + + /bbs 65 array def + /bhs 65 array def + 0 1 64 { + /i exch def + /dec chars barmap i 4 mul get get 2 barmap i 4 mul 1 add get exp cvi and 0 ne def + /asc chars barmap i 4 mul 2 add get get 2 barmap i 4 mul 3 add get exp cvi and 0 ne def + dec not asc not and { + bbs i 3 height mul 8 div put + bhs i 2 height mul 8 div put + } if + dec not asc and { + bbs i 3 height mul 8 div put + bhs i 5 height mul 8 div put + } if + dec asc not and { + bbs i 0 height mul 8 div put + bhs i 5 height mul 8 div put + } if + dec asc and { + bbs i 0 height mul 8 div put + bhs i 8 height mul 8 div put + } if + } for + + % Return the arguments + << + /ren //renlinear + /bbs bbs + /bhs bhs + /sbs [bhs length 1 sub {1.44 1.872} repeat 1.44] + /txt txt + /textxalign (left) + /textfont /Helvetica + /textyoffset 1 + /textxoffset -0.3 + /opt options + >> + + dontdraw not //renlinear if + + end + +} bind def +/onecode dup load /uk.co.terryburton.bwipp defineresource pop +end +/setpacking where {pop setpacking} if +% --END ENCODER onecode-- + +% --BEGIN ENCODER postnet-- +% --DESC: United States Postal Service POSTNET +% --EXAM: 01234 +% --EXOP: includetext includecheckintext +% --RNDR: renlinear +/setpacking where {pop currentpacking true setpacking} if +1 dict +dup /renlinear dup /uk.co.terryburton.bwipp findresource put +begin +/postnet { + + 20 dict begin + + /options exch def % We are given an option string + /barcode exch def % We are given a barcode string + + /dontdraw false def + /includetext false def % Enable/disable text + /includecheckintext false def + /textfont /Courier def + /textsize 10 def + /textyoffset -7 def + /height 0.125 def + + % Parse the input options + options type /stringtype eq { + 1 dict begin + options { + token false eq {exit} if dup length string cvs (=) search + true eq {cvlit exch pop exch def} {cvlit true def} ifelse + } loop + currentdict end /options exch def + } if + options {def} forall + + /textfont textfont cvlit def + /textsize textsize cvr def + /textyoffset textyoffset cvr def + /height height cvr def + + /barlen barcode length def + + % Ensure 5, 9 or 11 digits + barlen 5 lt { + /barlen -1 def % Error + } { + barlen 11 ge { + /barlen 11 def + } if + barlen 10 eq { + /barlen 9 def + } if + barlen 8 le { + /barlen 5 def + } if + } ifelse + + % Create an array containing the character mappings + /encs + [ (55222) (22255) (22525) (22552) (25225) + (25252) (25522) (52225) (52252) (52522) + (5) (5) + ] def + + % Create a string of the available characters + /barchars (0123456789) def + + /bhs barlen 5 mul 7 add array def + /txt barlen 1 add array def + + % Put start character + /enc encs 10 get def + /heights enc length array def + 0 1 enc length 1 sub { + /j exch def + heights j enc j 1 getinterval cvi height mul 5 div put + } for + bhs 0 heights putinterval % Put encoded digit into sbs + + /checksum 0 def + 0 1 barlen 1 sub { + /i exch def + % Lookup the encoding for the each barcode character + barcode i 1 getinterval barchars exch search + pop % Discard true leaving pre + length /indx exch def % indx is the length of pre + pop pop % Discard seek and post + /enc encs indx get def % Get the indxth encoding + /heights enc length array def + 0 1 enc length 1 sub { + /j exch def + heights j enc j 1 getinterval cvi height mul 5 div put + } for + bhs i 5 mul 1 add heights putinterval % Put encoded digit into sbs + txt i [barcode i 1 getinterval i 5 mul 1 add 3.312 mul textyoffset textfont textsize] put + /checksum checksum indx add def % checksum+=indx + } for + + % Put the checksum character + /checksum 10 checksum 10 mod sub 10 mod def + /enc encs checksum get def + /heights enc length array def + 0 1 enc length 1 sub { + /j exch def + heights j enc j 1 getinterval cvi height mul 5 div put + } for + bhs barlen 5 mul 1 add heights putinterval + + includecheckintext { + txt barlen [barchars checksum 1 getinterval barlen 5 mul 1 add 3.312 mul textyoffset textfont textsize] put + } { + txt barlen [( ) barlen 5 mul 1 add 72 mul 25 div textyoffset textfont textsize] put + } ifelse + + % Put end character + /enc encs 11 get def + /heights enc length array def + 0 1 enc length 1 sub { + /j exch def + heights j enc j 1 getinterval cvi height mul 5 div put + } for + bhs barlen 5 mul 6 add heights putinterval + + % Return the arguments + << + /ren //renlinear + /bhs bhs + /bbs [bhs length {0} repeat] + /sbs [bhs length 1 sub {1.44 1.872} repeat 1.44] + includetext { + /txt txt + } if + /opt options + >> + + dontdraw not //renlinear if + + end + +} bind def +/postnet dup load /uk.co.terryburton.bwipp defineresource pop +end +/setpacking where {pop setpacking} if +% --END ENCODER postnet-- + +% --BEGIN ENCODER planet-- +% --DESC: United States Postal Service PLANET +% --EXAM: 01234567890 +% --EXOP: includetext includecheckintext +% --RNDR: renlinear +/setpacking where {pop currentpacking true setpacking} if +1 dict +dup /renlinear dup /uk.co.terryburton.bwipp findresource put +begin +/planet { + + 20 dict begin + + /options exch def % We are given an option string + /barcode exch def % We are given a barcode string + + /dontdraw false def + /includetext false def % Enable/disable text + /includecheckintext false def + /textfont /Courier def + /textsize 10 def + /textyoffset -7 def + /height 0.125 def + + % Parse the input options + options type /stringtype eq { + 1 dict begin + options { + token false eq {exit} if dup length string cvs (=) search + true eq {cvlit exch pop exch def} {cvlit true def} ifelse + } loop + currentdict end /options exch def + } if + options {def} forall + + /textfont textfont cvlit def + /textsize textsize cvr def + /textyoffset textyoffset cvr def + /height height cvr def + + /barlen barcode length def + + % Ensure 11 or 13 digits + barlen 11 lt { + /barlen -1 def % Error + } { + barlen 13 ge { + /barlen 13 def + } { + /barlen 11 def + } ifelse + } ifelse + + % Create an array containing the character mappings + /encs + [ (22555) (55522) (55252) (55225) (52552) + (52525) (52255) (25552) (25525) (25255) + (5) (5) + ] def + + % Create a string of the available characters + /barchars (0123456789) def + + /bhs barlen 5 mul 7 add array def + /txt barlen 1 add array def + + % Put start character + /enc encs 10 get def + /heights enc length array def + 0 1 enc length 1 sub { + /j exch def + heights j enc j 1 getinterval cvi height mul 5 div put + } for + bhs 0 heights putinterval % Put encoded digit into sbs + + /checksum 0 def + 0 1 barlen 1 sub { + /i exch def + % Lookup the encoding for the each barcode character + barcode i 1 getinterval barchars exch search + pop % Discard true leaving pre + length /indx exch def % indx is the length of pre + pop pop % Discard seek and post + /enc encs indx get def % Get the indxth encoding + /heights enc length array def + 0 1 enc length 1 sub { + /j exch def + heights j enc j 1 getinterval cvi height mul 5 div put + } for + bhs i 5 mul 1 add heights putinterval % Put encoded digit into sbs + txt i [barcode i 1 getinterval i 5 mul 1 add 3.312 mul textyoffset textfont textsize] put + /checksum checksum indx add def % checksum+=indx + } for + + % Put the checksum character + /checksum 10 checksum 10 mod sub 10 mod def + /enc encs checksum get def + /heights enc length array def + 0 1 enc length 1 sub { + /j exch def + heights j enc j 1 getinterval cvi height mul 5 div put + } for + bhs barlen 5 mul 1 add heights putinterval + + includecheckintext { + txt barlen [barchars checksum 1 getinterval barlen 5 mul 1 add 3.312 mul textyoffset textfont textsize] put + } { + txt barlen [( ) barlen 5 mul 1 add 72 mul 25 div textyoffset textfont textsize] put + } ifelse + + % Put end character + /enc encs 11 get def + /heights enc length array def + 0 1 enc length 1 sub { + /j exch def + heights j enc j 1 getinterval cvi height mul 5 div put + } for + bhs barlen 5 mul 6 add heights putinterval + + % Return the arguments + << + /ren //renlinear + /bhs bhs + /bbs [bhs length {0} repeat] + /sbs [bhs length 1 sub {1.44 1.872} repeat 1.44] + includetext { + /txt txt + } if + /opt options + >> + + dontdraw not //renlinear if + + end + +} bind def +/planet dup load /uk.co.terryburton.bwipp defineresource pop +end +/setpacking where {pop setpacking} if +% --END ENCODER planet-- + +% --BEGIN ENCODER royalmail-- +% --DESC: Royal Mail 4 State Customer Code (RM4SCC) +% --EXAM: LE28HS9Z +% --EXOP: includetext includecheckintext barcolor=FF0000 +% --RNDR: renlinear +/setpacking where {pop currentpacking true setpacking} if +1 dict +dup /renlinear dup /uk.co.terryburton.bwipp findresource put +begin +/royalmail { + + 20 dict begin + + /options exch def % We are given an option string + /barcode exch def % We are given a barcode string + + /dontdraw false def + /includetext false def % Enable/disable text + /includecheckintext false def + /textfont /Courier def + /textsize 10 def + /textyoffset -7 def + /height 0.175 def + + % Parse the input options + options type /stringtype eq { + 1 dict begin + options { + token false eq {exit} if dup length string cvs (=) search + true eq {cvlit exch pop exch def} {cvlit true def} ifelse + } loop + currentdict end /options exch def + } if + options {def} forall + + /textfont textfont cvlit def + /textsize textsize cvr def + /textyoffset textyoffset cvr def + /height height cvr def + + % Create an array containing the character mappings + /encs + [ (3300) (2211) (2301) (2310) (3201) (3210) + (1122) (0033) (0123) (0132) (1023) (1032) + (1302) (0213) (0303) (0312) (1203) (1212) + (1320) (0231) (0321) (0330) (1221) (1230) + (3102) (2013) (2103) (2112) (3003) (3012) + (3120) (2031) (2121) (2130) (3021) (3030) + (2) (3) + ] def + + % Create a string of the available characters + /barchars (ZUVWXY501234B6789AHCDEFGNIJKLMTOPQRS) def + + /barlen barcode length def + /encstr barlen 4 mul 6 add string def + /txt barlen 1 add array def + + % Put start character + encstr 0 encs 36 get putinterval + + /checksumrow 0 def + /checksumcol 0 def + 0 1 barlen 1 sub { + /i exch def + % Lookup the encoding for the each barcode character + barcode i 1 getinterval barchars exch search + pop % Discard true leaving pre + length /indx exch def % indx is the length of pre + pop pop % Discard seek and post + /enc encs indx get def % Get the indxth encoding + encstr i 4 mul 1 add enc putinterval + txt i [barcode i 1 getinterval i 4 mul 1 add 3.312 mul textyoffset textfont textsize] put + /checksumrow checksumrow indx 6 idiv add def + /checksumcol checksumcol indx 6 mod add def + } for + + % Put the checksum character + /checksum checksumrow 6 mod 6 mul checksumcol 6 mod add def + /enc encs checksum get def + encstr barlen 4 mul 1 add enc putinterval + includecheckintext { + txt barlen [barchars checksum 1 getinterval barlen 4 mul 1 add 3.312 mul textyoffset textfont textsize] put + } { + txt barlen [( ) barlen 4 mul 1 add 3.312 mul textyoffset textfont textsize] put + } ifelse + + % Put end character + encstr barlen 4 mul 5 add encs 37 get putinterval + + /bbs encstr length array def + /bhs encstr length array def + 0 1 encstr length 1 sub { + /i exch def + /enc encstr i 1 getinterval def + enc (0) eq { + bbs i 3 height mul 8 div put + bhs i 2 height mul 8 div put + } if + enc (1) eq { + bbs i 0 height mul 8 div put + bhs i 5 height mul 8 div put + } if + enc (2) eq { + bbs i 3 height mul 8 div put + bhs i 5 height mul 8 div put + } if + enc (3) eq { + bbs i 0 height mul 8 div put + bhs i 8 height mul 8 div put + } if + } for + + % Return the arguments + << + /ren //renlinear + /bbs bbs + /bhs bhs + /sbs [bhs length 1 sub {1.44 1.872} repeat 1.44] + includetext { + /txt txt + } if + /opt options + >> + + dontdraw not //renlinear if + + end + +} bind def +/royalmail dup load /uk.co.terryburton.bwipp defineresource pop +end +/setpacking where {pop setpacking} if +% --END ENCODER royalmail-- + +% --BEGIN ENCODER auspost-- +% --DESC: AusPost 4 State Customer Code +% --EXAM: 5956439111ABA 9 +% --EXOP: includetext custinfoenc=character +% --RNDR: renlinear +/setpacking where {pop currentpacking true setpacking} if +1 dict +dup /renlinear dup /uk.co.terryburton.bwipp findresource put +begin +/auspost { + + 20 dict begin + + /options exch def % We are given an option string + /barcode exch def % We are given a barcode string + + /dontdraw false def + /includetext false def % Enable/disable text + /textfont /Courier def + /textsize 10 def + /textyoffset -7 def + /height 0.175 def + /custinfoenc (character) def + + % Parse the input options + options type /stringtype eq { + 1 dict begin + options { + token false eq {exit} if dup length string cvs (=) search + true eq {cvlit exch pop exch def} {cvlit true def} ifelse + } loop + currentdict end /options exch def + } if + options {def} forall + + /textfont textfont cvlit def + /textsize textsize cvr def + /textyoffset textyoffset cvr def + /height height cvr def + + % Create an array containing the character mappings + /encs + [ (000) (001) (002) (010) (011) (012) (020) (021) + (022) (100) (101) (102) (110) (111) (112) (120) + (121) (122) (200) (201) (202) (210) (211) (212) + (220) (221) (222) (300) (301) (302) (310) (311) + (312) (320) (321) (322) (023) (030) (031) (032) + (033) (103) (113) (123) (130) (131) (132) (133) + (203) (213) (223) (230) (231) (232) (233) (303) + (313) (323) (330) (331) (332) (333) (003) (013) + (00) (01) (02) (10) (11) (12) (20) (21) (22) (30) + (13) (3) + ] def + + % Create a string of the available characters + /barchars (ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789abcdefghijklmnopqrstuvwxyz #) def + + /barlen barcode length def + barcode 0 2 getinterval (11) eq {37} if + barcode 0 2 getinterval (45) eq {37} if + barcode 0 2 getinterval (59) eq {52} if + barcode 0 2 getinterval (62) eq {67} if + /encstr exch string def + /txt barlen 2 sub array def + + % Put start character + encstr 0 encs 74 get putinterval + + % Encode the FCC + 0 1 1 { + /i exch def + encs barcode i 1 getinterval cvi 64 add get + encstr i 2 mul 2 add 3 2 roll putinterval + } for + + % Encode the DPID + 2 1 9 { + /i exch def + encs barcode i 1 getinterval cvi 64 add get + encstr i 2 mul 2 add 3 2 roll putinterval + txt i 2 sub [barcode i 1 getinterval i 2 sub 2 mul 6 add 3.312 mul textyoffset textfont textsize] put + } for + + % Encode the customer information + custinfoenc (numeric) eq { + 0 1 barlen 11 sub { + /i exch def + encs barcode i 10 add 1 getinterval cvi 64 add get + encstr i 2 mul 22 add 3 2 roll putinterval + txt i 8 add [barcode i 10 add 1 getinterval i 2 mul 22 add 3.312 mul textyoffset textfont textsize] put + } for + /ciflen barlen 10 sub 2 mul def + } { + 0 1 barlen 11 sub { + /i exch def + barcode i 10 add 1 getinterval barchars exch search + pop + length /indx exch def + pop pop + /enc encs indx get def + encstr i 3 mul 22 add enc putinterval + txt i 8 add [barcode i 10 add 1 getinterval i 3 mul 22 add 3.312 mul textyoffset textfont textsize] put + } for + /ciflen barlen 10 sub 3 mul def + } ifelse + + % Add any filler characters + 22 ciflen add 1 encstr length 14 sub { + encstr exch encs 75 get putinterval + } for + + % Create the 64x64 Reed-Solomon table + /rstable 64 64 mul array def + rstable 0 [ 64 {0} repeat ] putinterval + rstable 64 [ 0 1 63 {} for ] putinterval + /prev 1 def + 64 { + /next prev 1 bitshift def + next 64 and 0 ne { + /next next 67 xor def + } if + 0 1 63 { + /j exch def + /nextcell {rstable 64 next mul j add} def + nextcell rstable 64 prev mul j add get 1 bitshift put + nextcell get 64 and 0 ne { + nextcell nextcell get 67 xor put + } if + } for + /prev next def + } repeat + + % Calculate the Reed-Solomon codes for triples + /rscodes encstr length 16 sub 3 idiv 4 add array def + rscodes 0 [ 4 {0} repeat ] putinterval + 2 3 encstr length 16 sub { + /i exch def + rscodes rscodes length i 2 sub 3 idiv sub 1 sub + encstr i 1 getinterval cvi 16 mul + encstr i 1 add 1 getinterval cvi 4 mul add + encstr i 2 add 1 getinterval cvi add + put + } for + rscodes length 5 sub -1 0 { + /i exch def + 0 1 4 { + /j exch def + rscodes i j add rscodes i j add get + rstable 64 [48 17 29 30 1] j get mul rscodes i 4 add get add get + xor put + } for + } for + /checkcode (000000000000) 12 string copy def + 0 1 3 { + /i exch def + /enc rscodes 3 i sub get 4 3 string cvrs def + checkcode i 3 mul 3 enc length sub add enc putinterval + } for + + % Put checkcode and end characters + encstr encstr length 14 sub checkcode putinterval + encstr encstr length 2 sub encs 74 get putinterval + + /bbs encstr length array def + /bhs encstr length array def + 0 1 encstr length 1 sub { + /i exch def + /enc encstr i 1 getinterval def + enc (0) eq { + bbs i 0 height mul 8 div put + bhs i 8 height mul 8 div put + } if + enc (1) eq { + bbs i 3 height mul 8 div put + bhs i 5 height mul 8 div put + } if + enc (2) eq { + bbs i 0 height mul 8 div put + bhs i 5 height mul 8 div put + } if + enc (3) eq { + bbs i 3 height mul 8 div put + bhs i 2 height mul 8 div put + } if + } for + + % Return the arguments + << + /ren //renlinear + /bbs bbs + /bhs bhs + /sbs [bhs length 1 sub {1.44 1.872} repeat 1.44] + includetext { + /txt txt + } if + /opt options + >> + + dontdraw not //renlinear if + + end + +} bind def +/auspost dup load /uk.co.terryburton.bwipp defineresource pop +end +/setpacking where {pop setpacking} if +% --END ENCODER auspost-- + +% --BEGIN ENCODER kix-- +% --DESC: Royal Dutch TPG Post KIX 4-State Barcode +% --EXAM: 1231FZ13XHS +% --EXOP: includetext includecheckintext +% --RNDR: renlinear +/setpacking where {pop currentpacking true setpacking} if +1 dict +dup /renlinear dup /uk.co.terryburton.bwipp findresource put +begin +/kix { + + 20 dict begin + + /options exch def % We are given an option string + /barcode exch def % We are given a barcode string + + /dontdraw false def + /includetext false def % Enable/disable text + /includecheckintext false def + /textfont /Courier def + /textsize 10 def + /textyoffset -7 def + /height 0.175 def + + % Parse the input options + options type /stringtype eq { + 1 dict begin + options { + token false eq {exit} if dup length string cvs (=) search + true eq {cvlit exch pop exch def} {cvlit true def} ifelse + } loop + currentdict end /options exch def + } if + options {def} forall + + /textfont textfont cvlit def + /textsize textsize cvr def + /textyoffset textyoffset cvr def + /height height cvr def + + % Create an array containing the character mappings + /encs + [ (0033) (0123) (0132) (1023) (1032) (1122) + (0213) (0303) (0312) (1203) (1212) (1302) + (0231) (0321) (0330) (1221) (1230) (1320) + (2013) (2103) (2112) (3003) (3012) (3102) + (2031) (2121) (2130) (3021) (3030) (3120) + (2211) (2301) (2310) (3201) (3210) (3300) + ] def + + % Create a string of the available characters + /barchars (0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ) def + + /barlen barcode length def + /encstr barlen 4 mul string def + /txt barlen array def + + 0 1 barlen 1 sub { + /i exch def + % Lookup the encoding for the each barcode character + barcode i 1 getinterval barchars exch search + pop % Discard true leaving pre + length /indx exch def % indx is the length of pre + pop pop % Discard seek and post + /enc encs indx get def % Get the indxth encoding + encstr i 4 mul enc putinterval + txt i [barcode i 1 getinterval i 4 mul 3.312 mul textyoffset textfont textsize] put + } for + + /bbs encstr length array def + /bhs encstr length array def + 0 1 encstr length 1 sub { + /i exch def + /enc encstr i 1 getinterval def + enc (0) eq { + bbs i 3 height mul 8 div put + bhs i 2 height mul 8 div put + } if + enc (1) eq { + bbs i 0 height mul 8 div put + bhs i 5 height mul 8 div put + } if + enc (2) eq { + bbs i 3 height mul 8 div put + bhs i 5 height mul 8 div put + } if + enc (3) eq { + bbs i 0 height mul 8 div put + bhs i 8 height mul 8 div put + } if + } for + + % Return the arguments + << + /ren //renlinear + /bbs bbs + /bhs bhs + /sbs [bhs length 1 sub {1.44 1.872} repeat 1.44] + includetext { + /txt txt + } if + /opt options + >> + + dontdraw not //renlinear if + + end + +} bind def +/kix dup load /uk.co.terryburton.bwipp defineresource pop +end +/setpacking where {pop setpacking} if +% --END ENCODER kix-- + +% --BEGIN ENCODER japanpost-- +% --DESC: Japan Post 4 State Customer Code +% --EXAM: 6540123789-A-K-Z +% --EXOP: includetext includecheckintext +% --RNDR: renlinear +/setpacking where {pop currentpacking true setpacking} if +1 dict +dup /renlinear dup /uk.co.terryburton.bwipp findresource put +begin +/japanpost { + + 20 dict begin + + /options exch def % We are given an option string + /barcode exch def % We are given a barcode string + + /dontdraw false def + /includetext false def % Enable/disable text + /includecheckintext false def + /textfont /Courier def + /textsize 10 def + /textyoffset -7 def + /height 0.175 def + + % Parse the input options + options type /stringtype eq { + 1 dict begin + options { + token false eq {exit} if dup length string cvs (=) search + true eq {cvlit exch pop exch def} {cvlit true def} ifelse + } loop + currentdict end /options exch def + } if + options {def} forall + + /textfont textfont cvlit def + /textsize textsize cvr def + /textyoffset textyoffset cvr def + /height height cvr def + + % Create an array containing the character mappings + % 0123456789- C1C2C3C4C5C6C7C8 ST EN + /encs + [ (300) (330) (312) (132) (321) (303) (123) (231) (213) (033) (030) + (120) (102) (210) (012) (201) (021) (003) (333) + (31) (13) + ] def + + % Create a string of the available characters + /barchars (0123456789-ABCDEFGHIJKLMNOPQRSTUVWXYZ) def + /barlen barcode length def + + /encstr 20 1 add 3 mul 4 add string def + /digits 20 array def + /txt barlen 1 add array def + + % Put start character + encstr 0 encs 19 get putinterval + + /checksum 0 def + /j 0 def /i 0 def + 0 1 barlen 1 sub { + /i exch def + barcode i 1 getinterval barchars exch search + pop % Discard true leaving pre + length /indx exch def % indx is the length of pre + pop pop % Discard match and post + indx 11 ge indx 37 lt and { % Insert escape + j 18 gt {exit} if % Should fit in 20 chars + % 11-20: C1 (11) + % 21-30: C2 (12) + % 31-36: C3 (13) + /digit indx 1 sub 10 idiv 10 add def + encstr j 3 mul 2 add encs digit get putinterval + /checksum checksum digit add def + digits j digit put + /j j 1 add def + } if + j 19 gt {exit} if % Should fit in 20 chars + /digit 0 def + indx 37 eq { + /digit 14 def % space (C14) + } if + indx 11 ge indx 37 lt and { + /digit indx 1 sub 10 mod def + } if + indx 11 lt { + /digit indx def + } if + encstr j 3 mul 2 add encs digit get putinterval % space + /checksum checksum digit add def + digits j digit put + txt i [barcode i 1 getinterval j 3 mul 2 add 3.312 mul textyoffset textfont textsize] put + /j j 1 add def + } for + + % Fill spaces (c14) at right end + j 1 20 1 sub { + /k exch def + encstr k 3 mul 2 add encs 14 get putinterval + /checksum checksum 14 add def + digits k 14 put + } for + + % Put the checksum character + /checksum checksum 19 mod 19 exch sub def + encstr 2 20 3 mul add encs checksum get putinterval + + % Put end character + encstr 2 21 3 mul add encs 20 get putinterval + /checkdigit ( ) def + includecheckintext { + /checkdigit barchars checksum 1 getinterval def + } if + txt i 1 add [ checkdigit 20 3 mul 2 add 3.312 mul textyoffset textfont textsize] put + + % Put end character + encstr 20 1 add 3 mul 2 add encs 20 get putinterval + + /bbs 21 3 mul 4 add array def + /bhs bbs length array def + 0 1 bbs length 1 sub { + /i exch def + /enc encstr i 1 getinterval def + /bunit 0 def + /hunit 0 def + enc (0) eq { + /bunit 3 def + /hunit 2 def + } if + enc (1) eq { + /bunit 0 def + /hunit 5 def + } if + enc (2) eq { + /bunit 3 def + /hunit 5 def + } if + enc (3) eq { + /bunit 0 def + /hunit 8 def + } if + bbs i bunit height mul 8 div put + bhs i hunit height mul 8 div put + } for + + % Return the arguments + << + /ren //renlinear + /bbs bbs + /bhs bhs + /sbs [bhs length 1 sub {1.44 1.872} repeat 1.44] + includetext { + /txt txt + } if + /opt options + >> + + dontdraw not //renlinear if + + end + +} bind def +/japanpost dup load /uk.co.terryburton.bwipp defineresource pop +end +/setpacking where {pop setpacking} if +% --END ENCODER japanpost-- + +% --BEGIN ENCODER msi-- +% --DESC: MSI Modified Plessey +% --EXAM: 0123456789 +% --EXOP: includetext includecheck includecheckintext +% --RNDR: renlinear +/setpacking where {pop currentpacking true setpacking} if +1 dict +dup /renlinear dup /uk.co.terryburton.bwipp findresource put +begin +/msi { + + 20 dict begin % Confine variables to local scope + + /options exch def % We are given an option string + /barcode exch def % We are given a barcode string + + /dontdraw false def + /includecheck false def % Enable/disable checkdigit + /includetext false def % Enable/disable text + /includecheckintext false def + /checktype (mod10) def + /badmod11 false def + /textfont /Courier def + /textsize 10 def + /textyoffset -7 def + /height 1 def + + % Parse the input options + options type /stringtype eq { + 1 dict begin + options { + token false eq {exit} if dup length string cvs (=) search + true eq {cvlit exch pop exch def} {cvlit true def} ifelse + } loop + currentdict end /options exch def + } if + options {def} forall + + /textfont textfont cvlit def + /textsize textsize cvr def + /textyoffset textyoffset cvr def + /height height cvr def + + % Create an array containing the character mappings + /encs + [ (12121212) (12121221) (12122112) (12122121) (12211212) + (12211221) (12212112) (12212121) (21121212) (21121221) + (21) (121) + ] def + + % Create a string of the available characters + /barchars (0123456789) def + + /barlen barcode length def % Length of the code + /txtlen barlen def + + /mod10 { + /code exch def + 0 0 code {48 sub exch 10 mul add exch} forall pop 2 mul + 0 {1 index 10 mod add exch 10 idiv dup 0 eq {pop exit} if exch} loop + 0 0 code {48 sub add exch} forall exch pop add + 10 mod 10 exch sub 10 mod + code length 1 add string dup 0 code putinterval dup code length 4 -1 roll 48 add put + } bind def + + /mod11 { + /code exch def + code length 1 sub code {48 sub exch dup 1 sub exch 6 mod 2 add exch} forall pop + 0 code length {3 1 roll mul add} repeat + 11 mod 11 exch sub 11 mod + dup 10 eq badmod11 and { + pop code length 2 add string dup 0 code putinterval dup code length (10) putinterval + } { + code length 1 add string dup 0 code putinterval dup code length 4 -1 roll 48 add put + } ifelse + } bind def + + /ncrmod11 { + /code exch def + code length 1 sub code {48 sub exch dup 1 sub exch 8 mod 2 add exch} forall pop + 0 code length {3 1 roll mul add} repeat + 11 mod 11 exch sub 11 mod + dup 10 eq badmod11 and { + pop code length 2 add string dup 0 code putinterval dup code length (10) putinterval + } { + code length 1 add string dup 0 code putinterval dup code length 4 -1 roll 48 add put + } ifelse + } bind def + + % Calculate checksum + includecheck { + checktype (mod10) eq {barcode mod10} if + checktype (mod1010) eq {barcode mod10 mod10} if + checktype (mod11) eq {barcode mod11} if + checktype (ncrmod11) eq {barcode ncrmod11} if + checktype (mod1110) eq {barcode mod11 mod10} if + checktype (ncrmod1110) eq {barcode ncrmod11 mod10} if + /barcode exch def + /barlen barcode length def + includecheckintext {/txtlen barlen def} if + } if + + /sbs barlen 8 mul 5 add string def + /txt barlen array def + + % Put start character + sbs 0 encs 10 get putinterval + + 0 1 barlen 1 sub { + /i exch def + % Lookup the encoding for the each barcode character + barcode i 1 getinterval barchars exch search + pop % Discard true leaving pre + length /indx exch def % indx is the length of pre + pop pop % Discard seek and post + /enc encs indx get def % Get the indxth encoding + sbs i 8 mul 2 add enc putinterval % Put encoded digit into sbs + txt i [barcode i 1 getinterval i 12 mul 3 add textyoffset textfont textsize] put + } for + + % Put the end character + sbs barlen 8 mul 2 add encs 11 get putinterval + + % Return the arguments + << + /ren //renlinear + /sbs [sbs {48 sub} forall] + /bhs [sbs length 1 add 2 idiv {height} repeat] + /bbs [sbs length 1 add 2 idiv {0} repeat] + includetext { + /txt txt 0 txtlen getinterval + } if + /opt options + >> + + dontdraw not //renlinear if + + end + +} bind def +/msi dup load /uk.co.terryburton.bwipp defineresource pop +end +/setpacking where {pop setpacking} if +% --END ENCODER msi-- + +% --BEGIN ENCODER plessey-- +% --DESC: Plessey UK +% --EXAM: 01234ABCD +% --EXOP: includetext includecheckintext +% --RNDR: renlinear +/setpacking where {pop currentpacking true setpacking} if +1 dict +dup /renlinear dup /uk.co.terryburton.bwipp findresource put +begin +/plessey { + + 20 dict begin % Confine variables to local scope + + /options exch def % We are given an option string + /barcode exch def % We are given a barcode string + + /dontdraw false def + /includetext false def % Enable/disable text + /includecheckintext false def + /unidirectional false def + /textfont /Courier def + /textsize 10 def + /textyoffset -7 def + /height 1 def + + % Parse the input options + options type /stringtype eq { + 1 dict begin + options { + token false eq {exit} if dup length string cvs (=) search + true eq {cvlit exch pop exch def} {cvlit true def} ifelse + } loop + currentdict end /options exch def + } if + options {def} forall + + /textfont textfont cvlit def + /textsize textsize cvr def + /textyoffset textyoffset cvr def + /height height cvr def + + % Create an array containing the character mappings + /encs + [ (14141414) (32141414) (14321414) (32321414) + (14143214) (32143214) (14323214) (32323214) + (14141432) (32141432) (14321432) (32321432) + (14143232) (32143232) (14323232) (32323232) + (32321432) (541412323) (323) + ] def + + % Create a string of the available characters + /barchars (0123456789ABCDEF) def + + /barlen barcode length def % Length of the code + unidirectional { + /sbs barlen 8 mul 27 add string def + } { + /sbs barlen 8 mul 33 add string def + } ifelse + /txt barlen 2 add array def + /checkbits barlen 4 mul 8 add array def + checkbits barlen 4 mul [ 0 0 0 0 0 0 0 0 ] putinterval + + % Put start character + sbs 0 encs 16 get putinterval + + 0 1 barlen 1 sub { + /i exch def + % Lookup the encoding for the each barcode character + barcode i 1 getinterval barchars exch search + pop % Discard true leaving pre + length /indx exch def % indx is the length of pre + pop pop % Discard seek and post + /enc encs indx get def % Get the indxth encoding + sbs i 8 mul 8 add enc putinterval % Put encoded digit into sbs + txt i [barcode i 1 getinterval i 20 mul 20 add textyoffset textfont textsize] put + checkbits i 4 mul [ + indx 1 and + indx -1 bitshift 1 and + indx -2 bitshift 1 and + indx -3 bitshift + ] putinterval + } for + + % Checksum is last 8 bits of a CRC using a salt + /checksalt [ 1 1 1 1 0 1 0 0 1 ] def + 0 1 barlen 4 mul 1 sub { + /i exch def + checkbits i get 1 eq { + 0 1 8 { + /j exch def + checkbits i j add checkbits i j add get checksalt j get xor put + } for + } if + } for + + % Calculate the value of the checksum digits + /checkval 0 def + 0 1 7 { + /i exch def + /checkval checkval 2 i exp cvi checkbits barlen 4 mul i add get mul add def + } for + + % Put the checksum characters + /checksum1 checkval 15 and def + /checksum2 checkval -4 bitshift def + sbs barlen 8 mul 8 add encs checksum1 get putinterval + sbs barlen 8 mul 16 add encs checksum2 get putinterval + includecheckintext { + txt barlen [barchars checksum1 1 getinterval barlen 20 mul 20 add textyoffset textfont textsize] put + txt barlen 1 add [barchars checksum2 1 getinterval barlen 1 add 20 mul 20 add textyoffset textfont textsize] put + } { + txt barlen [( ) barlen 20 mul 20 add textyoffset textfont textsize] put + txt barlen 1 add [( ) barlen 1 add 20 mul 20 add textyoffset textfont textsize] put + } ifelse + + % Put end character + unidirectional { + sbs barlen 8 mul 24 add encs 18 get putinterval + } { + sbs barlen 8 mul 24 add encs 17 get putinterval + } ifelse + + % Return the arguments + << + /ren //renlinear + /sbs [sbs {48 sub} forall] + /bhs [sbs length 1 add 2 idiv {height} repeat] + /bbs [sbs length 1 add 2 idiv {0} repeat] + includetext { + /txt txt + } if + /opt options + >> + + dontdraw not //renlinear if + + end + +} bind def +/plessey dup load /uk.co.terryburton.bwipp defineresource pop +end +/setpacking where {pop setpacking} if +% --END ENCODER plessey-- + +% --BEGIN ENCODER telepen-- +% --DESC: Telepen +% --EXAM: 123456 +% --EXOP: numeric includetext +% --RNDR: renlinear +/setpacking where {pop currentpacking true setpacking} if +1 dict +dup /renlinear dup /uk.co.terryburton.bwipp findresource put +begin +/telepen { + + 20 dict begin % Confine variables to local scope + + /options exch def % We are given an option string + /barcode exch def % We are given a barcode string + + /numeric false def + /dontdraw false def + /includetext false def % Enable/disable text + /textfont /Courier def + /textsize 10 def + /textyoffset -7 def + /height 1 def + /parse false def + + % Parse the input options + options type /stringtype eq { + 1 dict begin + options { + token false eq {exit} if dup length string cvs (=) search + true eq {cvlit exch pop exch def} {cvlit true def} ifelse + } loop + currentdict end /options exch def + } if + options {def} forall + + /textfont textfont cvlit def + /textsize textsize cvr def + /textyoffset textyoffset cvr def + /height height cvr def + + % Parse ordinals of the form ^NNN to ASCII + parse { + /msg barcode length string def + /j 0 def + barcode + { % loop + (^) search { + dup msg exch j exch putinterval + length j add 1 add /j exch def + pop + dup 0 3 getinterval cvi msg exch j 1 sub exch put + dup length 3 sub 3 exch getinterval + } { + dup msg exch j exch putinterval + length j add /j exch def + /barcode msg 0 j getinterval def + exit + } ifelse + } loop + } if + + % Create an array containing the character mappings + /encs + [ (31313131) (1131313111) (33313111) (1111313131) + (3111313111) (11333131) (13133131) (111111313111) + (31333111) (1131113131) (33113131) (1111333111) + (3111113131) (1113133111) (1311133111) (111111113131) + (3131113111) (11313331) (333331) (111131113111) + (31113331) (1133113111) (1313113111) (1111113331) + (31131331) (113111113111) (3311113111) (1111131331) + (311111113111) (1113111331) (1311111331) (11111111113111) + (31313311) (1131311131) (33311131) (1111313311) + (3111311131) (11333311) (13133311) (111111311131) + (31331131) (1131113311) (33113311) (1111331131) + (3111113311) (1113131131) (1311131131) (111111113311) + (3131111131) (1131131311) (33131311) (111131111131) + (3111131311) (1133111131) (1313111131) (111111131311) + (3113111311) (113111111131) (3311111131) (111113111311) + (311111111131) (111311111311) (131111111311) (11111111111131) + (3131311111) (11313133) (333133) (111131311111) + (31113133) (1133311111) (1313311111) (1111113133) + (313333) (113111311111) (3311311111) (11113333) + (311111311111) (11131333) (13111333) (11111111311111) + (31311133) (1131331111) (33331111) (1111311133) + (3111331111) (11331133) (13131133) (111111331111) + (3113131111) (1131111133) (33111133) (111113131111) + (3111111133) (111311131111) (131111131111) (111111111133) + (31311313) (113131111111) (3331111111) (1111311313) + (311131111111) (11331313) (13131313) (11111131111111) + (3133111111) (1131111313) (33111313) (111133111111) + (3111111313) (111313111111) (131113111111) (111111111313) + (313111111111) (1131131113) (33131113) (11113111111111) + (3111131113) (113311111111) (131311111111) (111111131113) + (3113111113) (11311111111111) (331111111111) (111113111113) + (31111111111111) (111311111113) (131111111113) (1111111111111111) + ] def + + /barlen barcode length def % Length of the code + /sbs barlen 16 mul 48 add string def + /txt barlen array def + + % Put the start character ASCII 95 + /enc encs 95 get def + sbs 0 enc putinterval + /l enc length def + + /checksum 0 def + /i 0 def /j 0 def + { % loop + i barlen eq {exit} if + numeric { % numeric mode: 00-99 & 0X-9X + barcode i get 16 gt { + /np barcode i 2 getinterval def + np 1 1 getinterval (X) eq { % X in even position amongst digits + /indx np 0 1 getinterval cvi 17 add def + } { + /indx np cvi 27 add def + } ifelse + txt j [np j 16 mul 16 add textyoffset textfont textsize] put + /i i 2 add def + } { + /indx barcode i get def + txt j [( ) j 16 mul 16 add textyoffset textfont textsize] put + /i i 1 add def + } ifelse + } { % ASCII mode + /indx barcode i get def + indx 32 ge indx 126 le and { + txt j [barcode i 1 getinterval j 16 mul 16 add textyoffset textfont textsize] put + } { + txt j [( ) j 16 mul 16 add textyoffset textfont textsize] put + } ifelse + /i i 1 add def + } ifelse + /checksum checksum indx add def + /enc encs indx get def + sbs l enc putinterval % Put encoded digit into sbs + /l l enc length add def + /j j 1 add def + } loop + + % Put the checksum character + /checksum 127 checksum 127 mod sub 127 mod def + /enc encs checksum get def + sbs l enc putinterval + /l l enc length add def + + % Put the end character ASCII 122 + /enc encs 122 get def + sbs l enc putinterval + /l l enc length add def + + % Shrink sbs and txt to fit exactly + /sbs sbs 0 l getinterval def + /txt txt 0 j getinterval def + + % Return the arguments + << + /ren //renlinear + /sbs [sbs {48 sub} forall] + /bhs [sbs length 1 add 2 idiv {height} repeat] + /bbs [sbs length 1 add 2 idiv {0} repeat] + includetext { + /txt txt + } if + /opt options + >> + + dontdraw not //renlinear if + + end + +} bind def +/telepen dup load /uk.co.terryburton.bwipp defineresource pop +end +/setpacking where {pop setpacking} if +% --END ENCODER telepen-- + +% --BEGIN ENCODER posicode-- +% --DESC: PosiCode +% --EXAM: ABC123 +% --EXOP: version=b inkspread=-0.5 parsefnc includetext +% --RNDR: renlinear +/setpacking where {pop currentpacking true setpacking} if +1 dict +dup /renlinear dup /uk.co.terryburton.bwipp findresource put +begin +/posicode { + + 20 dict begin % Confine variables to local scope + + /options exch def % We are given an option string + /barcode exch def % We are given a barcode string + + /dontdraw false def + /includetext false def % Enable/disable text + /textfont /Courier def + /textsize 10 def + /textxoffset 0 def + /textyoffset -7 def + /height 1 def + /encoding (auto) def + /version (a) def + /checkoffset 0 def + /raw false def + /parse false def + /parsefnc false def + + % Parse the input options + options type /stringtype eq { + 1 dict begin + options { + token false eq {exit} if dup length string cvs (=) search + true eq {cvlit exch pop exch def} {cvlit true def} ifelse + } loop + currentdict end /options exch def + } if + options {def} forall + + /textfont textfont cvlit def + /textsize textsize cvr def + /textxoffset textxoffset cvr def + /textyoffset textyoffset cvr def + /encoding encoding cvlit def + /version version cvlit def + /checkoffset checkoffset cvi def + /height height cvr def + + % Parse ordinals of the form ^NNN to ASCII + parse { + /msg barcode length string def + /j 0 def + barcode + { % loop + (^) search { + dup msg exch j exch putinterval + length j add 1 add /j exch def + pop + dup 0 3 getinterval cvi msg exch j 1 sub exch put + dup length 3 sub 3 exch getinterval + } { + dup msg exch j exch putinterval + length j add /j exch def + /barcode msg 0 j getinterval def + exit + } ifelse + } loop + } if + + /barlen barcode length def + + % Special function characters + /la0 -1 def /la1 -2 def /la2 -3 def + /sf0 -4 def /sf1 -5 def /sf2 -6 def + /fn1 -7 def /fn2 -8 def /fn3 -9 def /fn4 -10 def + + % Character maps for each state + << + /normal + [ + % 0 1 2 0 1 2 0 1 2 + [ (0) (^) (') ] [ (1) (;) 27 ] [ (2) (<) 28 ] % 0-2 + [ (3) (=) 29 ] [ (4) (>) 30 ] [ (5) (?) 31 ] % 3-5 + [ (6) (@) (!) ] [ (7) ([) (") ] [ (8) 92 (#) ] % 6-8 + [ (9) (]) (&) ] [ (A) (a) 1 ] [ (B) (b) 2 ] % 9-11 + [ (C) (c) 3 ] [ (D) (d) 4 ] [ (E) (e) 5 ] % 12-14 + [ (F) (f) 6 ] [ (G) (g) 7 ] [ (H) (h) 8 ] % 15-17 + [ (I) (i) 9 ] [ (J) (j) 10 ] [ (K) (k) 11 ] % 18-20 + [ (L) (l) 12 ] [ (M) (m) 13 ] [ (N) (n) 14 ] % 21-23 + [ (O) (o) 15 ] [ (P) (p) 16 ] [ (Q) (q) 17 ] % 24-26 + [ (R) (r) 18 ] [ (S) (s) 19 ] [ (T) (t) 20 ] % 27-29 + [ (U) (u) 21 ] [ (V) (v) 22 ] [ (W) (w) 23 ] % 30-32 + [ (X) (x) 24 ] [ (Y) (y) 25 ] [ (Z) (z) 26 ] % 33-35 + [ (-) (_) 40 ] [ (.) (`) 41 ] [ ( ) 127 0 ] % 36-38 + [ ($) ({) (*) ] [ (/) (|) (,) ] [ (+) (}) (:) ] % 39-41 + [ (%) (~) fn1 ] [ la1 la0 fn2 ] [ sf1 sf0 fn3 ] % 42-44 + [ sf2 sf2 fn4 ] % 45 + ] + /limited + [ + [ (0) -98 -98 ] [ (1) -98 -98 ] [ (2) -98 -98 ] % 0-2 + [ (3) -98 -98 ] [ (4) -98 -98 ] [ (5) -98 -98 ] % 3-5 + [ (6) -98 -98 ] [ (7) -98 -98 ] [ (8) -98 -98 ] % 6-8 + [ (9) -98 -98 ] [ (A) -98 -98 ] [ (B) -98 -98 ] % 9-11 + [ (C) -98 -98 ] [ (D) -98 -98 ] [ (E) -98 -98 ] % 12-14 + [ (F) -98 -98 ] [ (G) -98 -98 ] [ (H) -98 -98 ] % 15-17 + [ (I) -98 -98 ] [ (J) -98 -98 ] [ (K) -98 -98 ] % 18-20 + [ (L) -98 -98 ] [ (M) -98 -98 ] [ (N) -98 -98 ] % 21-23 + [ (O) -98 -98 ] [ (P) -98 -98 ] [ (Q) -98 -98 ] % 24-26 + [ (R) -98 -98 ] [ (S) -98 -98 ] [ (T) -98 -98 ] % 27-29 + [ (U) -98 -98 ] [ (V) -98 -98 ] [ (W) -98 -98 ] % 30-32 + [ (X) -98 -98 ] [ (Y) -98 -98 ] [ (Z) -98 -98 ] % 33-35 + [ (-) -98 -98 ] [ (.) -98 -98 ] % 36-37 + ] + >> + version (a) eq version (b) eq or {/normal} {/limited} ifelse get + /charmaps exch def + + % Invert charmaps to give character to value maps for each state + /charvals [ + charmaps length dict charmaps length dict charmaps length dict + ] def + 0 1 charmaps length 1 sub { + /i exch def + /encs charmaps i get def + 0 1 2 { + /j exch def + encs j get dup type /stringtype eq {0 get} if % convert string to ASCII if required + charvals j get exch i put + } for + } for + /set0 charvals 0 get def + /set1 charvals 1 get def + /set2 charvals 2 get def + + raw {/encoding (raw) def} if + + encoding (raw) eq { + /cws barlen array def + /i 0 def /j 0 def + { % loop + i barlen eq {exit} if + /cw barcode i 1 add 3 getinterval cvi def + cws j cw put + /i i 4 add def + /j j 1 add def + } loop + /cws cws 0 j getinterval def + /text () def + } if + + encoding (auto) eq { + + /fncvals << + (FNC1) fn1 + (FNC2) fn2 + (FNC3) fn3 + (FNC4) fn4 + >> def + + % Convert input into bytes accounting for FNC characters + /msg barlen array def + /text barlen string def + /i 0 def /j 0 def { + i barlen eq {exit} if + /char barcode i get def + text j char put + parsefnc char 94 eq and i barlen 4 sub lt and { + barcode i 1 add get 94 ne { + /char fncvals barcode i 1 add 4 getinterval get def + text j ( ) putinterval + /i i 4 add def + } { + /i i 1 add def + } ifelse + } if + msg j char put + /i i 1 add def + /j j 1 add def + } loop + /msg msg 0 j getinterval def + /msglen msg length def + /text text 0 j getinterval def + + % Convert the input message to codewords + /enc { + exch get cws exch j exch put + /j j 1 add def + } bind def + + /cws barcode length 2 mul array def + /i 0 def /j 0 def /cset (set0) def + { + i msglen eq {exit} if + + { % common exit + + % Read next two characters + /char1 msg i get def + /char2 i 1 add msglen lt {msg i 1 add get} {-99} ifelse def + + % If current mode is sufficient then directly encode + cset load char1 known { + char1 cset load enc + /i i 1 add def + exit + } if + + % If char1 is in set2 then shift encode + set2 char1 known { + sf2 cset load enc + char1 set2 enc + /i i 1 add def + exit + } if + + % If char2 is also not in this set then latch else shift encode + cset load char2 known not { + cset (set0) eq { + la1 cset load enc + /cset (set1) def + } { + la0 cset load enc + /cset (set0) def + } ifelse + exit + } { + cset (set0) eq { + sf1 cset load enc + char1 set1 enc + } { + sf0 cset load enc + char1 set0 enc + } ifelse + /i i 1 add def + exit + } ifelse + + exit + } loop + + } loop + /cws cws 0 j getinterval def + } if % auto encoding + + % Create an array containing the character mappings + << % ";"=11, "<"=12 + /a + [ (141112) (131212) (121312) (111412) (131113) + (121213) (111313) (121114) (111214) (111115) + (181111) (171211) (161311) (151411) (141511) + (131611) (121711) (111811) (171112) (161212) + (151312) (141412) (131512) (121612) (111712) + (161113) (151213) (141313) (131413) (121513) + (111613) (151114) (141214) (131314) (121414) + (111514) (141115) (131215) (121315) (111415) + (131116) (121216) (111316) (121117) (111217) + (111118) (1<111112) (111111111;1) + ] + /b + [ (151213) (141313) (131413) (121513) (141214) + (131314) (121414) (131215) (121315) (121216) + (191212) (181312) (171412) (161512) (151612) + (141712) (131812) (121912) (181213) (171313) + (161413) (151513) (141613) (131713) (121813) + (171214) (161314) (151414) (141514) (131614) + (121714) (161215) (151315) (141415) (131515) + (121615) (151216) (141316) (131416) (121516) + (141217) (131317) (121417) (131218) (121318) + (121219) (1<121312) (121212121<1) + ] + /limiteda + [ (111411) (111312) (111213) (111114) (121311) + (121212) (121113) (141111) (131211) (131112) + (171111) (161211) (151311) (141411) (131511) + (121611) (111711) (161112) (151212) (141312) + (131412) (121512) (111612) (151113) (141213) + (131313) (121413) (111513) (141114) (131214) + (121314) (111414) (131115) (121215) (111315) + (121116) (111216) (111117) (151111) (1) + ] + /limitedb + [ (121512) (121413) (121314) (121215) (131412) + (131313) (131214) (151212) (141312) (141213) + (181212) (171312) (161412) (151512) (141612) + (131712) (121812) (171213) (161313) (151413) + (141513) (131613) (121713) (161214) (151314) + (141414) (131514) (121614) (151215) (141315) + (131415) (121515) (141216) (131316) (121416) + (131217) (121317) (121218) (141212) (1) + ] + >> + version get /encs exch def + + /c2w [ + [ 495 330 210 126 70 35 15 5 ] + [ 165 120 84 56 35 20 10 4 ] + [ 45 36 28 21 15 10 6 3 ] + [ 9 8 7 6 5 4 3 2 ] + [ 1 1 1 1 1 1 1 1 ] + ] def + /v 0 def + cws { + /cw exch def + 6 { + cw v xor 1 and 0 ne { + /v v 7682 xor def + } if + /v v -1 bitshift def + /cw cw -1 bitshift def + } repeat + } forall + /v v checkoffset add def + + version (limiteda) eq version (limitedb) eq or { + /v v 1023 and def + v 824 gt v 853 lt and { + /v v 292 add def + } if + } { + /v v 1023 and 45 add def + } ifelse + + /d [ 2 2 2 2 2 2 ] def + /r 0 def /c 0 def /w 0 def /sum 0 def + { + sum v eq {exit} if + /t sum c2w r get c get add def + t v eq { + /w w 1 add def + d r w 2 add put + /sum t def + } if + t v gt { + d r w 2 add put + /r r 1 add def + /w 0 def + } if + t v lt { + /c c 1 add def + /w w 1 add def + /sum t def + } if + } loop + 20 0 1 4 {d exch get sub} for + d exch 5 exch put + version (b) eq version (limitedb) eq or { + /d [ d {1 add} forall ] def + } if + /cbs (111111111111) 12 string copy def + 5 -1 0 { + /i exch def + cbs 5 i sub 2 mul 1 add d i get 47 add put + } for + + % Concatenate the space bar successions + /sbs cws length 6 mul 31 add string def + encs encs length 2 sub get dup + sbs exch 0 exch putinterval + length /j exch def + 0 1 cws length 1 sub { + /i exch def + sbs j encs cws i get get putinterval + /j j 6 add def + } for + sbs j cbs putinterval + /j j 12 add def + encs encs length 1 sub get dup + sbs exch j exch putinterval + length j add /j exch def + /sbs sbs 0 j getinterval def + + % Return the arguments + << + /ren //renlinear + /sbs [sbs {48 sub} forall] + /bhs [sbs length 1 add 2 idiv {height} repeat] + /bbs [sbs length 1 add 2 idiv {0} repeat] + /txt [ [text textxoffset textyoffset textfont textsize] ] + /textxalign (center) + /opt options + >> + + dontdraw not //renlinear if + + end + +} bind def +/posicode dup load /uk.co.terryburton.bwipp defineresource pop +end +/setpacking where {pop setpacking} if +% --END ENCODER posicode-- + +% --BEGIN ENCODER codablockf-- +% --DESC: Codablock F +% --EXAM: CODABLOCK F 34567890123456789010040digit +% --EXOP: cols=8 +% --RNDR: renmatrix +/setpacking where {pop currentpacking true setpacking} if +1 dict +dup /renmatrix dup /uk.co.terryburton.bwipp findresource put +begin +/codablockf { + + 20 dict begin + + /options exch def + /barcode exch def + + /dontdraw false def + /rows -1 def + /cols 8 def + /rowheight 10 def + /sepheight 1 def + /encoding (auto) def + /parse false def + /parsefnc false def + + % Parse the input options + options type /stringtype eq { + 1 dict begin + options { + token false eq {exit} if dup length string cvs (=) search + true eq {cvlit exch pop exch def} {cvlit true def} ifelse + } loop + currentdict end /options exch def + } if + options {def} forall + + /rows rows cvi def + /cols cols cvi def + /rowheight rowheight cvi def + /sepheight sepheight cvi def + + cols 4 ge cols 62 le and + rows 2 ge rows 44 le and rows -1 eq or and {/c cols def} if + + % Parse ordinals of the form ^NNN to ASCII + parse { + /msg barcode length string def + /j 0 def + barcode + { % loop + (^) search { + dup msg exch j exch putinterval + length j add 1 add /j exch def + pop + dup 0 3 getinterval cvi msg exch j 1 sub exch put + dup length 3 sub 3 exch getinterval + } { + dup msg exch j exch putinterval + length j add /j exch def + /barcode msg 0 j getinterval def + exit + } ifelse + } loop + } if + + /barlen barcode length def + + % Convert input into bytes accounting for FNC characters + /swa -1 def /swb -2 def /swc -3 def /sft -4 def + /fn1 -5 def /fn2 -6 def /fn3 -7 def /fn4 -8 def + /sta -9 def /stp -10 def + + % Character maps for each state + /charmaps [ + % A B C A B C A B C + [ 32 32 (00) ] [ (!) (!) (01) ] [ (") (") (02) ] % 0-2 + [ (#) (#) (03) ] [ ($) ($) (04) ] [ (%) (%) (05) ] % 3-5 + [ (&) (&) (06) ] [ (') (') (07) ] [ 40 40 (08) ] % 6-8 + [ 41 41 (09) ] [ (*) (*) (10) ] [ (+) (+) (11) ] % 9-11 + [ (,) (,) (12) ] [ (-) (-) (13) ] [ (.) (.) (14) ] % 12-14 + [ (/) (/) (15) ] [ (0) (0) (16) ] [ (1) (1) (17) ] % 15-17 + [ (2) (2) (18) ] [ (3) (3) (19) ] [ (4) (4) (20) ] % 18-20 + [ (5) (5) (21) ] [ (6) (6) (22) ] [ (7) (7) (23) ] % 21-23 + [ (8) (8) (24) ] [ (9) (9) (25) ] [ (:) (:) (26) ] % 24-26 + [ (;) (;) (27) ] [ (<) (<) (28) ] [ (=) (=) (29) ] % 27-29 + [ (>) (>) (30) ] [ (?) (?) (31) ] [ (@) (@) (32) ] % 30-32 + [ (A) (A) (33) ] [ (B) (B) (34) ] [ (C) (C) (35) ] % 33-35 + [ (D) (D) (36) ] [ (E) (E) (37) ] [ (F) (F) (38) ] % 36-38 + [ (G) (G) (39) ] [ (H) (H) (40) ] [ (I) (I) (41) ] % 39-41 + [ (J) (J) (42) ] [ (K) (K) (43) ] [ (L) (L) (44) ] % 42-44 + [ (M) (M) (45) ] [ (N) (N) (46) ] [ (O) (O) (47) ] % 45-47 + [ (P) (P) (48) ] [ (Q) (Q) (49) ] [ (R) (R) (50) ] % 48-50 + [ (S) (S) (51) ] [ (T) (T) (52) ] [ (U) (U) (53) ] % 51-53 + [ (V) (V) (54) ] [ (W) (W) (55) ] [ (X) (X) (56) ] % 54-56 + [ (Y) (Y) (57) ] [ (Z) (Z) (58) ] [ ([) ([) (59) ] % 57-59 + [ 92 92 (60) ] [ (]) (]) (61) ] [ (^) (^) (62) ] % 60-62 + [ (_) (_) (63) ] [ 0 (`) (64) ] [ 1 (a) (65) ] % 63-65 + [ 2 (b) (66) ] [ 3 (c) (67) ] [ 4 (d) (68) ] % 66-68 + [ 5 (e) (69) ] [ 6 (f) (70) ] [ 7 (g) (71) ] % 69-71 + [ 8 (h) (72) ] [ 9 (i) (73) ] [ 10 (j) (74) ] % 72-74 + [ 11 (k) (75) ] [ 12 (l) (76) ] [ 13 (m) (77) ] % 75-77 + [ 14 (n) (78) ] [ 15 (o) (79) ] [ 16 (p) (80) ] % 78-80 + [ 17 (q) (81) ] [ 18 (r) (82) ] [ 19 (s) (83) ] % 81-83 + [ 20 (t) (84) ] [ 21 (u) (85) ] [ 22 (v) (86) ] % 84-86 + [ 23 (w) (87) ] [ 24 (x) (88) ] [ 25 (y) (89) ] % 87-89 + [ 26 (z) (90) ] [ 27 ({) (91) ] [ 28 (|) (92) ] % 90-92 + [ 29 (}) (93) ] [ 30 (~) (94) ] [ 31 127 (95) ] % 93-95 + [ fn3 fn3 (96) ] [ fn2 fn2 (97) ] [ sft sft (98) ] % 96-98 + [ swc swc (99) ] [ swb fn4 swb ] [ fn4 swa swa ] % 99-101 + [ fn1 fn1 fn1 ] [ sta sta sta ] [ stp stp stp ] % 102-104 + ] def + + % Invert charmaps to give character to value maps for each state + /charvals [ 105 dict 105 dict 105 dict ] def + 0 1 charmaps length 1 sub { + /i exch def + /encs charmaps i get def + 0 1 2 { + /j exch def + encs j get dup type /stringtype eq {0 get} if % convert string to ASCII if required + charvals j get exch i put + } for + } for + /seta charvals 0 get def + /setb charvals 1 get def + /setc charvals 2 get def + + /fncvals << + (FNC1) fn1 + (FNC2) fn2 + (FNC3) fn3 + (FNC4) fn4 + >> def + /msg barlen array def + /i 0 def /j 0 def { + i barlen eq {exit} if + /char barcode i get def + parsefnc char 94 eq and i barlen 4 sub lt and { + barcode i 1 add get 94 ne { + /char fncvals barcode i 1 add 4 getinterval get def + /i i 4 add def + } { + /i i 1 add def + } ifelse + } if + msg j char put + /i i 1 add def + /j j 1 add def + } loop + /msg msg 0 j getinterval def + /msglen msg length def + + % Determine digit runlength and characters from given position + /numsscr { + /n 0 def /s 0 def + /p exch def { + p msglen ge {exit} if + msg p get + dup setc exch known not {pop exit} if + fn1 eq { + % FNC1 in odd position of run like two digits + s 2 mod 0 eq {/s s 1 add def} {exit} ifelse + } if + /n n 1 add def + /s s 1 add def + /p p 1 add def + } loop + n s + } bind def + + % Encoding for each alphabet + /enca { + seta exch get cws exch j exch put + /j j 1 add def + } bind def + /encb { + setb exch get cws exch j exch put + /j j 1 add def + } bind def + /encc { + dup type /arraytype ne { + setc exch get + } { + aload pop 48 sub exch 48 sub 10 mul add + } ifelse + cws exch j exch put + /j j 1 add def + } bind def + + % Character exclusively in either alphabet A or B + /anotb {dup seta exch known exch setb exch known not and} bind def + /bnota {dup setb exch known exch seta exch known not and} bind def + + % Pre-compute relative position of next anotb and next bnota characters + /nextanotb [ msg length {0} repeat 9999 ] def + /nextbnota [ msg length {0} repeat 9999 ] def + msg length 1 sub -1 0 { + /i exch def + msg i get anotb { + nextanotb i 0 put + } { + nextanotb i nextanotb i 1 add get 1 add put + } ifelse + msg i get bnota { + nextbnota i 0 put + } { + nextbnota i nextbnota i 1 add get 1 add put + } ifelse + } for + + % Does a-only come before b-only after given position and vice versa + /abeforeb {dup nextanotb exch get exch nextbnota exch get lt} bind def + /bbeforea {dup nextbnota exch get exch nextanotb exch get lt} bind def + + % Add padding to row + /padrow { + { + { % common exit + cset (seta) eq {swc enca /cset (setc) def exit} if + cset (setb) eq {swc encb /cset (setc) def exit} if + cset (setc) eq {swb encc /cset (setb) def exit} if + } loop + } repeat + } bind def + + % Convert message to codewords + /cws c 5 add rows -1 ne {rows} {44} ifelse mul array def + + /i 0 def /j 0 def /r 1 def + /lastrow false def { + + lastrow {exit} if + + % Add start character and code subset selector + sta enca + i msglen lt {i numsscr} {-1 -1} ifelse /nums exch def /nchars exch def + { % common exit + msglen 0 eq { + swb enca + /cset (setb) def + exit + } if + nums 2 ge { + swc enca + /cset (setc) def + exit + } if + i abeforeb { + sft enca + /cset (seta) def + exit + } if + swb enca + /cset (setb) def + exit + } loop + /j j 1 add def % Skip row indicator position + + % Main encoding loop + /endofrow false def { + /rem c 3 add j c 5 add mod sub def % Codewords to end of row + + i msglen eq endofrow or {exit} if + + i numsscr /nums exch def /nchars exch def + + % Determine switches and shifts + { % common exit + cset (seta) eq cset (setb) eq or nums 4 ge and + msg i get fn1 ne and { + nums 2 mod 0 eq + rem 3 ge and { + swc cset (seta) eq {enca} {encb} ifelse + /cset (setc) def + 2 { + msg i get fn1 eq { + fn1 encc + /i i 1 add def + } { + msg i 2 getinterval encc + /i i 2 add def + } ifelse + } repeat + exit + } if + nums 2 mod 0 ne + rem 4 ge and { + msg i get cset (seta) eq {enca} {encb} ifelse + /i i 1 add def + swc cset (seta) eq {enca} {encb} ifelse + /cset (setc) def + 2 { + msg i get fn1 eq { + fn1 encc + /i i 1 add def + } { + msg i 2 getinterval encc + /i i 2 add def + } ifelse + } repeat + exit + } if + } if + cset (setb) eq msg i get anotb and + rem 2 ge and { + i msglen 1 sub lt { + i 1 add bbeforea { + sft encb + msg i get enca + /i i 1 add def + exit + } if + } if + swa encb + /cset (seta) def + msg i get enca + /i i 1 add def + exit + } if + cset (seta) eq msg i get bnota and + rem 2 ge and { + i msglen 1 sub lt { + i 1 add abeforeb { + sft enca + msg i get encb + /i i 1 add def + exit + } if + } if + swb enca + /cset (setb) def + msg i get encb + /i i 1 add def + exit + } if + cset (setc) eq nums 2 lt and + rem 2 ge and { + i abeforeb { + swa encc + /cset (seta) def + msg i get enca + /i i 1 add def + exit + } if + swb encc + /cset (setb) def + msg i get encb + /i i 1 add def + exit + } if + + % No switches or latches so try to encode + cset (seta) eq seta msg i get known and + rem 1 ge and { + msg i get enca + /i i 1 add def + exit + } if + cset (setb) eq setb msg i get known and + rem 1 ge and { + msg i get encb + /i i 1 add def + exit + } if + cset (setc) eq nums 2 ge and + rem 1 ge and { + msg i get fn1 eq { + fn1 encc + /i i 1 add def + } { + msg i 2 getinterval encc + /i i 2 add def + } ifelse + exit + } if + + % Encoding does not fit in the row + /endofrow true def + exit + + } loop % common exit + + } loop + + % Determine whether this is the final row + r rows eq rows -1 eq or r 1 gt and i msglen eq and rem 2 ge and { + rem 2 sub padrow + /j j 3 add def % Skip symbol and row checksum character positions + stp enca + /lastrow true def + } { + rem padrow + /j j 1 add def % Skip row checksum character positions + stp enca + /r r 1 add def + } ifelse + + } loop + /cws cws 0 j getinterval def + + % Maps for row indicators and symbol checksums + /abmap [ + 64 1 95 {} for + 0 1 15 {} for + 26 1 63 {} for + ] def + /cmap [ 0 1 85 {} for ] def + + % Add symbol check characters to last row + /chkmsg msglen array def + /j 0 def + 0 1 msglen 1 sub { + /i exch def + /char msg i get def + char 0 ge {chkmsg j char put /j j 1 add def} if + char fn1 eq i 0 ne and {chkmsg j 29 put /j j 1 add def} if + } for + /t1 0 def /t2 0 def /k1 0 def /k2 0 def + 0 1 j 1 sub { + /i exch def + /t1 chkmsg i get i mul 86 mod def + /t2 t1 chkmsg i get add 86 mod def + /k1 k1 t2 add 86 mod def + /k2 k2 t1 add 86 mod def + } for + cws cws length 4 sub cset (setc) ne {abmap} {cmap} ifelse k1 get put + cws cws length 3 sub cset (setc) ne {abmap} {cmap} ifelse k2 get put + + % Populate row indicators + cws 2 2 copy 1 sub get 99 ne {abmap} {cmap} ifelse r 2 sub get put + 1 1 r 1 sub { + /i exch def + cws i c 5 add mul 2 add 2 copy 1 sub get 99 ne {abmap} {cmap} ifelse i 42 add get put + } for + + % Calculate row check characters + 0 1 r 1 sub { + cws exch c 5 add mul c 4 add getinterval /rcws exch def + /csum rcws 0 get def + 1 1 rcws length 2 sub { + /i exch def + /csum csum rcws i get i mul add def + } for + rcws rcws length 1 sub csum 103 mod put + } for + + % Create an array containing the character mappings + /encs + [ (212222) (222122) (222221) (121223) (121322) (131222) (122213) + (122312) (132212) (221213) (221312) (231212) (112232) (122132) + (122231) (113222) (123122) (123221) (223211) (221132) (221231) + (213212) (223112) (312131) (311222) (321122) (321221) (312212) + (322112) (322211) (212123) (212321) (232121) (111323) (131123) + (131321) (112313) (132113) (132311) (211313) (231113) (231311) + (112133) (112331) (132131) (113123) (113321) (133121) (313121) + (211331) (231131) (213113) (213311) (213131) (311123) (311321) + (331121) (312113) (312311) (332111) (314111) (221411) (431111) + (111224) (111422) (121124) (121421) (141122) (141221) (112214) + (112412) (122114) (122411) (142112) (142211) (241211) (221114) + (413111) (241112) (134111) (111242) (121142) (121241) (114212) + (124112) (124211) (411212) (421112) (421211) (212141) (214121) + (412121) (111143) (111341) (131141) (114113) (114311) (411113) + (411311) (113141) (114131) (311141) (411131) (211412) (2331112) + ] def + + % Derive the bits for each row + /rowbits r array def + 0 1 r 1 sub { + /i exch def + /sbs [ + cws i c 5 add mul c 5 add getinterval { + encs exch get {48 sub} forall + } forall + ] def + mark + 0 sbs {1 index 1 eq {{0}} {{1}} ifelse repeat} forall + counttomark 1 sub array astore exch pop exch pop + rowbits i 3 -1 roll put + } for + + % Populate the bitmap + /symwid c 11 mul 57 add def + /pixs [ + symwid sepheight mul {1} repeat + 0 1 r 2 sub { + /i exch def + rowheight {rowbits i get aload pop} repeat + sepheight { + 1 1 0 1 0 0 0 0 1 0 0 + symwid 24 sub {1} repeat + 1 1 0 0 0 1 1 1 0 1 0 1 1 + } repeat + } for + rowheight {rowbits r 1 sub get aload pop} repeat + symwid sepheight mul {1} repeat + ] def + + % Return the arguments + << + /ren //renmatrix + /pixs pixs + /pixx symwid + /pixy pixs length symwid idiv + /height pixs length symwid idiv 72 div + /width symwid 72 div + /opt options + >> + + dontdraw not //renmatrix if + + end + +} bind def +/codablockf dup load /uk.co.terryburton.bwipp defineresource pop +end +/setpacking where {pop setpacking} if +% --END ENCODER codablockf-- + +% --BEGIN ENCODER code16k-- +% --DESC: Code 16K +% --EXAM: Abcd-1234567890-wxyZ +% --EXOP: +% --RNDR: renmatrix +/setpacking where {pop currentpacking true setpacking} if +1 dict +dup /renmatrix dup /uk.co.terryburton.bwipp findresource put +begin +/code16k { + + 20 dict begin + + /options exch def + /barcode exch def + + /dontdraw false def + /mode -1 def + /pos -1 def + /rows 0 def + /rowheight 8 def + /sepheight 1 def + /encoding (auto) def + /raw false def + /parse false def + /parsefnc false def + + % Parse the input options + options type /stringtype eq { + 1 dict begin + options { + token false eq {exit} if dup length string cvs (=) search + true eq {cvlit exch pop exch def} {cvlit true def} ifelse + } loop + currentdict end /options exch def + } if + options {def} forall + + /mode mode cvi def + /pos pos cvi def + /rows rows cvi def + /rowheight rowheight cvi def + /sepheight sepheight cvi def + + pos -1 ne {/rows 16 def} if + + % Parse ordinals of the form ^NNN to ASCII + parse { + /msg barcode length string def + /j 0 def + barcode + { % loop + (^) search { + dup msg exch j exch putinterval + length j add 1 add /j exch def + pop + dup 0 3 getinterval cvi msg exch j 1 sub exch put + dup length 3 sub 3 exch getinterval + } { + dup msg exch j exch putinterval + length j add /j exch def + /barcode msg 0 j getinterval def + exit + } ifelse + } loop + } if + + /barlen barcode length def + + % Convert input into bytes accounting for FNC characters + /swa -1 def /swb -2 def /swc -3 def + /sa1 -4 def /sb1 -5 def /sc1 -6 def + /sa2 -7 def /sb2 -8 def /sc2 -9 def + /pad -10 def /sb3 -11 def /sc3 -12 def + /fn1 -13 def /fn2 -14 def /fn3 -15 def /fn4 -16 def + + % Character maps for each state + /charmaps [ + % A B C A B C A B C + [ 32 32 (00) ] [ (!) (!) (01) ] [ (") (") (02) ] % 0-2 + [ (#) (#) (03) ] [ ($) ($) (04) ] [ (%) (%) (05) ] % 3-5 + [ (&) (&) (06) ] [ (') (') (07) ] [ 40 40 (08) ] % 6-8 + [ 41 41 (09) ] [ (*) (*) (10) ] [ (+) (+) (11) ] % 9-11 + [ (,) (,) (12) ] [ (-) (-) (13) ] [ (.) (.) (14) ] % 12-14 + [ (/) (/) (15) ] [ (0) (0) (16) ] [ (1) (1) (17) ] % 15-17 + [ (2) (2) (18) ] [ (3) (3) (19) ] [ (4) (4) (20) ] % 18-20 + [ (5) (5) (21) ] [ (6) (6) (22) ] [ (7) (7) (23) ] % 21-23 + [ (8) (8) (24) ] [ (9) (9) (25) ] [ (:) (:) (26) ] % 24-26 + [ (;) (;) (27) ] [ (<) (<) (28) ] [ (=) (=) (29) ] % 27-29 + [ (>) (>) (30) ] [ (?) (?) (31) ] [ (@) (@) (32) ] % 30-32 + [ (A) (A) (33) ] [ (B) (B) (34) ] [ (C) (C) (35) ] % 33-35 + [ (D) (D) (36) ] [ (E) (E) (37) ] [ (F) (F) (38) ] % 36-38 + [ (G) (G) (39) ] [ (H) (H) (40) ] [ (I) (I) (41) ] % 39-41 + [ (J) (J) (42) ] [ (K) (K) (43) ] [ (L) (L) (44) ] % 42-44 + [ (M) (M) (45) ] [ (N) (N) (46) ] [ (O) (O) (47) ] % 45-47 + [ (P) (P) (48) ] [ (Q) (Q) (49) ] [ (R) (R) (50) ] % 48-50 + [ (S) (S) (51) ] [ (T) (T) (52) ] [ (U) (U) (53) ] % 51-53 + [ (V) (V) (54) ] [ (W) (W) (55) ] [ (X) (X) (56) ] % 54-56 + [ (Y) (Y) (57) ] [ (Z) (Z) (58) ] [ ([) ([) (59) ] % 57-59 + [ 92 92 (60) ] [ (]) (]) (61) ] [ (^) (^) (62) ] % 60-62 + [ (_) (_) (63) ] [ 0 (`) (64) ] [ 1 (a) (65) ] % 63-65 + [ 2 (b) (66) ] [ 3 (c) (67) ] [ 4 (d) (68) ] % 66-68 + [ 5 (e) (69) ] [ 6 (f) (70) ] [ 7 (g) (71) ] % 69-71 + [ 8 (h) (72) ] [ 9 (i) (73) ] [ 10 (j) (74) ] % 72-74 + [ 11 (k) (75) ] [ 12 (l) (76) ] [ 13 (m) (77) ] % 75-77 + [ 14 (n) (78) ] [ 15 (o) (79) ] [ 16 (p) (80) ] % 78-80 + [ 17 (q) (81) ] [ 18 (r) (82) ] [ 19 (s) (83) ] % 81-83 + [ 20 (t) (84) ] [ 21 (u) (85) ] [ 22 (v) (86) ] % 84-86 + [ 23 (w) (87) ] [ 24 (x) (88) ] [ 25 (y) (89) ] % 87-89 + [ 26 (z) (90) ] [ 27 ({) (91) ] [ 28 (|) (92) ] % 90-92 + [ 29 (}) (93) ] [ 30 (~) (94) ] [ 31 127 (95) ] % 93-95 + [ fn3 fn3 (96) ] [ fn2 fn2 (97) ] [ sb1 sa1 (98) ] % 96-98 + [ swc swc (99) ] [ swb fn4 swb ] [ fn4 swa swa ] % 99-101 + [ fn1 fn1 fn1 ] [ pad pad pad ] [ sb2 sa2 sb1 ] % 102-104 + [ sc2 sc2 sb2 ] [ sc3 sc3 sb3 ] % 105-106 + ] def + + % Invert charmaps to give character to value maps for each state + /charvals [ 109 dict 109 dict 109 dict ] def + 0 1 charmaps length 1 sub { + /i exch def + /encs charmaps i get def + 0 1 2 { + /j exch def + encs j get dup type /stringtype eq {0 get} if % convert string to ASCII if required + charvals j get exch i put + } for + } for + /seta charvals 0 get def + /setb charvals 1 get def + /setc charvals 2 get def + + raw {/encoding (raw) def} if + + encoding (raw) eq { + /cws barlen array def + /i 0 def /j 0 def + { % loop + i barlen eq {exit} if + /cw barcode i 1 add 3 getinterval cvi def + cws j cw put + /i i 4 add def + /j j 1 add def + } loop + /cws cws 0 j getinterval def + /text () def + } if + + encoding (auto) eq { + + /fncvals << + (FNC1) fn1 + (FNC2) fn2 + (FNC3) fn3 + (FNC4) fn4 + >> def + /msg barlen array def + /i 0 def /j 0 def { + i barlen eq {exit} if + /char barcode i get def + parsefnc char 94 eq and i barlen 4 sub lt and { + barcode i 1 add get 94 ne { + /char fncvals barcode i 1 add 4 getinterval get def + /i i 4 add def + } { + /i i 1 add def + } ifelse + } if + msg j char put + /i i 1 add def + /j j 1 add def + } loop + /msg msg 0 j getinterval def + /msglen msg length def + + % Determine digit runlength and characters from given position + /numsscr { + /n 0 def /s 0 def + /p exch def { + p msglen ge {exit} if + msg p get + dup setc exch known not {pop exit} if + fn1 eq { + % FNC1 in odd position of run like two digits + s 2 mod 0 eq {/s s 1 add def} {exit} ifelse + } if + /n n 1 add def + /s s 1 add def + /p p 1 add def + } loop + n s + } bind def + + % Encoding for each alphabet + /enca { + seta exch get cws exch j exch put + /j j 1 add def + } bind def + /encb { + setb exch get cws exch j exch put + /j j 1 add def + } bind def + /encc { + dup type /arraytype ne { + setc exch get + } { + aload pop 48 sub exch 48 sub 10 mul add + } ifelse + cws exch j exch put + /j j 1 add def + } bind def + + % Character exclusively in either alphabet A or B + /anotb {dup seta exch known exch setb exch known not and} bind def + /bnota {dup setb exch known exch seta exch known not and} bind def + + % Pre-compute relative position of next anotb and next bnota characters + /nextanotb [ msg length {0} repeat 9999 ] def + /nextbnota [ msg length {0} repeat 9999 ] def + msg length 1 sub -1 0 { + /i exch def + msg i get anotb { + nextanotb i 0 put + } { + nextanotb i nextanotb i 1 add get 1 add put + } ifelse + msg i get bnota { + nextbnota i 0 put + } { + nextbnota i nextbnota i 1 add get 1 add put + } ifelse + } for + + % Does a-only come before b-only after given position and vice versa + /abeforeb {dup nextanotb exch get exch nextbnota exch get lt} bind def + /bbeforea {dup nextbnota exch get exch nextanotb exch get lt} bind def + + /cws barcode length 2 mul 3 add array def + + % Select mode and encode first characters + /i 0 def /j 0 def + { % common exit + % extended data length + pos -1 ne { + % encode one and two + cws 0 pos 10 idiv 1 sub put + cws 1 pos 10 mod 1 sub put + /j 2 def + /cset (setb) def + /mode 7 def + exit + } if + % empty => b + msglen 0 eq { + /cset (setb) def + /mode 1 def + exit + } if + % FNC1 . 2+ nums => c fnc1 + msglen 2 ge { + msg 0 get fn1 eq 1 numsscr exch pop 2 ge and { + /cset (setc) def + /mode 4 def + /i 1 def + exit + } if + } if + % FNC1 => b fnc1 + msg 0 get fn1 eq { + /cset (setb) def + /mode 3 def + /i 1 def + exit + } if + msglen 2 ge { + % 2+ even nums => c + 0 numsscr exch pop dup 2 ge exch 2 mod 0 eq and { + /cset (setc) def + /mode 2 def + exit + } if + % 3+ odd nums => c sb1 encode + 0 numsscr exch pop dup 3 ge exch 2 mod 1 eq and { + msg 0 get encb + /cset (setc) def + /mode 5 def + /i 1 def + exit + } if + % b . 2+ even nums => c sb1 encode + setb msg 0 get known + 1 numsscr exch pop dup 2 ge exch 2 mod 0 eq and and { + msg 0 get encb + /cset (setc) def + /mode 5 def + /i 1 def + exit + } if + % b . 3+ odd nums => c sb2 encode + setb msg 0 get known + 1 numsscr exch pop dup 3 ge exch 2 mod 1 eq and and { + msg 0 get encb + msg 1 get encb + /cset (setc) def + /mode 6 def + /i 2 def + exit + } if + % b . b . 2+ even nums => c sb2 encode + setb msg 0 get known + setb msg 1 get known and + 2 numsscr exch pop dup 2 ge exch 2 mod 0 eq and and { + msg 0 get encb + msg 1 get encb + /cset (setc) def + /mode 6 def + /i 2 def + exit + } if + } if + % anotb before bnota => a + 0 abeforeb { + /cset (seta) def + /mode 0 def + exit + } if + % otherwise => b + /cset (setb) def + /mode 1 def + exit + } loop + + { % Encode remainder + i msglen eq {exit} if + + i numsscr /nums exch def /nchars exch def + + % Determine switches and shifts + { % common exit + cset (seta) eq { + % bnota . anotb before bnota => sb1 encode + i msglen 1 sub lt { + msg i get bnota + i 1 add abeforeb and { + sb1 enca + msg i get encb + /i i 1 add def + exit + } if + } if + % bnota . bnota . anotb before bnota => sb2 encode + i msglen 2 sub lt { + msg i get bnota + msg i 1 add get bnota and + i 2 add abeforeb and { + sb2 enca + msg i get encb + msg i 1 add get encb + /i i 2 add def + exit + } if + } if + % bnota => swb + msg i get bnota { + swb enca + /cset (setb) def + exit + } if + % 4 nums . a => sc2 encode + i msglen 4 sub lt { + nums 4 eq + seta msg i 4 add get known and { + sc2 enca + 2 { + msg i get fn1 eq { + fn1 encc + /i i 1 add def + } { + msg i 2 getinterval encc + /i i 2 add def + } ifelse + } repeat + exit + } if + } if + % 6 nums . a => sc3 encode + i msglen 6 sub lt { + nums 6 eq + seta msg i 6 add get known and { + sc3 enca + 3 { + msg i get fn1 eq { + fn1 encc + /i i 1 add def + } { + msg i 2 getinterval encc + /i i 2 add def + } ifelse + } repeat + exit + } if + } if + % 4+ even nums => swc + nums 4 ge nums 2 mod 0 eq and { + swc enca + /cset (setc) def + exit + } if + % otherwise => encode + msg i get enca + /i i 1 add def + exit + } if + cset (setb) eq { + % anotb . bnota before anotb => sa1 encode + i msglen 1 sub lt { + msg i get anotb + i 1 add bbeforea and { + sa1 encb + msg i get enca + /i i 1 add def + exit + } if + } if + % anotb . anotb . bnota before anotb => sa2 encode + i msglen 2 sub lt { + msg i get anotb + msg i 1 add get anotb and + i 2 add bbeforea and { + sa2 encb + msg i get enca + msg i 1 add get enca + /i i 2 add def + exit + } if + } if + % anotb => swa + msg i get anotb { + swa encb + /cset (seta) def + exit + } if + % 4 nums . b => sc2 encode + i msglen 4 sub lt { + nums 4 eq + setb msg i 4 add get known and { + sc2 encb + 2 { + msg i get fn1 eq { + fn1 encc + /i i 1 add def + } { + msg i 2 getinterval encc + /i i 2 add def + } ifelse + } repeat + exit + } if + } if + % 6 nums . b => sc3 encode + i msglen 6 sub lt { + nums 6 eq + setb msg i 6 add get known and { + sc3 encb + 3 { + msg i get fn1 eq { + fn1 encc + /i i 1 add def + } { + msg i 2 getinterval encc + /i i 2 add def + } ifelse + } repeat + exit + } if + } if + % 4+ even nums => swc + nums 4 ge nums 2 mod 0 eq and { + swc encb + /cset (setc) def + exit + } if + % otherwise => encode + msg i get encb + /i i 1 add def + exit + } if + cset (setc) eq { + % 2+ nums => encode + nums 2 ge { + msg i get fn1 eq { + fn1 encc + /i i 1 add def + } { + msg i 2 getinterval encc + /i i 2 add def + } ifelse + exit + } if + % b . 2+ even nums => sb1 encode + i msglen 1 sub lt { + setb msg i get known + i 1 add numsscr exch pop dup 2 ge exch 2 mod 0 eq and and { + sb1 encc + msg i get encb + /i i 1 add def + exit + } if + } if + % b . 3+ odd nums => sb2 encode + i msglen 1 sub lt { + setb msg i get known + i 1 add numsscr exch pop dup 3 ge exch 2 mod 1 eq and and { + sb2 encc + msg i get encb + msg i 1 add get encb + /i i 2 add def + exit + } if + } if + % b . b . 2+ even nums => sb2 encode + i msglen 2 sub lt { + setb msg i get known + setb msg i 1 add get known and + i 2 add numsscr exch pop dup 2 ge exch 2 mod 0 eq and and { + sb2 encc + msg i get encb + msg i 1 add get encb + /i i 2 add def + exit + } if + } if + % b . b . 3+ odd nums => sb3 encode + i msglen 3 sub lt { + setb msg i get known + setb msg i 1 add get known and + i 2 add numsscr exch pop dup 3 ge exch 2 mod 1 eq and and { + sb3 encc + msg i get encb + msg i 1 add get encb + msg i 2 add get encb + /i i 3 add def + exit + } if + } if + % b . b . b . 2+ even nums => sb3 encode + i msglen 3 sub lt { + setb msg i get known + setb msg i 1 add get known and + setb msg i 2 add get known and + i 3 add numsscr exch pop dup 2 ge exch 2 mod 0 eq and and { + sb3 encc + msg i get encb + msg i 1 add get encb + msg i 2 add get encb + /i i 3 add def + exit + } if + } if + % anotb before bnota => swa + i abeforeb { + swa encc + /cset (seta) def + exit + } if + % otherwise => swb + swb encc + /cset (setb) def + exit + } if + exit + } loop + + } loop + /cws cws 0 j getinterval def + } if % auto encoding + + % Basic metrics for the each symbol + % r dcws + /metrics [ + [ 2 7 ] + [ 3 12 ] + [ 4 17 ] + [ 5 22 ] + [ 6 27 ] + [ 7 32 ] + [ 8 37 ] + [ 9 42 ] + [ 10 47 ] + [ 11 52 ] + [ 12 57 ] + [ 13 62 ] + [ 14 67 ] + [ 15 72 ] + [ 16 77 ] + ] def + + % Select metrics of an appropriate symbol + /urows rows def + /i 0 def + { % loop + /m metrics i get def + /r m 0 get def % Columns in symbol + /dcws m 1 get def % Data codewords in symbol + /okay true def + urows 0 ne urows r ne and {/okay false def} if + cws length dcws gt {/okay false def} if + okay {exit} if + /i i 1 add def + } loop + + % Extend cws to ncws codewords by addition of pad characters + /cws [ cws aload pop dcws cws length sub {103} repeat ] def + + % Add the start character + /cws [ r 2 sub 7 mul mode add cws aload pop ] def + + % Calculate the check characters + 0 0 1 dcws {dup 2 add exch cws exch get mul add} for + 107 mod /c1 exch def + 0 0 1 dcws {dup 1 add exch cws exch get mul add} for + c1 dcws 2 add mul add 107 mod /c2 exch def + /cws [ cws aload pop c1 c2 ] def + + % Create an array containing the character mappings + /encs + [ (212222) (222122) (222221) (121223) (121322) (131222) (122213) + (122312) (132212) (221213) (221312) (231212) (112232) (122132) + (122231) (113222) (123122) (123221) (223211) (221132) (221231) + (213212) (223112) (312131) (311222) (321122) (321221) (312212) + (322112) (322211) (212123) (212321) (232121) (111323) (131123) + (131321) (112313) (132113) (132311) (211313) (231113) (231311) + (112133) (112331) (132131) (113123) (113321) (133121) (313121) + (211331) (231131) (213113) (213311) (213131) (311123) (311321) + (331121) (312113) (312311) (332111) (314111) (221411) (431111) + (111224) (111422) (121124) (121421) (141122) (141221) (112214) + (112412) (122114) (122411) (142112) (142211) (241211) (221114) + (413111) (241112) (134111) (111242) (121142) (121241) (114212) + (124112) (124211) (411212) (421112) (421211) (212141) (214121) + (412121) (111143) (111341) (131141) (114113) (114311) (411113) + (411311) (113141) (114131) (311141) (411131) (211412) (211214) + (211232) (211133) + ] def + + % Start/stop character encodings + /startencs [ + (3211) (2221) (2122) (1411) (1132) (1231) (1114) (3112) + (3211) (2221) (2122) (1411) (1132) (1231) (1114) (3112) + ] def + /stopencsodd [ + (3211) (2221) (2122) (1411) (1132) (1231) (1114) (3112) + (1132) (1231) (1114) (3112) (3211) (2221) (2122) (1411) + ] def + /stopencseven [ + (2122) (1411) (1132) (1231) (1114) (3112) (1132) (1231) + (1114) (3112) (3211) (2221) (2122) (1411) (3211) (2221) + ] def + pos -1 eq pos 10 idiv 2 mod 1 eq or { + /stopencs stopencsodd def + } { + /stopencs stopencseven def + } ifelse + + % Derive the bits for each row + /rowbits r array def + 0 1 r 1 sub { + /i exch def + /sbs [ + 10 + startencs i get {48 sub} forall + 1 + cws i 5 mul 5 getinterval { + encs exch get {48 sub} forall + } forall + stopencs i get {48 sub} forall + 1 + ] def + mark + 1 sbs {1 index 0 eq {{1}} {{0}} ifelse repeat} forall + counttomark 1 sub array astore exch pop exch pop + rowbits i 3 -1 roll put + } for + + % Populate the bitmap + /pixs [ + 81 sepheight mul {1} repeat + 0 1 r 2 sub { + /i exch def + rowheight {rowbits i get aload pop} repeat + sepheight {10 {0} repeat 70 {1} repeat 0} repeat + } for + rowheight {rowbits r 1 sub get aload pop} repeat + 81 sepheight mul {1} repeat + ] def + + % Return the arguments + << + /ren //renmatrix + /pixs pixs + /pixx 81 + /pixy pixs length 81 idiv + /height pixs length 81 idiv 72 div + /width 81 72 div + /opt options + >> + + dontdraw not //renmatrix if + + end + +} bind def +/code16k dup load /uk.co.terryburton.bwipp defineresource pop +end +/setpacking where {pop setpacking} if +% --END ENCODER code16k-- + +% --BEGIN ENCODER code49-- +% --DESC: Code 49 +% --EXAM: MULTIPLE ROWS IN CODE 49 +% --EXOP: +% --RNDR: renmatrix +/setpacking where {pop currentpacking true setpacking} if +1 dict +dup /renmatrix dup /uk.co.terryburton.bwipp findresource put +begin +/code49 { + + 20 dict begin + + /options exch def + /barcode exch def + + /dontdraw false def + /mode -1 def + /pos -1 def + /rows 0 def + /rowheight 8 def + /sepheight 1 def + /parse false def + /parsefnc false def + + % Parse the input options + options type /stringtype eq { + 1 dict begin + options { + token false eq {exit} if dup length string cvs (=) search + true eq {cvlit exch pop exch def} {cvlit true def} ifelse + } loop + currentdict end /options exch def + } if + options {def} forall + + /mode mode cvi def + /pos pos cvi def + /rows rows cvi def + /rowheight rowheight cvi def + /sepheight sepheight cvi def + + % Parse ordinals of the form ^NNN to ASCII + parse { + /msg barcode length string def + /j 0 def + barcode + { % loop + (^) search { + dup msg exch j exch putinterval + length j add 1 add /j exch def + pop + dup 0 3 getinterval cvi msg exch j 1 sub exch put + dup length 3 sub 3 exch getinterval + } { + dup msg exch j exch putinterval + length j add /j exch def + /barcode msg 0 j getinterval def + exit + } ifelse + } loop + } if + + /barlen barcode length def + + % Convert input into bytes accounting for FNC characters + /s1 -1 def /s2 -2 def /fn1 -3 def /fn2 -4 def /fn3 -5 def /ns -6 def + /fncvals << + (FNC1) fn1 + (FNC2) fn2 + (FNC3) fn3 + >> def + /msg barlen array def + /i 0 def /j 0 def { + i barlen eq {exit} if + /char barcode i get def + parsefnc char 94 eq and i barlen 4 sub lt and { + barcode i 1 add get 94 ne { + /char fncvals barcode i 1 add 4 getinterval get def + /i i 4 add def + } { + /i i 1 add def + } ifelse + } if + msg j char put + /i i 1 add def + /j j 1 add def + } loop + /msg msg 0 j getinterval def + /msglen msg length def + + % Character encodings + /charmap [ + (0) (1) (2) (3) (4) (5) (6) (7) (8) (9) + (A) (B) (C) (D) (E) (F) (G) (H) (I) (J) (K) (L) (M) + (N) (O) (P) (Q) (R) (S) (T) (U) (V) (W) (X) (Y) (Z) + (-) (.) ( ) ($) (/) (+) (%) + s1 s2 fn1 fn2 fn3 ns + ] def + + % Invert charmap to give character to value map + /charvals 49 dict def + 0 1 48 { + /i exch def + charmap i get + dup type /stringtype eq {0 get} if % convert string to ASCII if required + charvals exch i put + } for + + % Shifted character encodings + /combos + [ (1 ) (1A) (1B) (1C) (1D) (1E) (1F) (1G) (1H) (1I) (1J) (1K) (1L) (1M) (1N) (1O) + (1P) (1Q) (1R) (1S) (1T) (1U) (1V) (1W) (1X) (1Y) (1Z) (11) (12) (13) (14) (15) + ( ) (16) (17) (18) ( $) ( %) (19) (10) (1-) (1.) (1$) ( +) (1/) ( -) ( .) ( /) + ( 0) ( 1) ( 2) ( 3) ( 4) ( 5) ( 6) ( 7) ( 8) ( 9) (1+) (21) (22) (23) (24) (25) + (26) ( A) ( B) ( C) ( D) ( E) ( F) ( G) ( H) ( I) ( J) ( K) ( L) ( M) ( N) ( O) + ( P) ( Q) ( R) ( S) ( T) ( U) ( V) ( W) ( X) ( Y) ( Z) (27) (28) (29) (20) (2-) + (2.) (2A) (2B) (2C) (2D) (2E) (2F) (2G) (2H) (2I) (2J) (2K) (2L) (2M) (2N) (2O) + (2P) (2Q) (2R) (2S) (2T) (2U) (2V) (2W) (2X) (2Y) (2Z) (2$) (2/) (2+) (2%) (2 ) + ] def + 0 1 127 { + /i exch def + combos i get dup 0 get /c1 exch def 1 get /c2 exch def + c1 49 eq { % s1 char + charvals i [ charvals s1 get charvals c2 get ] put + } if + c1 50 eq { % s2 char + charvals i [ charvals s2 get charvals c2 get ] put + } if + } for + + /encodealpha { + charvals exch get + dup type /arraytype ne {1 array astore} if + dup cws exch j exch putinterval + length j add /j exch def + } bind def + + /base48 { + 0 exch {48 sub exch 10 mul add} forall + [ 3 1 roll exch 1 sub {dup 48 mod exch 48 idiv} repeat ] + [ exch dup length 1 sub -1 0 {1 index exch get exch} for pop ] + dup cws exch j exch putinterval + length j add /j exch def + } bind def + + /encodenumeric { + /nums exch def + /pre nums length dup 5 mod dup 2 ne {sub} {sub 5 sub} ifelse def + 0 5 pre 1 sub {nums exch 5 getinterval 3 exch base48} for + /nums nums pre nums length pre sub getinterval def + nums length + dup 1 eq {nums i get encodealpha} if + dup 3 eq {2 nums base48} if + dup 4 eq {3 [49 48 nums aload pop] base48} if + 7 eq { + 3 [49 48 nums 0 4 getinterval aload pop] base48 + 2 nums 4 3 getinterval base48 + } if + } bind def + + % Pre-compute alphanumeric and numeric runlengths + /numericruns [ msglen {0} repeat 0 ] def + msglen 1 sub -1 0 { + /i exch def + msg i get + dup 48 ge exch 57 le and { + numericruns i numericruns i 1 add get 1 add put + } { + numericruns i 0 put + } ifelse + } for + + % Autoselect mode + mode -1 eq { + { % common exit + pos -1 ne {/mode 3 def exit} if + numericruns 0 get 5 ge {/mode 2 def exit} if + charvals msg 0 get get + dup type /arraytype ne {pop /mode 0 def exit} if + 0 get 43 eq {4} {5} ifelse /mode exch def + exit + } loop + } if + + /cws msglen 2 mul 1 add array def + /method (alpha) def /i -1 def /j -1 def + + % Handle start for each mode + mode 0 eq mode 1 eq or {/method (alpha) def /i 0 def /j 0 def} if + mode 2 eq {/method (numeric) def /i 0 def /j 0 def} if + mode 3 eq { + /posval [ + 12 22 + 13 23 33 + 14 24 34 44 + 15 25 35 45 55 + 16 26 36 46 56 66 + 17 27 37 47 57 67 77 + 18 28 38 48 58 68 78 88 + 19 29 39 49 59 69 79 89 99 + ] def + cws 0 0 1 43 {dup posval exch get pos ne {pop} if} for 1 add put + /method (alpha) def /i 0 def /j 1 def + } if + mode 4 eq mode 5 eq or { + cws 0 charvals msg 0 get get 1 get put + /method (alpha) def /i 1 def /j 1 def + } if + + % Encode remainder + { + i msglen eq {exit} if + { % not a loop but common exit point + method (alpha) eq { + numericruns i get 5 ge { + ns encodealpha + /method (numeric) def + exit + } if + msg i get encodealpha + /i i 1 add def + exit + } if + method (numeric) eq { + numericruns i get 5 lt { + ns encodealpha + /method (alpha) def + exit + } if + msg i numericruns i get getinterval encodenumeric + /i i numericruns i get add def + exit + } if + } loop + } loop + /cws cws 0 j getinterval def + + % Basic metrics for the each symbol + % r dcws + /metrics [ + [ 2 9 ] + [ 3 16 ] + [ 4 23 ] + [ 5 30 ] + [ 6 37 ] + [ 7 42 ] + [ 8 49 ] + ] def + + % Select metrics of an appropriate symbol + /urows rows def + /i 0 def + { % loop + /m metrics i get def + /r m 0 get def % Columns in symbol + /dcws m 1 get def % Data codewords in symbol + /okay true def + urows 0 ne urows r ne and {/okay false def} if + cws length dcws gt {/okay false def} if + okay {exit} if + /i i 1 add def + } loop + + % Extend cws to ncws codewords by addition of pad characters + /cws [ cws aload pop dcws cws length sub {48} repeat ] def + + % Populate code character array and add row check characters + /ccs r 8 mul array def + /j 0 def + 0 1 r 2 sub { + /i exch def + /cc cws j 7 getinterval def + ccs i 8 mul cc putinterval + ccs i 8 mul 7 add 0 cc {add} forall 49 mod put + /j j 7 add def + } for + j dcws lt { + ccs ccs length 8 sub cws j dcws j sub getinterval putinterval + } if + + % Place row count character + /cr7 r 2 sub 7 mul mode add def + ccs ccs length 2 sub cr7 put + + % Calculate the symbol check characters + [ 1 9 31 26 2 12 17 23 37 18 22 6 27 44 15 43 39 + 11 13 5 41 33 36 8 4 32 3 19 40 25 29 10 24 30 ] + dup [ exch 20 exch 0 32 getinterval aload pop ] /weightx exch def + dup [ exch 16 exch 1 32 getinterval aload pop ] /weighty exch def + [ exch 38 exch 2 32 getinterval aload pop ] /weightz exch def + /calccheck { + /weights exch def + /score 0 def + 0 1 r 1 sub 8 mul 2 idiv 1 sub { + /i exch def + ccs i 2 mul get 49 mul ccs i 2 mul 1 add get add + weights i 1 add get mul /score exch score add def + } for + score + } bind def + /lastrow ccs ccs length 8 sub 8 getinterval def + + % wr1 check character + r 7 ge { + cr7 weightz 0 get mul weightz calccheck add 2401 mod + dup 49 idiv exch 49 mod 2 array astore + lastrow 0 3 -1 roll putinterval + } if + /wr1 lastrow 0 get 49 mul lastrow 1 get add def + + % wr2 check character + cr7 weighty 0 get mul weighty calccheck add + wr1 weighty r 4 mul 3 sub get mul add + 2401 mod dup /wr2 exch def + dup 49 idiv exch 49 mod 2 array astore + lastrow 2 3 -1 roll putinterval + + % wr3 check character + cr7 weightx 0 get mul weightx calccheck add + wr1 weightx r 4 mul 3 sub get mul add + wr2 weightx r 4 mul 2 sub get mul add + 2401 mod + dup 49 idiv exch 49 mod 2 array astore + lastrow 4 3 -1 roll putinterval + + % Place last row check character + ccs ccs length 8 sub 7 getinterval 0 exch {add} forall 49 mod + ccs ccs length 1 sub 3 -1 roll put + + /patterns [ + [ % Even parity + (11521132) (25112131) (14212132) (25121221) (14221222) (12412132) (23321221) + (12421222) (21521221) (15112222) (15121312) (13312222) (24221311) (13321312) + (11512222) (22421311) (11521312) (25112311) (14212312) (23312311) (12412312) + (21512311) (16121131) (14321131) (12521131) (15212131) (15221221) (13412131) + (13421221) (11612131) (16112221) (16121311) (14312221) (14321311) (12512221) + (12521311) (15212311) (13412311) (11612311) (11131135) (31131133) (51131131) + (21122134) (41122132) (21131224) (41131222) (11113135) (31113133) (51113131) + (11122225) (31122223) (51122221) (11131315) (31131313) (51131311) (21113224) + (41113222) (21122314) (41122312) (11113315) (31113313) (51113311) (12131134) + (32131132) (21231133) (41231131) (22122133) (42122131) (11222134) (22131223) + (42131221) (11231224) (31231222) (12113134) (32113132) (12122224) (32122222) + (12131314) (32131312) (21231313) (41231311) (22113223) (42113221) (11213224) + (22122313) (42122311) (11222314) (31222312) (12113314) (32113312) (21213313) + (41213311) (13131133) (33131131) (22231132) (11331133) (31331131) (23122132) + (12222133) (23131222) (12231223) (32231221) (21331222) (13113133) (33113131) + (13122223) (33122221) (11313133) (13131313) (33131311) (11322223) (22231312) + (11331313) (31331311) (23113222) (12213223) (23122312) (12222313) (32222311) + (21322312) (13113313) (33113311) (22213312) (11313313) (31313311) (14131132) + (23231131) (12331132) (21431131) (24122131) (13222132) (24131221) (13231222) + (11422132) (22331221) (11431222) (14113132) (14122222) (12313132) (14131312) + (12322222) (23231311) (12331312) (21431311) (24113221) (13213222) (24122311) + (13222312) (11413222) (22322311) (11422312) (14113312) (23213311) (12313312) + (21413311) (15131131) (13331131) (14222131) (14231221) (12422131) (12431221) + (15113131) (15122221) (13313131) (15131311) (13322221) (11513131) (13331311) + (11522221) (14213221) (14222311) (12413221) (12422311) (15113311) (13313311) + (11513311) (11141134) (31141132) (21132133) (41132131) (21141223) (41141221) + (11123134) (31123132) (11132224) (31132222) (11141314) (31141312) (21114133) + (41114131) (21123223) (41123221) (21132313) (41132311) (11114224) (31114222) + (11123314) (31123312) (21114313) (41114311) (12141133) (32141131) (21241132) + (22132132) (11232133) (22141222) (11241223) (31241221) (12123133) (32123131) + (12132223) (32132221) (12141313) (32141311) (21241312) (22114132) (11214133) + (22123222) (11223223) (22132312) (11232313) (31232311) (12114223) (32114221) + (12123313) (32123311) (21223312) (22114312) (11214313) (31214311) (13141132) + (22241131) (11341132) (23132131) (12232132) (23141221) (12241222) (21341221) + (13123132) (13132222) (11323132) (13141312) (11332222) (22241311) (11341312) + (23114131) (12214132) (23123221) (12223222) (23132311) (12232312) (21332311) + (13114222) (13123312) (11314222) (22223311) (11323312) (23114311) (12214312) + (21314311) (14141131) (12341131) (13232131) (13241221) (11432131) (14123131) + (14132221) (12323131) (14141311) (12332221) (12341311) (13214131) (13223221) + (11414131) (13232311) (11423221) (11432311) (14114221) (14123311) (12314221) + (12323311) (13214311) (11414311) (11151133) (31151131) (21142132) (21151222) + (11133133) (31133131) (11142223) (31142221) (11151313) (31151311) (21124132) + (21133222) (21142312) (11115133) (31115131) (11124223) (31124221) (11133313) + (31133311) (21115222) (21124312) (12151132) (21251131) (22142131) (11242132) + (22151221) (11251222) (12133132) (12142222) (12151312) (21251311) (22124131) + (11224132) (22133221) (11233222) (22142311) (11242312) (12115132) (12124222) + (12133312) (21233311) (22115221) (11215222) (22124311) (11224312) (13151131) + (12242131) (12251221) (13133131) (13142221) (11333131) (13151311) (11342221) + (12224131) (12233221) (12242311) (13115131) (13124221) (11315131) (13133311) + (11324221) (11333311) (12215221) (12224311) (11161132) (21152131) (21161221) + (11143132) (11152222) (11161312) (21134131) (21143221) (21152311) (11125132) + (11134222) (11143312) (21116131) (21125221) (21134311) (12161131) (11252131) + (12143131) (12152221) (12161311) (11234131) (11243221) (11252311) (12125131) + (12134221) (12143311) (11216131) (11225221) (11234311) (11111236) (31111234) + (51111232) (21111325) (41111323) (61111321) (11111416) (31111414) (51111412) + (31211143) (51211141) (12111235) (32111233) (52111231) (21211234) (41211232) + (22111324) (42111322) (11211325) (31211323) (51211321) (12111415) (32111413) + (52111411) (21211414) (41211412) (12211144) (32211142) (21311143) (41311141) + (13111234) (33111232) (22211233) (42211231) (11311234) (31311232) (23111323) + (43111321) (12211324) (32211322) (21311323) (41311321) (13111414) (33111412) + (22211413) (42211411) (11311414) (31311412) (13211143) (33211141) (22311142) + (11411143) (31411141) (14111233) (34111231) (23211232) (12311233) (32311231) + (21411232) (24111322) (13211323) (33211321) (22311322) (11411323) (31411321) + (14111413) (34111411) (23211412) (12311413) (32311411) (21411412) (14211142) + (23311141) (12411142) (21511141) (15111232) (24211231) (13311232) (22411231) + (11511232) (25111321) (14211322) (23311321) (12411322) (21511321) (15111412) + (24211411) (13311412) (22411411) (11511412) (15211141) (13411141) (11611141) + (16111231) (14311231) (12511231) (15211321) (13411321) (11611321) (16111411) + (14311411) (12511411) (21121144) (41121142) (11112145) (31112143) (51112141) + (11121235) (31121233) (51121231) (21112234) (41112232) (21121324) (41121322) + (11112325) (31112323) (51112321) (11121415) (31121413) (51121411) (21112414) + (41112412) (22121143) (42121141) (11221144) (31221142) (12112144) (32112142) + (12121234) (32121232) (21221233) (41221231) (22112233) (42112231) (11212234) + (22121323) (42121321) (11221324) (31221322) (12112324) (32112322) (12121414) + (32121412) (21221413) (41221411) (22112413) (42112411) (11212414) (31212412) + (23121142) (12221143) (32221141) (21321142) (13112143) (33112141) (13121233) + (33121231) (11312143) (22221232) (11321233) (31321231) (23112232) (12212233) + (23121322) (12221323) (32221321) (21321322) (13112323) (33112321) (13121413) + (33121411) (11312323) (22221412) (11321413) (31321411) (23112412) (12212413) + (32212411) (21312412) (24121141) (13221142) (22321141) (11421142) (14112142) + (14121232) (12312142) (23221231) (12321232) (21421231) (24112231) (13212232) + (24121321) (13221322) (11412232) (22321321) (11421322) (14112322) (14121412) + (12312322) (23221411) (12321412) (21421411) (24112411) (13212412) (22312411) + (11412412) (14221141) (12421141) (15112141) (15121231) (13312141) (13321231) + (11512141) (11521231) (14212231) (14221321) (12412231) (12421321) (15112321) + (15121411) (13312321) (13321411) (11512321) (11521411) (14212411) (12412411) + (21131143) (41131141) (11122144) (31122142) (11131234) (31131232) (21113143) + (41113141) (21122233) (41122231) (21131323) (41131321) (11113234) (31113232) + (11122324) (31122322) (11131414) (31131412) (21113323) (41113321) (21122413) + (41122411) (11113414) (31113412) (22131142) (11231143) (31231141) (12122143) + (32122141) (12131233) (32131231) (21231232) (22113142) (11213143) (22122232) + (11222233) (22131322) (11231323) (31231321) (12113233) (32113231) (12122323) + (32122321) (12131413) (32131411) (21231412) (22113322) (11213323) (22122412) + (11222413) (31222411) (12113413) (32113411) (21213412) (23131141) (12231142) + (21331141) (13122142) (13131232) (11322142) (22231231) (11331232) (23113141) + (12213142) (23122231) (12222232) (23131321) (12231322) (21331321) (13113232) + (13122322) (11313232) (13131412) (11322322) (22231411) (11331412) (23113321) + (12213322) (23122411) (12222412) (21322411) (13113412) (22213411) (11313412) + (13231141) (11431141) (14122141) (14131231) (12322141) (12331231) (13213141) + (13222231) (11413141) (13231321) (11422231) (11431321) (14113231) (14122321) + (12313231) (14131411) (12322321) (12331411) (13213321) (13222411) (11413321) + (11422411) (14113411) (12313411) (21141142) (11132143) (31132141) (11141233) + (31141231) (21123142) (21132232) (21141322) (11114143) (31114141) (11123233) + (31123231) (11132323) (31132321) (11141413) (31141411) (21114232) (21123322) + (21132412) (11114323) (31114321) (11123413) (31123411) (22141141) (11241142) + (12132142) (12141232) (21241231) (22123141) (11223142) (22132231) (11232232) + (22141321) (11241322) (12114142) (12123232) (12132322) (12141412) (21241411) + (22114231) (11214232) (22123321) (11223322) (22132411) (11232412) (12114322) + (12123412) (21223411) (12241141) (13132141) (13141231) (11332141) (11341231) + (12223141) (12232231) (12241321) (13114141) (13123231) (11314141) (13132321) + (11323231) (13141411) (11332321) (11341411) (12214231) (12223321) (12232411) + (13114321) (13123411) (11314321) (11323411) (21151141) (11142142) (11151232) + (21133141) (21142231) (21151321) (11124142) (11133232) (11142322) (11151412) + (21115141) (21124231) (21133321) (21142411) (11115232) (11124322) (11133412) + (11251141) (12142141) (12151231) (11233141) (11242231) (11251321) (12124141) + (12133231) (12142321) (12151411) (11215141) (11224231) (11233321) (11242411) + (12115231) (12124321) (12133411) (11152141) (11161231) (11134141) (11143231) + (11152321) (11161411) (11116141) (11125231) (11134321) (11143411) (21111244) + (41111242) (11111335) (31111333) (51111331) (21111424) (41111422) (11111515) + (31111513) (51111511) (21211153) (41211151) (22111243) (42111241) (11211244) + (31211242) (12111334) (32111332) (21211333) (41211331) (22111423) (42111421) + (11211424) (31211422) (12111514) (32111512) (21211513) (41211511) (22211152) + (11311153) (31311151) (23111242) (12211243) (32211241) (21311242) (13111333) + (33111331) (22211332) (11311333) (31311331) (23111422) (12211423) (32211421) + (21311422) (13111513) (33111511) (22211512) (11311513) (31311511) (23211151) + (12311152) (21411151) (24111241) (13211242) (22311241) (11411242) (14111332) + (23211331) (12311332) (21411331) (24111421) (13211422) (22311421) (11411422) + (14111512) (23211511) (12311512) (21411511) (13311151) (11511151) (14211241) + (12411241) (15111331) (13311331) (11511331) (14211421) (12411421) (15111511) + (13311511) (11511511) (31121152) (21112153) (41112151) (21121243) (41121241) + (11112244) (31112242) (11121334) (31121332) (21112333) (41112331) (21121423) + (41121421) (11112424) (31112422) (11121514) (31121512) (21112513) (41112511) + (12121153) (32121151) (21221152) (22112152) (11212153) (22121242) (11221243) + (31221241) (12112243) (32112241) (12121333) (32121331) (21221332) (22112332) + (11212333) (22121422) (11221423) (31221421) (12112423) (32112421) (12121513) + (32121511) (21221512) (22112512) (11212513) (31212511) (13121152) (22221151) + (11321152) (23112151) (12212152) (23121241) (12221242) (21321241) (13112242) + (13121332) (11312242) (22221331) (11321332) (23112331) (12212332) (23121421) + (12221422) (21321421) (13112422) (13121512) (11312422) (22221511) (11321512) + (23112511) (12212512) (21312511) (14121151) (12321151) (13212151) (13221241) + (11412151) (11421241) (14112241) (14121331) (12312241) (12321331) (13212331) + (13221421) (11412331) (11421421) (14112421) (14121511) (12312421) (12321511) + (13212511) (11412511) (11131153) (31131151) (21122152) (21131242) (11113153) + (31113151) (11122243) (31122241) (11131333) (31131331) (21113242) (21122332) + (21131422) (11113333) (31113331) (11122423) (31122421) (11131513) (31131511) + (21113422) (21122512) (12131152) (21231151) (22122151) (11222152) (22131241) + (11231242) (12113152) (12122242) (12131332) (21231331) (22113241) (11213242) + (22122331) (11222332) (22131421) (11231422) (12113332) (12122422) (12131512) + (21231511) (22113421) (11213422) (22122511) (11222512) (13131151) (11331151) + (12222151) (12231241) (13113151) (13122241) (11313151) (13131331) (11322241) + (11331331) (12213241) (12222331) (12231421) (13113331) (13122421) (11313331) + (13131511) (11322421) (11331511) (12213421) (12222511) (11141152) (21132151) + (21141241) (11123152) (11132242) (11141332) (21114151) (21123241) (21132331) + (21141421) (11114242) (11123332) (11132422) (11141512) (21114331) (21123421) + (21132511) (12141151) (11232151) (11241241) (12123151) (12132241) (12141331) + (11214151) (11223241) (11232331) (11241421) (12114241) (12123331) (12132421) + (12141511) (11214331) (11223421) (11232511) (11151151) (11133151) (11142241) + (11151331) (11115151) (11124241) (11133331) (11142421) (11151511) (11111254) + (31111252) (21111343) (41111341) (11111434) (31111432) (21111523) (41111521) + (11111614) (31111612) (31211161) (12111253) (32111251) (21211252) (22111342) + (11211343) (31211341) (12111433) (32111431) (21211432) (22111522) (11211523) + (31211521) (12111613) (32111611) (21211612) (12211162) (21311161) (13111252) + (22211251) (11311252) (23111341) (12211342) (21311341) (13111432) (22211431) + (11311432) (23111521) (12211522) (21311521) (13111612) (22211611) (11311612) + (13211161) (11411161) (14111251) (12311251) (13211341) (11411341) (14111431) + (12311431) (13211521) (11411521) (14111611) (12311611) (21121162) (11112163) + (31112161) (11121253) (31121251) (21112252) (21121342) (11112343) (31112341) + (11121433) (31121431) (21112432) (21121522) (11112523) (31112521) (11121613) + (31121611) (22121161) (11221162) (12112162) (12121252) (21221251) (22112251) + (11212252) (22121341) (11221342) (12112342) (12121432) (21221431) (22112431) + (11212432) (22121521) (11221522) (12112522) (12121612) (21221611) (12221161) + (13112161) (13121251) (11312161) (11321251) (32121115) (52121113) (21221116) + (41221114) (61221112) (22112116) (42112114) (31212115) (51212113) (13121116) + (33121114) (22221115) (42221113) (11321116) (31321114) (51321112) (23112115) + (43112113) (12212116) (32212114) (52212112) (21312115) (41312113) (61312111) + (14121115) (34121113) (23221114) (43221112) (12321115) (32321113) (52321111) + (21421114) (41421112) (24112114) (13212115) (33212113) (22312114) (42312112) + (11412115) (31412113) (51412111) (15121114) (24221113) (13321114) (33321112) + (22421113) (42421111) (11521114) (31521112) (25112113) (14212114) (34212112) + (23312113) (43312111) (12412114) (32412112) (21512113) (41512111) (16121113) + (25221112) (14321113) (34321111) (23421112) (12521113) (32521111) (15212113) + (24312112) (13412113) (33412111) (22512112) (11612113) (31612111) (31131115) + (51131113) (21122116) (41122114) (61122112) (31113115) (51113113) (12131116) + (32131114) (52131112) (21231115) (41231113) (61231111) (22122115) (42122113) + (11222116) (31222114) (51222112) (12113116) (32113114) (52113112) (21213115) + (41213113) (61213111) (13131115) (33131113) (22231114) (42231112) (11331115) + (31331113) (51331111) (23122114) (43122112) (12222115) (32222113) (52222111) + (21322114) (41322112) (13113115) (33113113) (22213114) (42213112) (11313115) + (31313113) (51313111) (14131114) (34131112) (23231113) (43231111) (12331114) + (32331112) (21431113) (41431111) (24122113) (13222114) (33222112) (22322113) + (42322111) (11422114) (31422112) (14113114) (34113112) (23213113) (43213111) + (12313114) (32313112) (21413113) (41413111) (15131113) (24231112) (13331113) + (33331111) (22431112) (25122112) (14222113) (34222111) (23322112) (12422113) + (32422111) (21522112) (15113113) (24213112) (13313113) (33313111) (22413112) + (11513113) (31513111) (16131112) (25231111) (14331112) (23431111) (15222112) + (24322111) (13422112) (22522111) (16113112) (25213111) (14313112) (23413111) + (12513112) (21613111) (11141116) (31141114) (51141112) (21132115) (41132113) + (61132111) (11123116) (31123114) (51123112) (21114115) (41114113) (61114111) + (12141115) (32141113) (52141111) (21241114) (41241112) (22132114) (42132112) + (11232115) (31232113) (51232111) (12123115) (32123113) (52123111) (21223114) + (41223112) (22114114) (42114112) (11214115) (31214113) (51214111) (13141114) + (33141112) (22241113) (42241111) (11341114) (31341112) (23132113) (43132111) + (12232114) (32232112) (21332113) (41332111) (13123114) (33123112) (22223113) + (42223111) (11323114) (31323112) (23114113) (43114111) (12214114) (32214112) + (21314113) (41314111) (14141113) (34141111) (23241112) (12341113) (32341111) + (24132112) (13232113) (33232111) (22332112) (11432113) (31432111) (14123113) + (34123111) (23223112) (12323113) (32323111) (21423112) (24114112) (13214113) + (33214111) (22314112) (11414113) (31414111) (15141112) (24241111) (13341112) + (25132111) (14232112) (23332111) (12432112) (15123112) (24223111) (13323112) + (22423111) (11523112) (25114111) (14214112) (23314111) (12414112) (21514111) + (16141111) (14341111) (15232111) (13432111) (16123111) (14323111) (12523111) + (15214111) (13414111) (11614111) (11151115) (31151113) (51151111) (21142114) + (41142112) (11133115) (31133113) (51133111) (21124114) (41124112) (11115115) + (31115113) (51115111) (12151114) (32151112) (21251113) (41251111) (22142113) + (42142111) (11242114) (31242112) (12133114) (32133112) (21233113) (41233111) + (22124113) (42124111) (11224114) (31224112) (12115114) (32115112) (21215113) + (41215111) (13151113) (33151111) (22251112) (23142112) (12242113) (32242111) + (21342112) (13133113) (33133111) (22233112) (11333113) (31333111) (23124112) + (12224113) (32224111) (21324112) (13115113) (33115111) (22215112) (11315113) + (31315111) (14151112) (23251111) (24142111) (13242112) (22342111) (14133112) + (23233111) (12333112) (21433111) (24124111) (13224112) (22324111) (11424112) + (14115112) (23215111) (12315112) (21415111) (15151111) (14242111) (15133111) + (13333111) (14224111) (12424111) (15115111) (13315111) (11515111) (11161114) + (31161112) (21152113) (41152111) (11143114) (31143112) (21134113) (41134111) + (11125114) (31125112) (21116113) (41116111) (12161113) (32161111) (22152112) + (11252113) (31252111) (12143113) (32143111) (21243112) (22134112) (11234113) + (31234111) (12125113) (32125111) (21225112) (22116112) (11216113) (31216111) + (13161112) (23152111) (12252112) (13143112) (22243111) (11343112) (23134111) + (12234112) (21334111) (13125112) (22225111) (11325112) (23116111) (12216112) + (21316111) (14161111) (13252111) (14143111) (12343111) (13234111) (11434111) + (14125111) (12325111) (13216111) (11416111) (31111216) (51111214) (31211125) + (51211123) (32111215) (52111213) (21211216) (41211214) (61211212) (12211126) + (32211124) (52211122) (21311125) (41311123) (61311121) (13111216) (33111214) + (22211215) (42211213) (11311216) (31311214) (51311212) (13211125) (33211123) + (22311124) (42311122) (11411125) (31411123) (51411121) (14111215) (34111213) + (23211214) (43211212) (12311215) (32311213) (52311211) (21411214) (41411212) + (14211124) (34211122) (23311123) (43311121) (12411124) (32411122) (21511123) + (41511121) (15111214) (24211213) (13311214) (33311212) (22411213) (42411211) + (11511214) (31511212) (15211123) (24311122) (13411123) (33411121) (22511122) + (11611123) (31611121) (16111213) (25211212) (14311213) (34311211) (23411212) + (12511213) (32511211) (21611212) (21121126) (41121124) (61121122) (31112125) + (51112123) (31121215) (51121213) (21112216) (41112214) (61112212) (22121125) + (42121123) (11221126) (31221124) (51221122) (12112126) (32112124) (52112122) + (12121216) (32121214) (52121212) (21221215) (41221213) (61221211) (22112215) + (42112213) (11212216) (31212214) (51212212) (23121124) (43121122) (12221125) + (32221123) (52221121) (21321124) (41321122) (13112125) (33112123) (13121215) + (33121213) (11312125) (22221214) (42221212) (11321215) (31321213) (51321211) + (23112214) (43112212) (12212215) (32212213) (52212211) (21312214) (41312212) + (24121123) (13221124) (33221122) (22321123) (42321121) (11421124) (31421122) + (14112124) (34112122) (14121214) (34121212) (12312124) (23221213) (43221211) + (12321214) (32321212) (21421213) (41421211) (24112213) (13212214) (33212212) + (22312213) (42312211) (11412214) (31412212) (25121122) (14221123) (34221121) + (23321122) (12421123) (32421121) (21521122) (15112123) (15121213) (13312123) + (24221212) (13321213) (33321211) (11512123) (22421212) (11521213) (31521211) + (25112212) (14212213) (34212211) (23312212) (12412213) (32412211) (21512212) + (15221122) (24321121) (13421122) (22521121) (16112122) (16121212) (14312122) + (25221211) (14321212) (12512122) (23421211) (12521212) (15212212) (24312211) + (13412212) (22512211) (11612212) (21131125) (41131123) (61131121) (11122126) + (31122124) (51122122) (11131216) (31131214) (51131212) (21113125) (41113123) + (61113121) (21122215) (41122213) (61122211) (11113216) (31113214) (51113212) + (22131124) (42131122) (11231125) (31231123) (51231121) (12122125) (32122123) + (52122121) (12131215) (32131213) (52131211) (21231214) (41231212) (22113124) + (42113122) (11213125) (22122214) (42122212) (11222215) (31222213) (51222211) + (12113215) (32113213) (52113211) (21213214) (41213212) (23131123) (43131121) + (12231124) (32231122) (21331123) (41331121) (13122124) (33122122) (13131214) + (33131212) (11322124) (22231213) (42231211) (11331214) (31331212) (23113123) + (43113121) (12213124) (23122213) (43122211) (12222214) (32222212) (21322213) + (41322211) (13113214) (33113212) (22213213) (42213211) (11313214) (31313212) + (24131122) (13231123) (33231121) (22331122) (11431123) (31431121) (14122123) + (34122121) (14131213) (34131211) (12322123) (23231212) (12331213) (32331211) + (21431212) (24113122) (13213123) (24122212) (13222213) (33222211) (11413123) + (22322212) (11422213) (31422211) (14113213) (34113211) (23213212) (12313213) + (32313211) (21413212) (25131121) (14231122) (23331121) (12431122) (15122122) + (15131212) (13322122) (24231211) (13331212) (11522122) (22431211) (25113121) + (14213122) (25122211) (14222212) (12413122) (23322211) (12422212) (21522211) + (15113212) (24213211) (13313212) (22413211) (11513212) (15231121) (13431121) + (16122121) (16131211) (14322121) (14331211) (12522121) (15213121) (15222211) + (13413121) (13422211) (11613121) (16113211) (14313211) (12513211) (21141124) + (41141122) (11132125) (31132123) (51132121) (11141215) (31141213) (51141211) + (21123124) (41123122) (21132214) (41132212) (11114125) (31114123) (51114121) + (11123215) (31123213) (51123211) (21114214) (41114212) (22141123) (42141121) + (11241124) (31241122) (12132124) (32132122) (12141214) (32141212) (21241213) + (41241211) (22123123) (42123121) (11223124) (22132213) (42132211) (11232214) + (31232212) (12114124) (32114122) (12123214) (32123212) (21223213) (41223211) + (22114213) (42114211) (11214214) (31214212) (23141122) (12241123) (32241121) + (21341122) (13132123) (33132121) (13141213) (33141211) (11332123) (22241212) + (11341213) (31341211) (23123122) (12223123) (23132212) (12232213) (32232211) + (21332212) (13114123) (33114121) (13123213) (33123211) (11314123) (22223212) + (11323213) (31323211) (23114212) (12214213) (32214211) (21314212) (24141121) + (13241122) (22341121) (14132122) (14141212) (12332122) (23241211) (12341212) + (24123121) (13223122) (24132211) (13232212) (11423122) (22332211) (11432212) + (14114122) (14123212) (12314122) (23223211) (12323212) (21423211) (24114211) + (13214212) (22314211) (11414212) (14241121) (15132121) (15141211) (13332121) + (13341211) (14223121) (14232211) (12423121) (12432211) (15114121) (15123211) + (13314121) (13323211) (11514121) (11523211) (14214211) (12414211) (21151123) + (41151121) (11142124) (31142122) (11151214) (31151212) (21133123) (41133121) + (21142213) (41142211) (11124124) (31124122) (11133214) (31133212) (21115123) + (41115121) (21124213) (41124211) (11115214) (31115212) (22151122) (11251123) + (31251121) (12142123) (32142121) (12151213) (32151211) (21251212) (22133122) + (11233123) (22142212) (11242213) (31242211) (12124123) (32124121) (12133213) + (32133211) (21233212) (22115122) (11215123) (22124212) (11224213) (31224211) + (12115213) (32115211) (21215212) (23151121) (12251122) (13142122) (13151212) + (11342122) (22251211) (23133121) (12233122) (23142211) (12242212) (21342211) + (13124122) (13133212) (11324122) (22233211) (11333212) (23115121) (12215122) + (23124211) (12224212) (21324211) (13115212) (22215211) (11315212) (13251121) + (14142121) (14151211) (12342121) (13233121) (13242211) (11433121) (14124121) + (14133211) (12324121) (12333211) (13215121) (13224211) (11415121) (11424211) + (14115211) (12315211) (21161122) (11152123) (31152121) (11161213) (31161211) + (21143122) (21152212) (11134123) (31134121) (11143213) (31143211) (21125122) + (21134212) (11116123) (31116121) (11125213) (31125211) (22161121) (12152122) + (12161212) (22143121) (11243122) (22152211) (11252212) (12134122) (12143212) + (21243211) (22125121) (11225122) (22134211) (11234212) (12116122) (12125212) + (21225211) (13152121) (13161211) (12243121) (12252211) (13134121) (13143211) + (11334121) (11343211) (12225121) (12234211) (13116121) (13125211) (11316121) + (11325211) (21111226) (41111224) (61111222) (31111315) (51111313) (21211135) + (41211133) (61211131) (22111225) (42111223) (11211226) (31211224) (51211222) + (12111316) (32111314) (52111312) (21211315) (41211313) (61211311) (22211134) + (42211132) (11311135) (31311133) (51311131) (23111224) (43111222) (12211225) + (32211223) (52211221) (21311224) (41311222) (13111315) (33111313) (22211314) + (42211312) (11311315) (31311313) (51311311) (23211133) (43211131) (12311134) + (32311132) (21411133) (41411131) (24111223) (13211224) (33211222) (22311223) + (42311221) (11411224) (31411222) (14111314) (34111312) (23211313) (43211311) + (12311314) (32311312) (21411313) (41411311) (24211132) (13311133) (33311131) + (22411132) (11511133) (31511131) (25111222) (14211223) (34211221) (23311222) + (12411223) (32411221) (21511222) (15111313) (24211312) (13311313) (33311311) + (22411312) (11511313) (31511311) (25211131) (14311132) (23411131) (12511132) + (21611131) (15211222) (24311221) (13411222) (22511221) (11611222) (16111312) + (25211311) (14311312) (23411311) (12511312) (21611311) (31121134) (51121132) + (21112135) (41112133) (61112131) (21121225) (41121223) (61121221) (11112226) + (31112224) (51112222) (11121316) (31121314) (51121312) (21112315) (41112313) + (61112311) (12121135) (32121133) (52121131) (21221134) (41221132) (22112134) + (42112132) (11212135) (22121224) (42121222) (11221225) (31221223) (51221221) + (12112225) (32112223) (52112221) (12121315) (32121313) (52121311) (21221314) + (41221312) (22112314) (42112312) (11212315) (31212313) (51212311) (13121134) + (33121132) (22221133) (42221131) (11321134) (31321132) (23112133) (43112131) + (12212134) (23121223) (43121221) (12221224) (32221222) (21321223) (41321221) + (13112224) (33112222) (13121314) (33121312) (11312224) (22221313) (42221311) + (11321314) (31321312) (23112313) (43112311) (12212314) (32212312) (21312313) + (41312311) (14121133) (34121131) (23221132) (12321133) (32321131) (21421132) + (24112132) (13212133) (24121222) (13221223) (33221221) (11412133) (22321222) + (11421223) (31421221) (14112223) (34112221) (14121313) (34121311) (12312223) + (23221312) (12321313) (32321311) (21421312) (24112312) (13212313) (33212311) + (22312312) (11412313) (31412311) (15121132) (24221131) (13321132) (22421131) + ] [ % Odd parity + (22121116) (42121114) (31221115) (51221113) (32112115) (52112113) (21212116) + (41212114) (61212112) (23121115) (43121113) (12221116) (32221114) (52221112) + (21321115) (41321113) (61321111) (13112116) (33112114) (22212115) (42212113) + (11312116) (31312114) (51312112) (24121114) (13221115) (33221113) (22321114) + (42321112) (11421115) (31421113) (51421111) (14112115) (34112113) (23212114) + (43212112) (12312115) (32312113) (52312111) (21412114) (41412112) (25121113) + (14221114) (34221112) (23321113) (43321111) (12421114) (32421112) (21521113) + (41521111) (15112114) (24212113) (13312114) (33312112) (22412113) (42412111) + (11512114) (31512112) (15221113) (24321112) (13421113) (33421111) (22521112) + (16112113) (25212112) (14312113) (34312111) (23412112) (12512113) (32512111) + (21612112) (21131116) (41131114) (61131112) (31122115) (51122113) (21113116) + (41113114) (61113112) (22131115) (42131113) (11231116) (31231114) (51231112) + (12122116) (32122114) (52122112) (21222115) (41222113) (61222111) (22113115) + (42113113) (11213116) (31213114) (51213112) (23131114) (43131112) (12231115) + (32231113) (52231111) (21331114) (41331112) (13122115) (33122113) (22222114) + (42222112) (11322115) (31322113) (51322111) (23113114) (43113112) (12213115) + (32213113) (52213111) (21313114) (41313112) (24131113) (13231114) (33231112) + (22331113) (42331111) (11431114) (31431112) (14122114) (34122112) (23222113) + (43222111) (12322114) (32322112) (21422113) (41422111) (24113113) (13213114) + (33213112) (22313113) (42313111) (11413114) (31413112) (25131112) (14231113) + (34231111) (23331112) (12431113) (32431111) (15122113) (24222112) (13322113) + (33322111) (22422112) (11522113) (31522111) (25113112) (14213113) (34213111) + (23313112) (12413113) (32413111) (21513112) (15231112) (24331111) (13431112) + (16122112) (25222111) (14322112) (23422111) (12522112) (15213112) (24313111) + (13413112) (22513111) (11613112) (21141115) (41141113) (61141111) (11132116) + (31132114) (51132112) (21123115) (41123113) (61123111) (11114116) (31114114) + (51114112) (22141114) (42141112) (11241115) (31241113) (51241111) (12132115) + (32132113) (52132111) (21232114) (41232112) (22123114) (42123112) (11223115) + (31223113) (51223111) (12114115) (32114113) (52114111) (21214114) (41214112) + (23141113) (43141111) (12241114) (32241112) (21341113) (41341111) (13132114) + (33132112) (22232113) (42232111) (11332114) (31332112) (23123113) (43123111) + (12223114) (32223112) (21323113) (41323111) (13114114) (33114112) (22214113) + (42214111) (11314114) (31314112) (24141112) (13241113) (33241111) (22341112) + (14132113) (34132111) (23232112) (12332113) (32332111) (21432112) (24123112) + (13223113) (33223111) (22323112) (11423113) (31423111) (14114113) (34114111) + (23214112) (12314113) (32314111) (21414112) (25141111) (14241112) (23341111) + (15132112) (24232111) (13332112) (22432111) (25123111) (14223112) (23323111) + (12423112) (21523111) (15114112) (24214111) (13314112) (22414111) (11514112) + (15241111) (16132111) (14332111) (15223111) (13423111) (16114111) (14314111) + (12514111) (21151114) (41151112) (11142115) (31142113) (51142111) (21133114) + (41133112) (11124115) (31124113) (51124111) (21115114) (41115112) (22151113) + (42151111) (11251114) (31251112) (12142114) (32142112) (21242113) (41242111) + (22133113) (42133111) (11233114) (31233112) (12124114) (32124112) (21224113) + (41224111) (22115113) (42115111) (11215114) (31215112) (23151112) (12251113) + (32251111) (13142113) (33142111) (22242112) (11342113) (31342111) (23133112) + (12233113) (32233111) (21333112) (13124113) (33124111) (22224112) (11324113) + (31324111) (23115112) (12215113) (32215111) (21315112) (24151111) (13251112) + (14142112) (23242111) (12342112) (24133111) (13233112) (22333111) (11433112) + (14124112) (23224111) (12324112) (21424111) (24115111) (13215112) (22315111) + (11415112) (14251111) (15142111) (13342111) (14233111) (12433111) (15124111) + (13324111) (11524111) (14215111) (12415111) (21161113) (41161111) (11152114) + (31152112) (21143113) (41143111) (11134114) (31134112) (21125113) (41125111) + (11116114) (31116112) (22161112) (12152113) (32152111) (21252112) (22143112) + (11243113) (31243111) (12134113) (32134111) (21234112) (22125112) (11225113) + (31225111) (12116113) (32116111) (21216112) (23161111) (13152112) (22252111) + (23143111) (12243112) (21343111) (13134112) (22234111) (11334112) (23125111) + (12225112) (21325111) (13116112) (22216111) (11316112) (14152111) (13243111) + (14134111) (12334111) (13225111) (11425111) (14116111) (12316111) (41111215) + (61111213) (21211126) (41211124) (61211122) (22111216) (42111214) (31211215) + (51211213) (22211125) (42211123) (11311126) (31311124) (51311122) (23111215) + (43111213) (12211216) (32211214) (52211212) (21311215) (41311213) (61311211) + (23211124) (43211122) (12311125) (32311123) (52311121) (21411124) (41411122) + (24111214) (13211215) (33211213) (22311214) (42311212) (11411215) (31411213) + (51411211) (24211123) (13311124) (33311122) (22411123) (42411121) (11511124) + (31511122) (25111213) (14211214) (34211212) (23311213) (43311211) (12411214) + (32411212) (21511213) (41511211) (25211122) (14311123) (34311121) (23411122) + (12511123) (32511121) (21611122) (15211213) (24311212) (13411213) (33411211) + (22511212) (11611213) (31611211) (31121125) (51121123) (21112126) (41112124) + (61112122) (21121216) (41121214) (61121212) (31112215) (51112213) (12121126) + (32121124) (52121122) (21221125) (41221123) (61221121) (22112125) (42112123) + (11212126) (22121215) (42121213) (11221216) (31221214) (51221212) (12112216) + (32112214) (52112212) (21212215) (41212213) (61212211) (13121125) (33121123) + (22221124) (42221122) (11321125) (31321123) (51321121) (23112124) (43112122) + (12212125) (23121214) (43121212) (12221215) (32221213) (52221211) (21321214) + (41321212) (13112215) (33112213) (22212214) (42212212) (11312215) (31312213) + (51312211) (14121124) (34121122) (23221123) (43221121) (12321124) (32321122) + (21421123) (41421121) (24112123) (13212124) (24121213) (13221214) (33221212) + (11412124) (22321213) (42321211) (11421214) (31421212) (14112214) (34112212) + (23212213) (43212211) (12312214) (32312212) (21412213) (41412211) (15121123) + (24221122) (13321123) (33321121) (22421122) (11521123) (31521121) (25112122) + (14212123) (25121212) (14221213) (34221211) (12412123) (23321212) (12421213) + (32421211) (21521212) (15112213) (24212212) (13312213) (33312211) (22412212) + (11512213) (31512211) (16121122) (25221121) (14321122) (23421121) (12521122) + (15212122) (15221212) (13412122) (24321211) (13421212) (11612122) (22521211) + (16112212) (25212211) (14312212) (23412211) (12512212) (21612211) (11131126) + (31131124) (51131122) (21122125) (41122123) (61122121) (21131215) (41131213) + (61131211) (11113126) (31113124) (51113122) (11122216) (31122214) (51122212) + (21113215) (41113213) (61113211) (12131125) (32131123) (52131121) (21231124) + (41231122) (22122124) (42122122) (11222125) (22131214) (42131212) (11231215) + (31231213) (51231211) (12113125) (32113123) (52113121) (12122215) (32122213) + (52122211) (21222214) (41222212) (22113214) (42113212) (11213215) (31213213) + (51213211) (13131124) (33131122) (22231123) (42231121) (11331124) (31331122) + (23122123) (43122121) (12222124) (23131213) (43131211) (12231214) (32231212) + (21331213) (41331211) (13113124) (33113122) (13122214) (33122212) (11313124) + (22222213) (42222211) (11322214) (31322212) (23113213) (43113211) (12213214) + (32213212) (21313213) (41313211) (14131123) (34131121) (23231122) (12331123) + (32331121) (21431122) (24122122) (13222123) (24131212) (13231213) (33231211) + (11422123) (22331212) (11431213) (31431211) (14113123) (34113121) (14122213) + (34122211) (12313123) (23222212) (12322213) (32322211) (21422212) (24113212) + (13213213) (33213211) (22313212) (11413213) (31413211) (15131122) (24231121) + (13331122) (22431121) (25122121) (14222122) (25131211) (14231212) (12422122) + (23331211) (12431212) (15113122) (15122212) (13313122) (24222211) (13322212) + (11513122) (22422211) (11522212) (25113211) (14213212) (23313211) (12413212) + (21513211) (16131121) (14331121) (15222121) (15231211) (13422121) (13431211) + (16113121) (16122211) (14313121) (14322211) (12513121) (12522211) (15213211) + (13413211) (11613211) (11141125) (31141123) (51141121) (21132124) (41132122) + (21141214) (41141212) (11123125) (31123123) (51123121) (11132215) (31132213) + (51132211) (21114124) (41114122) (21123214) (41123212) (11114215) (31114213) + (51114211) (12141124) (32141122) (21241123) (41241121) (22132123) (42132121) + (11232124) (22141213) (42141211) (11241214) (31241212) (12123124) (32123122) + (12132214) (32132212) (21232213) (41232211) (22114123) (42114121) (11214124) + (22123213) (42123211) (11223214) (31223212) (12114214) (32114212) (21214213) + (41214211) (13141123) (33141121) (22241122) (11341123) (31341121) (23132122) + (12232123) (23141212) (12241213) (32241211) (21341212) (13123123) (33123121) + (13132213) (33132211) (11323123) (22232212) (11332213) (31332211) (23114122) + (12214123) (23123212) (12223213) (32223211) (21323212) (13114213) (33114211) + (22214212) (11314213) (31314211) (14141122) (23241121) (12341122) (24132121) + (13232122) (24141211) (13241212) (11432122) (22341211) (14123122) (14132212) + (12323122) (23232211) (12332212) (21432211) (24114121) (13214122) (24123211) + (13223212) (11414122) (22323211) (11423212) (14114212) (23214211) (12314212) + (21414211) (15141121) (13341121) (14232121) (14241211) (12432121) (15123121) + (15132211) (13323121) (13332211) (11523121) (14214121) (14223211) (12414121) + (12423211) (15114211) (13314211) (11514211) (11151124) (31151122) (21142123) + (41142121) (21151213) (41151211) (11133124) (31133122) (11142214) (31142212) + (21124123) (41124121) (21133213) (41133211) (11115124) (31115122) (11124214) + (31124212) (21115213) (41115211) (12151123) (32151121) (21251122) (22142122) + (11242123) (22151212) (11251213) (31251211) (12133123) (32133121) (12142213) + (32142211) (21242212) (22124122) (11224123) (22133212) (11233213) (31233211) + (12115123) (32115121) (12124213) (32124211) (21224212) (22115212) (11215213) + (31215211) (13151122) (22251121) (23142121) (12242122) (23151211) (12251212) + (13133122) (13142212) (11333122) (22242211) (11342212) (23124121) (12224122) + (23133211) (12233212) (21333211) (13115122) (13124212) (11315122) (22224211) + (11324212) (23115211) (12215212) (21315211) (14151121) (13242121) (13251211) + (14133121) (14142211) (12333121) (12342211) (13224121) (13233211) (11424121) + (11433211) (14115121) (14124211) (12315121) (12324211) (13215211) (11415211) + (11161123) (31161121) (21152122) (21161212) (11143123) (31143121) (11152213) + (31152211) (21134122) (21143212) (11125123) (31125121) (11134213) (31134211) + (21116122) (21125212) (12161122) (22152121) (11252122) (22161211) (12143122) + (12152212) (21252211) (22134121) (11234122) (22143211) (11243212) (12125122) + (12134212) (21234211) (22116121) (11216122) (22125211) (11225212) (13161121) + (12252121) (13143121) (13152211) (11343121) (12234121) (12243211) (13125121) + (13134211) (11325121) (11334211) (12216121) (12225211) (31111225) (51111223) + (21111316) (41111314) (61111312) (31211134) (51211132) (12111226) (32111224) + (52111222) (21211225) (41211223) (61211221) (22111315) (42111313) (11211316) + (31211314) (51211312) (12211135) (32211133) (52211131) (21311134) (41311132) + (13111225) (33111223) (22211224) (42211222) (11311225) (31311223) (51311221) + (23111314) (43111312) (12211315) (32211313) (52211311) (21311314) (41311312) + (13211134) (33211132) (22311133) (42311131) (11411134) (31411132) (14111224) + (34111222) (23211223) (43211221) (12311224) (32311222) (21411223) (41411221) + (24111313) (13211314) (33211312) (22311313) (42311311) (11411314) (31411312) + (14211133) (34211131) (23311132) (12411133) (32411131) (21511132) (15111223) + (24211222) (13311223) (33311221) (22411222) (11511223) (31511221) (25111312) + (14211313) (34211311) (23311312) (12411313) (32411311) (21511312) (15211132) + (24311131) (13411132) (22511131) (11611132) (16111222) (25211221) (14311222) + (23411221) (12511222) (21611221) (15211312) (24311311) (13411312) (22511311) + (11611312) (21121135) (41121133) (61121131) (11112136) (31112134) (51112132) + (11121226) (31121224) (51121222) (21112225) (41112223) (61112221) (21121315) + (41121313) (61121311) (11112316) (31112314) (51112312) (22121134) (42121132) + (11221135) (31221133) (51221131) (12112135) (32112133) (52112131) (12121225) + (32121223) (52121221) (21221224) (41221222) (22112224) (42112222) (11212225) + (22121314) (42121312) (11221315) (31221313) (51221311) (12112315) (32112313) + (52112311) (21212314) (41212312) (23121133) (43121131) (12221134) (32221132) + (21321133) (41321131) (13112134) (33112132) (13121224) (33121222) (11312134) + (22221223) (42221221) (11321224) (31321222) (23112223) (43112221) (12212224) + (23121313) (43121311) (12221314) (32221312) (21321313) (41321311) (13112314) + (33112312) (22212313) (42212311) (11312314) (31312312) (24121132) (13221133) + (33221131) (22321132) (11421133) (31421131) (14112133) (34112131) (14121223) + (34121221) (12312133) (23221222) (12321223) (32321221) (21421222) (24112222) + (13212223) (24121312) (13221313) (33221311) (11412223) (22321312) (11421313) + (31421311) (14112313) (34112311) (23212312) (12312313) (32312311) (21412312) + (25121131) (14221132) (23321131) (12421132) (21521131) (15112132) (15121222) + (13312132) (24221221) (13321222) (11512132) (22421221) (11521222) (25112221) + (14212222) (25121311) (14221312) (12412222) (23321311) (12421312) (21521311) + (15112312) (24212311) (13312312) (22412311) (11512312) (15221131) (13421131) + (16112131) (16121221) (14312131) (14321221) (12512131) (12521221) (15212221) + (15221311) (13412221) (13421311) (11612221) (16112311) (14312311) (12512311) + (21131134) (41131132) (11122135) (31122133) (51122131) (11131225) (31131223) + (51131221) (21113134) (41113132) (21122224) (41122222) (21131314) (41131312) + (11113225) (31113223) (51113221) (11122315) (31122313) (51122311) (21113314) + (41113312) (22131133) (42131131) (11231134) (31231132) (12122134) (32122132) + (12131224) (32131222) (21231223) (41231221) (22113133) (42113131) (11213134) + (22122223) (42122221) (11222224) (22131313) (42131311) (11231314) (31231312) + (12113224) (32113222) (12122314) (32122312) (21222313) (41222311) (22113313) + (42113311) (11213314) (31213312) (23131132) (12231133) (32231131) (21331132) + (13122133) (33122131) (13131223) (33131221) (11322133) (22231222) (11331223) + (31331221) (23113132) (12213133) (23122222) (12222223) (23131312) (12231313) + (32231311) (21331312) (13113223) (33113221) (13122313) (33122311) (11313223) + (22222312) (11322313) (31322311) (23113312) (12213313) (32213311) (21313312) + (24131131) (13231132) (22331131) (11431132) (14122132) (14131222) (12322132) + (23231221) (12331222) (21431221) (24113131) (13213132) (24122221) (13222222) + (24131311) (11413132) (13231312) (11422222) (22331311) (11431312) (14113222) + (14122312) (12313222) (23222311) (12322312) (21422311) (24113311) (13213312) + (22313311) (11413312) (14231131) (12431131) (15122131) (15131221) (13322131) + (13331221) (11522131) (14213131) (14222221) (12413131) (14231311) (12422221) + (12431311) (15113221) (15122311) (13313221) (13322311) (11513221) (11522311) + (14213311) (12413311) (21141133) (41141131) (11132134) (31132132) (11141224) + (31141222) (21123133) (41123131) (21132223) (41132221) (21141313) (41141311) + (11114134) (31114132) (11123224) (31123222) (11132314) (31132312) (21114223) + (41114221) (21123313) (41123311) (11114314) (31114312) (22141132) (11241133) + (31241131) (12132133) (32132131) (12141223) (32141221) (21241222) (22123132) + (11223133) (22132222) (11232223) (22141312) (11241313) (31241311) (12114133) + (32114131) (12123223) (32123221) (12132313) (32132311) (21232312) (22114222) + (11214223) (22123312) (11223313) (31223311) (12114313) (32114311) (21214312) + (23141131) (12241132) (21341131) (13132132) (13141222) (11332132) (22241221) + (11341222) (23123131) (12223132) (23132221) (12232222) (23141311) (12241312) + (21341311) (13114132) (13123222) (11314132) (13132312) (11323222) (22232311) + (11332312) (23114221) (12214222) (23123311) (12223312) (21323311) (13114312) + (22214311) (11314312) (13241131) (14132131) (14141221) (12332131) (12341221) + (13223131) (13232221) (11423131) (13241311) (11432221) (14114131) (14123221) + (12314131) (14132311) (12323221) (12332311) (13214221) (13223311) (11414221) + (11423311) (14114311) (12314311) (21151132) (11142133) (31142131) (11151223) + (31151221) (21133132) (21142222) (21151312) (11124133) (31124131) (11133223) + (31133221) (11142313) (31142311) (21115132) (21124222) (21133312) (11115223) + (31115221) (11124313) (31124311) (22151131) (11251132) (12142132) (12151222) + (21251221) (22133131) (11233132) (22142221) (11242222) (22151311) (11251312) + (12124132) (12133222) (12142312) (21242311) (22115131) (11215132) (22124221) + (11224222) (22133311) (11233312) (12115222) (12124312) (21224311) (12251131) + (13142131) (13151221) (11342131) (12233131) (12242221) (12251311) (13124131) + (13133221) (11324131) (13142311) (11333221) (11342311) (12215131) (12224221) + (12233311) (13115221) (13124311) (11315221) (11324311) (21161131) (11152132) + (11161222) (21143131) (21152221) (21161311) (11134132) (11143222) (11152312) + (21125131) (21134221) (21143311) (11116132) (11125222) (11134312) (12152131) + (12161221) (11243131) (11252221) (12134131) (12143221) (12152311) (11225131) + (11234221) (11243311) (12116131) (12125221) (12134311) (21111235) (41111233) + (61111231) (11111326) (31111324) (51111322) (21111415) (41111413) (61111411) + (21211144) (41211142) (22111234) (42111232) (11211235) (31211233) (51211231) + (12111325) (32111323) (52111321) (21211324) (41211322) (22111414) (42111412) + (11211415) (31211413) (51211411) (22211143) (42211141) (11311144) (31311142) + (23111233) (43111231) (12211234) (32211232) (21311233) (41311231) (13111324) + (33111322) (22211323) (42211321) (11311324) (31311322) (23111413) (43111411) + (12211414) (32211412) (21311413) (41311411) (23211142) (12311143) (32311141) + (21411142) (24111232) (13211233) (33211231) (22311232) (11411233) (31411231) + (14111323) (34111321) (23211322) (12311323) (32311321) (21411322) (24111412) + (13211413) (33211411) (22311412) (11411413) (31411411) (24211141) (13311142) + (22411141) (11511142) (25111231) (14211232) (23311231) (12411232) (21511231) + (15111322) (24211321) (13311322) (22411321) (11511322) (25111411) (14211412) + (23311411) (12411412) (21511411) (14311141) (12511141) (15211231) (13411231) + (11611231) (16111321) (14311321) (12511321) (15211411) (13411411) (11611411) + (31121143) (51121141) (21112144) (41112142) (21121234) (41121232) (11112235) + (31112233) (51112231) (11121325) (31121323) (51121321) (21112324) (41112322) + (21121414) (41121412) (11112415) (31112413) (51112411) (12121144) (32121142) + (21221143) (41221141) (22112143) (42112141) (11212144) (22121233) (42121231) + (11221234) (31221232) (12112234) (32112232) (12121324) (32121322) (21221323) + (41221321) (22112323) (42112321) (11212324) (22121413) (42121411) (11221414) + (31221412) (12112414) (32112412) (21212413) (41212411) (13121143) (33121141) + (22221142) (11321143) (31321141) (23112142) (12212143) (23121232) (12221233) + (32221231) (21321232) (13112233) (33112231) (13121323) (33121321) (11312233) + (22221322) (11321323) (31321321) (23112322) (12212323) (23121412) (12221413) + (32221411) (21321412) (13112413) (33112411) (22212412) (11312413) (31312411) + (14121142) (23221141) (12321142) (21421141) (24112141) (13212142) (24121231) + (13221232) (11412142) (22321231) (11421232) (14112232) (14121322) (12312232) + (23221321) (12321322) (21421321) (24112321) (13212322) (24121411) (13221412) + (11412322) (22321411) (11421412) (14112412) (23212411) (12312412) (21412411) + (15121141) (13321141) (11521141) (14212141) (14221231) (12412141) (12421231) + (15112231) (15121321) (13312231) (13321321) (11512231) (11521321) (14212321) + (14221411) (12412321) (12421411) (15112411) (13312411) (11512411) (11131144) + (31131142) (21122143) (41122141) (21131233) (41131231) (11113144) (31113142) + (11122234) (31122232) (11131324) (31131322) (21113233) (41113231) (21122323) + (41122321) (21131413) (41131411) (11113324) (31113322) (11122414) (31122412) + (21113413) (41113411) (12131143) (32131141) (21231142) (22122142) (11222143) + (22131232) (11231233) (31231231) (12113143) (32113141) (12122233) (32122231) + (12131323) (32131321) (21231322) (22113232) (11213233) (22122322) (11222323) + (22131412) (11231413) (31231411) (12113323) (32113321) (12122413) (32122411) + (21222412) (22113412) (11213413) (31213411) (13131142) (22231141) (11331142) + (23122141) (12222142) (23131231) (12231232) (21331231) (13113142) (13122232) + (11313142) (13131322) (11322232) (22231321) (11331322) (23113231) (12213232) + (23122321) (12222322) (23131411) (12231412) (21331411) (13113322) (13122412) + (11313322) (22222411) (11322412) (23113411) (12213412) (21313411) (14131141) + (12331141) (13222141) (13231231) (11422141) (11431231) (14113141) (14122231) + (12313141) (14131321) (12322231) (12331321) (13213231) (13222321) (11413231) + (13231411) (11422321) (11431411) (14113321) (14122411) (12313321) (12322411) + (13213411) (11413411) (11141143) (31141141) (21132142) (21141232) (11123143) + (31123141) (11132233) (31132231) (11141323) (31141321) (21114142) (21123232) + (21132322) (21141412) (11114233) (31114231) (11123323) (31123321) (11132413) + (31132411) (21114322) (21123412) (12141142) (21241141) (22132141) (11232142) + (22141231) (11241232) (12123142) (12132232) (12141322) (21241321) (22114141) + (11214142) (22123231) (11223232) (22132321) (11232322) (22141411) (11241412) + (12114232) (12123322) (12132412) (21232411) (22114321) (11214322) (22123411) + (11223412) (13141141) (11341141) (12232141) (12241231) (13123141) (13132231) + (11323141) (13141321) (11332231) (11341321) (12214141) (12223231) (12232321) + (12241411) (13114231) (13123321) (11314231) (13132411) (11323321) (11332411) + (12214321) (12223411) (11151142) (21142141) (21151231) (11133142) (11142232) + (11151322) (21124141) (21133231) (21142321) (21151411) (11115142) (11124232) + (11133322) (11142412) (21115231) (21124321) (21133411) (12151141) (11242141) + (11251231) (12133141) (12142231) (12151321) (11224141) (11233231) (11242321) + (11251411) (12115141) (12124231) (12133321) (12142411) (11215231) (11224321) + (11233411) (11161141) (11143141) (11152231) (11161321) (11125141) (11134231) + (11143321) (11152411) (11111245) (31111243) (51111241) (21111334) (41111332) + (11111425) (31111423) (51111421) (21111514) (41111512) (31211152) (12111244) + (32111242) (21211243) (41211241) (22111333) (42111331) (11211334) (31211332) + (12111424) (32111422) (21211423) (41211421) (22111513) (42111511) (11211514) + (31211512) (12211153) (32211151) (21311152) (13111243) (33111241) (22211242) + (11311243) (31311241) (23111332) (12211333) (32211331) (21311332) (13111423) + (33111421) (22211422) (11311423) (31311421) (23111512) (12211513) (32211511) + (21311512) (13211152) (22311151) (11411152) (14111242) (23211241) (12311242) + (21411241) (24111331) (13211332) (22311331) (11411332) (14111422) (23211421) + (12311422) (21411421) (24111511) (13211512) (22311511) (11411512) (14211151) + (12411151) (15111241) (13311241) (11511241) (14211331) (12411331) (15111421) + (13311421) (11511421) (14211511) (12411511) (21121153) (41121151) (11112154) + (31112152) (11121244) (31121242) (21112243) (41112241) (21121333) (41121331) + (11112334) (31112332) (11121424) (31121422) (21112423) (41112421) (21121513) + (41121511) (11112514) (31112512) (22121152) (11221153) (31221151) (12112153) + (32112151) (12121243) (32121241) (21221242) (22112242) (11212243) (22121332) + (11221333) (31221331) (12112333) (32112331) (12121423) (32121421) (21221422) + (22112422) (11212423) (22121512) (11221513) (31221511) (12112513) (32112511) + (21212512) (23121151) (12221152) (21321151) (13112152) (13121242) (11312152) + (22221241) (11321242) (23112241) (12212242) (23121331) (12221332) (21321331) + (13112332) (13121422) (11312332) (22221421) (11321422) (23112421) (12212422) + (23121511) (12221512) (21321511) (13112512) (22212511) (11312512) (13221151) + (11421151) (14112151) (14121241) (12312151) (12321241) (13212241) (13221331) + (11412241) (11421331) (14112331) (14121421) (12312331) (12321421) (13212421) + (13221511) (11412421) (11421511) (14112511) (12312511) (21131152) (11122153) + (31122151) (11131243) (31131241) (21113152) (21122242) (21131332) (11113243) + (31113241) (11122333) (31122331) (11131423) (31131421) (21113332) (21122422) + (21131512) (11113423) (31113421) (11122513) (31122511) (22131151) (11231152) + (12122152) (12131242) (21231241) (22113151) (11213152) (22122241) (11222242) + (22131331) (11231332) (12113242) (12122332) (12131422) (21231421) (22113331) + (11213332) (22122421) (11222422) (22131511) (11231512) (12113422) (12122512) + (21222511) (12231151) (13122151) (13131241) (11322151) (11331241) (12213151) + (12222241) (12231331) (13113241) (13122331) (11313241) (13131421) (11322331) + (11331421) (12213331) (12222421) (12231511) (13113421) (13122511) (11313421) + (11322511) (21141151) (11132152) (11141242) (21123151) (21132241) (21141331) + (11114152) (11123242) (11132332) (11141422) (21114241) (21123331) (21132421) + (21141511) (11114332) (11123422) (11132512) (11241151) (12132151) (12141241) + (11223151) (11232241) (11241331) (12114151) (12123241) (12132331) (12141421) + (11214241) (11223331) (11232421) (11241511) (12114331) (12123421) (12132511) + (11142151) (11151241) (11124151) (11133241) (11142331) (11151421) (11115241) + (11124331) (11133421) (11142511) (21111253) (41111251) (11111344) (31111342) + (21111433) (41111431) (11111524) (31111522) (21111613) (41111611) (21211162) + (22111252) (11211253) (31211251) (12111343) (32111341) (21211342) (22111432) + (11211433) (31211431) (12111523) (32111521) (21211522) (22111612) (11211613) + (31211611) (22211161) (11311162) (23111251) (12211252) (21311251) (13111342) + (22211341) (11311342) (23111431) (12211432) (21311431) (13111522) (22211521) + (11311522) (23111611) (12211612) (21311611) (12311161) (13211251) (11411251) + (14111341) (12311341) (13211431) (11411431) (14111521) (12311521) (13211611) + (11411611) (31121161) (21112162) (21121252) (11112253) (31112251) (11121343) + (31121341) (21112342) (21121432) (11112433) (31112431) (11121523) (31121521) + (21112522) (21121612) (12121162) (21221161) (22112161) (11212162) (22121251) + (11221252) (12112252) (12121342) (21221341) (22112341) (11212342) (22121431) + (11221432) (12112432) (12121522) (21221521) (22112521) (11212522) (22121611) + (11221612) (13121161) (11321161) (12212161) (12221251) (13112251) (13121341) + (11312251) (11321341) (12212341) (12221431) (13112431) (13121521) (11312431) + (11321521) (12212521) (12221611) (11131162) (21122161) (21131251) (11113162) + ] + ] def + + /parity [ + (1001) (0101) (1100) (0011) (1010) (0110) (1111) (0000) + ] def + + % Derive the bits for each row + /rowbits r array def + 0 1 r 1 sub { + /i exch def + /p i r 1 sub ne {parity i get} {(0000)} ifelse def + /ccrow ccs i 8 mul 8 getinterval def + /scrow [ + 0 2 7 {ccrow exch 2 getinterval aload pop exch 49 mul add} for + ] def + /sbs [ + 10 1 1 + 0 1 3 { + /j exch def + patterns p j get 48 sub get scrow j get get {48 sub} forall + } for + 4 1 + ] def + mark + 1 sbs {1 index 0 eq {{1}} {{0}} ifelse repeat} forall + counttomark 1 sub array astore exch pop exch pop + rowbits i 3 -1 roll put + } for + + % Populate the bitmap + /pixs [ + 81 sepheight mul {1} repeat + 0 1 r 2 sub { + /i exch def + rowheight {rowbits i get aload pop} repeat + sepheight {10 {0} repeat 70 {1} repeat 0} repeat + } for + rowheight {rowbits r 1 sub get aload pop} repeat + 81 sepheight mul {1} repeat + ] def + + % Return the arguments + << + /ren //renmatrix + /pixs pixs + /pixx 81 + /pixy pixs length 81 idiv + /height pixs length 81 idiv 72 div + /width 81 72 div + /opt options + >> + + dontdraw not //renmatrix if + + end + +} bind def +/code49 dup load /uk.co.terryburton.bwipp defineresource pop +end +/setpacking where {pop setpacking} if +% --END ENCODER code49-- + +% --BEGIN ENCODER channelcode-- +% --DESC: Channel Code +% --EXAM: 3493 +% --EXOP: height=0.5 includetext +% --RNDR: renlinear +/setpacking where {pop currentpacking true setpacking} if +1 dict +dup /renlinear dup /uk.co.terryburton.bwipp findresource put +begin +/channelcode { + + 20 dict begin % Confine variables to local scope + + /options exch def % We are given an option string + /barcode exch def % We are given a barcode string + + /dontdraw false def + /shortfinder false def + /includetext false def + /includecheck false def + /height 1 def + + % Parse the input options + options type /stringtype eq { + 1 dict begin + options { + token false eq {exit} if dup length string cvs (=) search + true eq {cvlit exch pop exch def} {cvlit true def} ifelse + } loop + currentdict end /options exch def + } if + options {def} forall + + /height height cvr def + + /barlen barcode length def + + barlen 2 ge barlen 7 le and { + /channels barlen 1 add def + } if + + % Determine finder + shortfinder { + /finder [ 1 1 1 1 1 ] def + } { + /finder [ 1 1 1 1 1 1 1 1 1 ] def + } ifelse + + /nextb { + dup + dup s exch get exch + dup b exch 1 sub get exch + dup s exch 1 sub get exch + b exch 2 sub get exch + add add add 4 gt {1} {2} ifelse + 1 index chan 2 add lt { + dup 1 4 index { + b 3 index 2 index put + 3 index exch sub 1 add 4 index 3 index 1 add nexts + } for + } { + dup 3 index le { + b 2 index 4 index put + value target eq { + /out [ + 3 1 10 {dup s exch get exch b exch get} for + ] 0 chan 2 mul getinterval def + } if + /value value 1 add def + } if + } ifelse + pop pop pop pop + } bind def + + /nexts { + dup chan 2 add lt {1} {1 index} ifelse 1 3 index { + s 2 index 2 index put + 2 index exch sub 1 add 3 index 2 index nextb + } for + pop pop pop + } bind def + + /encode { + /chan exch def + /target exch def + /value 0 def + /out -1 def + /b [ 1 1 1 0 0 0 0 0 0 0 0 ] def + /s [ 0 1 1 0 0 0 0 0 0 0 0 ] def + chan dup 3 nexts + out + } bind def + + % Encode the main data + /data barcode cvi channels encode def + + % Determine check data + /check [] def + includecheck { + /mod23 [ + [] [] [] + [ 13 12 4 9 3 1 ] + [ 13 2 12 3 18 16 4 1 ] + [ 11 16 17 8 20 4 10 2 5 1 ] + [ 1 4 16 18 3 12 2 8 9 13 6 1 ] + [ 20 16 22 13 15 12 5 4 8 9 21 3 7 1 ] + [ 2 6 18 8 1 3 9 4 12 13 16 2 6 18 8 1 ] + ] channels get def + 0 + 0 1 data length 1 sub { + dup data exch get 1 sub exch mod23 exch get mul add + } for + 23 mod 3 encode /check exch def + } if + + % Construct the symbol + /sbs [ + finder aload pop + data aload pop + check aload pop + ] def + + % Create the human readable text + /txt barlen array def + 0 1 barlen 1 sub { + /i exch def + txt i [barcode i 1 getinterval 0 0 () 0] put + } for + + % Return the arguments + << + /ren //renlinear + /sbs sbs + /bhs [sbs length 1 add 2 idiv {height} repeat] + /bbs [sbs length 1 add 2 idiv {0} repeat] + /txt txt + /textxalign (center) + /opt options + >> + + dontdraw not //renlinear if + + end + +} bind def +/channelcode dup load /uk.co.terryburton.bwipp defineresource pop +end +/setpacking where {pop setpacking} if +% --END ENCODER channelcode-- + +% --BEGIN ENCODER flattermarken-- +% --DESC: Flattermarken +% --EXAM: 12345 +% --EXOP: inkspread=-0.25 +% --RNDR: renlinear +/setpacking where {pop currentpacking true setpacking} if +1 dict +dup /renlinear dup /uk.co.terryburton.bwipp findresource put +begin +/flattermarken { + + 20 dict begin % Confine variable to local scope + + /options exch def % We are given an option string + /barcode exch def % We are given a barcode string + + /dontdraw false def + /includetext false def % Enable/disable text + /textfont /Courier def + /textsize 10 def + /textyoffset -7 def + /height 0.3 def + + % Parse the input options + options type /stringtype eq { + 1 dict begin + options { + token false eq {exit} if dup length string cvs (=) search + true eq {cvlit exch pop exch def} {cvlit true def} ifelse + } loop + currentdict end /options exch def + } if + options {def} forall + + /textfont textfont cvlit def + /textsize textsize cvr def + /textyoffset textyoffset cvr def + /height height cvr def + + % Create an array containing the character mappings + /encs + [ (0018) (0117) (0216) (0315) (0414) (0513) (0612) (0711) (0810) + (0900) + ] def + + % Create a string of the available characters + /barchars (1234567890) def + + /barlen barcode length def % Length of the code + + /sbs barlen 4 mul string def + /txt barlen array def + + 0 1 barlen 1 sub { + /i exch def + % Lookup the encoding for the each barcode character + barcode i 1 getinterval barchars exch search + pop % Discard true leaving pre + length /indx exch def % indx is the length of pre + pop pop % Discard seek and post + /enc encs indx get def % Get the indxth encoding + sbs i 4 mul enc putinterval % Put encoded digit into sbs + txt i [barcode i 1 getinterval i 9 mul textyoffset textfont textsize] put + } for + + % Return the arguments + << + /ren //renlinear + /sbs [sbs {48 sub} forall] + /bhs [sbs length 1 add 2 idiv {height} repeat] + /bbs [sbs length 1 add 2 idiv {0} repeat] + /txt txt + /opt options + >> + + dontdraw not //renlinear if + + end + +} bind def +/flattermarken dup load /uk.co.terryburton.bwipp defineresource pop +end +/setpacking where {pop setpacking} if +% --END ENCODER flattermarken-- + +% --BEGIN ENCODER raw-- +% --DESC: Raw bar space succession for custom symbologies +% --EXAM: 331132131313411122131311333213114131131221323 +% --EXOP: height=0.5 +% --RNDR: renlinear +/setpacking where {pop currentpacking true setpacking} if +1 dict +dup /renlinear dup /uk.co.terryburton.bwipp findresource put +begin +/raw { + + 20 dict begin % Confine variables to local scope + + /options exch def % We are given an option string + /sbs exch def % We are given a barcode string + + /dontdraw false def + /height 1 def + + % Parse the input options + options type /stringtype eq { + 1 dict begin + options { + token false eq {exit} if dup length string cvs (=) search + true eq {cvlit exch pop exch def} {cvlit true def} ifelse + } loop + currentdict end /options exch def + } if + options {def} forall + + /height height cvr def + + % Return the arguments + << + /ren //renlinear + /sbs [sbs {48 sub} forall] + /bhs [sbs length 1 add 2 idiv {height} repeat] + /bbs [sbs length 1 add 2 idiv {0} repeat] + /opt options + >> + + dontdraw not //renlinear if + + end + +} bind def +/raw dup load /uk.co.terryburton.bwipp defineresource pop +end +/setpacking where {pop setpacking} if +% --END ENCODER raw-- + +% --BEGIN ENCODER daft-- +% --DESC: Raw DAFT succession for custom 4 state symbologies +% --EXAM: FATDAFTDAD +% --EXOP: +% --RNDR: renlinear +/setpacking where {pop currentpacking true setpacking} if +1 dict +dup /renlinear dup /uk.co.terryburton.bwipp findresource put +begin +/daft { + + 20 dict begin + + /options exch def % We are given an option string + /barcode exch def % We are given a barcode string + + /dontdraw false def + /height 0.175 def + + % Parse the input options + options type /stringtype eq { + 1 dict begin + options { + token false eq {exit} if dup length string cvs (=) search + true eq {cvlit exch pop exch def} {cvlit true def} ifelse + } loop + currentdict end /options exch def + } if + options {def} forall + + /height height cvr def + + /barlen barcode length def + + /bbs barlen array def + /bhs barlen array def + 0 1 barlen 1 sub { + /i exch def + /enc barcode i 1 getinterval def + enc (D) eq { + bbs i 0 height mul 8 div put + bhs i 5 height mul 8 div put + } if + enc (A) eq { + bbs i 3 height mul 8 div put + bhs i 5 height mul 8 div put + } if + enc (F) eq { + bbs i 0 height mul 8 div put + bhs i 8 height mul 8 div put + } if + enc (T) eq { + bbs i 3 height mul 8 div put + bhs i 2 height mul 8 div put + } if + } for + + % Return the arguments + << + /ren //renlinear + /bbs bbs + /bhs bhs + /sbs [bhs length 1 sub {1.44 1.872} repeat 1.44] + /opt options + >> + + dontdraw not //renlinear if + + end + +} bind def +/daft dup load /uk.co.terryburton.bwipp defineresource pop +end +/setpacking where {pop setpacking} if +% --END ENCODER daft-- + +% --BEGIN ENCODER symbol-- +% --DESC: Miscellaneous symbols +% --EXAM: fima +% --EXOP: backgroundcolor=DD000011 +% --RNDR: renlinear +/setpacking where {pop currentpacking true setpacking} if +1 dict +dup /renlinear dup /uk.co.terryburton.bwipp findresource put +begin +/symbol { + + 20 dict begin % Confine variables to local scope + + /options exch def % We are given an option string + /barcode exch def % We are given a barcode string + + /dontdraw false def + + barcode (fima) eq { + /sbs [2.25 2.25 2.25 11.25 2.25 11.25 2.25 2.25 2.25] def + /bhs [.625 .625 .625 .625 .625] def + /bbs [0 0 0 0 0] def + } if + + barcode (fimb) eq { + /sbs [2.25 6.75 2.25 2.25 2.25 6.25 2.25 2.25 2.25 6.75 2.25] def + /bhs [.625 .625 .625 .625 .625 .625] def + /bbs [0 0 0 0 0 0] def + } if + + barcode (fimc) eq { + /sbs [2.25 2.25 2.25 6.75 2.25 6.75 2.25 6.75 2.25 2.25 2.25] def + /bhs [.625 .625 .625 .625 .625 .625] def + /bbs [0 0 0 0 0 0] def + } if + + barcode (fimd) eq { + /sbs [2.25 2.25 2.25 2.25 2.25 6.75 2.25 6.75 2.25 2.25 2.25 2.25 2.25] def + /bhs [.625 .625 .625 .625 .625 .625 .625] def + /bbs [0 0 0 0 0 0 0] def + } if + + % Return the arguments + << + /ren //renlinear + /sbs sbs + /bhs bhs + /bbs bbs + /opt options + >> + + dontdraw not //renlinear if + + end + +} bind def +/symbol dup load /uk.co.terryburton.bwipp defineresource pop +end +/setpacking where {pop setpacking} if +% --END ENCODER symbol-- + +% --BEGIN ENCODER pdf417-- +% --DESC: PDF417 +% --EXAM: This is PDF417 +% --EXOP: +% --RNDR: renmatrix +/setpacking where {pop currentpacking true setpacking} if +1 dict +dup /renmatrix dup /uk.co.terryburton.bwipp findresource put +begin +/pdf417 { + + 20 dict begin + + /options exch def + /barcode exch def + + /dontdraw false def + /compact false def + /eclevel -1 def + /columns 0 def + /rows 0 def + /rowmult 3 def + /ccc false def + /raw false def + /parse false def + + % Parse the input options + options type /stringtype eq { + 1 dict begin + options { + token false eq {exit} if dup length string cvs (=) search + true eq {cvlit exch pop exch def} {cvlit true def} ifelse + } loop + currentdict end /options exch def + } if + options {def} forall + + /eclevel eclevel cvi def + /columns columns cvi def + /rows rows cvi def + /rowmult rowmult cvr def + + % Parse ordinals of the form ^NNN to ASCII + parse { + /msg barcode length string def + /j 0 def + barcode + { % loop + (^) search { + dup msg exch j exch putinterval + length j add 1 add /j exch def + pop + dup 0 3 getinterval cvi msg exch j 1 sub exch put + dup length 3 sub 3 exch getinterval + } { + dup msg exch j exch putinterval + length j add /j exch def + /barcode msg 0 j getinterval def + exit + } ifelse + } loop + } if + + % Convert input into array of codewords + raw { + /datcws barcode length array def + /i 0 def /j 0 def + { % loop + i barcode length eq {exit} if + /cw barcode i 1 add 3 getinterval cvi def + datcws j cw put + /i i 4 add def + /j j 1 add def + } loop + /datcws datcws 0 j getinterval def + } { % Simple autoencoder from input to codewords using byte mode + /barlen barcode length def + barlen 6 mod 0 eq { + /datcws barlen 6 idiv 5 mul 1 add array def + datcws 0 924 put + } { + /datcws barlen 6 idiv 5 mul barlen 6 mod add 1 add array def + datcws 0 901 put + } ifelse + + % Rebase groups of 6 bytes splitting into 3 byte chunks + 0 1 barlen 6 idiv 1 sub { + /i exch def + /msbs [ barcode i 6 mul 3 getinterval {} forall ] def + /mscs [ + msbs aload pop exch 256 mul add exch 65536 mul add + 3 {dup 900 mod exch 900 idiv} repeat + ] def + /lsbs [barcode i 6 mul 3 add 3 getinterval {} forall] def + /lscs [ + lsbs aload pop exch 256 mul add exch 65536 mul add + 3 {dup 900 mod exch 900 idiv} repeat + ] def + /cws 5 array def + lscs 0 get mscs 0 get 316 mul add + cws 4 2 index 900 mod put + 900 idiv lscs 1 get add mscs 0 get 641 mul add mscs 1 get 316 mul add + cws 3 2 index 900 mod put + 900 idiv lscs 2 get add mscs 0 get 20 mul add mscs 1 get 641 mul add mscs 2 get 316 mul add + cws 2 2 index 900 mod put + 900 idiv lscs 3 get add mscs 1 get 20 mul add mscs 2 get 641 mul add + cws 1 2 index 900 mod put + 900 idiv mscs 2 get 20 mul add + cws 0 3 -1 roll 900 mod put + datcws i 5 mul 1 add cws putinterval + } for + + % Add the remaining bytes to the end of the codewords + /rem barlen 6 mod def + rem 0 ne { + datcws datcws length rem sub + [ barcode barlen rem sub rem getinterval {} forall ] + putinterval + } if + + ccc {/datcws [920 datcws aload pop] def} if + + } ifelse + + % Determine the error correction level if unspecified + /m datcws length def + eclevel -1 eq { + m 40 le {/eclevel 2 def} if + m 41 ge m 160 le and {/eclevel 3 def} if + m 161 ge m 320 le and {/eclevel 4 def} if + m 321 ge {/eclevel 5 def} if + } if + + % Reduce the error level so that it does not cause an excessive number of codewords + /maxeclevel 928 1 sub m sub ln 2 ln div cvi 1 sub def + eclevel maxeclevel gt {/eclevel maxeclevel def} if + /k 2 eclevel 1 add exp cvi def + + % To determine size of matrix, number of columns if given by user... + columns 0 eq {/columns m k add 3 div sqrt round cvi def} if + columns 1 ge columns 30 le and {/c columns def} if + + % ... and rows is greater of those required and that given by user within limits + /r m k add 1 add columns div ceiling cvi def % Required + r rows lt rows 90 le and {/r rows def} if + r 3 lt {/r 3 def} if + + % Opportunistically raise the error level if a better fit to the matrix is possible + /maxeclevel c r mul 1 sub m sub ln 2 ln div cvi 1 sub 8 2 copy gt {exch} if pop def + maxeclevel eclevel gt { + /eclevel maxeclevel def + /k 2 eclevel 1 add exp cvi def + } if + + % Create codewords array with one extra working space element and add padding + /n c r mul k sub def + /cws c r mul 1 add array def + cws 0 n put + cws 1 datcws putinterval + cws m 1 add [ n m sub 1 sub {900} repeat ] putinterval + cws n [ k {0} repeat 0 ] putinterval + + % Calculate the log and anti-log tables + /rsalog [ 1 928 {dup 3 mul 929 mod} repeat ] def + /rslog 929 array def + 1 1 928 {dup rsalog exch get exch rslog 3 1 roll put} for + + % Function to calculate the product in the field + /rsprod { + 2 copy 0 ne exch 0 ne and { + rslog exch get exch rslog exch get add 928 mod rsalog exch get + } { + pop pop 0 + } ifelse + } bind def + + % Generate the coefficients + /coeffs [ 1 k {0} repeat ] def + 1 1 k { + /i exch def + coeffs i coeffs i 1 sub get put + i 1 sub -1 1 { + /j exch def + coeffs j coeffs j 1 sub get coeffs j get rsalog i get rsprod add 929 mod put + } for + coeffs 0 coeffs 0 get rsalog i get rsprod put + } for + /coeffs coeffs 0 coeffs length 1 sub getinterval def + coeffs length 1 sub -2 0 {coeffs exch 2 copy get 929 exch sub put} for + + % Derive the error codewords + 0 1 n 1 sub { + /t exch cws exch get cws n get add 929 mod def + 0 1 k 1 sub { + /j exch def + cws n j add cws n j add 1 add get 929 t coeffs k j sub 1 sub get mul 929 mod sub add 929 mod put + } for + } for + n 1 n k add { dup cws exch 929 cws 5 -1 roll get sub 929 mod put } for + + % Trim the working space from the end of the codewords + /cws cws 0 cws length 1 sub getinterval def + + % Base 10 encoding of the bar space successions for the codewords in each cluster + /clusters [ + [ + 120256 125680 128380 120032 125560 128318 108736 119920 108640 86080 108592 86048 + 110016 120560 125820 109792 120440 125758 88256 109680 88160 89536 110320 120700 + 89312 110200 120638 89200 110140 89840 110460 89720 110398 89980 128506 119520 + 125304 128190 107712 119408 125244 107616 119352 84032 107568 119324 84000 107544 + 83984 108256 119672 125374 85184 108144 119612 85088 108088 119582 85040 108060 + 85728 108408 119742 85616 108348 85560 108318 85880 108478 85820 85790 107200 + 119152 125116 107104 119096 125086 83008 107056 119068 82976 107032 82960 82952 + 83648 107376 119228 83552 107320 119198 83504 107292 83480 83468 83824 107452 + 83768 107422 83740 83900 106848 118968 125022 82496 106800 118940 82464 106776 + 118926 82448 106764 82440 106758 82784 106936 119006 82736 106908 82712 106894 + 82700 82694 106974 82830 82240 106672 118876 82208 106648 118862 82192 106636 + 82184 106630 82180 82352 82328 82316 82080 118830 106572 106566 82050 117472 + 124280 127678 103616 117360 124220 103520 117304 124190 75840 103472 75808 104160 + 117624 124350 76992 104048 117564 76896 103992 76848 76824 77536 104312 117694 + 77424 104252 77368 77340 77688 104382 77628 77758 121536 126320 128700 121440 + 126264 128670 111680 121392 126236 111648 121368 126222 111632 121356 103104 117104 + 124092 112320 103008 117048 124062 112224 121656 126366 93248 74784 102936 117006 + 93216 112152 93200 75456 103280 117180 93888 75360 103224 117150 93792 112440 + 121758 93744 75288 93720 75632 103356 94064 75576 103326 94008 112542 93980 + 75708 94140 75678 94110 121184 126136 128606 111168 121136 126108 111136 121112 + 126094 111120 121100 111112 111108 102752 116920 123998 111456 102704 116892 91712 + 74272 121244 116878 91680 74256 102668 91664 111372 102662 74244 74592 102840 + 116958 92000 74544 102812 91952 111516 102798 91928 74508 74502 74680 102878 + 92088 74652 92060 74638 92046 92126 110912 121008 126044 110880 120984 126030 + 110864 120972 110856 120966 110852 110850 74048 102576 116828 90944 74016 102552 + 116814 90912 111000 121038 90896 73992 102534 90888 110982 90884 74160 102620 + 91056 74136 102606 91032 111054 91020 74118 91014 91100 91086 110752 120920 + 125998 110736 120908 110728 120902 110724 110722 73888 102488 116782 90528 73872 + 102476 90512 110796 102470 90504 73860 90500 73858 73944 90584 90572 90566 + 120876 120870 110658 102444 73800 90312 90308 90306 101056 116080 123580 100960 + 116024 70720 100912 115996 70688 100888 70672 70664 71360 101232 116156 71264 + 101176 116126 71216 101148 71192 71180 71536 101308 71480 101278 71452 71612 + 71582 118112 124600 127838 105024 118064 124572 104992 118040 124558 104976 118028 + 104968 118022 100704 115896 123486 105312 100656 115868 79424 70176 118172 115854 + 79392 105240 100620 79376 70152 79368 70496 100792 115934 79712 70448 118238 + 79664 105372 100750 79640 70412 79628 70584 100830 79800 70556 79772 70542 + 70622 79838 122176 126640 128860 122144 126616 128846 122128 126604 122120 126598 + 122116 104768 117936 124508 113472 104736 126684 124494 113440 122264 126670 113424 + 104712 117894 113416 122246 104706 69952 100528 115804 78656 69920 100504 115790 + 96064 78624 104856 117966 96032 113560 122318 100486 96016 78600 104838 96008 + 69890 70064 100572 78768 70040 100558 96176 78744 104910 96152 113614 70022 + 78726 70108 78812 70094 96220 78798 122016 126552 128814 122000 126540 121992 + 126534 121988 121986 104608 117848 124462 113056 104592 126574 113040 122060 117830 + 113032 104580 113028 104578 113026 69792 100440 115758 78240 69776 100428 95136 + 78224 104652 100422 95120 113100 69764 95112 78212 69762 78210 69848 100462 + 78296 69836 95192 78284 69830 95180 78278 69870 95214 121936 126508 121928 + 126502 121924 121922 104528 117804 112848 104520 117798 112840 121958 112836 104514 + 112834 69712 100396 78032 69704 100390 94672 78024 104550 94664 112870 69698 + 94660 78018 94658 78060 94700 94694 126486 121890 117782 104484 104482 69672 + 77928 94440 69666 77922 99680 68160 99632 68128 99608 115342 68112 99596 + 68104 99590 68448 99768 115422 68400 99740 68376 99726 68364 68358 68536 + 99806 68508 68494 68574 101696 116400 123740 101664 116376 101648 116364 101640 + 116358 101636 67904 99504 115292 72512 67872 116444 115278 72480 101784 116430 + 72464 67848 99462 72456 101766 67842 68016 99548 72624 67992 99534 72600 + 101838 72588 67974 68060 72668 68046 72654 118432 124760 127918 118416 124748 + 118408 124742 118404 118402 101536 116312 105888 101520 116300 105872 118476 116294 + 105864 101508 105860 101506 105858 67744 99416 72096 67728 116334 80800 72080 + 101580 99398 80784 105932 67716 80776 72068 67714 72066 67800 99438 72152 + 67788 80856 72140 67782 80844 72134 67822 72174 80878 126800 128940 126792 + 128934 126788 126786 118352 124716 122576 126828 124710 122568 126822 122564 118338 + 122562 101456 116268 105680 101448 116262 114128 105672 118374 114120 122598 101442 + 114116 105666 114114 67664 99372 71888 67656 99366 80336 71880 101478 97232 + 80328 105702 67650 97224 114150 71874 97220 67692 71916 67686 80364 71910 + 97260 80358 97254 126760 128918 126756 126754 118312 124694 122472 126774 122468 + 118306 122466 101416 116246 105576 101412 113896 105572 101410 113892 105570 113890 + 67624 99350 71784 101430 80104 71780 67618 96744 80100 71778 96740 80098 + 96738 71798 96758 126738 122420 122418 105524 113780 113778 71732 79988 96500 + 96498 66880 66848 98968 66832 66824 66820 66992 66968 66956 66950 67036 + 67022 100000 99984 115532 99976 115526 99972 99970 66720 98904 69024 100056 + 98892 69008 100044 69000 100038 68996 66690 68994 66776 98926 69080 100078 + 69068 66758 69062 66798 69102 116560 116552 116548 116546 99920 102096 116588 + 115494 102088 116582 102084 99906 102082 66640 68816 66632 98854 73168 68808 + 66628 73160 68804 66626 73156 68802 66668 68844 66662 73196 68838 73190 + 124840 124836 124834 116520 118632 124854 118628 116514 118626 99880 115478 101992 + 116534 106216 101988 99874 106212 101986 106210 66600 98838 68712 99894 72936 + 68708 66594 81384 72932 68706 81380 72930 66614 68726 72950 81398 128980 + 128978 124820 126900 124818 126898 116500 118580 116498 122740 118578 122738 99860 + 101940 99858 106100 101938 114420 + ] [ + 128352 129720 125504 128304 129692 125472 128280 129678 125456 128268 125448 128262 + 125444 125792 128440 129758 120384 125744 128412 120352 125720 128398 120336 125708 + 120328 125702 120324 120672 125880 128478 110144 120624 125852 110112 120600 125838 + 110096 120588 110088 120582 110084 110432 120760 125918 89664 110384 120732 89632 + 110360 120718 89616 110348 89608 110342 89952 110520 120798 89904 110492 89880 + 110478 89868 90040 110558 90012 89998 125248 128176 129628 125216 128152 129614 + 125200 128140 125192 128134 125188 125186 119616 125360 128220 119584 125336 128206 + 119568 125324 119560 125318 119556 119554 108352 119728 125404 108320 119704 125390 + 108304 119692 108296 119686 108292 108290 85824 108464 119772 85792 108440 119758 + 85776 108428 85768 108422 85764 85936 108508 85912 108494 85900 85894 85980 + 85966 125088 128088 129582 125072 128076 125064 128070 125060 125058 119200 125144 + 128110 119184 125132 119176 125126 119172 119170 107424 119256 125166 107408 119244 + 107400 119238 107396 107394 83872 107480 119278 83856 107468 83848 107462 83844 + 83842 83928 107502 83916 83910 83950 125008 128044 125000 128038 124996 124994 + 118992 125036 118984 125030 118980 118978 106960 119020 106952 119014 106948 106946 + 82896 106988 82888 106982 82884 82882 82924 82918 124968 128022 124964 124962 + 118888 124982 118884 118882 106728 118902 106724 106722 82408 106742 82404 82402 + 124948 124946 118836 118834 106612 106610 124224 127664 129372 124192 127640 129358 + 124176 127628 124168 127622 124164 124162 117568 124336 127708 117536 124312 127694 + 117520 124300 117512 124294 117508 117506 104256 117680 124380 104224 117656 124366 + 104208 117644 104200 117638 104196 104194 77632 104368 117724 77600 104344 117710 + 77584 104332 77576 104326 77572 77744 104412 77720 104398 77708 77702 77788 + 77774 128672 129880 93168 128656 129868 92664 128648 129862 92412 128644 128642 + 124064 127576 129326 126368 124048 129902 126352 128716 127558 126344 124036 126340 + 124034 126338 117152 124120 127598 121760 117136 124108 121744 126412 124102 121736 + 117124 121732 117122 121730 103328 117208 124142 112544 103312 117196 112528 121804 + 117190 112520 103300 112516 103298 112514 75680 103384 117230 94112 75664 103372 + 94096 112588 103366 94088 75652 94084 75650 75736 103406 94168 75724 94156 + 75718 94150 75758 128592 129836 91640 128584 129830 91388 128580 91262 128578 + 123984 127532 126160 123976 127526 126152 128614 126148 123970 126146 116944 124012 + 121296 116936 124006 121288 126182 121284 116930 121282 102864 116972 111568 102856 + 116966 111560 121318 111556 102850 111554 74704 102892 92112 74696 102886 92104 + 111590 92100 74690 92098 74732 92140 74726 92134 128552 129814 90876 128548 + 90750 128546 123944 127510 126056 128566 126052 123938 126050 116840 123958 121064 + 116836 121060 116834 121058 102632 116854 111080 121078 111076 102626 111074 74216 + 102646 91112 74212 91108 74210 91106 74230 91126 128532 90494 128530 123924 + 126004 123922 126002 116788 120948 116786 120946 102516 110836 102514 110834 73972 + 90612 73970 90610 128522 123914 125978 116762 120890 102458 110714 123552 127320 + 129198 123536 127308 123528 127302 123524 123522 116128 123608 127342 116112 123596 + 116104 123590 116100 116098 101280 116184 123630 101264 116172 101256 116166 101252 + 101250 71584 101336 116206 71568 101324 71560 101318 71556 71554 71640 101358 + 71628 71622 71662 127824 129452 79352 127816 129446 79100 127812 78974 127810 + 123472 127276 124624 123464 127270 124616 127846 124612 123458 124610 115920 123500 + 118224 115912 123494 118216 124646 118212 115906 118210 100816 115948 105424 100808 + 115942 105416 118246 105412 100802 105410 70608 100844 79824 70600 100838 79816 + 105446 79812 70594 79810 70636 79852 70630 79846 129960 95728 113404 129956 + 95480 113278 129954 95356 95294 127784 129430 78588 128872 129974 95996 78462 + 128868 127778 95870 128866 123432 127254 124520 123428 126696 128886 123426 126692 + 124514 126690 115816 123446 117992 115812 122344 117988 115810 122340 117986 122338 + 100584 115830 104936 100580 113640 104932 100578 113636 104930 113634 70120 100598 + 78824 70116 96232 78820 70114 96228 78818 96226 70134 78838 129940 94968 + 113022 129938 94844 94782 127764 78206 128820 127762 95102 128818 123412 124468 + 123410 126580 124466 126578 115764 117876 115762 122100 117874 122098 100468 104692 + 100466 113140 104690 113138 69876 78324 69874 95220 78322 95218 129930 94588 + 94526 127754 128794 123402 124442 126522 115738 117818 121978 100410 104570 112890 + 69754 78074 94714 94398 123216 127148 123208 127142 123204 123202 115408 123244 + 115400 123238 115396 115394 99792 115436 99784 115430 99780 99778 68560 99820 + 68552 99814 68548 68546 68588 68582 127400 129238 72444 127396 72318 127394 + 123176 127126 123752 123172 123748 123170 123746 115304 123190 116456 115300 116452 + 115298 116450 99560 115318 101864 99556 101860 99554 101858 68072 99574 72680 + 68068 72676 68066 72674 68086 72694 129492 80632 105854 129490 80508 80446 + 127380 72062 127924 127378 80766 127922 123156 123700 123154 124788 123698 124786 + 115252 116340 115250 118516 116338 118514 99444 101620 99442 105972 101618 105970 + 67828 72180 67826 80884 72178 80882 97008 114044 96888 113982 96828 96798 + 129482 80252 130010 97148 80190 97086 127370 127898 128954 123146 123674 124730 + 126842 115226 116282 118394 122618 99386 101498 105722 114170 67706 71930 80378 + 96632 113854 96572 96542 80062 96702 96444 96414 96350 123048 123044 123042 + 115048 123062 115044 115042 99048 115062 99044 99042 67048 99062 67044 67042 + 67062 127188 68990 127186 123028 123316 123026 123314 114996 115572 114994 115570 + 98932 100084 98930 100082 66804 69108 66802 69106 129258 73084 73022 127178 + 127450 123018 123290 123834 114970 115514 116602 98874 99962 102138 66682 68858 + 73210 81272 106174 81212 81182 72894 81342 97648 114364 97592 114334 97564 + 97550 81084 97724 81054 97694 97464 114270 97436 97422 80990 97502 97372 + 97358 97326 114868 114866 98676 98674 66292 66290 123098 114842 115130 98618 + 99194 66170 67322 69310 73404 73374 81592 106334 81564 81550 73310 81630 + 97968 114524 97944 114510 97932 97926 81500 98012 81486 97998 97880 114478 + 97868 97862 81454 97902 97836 97830 69470 73564 73550 81752 106414 81740 + 81734 73518 81774 81708 81702 + ] [ + 109536 120312 86976 109040 120060 86496 108792 119934 86256 108668 86136 129744 + 89056 110072 129736 88560 109820 129732 88312 109694 129730 88188 128464 129772 + 89592 128456 129766 89340 128452 89214 128450 125904 128492 125896 128486 125892 + 125890 120784 125932 120776 125926 120772 120770 110544 120812 110536 120806 110532 + 84928 108016 119548 84448 107768 119422 84208 107644 84088 107582 84028 129640 + 85488 108284 129636 85240 108158 129634 85116 85054 128232 129654 85756 128228 + 85630 128226 125416 128246 125412 125410 119784 125430 119780 119778 108520 119798 + 108516 108514 83424 107256 119166 83184 107132 83064 107070 83004 82974 129588 + 83704 107390 129586 83580 83518 128116 83838 128114 125172 125170 119284 119282 + 107508 107506 82672 106876 82552 106814 82492 82462 129562 82812 82750 128058 + 125050 119034 82296 106686 82236 82206 82366 82108 82078 76736 103920 117500 + 76256 103672 117374 76016 103548 75896 103486 75836 129384 77296 104188 129380 + 77048 104062 129378 76924 76862 127720 129398 77564 127716 77438 127714 124392 + 127734 124388 124386 117736 124406 117732 117730 104424 117750 104420 104418 112096 + 121592 126334 92608 111856 121468 92384 111736 121406 92272 111676 92216 111646 + 92188 75232 103160 117118 93664 74992 103036 93424 112252 102974 93304 74812 + 93244 74782 93214 129332 75512 103294 129908 129330 93944 75388 129906 93820 + 75326 93758 127604 75646 128756 127602 94078 128754 124148 126452 124146 126450 + 117236 121844 117234 121842 103412 103410 91584 111344 121212 91360 111224 121150 + 91248 111164 91192 111134 91164 91150 74480 102780 91888 74360 102718 91768 + 111422 91708 74270 91678 129306 74620 129850 92028 74558 91966 127546 128634 + 124026 126202 116986 121338 102906 90848 110968 121022 90736 110908 90680 110878 + 90652 90638 74104 102590 91000 74044 90940 74014 90910 74174 91070 90480 + 110780 90424 110750 90396 90382 73916 90556 73886 90526 90296 110686 90268 + 90254 73822 90334 90204 90190 71136 101112 116094 70896 100988 70776 100926 + 70716 70686 129204 71416 101246 129202 71292 71230 127348 71550 127346 123636 + 123634 116212 116210 101364 101362 79296 105200 118140 79072 105080 118078 78960 + 105020 78904 104990 78876 78862 70384 100732 79600 70264 100670 79480 105278 + 79420 70174 79390 129178 70524 129466 79740 70462 79678 127290 127866 123514 + 124666 115962 118266 100858 113376 122232 126654 95424 113264 122172 95328 113208 + 122142 95280 113180 95256 113166 95244 78560 104824 117950 95968 78448 104764 + 95856 113468 104734 95800 78364 95772 78350 95758 70008 100542 78712 69948 + 96120 78652 69918 96060 78622 96030 70078 78782 96190 94912 113008 122044 + 94816 112952 122014 94768 112924 94744 112910 94732 94726 78192 104636 95088 + 78136 104606 95032 113054 95004 78094 94990 69820 78268 69790 95164 78238 + 95134 94560 112824 121950 94512 112796 94488 112782 94476 94470 78008 104542 + 94648 77980 94620 77966 94606 69726 78046 94686 94384 112732 94360 112718 + 94348 94342 77916 94428 77902 94414 94296 112686 94284 94278 77870 94318 + 94252 94246 68336 99708 68216 99646 68156 68126 68476 68414 127162 123258 + 115450 99834 72416 101752 116414 72304 101692 72248 101662 72220 72206 67960 + 99518 72568 67900 72508 67870 72478 68030 72638 80576 105840 118460 80480 + 105784 118430 80432 105756 80408 105742 80396 80390 72048 101564 80752 71992 + 101534 80696 71964 80668 71950 80654 67772 72124 67742 80828 72094 80798 + 114016 122552 126814 96832 113968 122524 96800 113944 122510 96784 113932 96776 + 113926 96772 80224 105656 118366 97120 80176 105628 97072 114076 105614 97048 + 80140 97036 80134 97030 71864 101470 80312 71836 97208 80284 71822 97180 + 80270 97166 67678 71902 80350 97246 96576 113840 122460 96544 113816 122446 + 96528 113804 96520 113798 96516 96514 80048 105564 96688 80024 105550 96664 + 113870 96652 80006 96646 71772 80092 71758 96732 80078 96718 96416 113752 + 122414 96400 113740 96392 113734 96388 96386 79960 105518 96472 79948 96460 + 79942 96454 71726 79982 96494 96336 113708 96328 113702 96324 96322 79916 + 96364 79910 96358 96296 113686 96292 96290 79894 96310 66936 99006 66876 + 66846 67006 68976 100028 68920 99998 68892 68878 66748 69052 66718 69022 + 73056 102072 116574 73008 102044 72984 102030 72972 72966 68792 99934 73144 + 68764 73116 68750 73102 66654 68830 73182 81216 106160 118620 81184 106136 + 118606 81168 106124 81160 106118 81156 81154 72880 101980 81328 72856 101966 + 81304 106190 81292 72838 81286 68700 72924 68686 81372 72910 81358 114336 + 122712 126894 114320 122700 114312 122694 114308 114306 81056 106072 118574 97696 + 81040 106060 97680 114380 106054 97672 81028 97668 81026 97666 72792 101934 + 81112 72780 97752 81100 72774 97740 81094 97734 68654 72814 81134 97774 + 114256 122668 114248 122662 114244 114242 80976 106028 97488 80968 106022 97480 + 114278 97476 80962 97474 72748 81004 72742 97516 80998 97510 114216 122646 + 114212 114210 80936 106006 97384 80932 97380 80930 97378 72726 80950 97398 + 114196 114194 80916 97332 80914 97330 66236 66206 67256 99166 67228 67214 + 66142 67294 69296 100188 69272 100174 69260 69254 67164 69340 67150 69326 + 73376 102232 116654 73360 102220 73352 102214 73348 73346 69208 100142 73432 + 102254 73420 69190 73414 67118 69230 73454 106320 118700 106312 118694 106308 + 106306 73296 102188 81616 106348 102182 81608 73284 81604 73282 81602 69164 + 73324 69158 81644 73318 81638 122792 126934 122788 122786 106280 118678 114536 + 106276 114532 106274 114530 73256 102166 81512 73252 98024 81508 73250 98020 + 81506 98018 69142 73270 81526 98038 122772 122770 106260 114484 106258 114482 + 73236 81460 73234 97908 81458 97906 122762 106250 114458 73226 81434 97850 + 66396 66382 67416 99246 67404 67398 66350 67438 69456 100268 69448 100262 + 69444 69442 67372 69484 67366 69478 102312 116694 102308 102306 69416 100246 + 73576 102326 73572 69410 73570 67350 69430 73590 118740 118738 102292 106420 + 102290 106418 69396 73524 69394 81780 73522 81778 118730 102282 106394 69386 + 73498 81722 66476 66470 67496 99286 67492 67490 66454 67510 100308 100306 + 67476 69556 67474 69554 116714 + ] + ] def + + % Return the 17 bits for a codeword in a given cluster + /cwtobits { + clusters exch get exch get /v exch def + [ 17 {0} repeat v 2 17 string cvrs {48 sub} forall ] + dup length 17 sub 17 getinterval + } bind def + + % Populate bitmap for the image + compact { + /rwid 17 c mul 17 add 17 add 1 add def + } { + /rwid 17 c mul 17 add 17 add 17 add 18 add def + } ifelse + /pixs rwid r mul array def + + 0 1 r 1 sub { + /i exch def + + i 3 mod 0 eq { + /lcw i 3 idiv 30 mul r 1 sub 3 idiv add def + /rcw i 3 idiv 30 mul c add 1 sub def + } if + i 3 mod 1 eq { + /lcw i 3 idiv 30 mul eclevel 3 mul add r 1 sub 3 mod add def + /rcw i 3 idiv 30 mul r 1 sub 3 idiv add def + } if + i 3 mod 2 eq { + /lcw i 3 idiv 30 mul c add 1 sub def + /rcw i 3 idiv 30 mul eclevel 3 mul add r 1 sub 3 mod add def + } if + + pixs rwid i mul [ + 1 1 1 1 1 1 1 1 0 1 0 1 0 1 0 0 0 + lcw i 3 mod cwtobits {} forall + cws c i mul c getinterval { i 3 mod cwtobits {} forall } forall + compact { + 1 + } { + rcw i 3 mod cwtobits {} forall + 1 1 1 1 1 1 1 0 1 0 0 0 1 0 1 0 0 1 + } ifelse + ] putinterval + + } for + + % Return the arguments + << + /ren //renmatrix + /pixs pixs + /pixx rwid + /pixy r + /height r 72 div rowmult mul + /width rwid 72 div + /opt options + >> + + dontdraw not //renmatrix if + + end + +} bind def +/pdf417 dup load /uk.co.terryburton.bwipp defineresource pop +end +/setpacking where {pop setpacking} if +% --END ENCODER pdf417-- + +% --BEGIN ENCODER micropdf417-- +% --DESC: MicroPDF417 +% --EXAM: MicroPDF417 +% --EXOP: +% --RNDR: renmatrix +/setpacking where {pop currentpacking true setpacking} if +1 dict +dup /renmatrix dup /uk.co.terryburton.bwipp findresource put +begin +/micropdf417 { + + 20 dict begin + + /options exch def + /barcode exch def + + /dontdraw false def + /columns 0 def + /rows 0 def + /rowmult 2 def + /cca false def + /ccb false def + /raw false def + /parse false def + + % Parse the input options + options type /stringtype eq { + 1 dict begin + options { + token false eq {exit} if dup length string cvs (=) search + true eq {cvlit exch pop exch def} {cvlit true def} ifelse + } loop + currentdict end /options exch def + } if + options {def} forall + + /columns columns cvi def + /rows rows cvi def + /rowmult rowmult cvr def + + cca {/raw true def} if + + % Parse ordinals of the form ^NNN to ASCII + parse { + /msg barcode length string def + /j 0 def + barcode + { % loop + (^) search { + dup msg exch j exch putinterval + length j add 1 add /j exch def + pop + dup 0 3 getinterval cvi msg exch j 1 sub exch put + dup length 3 sub 3 exch getinterval + } { + dup msg exch j exch putinterval + length j add /j exch def + /barcode msg 0 j getinterval def + exit + } ifelse + } loop + } if + + % Convert input into array of codewords + raw { + /datcws barcode length array def + /i 0 def /j 0 def + { % loop + i barcode length eq {exit} if + /cw barcode i 1 add 3 getinterval cvi def + datcws j cw put + /i i 4 add def + /j j 1 add def + } loop + /datcws datcws 0 j getinterval def + } { % Simple autoencoder from input to codewords using byte mode + /barlen barcode length def + barlen 6 mod 0 eq { + /datcws barlen 6 idiv 5 mul 1 add array def + datcws 0 924 put + } { + /datcws barlen 6 idiv 5 mul barlen 6 mod add 1 add array def + datcws 0 901 put + } ifelse + + % Rebase groups of 6 bytes splitting into 3 byte chunks + 0 1 barlen 6 idiv 1 sub { + /i exch def + /msbs [ barcode i 6 mul 3 getinterval {} forall ] def + /mscs [ + msbs aload pop exch 256 mul add exch 65536 mul add + 3 {dup 900 mod exch 900 idiv} repeat + ] def + /lsbs [barcode i 6 mul 3 add 3 getinterval {} forall] def + /lscs [ + lsbs aload pop exch 256 mul add exch 65536 mul add + 3 {dup 900 mod exch 900 idiv} repeat + ] def + /cws 5 array def + lscs 0 get mscs 0 get 316 mul add + cws 4 2 index 900 mod put + 900 idiv lscs 1 get add mscs 0 get 641 mul add mscs 1 get 316 mul add + cws 3 2 index 900 mod put + 900 idiv lscs 2 get add mscs 0 get 20 mul add mscs 1 get 641 mul add mscs 2 get 316 mul add + cws 2 2 index 900 mod put + 900 idiv lscs 3 get add mscs 1 get 20 mul add mscs 2 get 641 mul add + cws 1 2 index 900 mod put + 900 idiv mscs 2 get 20 mul add + cws 0 3 -1 roll 900 mod put + datcws i 5 mul 1 add cws putinterval + } for + + % Add the remaining bytes to the end of the codewords + /rem barlen 6 mod def + rem 0 ne { + datcws datcws length rem sub + [ barcode barlen rem sub rem getinterval {} forall ] + putinterval + } if + + ccb {/datcws [920 datcws aload pop] def} if + + } ifelse + + % Basic metrics for the each symbol + % c r ecw rl rc rr + /metrics [ + [ 1 11 7 1 0 9 ] + [ 1 14 7 8 0 8 ] + [ 1 17 7 36 0 36 ] + [ 1 20 8 19 0 19 ] + [ 1 24 8 9 0 17 ] + [ 1 28 8 25 0 33 ] + [ 2 8 8 1 0 1 ] + [ 2 11 9 1 0 9 ] + [ 2 14 9 8 0 8 ] + [ 2 17 10 36 0 36 ] + [ 2 20 11 19 0 19 ] + [ 2 23 13 9 0 17 ] + [ 2 26 15 27 0 35 ] + [ 3 6 12 1 1 1 ] + [ 3 8 14 7 7 7 ] + [ 3 10 16 15 15 15 ] + [ 3 12 18 25 25 25 ] + [ 3 15 21 37 37 37 ] + [ 3 20 26 1 17 33 ] + [ 3 26 32 1 9 17 ] + [ 3 32 38 21 29 37 ] + [ 3 38 44 15 31 47 ] + [ 3 44 50 1 25 49 ] + [ 4 4 8 47 19 43 ] + [ 4 6 12 1 1 1 ] + [ 4 8 14 7 7 7 ] + [ 4 10 16 15 15 15 ] + [ 4 12 18 25 25 25 ] + [ 4 15 21 37 37 37 ] + [ 4 20 26 1 17 33 ] + [ 4 26 32 1 9 17 ] + [ 4 32 38 21 29 37 ] + [ 4 38 44 15 31 47 ] + [ 4 44 50 1 25 49 ] + ] def + + % Basic metrics for the each symbol + % c r ecw rl rc rr + /ccametrics [ + [ 2 5 4 39 0 19 ] + [ 2 6 4 1 0 33 ] + [ 2 7 5 32 0 12 ] + [ 2 8 5 8 0 40 ] + [ 2 9 6 14 0 46 ] + [ 2 10 6 43 0 23 ] + [ 2 12 7 20 0 52 ] + [ 3 4 4 11 43 23 ] + [ 3 5 5 1 33 13 ] + [ 3 6 6 5 37 17 ] + [ 3 7 7 15 47 27 ] + [ 3 8 7 21 1 33 ] + [ 4 3 4 40 20 52 ] + [ 4 4 5 43 23 3 ] + [ 4 5 6 46 26 6 ] + [ 4 6 7 34 14 46 ] + [ 4 7 8 29 9 41 ] + ] def + cca {/metrics ccametrics def} if + + % Select metrics of an appropriate symbol + /urows rows def + /ucols columns def + /i 0 def + { % loop + /m metrics i get def + /c m 0 get def % Rows in symbol + /r m 1 get def % Columns in symbol + /k m 2 get def % Error correction codewords + /rapl m 3 get def % Left row address pattern + /rapc m 4 get def % Centre row address pattern + /rapr m 5 get def % Right row address pattern + /ncws r c mul k sub def % Data codewords + /okay true def + datcws length ncws gt {/okay false def} if + urows 0 ne urows r ne and {/okay false def} if + ucols 0 ne ucols c ne and {/okay false def} if + okay {exit} if + /i i 1 add def + } loop + /m datcws length def + + % Create codewords array with one extra working space element and add padding + /n c r mul k sub def + /cws c r mul 1 add array def + cws 0 datcws putinterval + cws m [ n m sub {900} repeat ] putinterval + cws n [ k {0} repeat 0 ] putinterval + + % Calculate the log and anti-log tables + /rsalog [ 1 928 {dup 3 mul 929 mod} repeat ] def + /rslog 929 array def + 1 1 928 {dup rsalog exch get exch rslog 3 1 roll put} for + + % Function to calculate the product in the field + /rsprod { + 2 copy 0 ne exch 0 ne and { + rslog exch get exch rslog exch get add 928 mod rsalog exch get + } { + pop pop 0 + } ifelse + } bind def + + % Generate the coefficients + /coeffs [ 1 k {0} repeat ] def + 1 1 k { + /i exch def + coeffs i coeffs i 1 sub get put + i 1 sub -1 1 { + /j exch def + coeffs j coeffs j 1 sub get coeffs j get rsalog i get rsprod add 929 mod put + } for + coeffs 0 coeffs 0 get rsalog i get rsprod put + } for + /coeffs coeffs 0 coeffs length 1 sub getinterval def + coeffs length 1 sub -2 0 {coeffs exch 2 copy get 929 exch sub put} for + + % Derive the error codewords + 0 1 n 1 sub { + /t exch cws exch get cws n get add 929 mod def + 0 1 k 1 sub { + /j exch def + cws n j add cws n j add 1 add get 929 t coeffs k j sub 1 sub get mul 929 mod sub add 929 mod put + } for + } for + n 1 n k add { dup cws exch 929 cws 5 -1 roll get sub 929 mod put } for + + % Trim the working space from the end of the codewords + /cws cws 0 cws length 1 sub getinterval def + + % Base 10 encoding of the bar space successions for the codewords in each cluster + /clusters [ + [ + 120256 125680 128380 120032 125560 128318 108736 119920 108640 86080 108592 86048 + 110016 120560 125820 109792 120440 125758 88256 109680 88160 89536 110320 120700 + 89312 110200 120638 89200 110140 89840 110460 89720 110398 89980 128506 119520 + 125304 128190 107712 119408 125244 107616 119352 84032 107568 119324 84000 107544 + 83984 108256 119672 125374 85184 108144 119612 85088 108088 119582 85040 108060 + 85728 108408 119742 85616 108348 85560 108318 85880 108478 85820 85790 107200 + 119152 125116 107104 119096 125086 83008 107056 119068 82976 107032 82960 82952 + 83648 107376 119228 83552 107320 119198 83504 107292 83480 83468 83824 107452 + 83768 107422 83740 83900 106848 118968 125022 82496 106800 118940 82464 106776 + 118926 82448 106764 82440 106758 82784 106936 119006 82736 106908 82712 106894 + 82700 82694 106974 82830 82240 106672 118876 82208 106648 118862 82192 106636 82184 106630 82180 82352 82328 82316 82080 118830 106572 106566 82050 117472 124280 127678 103616 117360 124220 103520 117304 124190 75840 103472 75808 104160 117624 124350 76992 104048 117564 76896 103992 76848 76824 77536 104312 117694 @@ -5808,59 +12080,2328 @@ ] ] def - % Return the 17 bits for a codeword in a given cluster - /cwtobits { - clusters exch get exch get /v exch def - [ 17 {0} repeat v 2 17 string cvrs {48 sub} forall ] - dup length 17 sub 17 getinterval + % Row address patterns + /raps [ + [ % Left and right + 802 930 946 818 882 890 826 954 922 986 970 906 778 + 794 786 914 978 982 980 916 948 932 934 942 940 936 + 808 812 814 806 822 950 918 790 788 820 884 868 870 + 878 876 872 840 856 860 862 846 844 836 838 834 866 + ] [ % Centre + 718 590 622 558 550 566 534 530 538 570 562 546 610 + 626 634 762 754 758 630 628 612 614 582 578 706 738 + 742 740 748 620 556 552 616 744 712 716 708 710 646 + 654 652 668 664 696 688 656 720 592 600 604 732 734 + ] + ] def + + % Return the 17 bits for a codeword in a given cluster + /cwtobits { + clusters exch get exch get /v exch def + [ 17 {0} repeat v 2 17 string cvrs {48 sub} forall ] + dup length 17 sub 17 getinterval + } bind def + + % Return the 10 bits for a row address pattern + /raptobits { + raps exch get exch get /v exch def + [ 10 {0} repeat v 2 10 string cvrs {48 sub} forall ] + dup length 10 sub 10 getinterval + } bind def + + % Populate bitmap for the image + /rwid [38 55 82 99] c 1 sub get def + c 3 eq cca and {/rwid 72 def} if + /pixs rwid r mul array def + + 0 1 r 1 sub { + /i exch def + /clst i rapl add 1 sub 3 mod def + pixs rwid i mul [ + c 1 eq { + i rapl add 1 sub 52 mod 0 raptobits aload pop + cws i get clst cwtobits aload pop + i rapr add 1 sub 52 mod 0 raptobits aload pop + } if + c 2 eq { + i rapl add 1 sub 52 mod 0 raptobits aload pop + cws i 2 mul get clst cwtobits aload pop + cws i 2 mul 1 add get clst cwtobits aload pop + i rapr add 1 sub 52 mod 0 raptobits aload pop + } if + c 3 eq { + cca not { + i rapl add 1 sub 52 mod 0 raptobits aload pop + } if + cws i 3 mul get clst cwtobits aload pop + i rapc add 1 sub 52 mod 1 raptobits aload pop + cws i 3 mul 1 add get clst cwtobits aload pop + cws i 3 mul 2 add get clst cwtobits aload pop + i rapr add 1 sub 52 mod 0 raptobits aload pop + } if + c 4 eq { + i rapl add 1 sub 52 mod 0 raptobits aload pop + cws i 4 mul get clst cwtobits aload pop + cws i 4 mul 1 add get clst cwtobits aload pop + i rapc add 1 sub 52 mod 1 raptobits aload pop + cws i 4 mul 2 add get clst cwtobits aload pop + cws i 4 mul 3 add get clst cwtobits aload pop + i rapr add 1 sub 52 mod 0 raptobits aload pop + } if + 1 + ] putinterval + } for + + % Return the arguments + << + /ren //renmatrix + /pixs pixs + /pixx rwid + /pixy r + /height r 72 div rowmult mul + /width rwid 72 div + /opt options + >> + + dontdraw not //renmatrix if + + end + +} bind def +/micropdf417 dup load /uk.co.terryburton.bwipp defineresource pop +end +/setpacking where {pop setpacking} if +% --END ENCODER micropdf417-- + +% --BEGIN ENCODER datamatrix-- +% --DESC: Data Matrix +% --EXAM: This is Data Matrix! +% --EXOP: rows=32 columns=32 +% --RNDR: renmatrix +/setpacking where {pop currentpacking true setpacking} if +1 dict +dup /renmatrix dup /uk.co.terryburton.bwipp findresource put +begin +/datamatrix { + + 20 dict begin + + /options exch def + /barcode exch def + + /dontdraw false def + /columns 0 def + /rows 0 def + /encoding (byte) def + /raw false def + /parse false def + + % Parse the input options + options type /stringtype eq { + 1 dict begin + options { + token false eq {exit} if dup length string cvs (=) search + true eq {cvlit exch pop exch def} {cvlit true def} ifelse + } loop + currentdict end /options exch def + } if + options {def} forall + + /columns columns cvi def + /rows rows cvi def + + % Parse ordinals of the form ^NNN to ASCII + parse { + /msg barcode length string def + /j 0 def + barcode + { % loop + (^) search { + dup msg exch j exch putinterval + length j add 1 add /j exch def + pop + dup 0 3 getinterval cvi msg exch j 1 sub exch put + dup length 3 sub 3 exch getinterval + } { + dup msg exch j exch putinterval + length j add /j exch def + /barcode msg 0 j getinterval def + exit + } ifelse + } loop + } if + + /barlen barcode length def + + raw {/encoding (raw) def} if + + encoding (raw) eq { + /cws barlen array def + /i 0 def /j 0 def + { % loop + i barlen eq {exit} if + /cw barcode i 1 add 3 getinterval cvi def + cws j cw put + /i i 4 add def + /j j 1 add def + } loop + /cws cws 0 j getinterval def + } if + + encoding (byte) eq { + barlen 250 lt { + /cws [231 barlen barcode {} forall] def + } { + /cws [231 barlen 250 idiv 249 add barlen 250 mod barcode {} forall] def + } ifelse + 1 1 cws length 1 sub { + /i exch def + i 1 add 149 mul 255 mod 1 add cws i get add + dup 256 ge {256 sub} if + cws exch i exch put + } for + } if + + encoding (ascii) eq { + /cws barlen 2 mul array def + /i 0 def /j 0 def + { % loop + i barlen eq {exit} if + /char barcode i get def + char 48 ge char 57 le and i barlen 1 sub lt and { + barcode i 1 add get dup 48 ge exch 57 le and { % Digit pair + cws j barcode i 2 getinterval cvi 130 add put + /i i 2 add def + /j j 1 add def + } { % Singular digit + cws j char 1 add put + /i i 1 add def + /j j 1 add def + } ifelse + } { char 127 le { % ASCII + cws j char 1 add put + /i i 1 add def + /j j 1 add def + } { % Extended ASCII + cws j 235 put + cws j 1 add char 127 sub put + /i i 1 add def + /j j 2 add def + } ifelse } ifelse + } loop + /cws cws 0 j getinterval def + } if + + encoding (edifact) eq { + /cws 1558 array def + /i 0 def /j 1 def /k 0 def + cws 0 240 put + { % loop + i barlen gt {exit} if + /k 0 def /v 0 def + { % loop until triplet is full or beyond end of data + k 4 eq i barlen gt or {exit} if + /cval (unset) def + i barlen lt { + /char barcode i get def + char 32 ge char 94 le and { + /cval char 63 and def + } if + } { % Unlatch at end of data + /cval 31 def + } ifelse + /v v cval 3 k sub 6 mul bitshift or def + /k k 1 add def + /i i 1 add def + } loop + cws j [ v -16 bitshift v -8 bitshift 255 and v 255 and ] putinterval + /j j 3 add def + } loop + /cws cws 0 j getinterval def + } if + + encoding (c40) eq encoding (text) eq or encoding (x12) eq or { + + /s1 0 def /s2 1 def /s3 2 def /us 30 def + + encoding (c40) eq { + /latch 230 def + /charmap [ + 0 1 31 { [ exch s1 exch ] } for % 0-31 + [ 3 ] % 32 + 0 1 14 { [ exch s2 exch ] } for % 33-47 + 4 1 13 { [ exch ] } for % 48-57 + 15 1 21 { [ exch s2 exch ] } for % 58-64 + 14 1 39 { [ exch ] } for % 65-90 + 22 1 26 { [ exch s2 exch ] } for % 91-95 + [ s3 0 ] % 96 + 1 1 26 { [ exch s3 exch ] } for % 97-122 + 27 1 31 { [ exch s3 exch ] } for % 123-127 + 0 1 31 { [ s2 us 4 -1 roll s1 exch ] } for % 128-159 + [ s2 us 3 ] % 160 + 0 1 14 { [ s2 us 4 -1 roll s2 exch ] } for % 161-175 + 4 1 13 { [ s2 us 4 -1 roll ] } for % 176-185 + 15 1 21 { [ s2 us 4 -1 roll s2 exch ] } for % 186-192 + 14 1 39 { [ s2 us 4 -1 roll ] } for % 193-218 + 22 1 26 { [ s2 us 4 -1 roll s2 exch ] } for % 219-223 + [ s2 us s3 0 ] % 224 + 1 1 26 { [ s2 us 4 -1 roll s3 exch ] } for % 225-250 + 27 1 31 { [ s2 us 4 -1 roll s3 exch ] } for % 251-255 + ] def + } if + + encoding (text) eq { + /latch 239 def + /charmap [ + 0 1 31 { [ exch s1 exch ] } for % 0-31 + [ 3 ] % 32 + 0 1 14 { [ exch s2 exch ] } for % 33-47 + 4 1 13 { [ exch ] } for % 48-57 + 15 1 21 { [ exch s2 exch ] } for % 58-64 + 1 1 26 { [ exch s3 exch ] } for % 65-90 + 22 1 26 { [ exch s2 exch ] } for % 91-95 + [ s3 0 ] % 96 + 14 1 39 { [ exch ] } for % 97-122 + 27 1 31 { [ exch s3 exch ] } for % 123-127 + 0 1 31 { [ s2 us 4 -1 roll s1 exch ] } for % 128-159 + [ s2 us 3 ] % 160 + 0 1 14 { [ s2 us 4 -1 roll s2 exch ] } for % 161-175 + 4 1 13 { [ s2 us 4 -1 roll ] } for % 176-185 + 15 1 21 { [ s2 us 4 -1 roll s2 exch ] } for % 186-192 + 1 1 26 { [ s2 us 4 -1 roll s3 exch ] } for % 193-218 + 22 1 26 { [ s2 us 4 -1 roll s2 exch ] } for % 219-223 + [ s2 us s3 0 ] % 224 + 14 1 39 { [ s2 us 4 -1 roll ] } for % 225-250 + 27 1 31 { [ s2 us 4 -1 roll s3 exch ] } for % 251-255 + ] def + } if + + encoding (x12) eq { + /latch 238 def + /charmap [ + 13 { [ () ] } repeat % 0-12 + [ 0 ] % 13 + 18 { [ () ] } repeat % 14-31 + [ 3 ] % 32 + 9 { [ () ] } repeat % 33-41 + [ 1 ] % 42 + 5 { [ () ] } repeat % 43-47 + 4 1 13 { [ exch ] } for % 48-57 + 4 { [ () ] } repeat % 58-61 + [ 2 ] % 62 + 2 { [ () ] } repeat % 63-64 + 14 1 39 { [ exch ] } for % 65-90 + 165 { [ () ] } repeat % 91-255 + ] def + } if + + % Derive the encoded character stream + /encstr barlen 4 mul array def + /j 0 def + 0 1 barlen 1 sub { + barcode exch get charmap exch get + dup encstr exch j exch putinterval + length j add /j exch def + } for + /encstr encstr 0 j getinterval def + /enclen j def + + % Compress triples into doubles + /cws 1558 array def + /i 0 def /j 1 def /k 0 def + cws 0 latch put + { % loop + i enclen ge {exit} if + /k 0 def /v 1 def + { % loop until triple is full or end of data + k 3 eq i enclen ge or {exit} if + /v v encstr i get 40 2 k sub exp cvi mul add def + /k k 1 add def + /i i 1 add def + } loop + cws j [ v -8 bitshift v 255 and ] putinterval + /j j 2 add def + } loop + cws j 254 put + /cws cws 0 j 1 add getinterval def + + } if + + % Basic metrics for the each symbol + % rows cols regh regv rscw rsbl + /metrics [ + % Standard square symbols + [ 10 10 1 1 5 1 ] + [ 12 12 1 1 7 1 ] + [ 14 14 1 1 10 1 ] + [ 16 16 1 1 12 1 ] + [ 18 18 1 1 14 1 ] + [ 20 20 1 1 18 1 ] + [ 22 22 1 1 20 1 ] + [ 24 24 1 1 24 1 ] + [ 26 26 1 1 28 1 ] + [ 32 32 2 2 36 1 ] + [ 36 36 2 2 42 1 ] + [ 40 40 2 2 48 1 ] + [ 44 44 2 2 56 1 ] + [ 48 48 2 2 68 1 ] + [ 52 52 2 2 84 2 ] + [ 64 64 4 4 112 2 ] + [ 72 72 4 4 144 4 ] + [ 80 80 4 4 192 4 ] + [ 88 88 4 4 224 4 ] + [ 96 96 4 4 272 4 ] + [ 104 104 4 4 336 6 ] + [ 120 120 6 6 408 6 ] + [ 132 132 6 6 496 8 ] + [ 144 144 6 6 620 10 ] + % Optional rectangular symbols + [ 8 18 1 1 7 1 ] + [ 8 32 1 2 11 1 ] + [ 12 26 1 1 14 1 ] + [ 12 36 1 2 18 1 ] + [ 16 36 1 2 24 1 ] + [ 16 48 1 2 28 1 ] + ] def + + % Select metrics of an appropriate symbol + /urows rows def + /ucols columns def + /i 0 def + { % loop + /m metrics i get def + /rows m 0 get def % Rows in symbol + /cols m 1 get def % Columns in symbol + /regh m 2 get def % Horizontal regions + /regv m 3 get def % Vertical regions + /rscw m 4 get def % Error correction codewords + /rsbl m 5 get def % Error correction blocks + /mrows rows 2 regh mul sub def % Rows in the mapping matrix + /mcols cols 2 regv mul sub def % Columns in the mapping matrix + /rrows mrows regh idiv def % Rows per region + /rcols mcols regv idiv def % Columns per region + /ncws mrows mcols mul 8 idiv rscw sub def % Data codewords + /okay true def + cws length ncws gt {/okay false def} if + urows 0 ne urows rows ne and {/okay false def} if + ucols 0 ne ucols cols ne and {/okay false def} if + okay {exit} if + /i i 1 add def + } loop + + % Extend cws to ncws codewords by addition of pseudo-randomised pad characters + cws length ncws lt { + /datlen cws length def + /cws [ cws {} forall ncws datlen sub {129} repeat ] def + datlen 1 add 1 ncws 1 sub { + /i exch def + i 1 add 149 mul 253 mod 1 add 129 add + dup 254 gt {254 sub} if + cws exch i exch put + } for + } if + + % De-interleave the codewords into blocks + /cwbs rsbl array def % Array of data codeword blocks + /ecbs rsbl array def % Array of error correction blocks + 0 1 rsbl 1 sub { + /i exch def + cws length 1558 ne { + /cwbsize cws length rsbl idiv def + } { + i 7 le {/cwbsize 156 def} {/cwbsize 155 def} ifelse + } ifelse + /cwb cwbsize array def + 0 1 cwbsize 1 sub { + /j exch def + cwb j cws j rsbl mul i add get put + } for + cwbs i cwb put + ecbs i [ rscw rsbl idiv {0} repeat ] put + } for + + % Calculate the log and anti-log tables + /rsalog [ 1 255 { dup 2 mul dup 256 ge {301 xor} if } repeat ] def + /rslog 256 array def + 1 1 255 {dup rsalog exch get exch rslog 3 1 roll put} for + + % Function to calculate the product in the field + /rsprod { + 2 copy 0 ne exch 0 ne and { + rslog exch get exch rslog exch get add 255 mod rsalog exch get + } { + pop pop 0 + } ifelse + } bind def + + % Generate the coefficients + /coeffs [ 1 rscw rsbl idiv {0} repeat ] def + 1 1 rscw rsbl idiv { + /i exch def + coeffs i coeffs i 1 sub get put + i 1 sub -1 1 { + /j exch def + coeffs j coeffs j 1 sub get coeffs j get rsalog i get rsprod xor put + } for + coeffs 0 coeffs 0 get rsalog i get rsprod put + } for + /coeffs coeffs 0 coeffs length 1 sub getinterval def + + % Calculate the error correction codewords for each block + 0 1 cwbs length 1 sub { + /i exch def + /cwb cwbs i get def + /ecb ecbs i get def + 0 1 cwb length 1 sub { + /t exch cwb exch get ecb 0 get xor def + ecb length 1 sub -1 0 { + /j exch def + /p ecb length j sub 1 sub def + ecb p t coeffs j get rsprod put + j 0 gt { ecb p ecb p 1 add get ecb p get xor put } if + } for + } for + } for + + % Strange fixup for 144x144 symbols + ncws 1558 eq { + /ecbs [ ecbs 8 2 getinterval {} forall ecbs 0 8 getinterval {} forall ] def + } if + + % Extend codewords with the interleaved error correction codes + /cws [ cws {} forall rscw {0} repeat ] def + 0 1 rscw 1 sub { + /i exch def + cws ncws i add ecbs i rsbl mod get i rsbl idiv get put + } for + + % Place the codewords into the matrix + /module { + % cw row col shape + 4 -1 roll + (00000000) 8 string copy dup 3 -1 roll 2 8 string cvrs + dup length 8 exch sub exch putinterval + 7 -1 0 {1 index exch get 48 sub exch} for pop + 11 -3 roll + % 1 2 4 8 16 32 64 128 row col shape + { % Place each bit of the codeword in the shape, MSB first + exec + 1 index 0 lt { + exch mrows add exch + 4 mrows 4 add 8 mod sub add + } if + dup 0 lt { + mcols add exch + 4 mcols 4 add 8 mod sub add exch + } if + exch mcols mul add + mmat exch 5 -1 roll put + } forall + } bind def + + % Placement patterns + /dmn [ + { 2 copy 2 sub exch 2 sub exch } bind { 2 copy 1 sub exch 2 sub exch } bind + { 2 copy 2 sub exch 1 sub exch } bind { 2 copy 1 sub exch 1 sub exch } bind + { 2 copy exch 1 sub exch } bind { 2 copy 2 sub } bind + { 2 copy 1 sub } bind { 2 copy } bind + ] def + + /dmc1 [ + { mrows 1 sub 0 } bind { mrows 1 sub 1 } bind + { mrows 1 sub 2 } bind { 0 mcols 2 sub } bind + { 0 mcols 1 sub } bind { 1 mcols 1 sub } bind + { 2 mcols 1 sub } bind { 3 mcols 1 sub } bind + ] def + + /dmc2 [ + { mrows 3 sub 0 } bind { mrows 2 sub 0 } bind + { mrows 1 sub 0 } bind { 0 mcols 4 sub } bind + { 0 mcols 3 sub } bind { 0 mcols 2 sub } bind + { 0 mcols 1 sub } bind { 1 mcols 1 sub } bind + ] def + + /dmc3 [ + { mrows 3 sub 0 } bind { mrows 2 sub 0 } bind + { mrows 1 sub 0 } bind { 0 mcols 2 sub } bind + { 0 mcols 1 sub } bind { 1 mcols 1 sub } bind + { 2 mcols 1 sub } bind { 3 mcols 1 sub } bind + ] def + + /dmc4 [ + { mrows 1 sub 0 } bind { mrows 1 sub mcols 1 sub } bind + { 0 mcols 3 sub } bind { 0 mcols 2 sub } bind + { 0 mcols 1 sub } bind { 1 mcols 3 sub } bind + { 1 mcols 2 sub } bind { 1 mcols 1 sub } bind + ] def + + /mmat [ mrows mcols mul {-1} repeat ] def + cws length 1 sub -1 0 {cws exch get} for % Reverse cws onto stack + 4 0 % Starting row and column + { % loop + 2 copy 0 eq exch mrows eq and { + dmc1 module + } if + 2 copy 0 eq exch mrows 2 sub eq and mcols 4 mod 0 ne and { + dmc2 module + } if + 2 copy 0 eq exch mrows 2 sub eq and mcols 8 mod 4 eq and { + dmc3 module + } if + 2 copy 2 eq exch mrows 4 add eq and mcols 8 mod 0 eq and { + dmc4 module + } if + + { % loop for sweeping upwards + 2 copy 0 ge exch mrows lt and { + 2 copy exch mcols mul add mmat exch get -1 eq { + dmn module + } if + } if + 2 add exch 2 sub exch + 2 copy mcols lt exch 0 ge and not {exit} if + } loop + 3 add exch 1 add exch + + { % loop for sweeping downwards + 2 copy mcols lt exch 0 ge and { + 2 copy exch mcols mul add mmat exch get -1 eq { + dmn module + } if + } if + 2 sub exch 2 add exch + 2 copy 0 ge exch mrows lt and not {exit} if + } loop + 1 add exch 3 add exch + + 2 copy mcols lt exch mrows lt or not {pop pop exit} if + + } loop + + % Set checker pattern if required + mmat mrows mcols mul 1 sub get -1 eq { + mmat mrows mcols 1 sub mul 2 sub [1 0] putinterval + mmat mrows mcols mul 2 sub [0 1] putinterval + } if + + % Place the modules onto a pixel map between alignment patterns + /pixs rows cols mul array def + /cwpos 0 def + 0 1 rows 1 sub { + /i exch def + i rrows 2 add mod 0 eq { pixs i cols mul [ cols 2 idiv {1 0} repeat ] putinterval } if + i rrows 2 add mod rrows 1 add eq { pixs i cols mul [ cols {1} repeat ] putinterval } if + i rrows 2 add mod 0 ne i rrows 2 add mod rrows 1 add ne and { + 0 1 cols 1 sub { + /j exch def + j rcols 2 add mod 0 eq { pixs i cols mul j add 1 put } if + j rcols 2 add mod rcols 1 add eq { pixs i cols mul j add i 2 mod put } if + j rcols 2 add mod 0 ne j rcols 2 add mod rcols 1 add ne and { + pixs i cols mul j add mmat cwpos get put + /cwpos cwpos 1 add def + } if + } for + } if + } for + + % Return the arguments + << + /ren //renmatrix + /pixs pixs + /pixx cols + /pixy rows + /height rows 72 div 1.5 mul + /width cols 72 div 1.5 mul + /opt options + >> + + dontdraw not //renmatrix if + + end + +} bind def +/datamatrix dup load /uk.co.terryburton.bwipp defineresource pop +end +/setpacking where {pop setpacking} if +% --END ENCODER datamatrix-- + +% --BEGIN ENCODER qrcode-- +% --DESC: QR Code +% --EXAM: http://www.terryburton.co.uk/barcodewriter/ +% --EXOP: eclevel=M +% --RNDR: renmatrix +/setpacking where {pop currentpacking true setpacking} if +1 dict +dup /renmatrix dup /uk.co.terryburton.bwipp findresource put +begin +/qrcode { + + 20 dict begin + + /options exch def + /barcode exch def + + /dontdraw false def + /format (full) def % full or micro + /version (unset) def + /eclevel (unset) def % L, M, Q or H + /raw false def + /parse false def + + % Parse the input options + options type /stringtype eq { + 1 dict begin + options { + token false eq {exit} if dup length string cvs (=) search + true eq {cvlit exch pop exch def} {cvlit true def} ifelse + } loop + currentdict end /options exch def + } if + options {def} forall + + % Parse ordinals of the form ^NNN to ASCII + parse { + /msg barcode length string def + /j 0 def + barcode + { % loop + (^) search { + dup msg exch j exch putinterval + length j add 1 add /j exch def + pop + dup 0 3 getinterval cvi msg exch j 1 sub exch put + dup length 3 sub 3 exch getinterval + } { + dup msg exch j exch putinterval + length j add /j exch def + /barcode msg 0 j getinterval def + exit + } ifelse + } loop + } if + + % Force raw mode for micro format symbols + format (micro) eq {/raw true def} if + + % Default to error correction level M + eclevel (unset) eq {/eclevel (M) def} if + + % Convert from input into message bitstream + raw { + /msgbits barcode def + } { % Simple autoencoder from input to bitstream using byte mode only for full format symbols + + /barlen barcode length def + eclevel (unset) eq {/eclevel (M) def} if + + % Determine smallest symbol version to hold given amount of byte-encoded data + version (unset) eq { + /caps [ + [ + 17 32 53 78 106 134 154 192 230 271 % 1-L - 10-L + 321 367 425 458 520 586 644 718 792 858 % 11-L - 20-L + 929 1003 1091 1171 1273 1367 1465 1528 1628 1732 % 21-L - 30-L + 1840 1952 2068 2188 2303 2431 2563 2699 2809 2953 % 31-L - 40-L + ] [ + 14 26 42 62 84 106 122 152 180 213 % 1-M - 10-M + 251 287 331 362 412 450 504 560 624 666 % 11-M - 20-M + 711 779 857 911 997 1059 1125 1190 1264 1370 % 21-M - 30-M + 1452 1538 1628 1722 1809 1911 1989 2099 2213 2331 % 31-M - 40-M + ] [ + 11 20 32 46 60 74 86 108 130 151 % 1-Q - 10-Q + 177 203 241 258 292 322 364 394 442 482 % 11-Q - 20-Q + 509 565 611 661 715 751 805 868 908 982 % 21-Q - 30-Q + 1030 1112 1168 1228 1283 1351 1423 1499 1579 1663 % 31-Q - 40-Q + ] [ + 7 14 24 34 44 58 64 84 98 119 % 1-H - 10-H + 137 155 177 194 220 250 280 310 338 382 % 11-H - 20-H + 403 439 461 511 535 593 625 658 698 742 % 21-H - 30-H + 790 842 898 958 983 1051 1093 1139 1219 1273 % 31-H - 40-H + ] + ] def + /caps caps (LMQH) eclevel search pop length exch pop exch pop get def + /i 1 def + { + barlen caps i 1 sub get le {exit} if + /i i 1 add def + } loop + /version i 10 2 string cvrs def + } if + + % Set the control character data for the version + /mid (0100) def /term (0000) def /cclen 8 def + version 0 1 getinterval (M) ne { % Version 10 and above + version cvi 10 ge {/cclen 16 def} if + } if + /midlen mid length def + /termlen term length def + + % Create the bitstream as byte_mode_id character_count data_bytes term + /msgbits midlen cclen add barlen 8 mul add termlen add string def + msgbits 0 mid putinterval + (0000000000000000) 0 cclen getinterval cclen string copy + dup barlen cvi 2 cclen string cvrs dup length cclen exch sub exch putinterval + /cc exch def + msgbits midlen cc putinterval + 0 1 barlen 1 sub { + /i exch def + (00000000) 8 string copy dup barcode i get cvi 2 8 string cvrs dup length 8 exch sub exch putinterval + msgbits midlen cclen add i 8 mul add 3 -1 roll putinterval + } for + msgbits midlen cclen add barlen 8 mul add term putinterval + + } ifelse + + % Lookup the most appropriate symbol specification + /metrics [ + % format vers size align modules error codewords error correction blocks + % L M Q H L1 L2 M1 M2 Q1 Q2 H1 H2 + [ (micro) (M1) 11 98 99 36 [ 2 99 99 99 ] [ 1 0 -1 -1 -1 -1 -1 -1 ] ] + [ (micro) (M2) 13 98 99 80 [ 5 6 99 99 ] [ 1 0 1 0 -1 -1 -1 -1 ] ] + [ (micro) (M3) 15 98 99 132 [ 6 8 99 99 ] [ 1 0 1 0 -1 -1 -1 -1 ] ] + [ (micro) (M4) 17 98 99 192 [ 8 10 14 99 ] [ 1 0 1 0 1 0 -1 -1 ] ] + [ (full) (1) 21 98 99 208 [ 7 10 13 17 ] [ 1 0 1 0 1 0 1 0 ] ] + [ (full) (2) 25 18 99 359 [ 10 16 22 28 ] [ 1 0 1 0 1 0 1 0 ] ] + [ (full) (3) 29 22 99 567 [ 15 26 36 44 ] [ 1 0 1 0 2 0 2 0 ] ] + [ (full) (4) 33 26 99 807 [ 20 36 52 64 ] [ 1 0 2 0 2 0 4 0 ] ] + [ (full) (5) 37 30 99 1079 [ 26 48 72 88 ] [ 1 0 2 0 2 2 2 2 ] ] + [ (full) (6) 41 34 99 1383 [ 36 64 96 112 ] [ 2 0 4 0 4 0 4 0 ] ] + [ (full) (7) 45 22 38 1568 [ 40 72 108 130 ] [ 2 0 4 0 2 4 4 1 ] ] + [ (full) (8) 49 24 42 1936 [ 48 88 132 156 ] [ 2 0 2 2 4 2 4 2 ] ] + [ (full) (9) 53 26 46 2336 [ 60 110 160 192 ] [ 2 0 3 2 4 4 4 4 ] ] + [ (full) (10) 57 28 50 2768 [ 72 130 192 224 ] [ 2 2 4 1 6 2 6 2 ] ] + [ (full) (11) 61 30 54 3232 [ 80 150 224 264 ] [ 4 0 1 4 4 4 3 8 ] ] + [ (full) (12) 65 32 58 3728 [ 96 176 260 308 ] [ 2 2 6 2 4 6 7 4 ] ] + [ (full) (13) 69 34 62 4256 [ 104 198 288 352 ] [ 4 0 8 1 8 4 12 4 ] ] + [ (full) (14) 73 26 46 4651 [ 120 216 320 384 ] [ 3 1 4 5 11 5 11 5 ] ] + [ (full) (15) 77 26 48 5243 [ 132 240 360 432 ] [ 5 1 5 5 5 7 11 7 ] ] + [ (full) (16) 81 26 50 5867 [ 144 280 408 480 ] [ 5 1 7 3 15 2 3 13 ] ] + [ (full) (17) 85 30 54 6523 [ 168 308 448 532 ] [ 1 5 10 1 1 15 2 17 ] ] + [ (full) (18) 89 30 56 7211 [ 180 338 504 588 ] [ 5 1 9 4 17 1 2 19 ] ] + [ (full) (19) 93 30 58 7931 [ 196 364 546 650 ] [ 3 4 3 11 17 4 9 16 ] ] + [ (full) (20) 97 34 62 8683 [ 224 416 600 700 ] [ 3 5 3 13 15 5 15 10 ] ] + [ (full) (21) 101 28 50 9252 [ 224 442 644 750 ] [ 4 4 17 0 17 6 19 6 ] ] + [ (full) (22) 105 26 50 10068 [ 252 476 690 816 ] [ 2 7 17 0 7 16 34 0 ] ] + [ (full) (23) 109 30 54 10916 [ 270 504 750 900 ] [ 4 5 4 14 11 14 16 14 ] ] + [ (full) (24) 113 28 54 11796 [ 300 560 810 960 ] [ 6 4 6 14 11 16 30 2 ] ] + [ (full) (25) 117 32 58 12708 [ 312 588 870 1050 ] [ 8 4 8 13 7 22 22 13 ] ] + [ (full) (26) 121 30 58 13652 [ 336 644 952 1110 ] [ 10 2 19 4 28 6 33 4 ] ] + [ (full) (27) 125 34 62 14628 [ 360 700 1020 1200 ] [ 8 4 22 3 8 26 12 28 ] ] + [ (full) (28) 129 26 50 15371 [ 390 728 1050 1260 ] [ 3 10 3 23 4 31 11 31 ] ] + [ (full) (29) 133 30 54 16411 [ 420 784 1140 1350 ] [ 7 7 21 7 1 37 19 26 ] ] + [ (full) (30) 137 26 52 17483 [ 450 812 1200 1440 ] [ 5 10 19 10 15 25 23 25 ] ] + [ (full) (31) 141 30 56 18587 [ 480 868 1290 1530 ] [ 13 3 2 29 42 1 23 28 ] ] + [ (full) (32) 145 34 60 19723 [ 510 924 1350 1620 ] [ 17 0 10 23 10 35 19 35 ] ] + [ (full) (33) 149 30 58 20891 [ 540 980 1440 1710 ] [ 17 1 14 21 29 19 11 46 ] ] + [ (full) (34) 153 34 62 22091 [ 570 1036 1530 1800 ] [ 13 6 14 23 44 7 59 1 ] ] + [ (full) (35) 157 30 54 23008 [ 570 1064 1590 1890 ] [ 12 7 12 26 39 14 22 41 ] ] + [ (full) (36) 161 24 50 24272 [ 600 1120 1680 1980 ] [ 6 14 6 34 46 10 2 64 ] ] + [ (full) (37) 165 28 54 25568 [ 630 1204 1770 2100 ] [ 17 4 29 14 49 10 24 46 ] ] + [ (full) (38) 169 32 58 26896 [ 660 1260 1860 2220 ] [ 4 18 13 32 48 14 42 32 ] ] + [ (full) (39) 173 26 54 28256 [ 720 1316 1950 2310 ] [ 20 4 40 7 43 22 10 67 ] ] + [ (full) (40) 177 30 58 29648 [ 750 1372 2040 2430 ] [ 19 6 18 31 34 34 20 61 ] ] + ] def + /eclval (LMQH) eclevel search pop length exch pop exch pop def + /i 0 def + { % loop + /m metrics i get def + /frmt m 0 get def % Format of the symbol + /vers m 1 get def % Version of symbol + /size m 2 get def % Length of side + /asp2 m 3 get def % Position of second alignment symbol + /asp3 m 4 get def % Position of third alignment symbol + /nmod m 5 get def % Number of modules + /ncws nmod 8 idiv def % Total number of codewords + /rbit nmod 8 mod def % Number of remainder bits + /lc4b false def % Last data codeword is 4 bits long + size 11 eq size 15 eq or { % Adjustments for M1 and M3 symbols + /ncws ncws 1 add def + /rbit 0 def + /lc4b true def + } if + /ecws m 6 get eclval get def % Number of error correction codewords + /dcws ncws ecws sub def % Number of data codewords + /dmod dcws 8 mul lc4b {4} {0} ifelse sub def % Number of data modules + /ecb1 m 7 get eclval 2 mul get def % First error correction blocks + /ecb2 m 7 get eclval 2 mul 1 add get def % Second error correction blocks + /okay true def + format frmt ne {/okay false def} if % The format must match that supplied + version (unset) ne version vers ne and {/okay false def} if % The version must match that supplied + msgbits length dmod gt {/okay false def} if % Bitstream must fit into data modules + ecb1 -1 eq ecb2 -1 eq or {/okay false def} if % Error correction level must be valid + okay {exit} if + /i i 1 add def + } loop + /format frmt def + /version vers def + /dcpb dcws ecb1 ecb2 add idiv def % Base data codewords per block + /ecpb ncws ecb1 ecb2 add idiv dcpb sub def % Error correction codewords per block + + % Expand the message bits by adding padding as necessary + /pad dmod string def + 0 4 dmod 1 sub {pad exch (0000) putinterval} for + pad 0 msgbits putinterval + /padstrs [ (11101100) (00010001) ] def + /padnum 0 def + msgbits length 8 div ceiling 8 mul cvi 8 dmod lc4b {5} {1} ifelse sub { + pad exch padstrs padnum get putinterval + /padnum padnum 1 add 2 mod def + } for + + % Evaluate the padded message into codewords + /cws dcws array def + 0 1 cws length 1 sub { + /c exch def + /bpcw 8 def + lc4b c cws length 1 sub eq and {/bpcw 4 def} if + /cwb pad c 8 mul bpcw getinterval def + /cw 0 def + 0 1 bpcw 1 sub { + /i exch def + /cw cw 2 bpcw i sub 1 sub exp cvi cwb i get 48 sub mul add def + } for + cws c cw put + } for + + % Calculate the log and anti-log tables + /rsalog [ 1 255 { dup 2 mul dup 256 ge {285 xor} if } repeat ] def + /rslog 256 array def + 1 1 255 {dup rsalog exch get exch rslog 3 1 roll put} for + + % Function to calculate the product in the field + /rsprod { + 2 copy 0 ne exch 0 ne and { + rslog exch get exch rslog exch get add 255 mod rsalog exch get + } { + pop pop 0 + } ifelse + } bind def + + % Generate the coefficients for the Reed-Solomon algorithm + /coeffs [ 1 ecpb {0} repeat ] def + 0 1 ecpb 1 sub { + /i exch def + coeffs i 1 add coeffs i get put + i -1 1 { + /j exch def + coeffs j coeffs j 1 sub get coeffs j get rsalog i get rsprod xor put + } for + coeffs 0 coeffs 0 get rsalog i get rsprod put + } for + /coeffs coeffs 0 coeffs length 1 sub getinterval def + + % Reed-Solomon algorithm to derive the error correction codewords + /rscodes { + /rscws exch def + /rsnd rscws length def + /rscws [ rscws {} forall ecpb {0} repeat ] def + 0 1 rsnd 1 sub { + /m exch def + /k rscws m get def + 0 1 ecpb 1 sub { + /j exch def + rscws m j add 1 add coeffs ecpb j sub 1 sub get k rsprod rscws m j add 1 add get xor put + } for + } for + rscws rsnd ecpb getinterval + } bind def + + % Divide codewords into two groups of blocks and calculate the error correction codewords + /dcwsb ecb1 ecb2 add array def + /ecwsb ecb1 ecb2 add array def + 0 1 ecb1 1 sub { % First group of blocks has smaller number of data codewords + /i exch def + dcwsb i cws i dcpb mul dcpb getinterval put + ecwsb i dcwsb i get rscodes put + } for + 0 1 ecb2 1 sub { % Second group of blocks has larger number of data codewords + /i exch def + dcwsb ecb1 i add cws ecb1 dcpb mul i dcpb 1 add mul add dcpb 1 add getinterval put + ecwsb ecb1 i add dcwsb ecb1 i add get rscodes put + } for + + % Reassemble the codewords + /cws ncws array def + /cw 0 def + 0 1 dcpb { % Interleave the data codeword blocks + /i exch def + 0 1 ecb1 ecb2 add 1 sub { + /j exch def + i dcwsb j get length lt { % Ignore the end of short blocks + cws cw dcwsb j get i get put + /cw cw 1 add def + } if + } for + } for + 0 1 ecpb 1 sub { % Interleave the error codeword blocks + /i exch def + 0 1 ecb1 ecb2 add 1 sub { + /j exch def + cws cw ecwsb j get i get put + /cw cw 1 add def + } for + } for + + % Extend codewords by one if there are remainder bits + rbit 0 gt { + /pad cws length 1 add array def + pad 0 cws putinterval + pad pad length 1 sub 0 put + /cws pad def + } if + + % Fixups for the short final data byte in M1 and M3 symbols + lc4b { + dcws 1 sub 1 ncws 2 sub { + /i exch def + cws i cws i get 15 and 4 bitshift put + cws i cws i 1 add get -4 bitshift 15 and cws i get or put + } for + cws ncws 1 sub cws ncws 1 sub get 15 and 4 bitshift put + } if + + % Create the bitmap + /pixs [ size size mul {-1} repeat ] def + /qmv {size mul add} bind def + + % Finder patterns + /fpat [ + [ 1 1 1 1 1 1 1 0 ] + [ 1 0 0 0 0 0 1 0 ] + [ 1 0 1 1 1 0 1 0 ] + [ 1 0 1 1 1 0 1 0 ] + [ 1 0 1 1 1 0 1 0 ] + [ 1 0 0 0 0 0 1 0 ] + [ 1 1 1 1 1 1 1 0 ] + [ 0 0 0 0 0 0 0 0 ] + ] def + 0 1 fpat length 1 sub { + /y exch def + 0 1 fpat 0 get length 1 sub { + /x exch def + /fpb fpat y get x get def + pixs x y qmv fpb put + format (full) eq { + pixs size x sub 1 sub y qmv fpb put + pixs x size y sub 1 sub qmv fpb put + } if + } for + } for + + % Alignment patterns + /algnpat [ + [ 1 1 1 1 1 ] + [ 1 0 0 0 1 ] + [ 1 0 1 0 1 ] + [ 1 0 0 0 1 ] + [ 1 1 1 1 1 ] + ] def + /putalgnpat { + /py exch def + /px exch def + 0 1 4 { + /pb exch def + 0 1 4 { + /pa exch def + pixs px pa add py pb add qmv algnpat pb get pa get put + } for + } for + } bind def + asp2 2 sub asp3 asp2 sub size 13 sub { + /i exch def + i 4 putalgnpat + 4 i putalgnpat + } for + asp2 2 sub asp3 asp2 sub size 9 sub { + /x exch def + asp2 2 sub asp3 asp2 sub size 9 sub { + /y exch def + x y putalgnpat + } for + } for + + % Timing patterns + format (full) eq { + 8 1 size 9 sub { + /i exch def + pixs i 6 qmv i 1 add 2 mod put + pixs 6 i qmv i 1 add 2 mod put + } for + } { + 8 1 size 1 sub { + /i exch def + pixs i 0 qmv i 1 add 2 mod put + pixs 0 i qmv i 1 add 2 mod put + } for + } ifelse + + % Format information modules + format (full) eq { + /formatmap [ + [ [ 0 8 ] [ 8 size 1 sub ] ] [ [ 1 8 ] [ 8 size 2 sub ] ] [ [ 2 8 ] [ 8 size 3 sub ] ] + [ [ 3 8 ] [ 8 size 4 sub ] ] [ [ 4 8 ] [ 8 size 5 sub ] ] [ [ 5 8 ] [ 8 size 6 sub ] ] + [ [ 7 8 ] [ 8 size 7 sub ] ] [ [ 8 8 ] [ size 8 sub 8 ] ] [ [ 8 7 ] [ size 7 sub 8 ] ] + [ [ 8 5 ] [ size 6 sub 8 ] ] [ [ 8 4 ] [ size 5 sub 8 ] ] [ [ 8 3 ] [ size 4 sub 8 ] ] + [ [ 8 2 ] [ size 3 sub 8 ] ] [ [ 8 1 ] [ size 2 sub 8 ] ] [ [ 8 0 ] [ size 1 sub 8 ] ] + ] def + } { + /formatmap [ + [ [ 1 8 ] ] [ [ 2 8 ] ] [ [ 3 8 ] ] [ [ 4 8 ] ] [ [ 5 8 ] ] + [ [ 6 8 ] ] [ [ 7 8 ] ] [ [ 8 8 ] ] [ [ 8 7 ] ] [ [ 8 6 ] ] + [ [ 8 5 ] ] [ [ 8 4 ] ] [ [ 8 3 ] ] [ [ 8 2 ] ] [ [ 8 1 ] ] + ] def + } ifelse + formatmap { + { {} forall qmv pixs exch 0 put } forall + } forall + + % Version information modules + size 45 ge { + /versionmap [ + [ [ size 9 sub 5 ] [ 5 size 9 sub ] ] [ [ size 10 sub 5 ] [ 5 size 10 sub ] ] + [ [ size 11 sub 5 ] [ 5 size 11 sub ] ] [ [ size 9 sub 4 ] [ 4 size 9 sub ] ] + [ [ size 10 sub 4 ] [ 4 size 10 sub ] ] [ [ size 11 sub 4 ] [ 4 size 11 sub ] ] + [ [ size 9 sub 3 ] [ 3 size 9 sub ] ] [ [ size 10 sub 3 ] [ 3 size 10 sub ] ] + [ [ size 11 sub 3 ] [ 3 size 11 sub ] ] [ [ size 9 sub 2 ] [ 2 size 9 sub ] ] + [ [ size 10 sub 2 ] [ 2 size 10 sub ] ] [ [ size 11 sub 2 ] [ 2 size 11 sub ] ] + [ [ size 9 sub 1 ] [ 1 size 9 sub ] ] [ [ size 10 sub 1 ] [ 1 size 10 sub ] ] + [ [ size 11 sub 1 ] [ 1 size 11 sub ] ] [ [ size 9 sub 0 ] [ 0 size 9 sub ] ] + [ [ size 10 sub 0 ] [ 0 size 10 sub ] ] [ [ size 11 sub 0 ] [ 0 size 11 sub ] ] + ] def + } { + /versionmap [] def + } ifelse + versionmap { + { {} forall qmv pixs exch 0 put } forall + } forall + + % Solitary dark module in full symbols + format (full) eq { + pixs 8 size 8 sub qmv 1 put + } if + + % Calculate the mask patterns + format (full) eq { + /maskfuncs [ + {add 2 mod} bind + {exch pop 2 mod} bind + {pop 3 mod} bind + {add 3 mod} bind + {2 idiv exch 3 idiv add 2 mod} bind + {mul dup 2 mod exch 3 mod add} bind + {mul dup 2 mod exch 3 mod add 2 mod} bind + {2 copy mul 3 mod 3 1 roll add 2 mod add 2 mod} bind + ] def + } { + /maskfuncs [ + {exch pop 2 mod} bind + {2 idiv exch 3 idiv add 2 mod} bind + {mul dup 2 mod exch 3 mod add 2 mod} bind + {2 copy mul 3 mod 3 1 roll add 2 mod add 2 mod} bind + ] def + } ifelse + /masks maskfuncs length array def + 0 1 masks length 1 sub { + /m exch def + /mask size size mul array def + 0 1 size 1 sub { + /j exch def + 0 1 size 1 sub { + /i exch def + i j maskfuncs m get exec 0 eq + pixs i j qmv get -1 eq and {1} {0} ifelse + mask i j qmv 3 -1 roll put + } for + } for + masks m mask put + } for + + % Walk the symbol placing the bitstream + /posx size 1 sub def + /posy size 1 sub def + /dir -1 def % -1 is upwards, 1 is downwards + /col 1 def % 0 is left bit, 1 is right bit + /num 0 def + { % loop + posx 0 lt {exit} if + pixs posx posy qmv get -1 eq { + cws num 8 idiv get 7 num 8 mod sub neg bitshift 1 and + pixs posx posy qmv 3 -1 roll put + /num num 1 add def + } if + col 1 eq { + /col 0 def + /posx posx 1 sub def + } { + /col 1 def + /posx posx 1 add def + /posy posy dir add def + posy 0 lt posy size ge or { % Turn around at top and bottom + /dir dir -1 mul def + /posy posy dir add def + /posx posx 2 sub def + % Hop over the timing pattern in full size symbols + format (full) eq posx 6 eq and {/posx posx 1 sub def} if + } if + } ifelse + } loop + + % Evaluate runlength encoded rows or columns in full symbols + /evalfulln1n3 { + /scrle exch def + % Detect runs of 5 or more like modules + /scr1 0 scrle { dup 5 ge {add 2 sub dup} if pop } forall def + % Detect 1:1:3:1:1 ratio next to 4 modules of whitespace + /scr3 0 def + 3 2 scrle length 3 sub { % Scan odd (dark) runs within bounds + /j exch def + scrle j get 3 mod 0 eq { % Multiple of 3 black modules + /fact scrle j get 3 idiv def + scrle j 2 sub 5 getinterval {fact eq} forall and exch pop and and { + j 3 eq j 4 add scrle length ge or { % At either extent of run + /scr3 scr3 40 add def + } { % Bounded by dark modules + scrle j 3 sub get 4 ge scrle j 3 add get 4 ge or { + /scr3 scr3 40 add def + } if + } ifelse + } if + } if + } for + scr1 scr3 + } bind def + + % Evaluation algorithm for full symbols + /evalfull { + /sym exch def + + /n1 0 def /n2 0 def /n3 0 def + /rle size 1 add array def + /lastpairs size array def + /thispairs size array def + /sizeadd1 size 1 add def + 0 1 size 1 sub { + /i exch def + + % Runlength encode (light, dark, light, ...) and evaluate each column + mark 0 0 + i size dup dup mul 1 sub { + sym exch get exch 1 index eq {exch 1 add exch} {1 exch} ifelse + } for + pop + rle 0 counttomark 2 sub getinterval astore + evalfulln1n3 n3 add /n3 exch def n1 add /n1 exch def + pop + + % Runlength encode (light, dark, light, ...) and evaluate each row + /symrow sym i size mul size getinterval def + mark 0 0 + symrow { + exch 1 index eq {exch 1 add exch} {1 exch} ifelse + } forall + pop + rle 0 counttomark 2 sub getinterval astore + evalfulln1n3 n3 add /n3 exch def n1 add /n1 exch def + pop + + % Count and score same coloured blocks + /lastpairs thispairs /thispairs lastpairs def def + symrow 0 get 1 eq {0} {1} ifelse + symrow {exch 1 index add exch} forall + pop + thispairs astore pop + i 0 gt { + mark + lastpairs aload pop thispairs aload pop + n2 size { exch sizeadd1 index add 3 and 0 eq {3 add} if } repeat + /n2 exch def + cleartomark + } if + + } for + + % Score dark/light imbalance + /dark 0 sym {add} forall def + /n4 dark 100 mul size dup mul div 50 sub abs 5 div cvi 10 mul def + + n1 n2 add n3 add n4 add + } bind def + + % Evaluation algorithm for micro symbols + /evalmicro { + /sym exch def + /dkrhs 0 def /dkbot 0 def + 1 1 size 1 sub { + /i exch def + /dkrhs dkrhs sym size 1 sub i qmv get add def + /dkbot dkbot sym i size 1 sub qmv get add def + } for + dkrhs dkbot le { + dkrhs 16 mul dkbot add neg + } { + dkbot 16 mul dkrhs add neg + } ifelse + } bind def + + % Evaluate the masked symbols to find the most suitable + /bestscore 999999999 def + 0 1 masks length 1 sub { + /m exch def + /masksym size size mul array def + 0 1 size size mul 1 sub { + /i exch def + masksym i pixs i get masks m get i get xor put + } for + format (full) eq { + masksym evalfull /score exch def + } { + masksym evalmicro /score exch def + } ifelse + score bestscore lt { + /bestsym masksym def + /bestmaskval m def + /bestscore score def + } if + } for + /pixs bestsym def + + % Add the format information + format (full) eq { + /fmtvals [ + 16#5412 16#5125 16#5e7c 16#5b4b 16#45f9 16#40ce 16#4f97 16#4aa0 + 16#77c4 16#72f3 16#7daa 16#789d 16#662f 16#6318 16#6c41 16#6976 + 16#1689 16#13be 16#1ce7 16#19d0 16#0762 16#0255 16#0d0c 16#083b + 16#355f 16#3068 16#3f31 16#3a06 16#24b4 16#2183 16#2eda 16#2bed + ] def + /ecid (MLHQ) eclevel search pop length exch pop exch pop def + /fmtval fmtvals ecid 3 bitshift bestmaskval add get def + } { + /fmtvals [ + 16#4445 16#4172 16#4e2b 16#4b1c 16#55ae 16#5099 16#5fc0 16#5af7 + 16#6793 16#62a4 16#6dfd 16#68ca 16#7678 16#734f 16#7c16 16#7921 + 16#06de 16#03e9 16#0cb0 16#0987 16#1735 16#1202 16#1d5b 16#186c + 16#2508 16#203f 16#2f66 16#2a51 16#34e3 16#31d4 16#3e8d 16#3bba + ] def + /symid [ [0] [1 2] [3 4] [5 6 7] ] size 11 sub 2 idiv get eclval get def + /fmtval fmtvals symid 2 bitshift bestmaskval add get def + } ifelse + 0 1 formatmap length 1 sub { + /i exch def + formatmap i get { + pixs exch {} forall qmv fmtval 14 i sub neg bitshift 1 and put + } forall + } for + + % Add the version information + size 45 ge { + /vervals [ + 16#07c94 16#085bc 16#09a99 16#0a4d3 16#0bbf6 16#0c762 16#0d847 + 16#0e60d 16#0f928 16#10b78 16#1145d 16#12a17 16#13532 16#149a6 + 16#15683 16#168c9 16#177ec 16#18ec4 16#191e1 16#1afab 16#1b08e + 16#1cc1a 16#1d33f 16#1ed75 16#1f250 16#209d5 16#216fd 16#228ba + 16#2379f 16#24b0b 16#2542e 16#26a64 16#27541 16#28c69 + ] def + /verval vervals size 17 sub 4 idiv 7 sub get def + 0 1 versionmap length 1 sub { + /i exch def + versionmap i get { + pixs exch {} forall qmv verval 17 i sub neg bitshift 1 and put + } forall + } for + } if + + % Return the arguments + << + /ren //renmatrix + /pixs pixs + /pixx size + /pixy size + /height size 2 mul 72 div + /width size 2 mul 72 div + /opt options + >> + + dontdraw not //renmatrix if + + end + +} bind def +/qrcode dup load /uk.co.terryburton.bwipp defineresource pop +end +/setpacking where {pop setpacking} if +% --END ENCODER qrcode-- + +% --BEGIN ENCODER maxicode-- +% --DESC: MaxiCode +% --EXAM: [\)>^03001^02996152382802^029840^029001^0291Z00004951^029UPSN^02906X610^029159^0291234567^0291/1^029^029Y^029634 ALPHA DR^029PITTSBURGH^029PA^029^004 +% --EXOP: mode=2 parse +% --RNDR: renmaximatrix +/setpacking where {pop currentpacking true setpacking} if +1 dict +dup /renmaximatrix dup /uk.co.terryburton.bwipp findresource put +begin +/maxicode { + + 20 dict begin + + /options exch def % We are given an option string + /barcode exch def % We are given a barcode string + + /dontdraw false def + /mode -1 def + /sam -1 def + /parse false def + + % Parse the input options + options type /stringtype eq { + 1 dict begin + options { + token false eq {exit} if dup length string cvs (=) search + true eq {cvlit exch pop exch def} {cvlit true def} ifelse + } loop + currentdict end /options exch def + } if + options {def} forall + + /mode mode cvi def + /sam sam cvi def + + % Parse ordinals of the form ^NNN to ASCII + parse { + /msg barcode length string def + /j 0 def + barcode + { % loop + (^) search { + dup msg exch j exch putinterval + length j add 1 add /j exch def + pop + dup 0 3 getinterval cvi msg exch j 1 sub exch put + dup length 3 sub 3 exch getinterval + } { + dup msg exch j exch putinterval + length j add /j exch def + /barcode msg 0 j getinterval def + exit + } ifelse + } loop + } if + + /msg barcode def + /msglen msg length def + + % Special message handling for modes 2 and 3 + mode 2 eq mode 3 eq or { + + % Normalise messages that begin with a field identifier [)>RS01GSyy + msg 0 7 getinterval <5b293e1e30311d> eq { + /fid msg 0 9 getinterval def + /msg msg 9 msglen 9 sub getinterval def + } { + /fid () def + } ifelse + + % Read the postcode, country code and service code fields seperated by GS + msg <1d> search pop /pcode exch def + pop <1d> search pop /ccode exch def + pop <1d> search pop /scode exch def + pop /msg exch def + + % Prepend the field identifier + msg length fid length add string dup + 0 fid putinterval dup + fid length msg putinterval + /msg exch def + /msglen msg length def + + } if + + % Special function characters + /eci -1 def /pad -2 def /ns -3 def + /la -4 def /lb -5 def + /sa -6 def /sb -7 def /sc -8 def /sd -9 def /se -10 def + /sa2 -11 def /sa3 -12 def + /lkc -13 def /lkd -14 def /lke -15 def + /pd2 -16 def /pd3 -17 def + + % Character maps for each state + /charmaps [ + % A B C D E + [ 13 (`) 192 224 0 ] % 0 + [ (A) (a) 193 225 1 ] % 1 + [ (B) (b) 194 226 2 ] % 2 + [ (C) (c) 195 227 3 ] % 3 + [ (D) (d) 196 228 4 ] % 4 + [ (E) (e) 197 229 5 ] % 5 + [ (F) (f) 198 230 6 ] % 6 + [ (G) (g) 199 231 7 ] % 7 + [ (H) (h) 200 232 8 ] % 8 + [ (I) (i) 201 233 9 ] % 9 + [ (J) (j) 202 234 10 ] % 10 + [ (K) (k) 203 235 11 ] % 11 + [ (L) (l) 204 236 12 ] % 12 + [ (M) (m) 205 237 13 ] % 13 + [ (N) (n) 206 238 14 ] % 14 + [ (O) (o) 207 239 15 ] % 15 + [ (P) (p) 208 240 16 ] % 16 + [ (Q) (q) 209 241 17 ] % 17 + [ (R) (r) 210 242 18 ] % 18 + [ (S) (s) 211 243 19 ] % 19 + [ (T) (t) 212 244 20 ] % 20 + [ (U) (u) 213 245 21 ] % 21 + [ (V) (v) 214 246 22 ] % 22 + [ (W) (w) 215 247 23 ] % 23 + [ (X) (x) 216 248 24 ] % 24 + [ (Y) (y) 217 249 25 ] % 25 + [ (Z) (z) 218 250 26 ] % 26 + [ eci eci eci eci eci ] % 27 + [ 28 28 28 28 pad ] % 28 + [ 29 29 29 29 pad ] % 29 + [ 30 30 30 30 27 ] % 30 + [ ns ns ns ns ns ] % 31 + [ ( ) ({) 219 251 28 ] % 32 + [ pad pad 220 252 29 ] % 33 + [ (") (}) 221 253 30 ] % 34 + [ (#) (~) 222 254 31 ] % 35 + [ ($) 127 223 255 159 ] % 36 + [ (%) (;) 170 161 160 ] % 37 + [ (&) (<) 172 168 162 ] % 38 + [ (') (=) 177 171 163 ] % 39 + [ 40 (>) 178 175 164 ] % 40 + [ 41 (?) 179 176 165 ] % 41 + [ (*) ([) 181 180 166 ] % 42 + [ (+) 92 185 183 167 ] % 43 + [ (,) (]) 186 184 169 ] % 44 + [ (-) (^) 188 187 173 ] % 45 + [ (.) (_) 189 191 174 ] % 46 + [ (/) ( ) 190 138 182 ] % 47 + [ (0) (,) 128 139 149 ] % 48 + [ (1) (.) 129 140 150 ] % 49 + [ (2) (/) 130 141 151 ] % 50 + [ (3) (:) 131 142 152 ] % 51 + [ (4) (@) 132 143 153 ] % 52 + [ (5) (!) 133 144 154 ] % 53 + [ (6) (|) 134 145 155 ] % 54 + [ (7) pd2 135 146 156 ] % 55 + [ (8) sa2 136 147 157 ] % 56 + [ (9) sa3 137 148 158 ] % 57 + [ (:) pd3 la la la ] % 58 + [ sb sa ( ) ( ) ( ) ] % 59 + [ sc sc lkc sc sc ] % 60 + [ sd sd sd lkd sd ] % 61 + [ se se se se lke ] % 62 + [ lb la lb lb lb ] % 63 + ] def + + % Invert charmaps to give character to value maps for each state + /charvals [ 64 dict 64 dict 64 dict 64 dict 64 dict ] def + 0 1 charmaps length 1 sub { + /i exch def + /encs charmaps i get def + 0 1 4 { + /j exch def + encs j get dup type /stringtype eq {0 get} if % convert string to ASCII if required + charvals j get exch i put + } for + } for + /seta charvals 0 get def + /setb charvals 1 get def + /setc charvals 2 get def + /setd charvals 3 get def + /sete charvals 4 get def + + % Compute numeric runlengths + /nseq [ msglen 1 add {0} repeat ] def + msglen 1 sub -1 0 { + /i exch def + msg i get dup 48 ge exch 57 le and { + nseq i nseq i 1 add get 1 add put + } { + nseq i 0 put + } ifelse + } for + /nseq nseq 0 msglen getinterval def + + % Encode the message from ASCII to codewords + /prefixinset { + 0 { + 2 copy exch length ge {exit} if + 2 copy get 3 index exch known {1 add} {exit} ifelse + } loop + exch pop exch pop + } bind def + + /enc { + exch get out exch j exch put + /j j 1 add def + } bind def + + /out 144 array def + /i 0 def /j 0 def /cset (seta) def + { % loop + % Exit when no characters remain latching back to A if necessary + i msglen eq { + cset (seta) ne cset (setb) ne and { + la cset load enc + /cset (seta) def + } if + exit + } if + { % not a loop but common exit point + + % If 9 numerals available then use NS + nseq i get 9 ge { + msg i 9 getinterval cvi 4 { dup 63 and exch -6 bitshift } repeat cset load ns get + 0 2 10 {index} for 6 array astore 7 1 roll 6 {pop} repeat + out exch j exch putinterval + /i i 9 add def + /j j 6 add def + exit + } if + + % Read next three characters + /char1 msg i get def + /char2 i 1 add msglen lt {msg i 1 add get} {-99} ifelse def + /char3 i 2 add msglen lt {msg i 2 add get} {-99} ifelse def + + % If current mode is sufficient then directly encode + cset load char1 known { + char1 cset load enc + /i i 1 add def + exit + } if + + % For switching from A to B + cset (seta) eq setb char1 known and { + setb char2 known { + lb seta enc + /cset (setb) def + } { + sb seta enc + char1 setb enc + /i i 1 add def + } ifelse + exit + } if + + % For switching from B to A encode according to length of prefix + cset (setb) eq seta char1 known and { + /p seta msg i 4 msglen i sub 2 copy gt {exch} if pop getinterval prefixinset def + p 1 eq { + sa setb enc + char1 seta enc + /i i 1 add def + } if + p 2 eq { + sa2 setb enc + char1 seta enc + char2 seta enc + /i i 2 add def + } if + p 3 eq { + sa3 setb enc + char1 seta enc + char2 seta enc + char3 seta enc + /i i 3 add def + } if + p 4 ge { + la setb enc + /cset (seta) def + } if + exit + } if + + % If character is in A or B then directly latch + seta char1 known { + la cset load enc + /cset (seta) def + exit + } if + setb char1 known { + lb cset load enc + /cset (setb) def + exit + } if + + % Determine which one of sets C, D or E the character is in + setc char1 known {/setx (setc) def /sx sc def /lkx lkc def} if + setd char1 known {/setx (setd) def /sx sd def /lkx lkd def} if + sete char1 known {/setx (sete) def /sx se def /lkx lke def} if + + % Encode according to the length of the prefix + /p setx load msg i 4 msglen i sub 2 copy gt {exch} if pop getinterval prefixinset def + p 1 eq { + sx cset load enc + char1 setx load enc + /i i 1 add def + } if + p 2 eq { + sx cset load enc + char1 setx load enc + sx cset load enc + char2 setx load enc + /i i 2 add def + } if + p 3 eq { + sx cset load enc + char1 setx load enc + sx cset load enc + char2 setx load enc + sx cset load enc + char3 setx load enc + /i i 3 add def + } if + p 4 ge { + sx cset load enc + lkx setx load enc + /cset setx def + } if + + exit + } loop % out + } loop + /encmsg out 0 j getinterval def + /padval cset load pad get def + + % Prefix the encoded message with the structured append insert + /sami [] def + sam -1 ne { + /sami 2 array def + sami 0 seta pad get put + sami 1 sam 10 idiv 1 sub 8 mul sam 10 mod 1 sub add put + } if + /encmsg [ sami aload pop encmsg aload pop ] def + + % Derive the primary and secondary codewords for modes 2 and 3 + mode 2 eq mode 3 eq or { + + % Calculate the fixed-width binary values for the mode, postcode, country code and service + /mdb (0000) 4 string copy dup mode cvi 2 4 string cvrs dup length 4 exch sub exch putinterval def + /ccb (0000000000) 10 string copy dup ccode cvi 2 10 string cvrs dup length 10 exch sub exch putinterval def + /scb (0000000000) 10 string copy dup scode cvi 2 10 string cvrs dup length 10 exch sub exch putinterval def + /pcb (000000000000000000000000000000000000) 36 string copy def + mode 2 eq { + % For numeric postcode, first six bits represent length and remaining 30 bits the value + pcb pcode length 2 6 string cvrs dup length 6 exch sub exch putinterval + pcb pcode cvi 2 30 string cvrs dup length 36 exch sub exch putinterval + } { % mode=3 + % For alphanumeric postcode, trim or pad with spaces to 6 chars and encode to binary + /pccw [ + ( ) 6 string copy dup 0 pcode length 6 gt {pcode 0 6 getinterval} {pcode} ifelse putinterval + {seta exch get} forall + ] def + 0 1 5 { + /i exch def + pcb pccw i get 2 6 string cvrs dup length 6 i mul 6 add exch sub exch putinterval + } for + } ifelse + + % Convolute the binary values into the structured carrier message + /scm 60 string def + scm 2 mdb putinterval + scm 38 pcb 0 4 getinterval putinterval + scm 30 pcb 4 6 getinterval putinterval + scm 24 pcb 10 6 getinterval putinterval + scm 18 pcb 16 6 getinterval putinterval + scm 12 pcb 22 6 getinterval putinterval + scm 6 pcb 28 6 getinterval putinterval + scm 0 pcb 34 2 getinterval putinterval + scm 52 ccb 0 2 getinterval putinterval + scm 42 ccb 2 6 getinterval putinterval + scm 36 ccb 8 2 getinterval putinterval + scm 54 scb 0 6 getinterval putinterval + scm 48 scb 6 4 getinterval putinterval + + % Evaluate the structured carrier message as codewords + /pri [ 0 0 0 0 0 0 0 0 0 0 ] def + 0 1 59 { + /i exch def + /ps i 6 idiv def + /ep 2 5 i 6 mod sub exp cvi scm i get 48 sub mul def + pri ps pri ps get ep add put + } for + + % Pad the encoded message into the secondary component + /sec [ 84 {padval} repeat ] def + sec 0 encmsg putinterval + + } if + + % Derive the primary and secondary codewords for modes 4, 5 and 6 + mode 4 eq mode 5 eq or mode 6 eq or mode -1 eq or { + + % If mode isn't specified then use EEC if message fits, otherwise SEC + mode -1 eq { + /mode encmsg length 77 le {5} {4} ifelse def + } if + + % First symbol is the mode and the remainder are the padded message + /cws [ mode 5 eq {78} {94} ifelse {padval} repeat ] def + cws 0 mode put + cws 1 encmsg putinterval + + % Fit the message into the primary and secondary components + /pri cws 0 10 getinterval def + /sec cws 10 cws length 10 sub getinterval def + + } if + + % Calculate the log and anti-log tables + /rsalog [ 1 63 { dup 2 mul dup 64 ge {67 xor} if } repeat ] def + /rslog 64 array def + 1 1 63 {dup rsalog exch get exch rslog 3 1 roll put} for + + % Function to calculate the product in the field + /rsprod { + 2 copy 0 ne exch 0 ne and { + rslog exch get exch rslog exch get add 63 mod rsalog exch get + } { + pop pop 0 + } ifelse + } bind def + + % Generate error correction codewords + /rscodes { + + /rsnum exch def + /cwb exch def + + % Generate the coefficients + /coeffs [ 1 rsnum {0} repeat ] def + 1 1 rsnum { + /i exch def + coeffs i coeffs i 1 sub get put + i 1 sub -1 1 { + /j exch def + coeffs j coeffs j 1 sub get coeffs j get rsalog i get rsprod xor put + } for + coeffs 0 coeffs 0 get rsalog i get rsprod put + } for + /coeffs coeffs 0 coeffs length 1 sub getinterval def + + % Calculate the error correction codewords + /ecb [ rsnum {0} repeat ] def + 0 1 cwb length 1 sub { + /t exch cwb exch get ecb 0 get xor def + ecb length 1 sub -1 0 { + /i exch def + /p ecb length i sub 1 sub def + ecb p t coeffs i get rsprod put + i 0 gt { ecb p ecb p 1 add get ecb p get xor put } if + } for + } for + + ecb + + } bind def + + % Split secondary codeword into odd and even elements + /seco [ 0 2 sec length 1 sub { sec exch get } for ] def + /sece [ 1 2 sec length 1 sub { sec exch get } for ] def + + % Calculate the parity codewords for secondary codeword parts based on mode + /scodes sec length 84 eq {20} {28} ifelse def % SEC/EEC mode + /secochk seco scodes rscodes def + /secechk sece scodes rscodes def + + % Recompose the secondary parity codewords + /secchk [ 0 1 scodes 1 sub { dup secochk exch get exch secechk exch get } for ] def + + % Concatinate the data into final codewords + /codewords [ + pri aload pop + pri 10 rscodes aload pop + sec aload pop + secchk aload pop + ] def + + % Convert the codewords into module bits + /mods [ 864 {0} repeat ] def + 0 1 143 { + /i exch def + /cw [ codewords i get 2 6 string cvrs {48 sub} forall ] def + mods 6 i mul 6 cw length sub add cw putinterval + } for + + % Maps modules to pixels in the grid + /modmap [ + 469 529 286 316 347 346 673 672 703 702 647 676 283 282 313 312 370 610 618 379 + 378 409 408 439 705 704 559 589 588 619 458 518 640 701 675 674 285 284 315 314 + 310 340 531 289 288 319 349 348 456 486 517 516 471 470 369 368 399 398 429 428 + 549 548 579 578 609 608 649 648 679 678 709 708 639 638 669 668 699 698 279 278 + 309 308 339 338 381 380 411 410 441 440 561 560 591 590 621 620 547 546 577 576 + 607 606 367 366 397 396 427 426 291 290 321 320 351 350 651 650 681 680 711 710 + 1 0 31 30 61 60 3 2 33 32 63 62 5 4 35 34 65 64 7 6 + 37 36 67 66 9 8 39 38 69 68 11 10 41 40 71 70 13 12 43 42 + 73 72 15 14 45 44 75 74 17 16 47 46 77 76 19 18 49 48 79 78 + 21 20 51 50 81 80 23 22 53 52 83 82 25 24 55 54 85 84 27 26 + 57 56 87 86 117 116 147 146 177 176 115 114 145 144 175 174 113 112 143 142 + 173 172 111 110 141 140 171 170 109 108 139 138 169 168 107 106 137 136 167 166 + 105 104 135 134 165 164 103 102 133 132 163 162 101 100 131 130 161 160 99 98 + 129 128 159 158 97 96 127 126 157 156 95 94 125 124 155 154 93 92 123 122 + 153 152 91 90 121 120 151 150 181 180 211 210 241 240 183 182 213 212 243 242 + 185 184 215 214 245 244 187 186 217 216 247 246 189 188 219 218 249 248 191 190 + 221 220 251 250 193 192 223 222 253 252 195 194 225 224 255 254 197 196 227 226 + 257 256 199 198 229 228 259 258 201 200 231 230 261 260 203 202 233 232 263 262 + 205 204 235 234 265 264 207 206 237 236 267 266 297 296 327 326 357 356 295 294 + 325 324 355 354 293 292 323 322 353 352 277 276 307 306 337 336 275 274 305 304 + 335 334 273 272 303 302 333 332 271 270 301 300 331 330 361 360 391 390 421 420 + 363 362 393 392 423 422 365 364 395 394 425 424 383 382 413 412 443 442 385 384 + 415 414 445 444 387 386 417 416 447 446 477 476 507 506 537 536 475 474 505 504 + 535 534 473 472 503 502 533 532 455 454 485 484 515 514 453 452 483 482 513 512 + 451 450 481 480 511 510 541 540 571 570 601 600 543 542 573 572 603 602 545 544 + 575 574 605 604 563 562 593 592 623 622 565 564 595 594 625 624 567 566 597 596 + 627 626 657 656 687 686 717 716 655 654 685 684 715 714 653 652 683 682 713 712 + 637 636 667 666 697 696 635 634 665 664 695 694 633 632 663 662 693 692 631 630 + 661 660 691 690 721 720 751 750 781 780 723 722 753 752 783 782 725 724 755 754 + 785 784 727 726 757 756 787 786 729 728 759 758 789 788 731 730 761 760 791 790 + 733 732 763 762 793 792 735 734 765 764 795 794 737 736 767 766 797 796 739 738 + 769 768 799 798 741 740 771 770 801 800 743 742 773 772 803 802 745 744 775 774 + 805 804 747 746 777 776 807 806 837 836 867 866 897 896 835 834 865 864 895 894 + 833 832 863 862 893 892 831 830 861 860 891 890 829 828 859 858 889 888 827 826 + 857 856 887 886 825 824 855 854 885 884 823 822 853 852 883 882 821 820 851 850 + 881 880 819 818 849 848 879 878 817 816 847 846 877 876 815 814 845 844 875 874 + 813 812 843 842 873 872 811 810 841 840 871 870 901 900 931 930 961 960 903 902 + 933 932 963 962 905 904 935 934 965 964 907 906 937 936 967 966 909 908 939 938 + 969 968 911 910 941 940 971 970 913 912 943 942 973 972 915 914 945 944 975 974 + 917 916 947 946 977 976 919 918 949 948 979 978 921 920 951 950 981 980 923 922 + 953 952 983 982 925 924 955 954 985 984 927 926 957 956 987 986 58 89 88 118 + 149 148 178 209 208 238 269 268 298 329 328 358 389 388 418 449 448 478 509 508 + 538 569 568 598 629 628 658 689 688 718 749 748 778 809 808 838 869 868 898 929 + 928 958 989 988 + ] def + + % Lookup pixels for enabled modules from modmap + /pixs 864 array def + /j 0 def + 0 1 mods length 1 sub { + /i exch def + mods i get 1 eq { + pixs j modmap i get put + /j j 1 add def + } if + } for + /pixs [ pixs 0 j getinterval {} forall 28 29 280 281 311 457 488 500 530 670 700 677 707 ] def + + % Return the arguments + << + /ren //renmaximatrix + /pixs pixs + /opt options + >> + + dontdraw not //renmaximatrix if + + end + +} bind def +/maxicode dup load /uk.co.terryburton.bwipp defineresource pop +end +/setpacking where {pop setpacking} if +% --END ENCODER maxicode-- + +% --BEGIN ENCODER azteccode-- +% --DESC: Aztec Code +% --EXAM: This is Aztec Code +% --EXOP: format=full +% --RNDR: renmatrix +/setpacking where {pop currentpacking true setpacking} if +1 dict +dup /renmatrix dup /uk.co.terryburton.bwipp findresource put +begin +/azteccode { + + 20 dict begin + + /options exch def + /barcode exch def + + /dontdraw false def + /format (unset) def % full, compact or rune + /readerinit false def + /layers -1 def + /eclevel 23 def + /ecaddchars 3 def + /raw false def + /parse false def + + % Parse the input options + options type /stringtype eq { + 1 dict begin + options { + token false eq {exit} if dup length string cvs (=) search + true eq {cvlit exch pop exch def} {cvlit true def} ifelse + } loop + currentdict end /options exch def + } if + options {def} forall + + /layers layers cvi def + /eclevel eclevel cvr def + /ecaddchars ecaddchars cvi def + + % Parse ordinals of the form ^NNN to ASCII + parse { + /msg barcode length string def + /j 0 def + barcode + { % loop + (^) search { + dup msg exch j exch putinterval + length j add 1 add /j exch def + pop + dup 0 3 getinterval cvi msg exch j 1 sub exch put + dup length 3 sub 3 exch getinterval + } { + dup msg exch j exch putinterval + length j add /j exch def + /barcode msg 0 j getinterval def + exit + } ifelse + } loop + } if + + % Convert from input into message bitstream + /msgbits () def + format (rune) ne raw and {/msgbits barcode def} if + format (rune) ne raw not and { % Simple autoencoder from input to bitstream using byte mode only + + % Determine the character count + /barlen barcode length def + barlen 31 le { + (00000) 5 string copy dup barlen 2 5 string cvrs + dup length 5 exch sub exch putinterval + /cc exch def + } { + (0000000000000000) 16 string copy dup barlen 31 sub 2 16 string cvrs + dup length 16 exch sub exch putinterval + /cc exch def + } ifelse + /cclen cc length def + + % Create the bitstream as byte_mode_id character_count data_bytes + /msgbits 5 cclen add barlen 8 mul add string def + msgbits 0 (11111) putinterval + msgbits 5 cc putinterval + 0 1 barlen 1 sub { + /i exch def + (00000000) 8 string copy dup barcode i get cvi 2 8 string cvrs dup length 8 exch sub exch putinterval + msgbits 5 cclen add i 8 mul add 3 -1 roll putinterval + } for + + } if + + % Lookup the most appropriate symbol specification + /metrics [ + [ (rune) 0 0 0 6 ] % Special metric for rune symbols + [ (compact) 1 1 17 6 ] [ (full) 1 1 21 6 ] [ (compact) 2 0 40 6 ] + [ (full) 2 1 48 6 ] [ (compact) 3 0 51 8 ] [ (full) 3 1 60 8 ] + [ (compact) 4 0 76 8 ] [ (full) 4 1 88 8 ] [ (full) 5 1 120 8 ] + [ (full) 6 1 156 8 ] [ (full) 7 1 196 8 ] [ (full) 8 1 240 8 ] + [ (full) 9 1 230 10 ] [ (full) 10 1 272 10 ] [ (full) 11 1 316 10 ] + [ (full) 12 1 364 10 ] [ (full) 13 1 416 10 ] [ (full) 14 1 470 10 ] + [ (full) 15 1 528 10 ] [ (full) 16 1 588 10 ] [ (full) 17 1 652 10 ] + [ (full) 18 1 720 10 ] [ (full) 19 1 790 10 ] [ (full) 20 1 864 10 ] + [ (full) 21 1 940 10 ] [ (full) 22 1 1020 10 ] [ (full) 23 0 920 12 ] + [ (full) 24 0 992 12 ] [ (full) 25 0 1066 12 ] [ (full) 26 0 1144 12 ] + [ (full) 27 0 1224 12 ] [ (full) 28 0 1306 12 ] [ (full) 29 0 1392 12 ] + [ (full) 30 0 1480 12 ] [ (full) 31 0 1570 12 ] [ (full) 32 0 1664 12 ] + ] def + + /i 0 def + { % loop + /m metrics i get def + /frmt m 0 get def % Format of the symbol + /mlyr m 1 get def % Data layers + /icap m 2 get def % Reader initialisation capable + /ncws m 3 get def % Total of codewords + /bpcw m 4 get def % Bits per codeword + /numecw ncws eclevel mul 100 div ecaddchars add ceiling cvi def + msgbits length 0 eq {/numecw 0 def} if % Error correction codewords + /numdcw ncws numecw sub def % Data codewords + /okay true def + format (unset) ne format frmt ne and {/okay false def} if + readerinit icap 1 ne and {/okay false def} if + layers -1 ne layers mlyr ne and {/okay false def} if + msgbits length bpcw div ceiling cvi numdcw gt {/okay false def} if + okay {exit} if + /i i 1 add def + } loop + /layers mlyr def + /format frmt def + + % Expand message bits into codewords avoiding codewords with all zeros or all ones + /allzero {dup length (000000000000) 0 3 -1 roll getinterval eq} bind def + /allones {dup length (111111111111) 0 3 -1 roll getinterval eq} bind def + /cws ncws array def + /m 0 def /c 0 def + { + msgbits length m le {exit} if + msgbits length m sub bpcw ge { + /cwb msgbits m bpcw 1 sub getinterval def % All but last bit + /cwf msgbits m bpcw add 1 sub 1 getinterval def % Last bit + cwb allzero {/cwf (1) def /m m 1 sub def} if % Flip last bit to avoid zeros + cwb allones {/cwf (0) def /m m 1 sub def} if % Flip last bit to avoid ones + % Concatinate the bits + 12 string dup 0 cwb putinterval + dup bpcw 1 sub cwf putinterval + 0 bpcw getinterval + /cwb exch def + } { % Final codeword + /cwb msgbits m msgbits length m sub getinterval def + /cwb (111111111111) 12 string copy dup 0 cwb putinterval 0 bpcw getinterval def + cwb allones {cwb cwb length 1 sub (0) putinterval} if % Prevent all ones + } ifelse + % Conversion of binary data into byte array + /cw 0 def + 0 1 bpcw 1 sub { + /i exch def + /cw cw 2 bpcw i sub 1 sub exp cvi cwb i get 48 sub mul add def + } for + cws c cw put + /m m bpcw add def + /c c 1 add def + } loop + /cws cws 0 c getinterval def + + % Reed-Solomon algorithm + /rscodes { + + /rspm exch def + /rsgf exch def + /rsnc exch def + /rscws exch def + + % Calculate the log and anti-log tables + /rsalog [ 1 rsgf 1 sub { dup 2 mul dup rsgf ge {rspm xor} if } repeat ] def + /rslog rsgf array def + 1 1 rsgf 1 sub {dup rsalog exch get exch rslog 3 1 roll put} for + + % Function to calculate the product in the field + /rsprod { + 2 copy 0 ne exch 0 ne and { + rslog exch get exch rslog exch get add rsgf 1 sub mod rsalog exch get + } { + pop pop 0 + } ifelse + } bind def + + % Generate the coefficients + /coeffs [ 1 rsnc {0} repeat ] def + 1 1 rsnc { + /i exch def + coeffs i coeffs i 1 sub get put + i 1 sub -1 1 { + /j exch def + coeffs j coeffs j 1 sub get coeffs j get rsalog i get rsprod xor put + } for + coeffs 0 coeffs 0 get rsalog i get rsprod put + } for + + % Extend the input with the error correction values + /nd rscws length def + /rscws [ rscws {} forall rsnc {0} repeat 0 ] def + 0 1 nd 1 sub { + /k exch rscws exch get rscws nd get xor def + 0 1 rsnc 1 sub { + /j exch def + rscws nd j add rscws nd j add 1 add get k coeffs rsnc j sub 1 sub get rsprod xor put + } for + } for + + % Return all but the last codeword + rscws 0 rscws length 1 sub getinterval + + } bind def + + % Create the codewords and bit string for the mode + format (full) eq { + /mode layers 1 sub 11 bitshift cws length 1 sub add def + readerinit {/mode mode 2#1000000000000000 or def} if + /mode [ + mode 2#1111000000000000 and -12 bitshift + mode 2#0000111100000000 and -8 bitshift + mode 2#0000000011110000 and -4 bitshift + mode 2#0000000000001111 and + ] def + /mode mode 6 16 19 rscodes def + } if + format (compact) eq { + /mode layers 1 sub 6 bitshift cws length 1 sub add def + readerinit {/mode mode 2#10000000 or def} if + /mode [ + mode 2#11110000 and -4 bitshift + mode 2#00001111 and + ] def + /mode mode 5 16 19 rscodes def + } if + format (rune) eq { + /mode barcode cvi def + /mode [ + mode 2#11110000 and -4 bitshift + mode 2#00001111 and + ] def + /mode mode 5 16 19 rscodes def + /mode [mode {2#1010 xor} forall] def % Invert alternate bits + } if + /modebits mode length 4 mul string def + 0 1 modebits length 1 sub {modebits exch (0) putinterval} for + 0 1 mode length 1 sub { + /i exch def + modebits mode i get 2 4 string cvrs dup length 4 exch sub 4 i mul add exch putinterval + } for + + % Extend the data codewords with error correction codewords to create the bit string for the data + /rsparams [ + [] [] [] [] [] [] + [ 64 67 ] % 6-bit codewords + [] + [ 256 301 ] % 8-bit codewords + [] + [ 1024 1033 ] % 10-bit codewords + [] + [ 4096 4201 ] % 12-bit codewords + ] def + /cws cws ncws cws length sub rsparams bpcw get {} forall rscodes def + format (full) eq { + /databits layers layers mul 16 mul layers 112 mul add string def + } { + /databits layers layers mul 16 mul layers 88 mul add string def + } ifelse + 0 1 databits length 1 sub {databits exch (0) putinterval} for + 0 1 ncws 1 sub { + /i exch def + databits cws i get 2 bpcw string cvrs + dup length bpcw exch sub bpcw i mul add databits length ncws bpcw mul sub add + exch putinterval + } for + + % Move to a point in the cartesian plane centered on the bullseye + /cmv {size mul sub mid add} bind def + + % Move to a bit position within a layer + /lmv { + /lbit exch def + /llyr exch def + /lwid fw llyr 4 mul add def + /ldir lbit 2 idiv lwid idiv def + ldir 0 eq { % Top + lwid 1 sub 2 idiv neg 1 add lbit 2 idiv lwid mod add + fw 1 sub 2 idiv llyr 2 mul add lbit 2 mod add + cmv + } if + ldir 1 eq { % Right + fw 2 idiv llyr 2 mul add lbit 2 mod add + lwid 1 sub 2 idiv 1 sub lbit 2 idiv lwid mod sub + cmv + } if + ldir 2 eq { % Bottom + lwid 2 idiv neg 1 add lbit 2 idiv lwid mod add neg + fw 2 idiv llyr 2 mul add lbit 2 mod add neg + cmv + } if + ldir 3 eq { % Left + fw 1 sub 2 idiv llyr 2 mul add lbit 2 mod add neg + lwid 2 idiv 1 sub lbit 2 idiv lwid mod sub neg + cmv + } if } bind def - % Populate bitmap for the image - compact { - /rwid 17 c mul 17 add 17 add 1 add def + % Create the pixel map + % For full symbols we disregard the reference grid at this stage + format (full) eq {/fw 12 def} {/fw 9 def} ifelse + /size fw layers 4 mul add 2 add def + /pixs [size size mul {-1} repeat] def + /mid size 1 sub 2 idiv size mul size 1 sub 2 idiv add def + + % Data layers + /i 0 def + 1 1 layers { + /layer exch def + 0 1 fw layer 4 mul add 8 mul 1 sub { + /pos exch def + pixs layer pos lmv databits databits length i sub 1 sub get 48 sub put + /i i 1 add def + } for + } for + + % For full symbols expand the pixel map by inserting the reference grid + format (full) eq { + /fw 13 def + /size fw layers 4 mul add 2 add layers 10.5 add 7.5 div 1 sub cvi 2 mul add def + /mid size size mul 2 idiv def + /npixs [size size mul {-2} repeat] def + 0 16 size 2 idiv { + /i exch def + 0 1 size 1 sub { + /j exch def + npixs size 2 idiv neg j add i cmv [size 2 idiv j add i add 1 add 2 mod] putinterval + npixs size 2 idiv neg j add i neg cmv [size 2 idiv j add i add 1 add 2 mod] putinterval + npixs i size 2 idiv neg j add cmv [size 2 idiv j add i add 1 add 2 mod] putinterval + npixs i neg size 2 idiv neg j add cmv [size 2 idiv j add i add 1 add 2 mod] putinterval + } for + } for + /j 0 def + 0 1 npixs length 1 sub { + /i exch def + npixs i get -2 eq { + npixs i pixs j get put + /j j 1 add def + } if + } for + /pixs npixs def + } if + + % Finder pattern + /fw fw 2 idiv def + fw neg 1 fw { + /i exch def + fw neg 1 fw { + /j exch def + pixs i j cmv + i abs j abs gt {i abs} {j abs} ifelse 1 add 2 mod + put + } for + } for + + % Orientation bits + [ [ fw 1 add neg fw 1 ] [ fw 1 add neg fw 1 add 1 ] + [ fw neg fw 1 add 1 ] [ fw 1 add fw 1 add 1 ] + [ fw 1 add fw 1 ] [ fw 1 add fw neg 1 ] + [ fw fw 1 add 0 ] [ fw 1 add fw 1 add neg 0 ] + [ fw fw 1 add neg 0 ] [ fw neg fw 1 add neg 0 ] + [ fw 1 add neg fw 1 add neg 0 ] [ fw 1 add neg fw neg 0 ] + ] {pixs exch {} forall 3 1 roll cmv exch put} forall + + % Mode ring + format (full) eq { + /modemap [ + [-5 7] [-4 7] [-3 7] [-2 7] [-1 7] [ 1 7] [ 2 7] [ 3 7] [ 4 7] [ 5 7] + [ 7 5] [ 7 4] [ 7 3] [ 7 2] [ 7 1] [ 7 -1] [ 7 -2] [ 7 -3] [ 7 -4] [ 7 -5] + [ 5 -7] [ 4 -7] [ 3 -7] [ 2 -7] [ 1 -7] [-1 -7] [-2 -7] [-3 -7] [-4 -7] [-5 -7] + [-7 -5] [-7 -4] [-7 -3] [-7 -2] [-7 -1] [-7 1] [-7 2] [-7 3] [-7 4] [-7 5] + ] def } { - /rwid 17 c mul 17 add 17 add 17 add 18 add def + /modemap [ + [-3 5] [-2 5] [-1 5] [ 0 5] [ 1 5] [ 2 5] [ 3 5] + [ 5 3] [ 5 2] [ 5 1] [ 5 0] [ 5 -1] [ 5 -2] [ 5 -3] + [ 3 -5] [ 2 -5] [ 1 -5] [ 0 -5] [-1 -5] [-2 -5] [-3 -5] + [-5 -3] [-5 -2] [-5 -1] [-5 0] [-5 1] [-5 2] [-5 3] + ] def } ifelse - /pixs rwid r mul array def - - 0 1 r 1 sub { + 0 1 modemap length 1 sub { /i exch def - - i 3 mod 0 eq { - /lcw i 3 idiv 30 mul r 1 sub 3 idiv add def - /rcw i 3 idiv 30 mul c add 1 sub def - } if - i 3 mod 1 eq { - /lcw i 3 idiv 30 mul eclevel 3 mul add r 1 sub 3 mod add def - /rcw i 3 idiv 30 mul r 1 sub 3 idiv add def - } if - i 3 mod 2 eq { - /lcw i 3 idiv 30 mul c add 1 sub def - /rcw i 3 idiv 30 mul eclevel 3 mul add r 1 sub 3 mod add def - } if - - pixs rwid i mul [ - 1 1 1 1 1 1 1 1 0 1 0 1 0 1 0 0 0 - lcw i 3 mod cwtobits {} forall - cws c i mul c getinterval { i 3 mod cwtobits {} forall } forall - compact { - 1 - } { - rcw i 3 mod cwtobits {} forall - 1 1 1 1 1 1 1 0 1 0 0 0 1 0 1 0 0 1 - } ifelse - ] putinterval - + pixs modemap i get {} forall cmv modebits i get 48 sub put } for - % Return the arguments << - /ren (renmatrix) + /ren //renmatrix /pixs pixs - /pixx rwid - /pixy r - /height r 72 div rowmult mul - /width rwid 72 div + /pixx size + /pixy size + /height size 2 mul 72 div + /width size 2 mul 72 div /opt options >> @@ -5869,14 +14410,21 @@ end } bind def -% --END ENCODER pdf417-- +/azteccode dup load /uk.co.terryburton.bwipp defineresource pop +end +/setpacking where {pop setpacking} if +% --END ENCODER azteccode-- -% --BEGIN ENCODER datamatrix-- -% --DESC: Data Matrix -% --EXAM: This is Data Matrix! -% --EXOP: rows=32 columns=32 +% --BEGIN ENCODER codeone-- +% --DESC: Code One +% --EXAM: Code One +% --EXOP: version=B % --RNDR: renmatrix -/datamatrix { +/setpacking where {pop currentpacking true setpacking} if +1 dict +dup /renmatrix dup /uk.co.terryburton.bwipp findresource put +begin +/codeone { 20 dict begin @@ -5884,9 +14432,8 @@ /barcode exch def /dontdraw false def - /columns 0 def - /rows 0 def - /encoding (byte) def + /version (unset) def + /encoding (ascii) def /raw false def /parse false def @@ -5901,8 +14448,8 @@ } if options {def} forall - /columns columns cvi def - /rows rows cvi def + /stype version 0 1 getinterval (S) eq def + stype {/raw true def} if % Parse ordinals of the form ^NNN to ASCII parse { @@ -5923,276 +14470,100 @@ exit } ifelse } loop - } if - - /barlen barcode length def - - raw {/encoding (raw) def} if - - encoding (raw) eq { - /cws barlen array def - /i 0 def /j 0 def - { % loop - i barlen eq {exit} if - /cw barcode i 1 add 3 getinterval cvi def - cws j cw put - /i i 4 add def - /j j 1 add def - } loop - /cws cws 0 j getinterval def - } if - - encoding (byte) eq { - barlen 250 lt { - /cws [231 barlen barcode {} forall] def - } { - /cws [231 barlen 250 idiv 249 add barlen 250 mod barcode {} forall] def - } ifelse - 1 1 cws length 1 sub { - /i exch def - i 1 add 149 mul 255 mod 1 add cws i get add - dup 256 ge {256 sub} if - cws exch i exch put - } for - } if - - encoding (ascii) eq { - /cws barlen 2 mul array def - /i 0 def /j 0 def - { % loop - i barlen eq {exit} if - /char barcode i get def - char 48 ge char 57 le and i barlen 1 sub lt and { - barcode i 1 add get dup 48 ge exch 57 le and { % Digit pair - cws j barcode i 2 getinterval cvi 130 add put - /i i 2 add def - /j j 1 add def - } { % Singular digit - cws j char 1 add put - /i i 1 add def - /j j 1 add def - } ifelse - } { char 127 le { % ASCII - cws j char 1 add put - /i i 1 add def - /j j 1 add def - } { % Extended ASCII - cws j 235 put - cws j 1 add char 127 sub put - /i i 1 add def - /j j 2 add def - } ifelse } ifelse - } loop - /cws cws 0 j getinterval def - } if - - encoding (edifact) eq { - /cws 1558 array def - /i 0 def /j 1 def /k 0 def - cws 0 240 put - { % loop - i barlen gt {exit} if - /k 0 def /v 0 def - { % loop until triplet is full or beyond end of data - k 4 eq i barlen gt or {exit} if - /cval (unset) def - i barlen lt { - /char barcode i get def - char 32 ge char 94 le and { - /cval char 63 and def - } if - } { % Unlatch at end of data - /cval 31 def - } ifelse - /v v cval 3 k sub 6 mul bitshift or def - /k k 1 add def - /i i 1 add def - } loop - cws j [ v -16 bitshift v -8 bitshift 255 and v 255 and ] putinterval - /j j 3 add def - } loop - /cws cws 0 j getinterval def - } if - - encoding (c40) eq encoding (text) eq or encoding (x12) eq or { - - /s1 0 def /s2 1 def /s3 2 def /us 30 def - - encoding (c40) eq { - /latch 230 def - /charmap [ - 0 1 31 { [ exch s1 exch ] } for % 0-31 - [ 3 ] % 32 - 0 1 14 { [ exch s2 exch ] } for % 33-47 - 4 1 13 { [ exch ] } for % 48-57 - 15 1 21 { [ exch s2 exch ] } for % 58-64 - 14 1 39 { [ exch ] } for % 65-90 - 22 1 26 { [ exch s2 exch ] } for % 91-95 - [ s3 0 ] % 96 - 1 1 26 { [ exch s3 exch ] } for % 97-122 - 27 1 31 { [ exch s3 exch ] } for % 123-127 - 0 1 31 { [ s2 us 4 -1 roll s1 exch ] } for % 128-159 - [ s2 us 3 ] % 160 - 0 1 14 { [ s2 us 4 -1 roll s2 exch ] } for % 161-175 - 4 1 13 { [ s2 us 4 -1 roll ] } for % 176-185 - 15 1 21 { [ s2 us 4 -1 roll s2 exch ] } for % 186-192 - 14 1 39 { [ s2 us 4 -1 roll ] } for % 193-218 - 22 1 26 { [ s2 us 4 -1 roll s2 exch ] } for % 219-223 - [ s2 us s3 0 ] % 224 - 1 1 26 { [ s2 us 4 -1 roll s3 exch ] } for % 225-250 - 27 1 31 { [ s2 us 4 -1 roll s3 exch ] } for % 251-255 - ] def - } if - - encoding (text) eq { - /latch 239 def - /charmap [ - 0 1 31 { [ exch s1 exch ] } for % 0-31 - [ 3 ] % 32 - 0 1 14 { [ exch s2 exch ] } for % 33-47 - 4 1 13 { [ exch ] } for % 48-57 - 15 1 21 { [ exch s2 exch ] } for % 58-64 - 1 1 26 { [ exch s3 exch ] } for % 65-90 - 22 1 26 { [ exch s2 exch ] } for % 91-95 - [ s3 0 ] % 96 - 14 1 39 { [ exch ] } for % 97-122 - 27 1 31 { [ exch s3 exch ] } for % 123-127 - 0 1 31 { [ s2 us 4 -1 roll s1 exch ] } for % 128-159 - [ s2 us 3 ] % 160 - 0 1 14 { [ s2 us 4 -1 roll s2 exch ] } for % 161-175 - 4 1 13 { [ s2 us 4 -1 roll ] } for % 176-185 - 15 1 21 { [ s2 us 4 -1 roll s2 exch ] } for % 186-192 - 1 1 26 { [ s2 us 4 -1 roll s3 exch ] } for % 193-218 - 22 1 26 { [ s2 us 4 -1 roll s2 exch ] } for % 219-223 - [ s2 us s3 0 ] % 224 - 14 1 39 { [ s2 us 4 -1 roll ] } for % 225-250 - 27 1 31 { [ s2 us 4 -1 roll s3 exch ] } for % 251-255 - ] def - } if - - encoding (x12) eq { - /latch 238 def - /charmap [ - 13 { [ () ] } repeat % 0-12 - [ 0 ] % 13 - 18 { [ () ] } repeat % 14-31 - [ 3 ] % 32 - 9 { [ () ] } repeat % 33-41 - [ 1 ] % 42 - 5 { [ () ] } repeat % 43-47 - 4 1 13 { [ exch ] } for % 48-57 - 4 { [ () ] } repeat % 58-61 - [ 2 ] % 62 - 2 { [ () ] } repeat % 63-64 - 14 1 39 { [ exch ] } for % 65-90 - 165 { [ () ] } repeat % 91-255 - ] def - } if - - % Derive the encoded character stream - /encstr barlen 4 mul array def - /j 0 def - 0 1 barlen 1 sub { - barcode exch get charmap exch get - dup encstr exch j exch putinterval - length j add /j exch def - } for - /encstr encstr 0 j getinterval def - /enclen j def + } if - % Compress triples into doubles - /cws 1558 array def - /i 0 def /j 1 def /k 0 def - cws 0 latch put - { % loop - i enclen ge {exit} if - /k 0 def /v 1 def - { % loop until triple is full or end of data - k 3 eq i enclen ge or {exit} if - /v v encstr i get 40 2 k sub exp cvi mul add def - /k k 1 add def - /i i 1 add def - } loop - cws j [ v -8 bitshift v 255 and ] putinterval - /j j 2 add def + /barlen barcode length def + + raw {/encoding (raw) def} if + + encoding (raw) eq { + /cws barlen array def + /i 0 def /j 0 def + { % loop + i barlen eq {exit} if + /cw barcode i 1 add 3 getinterval cvi def + cws j cw put + /i i 4 add def + /j j 1 add def } loop - cws j 254 put - /cws cws 0 j 1 add getinterval def + /cws cws 0 j getinterval def + } if + encoding (ascii) eq { + /cws barlen 2 mul array def + /i 0 def /j 0 def + { % loop + i barlen eq {exit} if + /char barcode i get def + char 48 ge char 57 le and i barlen 1 sub lt and { + barcode i 1 add get dup 48 ge exch 57 le and { % Digit pair + cws j barcode i 2 getinterval cvi 130 add put + /i i 2 add def + /j j 1 add def + } { % Singular digit + cws j char 1 add put + /i i 1 add def + /j j 1 add def + } ifelse + } { char 127 le { % ASCII + cws j char 1 add put + /i i 1 add def + /j j 1 add def + } { % Extended ASCII + cws j 235 put + cws j 1 add char 127 sub put + /i i 1 add def + /j j 2 add def + } ifelse } ifelse + } loop + /cws cws 0 j getinterval def } if % Basic metrics for the each symbol - % rows cols regh regv rscw rsbl + % ver row col dcol dcws rscw rsbl ro ri rl /metrics [ - % Standard square symbols - [ 10 10 1 1 5 1 ] - [ 12 12 1 1 7 1 ] - [ 14 14 1 1 10 1 ] - [ 16 16 1 1 12 1 ] - [ 18 18 1 1 14 1 ] - [ 20 20 1 1 18 1 ] - [ 22 22 1 1 20 1 ] - [ 24 24 1 1 24 1 ] - [ 26 26 1 1 28 1 ] - [ 32 32 2 2 36 1 ] - [ 36 36 2 2 42 1 ] - [ 40 40 2 2 48 1 ] - [ 44 44 2 2 56 1 ] - [ 48 48 2 2 68 1 ] - [ 52 52 2 2 84 2 ] - [ 64 64 4 4 112 2 ] - [ 72 72 4 4 144 4 ] - [ 80 80 4 4 192 4 ] - [ 88 88 4 4 224 4 ] - [ 96 96 4 4 272 4 ] - [ 104 104 4 4 336 6 ] - [ 120 120 6 6 408 6 ] - [ 132 132 6 6 496 8 ] - [ 144 144 6 6 620 10 ] - % Optional rectangular symbols - [ 8 18 1 1 7 1 ] - [ 8 32 1 2 11 1 ] - [ 12 26 1 1 14 1 ] - [ 12 36 1 2 18 1 ] - [ 16 36 1 2 24 1 ] - [ 16 48 1 2 28 1 ] + [ (A) 16 18 16 10 10 1 4 99 6 ] + [ (B) 22 22 20 19 16 1 4 99 8 ] + [ (C) 28 32 28 44 26 1 4 22 11 ] + [ (D) 40 42 36 91 44 1 4 16 16 ] + [ (E) 52 54 48 182 70 1 4 22 22 ] + [ (F) 70 76 68 370 140 2 4 22 31 ] + [ (G) 104 98 88 732 280 4 6 21 47 ] + [ (H) 148 134 120 1480 560 8 6 20 69 ] + [ (S-10) 8 11 10 4 4 1 99 99 99 ] + [ (S-20) 8 21 20 8 8 1 99 99 99 ] + [ (S-30) 8 31 30 12 12 1 99 99 99 ] + [ (T-16) 16 17 16 10 10 1 99 99 99 ] + [ (T-32) 16 33 32 24 16 1 99 99 99 ] + [ (T-48) 16 49 48 38 22 1 99 99 99 ] ] def % Select metrics of an appropriate symbol - /urows rows def - /ucols columns def /i 0 def { % loop /m metrics i get def - /rows m 0 get def % Rows in symbol - /cols m 1 get def % Columns in symbol - /regh m 2 get def % Horizontal regions - /regv m 3 get def % Vertical regions - /rscw m 4 get def % Error correction codewords - /rsbl m 5 get def % Error correction blocks - /mrows rows 2 regh mul sub def % Rows in the mapping matrix - /mcols cols 2 regv mul sub def % Columns in the mapping matrix - /rrows mrows regh idiv def % Rows per region - /rcols mcols regv idiv def % Columns per region - /ncws mrows mcols mul 8 idiv rscw sub def % Data codewords + /vers m 0 get def % Version of symbol + /rows m 1 get def % Rows in symbol + /cols m 2 get def % Columns in symbol + /dcol m 3 get def % Data columns in symbol + /dcws m 4 get def % Data codewords in symbol + /rscw m 5 get def % Error correction codewords + /rsbl m 6 get def % Error correction blocks + /riso m 7 get def % Riser offset + /risi m 8 get def % Riser interval + /risl m 9 get def % Riser length + /dcpb dcws rsbl idiv def % Data codewords per block + /ecpb rscw rsbl idiv def % Error codewords per block /okay true def - cws length ncws gt {/okay false def} if - urows 0 ne urows rows ne and {/okay false def} if - ucols 0 ne ucols cols ne and {/okay false def} if + version (unset) ne version vers ne and {/okay false def} if % The version must match that supplied + cws length dcws gt {/okay false def} if okay {exit} if /i i 1 add def } loop - % Extend cws to ncws codewords by addition of pseudo-randomised pad characters - cws length ncws lt { - /datlen cws length def - /cws [ cws {} forall ncws datlen sub {129} repeat ] def - datlen 1 add 1 ncws 1 sub { - /i exch def - i 1 add 149 mul 253 mod 1 add 129 add - dup 254 gt {254 sub} if - cws exch i exch put - } for + % Extend cws to ncws codewords by addition of pad characters + stype not { + /cws [ cws aload pop dcws cws length sub {129} repeat ] def } if % De-interleave the codewords into blocks @@ -6200,207 +14571,166 @@ /ecbs rsbl array def % Array of error correction blocks 0 1 rsbl 1 sub { /i exch def - cws length 1558 ne { - /cwbsize cws length rsbl idiv def - } { - i 7 le {/cwbsize 156 def} {/cwbsize 155 def} ifelse - } ifelse - /cwb cwbsize array def - 0 1 cwbsize 1 sub { + /cwb dcpb array def + 0 1 dcpb 1 sub { /j exch def cwb j cws j rsbl mul i add get put } for cwbs i cwb put - ecbs i [ rscw rsbl idiv {0} repeat ] put } for - % Calculate the log and anti-log tables - /rsalog [ 1 255 { dup 2 mul dup 256 ge {301 xor} if } repeat ] def - /rslog 256 array def - 1 1 255 {dup rsalog exch get exch rslog 3 1 roll put} for - - % Function to calculate the product in the field + % Log and anti-log tables and function to calculate product in the field + /gf stype {32} {256} ifelse def + /gf-1 gf 1 sub def + /pm stype {37} {301} ifelse def + /rsalog [ 1 gf-1 { dup 2 mul dup gf ge {pm xor} if } repeat ] def + /rslog gf array def + 1 1 gf-1 {dup rsalog exch get exch rslog 3 1 roll put} for /rsprod { 2 copy 0 ne exch 0 ne and { - rslog exch get exch rslog exch get add 255 mod rsalog exch get + rslog exch get exch rslog exch get add gf-1 mod rsalog exch get } { - pop pop 0 - } ifelse - } bind def - - % Generate the coefficients - /coeffs [ 1 rscw rsbl idiv {0} repeat ] def - 1 1 rscw rsbl idiv { - /i exch def - coeffs i coeffs i 1 sub get put - i 1 sub -1 1 { - /j exch def - coeffs j coeffs j 1 sub get coeffs j get rsalog i get rsprod xor put - } for - coeffs 0 coeffs 0 get rsalog i get rsprod put - } for - /coeffs coeffs 0 coeffs length 1 sub getinterval def - - % Calculate the error correction codewords for each block - 0 1 cwbs length 1 sub { - /i exch def - /cwb cwbs i get def - /ecb ecbs i get def - 0 1 cwb length 1 sub { - /t exch cwb exch get ecb 0 get xor def - ecb length 1 sub -1 0 { - /j exch def - /p ecb length j sub 1 sub def - ecb p t coeffs j get rsprod put - j 0 gt { ecb p ecb p 1 add get ecb p get xor put } if - } for - } for - } for - - % Strange fixup for 144x144 symbols - ncws 1558 eq { - /ecbs [ ecbs 8 2 getinterval {} forall ecbs 0 8 getinterval {} forall ] def - } if - - % Extend codewords with the interleaved error correction codes - /cws [ cws {} forall rscw {0} repeat ] def - 0 1 rscw 1 sub { - /i exch def - cws ncws i add ecbs i rsbl mod get i rsbl idiv get put - } for - - % Place the codewords into the matrix - /module { - % cw row col shape - 4 -1 roll - (00000000) 8 string copy dup 3 -1 roll 2 8 string cvrs - dup length 8 exch sub exch putinterval - 7 -1 0 {1 index exch get 48 sub exch} for pop - 11 -3 roll - % 1 2 4 8 16 32 64 128 row col shape - { % Place each bit of the codeword in the shape, MSB first - exec - 1 index 0 lt { - exch mrows add exch - 4 mrows 4 add 8 mod sub add - } if - dup 0 lt { - mcols add exch - 4 mcols 4 add 8 mod sub add exch - } if - exch mcols mul add - mmat exch 5 -1 roll put - } forall - } bind def - - % Placement patterns - /dmn [ - { 2 copy 2 sub exch 2 sub exch } bind { 2 copy 1 sub exch 2 sub exch } bind - { 2 copy 2 sub exch 1 sub exch } bind { 2 copy 1 sub exch 1 sub exch } bind - { 2 copy exch 1 sub exch } bind { 2 copy 2 sub } bind - { 2 copy 1 sub } bind { 2 copy } bind - ] def - - /dmc1 [ - { mrows 1 sub 0 } bind { mrows 1 sub 1 } bind - { mrows 1 sub 2 } bind { 0 mcols 2 sub } bind - { 0 mcols 1 sub } bind { 1 mcols 1 sub } bind - { 2 mcols 1 sub } bind { 3 mcols 1 sub } bind - ] def - - /dmc2 [ - { mrows 3 sub 0 } bind { mrows 2 sub 0 } bind - { mrows 1 sub 0 } bind { 0 mcols 4 sub } bind - { 0 mcols 3 sub } bind { 0 mcols 2 sub } bind - { 0 mcols 1 sub } bind { 1 mcols 1 sub } bind - ] def - - /dmc3 [ - { mrows 3 sub 0 } bind { mrows 2 sub 0 } bind - { mrows 1 sub 0 } bind { 0 mcols 2 sub } bind - { 0 mcols 1 sub } bind { 1 mcols 1 sub } bind - { 2 mcols 1 sub } bind { 3 mcols 1 sub } bind - ] def - - /dmc4 [ - { mrows 1 sub 0 } bind { mrows 1 sub mcols 1 sub } bind - { 0 mcols 3 sub } bind { 0 mcols 2 sub } bind - { 0 mcols 1 sub } bind { 1 mcols 3 sub } bind - { 1 mcols 2 sub } bind { 1 mcols 1 sub } bind - ] def - - /mmat [ mrows mcols mul {-1} repeat ] def - cws length 1 sub -1 0 {cws exch get} for % Reverse cws onto stack - 4 0 % Starting row and column - { % loop - 2 copy 0 eq exch mrows eq and { - dmc1 module - } if - 2 copy 0 eq exch mrows 2 sub eq and mcols 4 mod 0 ne and { - dmc2 module - } if - 2 copy 0 eq exch mrows 2 sub eq and mcols 8 mod 4 eq and { - dmc3 module - } if - 2 copy 2 eq exch mrows 4 add eq and mcols 8 mod 0 eq and { - dmc4 module - } if + pop pop 0 + } ifelse + } bind def - { % loop for sweeping upwards - 2 copy 0 ge exch mrows lt and { - 2 copy exch mcols mul add mmat exch get -1 eq { - dmn module - } if - } if - 2 add exch 2 sub exch - 2 copy mcols lt exch 0 ge and not {exit} if - } loop - 3 add exch 1 add exch + % Generate the coefficients for the Reed-Solomon algorithm + /coeffs [ 1 ecpb {0} repeat ] def + 0 1 ecpb 1 sub { + /i exch def + coeffs i 1 add coeffs i get put + i -1 1 { + /j exch def + coeffs j coeffs j 1 sub get coeffs j get rsalog i get rsprod xor put + } for + coeffs 0 coeffs 0 get rsalog i get rsprod put + } for + /coeffs coeffs 0 coeffs length 1 sub getinterval def - { % loop for sweeping downwards - 2 copy mcols lt exch 0 ge and { - 2 copy exch mcols mul add mmat exch get -1 eq { - dmn module - } if - } if - 2 sub exch 2 add exch - 2 copy 0 ge exch mrows lt and not {exit} if - } loop - 1 add exch 3 add exch + % Reed-Solomon algorithm to derive the error correction codewords + 0 1 cwbs length 1 sub { + /i exch def + /rscws [ cwbs i get aload pop ecpb {0} repeat ] def + 0 1 dcpb 1 sub { + /m exch def + /k rscws m get def + 0 1 ecpb 1 sub { + /j exch def + rscws m j add 1 add coeffs ecpb j sub 1 sub get k rsprod rscws m j add 1 add get xor put + } for + } for + ecbs i rscws dcpb ecpb getinterval put + } for - 2 copy mcols lt exch mrows lt or not {pop pop exit} if + % Extend codewords with the interleaved error correction codes + /cws [ cws aload pop rscw {0} repeat ] def + 0 1 rscw 1 sub { + /i exch def + cws dcws i add ecbs i rsbl mod get i rsbl idiv get put + } for - } loop + % Module matrix for layout of the codewords + /mmat dcws rscw add stype {5} {8} ifelse mul array def + /r 0 def /c 0 def + 0 stype {2} {1} ifelse cws length 1 sub { + /i exch def + stype not { + (00000000) 8 string copy dup cws i get 2 8 string cvrs + dup length 8 exch sub exch putinterval [ exch {48 sub} forall ] + dup 0 4 getinterval /top exch def + 4 4 getinterval /bot exch def + } { + (00000) 5 string copy dup cws i get 2 5 string cvrs + dup length 5 exch sub exch putinterval [ exch {48 sub} forall ] + /c1 exch def + (00000) 5 string copy dup cws i 1 add get 2 5 string cvrs + dup length 5 exch sub exch putinterval [ exch {48 sub} forall ] + /c2 exch def + /top [ c1 0 3 getinterval aload pop c2 0 2 getinterval aload pop ] def + /bot [ c1 3 2 getinterval aload pop c2 2 3 getinterval aload pop ] def + } ifelse + mmat r dcol mul c add top putinterval + mmat r 1 add dcol mul c add bot putinterval + /c c top length add def + c dcol eq {/c 0 def /r r 2 add def} if + } for - % Set checker pattern if required - mmat mrows mcols mul 1 sub get -1 eq { - mmat mrows mcols 1 sub mul 2 sub [1 0] putinterval - mmat mrows mcols mul 2 sub [0 1] putinterval - } if + % Create bitmap and add finder patterns + /mmv {cols mul add} bind def + /pixs [ rows cols mul {-1} repeat ] def + + % Centre pattern + /artifact [ + {cols {0} repeat} bind + {cols {1} repeat} bind + {0 cols 2 sub {1} repeat 0} bind + {0 1 cols 4 sub {0} repeat 1 0} bind + {cols 1 sub 2 idiv {-1} repeat 1 cols 1 sub 2 idiv {-1} repeat} bind + {cols 1 sub 2 idiv {-1} repeat 0 cols 1 sub 2 idiv {-1} repeat} bind + {1 cols 2 sub {0} repeat 1} bind + {1 0 cols 4 sub {1} repeat 0 1} bind + ] def + /cpat << + /A (121343) + /B (12134343) + /C (12121343) + /D (1213434343) + /E (1212134343) + /F (1212121343) + /G (121213434343) + /H (121212134343) + /S (56661278) + /T (5666666666127878) + >> vers 0 1 getinterval get def + pixs 0 rows cpat length sub 2 idiv mmv + [ cpat {artifact exch 49 sub get exec} forall ] putinterval + + % Risers + 0 1 risl 1 sub { + /i exch def + riso risi cols 1 sub { + /j exch def + [ 1 i 12 mod 0 eq {1} {0} ifelse ] dup + pixs j i mmv + 3 -1 roll putinterval + i risl 1 sub ne { + pixs cols j sub 2 sub rows i sub 1 sub mmv + 3 -1 roll putinterval + } {pop} ifelse + } for + } for + + % Black dots + << + /A [ [12 5] ] + /B [ [16 7] ] + /C [ [26 12] ] + /D [] + /E [ [26 23] ] + /F [ [26 32] [70 32] [26 34] [70 34] ] + /G [ [27 48] [69 48] ] + /H [ [26 70] [66 70] [106 70] [26 72] [66 72] [106 72] ] + /S-10 [] + /S-20 [ [10 4] ] + /S-30 [ [15 4] [15 6] ] + /T-16 [ [8 10] ] + /T-32 [ [16 10] [16 12] ] + /T-48 [ [24 10] [24 12] [24 14] ] + >> vers get {pixs exch aload pop mmv 1 put} forall % Place the modules onto a pixel map between alignment patterns - /pixs rows cols mul array def - /cwpos 0 def - 0 1 rows 1 sub { + /j 0 def + 0 1 pixs length 1 sub { /i exch def - i rrows 2 add mod 0 eq { pixs i cols mul [ cols 2 idiv {1 0} repeat ] putinterval } if - i rrows 2 add mod rrows 1 add eq { pixs i cols mul [ cols {1} repeat ] putinterval } if - i rrows 2 add mod 0 ne i rrows 2 add mod rrows 1 add ne and { - 0 1 cols 1 sub { - /j exch def - j rcols 2 add mod 0 eq { pixs i cols mul j add 1 put } if - j rcols 2 add mod rcols 1 add eq { pixs i cols mul j add i 2 mod put } if - j rcols 2 add mod 0 ne j rcols 2 add mod rcols 1 add ne and { - pixs i cols mul j add mmat cwpos get put - /cwpos cwpos 1 add def - } if - } for - } if + pixs i get -1 eq { + pixs i mmat j get put + /j j 1 add def + } if } for % Return the arguments << - /ren (renmatrix) + /ren //renmatrix /pixs pixs /pixx cols /pixy rows @@ -6414,27 +14744,36 @@ end } bind def -% --END ENCODER datamatrix-- - -% --BEGIN ENCODER qrcode-- -% --DESC: QR Code -% --EXAM: http://www.terryburton.co.uk/barcodewriter/ -% --EXOP: eclevel=M +/codeone dup load /uk.co.terryburton.bwipp defineresource pop +end +/setpacking where {pop setpacking} if +% --END ENCODER codeone-- + +% --BEGIN ENCODER gs1-cc-- +% --REQUIRES micropdf417 pdf417-- +% --DESC: GS1 Composite 2D Component +% --EXAM: (01)95012345678903(3103)000123 +% --EXOP: ccversion=b cccolumns=4 % --RNDR: renmatrix -/qrcode { - - 20 dict begin +/setpacking where {pop currentpacking true setpacking} if +1 dict +dup /renmatrix dup /uk.co.terryburton.bwipp findresource put +dup /pdf417 dup /uk.co.terryburton.bwipp findresource put +dup /micropdf417 dup /uk.co.terryburton.bwipp findresource put +begin +/gs1-cc { + + 20 dict begin % Confine variables to local scope - /options exch def - /barcode exch def + /options exch def % We are given an option string + /barcode exch def % We are given a barcode string /dontdraw false def - /format (full) def % full or micro - /version (unset) def - /eclevel (unset) def % L, M, Q or H - /raw false def - /parse false def - + /ccversion (a) def + /cccolumns -1 def + /lintype () def + /linwidth -1 def + % Parse the input options options type /stringtype eq { 1 dict begin @@ -6445,686 +14784,1406 @@ currentdict end /options exch def } if options {def} forall + + /cccolumns cccolumns cvi def + /linwidth linwidth cvi def - % Parse ordinals of the form ^NNN to ASCII - parse { - /msg barcode length string def + % Select columns based on linear type + cccolumns -1 eq { + << + /ean13 4 + /upca 4 + /ean8 3 + /upce 2 + /gs1-128 + ccversion (c) ne {4} {linwidth 52 sub 17 idiv} ifelse + /databaromni 4 + /databarstacked 2 + /databarstackedomni 2 + /databartruncated 4 + /databarlimited 3 + /databarexpanded 4 + /databarexpandedstacked 4 + >> lintype get /cccolumns exch def + } if + + % Expand ordinals of the form ^NNN to ASCII + /expand { + /in exch def + /out in length string def /j 0 def - barcode + in { % loop (^) search { - dup msg exch j exch putinterval + dup out exch j exch putinterval length j add 1 add /j exch def pop - dup 0 3 getinterval cvi msg exch j 1 sub exch put + dup 0 3 getinterval cvi out exch j 1 sub exch put dup length 3 sub 3 exch getinterval } { - dup msg exch j exch putinterval + dup out exch j exch putinterval length j add /j exch def - /barcode msg 0 j getinterval def - exit + out 0 j getinterval exit } ifelse } loop - } if + } bind def + + % Parse out AIs + /ais [] def + /aival 2 dict def + barcode dup length 1 sub 1 exch getinterval + { % loop + dup () eq {exit} if + (\)) search pop + exch pop + exch (\() search { + exch pop exch 3 1 roll + } { + () 3 1 roll + } ifelse + [ ais aload pop counttomark 2 add index ] /ais exch def + aival 3 1 roll expand put + } loop + pop + + % Method selection + /isupper {dup 65 ge exch 90 le and} bind def % A-Z + /isnum0 {dup 48 ge exch 57 le and} bind def % 0-9 + /isnum1 {dup 49 ge exch 57 le and} bind def % 1-9 + { % common exit + + % (10/11/17)... + ais length 1 ge { + ais 0 get (10) eq ais 0 get (11) eq or ais 0 get (17) eq or { + -1 (10) exit + } if + } if - % Convert from input into message bitstream - raw { - /msgbits barcode def - } { % Simple autoencoder from input to bitstream using byte mode only for full format symbols + % (90){0-3 digits not starting 0}{upper alpha}... + ais length 1 ge { + ais 0 get (90) eq { + /v aival (90) get def + v length 1 ge { + v 0 get isupper { + 0 (11) exit + } if + } if + v length 2 ge { + v 0 get isnum1 + v 1 get isupper and { + 1 (11) exit + } if + } if + v length 3 ge { + v 0 get isnum1 + v 1 get isnum0 and + v 2 get isupper and { + 2 (11) exit + } if + } if + v length 4 ge { + v 0 get isnum1 + v 1 get isnum0 and + v 2 get isnum0 and + v 3 get isupper and { + 3 (11) exit + } if + } if + } if + } if - /barlen barcode length def - eclevel (unset) eq {/eclevel (M) def} if + % Freeform + -1 (0) exit + + } loop + /method exch def + /npre exch def - % Determine smallest symbol version to hold given amount of byte-encoded data - version (unset) eq { - /caps [ - [ - 17 32 53 78 106 134 154 192 230 271 % 1-L - 10-L - 321 367 425 458 520 586 644 718 792 858 % 11-L - 20-L - 929 1003 1091 1171 1273 1367 1465 1528 1628 1732 % 21-L - 30-L - 1840 1952 2068 2188 2303 2431 2563 2699 2809 2953 % 31-L - 40-L - ] [ - 14 26 42 62 84 106 122 152 180 213 % 1-M - 10-M - 251 287 331 362 412 450 504 560 624 666 % 11-M - 20-M - 711 779 857 911 997 1059 1125 1190 1264 1370 % 21-M - 30-M - 1452 1538 1628 1722 1809 1911 1989 2099 2213 2331 % 31-M - 40-M - ] [ - 11 20 32 46 60 74 86 108 130 151 % 1-Q - 10-Q - 177 203 241 258 292 322 364 394 442 482 % 11-Q - 20-Q - 509 565 611 661 715 751 805 868 908 982 % 21-Q - 30-Q - 1030 1112 1168 1228 1283 1351 1423 1499 1579 1663 % 31-Q - 40-Q - ] [ - 7 14 24 34 44 58 64 84 98 119 % 1-H - 10-H - 137 155 177 194 220 250 280 310 338 382 % 11-H - 20-H - 403 439 461 511 535 593 625 658 698 742 % 21-H - 30-H - 790 842 898 958 983 1051 1093 1139 1219 1273 % 31-H - 40-H - ] + /fnc1 -1 def /lnumeric -2 def /lalphanumeric -3 def /liso646 -4 def + + /tobin { + string dup length 1 sub 0 exch 1 exch {1 index exch 48 put} for + dup 3 -1 roll 2 2 index length string cvrs dup length 2 index length exch sub exch putinterval + } bind def + + /alpha << + 65 1 90 {dup 65 sub 5 tobin} for + 48 1 57 {dup 4 add 6 tobin} for + fnc1 (11111) + >> def + + /numeric << + 0 1 119 { + dup (00) 2 string copy dup 3 -1 roll 11 2 string cvrs + dup length 2 exch sub exch putinterval + dup 0 get 65 eq {dup 0 94 put} if + dup 1 get 65 eq {dup 1 94 put} if + exch 8 add + (0000000) 7 string copy dup 3 -1 roll 2 7 string cvrs + dup length 7 exch sub exch putinterval + } for + lalphanumeric (0000) + >> def + + /alphanumeric << + 48 1 57 {dup 43 sub 5 tobin} for + fnc1 (01111) + 65 1 90 {dup 33 sub 6 tobin} for + 42 (111010) + 44 1 47 {dup 15 add 6 tobin} for + lnumeric (000) + liso646 (00100) + >> def + + /iso646 << + 48 1 57 {dup 43 sub 5 tobin} for + fnc1 (01111) + 65 1 90 {dup 1 sub 7 tobin} for + 97 1 122 {dup 7 sub 7 tobin} for + 33 (11101000) + 34 (11101001) + 37 1 47 {dup 197 add 8 tobin} for + 58 1 63 {dup 187 add 8 tobin} for + 95 (11111011) + 32 (11111100) + lnumeric (000) + lalphanumeric (00100) + >> def + + method (10) eq { % TODO: fixme + ais 0 get (11) eq ais 0 get (17) eq or { + aival ais 0 get get + dup 0 2 getinterval cvi 384 mul exch + dup 2 2 getinterval cvi 1 sub 32 mul exch + 4 2 getinterval cvi add add + (0000000000000000) 16 string copy dup 3 -1 roll 2 16 string cvrs + dup length 16 exch sub exch putinterval + [ 1 0 + 4 -1 roll {48 sub} forall + ais 0 get (11) eq {0} {1} ifelse + ] /cdf exch def + /ais ais 1 ais length 1 sub getinterval def + } { + /cdf [ 1 0 1 1 ] def + } ifelse + ais length 0 ne { + ais 0 get (10) eq { + /gpf [ aival (10) get {} forall ] def + ais length 1 gt {/gpf [ gpf aload pop fnc1 ] def} if % TODO: check + /ais ais 1 ais length 1 sub getinterval def + } { + /gpf [fnc1] def % TODO: check + } ifelse + } { + /cdf [ cdf aload pop 0 0 0 0 0 1 1 1 1 ] def + /gpf [] def + } ifelse + /mode (numeric) def + } if + + method (11) eq { + /cdf [ 1 1 ] def + /ai90 aival (90) get def + npre 1 add ai90 length ne { + ai90 npre 1 add ai90 length npre sub 1 sub getinterval + } { + () + } ifelse + /ai90rem exch def + /nalpha 0 ai90rem {dup 65 ge exch 90 le and {1 add} if} forall def + /nnums 0 ai90rem {dup 48 ge exch 57 le and {1 add} if} forall def + /mode nalpha nnums gt {(alpha)} {(numeric)} ifelse def + nalpha nnums add ai90rem length ne {/mode (alphanumeric) def} if + /cdf [ + cdf aload pop + mode (alphanumeric) eq {0} if + mode (numeric) eq {1 0} if + mode (alpha) eq {1 1} if + ] def + /ais1 ais length 1 gt {ais 1 get} {-1} ifelse def + ais1 (21) eq ais1 (8004) eq or { + /cdf [ cdf aload pop ais1 (21) eq {1 0} {1 1} ifelse ] def + } { + /cdf [ cdf aload pop 0 ] def + } ifelse + /nval npre 0 ne {ai90 0 npre getinterval cvi} {0} ifelse def + (BDHIJKLNPQRSTVXZ) ai90 npre 1 getinterval search { + length exch pop exch pop + /aval exch def + } { + pop /aval -1 def + } ifelse + nval 31 lt aval -1 ne and { + (00000) 5 string copy dup nval 2 5 string cvrs + dup length 5 exch sub exch putinterval + [ exch {48 sub} forall ] /nbits exch def + (0000) 4 string copy dup aval 2 4 string cvrs + dup length 4 exch sub exch putinterval + [ exch {48 sub} forall ] /abits exch def + /cdf [ + cdf aload pop + nbits aload pop + abits aload pop ] def - /caps caps (LMQH) eclevel search pop length exch pop exch pop get def - /i 1 def - { - barlen caps i 1 sub get le {exit} if - /i i 1 add def - } loop - /version i 10 2 string cvrs def + } { + (0000000000) 10 string copy dup nval 2 10 string cvrs + dup length 10 exch sub exch putinterval + [ exch {48 sub} forall ] /nbits exch def + (00000) 5 string copy dup ai90 npre get 65 sub 2 5 string cvrs + dup length 5 exch sub exch putinterval + [ exch {48 sub} forall ] /abits exch def + /cdf [ + cdf aload pop + 1 1 1 1 1 + nbits aload pop + abits aload pop + ] def + } ifelse + mode (numeric) eq { + /gpf [ ai90rem {} forall ais length 1 gt {fnc1} if ] def + } { + /encs mode (alpha) eq {alpha} {alphanumeric} ifelse def + /in [ ai90rem {} forall ais length 1 gt {fnc1} if ] def + /out in length 6 mul array def + /j 0 def + 0 1 in length 1 sub { + in exch get encs exch get + dup [ exch {48 sub} forall ] out exch j exch putinterval + length j add /j exch def + } for + /cdf [ + cdf aload pop + out 0 j getinterval aload pop + ] def + /gpf [] def + ais length 1 gt mode (alpha) ne or {/mode (numeric) def} if + } ifelse + /ais ais 1 ais length 1 sub getinterval def + ais length 0 ne { + ais1 (21) eq ais1 (8004) eq or { + /gpf [ + gpf aload pop + aival ais1 get {} forall + ] def + /ais ais 1 ais length 1 sub getinterval def + ais length 0 ne {/gpf [gpf aload pop fnc1] def} if + } if } if + } if - % Set the control character data for the version - /mid (0100) def /term (0000) def /cclen 8 def - version 0 1 getinterval (M) ne { % Version 10 and above - version cvi 10 ge {/cclen 16 def} if - } if - /midlen mid length def - /termlen term length def + method (0) eq { + /cdf [ 0 ] def + /gpf [] def + /mode (numeric) def + } if - % Create the bitstream as byte_mode_id character_count data_bytes term - /msgbits midlen cclen add barlen 8 mul add termlen add string def - msgbits 0 mid putinterval - (0000000000000000) 0 cclen getinterval cclen string copy - dup barlen cvi 2 cclen string cvrs dup length cclen exch sub exch putinterval - /cc exch def - msgbits midlen cc putinterval - 0 1 barlen 1 sub { - /i exch def - (00000000) 8 string copy dup barcode i get cvi 2 8 string cvrs dup length 8 exch sub exch putinterval - msgbits midlen cclen add i 8 mul add 3 -1 roll putinterval - } for - msgbits midlen cclen add barlen 8 mul add term putinterval + % Pre-defined fixed length data field AIs + % any AI whose prefix is not included in this table must be + % terminated with "FNC1", even if it's fixed length + /aifixed 23 dict def + [ + 0 1 4 {} for + ] { + (00) 2 string copy dup dup 1 5 -1 roll 48 add put aifixed 3 1 roll put + } forall + [ + 11 1 20 {} for + 23 + 31 1 36 {} for + 41 + ] { + 10 2 string cvrs dup aifixed 3 1 roll put + } forall - } ifelse + % Append the remaining AI data + 0 1 ais length 1 sub { + /i exch def + /ai ais i get def + /val aival ai get def + gpf length ai length add val length add array + dup 0 gpf putinterval + dup gpf length ai [ exch {} forall ] putinterval + dup gpf length ai length add val [ exch {} forall ] putinterval + /gpf exch def + i ais length 1 sub ne aifixed ai 0 2 getinterval known not and { % Append FNC1 + gpf length 1 add array + dup 0 gpf putinterval + dup gpf length fnc1 put + /gpf exch def + } if + } for - % Lookup the most appropriate symbol specification - /metrics [ - % format vers size align modules error codewords error correction blocks - % L M Q H L1 L2 M1 M2 Q1 Q2 H1 H2 - [ (micro) (M1) 11 98 99 36 [ 2 99 99 99 ] [ 1 0 -1 -1 -1 -1 -1 -1 ] ] - [ (micro) (M2) 13 98 99 80 [ 5 6 99 99 ] [ 1 0 1 0 -1 -1 -1 -1 ] ] - [ (micro) (M3) 15 98 99 132 [ 6 8 99 99 ] [ 1 0 1 0 -1 -1 -1 -1 ] ] - [ (micro) (M4) 17 98 99 192 [ 8 10 14 99 ] [ 1 0 1 0 1 0 -1 -1 ] ] - [ (full) (1) 21 98 99 208 [ 7 10 13 17 ] [ 1 0 1 0 1 0 1 0 ] ] - [ (full) (2) 25 18 99 359 [ 10 16 22 28 ] [ 1 0 1 0 1 0 1 0 ] ] - [ (full) (3) 29 22 99 567 [ 15 26 36 44 ] [ 1 0 1 0 2 0 2 0 ] ] - [ (full) (4) 33 26 99 807 [ 20 36 52 64 ] [ 1 0 2 0 2 0 4 0 ] ] - [ (full) (5) 37 30 99 1079 [ 26 48 72 88 ] [ 1 0 2 0 2 2 2 2 ] ] - [ (full) (6) 41 34 99 1383 [ 36 64 96 112 ] [ 2 0 4 0 4 0 4 0 ] ] - [ (full) (7) 45 22 38 1568 [ 40 72 108 130 ] [ 2 0 4 0 2 4 4 1 ] ] - [ (full) (8) 49 24 42 1936 [ 48 88 132 156 ] [ 2 0 2 2 4 2 4 2 ] ] - [ (full) (9) 53 26 46 2336 [ 60 110 160 192 ] [ 2 0 3 2 4 4 4 4 ] ] - [ (full) (10) 57 28 50 2768 [ 72 130 192 224 ] [ 2 2 4 1 6 2 6 2 ] ] - [ (full) (11) 61 30 54 3232 [ 80 150 224 264 ] [ 4 0 1 4 4 4 3 8 ] ] - [ (full) (12) 65 32 58 3728 [ 96 176 260 308 ] [ 2 2 6 2 4 6 7 4 ] ] - [ (full) (13) 69 34 62 4256 [ 104 198 288 352 ] [ 4 0 8 1 8 4 12 4 ] ] - [ (full) (14) 73 26 46 4651 [ 120 216 320 384 ] [ 3 1 4 5 11 5 11 5 ] ] - [ (full) (15) 77 26 48 5243 [ 132 240 360 432 ] [ 5 1 5 5 5 7 11 7 ] ] - [ (full) (16) 81 26 50 5867 [ 144 280 408 480 ] [ 5 1 7 3 15 2 3 13 ] ] - [ (full) (17) 85 30 54 6523 [ 168 308 448 532 ] [ 1 5 10 1 1 15 2 17 ] ] - [ (full) (18) 89 30 56 7211 [ 180 338 504 588 ] [ 5 1 9 4 17 1 2 19 ] ] - [ (full) (19) 93 30 58 7931 [ 196 364 546 650 ] [ 3 4 3 11 17 4 9 16 ] ] - [ (full) (20) 97 34 62 8683 [ 224 416 600 700 ] [ 3 5 3 13 15 5 15 10 ] ] - [ (full) (21) 101 28 50 9252 [ 224 442 644 750 ] [ 4 4 17 0 17 6 19 6 ] ] - [ (full) (22) 105 26 50 10068 [ 252 476 690 816 ] [ 2 7 17 0 7 16 34 0 ] ] - [ (full) (23) 109 30 54 10916 [ 270 504 750 900 ] [ 4 5 4 14 11 14 16 14 ] ] - [ (full) (24) 113 28 54 11796 [ 300 560 810 960 ] [ 6 4 6 14 11 16 30 2 ] ] - [ (full) (25) 117 32 58 12708 [ 312 588 870 1050 ] [ 8 4 8 13 7 22 22 13 ] ] - [ (full) (26) 121 30 58 13652 [ 336 644 952 1110 ] [ 10 2 19 4 28 6 33 4 ] ] - [ (full) (27) 125 34 62 14628 [ 360 700 1020 1200 ] [ 8 4 22 3 8 26 12 28 ] ] - [ (full) (28) 129 26 50 15371 [ 390 728 1050 1260 ] [ 3 10 3 23 4 31 11 31 ] ] - [ (full) (29) 133 30 54 16411 [ 420 784 1140 1350 ] [ 7 7 21 7 1 37 19 26 ] ] - [ (full) (30) 137 26 52 17483 [ 450 812 1200 1440 ] [ 5 10 19 10 15 25 23 25 ] ] - [ (full) (31) 141 30 56 18587 [ 480 868 1290 1530 ] [ 13 3 2 29 42 1 23 28 ] ] - [ (full) (32) 145 34 60 19723 [ 510 924 1350 1620 ] [ 17 0 10 23 10 35 19 35 ] ] - [ (full) (33) 149 30 58 20891 [ 540 980 1440 1710 ] [ 17 1 14 21 29 19 11 46 ] ] - [ (full) (34) 153 34 62 22091 [ 570 1036 1530 1800 ] [ 13 6 14 23 44 7 59 1 ] ] - [ (full) (35) 157 30 54 23008 [ 570 1064 1590 1890 ] [ 12 7 12 26 39 14 22 41 ] ] - [ (full) (36) 161 24 50 24272 [ 600 1120 1680 1980 ] [ 6 14 6 34 46 10 2 64 ] ] - [ (full) (37) 165 28 54 25568 [ 630 1204 1770 2100 ] [ 17 4 29 14 49 10 24 46 ] ] - [ (full) (38) 169 32 58 26896 [ 660 1260 1860 2220 ] [ 4 18 13 32 48 14 42 32 ] ] - [ (full) (39) 173 26 54 28256 [ 720 1316 1950 2310 ] [ 20 4 40 7 43 22 10 67 ] ] - [ (full) (40) 177 30 58 29648 [ 750 1372 2040 2430 ] [ 19 6 18 31 34 34 20 61 ] ] - ] def - /eclval (LMQH) eclevel search pop length exch pop exch pop def - /i 0 def - { % loop - /m metrics i get def - /frmt m 0 get def % Format of the symbol - /vers m 1 get def % Version of symbol - /size m 2 get def % Length of side - /asp2 m 3 get def % Position of second alignment symbol - /asp3 m 4 get def % Position of third alignment symbol - /nmod m 5 get def % Number of modules - /ncws nmod 8 idiv def % Total number of codewords - /rbit nmod 8 mod def % Number of remainder bits - /lc4b false def % Last data codeword is 4 bits long - size 11 eq size 15 eq or { % Adjustments for M1 and M3 symbols - /ncws ncws 1 add def - /rbit 0 def - /lc4b true def + % Calculate the number of bits remaining to the next valid symbol size + /rembits { + /used exch def + ccversion (c) ne { % cc-a or cc-b + << + /a [ + [167 138 118 108 88 78 59] + [167 138 118 98 78] + [197 167 138 108 78] + ] + /b [ + [ 336 296 256 208 160 104 56] + [ 768 648 536 416 304 208 152 112 72 32] + [1184 1016 840 672 496 352 264 208 152 96 56] + ] + >> ccversion get cccolumns 2 sub get /bitcaps exch def + -1 bitcaps {dup used ge {exch} if pop} forall + dup -1 ne {used sub} if + } { + << /c -1 >> ccversion get pop % Assert cc-c + /m used 8 div ceiling cvi dup 6 idiv 5 mul exch 6 mod add def + m 40 le {8 } if + m 41 ge m 160 le and {16} if + m 161 ge m 320 le and {32} if + m 321 ge {64} if + /eccws exch def + /m m eccws add 3 add def + /c linwidth 52 sub 17 idiv def + m c idiv 90 gt {/c c 1 add def} if + /r m c div ceiling cvi def + /tgt c r mul eccws sub 3 sub dup 5 idiv 6 mul exch 5 mod add 8 mul def + used 8296 le {tgt used sub} {-1} ifelse + } ifelse + dup -1 eq { % Upgrade CC-A to CC-B or CC-B to CC-C to fit + pop + ccversion (a) eq { + /ccversion (b) def + } { + ccversion (b) eq lintype (gs1-128) eq and { + /ccversion (c) def + /cccolumns linwidth 52 sub 17 idiv def + } { + /ccversion -1 def + } ifelse + } ifelse + used rembits } if - /ecws m 6 get eclval get def % Number of error correction codewords - /dcws ncws ecws sub def % Number of data codewords - /dmod dcws 8 mul lc4b {4} {0} ifelse sub def % Number of data modules - /ecb1 m 7 get eclval 2 mul get def % First error correction blocks - /ecb2 m 7 get eclval 2 mul 1 add get def % Second error correction blocks - /okay true def - version vers ne {/okay false def} if % The version must match that supplied - msgbits length dmod gt {/okay false def} if % Bitstream must fit into data modules - ecb1 -1 eq ecb2 -1 eq or {/okay false def} if % Error correction level must be valid - okay {exit} if - /i i 1 add def + } bind def + + /encode { + dup /raw ne {exch get} {pop} ifelse + [ exch {48 sub} forall ] + dup length exch + gpfenc exch j exch putinterval + /j exch j add def + } bind def + + % Pre-compute alphanumeric and numeric runlengths and position of next ISO646-only characters + /numericruns [ gpf length {0} repeat 0 -1 ] def + /alphanumericruns [ gpf length {0} repeat 0 ] def + /nextiso646only [ gpf length {0} repeat 9999 ] def + gpf length 1 sub -1 0 { + /i exch def + gpf i get + (00) 2 string copy + dup 0 gpf i get dup fnc1 eq {pop 94} if put + i gpf length 1 sub lt {dup 1 gpf i 1 add get dup fnc1 eq {pop 94} if put} if + numeric exch known { + numericruns i numericruns i 2 add get 2 add put + } { + numericruns i 0 put + } ifelse + dup alphanumeric exch known { + alphanumericruns i alphanumericruns i 1 add get 1 add put + } { + alphanumericruns i 0 put + } ifelse + dup iso646 exch known exch alphanumeric exch known not and { + nextiso646only i 0 put + } { + nextiso646only i nextiso646only i 1 add get 1 add put + } ifelse + } for + + % Encode the general purpose field + /gpfenc 8296 array def + /i 0 def /j 0 def + { % loop + i gpf length eq {exit} if + { % not a loop but common exit point + + mode (numeric) eq { + i gpf length 2 sub le { + 2 string + dup 0 gpf i get dup fnc1 eq {pop 94} if put + dup 1 gpf i 1 add get dup fnc1 eq {pop 94} if put + dup numeric exch known { + numeric encode + /i i 2 add def + exit + } if + pop + lalphanumeric numeric encode + /mode (alphanumeric) def + exit + } { + gpf i get dup 48 lt exch 57 gt or { + lalphanumeric numeric encode + /mode (alphanumeric) def + exit + } if + /rem cdf length j add rembits def + rem 4 ge rem 6 le and { % C1 + 1 into 4 to 6 bits + (000000) 6 string copy 0 rem getinterval + dup gpf i get 47 sub 2 4 string cvrs + dup length 4 exch sub exch putinterval /raw encode + /i i 1 add def + exit + } { % C1.FNC1 + 2 string dup 0 gpf i get put dup 1 94 put numeric encode + /i i 1 add def + exit + } ifelse + } ifelse + } if + + mode (alphanumeric) eq { + gpf i get fnc1 eq { + fnc1 alphanumeric encode + /i i 1 add def + exit + } if + gpf i get dup iso646 exch known exch alphanumeric exch known not and { + liso646 alphanumeric encode + /mode (iso646) def + exit + } if + numericruns i get 6 ge { + lnumeric alphanumeric encode + /mode (numeric) def + exit + } if + numericruns i get dup 4 ge exch i add gpf length eq and { + lnumeric alphanumeric encode + /mode (numeric) def + exit + } if + gpf i get alphanumeric encode + /i i 1 add def + exit + } if + + mode (iso646) eq { + gpf i get fnc1 eq { + fnc1 iso646 encode + /i i 1 add def + exit + } if + numericruns i get 4 ge nextiso646only i get 10 ge and { + lnumeric iso646 encode + /mode (numeric) def + exit + } if + alphanumericruns i get 5 ge nextiso646only i get 10 ge and { + lalphanumeric iso646 encode + /mode (alphanumeric) def + exit + } if + gpf i get iso646 encode + /i i 1 add def + exit + } if + + } loop } loop - /format frmt def - /version vers def - /dcpb dcws ecb1 ecb2 add idiv def % Base data codewords per block - /ecpb ncws ecb1 ecb2 add idiv dcpb sub def % Error correction codewords per block - - % Expand the message bits by adding padding as necessary - /pad dmod string def - 0 4 dmod 1 sub {pad exch (0000) putinterval} for - pad 0 msgbits putinterval - /padstrs [ (11101100) (00010001) ] def - /padnum 0 def - msgbits length 8 div ceiling 8 mul cvi 8 dmod lc4b {5} {1} ifelse sub { - pad exch padstrs padnum get putinterval - /padnum padnum 1 add 2 mod def - } for + /gpf gpfenc 0 j getinterval def - % Evaluate the padded message into codewords - /cws dcws array def - 0 1 cws length 1 sub { - /c exch def - /bpcw 8 def - lc4b c cws length 1 sub eq and {/bpcw 4 def} if - /cwb pad c 8 mul bpcw getinterval def - /cw 0 def - 0 1 bpcw 1 sub { + % Create pad + /pad cdf length gpf length add rembits array def + pad length 0 gt { + 0 5 pad length 1 sub { % Fill with 00100 /i exch def - /cw cw 2 bpcw i sub 1 sub exp cvi cwb i get 48 sub mul add def - } for - cws c cw put - } for - - % Calculate the log and anti-log tables - /rsalog [ 1 255 { dup 2 mul dup 256 ge {285 xor} if } repeat ] def - /rslog 256 array def - 1 1 255 {dup rsalog exch get exch rslog 3 1 roll put} for - - % Function to calculate the product in the field - /rsprod { - 2 copy 0 ne exch 0 ne and { - rslog exch get exch rslog exch get add 255 mod rsalog exch get - } { - pop pop 0 - } ifelse - } bind def - - % Generate the coefficients for the Reed-Solomon algorithm - /coeffs [ 1 ecpb {0} repeat ] def - 0 1 ecpb 1 sub { - /i exch def - coeffs i 1 add coeffs i get put - i -1 1 { - /j exch def - coeffs j coeffs j 1 sub get coeffs j get rsalog i get rsprod xor put + pad i [ 0 0 1 0 0 ] 0 pad length i sub 5 2 copy gt {exch} if pop getinterval putinterval } for - coeffs 0 coeffs 0 get rsalog i get rsprod put - } for - /coeffs coeffs 0 coeffs length 1 sub getinterval def + mode (numeric) eq { % Prefix shift from numeric to ASCII + /pad [ 0 0 0 0 pad aload pop ] 0 pad length getinterval def + } if + mode (alpha) eq { % Prefix FNC1 + /pad [ 1 1 1 1 1 pad aload pop ] 0 pad length getinterval def + } if + } if - % Reed-Solomon algorithm to derive the error correction codewords - /rscodes { - /rscws exch def - /rsnd rscws length def - /rscws [ rscws {} forall ecpb {0} repeat ] def - 0 1 rsnd 1 sub { - /m exch def - /k rscws m get def - 0 1 ecpb 1 sub { - /j exch def - rscws m j add 1 add coeffs ecpb j sub 1 sub get k rsprod rscws m j add 1 add get xor put - } for - } for - rscws rsnd ecpb getinterval - } bind def + % Concatinate fields + /bits [ + cdf aload pop + gpf aload pop + pad aload pop + ] def - % Divide codewords into two groups of blocks and calculate the error correction codewords - /dcwsb ecb1 ecb2 add array def - /ecwsb ecb1 ecb2 add array def - 0 1 ecb1 1 sub { % First group of blocks has smaller number of data codewords - /i exch def - dcwsb i cws i dcpb mul dcpb getinterval put - ecwsb i dcwsb i get rscodes put - } for - 0 1 ecb2 1 sub { % Second group of blocks has larger number of data codewords - /i exch def - dcwsb ecb1 i add cws ecb1 dcpb mul i dcpb 1 add mul add dcpb 1 add getinterval put - ecwsb ecb1 i add dcwsb ecb1 i add get rscodes put - } for - - % Reassemble the codewords - /cws ncws array def - /cw 0 def - 0 1 dcpb { % Interleave the data codeword blocks - /i exch def - 0 1 ecb1 ecb2 add 1 sub { - /j exch def - i dcwsb j get length lt { % Ignore the end of short blocks - cws cw dcwsb j get i get put - /cw cw 1 add def - } if - } for - } for - 0 1 ecpb 1 sub { % Interleave the error codeword blocks - /i exch def - 0 1 ecb1 ecb2 add 1 sub { + ccversion (a) eq { + /pwr928 [ + [ 0 0 0 0 0 0 1 ] + 68 {7 array} repeat + ] def + 1 1 68 { /j exch def - cws cw ecwsb j get i get put - /cw cw 1 add def + /v 0 def + 6 -1 1 { + /i exch def + /v pwr928 j 1 sub get i get 2 mul v 928 idiv add def + pwr928 j get i v 928 mod put + } for + pwr928 j get 0 pwr928 j 1 sub get 0 get 2 mul v 928 idiv add put } for - } for - - % Extend codewords by one if there are remainder bits - rbit 0 gt { - /pad cws length 1 add array def - pad 0 cws putinterval - pad pad length 1 sub 0 put - /cws pad def - } if - - % Fixups for the short final data byte in M1 and M3 symbols - lc4b { - dcws 1 sub 1 ncws 2 sub { + /cws [ 28 {0} repeat ] def + /b 0 def /c 0 def + { % loop + b bits length eq {exit} if + /bs bits b 69 bits length b sub 2 copy gt {exch} if pop getinterval def + /bsl bs length def + /cs cws c bsl 10 idiv 1 add getinterval def + /csl cs length def + 0 1 bsl 1 sub { + /i exch def + 0 1 csl 1 sub { + /j exch def + cs j 2 copy get + pwr928 i get j 7 add csl sub get + bs bsl i sub 1 sub get + mul add put + } for + } for + csl 1 sub -1 1 { + /i exch def + cs i 1 sub 2 copy get cs i get 928 idiv add put + cs i 2 copy get 928 mod put + } for + /b b bsl add def + /c c csl add def + } loop + /cws cws 0 c getinterval def + /barcode cws length 4 mul string def + 0 1 cws length 1 sub { /i exch def - cws i cws i get 15 and 4 bitshift put - cws i cws i 1 add get -4 bitshift 15 and cws i get or put + (^ ) 4 string copy dup cws i get 10 4 string cvrs + dup length 4 exch sub exch putinterval + barcode i 4 mul 3 -1 roll putinterval } for - cws ncws 1 sub cws ncws 1 sub get 15 and 4 bitshift put + options (dontdraw) true put + options (cca) true put + options (columns) cccolumns put + /args barcode options //micropdf417 exec def } if - % Create the bitmap - /pixs [ size size mul {-1} repeat ] def - /qmv {size mul add} bind def - - % Finder patterns - /fpat [ - [ 1 1 1 1 1 1 1 0 ] - [ 1 0 0 0 0 0 1 0 ] - [ 1 0 1 1 1 0 1 0 ] - [ 1 0 1 1 1 0 1 0 ] - [ 1 0 1 1 1 0 1 0 ] - [ 1 0 0 0 0 0 1 0 ] - [ 1 1 1 1 1 1 1 0 ] - [ 0 0 0 0 0 0 0 0 ] - ] def - 0 1 fpat length 1 sub { - /y exch def - 0 1 fpat 0 get length 1 sub { - /x exch def - /fpb fpat y get x get def - pixs x y qmv fpb put - format (full) eq { - pixs size x sub 1 sub y qmv fpb put - pixs x size y sub 1 sub qmv fpb put - } if - } for - } for - - % Alignment patterns - /algnpat [ - [ 1 1 1 1 1 ] - [ 1 0 0 0 1 ] - [ 1 0 1 0 1 ] - [ 1 0 0 0 1 ] - [ 1 1 1 1 1 ] - ] def - /putalgnpat { - /py exch def - /px exch def - 0 1 4 { - /pb exch def - 0 1 4 { - /pa exch def - pixs px pa add py pb add qmv algnpat pb get pa get put - } for - } for - } bind def - asp2 2 sub asp3 asp2 sub size 13 sub { - /i exch def - i 4 putalgnpat - 4 i putalgnpat - } for - asp2 2 sub asp3 asp2 sub size 9 sub { - /x exch def - asp2 2 sub asp3 asp2 sub size 9 sub { - /y exch def - x y putalgnpat - } for - } for - - % Timing patterns - format (full) eq { - 8 1 size 9 sub { + ccversion (b) eq { + /barcode bits length 8 idiv string def + 0 1 barcode length 1 sub { /i exch def - pixs i 6 qmv i 1 add 2 mod put - pixs 6 i qmv i 1 add 2 mod put + bits i 8 mul 8 getinterval 0 exch {add 2 mul} forall 2 idiv + barcode exch i exch put } for - } { - 8 1 size 1 sub { + options (dontdraw) true put + options (ccb) true put + options (columns) cccolumns put + /args barcode options //micropdf417 exec def + } if + + ccversion (c) eq { + /barcode bits length 8 idiv string def + 0 1 barcode length 1 sub { /i exch def - pixs i 0 qmv i 1 add 2 mod put - pixs 0 i qmv i 1 add 2 mod put + bits i 8 mul 8 getinterval 0 exch {add 2 mul} forall 2 idiv + barcode exch i exch put } for - } ifelse - - % Format information modules - format (full) eq { - /formatmap [ - [ [ 0 8 ] [ 8 size 1 sub ] ] [ [ 1 8 ] [ 8 size 2 sub ] ] [ [ 2 8 ] [ 8 size 3 sub ] ] - [ [ 3 8 ] [ 8 size 4 sub ] ] [ [ 4 8 ] [ 8 size 5 sub ] ] [ [ 5 8 ] [ 8 size 6 sub ] ] - [ [ 7 8 ] [ 8 size 7 sub ] ] [ [ 8 8 ] [ size 8 sub 8 ] ] [ [ 8 7 ] [ size 7 sub 8 ] ] - [ [ 8 5 ] [ size 6 sub 8 ] ] [ [ 8 4 ] [ size 5 sub 8 ] ] [ [ 8 3 ] [ size 4 sub 8 ] ] - [ [ 8 2 ] [ size 3 sub 8 ] ] [ [ 8 1 ] [ size 2 sub 8 ] ] [ [ 8 0 ] [ size 1 sub 8 ] ] - ] def + options (dontdraw) true put + options (ccc) true put + options (columns) cccolumns put + /args barcode options //pdf417 exec def + } if + + args + dontdraw not //renmatrix if + + end + +} bind def +/gs1-cc dup load /uk.co.terryburton.bwipp defineresource pop +end +/setpacking where {pop setpacking} if +% --END ENCODER gs1-cc-- + +% --BEGIN ENCODER ean13composite-- +% --REQUIRES ean13 micropdf417 pdf417 gs1-cc-- +% --SUGGESTS ean5 ean2-- +% --DESC: EAN-13 Composite +% --EXAM: 331234567890|(99)1234-abcd +% --EXOP: includetext +% --RNDR: renlinear renmatrix +/setpacking where {pop currentpacking true setpacking} if +2 dict +dup /ean13 dup /uk.co.terryburton.bwipp findresource put +dup /gs1-cc dup /uk.co.terryburton.bwipp findresource put +dup /renlinear dup /uk.co.terryburton.bwipp findresource put +dup /renmatrix dup /uk.co.terryburton.bwipp findresource put +begin +/ean13composite { + + 20 dict begin % Confine variables to local scope + + /options exch def + /barcode exch def + + /dontdraw false def + + % Parse the input options + options type /stringtype eq { + 1 dict begin + options { + token false eq {exit} if dup length string cvs (=) search + true eq {cvlit exch pop exch def} {cvlit true def} ifelse + } loop + currentdict end /options exch def + } if + options {def} forall + + % Split the linear and composite parts + barcode (|) search { + /linear exch def + pop + /comp exch def } { - /formatmap [ - [ [ 1 8 ] ] [ [ 2 8 ] ] [ [ 3 8 ] ] [ [ 4 8 ] ] [ [ 5 8 ] ] - [ [ 6 8 ] ] [ [ 7 8 ] ] [ [ 8 8 ] ] [ [ 8 7 ] ] [ [ 8 6 ] ] - [ [ 8 5 ] ] [ [ 8 4 ] ] [ [ 8 3 ] ] [ [ 8 2 ] ] [ [ 8 1 ] ] - ] def + pop } ifelse - formatmap { - { {} forall qmv pixs exch 0 put } forall - } forall - - % Version information modules - size 45 ge { - /versionmap [ - [ [ size 9 sub 5 ] [ 5 size 9 sub ] ] [ [ size 10 sub 5 ] [ 5 size 10 sub ] ] - [ [ size 11 sub 5 ] [ 5 size 11 sub ] ] [ [ size 9 sub 4 ] [ 4 size 9 sub ] ] - [ [ size 10 sub 4 ] [ 4 size 10 sub ] ] [ [ size 11 sub 4 ] [ 4 size 11 sub ] ] - [ [ size 9 sub 3 ] [ 3 size 9 sub ] ] [ [ size 10 sub 3 ] [ 3 size 10 sub ] ] - [ [ size 11 sub 3 ] [ 3 size 11 sub ] ] [ [ size 9 sub 2 ] [ 2 size 9 sub ] ] - [ [ size 10 sub 2 ] [ 2 size 10 sub ] ] [ [ size 11 sub 2 ] [ 2 size 11 sub ] ] - [ [ size 9 sub 1 ] [ 1 size 9 sub ] ] [ [ size 10 sub 1 ] [ 1 size 10 sub ] ] - [ [ size 11 sub 1 ] [ 1 size 11 sub ] ] [ [ size 9 sub 0 ] [ 0 size 9 sub ] ] - [ [ size 10 sub 0 ] [ 0 size 10 sub ] ] [ [ size 11 sub 0 ] [ 0 size 11 sub ] ] - ] def + + gsave + + options (lintype) (ean13) put + options (inkspread) (0) put + options (dontdraw) true put + + % Plot the linear part + linear options //ean13 exec //renlinear exec + + % Plot the separator + -1 72 rmoveto << + /ren //renmatrix + /pixs [ + 0 1 93 {0} repeat 1 0 + 1 0 93 {0} repeat 0 1 + 0 1 93 {0} repeat 1 0 + ] + /pixx 97 + /pixy 3 + /height 6 72 div + /width 97 72 div + /opt options + >> //renmatrix exec + + % Plot the 2D part + -2 6 rmoveto comp options //gs1-cc exec //renmatrix exec + + grestore + + end + +} bind def +/ean13composite dup load /uk.co.terryburton.bwipp defineresource pop +end +/setpacking where {pop setpacking} if +% --END ENCODER ean13composite-- + +% --BEGIN ENCODER ean8composite-- +% --REQUIRES ean8 micropdf417 pdf417 gs1-cc-- +% --SUGGESTS ean5 ean2-- +% --DESC: EAN-8 Composite +% --EXAM: 12345670|(21)A12345678 +% --EXOP: includetext +% --RNDR: renlinear renmatrix +/setpacking where {pop currentpacking true setpacking} if +2 dict +dup /ean8 dup /uk.co.terryburton.bwipp findresource put +dup /gs1-cc dup /uk.co.terryburton.bwipp findresource put +dup /renlinear dup /uk.co.terryburton.bwipp findresource put +dup /renmatrix dup /uk.co.terryburton.bwipp findresource put +begin +/ean8composite { + + 20 dict begin % Confine variables to local scope + + /options exch def + /barcode exch def + + /dontdraw false def + + % Parse the input options + options type /stringtype eq { + 1 dict begin + options { + token false eq {exit} if dup length string cvs (=) search + true eq {cvlit exch pop exch def} {cvlit true def} ifelse + } loop + currentdict end /options exch def + } if + options {def} forall + + % Split the linear and composite parts + barcode (|) search { + /linear exch def + pop + /comp exch def } { - /versionmap [] def + pop } ifelse - versionmap { - { {} forall qmv pixs exch 0 put } forall - } forall - - % Solitary dark module in full symbols - format (full) eq { - pixs 8 size 8 sub qmv 1 put + + gsave + + % Get the result of encoding with ean8 and gs1-cc + options (lintype) (ean8) put + options (inkspread) (0) put + options (dontdraw) true put + + % Plot the linear part + linear options //ean8 exec //renlinear exec + + % Plot the separator + -1 72 rmoveto << + /ren //renmatrix + /pixs [ + 0 1 65 {0} repeat 1 0 + 1 0 65 {0} repeat 0 1 + 0 1 65 {0} repeat 1 0 + ] + /pixx 69 + /pixy 3 + /height 6 72 div + /width 69 72 div + /opt options + >> //renmatrix exec + + % Plot the 2D part + comp options //gs1-cc exec + dup (pixx) get 69 exch sub 6 rmoveto + //renmatrix exec + + grestore + + end + +} bind def +/ean8composite dup load /uk.co.terryburton.bwipp defineresource pop +end +/setpacking where {pop setpacking} if +% --END ENCODER ean8composite-- + +% --BEGIN ENCODER upcacomposite-- +% --REQUIRES upca micropdf417 pdf417 gs1-cc-- +% --SUGGESTS ean5 ean2-- +% --DESC: UPC-A Composite +% --EXAM: 01600033610|(99)1234-abcd +% --EXOP: includetext +% --RNDR: renlinear renmatrix +/setpacking where {pop currentpacking true setpacking} if +2 dict +dup /upca dup /uk.co.terryburton.bwipp findresource put +dup /gs1-cc dup /uk.co.terryburton.bwipp findresource put +dup /renlinear dup /uk.co.terryburton.bwipp findresource put +dup /renmatrix dup /uk.co.terryburton.bwipp findresource put +begin +/upcacomposite { + + 20 dict begin % Confine variables to local scope + + /options exch def + /barcode exch def + + /dontdraw false def + + % Parse the input options + options type /stringtype eq { + 1 dict begin + options { + token false eq {exit} if dup length string cvs (=) search + true eq {cvlit exch pop exch def} {cvlit true def} ifelse + } loop + currentdict end /options exch def } if - - % Calculate the mask patterns - format (full) eq { - /maskfuncs [ - {add 2 mod} bind - {exch pop 2 mod} bind - {pop 3 mod} bind - {add 3 mod} bind - {2 idiv exch 3 idiv add 2 mod} bind - {mul dup 2 mod exch 3 mod add} bind - {mul dup 2 mod exch 3 mod add 2 mod} bind - {2 copy mul 3 mod 3 1 roll add 2 mod add 2 mod} bind - ] def + options {def} forall + + % Split the linear and composite parts + barcode (|) search { + /linear exch def + pop + /comp exch def } { - /maskfuncs [ - {exch pop 2 mod} bind - {2 idiv exch 3 idiv add 2 mod} bind - {mul dup 2 mod exch 3 mod add 2 mod} bind - {2 copy mul 3 mod 3 1 roll add 2 mod add 2 mod} bind - ] def + pop } ifelse - /masks maskfuncs length array def - 0 1 masks length 1 sub { - /m exch def - /mask size size mul array def - 0 1 size 1 sub { - /j exch def - 0 1 size 1 sub { - /i exch def - i j maskfuncs m get exec 0 eq - pixs i j qmv get -1 eq and {1} {0} ifelse - mask i j qmv 3 -1 roll put - } for - } for - masks m mask put - } for - - % Walk the symbol placing the bitstream - /posx size 1 sub def - /posy size 1 sub def - /dir -1 def % -1 is upwards, 1 is downwards - /col 1 def % 0 is left bit, 1 is right bit - /num 0 def - { % loop - posx 0 lt {exit} if - pixs posx posy qmv get -1 eq { - cws num 8 idiv get 7 num 8 mod sub neg bitshift 1 and - pixs posx posy qmv 3 -1 roll put - /num num 1 add def - } if - col 1 eq { - /col 0 def - /posx posx 1 sub def - } { - /col 1 def - /posx posx 1 add def - /posy posy dir add def - posy 0 lt posy size ge or { % Turn around at top and bottom - /dir dir -1 mul def - /posy posy dir add def - /posx posx 2 sub def - % Hop over the timing pattern in full size symbols - format (full) eq posx 6 eq and {/posx posx 1 sub def} if - } if - } ifelse - } loop - % Evaluate runlength encoded rows or columns in full symbols - /evalfulln1n3 { - /scrle exch def - % Detect runs of 5 or more like modules - /scr1 0 scrle { dup 5 ge {add 2 sub dup} if pop } forall def - % Detect 1:1:3:1:1 ratio next to 4 modules of whitespace - /scr3 0 def - 3 2 scrle length 3 sub { % Scan odd (dark) runs within bounds - /j exch def - scrle j get 3 mod 0 eq { % Multiple of 3 black modules - /fact scrle j get 3 idiv def - scrle j 2 sub 5 getinterval {fact eq} forall and exch pop and and { - j 3 eq j 4 add scrle length ge or { % At either extent of run - /scr3 scr3 40 add def - } { % Bounded by dark modules - scrle j 3 sub get 4 ge scrle j 3 add get 4 ge or { - /scr3 scr3 40 add def - } if - } ifelse - } if - } if + gsave + + options (lintype) (ean13) put + options (inkspread) (0) put + options (dontdraw) true put + + % Plot the linear part + linear options //upca exec //renlinear exec + + % Plot the separator + -1 72 rmoveto << + /ren //renmatrix + /pixs [ + 0 1 93 {0} repeat 1 0 + 1 0 93 {0} repeat 0 1 + 0 1 93 {0} repeat 1 0 + ] + /pixx 97 + /pixy 3 + /height 6 72 div + /width 97 72 div + /opt options + >> //renmatrix exec + + % Plot the 2D part + -2 6 rmoveto comp options //gs1-cc exec //renmatrix exec + + grestore + + end + +} bind def +/upcacomposite dup load /uk.co.terryburton.bwipp defineresource pop +end +/setpacking where {pop setpacking} if +% --END ENCODER upcacomposite-- + +% --BEGIN ENCODER upcecomposite-- +% --REQUIRES upce micropdf417 pdf417 gs1-cc-- +% --SUGGESTS ean5 ean2-- +% --DESC: UPC-E Composite +% --EXAM: 0121230|(15)021231 +% --EXOP: includetext +% --RNDR: renlinear renmatrix +/setpacking where {pop currentpacking true setpacking} if +2 dict +dup /upce dup /uk.co.terryburton.bwipp findresource put +dup /gs1-cc dup /uk.co.terryburton.bwipp findresource put +dup /renlinear dup /uk.co.terryburton.bwipp findresource put +dup /renmatrix dup /uk.co.terryburton.bwipp findresource put +begin +/upcecomposite { + + 20 dict begin % Confine variables to local scope + + /options exch def + /barcode exch def + + /dontdraw false def + + % Parse the input options + options type /stringtype eq { + 1 dict begin + options { + token false eq {exit} if dup length string cvs (=) search + true eq {cvlit exch pop exch def} {cvlit true def} ifelse + } loop + currentdict end /options exch def + } if + options {def} forall + + % Split the linear and composite parts + barcode (|) search { + /linear exch def + pop + /comp exch def + } { + pop + } ifelse + + % Define the separator + /sep << + /ren //renmatrix + /pixs [ + 0 1 49 {0} repeat 1 0 + 1 0 49 {0} repeat 0 1 + 0 1 49 {0} repeat 1 0 + ] + /pixx 53 + /pixy 3 + /height 6 72 div + /width 53 72 div + /opt options + >> def + + gsave + + options (lintype) (upce) put + options (inkspread) (0) put + options (dontdraw) true put + + % Plot the linear part + linear options //upce exec //renlinear exec + + % Plot the separator + -1 72 rmoveto << + /ren //renmatrix + /pixs [ + 0 1 49 {0} repeat 1 0 + 1 0 49 {0} repeat 0 1 + 0 1 49 {0} repeat 1 0 + ] + /pixx 53 + /pixy 3 + /height 6 72 div + /width 53 72 div + /opt options + >> //renmatrix exec + + % Plot the 2D part + -2 6 rmoveto comp options //gs1-cc exec //renmatrix exec + + grestore + + end + +} bind def +/upcecomposite dup load /uk.co.terryburton.bwipp defineresource pop +end +/setpacking where {pop setpacking} if +% --END ENCODER upcecomposite-- + +% --BEGIN ENCODER databaromnicomposite-- +% --REQUIRES databaromni micropdf417 pdf417 gs1-cc-- +% --DESC: GS1 DataBar Omnidirectional Composite +% --EXAM: (01)03612345678904|(11)990102 +% --EXOP: +% --RNDR: renlinear renmatrix +/setpacking where {pop currentpacking true setpacking} if +2 dict +dup /databaromni dup /uk.co.terryburton.bwipp findresource put +dup /gs1-cc dup /uk.co.terryburton.bwipp findresource put +dup /renlinear dup /uk.co.terryburton.bwipp findresource put +dup /renmatrix dup /uk.co.terryburton.bwipp findresource put +begin +/databaromnicomposite { + + 20 dict begin % Confine variables to local scope + + /options exch def + /barcode exch def + + /dontdraw false def + + % Parse the input options + options type /stringtype eq { + 1 dict begin + options { + token false eq {exit} if dup length string cvs (=) search + true eq {cvlit exch pop exch def} {cvlit true def} ifelse + } loop + currentdict end /options exch def + } if + options {def} forall + + % Split the linear and composite parts + barcode (|) search { + /linear exch def + pop + /comp exch def + } { + pop + } ifelse + + gsave + + options (lintype) (databaromni) put + options (linkage) true put + options (inkspread) (0) put + options (dontdraw) true put + + % Plot the linear part + linear options //databaromni exec + dup (sbs) get /linsbs exch def + dup (bhs) get 0 get 72 mul /linheight exch def + //renlinear exec + + % Plot the separator + /sepfinder { + /fp exch def + fp 1 fp 12 add { + /i exch def + bot i get 0 eq { + bot i 1 sub get 1 eq { + 1 + } { + sep i 1 sub get 0 eq {1} {0} ifelse + } ifelse + } { + 0 + } ifelse + sep exch i exch put } for - scr1 scr3 + /f3 [1 1 1 1 1 1 1 1 1 0 1 1 1] def + true 0 1 12 {dup bot exch fp add get exch f3 exch get eq and} for { + % Right shifted module for value 3 finder + sep fp [ 0 0 0 0 0 0 0 0 0 0 1 0 0 ] putinterval + } if } bind def - - % Evaluation algorithm for full symbols - /evalfull { - /sym exch def + mark + 0 linsbs {1 index 1 eq {{0}} {{1}} ifelse repeat} forall + counttomark 1 sub array astore /bot exch def pop pop + /sep [ bot {1 exch sub} forall ] def + sep 0 [0 0 0] putinterval + sep sep length 4 sub [0 0 0 0] putinterval + 18 sepfinder 64 sepfinder + 0 linheight rmoveto << + /ren //renmatrix + /pixs sep + /pixx sep length + /pixy 1 + /height 1 72 div + /width sep length 72 div + /opt options + >> //renmatrix exec - /n1 0 def /n2 0 def /n3 0 def - /rle size array def - /lastpairs size array def - /thispairs size array def - /sizeadd1 size 1 add def - 0 1 size 1 sub { - /i exch def + % Plot the 2D part + -5 1 rmoveto comp options //gs1-cc exec //renmatrix exec - % Runlength encode (light, dark, light, ...) and evaluate each column - mark 0 0 - i size dup dup mul 1 sub { - sym exch get exch 1 index eq {exch 1 add exch} {1 exch} ifelse - } for - pop - rle 0 counttomark 2 sub getinterval astore - evalfulln1n3 n3 add /n3 exch def n1 add /n1 exch def - pop + grestore - % Runlength encode (light, dark, light, ...) and evaluate each row - /symrow sym i size mul size getinterval def - mark 0 0 - symrow { - exch 1 index eq {exch 1 add exch} {1 exch} ifelse - } forall - pop - rle 0 counttomark 2 sub getinterval astore - evalfulln1n3 n3 add /n3 exch def n1 add /n1 exch def - pop + end - % Count and score same coloured blocks - /lastpairs thispairs /thispairs lastpairs def def - symrow 0 get 1 eq {0} {1} ifelse - symrow {exch 1 index add exch} forall - pop - thispairs astore pop - i 0 gt { - mark - lastpairs aload pop thispairs aload pop - n2 size { exch sizeadd1 index add 3 and 0 eq {3 add} if } repeat - /n2 exch def - cleartomark - } if +} bind def +/databaromnicomposite dup load /uk.co.terryburton.bwipp defineresource pop +end +/setpacking where {pop setpacking} if +% --END ENCODER databaromnicomposite-- + +% --BEGIN ENCODER databarstackedcomposite-- +% --REQUIRES databaromni databarstacked micropdf417 pdf417 gs1-cc-- +% --DESC: GS1 DataBar Stacked Composite +% --EXAM: (01)03412345678900|(17)010200 +% --EXOP: +% --RNDR: renlinear renmatrix +/setpacking where {pop currentpacking true setpacking} if +2 dict +dup /databarstacked dup /uk.co.terryburton.bwipp findresource put +dup /gs1-cc dup /uk.co.terryburton.bwipp findresource put +dup /renmatrix dup /uk.co.terryburton.bwipp findresource put +begin +/databarstackedcomposite { - } for - - % Score dark/light imbalance - /dark 0 sym {add} forall def - /n4 dark 100 mul size dup mul div 50 sub abs 5 div cvi 10 mul def + 20 dict begin % Confine variables to local scope - n1 n2 add n3 add n4 add - } bind def + /options exch def + /barcode exch def + + /dontdraw false def - % Evaluation algorithm for micro symbols - /evalmicro { - /sym exch def - /dkrhs 0 def /dkbot 0 def - 1 1 size 1 sub { + % Parse the input options + options type /stringtype eq { + 1 dict begin + options { + token false eq {exit} if dup length string cvs (=) search + true eq {cvlit exch pop exch def} {cvlit true def} ifelse + } loop + currentdict end /options exch def + } if + options {def} forall + + % Split the linear and composite parts + barcode (|) search { + /linear exch def + pop + /comp exch def + } { + pop + } ifelse + + gsave + + options (lintype) (databarstacked) put + options (linkage) true put + options (inkspread) (0) put + options (dontdraw) true put + + % Plot the linear part + linear options //databarstacked exec + dup (pixs) get 0 2 index (pixx) get getinterval /bot exch def + dup (pixy) get /linheight exch def + //renmatrix exec + + % Plot the separator + /sepfinder { + /fp exch def + fp 1 fp 12 add { /i exch def - /dkrhs dkrhs sym size 1 sub i qmv get add def - /dkbot dkbot sym i size 1 sub qmv get add def + bot i get 0 eq { + bot i 1 sub get 1 eq { + 1 + } { + sep i 1 sub get 0 eq {1} {0} ifelse + } ifelse + } { + 0 + } ifelse + sep exch i exch put } for - dkrhs dkbot le { - dkrhs 16 mul dkbot add neg - } { - dkbot 16 mul dkrhs add neg - } ifelse + /f3 [1 1 1 1 1 1 1 1 1 0 1 1 1] def + true 0 1 12 {dup bot exch fp add get exch f3 exch get eq and} for { + % Right shifted module for value 3 finder + sep fp [ 0 0 0 0 0 0 0 0 0 0 1 0 0 ] putinterval + } if } bind def - - % Evaluate the masked symbols to find the most suitable - /bestscore 999999999 def - 0 1 masks length 1 sub { - /m exch def - /masksym size size mul array def - 0 1 size size mul 1 sub { + /sep [ bot {1 exch sub} forall ] def + sep 0 [ 0 0 0 0 ] putinterval + sep sep length 4 sub [ 0 0 0 0 ] putinterval + 18 sepfinder + 0 linheight rmoveto << + /ren //renmatrix + /pixs sep + /pixx sep length + /pixy 1 + /height 1 72 div + /width sep length 72 div + /opt options + >> //renmatrix exec + + % Plot the 2D part + 1 1 rmoveto comp options //gs1-cc exec //renmatrix exec + + grestore + + end + +} bind def +/databarstackedcomposite dup load /uk.co.terryburton.bwipp defineresource pop +end +/setpacking where {pop setpacking} if +% --END ENCODER databarstackedcomposite-- + +% --BEGIN ENCODER databarstackedomnicomposite-- +% --REQUIRES databaromni databarstackedomni micropdf417 pdf417 gs1-cc-- +% --DESC: GS1 DataBar Stacked Omnidirectional Composite +% --EXAM: (01)03612345678904|(11)990102 +% --EXOP: +% --RNDR: renlinear renmatrix +/setpacking where {pop currentpacking true setpacking} if +2 dict +dup /databarstackedomni dup /uk.co.terryburton.bwipp findresource put +dup /gs1-cc dup /uk.co.terryburton.bwipp findresource put +dup /renmatrix dup /uk.co.terryburton.bwipp findresource put +begin +/databarstackedomnicomposite { + + 20 dict begin % Confine variables to local scope + + /options exch def + /barcode exch def + + /dontdraw false def + + % Parse the input options + options type /stringtype eq { + 1 dict begin + options { + token false eq {exit} if dup length string cvs (=) search + true eq {cvlit exch pop exch def} {cvlit true def} ifelse + } loop + currentdict end /options exch def + } if + options {def} forall + + % Split the linear and composite parts + barcode (|) search { + /linear exch def + pop + /comp exch def + } { + pop + } ifelse + + gsave + + options (lintype) (databarstackedomni) put + options (linkage) true put + options (inkspread) (0) put + options (dontdraw) true put + + % Plot the linear part + linear options //databarstackedomni exec + dup (pixs) get 0 2 index (pixx) get getinterval /bot exch def + dup (pixy) get /linheight exch def + //renmatrix exec + + % Plot the separator + /sepfinder { + /fp exch def + fp 1 fp 12 add { /i exch def - masksym i pixs i get masks m get i get xor put + bot i get 0 eq { + bot i 1 sub get 1 eq { + 1 + } { + sep i 1 sub get 0 eq {1} {0} ifelse + } ifelse + } { + 0 + } ifelse + sep exch i exch put } for - format (full) eq { - masksym evalfull /score exch def - } { - masksym evalmicro /score exch def - } ifelse - score bestscore lt { - /bestsym masksym def - /bestmaskval m def - /bestscore score def - } if - } for - /pixs bestsym def - - % Add the format information - format (full) eq { - /fmtvals [ - 16#5412 16#5125 16#5e7c 16#5b4b 16#45f9 16#40ce 16#4f97 16#4aa0 - 16#77c4 16#72f3 16#7daa 16#789d 16#662f 16#6318 16#6c41 16#6976 - 16#1689 16#13be 16#1ce7 16#19d0 16#0762 16#0255 16#0d0c 16#083b - 16#355f 16#3068 16#3f31 16#3a06 16#24b4 16#2183 16#2eda 16#2bed - ] def - /ecid (MLHQ) eclevel search pop length exch pop exch pop def - /fmtval fmtvals ecid 3 bitshift bestmaskval add get def - } { - /fmtvals [ - 16#4445 16#4172 16#4e2b 16#4b1c 16#55ae 16#5099 16#5fc0 16#5af7 - 16#6793 16#62a4 16#6dfd 16#68ca 16#7678 16#734f 16#7c16 16#7921 - 16#06de 16#03e9 16#0cb0 16#0987 16#1735 16#1202 16#1d5b 16#186c - 16#2508 16#203f 16#2f66 16#2a51 16#34e3 16#31d4 16#3e8d 16#3bba - ] def - /symid [ [0] [1 2] [3 4] [5 6 7] ] size 11 sub 2 idiv get eclval get def - /fmtval fmtvals symid 2 bitshift bestmaskval add get def + /f3 [1 1 1 1 1 1 1 1 1 0 1 1 1] def + true 0 1 12 {dup bot exch fp add get exch f3 exch get eq and} for { + % Right shifted module for value 3 finder + sep fp [ 0 0 0 0 0 0 0 0 0 0 1 0 0 ] putinterval + } if + } bind def + /sep [ bot {1 exch sub} forall ] def + sep 0 [ 0 0 0 ] putinterval + sep sep length 4 sub [ 0 0 0 0 ] putinterval + 18 sepfinder + 0 linheight rmoveto << + /ren //renmatrix + /pixs sep + /pixx sep length + /pixy 1 + /height 1 72 div + /width sep length 72 div + /opt options + >> //renmatrix exec + + % Plot the 2D part + 1 1 rmoveto comp options //gs1-cc exec //renmatrix exec + + grestore + + end + +} bind def +/databarstackedomnicomposite dup load /uk.co.terryburton.bwipp defineresource pop +end +/setpacking where {pop setpacking} if +% --END ENCODER databarstackedomnicomposite-- + +% --BEGIN ENCODER databartruncatedcomposite-- +% --REQUIRES databaromni databartruncated micropdf417 pdf417 gs1-cc-- +% --DESC: GS1 DataBar Truncated Composite +% --EXAM: (01)03612345678904|(11)990102 +% --EXOP: +% --RNDR: renlinear renmatrix +/setpacking where {pop currentpacking true setpacking} if +2 dict +dup /databartruncated dup /uk.co.terryburton.bwipp findresource put +dup /gs1-cc dup /uk.co.terryburton.bwipp findresource put +dup /renlinear dup /uk.co.terryburton.bwipp findresource put +dup /renmatrix dup /uk.co.terryburton.bwipp findresource put +begin +/databartruncatedcomposite { + + 20 dict begin % Confine variables to local scope + + /options exch def + /barcode exch def + + /dontdraw false def + + % Parse the input options + options type /stringtype eq { + 1 dict begin + options { + token false eq {exit} if dup length string cvs (=) search + true eq {cvlit exch pop exch def} {cvlit true def} ifelse + } loop + currentdict end /options exch def + } if + options {def} forall + + % Split the linear and composite parts + barcode (|) search { + /linear exch def + pop + /comp exch def + } { + pop } ifelse - 0 1 formatmap length 1 sub { - /i exch def - formatmap i get { - pixs exch {} forall qmv fmtval 14 i sub neg bitshift 1 and put - } forall - } for - - % Add the version information - size 45 ge { - /vervals [ - 16#07c94 16#085bc 16#09a99 16#0a4d3 16#0bbf6 16#0c762 16#0d847 - 16#0e60d 16#0f928 16#10b78 16#1145d 16#12a17 16#13532 16#149a6 - 16#15683 16#168c9 16#177ec 16#18ec4 16#191e1 16#1afab 16#1b08e - 16#1cc1a 16#1d33f 16#1ed75 16#1f250 16#209d5 16#216fd 16#228ba - 16#2379f 16#24b0b 16#2542e 16#26a64 16#27541 16#28c69 - ] def - /verval vervals size 17 sub 4 idiv 7 sub get def - 0 1 versionmap length 1 sub { + + gsave + + options (lintype) (databartruncated) put + options (linkage) true put + options (inkspread) (0) put + options (dontdraw) true put + + % Plot the linear part + linear options //databartruncated exec + dup (sbs) get /linsbs exch def + dup (bhs) get 0 get 72 mul /linheight exch def + //renlinear exec + + % Plot the separator + /sepfinder { + /fp exch def + fp 1 fp 12 add { /i exch def - versionmap i get { - pixs exch {} forall qmv verval 17 i sub neg bitshift 1 and put - } forall + bot i get 0 eq { + bot i 1 sub get 1 eq { + 1 + } { + sep i 1 sub get 0 eq {1} {0} ifelse + } ifelse + } { + 0 + } ifelse + sep exch i exch put } for - } if + /f3 [1 1 1 1 1 1 1 1 1 0 1 1 1] def + true 0 1 12 {dup bot exch fp add get exch f3 exch get eq and} for { + % Right shifted module for value 3 finder + sep fp [ 0 0 0 0 0 0 0 0 0 0 1 0 0 ] putinterval + } if + } bind def + mark + 0 linsbs {1 index 1 eq {{0}} {{1}} ifelse repeat} forall + counttomark 1 sub array astore /bot exch def pop pop + /sep [ bot {1 exch sub} forall ] def + sep 0 [0 0 0] putinterval + sep sep length 4 sub [0 0 0 0] putinterval + 18 sepfinder 64 sepfinder + 0 linheight rmoveto << + /ren //renmatrix + /pixs sep + /pixx sep length + /pixy 1 + /height 1 72 div + /width sep length 72 div + /opt options + >> //renmatrix exec - % Return the arguments - << - /ren (renmatrix) - /pixs pixs - /pixx size - /pixy size - /height size 2 mul 72 div - /width size 2 mul 72 div - /opt options - >> + % Plot the 2D part + -5 1 rmoveto comp options //gs1-cc exec //renmatrix exec - dontdraw not //renmatrix if + grestore end } bind def -% --END ENCODER qrcode-- - -% --BEGIN ENCODER maxicode-- -% --DESC: MaxiCode -% --EXAM: [\)>^03001^02996152382802^029840^029001^0291Z00004951^029UPSN^02906X610^029159^0291234567^0291/1^029^029Y^029634 ALPHA DR^029PITTSBURGH^029PA^029^004 -% --EXOP: mode=2 parse -% --RNDR: renmaximatrix -/maxicode { +/databartruncatedcomposite dup load /uk.co.terryburton.bwipp defineresource pop +end +/setpacking where {pop setpacking} if +% --END ENCODER databartruncatedcomposite-- + +% --BEGIN ENCODER databarlimitedcomposite-- +% --REQUIRES databarlimited micropdf417 pdf417 gs1-cc-- +% --DESC: GS1 DataBar Limited Composite +% --EXAM: (01)03512345678907|(21)abcdefghijklmnopqrstuv +% --EXOP: +% --RNDR: renlinear renmatrix +/setpacking where {pop currentpacking true setpacking} if +2 dict +dup /databarlimited dup /uk.co.terryburton.bwipp findresource put +dup /gs1-cc dup /uk.co.terryburton.bwipp findresource put +dup /renlinear dup /uk.co.terryburton.bwipp findresource put +dup /renmatrix dup /uk.co.terryburton.bwipp findresource put +begin +/databarlimitedcomposite { - 20 dict begin + 20 dict begin % Confine variables to local scope - /options exch def % We are given an option string - /barcode exch def % We are given a barcode string + /options exch def + /barcode exch def /dontdraw false def - /mode -1 def - /sam -1 def - /parse false def - + % Parse the input options options type /stringtype eq { 1 dict begin @@ -7136,572 +16195,629 @@ } if options {def} forall - /mode mode cvi def - /sam sam cvi def + % Split the linear and composite parts + barcode (|) search { + /linear exch def + pop + /comp exch def + } { + pop + } ifelse - % Parse ordinals of the form ^NNN to ASCII - parse { - /msg barcode length string def - /j 0 def - barcode - { % loop - (^) search { - dup msg exch j exch putinterval - length j add 1 add /j exch def - pop - dup 0 3 getinterval cvi msg exch j 1 sub exch put - dup length 3 sub 3 exch getinterval - } { - dup msg exch j exch putinterval - length j add /j exch def - /barcode msg 0 j getinterval def - exit - } ifelse - } loop - } if - - /msg barcode def - /msglen msg length def + gsave - % Special message handling for modes 2 and 3 - mode 2 eq mode 3 eq or { + options (lintype) (databarlimited) put + options (linkage) true put + options (inkspread) (0) put + options (dontdraw) true put - % Normalise messages that begin with a field identifier [)>RS01GSyy - msg 0 7 getinterval <5b293e1e30311d> eq { - /fid msg 0 9 getinterval def - /msg msg 9 msglen 9 sub getinterval def - } { - /fid () def - } ifelse + % Plot the linear part + linear options //databarlimited exec + dup (sbs) get /linsbs exch def + dup (bhs) get 0 get 72 mul /linheight exch def + //renlinear exec + + % Plot the separator + mark + 1 linsbs {1 index 0 eq {{1}} {{0}} ifelse repeat} forall + counttomark 1 sub array astore /sep exch def pop pop + sep 0 [0 0 0] putinterval + sep sep length 4 sub [0 0 0 0] putinterval + 0 linheight rmoveto << + /ren //renmatrix + /pixs sep + /pixx sep length + /pixy 1 + /height 1 72 div + /width sep length 72 div + /opt options + >> //renmatrix exec - % Read the postcode, country code and service code fields seperated by GS - msg <1d> search pop /pcode exch def - pop <1d> search pop /ccode exch def - pop <1d> search pop /scode exch def - pop /msg exch def + % Plot the 2D part + comp options //gs1-cc exec + dup (pixx) get 72 exch sub 1 rmoveto + //renmatrix exec - % Prepend the field identifier - msg length fid length add string dup - 0 fid putinterval dup - fid length msg putinterval - /msg exch def - /msglen msg length def + grestore + + end +} bind def +/databarlimitedcomposite dup load /uk.co.terryburton.bwipp defineresource pop +end +/setpacking where {pop setpacking} if +% --END ENCODER databarlimitedcomposite-- + +% --BEGIN ENCODER databarexpandedcomposite-- +% --REQUIRES databarexpanded micropdf417 pdf417 gs1-cc-- +% --DESC: GS1 DataBar Expanded Composite +% --EXAM: (01)93712345678904(3103)001234|(91)1A2B3C4D5E +% --EXOP: +% --RNDR: renlinear renmatrix +/setpacking where {pop currentpacking true setpacking} if +2 dict +dup /databarexpanded dup /uk.co.terryburton.bwipp findresource put +dup /gs1-cc dup /uk.co.terryburton.bwipp findresource put +dup /renlinear dup /uk.co.terryburton.bwipp findresource put +dup /renmatrix dup /uk.co.terryburton.bwipp findresource put +begin +/databarexpandedcomposite { + + 20 dict begin % Confine variables to local scope + + /options exch def + /barcode exch def + + /dontdraw false def + + % Parse the input options + options type /stringtype eq { + 1 dict begin + options { + token false eq {exit} if dup length string cvs (=) search + true eq {cvlit exch pop exch def} {cvlit true def} ifelse + } loop + currentdict end /options exch def } if + options {def} forall - % Special function characters - /eci -1 def /pad -2 def /ns -3 def - /la -4 def /lb -5 def - /sa -6 def /sb -7 def /sc -8 def /sd -9 def /se -10 def - /sa2 -11 def /sa3 -12 def - /lkc -13 def /lkd -14 def /lke -15 def - /pd2 -16 def /pd3 -17 def - - % Character maps for each state - /charmaps [ - % A B C D E - [ 13 (`) 192 224 0 ] % 0 - [ (A) (a) 193 225 1 ] % 1 - [ (B) (b) 194 226 2 ] % 2 - [ (C) (c) 195 227 3 ] % 3 - [ (D) (d) 196 228 4 ] % 4 - [ (E) (e) 197 229 5 ] % 5 - [ (F) (f) 198 230 6 ] % 6 - [ (G) (g) 199 231 7 ] % 7 - [ (H) (h) 200 232 8 ] % 8 - [ (I) (i) 201 233 9 ] % 9 - [ (J) (j) 202 234 10 ] % 10 - [ (K) (k) 203 235 11 ] % 11 - [ (L) (l) 204 236 12 ] % 12 - [ (M) (m) 205 237 13 ] % 13 - [ (N) (n) 206 238 14 ] % 14 - [ (O) (o) 207 239 15 ] % 15 - [ (P) (p) 208 240 16 ] % 16 - [ (Q) (q) 209 241 17 ] % 17 - [ (R) (r) 210 242 18 ] % 18 - [ (S) (s) 211 243 19 ] % 19 - [ (T) (t) 212 244 20 ] % 20 - [ (U) (u) 213 245 21 ] % 21 - [ (V) (v) 214 246 22 ] % 22 - [ (W) (w) 215 247 23 ] % 23 - [ (X) (x) 216 248 24 ] % 24 - [ (Y) (y) 217 249 25 ] % 25 - [ (Z) (z) 218 250 26 ] % 26 - [ eci eci eci eci eci ] % 27 - [ 28 28 28 28 pad ] % 28 - [ 29 29 29 29 pad ] % 29 - [ 30 30 30 30 27 ] % 30 - [ ns ns ns ns ns ] % 31 - [ ( ) ({) 219 251 28 ] % 32 - [ pad pad 220 252 29 ] % 33 - [ (") (}) 221 253 30 ] % 34 - [ (#) (~) 222 254 31 ] % 35 - [ ($) 127 223 255 159 ] % 36 - [ (%) (;) 170 161 160 ] % 37 - [ (&) (<) 172 168 162 ] % 38 - [ (') (=) 177 171 163 ] % 39 - [ 40 (>) 178 175 164 ] % 40 - [ 41 (?) 179 176 165 ] % 41 - [ (*) ([) 181 180 166 ] % 42 - [ (+) 92 185 183 167 ] % 43 - [ (,) (]) 186 184 169 ] % 44 - [ (-) (^) 188 187 173 ] % 45 - [ (.) (_) 189 191 174 ] % 46 - [ (/) ( ) 190 138 182 ] % 47 - [ (0) (,) 128 139 149 ] % 48 - [ (1) (.) 129 140 150 ] % 49 - [ (2) (/) 130 141 151 ] % 50 - [ (3) (:) 131 142 152 ] % 51 - [ (4) (@) 132 143 153 ] % 52 - [ (5) (!) 133 144 154 ] % 53 - [ (6) (|) 134 145 155 ] % 54 - [ (7) pd2 135 146 156 ] % 55 - [ (8) sa2 136 147 157 ] % 56 - [ (9) sa3 137 148 158 ] % 57 - [ (:) pd3 la la la ] % 58 - [ sb sa ( ) ( ) ( ) ] % 59 - [ sc sc lkc sc sc ] % 60 - [ sd sd sd lkd sd ] % 61 - [ se se se se lke ] % 62 - [ lb la lb lb lb ] % 63 - ] def - - % Invert charmaps to give character to value maps for each state - /charvals [ 64 dict 64 dict 64 dict 64 dict 64 dict ] def - 0 1 charmaps length 1 sub { - /i exch def - /encs charmaps i get def - 0 1 4 { - /j exch def - encs j get dup type /stringtype eq {0 get} if % convert string to ASCII if required - charvals j get exch i put + % Split the linear and composite parts + barcode (|) search { + /linear exch def + pop + /comp exch def + } { + pop + } ifelse + + gsave + + options (lintype) (databarexpanded) put + options (linkage) true put + options (inkspread) (0) put + options (dontdraw) true put + + % Plot the linear part + linear options //databarexpanded exec + dup (sbs) get /linsbs exch def + dup (bhs) get 0 get 72 mul /linheight exch def + //renlinear exec + + % Plot the separator + /sepfinder { + /fp exch def + fp 1 fp 12 add { + /i exch def + bot i get 0 eq { + bot i 1 sub get 1 eq { + 1 + } { + sep i 1 sub get 0 eq {1} {0} ifelse + } ifelse + } { + 0 + } ifelse + sep exch i exch put } for - } for - /seta charvals 0 get def - /setb charvals 1 get def - /setc charvals 2 get def - /setd charvals 3 get def - /sete charvals 4 get def + } bind def + mark + 0 linsbs {1 index 1 eq {{0}} {{1}} ifelse repeat} forall + counttomark 1 sub array astore /bot exch def pop pop + /sep [ bot {1 exch sub} forall ] def + sep 0 [0 0 0] putinterval + sep sep length 4 sub [0 0 0 0] putinterval + [ % Finder pattern module positions + 18 98 bot length 13 sub {} for + 69 98 bot length 13 sub {} for + ] {sepfinder} forall + 0 linheight rmoveto << + /ren //renmatrix + /pixs sep + /pixx sep length + /pixy 1 + /height 1 72 div + /width sep length 72 div + /opt options + >> //renmatrix exec - % Compute numeric runlengths - /nseq [ msglen 1 add {0} repeat ] def - msglen 1 sub -1 0 { - /i exch def - msg i get dup 48 ge exch 57 le and { - nseq i nseq i 1 add get 1 add put - } { - nseq i 0 put - } ifelse - } for - /nseq nseq 0 msglen getinterval def + % Plot the 2D part + 1 1 rmoveto comp options //gs1-cc exec //renmatrix exec - % Encode the message from ASCII to codewords - /prefixinset { - 0 { - 2 copy exch length ge {exit} if - 2 copy get 3 index exch known {1 add} {exit} ifelse + grestore + + end + +} bind def +/databarexpandedcomposite dup load /uk.co.terryburton.bwipp defineresource pop +end +/setpacking where {pop setpacking} if +% --END ENCODER databarexpandedcomposite-- + +% --BEGIN ENCODER databarexpandedstackedcomposite-- +% --REQUIRES databarexpanded databarexpandedstacked micropdf417 pdf417 gs1-cc-- +% --DESC: GS1 DataBar Expanded Stacked Composite +% --EXAM: (01)00012345678905(10)ABCDEF|(21)12345678 +% --EXOP: segments=4 +% --RNDR: renmatrix renlinear +/setpacking where {pop currentpacking true setpacking} if +2 dict +dup /databarexpandedstacked dup /uk.co.terryburton.bwipp findresource put +dup /gs1-cc dup /uk.co.terryburton.bwipp findresource put +dup /renmatrix dup /uk.co.terryburton.bwipp findresource put +begin +/databarexpandedstackedcomposite { + + 20 dict begin % Confine variables to local scope + + /options exch def + /barcode exch def + + /dontdraw false def + + % Parse the input options + options type /stringtype eq { + 1 dict begin + options { + token false eq {exit} if dup length string cvs (=) search + true eq {cvlit exch pop exch def} {cvlit true def} ifelse } loop - exch pop exch pop - } bind def - - /enc { - exch get out exch j exch put - /j j 1 add def - } bind def + currentdict end /options exch def + } if + options {def} forall - /out 144 array def - /i 0 def /j 0 def /cset (seta) def - { % loop - % Exit when no characters remain latching back to A if necessary - i msglen eq { - cset (seta) ne cset (setb) ne and { - la cset load enc - /cset (seta) def - } if - exit - } if - { % not a loop but common exit point - - % If 9 numerals available then use NS - nseq i get 9 ge { - msg i 9 getinterval cvi 4 { dup 63 and exch -6 bitshift } repeat cset load ns get - 0 2 10 {index} for 6 array astore 7 1 roll 6 {pop} repeat - out exch j exch putinterval - /i i 9 add def - /j j 6 add def - exit - } if - - % Read next three characters - /char1 msg i get def - /char2 i 1 add msglen lt {msg i 1 add get} {-99} ifelse def - /char3 i 2 add msglen lt {msg i 2 add get} {-99} ifelse def - - % If current mode is sufficient then directly encode - cset load char1 known { - char1 cset load enc - /i i 1 add def - exit - } if - - % For switching from A to B - cset (seta) eq setb char1 known and { - setb char2 known { - lb seta enc - /cset (setb) def + % Split the linear and composite parts + barcode (|) search { + /linear exch def + pop + /comp exch def + } { + pop + } ifelse + + gsave + + options (lintype) (databarexpandedstacked) put + options (linkage) true put + options (inkspread) (0) put + options (dontdraw) true put + + % Plot the linear part + linear options //databarexpandedstacked exec + dup (pixs) get 0 2 index (pixx) get getinterval /bot exch def + dup (pixy) get /linheight exch def + //renmatrix exec + + % Plot the separator + /sepfinder { + /fp exch def + fp 1 fp 12 add { + /i exch def + bot i get 0 eq { + bot i 1 sub get 1 eq { + 1 } { - sb seta enc - char1 setb enc - /i i 1 add def + sep i 1 sub get 0 eq {1} {0} ifelse } ifelse - exit - } if - - % For switching from B to A encode according to length of prefix - cset (setb) eq seta char1 known and { - /p seta msg i 4 msglen i sub 2 copy gt {exch} if pop getinterval prefixinset def - p 1 eq { - sa setb enc - char1 seta enc - /i i 1 add def - } if - p 2 eq { - sa2 setb enc - char1 seta enc - char2 seta enc - /i i 2 add def - } if - p 3 eq { - sa3 setb enc - char1 seta enc - char2 seta enc - char3 seta enc - /i i 3 add def - } if - p 4 ge { - la setb enc - /cset (seta) def - } if - exit - } if - - % If character is in A or B then directly latch - seta char1 known { - la cset load enc - /cset (seta) def - exit - } if - setb char1 known { - lb cset load enc - /cset (setb) def - exit - } if - - % Determine which one of sets C, D or E the character is in - setc char1 known {/setx (setc) def /sx sc def /lkx lkc def} if - setd char1 known {/setx (setd) def /sx sd def /lkx lkd def} if - sete char1 known {/setx (sete) def /sx se def /lkx lke def} if - - % Encode according to the length of the prefix - /p setx load msg i 4 msglen i sub 2 copy gt {exch} if pop getinterval prefixinset def - p 1 eq { - sx cset load enc - char1 setx load enc - /i i 1 add def - } if - p 2 eq { - sx cset load enc - char1 setx load enc - sx cset load enc - char2 setx load enc - /i i 2 add def - } if - p 3 eq { - sx cset load enc - char1 setx load enc - sx cset load enc - char2 setx load enc - sx cset load enc - char3 setx load enc - /i i 3 add def - } if - p 4 ge { - sx cset load enc - lkx setx load enc - /cset setx def - } if - - exit - } loop % out - } loop - /encmsg out 0 j getinterval def - /padval cset load pad get def + } { + 0 + } ifelse + sep exch i exch put + } for + } bind def + /sep [ bot {1 exch sub} forall ] def + sep 0 [ 0 0 0 ] putinterval + sep sep length 4 sub [ 0 0 0 0 ] putinterval + [ % Finder pattern module positions + 19 98 bot length 13 sub {} for + 70 98 bot length 13 sub {} for + ] {sepfinder} forall + 0 linheight rmoveto << + /ren //renmatrix + /pixs sep + /pixx sep length + /pixy 1 + /height 1 72 div + /width sep length 72 div + /opt options + >> //renmatrix exec - % Prefix the encoded message with the structured append insert - /sami [] def - sam -1 ne { - /sami 2 array def - sami 0 seta pad get put - sami 1 sam 10 idiv 1 sub 8 mul sam 10 mod 1 sub add put + % Plot the 2D part + bot 0 get 0 eq {2} {0} ifelse 1 rmoveto + comp options //gs1-cc exec //renmatrix exec + + grestore + + end + +} bind def +/databarexpandedstackedcomposite dup load /uk.co.terryburton.bwipp defineresource pop +end +/setpacking where {pop setpacking} if +% --END ENCODER databarexpandedstackedcomposite-- + +% --BEGIN ENCODER gs1-128composite-- +% --REQUIRES code128 gs1-128 micropdf417 pdf417 gs1-cc-- +% --DESC: GS1-128 Composite +% --EXAM: (00)030123456789012340|(02)13012345678909(37)24(10)1234567ABCDEFG +% --EXOP: ccversion=c +% --RNDR: renlinear renmatrix +/setpacking where {pop currentpacking true setpacking} if +2 dict +dup /gs1-128 dup /uk.co.terryburton.bwipp findresource put +dup /gs1-cc dup /uk.co.terryburton.bwipp findresource put +dup /renlinear dup /uk.co.terryburton.bwipp findresource put +dup /renmatrix dup /uk.co.terryburton.bwipp findresource put +begin +/gs1-128composite { + + 20 dict begin % Confine variables to local scope + + /options exch def + /barcode exch def + + /dontdraw false def + + % Parse the input options + options type /stringtype eq { + 1 dict begin + options { + token false eq {exit} if dup length string cvs (=) search + true eq {cvlit exch pop exch def} {cvlit true def} ifelse + } loop + currentdict end /options exch def + } if + options {def} forall + + % Split the linear and composite parts + barcode (|) search { + /linear exch def + pop + /comp exch def + } { + pop + } ifelse + + gsave + + options (inkspread) (0) put + options (dontdraw) true put + + % Dummy plot of linear part with CC-A to get width + options (linkagea) true put + linear << options {} forall >> //gs1-128 exec + (sbs) get 0 exch {add} forall /linwidth exch def + + % Create 2D part and determine type + options (lintype) (gs1-128) put + options (linwidth) linwidth put + comp options //gs1-cc exec /compsym exch def + compsym (pixx) get 99 eq {(a)} {(c)} ifelse /linktype exch def + + % Plot linear part + linktype (a) eq { + options (linkagea) true put + options (linkagec) false put + } { + options (linkagea) false put + options (linkagec) true put + } ifelse + linear << options {} forall >> //gs1-128 exec + dup (sbs) get /linsbs exch def + dup (bhs) get 0 get 72 mul /linheight exch def + //renlinear exec + + % Plot the separator + mark + 1 linsbs {1 index 0 eq {{1}} {{0}} ifelse repeat} forall + counttomark 1 sub array astore /sep exch def pop pop + 0 linheight rmoveto << + /ren //renmatrix + /pixs sep + /pixx sep length + /pixy 1 + /height 1 72 div + /width sep length 72 div + /opt options + >> //renmatrix exec + + % Plot the 2D part + linktype (a) eq { + /s linwidth 2 sub 11 idiv def + /p s 9 sub 2 idiv def + /x s p sub 1 sub 11 mul 10 add p 0 eq {2 add} if 99 sub def + x 1 rmoveto + } { + -7 1 rmoveto + } ifelse + + compsym //renmatrix exec + + grestore + + end + +} bind def +/gs1-128composite dup load /uk.co.terryburton.bwipp defineresource pop +end +/setpacking where {pop setpacking} if +% --END ENCODER gs1-128composite-- + +% --BEGIN ENCODER hibccode39-- +% --REQUIRES code39-- +% --DESC: HIBC Code 39 +% --EXAM: A123BJC5D6E71 +% --EXOP: includetext +% --RNDR: renlinear +/setpacking where {pop currentpacking true setpacking} if +1 dict +dup /renlinear dup /uk.co.terryburton.bwipp findresource put +dup /code39 dup /uk.co.terryburton.bwipp findresource put +begin +/hibccode39 { + + 20 dict begin % Confine variables to local scope + + /options exch def % We are given an option string + /barcode exch def % We are given a barcode string + + /dontdraw false def + /textfont /Courier def + /textsize 10 def + /textyoffset -7 def + /textxoffset 0 def + + % Parse the input options + options type /stringtype eq { + 1 dict begin + options { + token false eq {exit} if dup length string cvs (=) search + true eq {cvlit exch pop exch def} {cvlit true def} ifelse + } loop + currentdict end /options exch def } if - /encmsg [ sami aload pop encmsg aload pop ] def + options {def} forall - % Derive the primary and secondary codewords for modes 2 and 3 - mode 2 eq mode 3 eq or { + /textfont textfont cvlit def + /textsize textsize cvr def + /textyoffset textyoffset cvr def + /textxoffset textxoffset cvr def - % Calculate the fixed-width binary values for the mode, postcode, country code and service - /mdb (0000) 4 string copy dup mode cvi 2 4 string cvrs dup length 4 exch sub exch putinterval def - /ccb (0000000000) 10 string copy dup ccode cvi 2 10 string cvrs dup length 10 exch sub exch putinterval def - /scb (0000000000) 10 string copy dup scode cvi 2 10 string cvrs dup length 10 exch sub exch putinterval def - /pcb (000000000000000000000000000000000000) 36 string copy def - mode 2 eq { - % For numeric postcode, first six bits represent length and remaining 30 bits the value - pcb pcode length 2 6 string cvrs dup length 6 exch sub exch putinterval - pcb pcode cvi 2 30 string cvrs dup length 36 exch sub exch putinterval - } { % mode=3 - % For alphanumeric postcode, trim or pad with spaces to 6 chars and encode to binary - /pccw [ - ( ) 6 string copy dup 0 pcode length 6 gt {pcode 0 6 getinterval} {pcode} ifelse putinterval - {seta exch get} forall - ] def - 0 1 5 { - /i exch def - pcb pccw i get 2 6 string cvrs dup length 6 i mul 6 add exch sub exch putinterval - } for - } ifelse + /barlen barcode length def - % Convolute the binary values into the structured carrier message - /scm 60 string def - scm 2 mdb putinterval - scm 38 pcb 0 4 getinterval putinterval - scm 30 pcb 4 6 getinterval putinterval - scm 24 pcb 10 6 getinterval putinterval - scm 18 pcb 16 6 getinterval putinterval - scm 12 pcb 22 6 getinterval putinterval - scm 6 pcb 28 6 getinterval putinterval - scm 0 pcb 34 2 getinterval putinterval - scm 52 ccb 0 2 getinterval putinterval - scm 42 ccb 2 6 getinterval putinterval - scm 36 ccb 8 2 getinterval putinterval - scm 54 scb 0 6 getinterval putinterval - scm 48 scb 6 4 getinterval putinterval + /barchars (0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ-. $/+%) def - % Evaluate the structured carrier message as codewords - /pri [ 0 0 0 0 0 0 0 0 0 0 ] def - 0 1 59 { - /i exch def - /ps i 6 idiv def - /ep 2 5 i 6 mod sub exp cvi scm i get 48 sub mul def - pri ps pri ps get ep add put - } for + /barcode barlen 2 add string dup 1 barcode putinterval def + barcode 0 43 put - % Pad the encoded message into the secondary component - /sec [ 84 {padval} repeat ] def - sec 0 encmsg putinterval + /checksum 0 def + 0 1 barlen { + /i exch def + % Lookup the encoding for the each barcode character + barcode i 1 getinterval barchars exch search + pop % Discard true leaving pre + length /indx exch def % indx is the length of pre + pop pop % Discard seek and post + /checksum checksum indx add def + } for + barcode barlen 1 add barchars checksum 43 mod get put - } if + /text barlen 4 add string def + text 0 42 put + text 1 barcode putinterval + text barlen 2 add barcode barlen 1 add get dup 32 eq {pop 95} if put + text barlen 3 add 42 put - % Derive the primary and secondary codewords for modes 4, 5 and 6 - mode 4 eq mode 5 eq or mode 6 eq or mode -1 eq or { + % Get the result of encoding with code39 + options (dontdraw) true put + options (includecheck) false put + /args barcode options //code39 exec def - % If mode isn't specified then use EEC if message fits, otherwise SEC - mode -1 eq { - /mode encmsg length 77 le {5} {4} ifelse def - } if + args (txt) [ [text textxoffset textyoffset textfont textsize] ] put + args (textxalign) (center) put + args (opt) options put + args + + dontdraw not //renlinear if - % First symbol is the mode and the remainder are the padded message - /cws [ mode 5 eq {78} {94} ifelse {padval} repeat ] def - cws 0 mode put - cws 1 encmsg putinterval + end - % Fit the message into the primary and secondary components - /pri cws 0 10 getinterval def - /sec cws 10 cws length 10 sub getinterval def +} bind def +/hibccode39 dup load /uk.co.terryburton.bwipp defineresource pop +end +/setpacking where {pop setpacking} if +% --END ENCODER hibccode39-- + +% --BEGIN ENCODER hibccode128-- +% --REQUIRES code128-- +% --DESC: HIBC Code 128 +% --EXAM: A123BJC5D6E71 +% --EXOP: includetext +% --RNDR: renlinear +/setpacking where {pop currentpacking true setpacking} if +1 dict +dup /renlinear dup /uk.co.terryburton.bwipp findresource put +dup /code128 dup /uk.co.terryburton.bwipp findresource put +begin +/hibccode128 { + 20 dict begin % Confine variables to local scope + + /options exch def % We are given an option string + /barcode exch def % We are given a barcode string + + /dontdraw false def + /textfont /Courier def + /textsize 10 def + /textyoffset -7 def + /textxoffset 0 def + + % Parse the input options + options type /stringtype eq { + 1 dict begin + options { + token false eq {exit} if dup length string cvs (=) search + true eq {cvlit exch pop exch def} {cvlit true def} ifelse + } loop + currentdict end /options exch def } if + options {def} forall - % Create the 64x64 Reed-Solomon table - /rstable 64 64 mul array def - rstable 0 [ 64 {0} repeat ] putinterval - rstable 64 [ 0 1 63 {} for ] putinterval - /prev 1 def - 64 { - /next prev 1 bitshift def - next 64 and 0 ne { - /next next 67 xor def - } if - 0 1 63 { - /j exch def - /nextcell {rstable 64 next mul j add} def - nextcell rstable 64 prev mul j add get 1 bitshift put - nextcell get 64 and 0 ne { - nextcell nextcell get 67 xor put - } if - } for - /prev next def - } repeat + /textfont textfont cvlit def + /textsize textsize cvr def + /textyoffset textyoffset cvr def + /textxoffset textxoffset cvr def - % Calculate the parity codewords for primary codewords - /pgen [46 44 49 3 2 57 42 39 28 31 1] def - /rscodes [ 10 {0} repeat 9 -1 0 { pri exch get } for ] def - rscodes length 11 sub -1 0 { - /i exch def - 0 1 10 { - /j exch def - rscodes i j add rscodes i j add get - rstable 64 pgen j get mul rscodes i 10 add get add get - xor put - } for - } for - /prichk [ 9 -1 0 { rscodes exch get } for ] def + /barlen barcode length def - % Split secondary codeword into odd and even elements - /seco [ 0 2 sec length 1 sub { sec exch get } for ] def - /sece [ 1 2 sec length 1 sub { sec exch get } for ] def + /barchars (0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ-. $/+%) def - % Calculate the parity codewords for secondary codeword parts based on mode - sec length 84 eq { % SEC mode - /sgen [ 59 23 19 31 33 38 17 22 48 15 36 57 37 22 8 27 33 11 44 23 1 ] def - } { % EEC mode - /sgen [ 28 11 20 7 43 9 41 34 49 46 37 40 55 34 45 61 13 23 29 22 10 35 55 41 10 53 45 22 1 ] def - } ifelse - /scodes sgen length 1 sub def - /rscodes [ scodes {0} repeat seco length 1 sub -1 0 { seco exch get } for ] def - rscodes length scodes sub 1 sub -1 0 { - /i exch def - 0 1 scodes { - /j exch def - rscodes i j add rscodes i j add get - rstable 64 sgen j get mul rscodes i scodes add get add get - xor put - } for - } for - /secochk [ scodes 1 sub -1 0 { rscodes exch get } for ] def - /rscodes [ scodes {0} repeat sece length 1 sub -1 0 { sece exch get } for ] def - rscodes length scodes sub 1 sub -1 0 { + /barcode barlen 2 add string dup 1 barcode putinterval def + barcode 0 43 put + + /checksum 0 def + 0 1 barlen { /i exch def - 0 1 scodes { - /j exch def - rscodes i j add rscodes i j add get - rstable 64 sgen j get mul rscodes i scodes add get add get - xor put - } for + % Lookup the encoding for the each barcode character + barcode i 1 getinterval barchars exch search + pop % Discard true leaving pre + length /indx exch def % indx is the length of pre + pop pop % Discard seek and post + /checksum checksum indx add def } for - /secechk [ scodes 1 sub -1 0 { rscodes exch get } for ] def + barcode barlen 1 add barchars checksum 43 mod get put - % Recompose the secondary parity codewords - /secchk [ 0 1 scodes 1 sub { dup secochk exch get exch secechk exch get } for ] def + /text barlen 4 add string def + text 0 42 put + text 1 barcode putinterval + text barlen 2 add barcode barlen 1 add get dup 32 eq {pop 95} if put + text barlen 3 add 42 put - % Concatinate the data into final codewords - /codewords [ - pri {} forall - prichk {} forall - sec {} forall - secchk {} forall - ] def + % Get the result of encoding with code128 + options (dontdraw) true put + /args barcode options //code128 exec def - % Convert the codewords into module bits - /mods [ 864 {0} repeat ] def - 0 1 143 { - /i exch def - /cw [ codewords i get 2 6 string cvrs {48 sub} forall ] def - mods 6 i mul 6 cw length sub add cw putinterval - } for + args (txt) [ [text textxoffset textyoffset textfont textsize] ] put + args (textxalign) (center) put + args (opt) options put + args + + dontdraw not //renlinear if - % Maps modules to pixels in the grid - /modmap [ - 469 529 286 316 347 346 673 672 703 702 647 676 283 282 313 312 370 610 618 379 - 378 409 408 439 705 704 559 589 588 619 458 518 640 701 675 674 285 284 315 314 - 310 340 531 289 288 319 349 348 456 486 517 516 471 470 369 368 399 398 429 428 - 549 548 579 578 609 608 649 648 679 678 709 708 639 638 669 668 699 698 279 278 - 309 308 339 338 381 380 411 410 441 440 561 560 591 590 621 620 547 546 577 576 - 607 606 367 366 397 396 427 426 291 290 321 320 351 350 651 650 681 680 711 710 - 1 0 31 30 61 60 3 2 33 32 63 62 5 4 35 34 65 64 7 6 - 37 36 67 66 9 8 39 38 69 68 11 10 41 40 71 70 13 12 43 42 - 73 72 15 14 45 44 75 74 17 16 47 46 77 76 19 18 49 48 79 78 - 21 20 51 50 81 80 23 22 53 52 83 82 25 24 55 54 85 84 27 26 - 57 56 87 86 117 116 147 146 177 176 115 114 145 144 175 174 113 112 143 142 - 173 172 111 110 141 140 171 170 109 108 139 138 169 168 107 106 137 136 167 166 - 105 104 135 134 165 164 103 102 133 132 163 162 101 100 131 130 161 160 99 98 - 129 128 159 158 97 96 127 126 157 156 95 94 125 124 155 154 93 92 123 122 - 153 152 91 90 121 120 151 150 181 180 211 210 241 240 183 182 213 212 243 242 - 185 184 215 214 245 244 187 186 217 216 247 246 189 188 219 218 249 248 191 190 - 221 220 251 250 193 192 223 222 253 252 195 194 225 224 255 254 197 196 227 226 - 257 256 199 198 229 228 259 258 201 200 231 230 261 260 203 202 233 232 263 262 - 205 204 235 234 265 264 207 206 237 236 267 266 297 296 327 326 357 356 295 294 - 325 324 355 354 293 292 323 322 353 352 277 276 307 306 337 336 275 274 305 304 - 335 334 273 272 303 302 333 332 271 270 301 300 331 330 361 360 391 390 421 420 - 363 362 393 392 423 422 365 364 395 394 425 424 383 382 413 412 443 442 385 384 - 415 414 445 444 387 386 417 416 447 446 477 476 507 506 537 536 475 474 505 504 - 535 534 473 472 503 502 533 532 455 454 485 484 515 514 453 452 483 482 513 512 - 451 450 481 480 511 510 541 540 571 570 601 600 543 542 573 572 603 602 545 544 - 575 574 605 604 563 562 593 592 623 622 565 564 595 594 625 624 567 566 597 596 - 627 626 657 656 687 686 717 716 655 654 685 684 715 714 653 652 683 682 713 712 - 637 636 667 666 697 696 635 634 665 664 695 694 633 632 663 662 693 692 631 630 - 661 660 691 690 721 720 751 750 781 780 723 722 753 752 783 782 725 724 755 754 - 785 784 727 726 757 756 787 786 729 728 759 758 789 788 731 730 761 760 791 790 - 733 732 763 762 793 792 735 734 765 764 795 794 737 736 767 766 797 796 739 738 - 769 768 799 798 741 740 771 770 801 800 743 742 773 772 803 802 745 744 775 774 - 805 804 747 746 777 776 807 806 837 836 867 866 897 896 835 834 865 864 895 894 - 833 832 863 862 893 892 831 830 861 860 891 890 829 828 859 858 889 888 827 826 - 857 856 887 886 825 824 855 854 885 884 823 822 853 852 883 882 821 820 851 850 - 881 880 819 818 849 848 879 878 817 816 847 846 877 876 815 814 845 844 875 874 - 813 812 843 842 873 872 811 810 841 840 871 870 901 900 931 930 961 960 903 902 - 933 932 963 962 905 904 935 934 965 964 907 906 937 936 967 966 909 908 939 938 - 969 968 911 910 941 940 971 970 913 912 943 942 973 972 915 914 945 944 975 974 - 917 916 947 946 977 976 919 918 949 948 979 978 921 920 951 950 981 980 923 922 - 953 952 983 982 925 924 955 954 985 984 927 926 957 956 987 986 58 89 88 118 - 149 148 178 209 208 238 269 268 298 329 328 358 389 388 418 449 448 478 509 508 - 538 569 568 598 629 628 658 689 688 718 749 748 778 809 808 838 869 868 898 929 - 928 958 989 988 - ] def + end + +} bind def +/hibccode128 dup load /uk.co.terryburton.bwipp defineresource pop +end +/setpacking where {pop setpacking} if +% --END ENCODER hibccode128-- + +% --BEGIN ENCODER hibcdatamatrix-- +% --REQUIRES datamatrix-- +% --DESC: HIBC Data Matrix +% --EXAM: A123BJC5D6E71 +% --EXOP: +% --RNDR: renmatrix +/setpacking where {pop currentpacking true setpacking} if +1 dict +dup /renmatrix dup /uk.co.terryburton.bwipp findresource put +dup /datamatrix dup /uk.co.terryburton.bwipp findresource put +begin +/hibcdatamatrix { + + 20 dict begin % Confine variables to local scope + + /options exch def % We are given an option string + /barcode exch def % We are given a barcode string + + /dontdraw false def + + % Parse the input options + options type /stringtype eq { + 1 dict begin + options { + token false eq {exit} if dup length string cvs (=) search + true eq {cvlit exch pop exch def} {cvlit true def} ifelse + } loop + currentdict end /options exch def + } if + options {def} forall + + /barlen barcode length def + + /barchars (0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ-. $/+%) def - % Lookup pixels for enabled modules from modmap - /pixs 864 array def - /j 0 def - 0 1 mods length 1 sub { + /barcode barlen 2 add string dup 1 barcode putinterval def + barcode 0 43 put + + /checksum 0 def + 0 1 barlen { /i exch def - mods i get 1 eq { - pixs j modmap i get put - /j j 1 add def - } if + % Lookup the encoding for the each barcode character + barcode i 1 getinterval barchars exch search + pop % Discard true leaving pre + length /indx exch def % indx is the length of pre + pop pop % Discard seek and post + /checksum checksum indx add def } for - /pixs [ pixs 0 j getinterval {} forall 28 29 280 281 311 457 488 500 530 670 700 677 707 ] def + barcode barlen 1 add barchars checksum 43 mod get put - % Return the arguments - << - /ren (renmaximatrix) - /pixs pixs - /opt options - >> + % Get the result of encoding with datamatrix + options (dontdraw) true put + /args barcode options //datamatrix exec def - dontdraw not //renmaximatrix if + args (opt) options put + args + + dontdraw not //renmatrix if end } bind def -% --END ENCODER maxicode-- - -% --BEGIN ENCODER azteccode-- -% --DESC: Aztec Code -% --EXAM: This is Aztec Code -% --EXOP: format=full +/hibcdatamatrix dup load /uk.co.terryburton.bwipp defineresource pop +end +/setpacking where {pop setpacking} if +% --END ENCODER hibcdatamatrix-- + +% --BEGIN ENCODER hibcpdf417-- +% --REQUIRES pdf417-- +% --DESC: HIBC PDF417 +% --EXAM: A123BJC5D6E71 +% --EXOP: % --RNDR: renmatrix -/azteccode { +/setpacking where {pop currentpacking true setpacking} if +1 dict +dup /renmatrix dup /uk.co.terryburton.bwipp findresource put +dup /pdf417 dup /uk.co.terryburton.bwipp findresource put +begin +/hibcpdf417 { - 20 dict begin + 20 dict begin % Confine variables to local scope - /options exch def - /barcode exch def + /options exch def % We are given an option string + /barcode exch def % We are given a barcode string /dontdraw false def - /format (unset) def % full, compact or rune - /readerinit false def - /layers -1 def - /eclevel 23 def - /ecaddchars 3 def - /raw false def - /parse false def + /columns 2 def % Parse the input options options type /stringtype eq { @@ -7713,380 +16829,249 @@ currentdict end /options exch def } if options {def} forall + + /columns columns cvi def + + /barlen barcode length def + + /barchars (0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ-. $/+%) def + + /barcode barlen 2 add string dup 1 barcode putinterval def + barcode 0 43 put + + /checksum 0 def + 0 1 barlen { + /i exch def + % Lookup the encoding for the each barcode character + barcode i 1 getinterval barchars exch search + pop % Discard true leaving pre + length /indx exch def % indx is the length of pre + pop pop % Discard seek and post + /checksum checksum indx add def + } for + barcode barlen 1 add barchars checksum 43 mod get put + + % Get the result of encoding with pdf417 + options (dontdraw) true put + options (columns) columns put + /args barcode options //pdf417 exec def + + args (opt) options put + args - /layers layers cvi def - /eclevel eclevel cvr def - /ecaddchars ecaddchars cvi def + dontdraw not //renmatrix if - % Parse ordinals of the form ^NNN to ASCII - parse { - /msg barcode length string def - /j 0 def - barcode - { % loop - (^) search { - dup msg exch j exch putinterval - length j add 1 add /j exch def - pop - dup 0 3 getinterval cvi msg exch j 1 sub exch put - dup length 3 sub 3 exch getinterval - } { - dup msg exch j exch putinterval - length j add /j exch def - /barcode msg 0 j getinterval def - exit - } ifelse - } loop - } if + end - % Convert from input into message bitstream - /msgbits () def - format (rune) ne raw and {/msgbits barcode def} if - format (rune) ne raw not and { % Simple autoencoder from input to bitstream using byte mode only +} bind def +/hibcpdf417 dup load /uk.co.terryburton.bwipp defineresource pop +end +/setpacking where {pop setpacking} if +% --END ENCODER hibcpdf417-- + +% --BEGIN ENCODER hibcmicropdf417-- +% --REQUIRES micropdf417-- +% --DESC: HIBC MicroPDF417 +% --EXAM: A123BJC5D6E71 +% --EXOP: +% --RNDR: renmatrix +/setpacking where {pop currentpacking true setpacking} if +1 dict +dup /renmatrix dup /uk.co.terryburton.bwipp findresource put +dup /micropdf417 dup /uk.co.terryburton.bwipp findresource put +begin +/hibcmicropdf417 { - % Determine the character count - /barlen barcode length def - barlen 31 le { - (00000) 5 string copy dup barlen 2 5 string cvrs - dup length 5 exch sub exch putinterval - /cc exch def - } { - (0000000000000000) 16 string copy dup barlen 31 sub 2 16 string cvrs - dup length 16 exch sub exch putinterval - /cc exch def - } ifelse - /cclen cc length def + 20 dict begin % Confine variables to local scope - % Create the bitstream as byte_mode_id character_count data_bytes - /msgbits 5 cclen add barlen 8 mul add string def - msgbits 0 (11111) putinterval - msgbits 5 cc putinterval - 0 1 barlen 1 sub { - /i exch def - (00000000) 8 string copy dup barcode i get cvi 2 8 string cvrs dup length 8 exch sub exch putinterval - msgbits 5 cclen add i 8 mul add 3 -1 roll putinterval - } for + /options exch def % We are given an option string + /barcode exch def % We are given a barcode string - } if + /dontdraw false def + /columns 2 def - % Lookup the most appropriate symbol specification - /metrics [ - [ (rune) 0 0 0 6 ] % Special metric for rune symbols - [ (compact) 1 1 17 6 ] [ (full) 1 1 21 6 ] [ (compact) 2 0 40 6 ] - [ (full) 2 1 48 6 ] [ (compact) 3 0 51 8 ] [ (full) 3 1 60 8 ] - [ (compact) 4 0 76 8 ] [ (full) 4 1 88 8 ] [ (full) 5 1 120 8 ] - [ (full) 6 1 156 8 ] [ (full) 7 1 196 8 ] [ (full) 8 1 240 8 ] - [ (full) 9 1 230 10 ] [ (full) 10 1 272 10 ] [ (full) 11 1 316 10 ] - [ (full) 12 1 364 10 ] [ (full) 13 1 416 10 ] [ (full) 14 1 470 10 ] - [ (full) 15 1 528 10 ] [ (full) 16 1 588 10 ] [ (full) 17 1 652 10 ] - [ (full) 18 1 720 10 ] [ (full) 19 1 790 10 ] [ (full) 20 1 864 10 ] - [ (full) 21 1 940 10 ] [ (full) 22 1 1020 10 ] [ (full) 23 0 920 12 ] - [ (full) 24 0 992 12 ] [ (full) 25 0 1066 12 ] [ (full) 26 0 1144 12 ] - [ (full) 27 0 1224 12 ] [ (full) 28 0 1306 12 ] [ (full) 29 0 1392 12 ] - [ (full) 30 0 1480 12 ] [ (full) 31 0 1570 12 ] [ (full) 32 0 1664 12 ] - ] def + % Parse the input options + options type /stringtype eq { + 1 dict begin + options { + token false eq {exit} if dup length string cvs (=) search + true eq {cvlit exch pop exch def} {cvlit true def} ifelse + } loop + currentdict end /options exch def + } if + options {def} forall - /i 0 def - { % loop - /m metrics i get def - /frmt m 0 get def % Format of the symbol - /mlyr m 1 get def % Data layers - /icap m 2 get def % Reader initialisation capable - /ncws m 3 get def % Total of codewords - /bpcw m 4 get def % Bits per codeword - /numecw ncws eclevel mul 100 div ecaddchars add ceiling cvi def - msgbits length 0 eq {/numecw 0 def} if % Error correction codewords - /numdcw ncws numecw sub def % Data codewords - /okay true def - format (unset) ne format frmt ne and {/okay false def} if - readerinit icap 1 ne and {/okay false def} if - layers -1 ne layers mlyr ne and {/okay false def} if - msgbits length bpcw div ceiling cvi numdcw gt {/okay false def} if - okay {exit} if - /i i 1 add def - } loop - /layers mlyr def - /format frmt def + /columns columns cvi def - % Expand message bits into codewords avoiding codewords with all zeros or all ones - /allzero {dup length (000000000000) 0 3 -1 roll getinterval eq} bind def - /allones {dup length (111111111111) 0 3 -1 roll getinterval eq} bind def - /cws ncws array def - /m 0 def /c 0 def - { - msgbits length m le {exit} if - msgbits length m sub bpcw ge { - /cwb msgbits m bpcw 1 sub getinterval def % All but last bit - /cwf msgbits m bpcw add 1 sub 1 getinterval def % Last bit - cwb allzero {/cwf (1) def /m m 1 sub def} if % Flip last bit to avoid zeros - cwb allones {/cwf (0) def /m m 1 sub def} if % Flip last bit to avoid ones - % Concatinate the bits - 12 string dup 0 cwb putinterval - dup bpcw 1 sub cwf putinterval - 0 bpcw getinterval - /cwb exch def - } { % Final codeword - /cwb msgbits m msgbits length m sub getinterval def - /cwb (111111111111) 12 string copy dup 0 cwb putinterval 0 bpcw getinterval def - cwb allones {cwb cwb length 1 sub (0) putinterval} if % Prevent all ones - } ifelse - % Conversion of binary data into byte array - /cw 0 def - 0 1 bpcw 1 sub { - /i exch def - /cw cw 2 bpcw i sub 1 sub exp cvi cwb i get 48 sub mul add def - } for - cws c cw put - /m m bpcw add def - /c c 1 add def - } loop - /cws cws 0 c getinterval def + /barlen barcode length def - % Reed-Solomon algorithm - /rscodes { + /barchars (0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ-. $/+%) def - /rspm exch def - /rsgf exch def - /rsnc exch def - /rscws exch def + /barcode barlen 2 add string dup 1 barcode putinterval def + barcode 0 43 put - % Calculate the log and anti-log tables - /rsalog [ 1 rsgf 1 sub { dup 2 mul dup rsgf ge {rspm xor} if } repeat ] def - /rslog rsgf array def - 1 1 rsgf 1 sub {dup rsalog exch get exch rslog 3 1 roll put} for + /checksum 0 def + 0 1 barlen { + /i exch def + % Lookup the encoding for the each barcode character + barcode i 1 getinterval barchars exch search + pop % Discard true leaving pre + length /indx exch def % indx is the length of pre + pop pop % Discard seek and post + /checksum checksum indx add def + } for + barcode barlen 1 add barchars checksum 43 mod get put - % Function to calculate the product in the field - /rsprod { - 2 copy 0 ne exch 0 ne and { - rslog exch get exch rslog exch get add rsgf 1 sub mod rsalog exch get - } { - pop pop 0 - } ifelse - } bind def + % Get the result of encoding with micropdf417 + options (dontdraw) true put + options (columns) columns put + /args barcode options //micropdf417 exec def - % Generate the coefficients - /coeffs [ 1 rsnc {0} repeat ] def - 1 1 rsnc { - /i exch def - coeffs i coeffs i 1 sub get put - i 1 sub -1 1 { - /j exch def - coeffs j coeffs j 1 sub get coeffs j get rsalog i get rsprod xor put - } for - coeffs 0 coeffs 0 get rsalog i get rsprod put - } for + args (opt) options put + args + + dontdraw not //renmatrix if - % Extend the input with the error correction values - /nd rscws length def - /rscws [ rscws {} forall rsnc {0} repeat 0 ] def - 0 1 nd 1 sub { - /k exch rscws exch get rscws nd get xor def - 0 1 rsnc 1 sub { - /j exch def - rscws nd j add rscws nd j add 1 add get k coeffs rsnc j sub 1 sub get rsprod xor put - } for - } for + end - % Return all but the last codeword - rscws 0 rscws length 1 sub getinterval +} bind def +/hibcmicropdf417 dup load /uk.co.terryburton.bwipp defineresource pop +end +/setpacking where {pop setpacking} if +% --END ENCODER hibcmicropdf417-- + +% --BEGIN ENCODER hibcqrcode-- +% --REQUIRES qrcode-- +% --DESC: HIBC QR Code +% --EXAM: A123BJC5D6E71 +% --EXOP: +% --RNDR: renmatrix +/setpacking where {pop currentpacking true setpacking} if +1 dict +dup /renmatrix dup /uk.co.terryburton.bwipp findresource put +dup /qrcode dup /uk.co.terryburton.bwipp findresource put +begin +/hibcqrcode { - } bind def + 20 dict begin % Confine variables to local scope - % Create the codewords and bit string for the mode - format (full) eq { - /mode layers 1 sub 11 bitshift cws length 1 sub add def - readerinit {/mode mode 2#1000000000000000 or def} if - /mode [ - mode 2#1111000000000000 and -12 bitshift - mode 2#0000111100000000 and -8 bitshift - mode 2#0000000011110000 and -4 bitshift - mode 2#0000000000001111 and - ] def - /mode mode 6 16 19 rscodes def - } if - format (compact) eq { - /mode layers 1 sub 6 bitshift cws length 1 sub add def - readerinit {/mode mode 2#10000000 or def} if - /mode [ - mode 2#11110000 and -4 bitshift - mode 2#00001111 and - ] def - /mode mode 5 16 19 rscodes def - } if - format (rune) eq { - /mode barcode cvi def - /mode [ - mode 2#11110000 and -4 bitshift - mode 2#00001111 and - ] def - /mode mode 5 16 19 rscodes def - /mode [mode {2#1010 xor} forall] def % Invert alternate bits + /options exch def % We are given an option string + /barcode exch def % We are given a barcode string + + /dontdraw false def + + % Parse the input options + options type /stringtype eq { + 1 dict begin + options { + token false eq {exit} if dup length string cvs (=) search + true eq {cvlit exch pop exch def} {cvlit true def} ifelse + } loop + currentdict end /options exch def } if - /modebits mode length 4 mul string def - 0 1 modebits length 1 sub {modebits exch (0) putinterval} for - 0 1 mode length 1 sub { - /i exch def - modebits mode i get 2 4 string cvrs dup length 4 exch sub 4 i mul add exch putinterval - } for + options {def} forall - % Extend the data codewords with error correction codewords to create the bit string for the data - /rsparams [ - [] [] [] [] [] [] - [ 64 67 ] % 6-bit codewords - [] - [ 256 301 ] % 8-bit codewords - [] - [ 1024 1033 ] % 10-bit codewords - [] - [ 4096 4201 ] % 12-bit codewords - ] def - /cws cws ncws cws length sub rsparams bpcw get {} forall rscodes def - format (full) eq { - /databits layers layers mul 16 mul layers 112 mul add string def - } { - /databits layers layers mul 16 mul layers 88 mul add string def - } ifelse - 0 1 databits length 1 sub {databits exch (0) putinterval} for - 0 1 ncws 1 sub { + /barlen barcode length def + + /barchars (0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ-. $/+%) def + + /barcode barlen 2 add string dup 1 barcode putinterval def + barcode 0 43 put + + /checksum 0 def + 0 1 barlen { /i exch def - databits cws i get 2 bpcw string cvrs - dup length bpcw exch sub bpcw i mul add databits length ncws bpcw mul sub add - exch putinterval + % Lookup the encoding for the each barcode character + barcode i 1 getinterval barchars exch search + pop % Discard true leaving pre + length /indx exch def % indx is the length of pre + pop pop % Discard seek and post + /checksum checksum indx add def } for + barcode barlen 1 add barchars checksum 43 mod get put - % Move to a point in the cartesian plane centered on the bullseye - /cmv {size mul sub mid add} bind def + % Get the result of encoding with qrcode + options (dontdraw) true put + /args barcode options //qrcode exec def - % Move to a bit position within a layer - /lmv { - /lbit exch def - /llyr exch def - /lwid fw llyr 4 mul add def - /ldir lbit 2 idiv lwid idiv def - ldir 0 eq { % Top - lwid 1 sub 2 idiv neg 1 add lbit 2 idiv lwid mod add - fw 1 sub 2 idiv llyr 2 mul add lbit 2 mod add - cmv - } if - ldir 1 eq { % Right - fw 2 idiv llyr 2 mul add lbit 2 mod add - lwid 1 sub 2 idiv 1 sub lbit 2 idiv lwid mod sub - cmv - } if - ldir 2 eq { % Bottom - lwid 2 idiv neg 1 add lbit 2 idiv lwid mod add neg - fw 2 idiv llyr 2 mul add lbit 2 mod add neg - cmv - } if - ldir 3 eq { % Left - fw 1 sub 2 idiv llyr 2 mul add lbit 2 mod add neg - lwid 2 idiv 1 sub lbit 2 idiv lwid mod sub neg - cmv - } if - } bind def + args (opt) options put + args + + dontdraw not //renmatrix if - % Create the pixel map - % For full symbols we disregard the reference grid at this stage - format (full) eq {/fw 12 def} {/fw 9 def} ifelse - /size fw layers 4 mul add 2 add def - /pixs [size size mul {-1} repeat] def - /mid size 1 sub 2 idiv size mul size 1 sub 2 idiv add def + end - % Data layers - /i 0 def - 1 1 layers { - /layer exch def - 0 1 fw layer 4 mul add 8 mul 1 sub { - /pos exch def - pixs layer pos lmv databits databits length i sub 1 sub get 48 sub put - /i i 1 add def - } for - } for +} bind def +/hibcqrcode dup load /uk.co.terryburton.bwipp defineresource pop +end +/setpacking where {pop setpacking} if +% --END ENCODER hibcqrcode-- + +% --BEGIN ENCODER hibccodablockf-- +% --REQUIRES codablockf-- +% --DESC: HIBC Codablock F +% --EXAM: A123BJC5D6E71 +% --EXOP: +% --RNDR: renmatrix +/setpacking where {pop currentpacking true setpacking} if +1 dict +dup /renmatrix dup /uk.co.terryburton.bwipp findresource put +dup /codablockf dup /uk.co.terryburton.bwipp findresource put +begin +/hibccodablockf { - % For full symbols expand the pixel map by inserting the reference grid - format (full) eq { - /fw 13 def - /size fw layers 4 mul add 2 add layers 10.5 add 7.5 div 1 sub cvi 2 mul add def - /mid size size mul 2 idiv def - /npixs [size size mul {-2} repeat] def - 0 16 size 2 idiv { - /i exch def - 0 1 size 1 sub { - /j exch def - npixs size 2 idiv neg j add i cmv [size 2 idiv j add i add 1 add 2 mod] putinterval - npixs size 2 idiv neg j add i neg cmv [size 2 idiv j add i add 1 add 2 mod] putinterval - npixs i size 2 idiv neg j add cmv [size 2 idiv j add i add 1 add 2 mod] putinterval - npixs i neg size 2 idiv neg j add cmv [size 2 idiv j add i add 1 add 2 mod] putinterval - } for - } for - /j 0 def - 0 1 npixs length 1 sub { - /i exch def - npixs i get -2 eq { - npixs i pixs j get put - /j j 1 add def - } if - } for - /pixs npixs def + 20 dict begin % Confine variables to local scope + + /options exch def % We are given an option string + /barcode exch def % We are given a barcode string + + /dontdraw false def + + % Parse the input options + options type /stringtype eq { + 1 dict begin + options { + token false eq {exit} if dup length string cvs (=) search + true eq {cvlit exch pop exch def} {cvlit true def} ifelse + } loop + currentdict end /options exch def } if + options {def} forall - % Finder pattern - /fw fw 2 idiv def - fw neg 1 fw { - /i exch def - fw neg 1 fw { - /j exch def - pixs i j cmv - i abs j abs gt {i abs} {j abs} ifelse 1 add 2 mod - put - } for - } for + /barlen barcode length def - % Orientation bits - [ [ fw 1 add neg fw 1 ] [ fw 1 add neg fw 1 add 1 ] - [ fw neg fw 1 add 1 ] [ fw 1 add fw 1 add 1 ] - [ fw 1 add fw 1 ] [ fw 1 add fw neg 1 ] - [ fw fw 1 add 0 ] [ fw 1 add fw 1 add neg 0 ] - [ fw fw 1 add neg 0 ] [ fw neg fw 1 add neg 0 ] - [ fw 1 add neg fw 1 add neg 0 ] [ fw 1 add neg fw neg 0 ] - ] {pixs exch {} forall 3 1 roll cmv exch put} forall + /barchars (0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ-. $/+%) def - % Mode ring - format (full) eq { - /modemap [ - [-5 7] [-4 7] [-3 7] [-2 7] [-1 7] [ 1 7] [ 2 7] [ 3 7] [ 4 7] [ 5 7] - [ 7 5] [ 7 4] [ 7 3] [ 7 2] [ 7 1] [ 7 -1] [ 7 -2] [ 7 -3] [ 7 -4] [ 7 -5] - [ 5 -7] [ 4 -7] [ 3 -7] [ 2 -7] [ 1 -7] [-1 -7] [-2 -7] [-3 -7] [-4 -7] [-5 -7] - [-7 -5] [-7 -4] [-7 -3] [-7 -2] [-7 -1] [-7 1] [-7 2] [-7 3] [-7 4] [-7 5] - ] def - } { - /modemap [ - [-3 5] [-2 5] [-1 5] [ 0 5] [ 1 5] [ 2 5] [ 3 5] - [ 5 3] [ 5 2] [ 5 1] [ 5 0] [ 5 -1] [ 5 -2] [ 5 -3] - [ 3 -5] [ 2 -5] [ 1 -5] [ 0 -5] [-1 -5] [-2 -5] [-3 -5] - [-5 -3] [-5 -2] [-5 -1] [-5 0] [-5 1] [-5 2] [-5 3] - ] def - } ifelse - 0 1 modemap length 1 sub { + /barcode barlen 2 add string dup 1 barcode putinterval def + barcode 0 43 put + + /checksum 0 def + 0 1 barlen { /i exch def - pixs modemap i get {} forall cmv modebits i get 48 sub put + % Lookup the encoding for the each barcode character + barcode i 1 getinterval barchars exch search + pop % Discard true leaving pre + length /indx exch def % indx is the length of pre + pop pop % Discard seek and post + /checksum checksum indx add def } for + barcode barlen 1 add barchars checksum 43 mod get put - << - /ren (renmatrix) - /pixs pixs - /pixx size - /pixy size - /height size 2 mul 72 div - /width size 2 mul 72 div - /opt options - >> + % Get the result of encoding with codablockf + options (dontdraw) true put + /args barcode options //codablockf exec def + args (opt) options put + args + dontdraw not //renmatrix if end } bind def -% --END ENCODER azteccode-- +/hibccodablockf dup load /uk.co.terryburton.bwipp defineresource pop +end +/setpacking where {pop setpacking} if +% --END ENCODER hibccodablockf-- % --END TEMPLATE-- diff --git a/Master/texmf-dist/tex/generic/pst-barcode/pst-barcode.tex b/Master/texmf-dist/tex/generic/pst-barcode/pst-barcode.tex index edf945d586b..7346c8f938a 100644 --- a/Master/texmf-dist/tex/generic/pst-barcode/pst-barcode.tex +++ b/Master/texmf-dist/tex/generic/pst-barcode/pst-barcode.tex @@ -19,8 +19,8 @@ \let\PSTBarcodeLoaded\endinput \ifx\PSTricksLoaded\endinput\else\input pstricks.tex\fi % -\def\fileversion{0.07} -\def\filedate{2009/08/12} +\def\fileversion{0.08} +\def\filedate{2011/03/10} \message{`PST-barcode' v\fileversion, \filedate\space (tb,hv)} % \edef\PstAtCode{\the\catcode`\@} \catcode`\@=11\relax @@ -45,8 +45,7 @@ \psk@barcode@scalex\space \psk@barcode@scaley\space \psk@barcode@transx\space \psk@barcode@transy\space translate scale rotate - 0 0 moveto (#1) (#2) #3 -%\space barcode % is no more needed + 0 0 moveto (#1) (#2) /#3 /uk.co.terryburton.bwipp findresource exec grestore }% \end@SpecialObj% diff --git a/Master/texmf-dist/tex/latex/pst-barcode/pst-barcode.sty b/Master/texmf-dist/tex/latex/pst-barcode/pst-barcode.sty index acce0bf8906..34e80d319f1 100644 --- a/Master/texmf-dist/tex/latex/pst-barcode/pst-barcode.sty +++ b/Master/texmf-dist/tex/latex/pst-barcode/pst-barcode.sty @@ -6,6 +6,6 @@ [\filedate\space v\fileversion\space `PST-barcode' (hv)] \IfFileExists{pst-barcode.pro}{% \ProvidesFile{pst-barcode.pro} - [2009/08/12 PostScript prologue file (hv)] + [2011/03/12 PostScript prologue file (hv)] \@addtofilelist{pst-barcode.pro}}{}% \endinput -- cgit v1.2.3