| 1 |
|
| 2 |
%%%%%%%%%%%% The macro \EAN generates EAN-8 barcodes. %%%%%%%%%%%%%%%%%% |
| 3 |
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 4 |
%% May 30, 1995 Jaroslav Moucka (Mou\v{c}ka) |
| 5 |
|
| 6 |
% This macro is inspired by ean13 macro by Petr Olsak |
| 7 |
% The ean8 macro is very similar as ean13 and more simple. |
| 8 |
% Don't change the Copyright message. |
| 9 |
% You can use the macro on your own risk. |
| 10 |
% The macro must be tested! There is no warranty that the macro works OK. |
| 11 |
|
| 12 |
% Usage: For example \EAN 8591-2342 generates the \vbox with barcodes |
| 13 |
% in TeX hight accuracy using \rule primitive. |
| 14 |
% The EAN number is appended downwards in OCR-b font (9pt). |
| 15 |
% Don't use brackets in parameters! |
| 16 |
% The macro checks the checksum in EAN. |
| 17 |
|
| 18 |
% Recomendation: If you plan the offset print, use the barcode |
| 19 |
% correction 20 for your phototypesetter. See the \bcorr=.020mm bellow. |
| 20 |
|
| 21 |
\font\ocrb=ocrb9 |
| 22 |
|
| 23 |
\newcount\numlines \newcount\nummodules |
| 24 |
\newcount\numdigit \newcount\evensum \newcount\oddsum |
| 25 |
|
| 26 |
\newdimen\X \newdimen\bcorr \newdimen\workdimen \newdimen\barheight |
| 27 |
|
| 28 |
%%% First, we prepare internal code in format: dig dig dig (44 digits). |
| 29 |
%%% Odd possition of dig is number of moduls for white space, |
| 30 |
%%% even for black space; from left to right. |
| 31 |
|
| 32 |
\def\internalcode{0111} % Begin mark at start |
| 33 |
\def\frontdigits{} % 8--5 digit of EAN |
| 34 |
|
| 35 |
%%% EAN-8: |
| 36 |
\message{The EAN-8 barcodes macro. Copyright (C) Jaroslav Moucka, 1995} |
| 37 |
|
| 38 |
\def\EAN{\begingroup\EANscan} |
| 39 |
|
| 40 |
\def\EANscan#1{\if#1-\let\next=\EANscan \else |
| 41 |
\advance\numdigit by1 |
| 42 |
\ifnum\numdigit<8 |
| 43 |
\ifodd\numdigit \advance\evensum by #1 \else \advance\oddsum by #1 \fi |
| 44 |
\let\next=\EANscan |
| 45 |
\ifnum\numdigit=1 \def\tabs{\A\A\A\A} \fi |
| 46 |
\ifnum\numdigit<5 \usetabA #1 \edef\frontdigits{\frontdigits#1} \else |
| 47 |
\ifnum\numdigit=5 \insertseparator \A \usetabC #1 \def\enddigits{#1} |
| 48 |
\else \usetabC #1 \edef\enddigits{\enddigits#1} |
| 49 |
\fi\fi |
| 50 |
\else \testchecksum #1 \usetabC #1 \edef\enddigits{\enddigits#1} |
| 51 |
\let\next=\EANclose |
| 52 |
\fi\fi \next} |
| 53 |
|
| 54 |
|
| 55 |
\def\EANclose{\insertendmark |
| 56 |
\wlog{EAN: \frontdigits\space\enddigits} |
| 57 |
\wlog{EANinternal: \internalcode} |
| 58 |
\expandafter\EANbox\internalcode..\endgroup} |
| 59 |
|
| 60 |
\def\testchecksum#1{\multiply\evensum by3 \advance\evensum by\oddsum |
| 61 |
\oddsum=\evensum |
| 62 |
\divide\oddsum by10 \multiply\oddsum by10 \advance\oddsum by10 |
| 63 |
\advance\oddsum by-\evensum \ifnum\oddsum=10 \oddsum=0 \fi |
| 64 |
\ifnum#1=\oddsum \else |
| 65 |
\errmessage{The checksum digit has to be \the\oddsum, no #1 !}\fi} |
| 66 |
|
| 67 |
\def\A{\def\0{3211}\def\1{2221}\def\2{2122}\def\3{1411}\def\4{1132} |
| 68 |
\def\5{1231}\def\6{1114}\def\7{1312}\def\8{1213}\def\9{3112}} |
| 69 |
|
| 70 |
\def\usetabA#1{\expandafter\scantab\tabs\end \usetabC #1} |
| 71 |
|
| 72 |
\def\scantab#1#2\end{#1\def\tabs{#2}} |
| 73 |
|
| 74 |
\def\usetabC#1{\edef\internalcode{\internalcode\csname#1\endcsname}} |
| 75 |
|
| 76 |
\def\insertseparator{\edef\internalcode{\internalcode 11111}} |
| 77 |
|
| 78 |
\def\insertendmark{\edef\internalcode{\internalcode 111}} |
| 79 |
|
| 80 |
|
| 81 |
\def\EANbox{\vbox\bgroup\offinterlineskip |
| 82 |
\setbox0=\hbox\bgroup \kern7\X \EANrepeat} |
| 83 |
|
| 84 |
\def\EANrepeat#1#2{\if#1.\let\next=\EANfinal \else\let\next=\EANrepeat |
| 85 |
\advance\numlines by1 |
| 86 |
\advance\nummodules by#1 \advance\nummodules by#2 |
| 87 |
\workdimen=#1\X \advance\workdimen by \bcorr \kern\workdimen |
| 88 |
\workdimen=#2\X \advance\workdimen by-\bcorr \vrule width\workdimen |
| 89 |
\ifdim\barheight=0pt height 55.24242424\X \else height\barheight \fi |
| 90 |
\ifnum\numlines=1 depth5\X\else |
| 91 |
\ifnum\numlines=2 depth5\X\else |
| 92 |
\ifnum\numlines=11 depth5\X\else |
| 93 |
\ifnum\numlines=12 depth5\X\else |
| 94 |
\ifnum\numlines=21 depth5\X\else |
| 95 |
\ifnum\numlines=22 depth5\X\else depth0pt \fi\fi\fi\fi\fi\fi |
| 96 |
\fi\next} |
| 97 |
|
| 98 |
\def\EANfinal{\testconsistence |
| 99 |
\kern7\X\egroup |
| 100 |
\dp0=0pt \box0 \kern-1\X |
| 101 |
\hbox{\ocrb\kern11\X \frontdigits\kern5\X \enddigits} |
| 102 |
\egroup } |
| 103 |
|
| 104 |
\def\internalerr{\errmassage{Sorry, my internal tables are wrong, may be.}} |
| 105 |
|
| 106 |
\def\testconsistence{\ifnum\numlines=22\else\internalerr\fi |
| 107 |
\ifnum\nummodules=67\else\internalerr\fi} |
| 108 |
|
| 109 |
\barheight=0pt |
| 110 |
\X=.33mm % Basic size 100%, SC2 code |
| 111 |
\bcorr=.020mm % Barcode correction for offset |
| 112 |
\endinput |
| 113 |
|
| 114 |
|