| 1 |
%Author: Ji\v{r}\'{i} Mrkus |
| 2 |
%License: LaTeX Project Public License |
| 3 |
\newcount\stringlength |
| 4 |
\stringlength=0 |
| 5 |
\newcount\check |
| 6 |
\check=0 |
| 7 |
\newcount\badchar |
| 8 |
\badchar=0 |
| 9 |
\newcount\oddcount |
| 10 |
\oddcount=0 |
| 11 |
\newcount\evencount |
| 12 |
\evencount=0 |
| 13 |
\newcount\helplen |
| 14 |
\helplen=0 |
| 15 |
\newcount\moda |
| 16 |
\newcount\modb |
| 17 |
|
| 18 |
\newdimen\module |
| 19 |
\newdimen\height |
| 20 |
\newdimen\fivemodule |
| 21 |
\newdimen\fntsize |
| 22 |
\newdimen\unita |
| 23 |
\newdimen\unitb |
| 24 |
\newdimen\unitc |
| 25 |
\newdimen\helpind |
| 26 |
|
| 27 |
\fntsize=12pt |
| 28 |
\module=0.33mm |
| 29 |
\height=25.9mm |
| 30 |
|
| 31 |
|
| 32 |
|
| 33 |
\def\upca#1 {\kern 1.5mm\edef\currfont{\the\font}% |
| 34 |
\helpind=\parindent% |
| 35 |
\parindent=0pt% |
| 36 |
\unita=\module% |
| 37 |
\multiply\unita by1065% |
| 38 |
\divide\unita by1000% |
| 39 |
\unitb=\unita% |
| 40 |
\unitc=\unita% |
| 41 |
\multiply\unita by4% |
| 42 |
\multiply\unitb by11% |
| 43 |
\multiply\unitc by2% |
| 44 |
\fntsize=\module% |
| 45 |
\multiply\fntsize by950% |
| 46 |
\divide\fntsize by100% |
| 47 |
\font\upcafont=ocrb10 at \fntsize% |
| 48 |
\upcafont% |
| 49 |
\fivemodule=\module% |
| 50 |
\multiply\fivemodule by5% |
| 51 |
\stringlength=0 \badchar=0% |
| 52 |
\control[#1] \ifnum\badchar=0 \ifnum\check=1 \controlchar[#1]% |
| 53 |
\hbox{\upcacode[#1{\checkchar}]}\else% |
| 54 |
\hbox{\upcacode[#1]}\fi\else\fi% |
| 55 |
\parindent=\helpind \currfont \kern 1.5mm} |
| 56 |
|
| 57 |
|
| 58 |
|
| 59 |
\def\upcacode[#1]{\stringlength=1% |
| 60 |
\advance\height by\fivemodule% |
| 61 |
\ooalign{\split[00000]\split[101] \upcahash[#1]\split[00000]\cr% |
| 62 |
\hbox{\kern-\unitc \lower \unita\hbox{\upcatext[#1]}}}} |
| 63 |
|
| 64 |
|
| 65 |
%Macro which prints text under the code |
| 66 |
\def\upcatext[#1#2]{#1\kern\unitb \sndtext[#2]} |
| 67 |
\def\sndtext[#1#2#3#4#5#6]{#1#2#3#4#5\kern\unita \rdtext[#6]} |
| 68 |
\def\rdtext[#1#2#3#4#5#6]{#1#2#3#4#5\kern\unitb #6} |
| 69 |
|
| 70 |
%This macro converts number to sequence of 0 and 1 |
| 71 |
\def\upcahash[#1#2]{% |
| 72 |
\if#10 \ifnum\stringlength=1 \split[0001101]\else% |
| 73 |
\ifnum\stringlength<7% |
| 74 |
\raise\fivemodule\hbox{\split[0001101]}\else% |
| 75 |
\ifnum\stringlength=12 \split[1110010]\else% |
| 76 |
\raise\fivemodule\hbox{\split[1110010]}\fi\fi\fi\else% |
| 77 |
\if#11 \ifnum\stringlength=1 \split[0011001]\else% |
| 78 |
\ifnum\stringlength<7% |
| 79 |
\raise\fivemodule\mbox{\split[0011001]}\else% |
| 80 |
\ifnum\stringlength=12 \split[1100110]\else% |
| 81 |
\raise\fivemodule\hbox{\split[1100110]}\fi\fi\fi\else% |
| 82 |
\if#12 \ifnum\stringlength=1 \split[0010011]\else% |
| 83 |
\ifnum\stringlength<7% |
| 84 |
\raise\fivemodule\hbox{\split[0010011]}\else% |
| 85 |
\ifnum\stringlength=12 \split[1101100]\else% |
| 86 |
\raise\fivemodule\hbox{\split[1101100]}\fi\fi\fi\else% |
| 87 |
\if#13 \ifnum\stringlength=1 \split[0111101]\else% |
| 88 |
\ifnum\stringlength<7% |
| 89 |
\raise\fivemodule\hbox{\split[0111101]}\else% |
| 90 |
\ifnum\stringlength=12 \split[1000010]\else% |
| 91 |
\raise\fivemodule\hbox{\split[1000010]}\fi\fi\fi\else% |
| 92 |
\if#14 \ifnum\stringlength=1 \split[0100011]\else% |
| 93 |
\ifnum\stringlength<7% |
| 94 |
\raise\fivemodule\hbox{\split[0100011]}\else% |
| 95 |
\ifnum\stringlength=12 \split[1011100]\else% |
| 96 |
\raise\fivemodule\hbox{\split[1011100]}\fi\fi\fi\else% |
| 97 |
\if#15 \ifnum\stringlength=1 \split[0110001]\else% |
| 98 |
\ifnum\stringlength<7% |
| 99 |
\raise\fivemodule\hbox{\split[0110001]}\else% |
| 100 |
\ifnum\stringlength=12 \split[1001110]\else% |
| 101 |
\raise\fivemodule\hbox{\split[1001110]}\fi\fi\fi\else% |
| 102 |
\if#16 \ifnum\stringlength=1 \split[0101111]\else% |
| 103 |
\ifnum\stringlength<7% |
| 104 |
\raise\fivemodule\hbox{\split[0101111]}\else% |
| 105 |
\ifnum\stringlength=12 \split[1010000]\else% |
| 106 |
\raise\fivemodule\hbox{\split[1010000]}\fi\fi\fi\else% |
| 107 |
\if#17 \ifnum\stringlength=1 \split[0111011]\else% |
| 108 |
\ifnum\stringlength<7% |
| 109 |
\raise\fivemodule\hbox{\split[0111011]}\else% |
| 110 |
\ifnum\stringlength=12 \split[1000100]\else% |
| 111 |
\raise\fivemodule\hbox{\split[1000100]}\fi\fi\fi\else% |
| 112 |
\if#18 \ifnum\stringlength=1 \split[0110111]\else% |
| 113 |
\ifnum\stringlength<7% |
| 114 |
\raise\fivemodule\hbox{\split[0110111]}\else% |
| 115 |
\ifnum\stringlength=12 \split[1001000]\else% |
| 116 |
\raise\fivemodule\hbox{\split[1001000]}\fi\fi\fi\else% |
| 117 |
\if#19 \ifnum\stringlength=1 \split[0001011]\else% |
| 118 |
\ifnum\stringlength<7% |
| 119 |
\raise\fivemodule\hbox{\split[0001011]}\else% |
| 120 |
\ifnum\stringlength=12 \split[1110010]\else% |
| 121 |
\raise\fivemodule\hbox{\split[1110100]}\fi\fi\fi \else \fi\fi\fi\fi\fi\fi\fi\fi\fi\fi% |
| 122 |
\ifnum\stringlength=11 \advance\height by\fivemodule\else\fi% |
| 123 |
\ifnum\stringlength=6% |
| 124 |
\advance\height by\fivemodule% |
| 125 |
\split[01010]% |
| 126 |
\advance\height by-\fivemodule \else \fi% |
| 127 |
\ifnum\stringlength=1 \advance\height by-\fivemodule \else\fi% |
| 128 |
\advance\stringlength by1% |
| 129 |
\if:#2: \split[101]% |
| 130 |
\advance\height by-\fivemodule% |
| 131 |
\else\upcahash[#2]\fi} |
| 132 |
|
| 133 |
%Macro takes as parameter sequence of 0 and 1, every character passes on draw macro |
| 134 |
\def\split[#1#2]{\draw[#1] \if:#2: \else \split[#2] \fi} |
| 135 |
|
| 136 |
%This macro takes as parameter one character (0 or 1) and draws a bar or space |
| 137 |
\def\draw[#1]{\if#11\vrule height \height width \module \else \if#10\hskip \module \fi \fi} |
| 138 |
|
| 139 |
%Returns true if character in parameter is a digit, false otherwise |
| 140 |
\newif\ifnext |
| 141 |
\def\ifdigit[#1]{\ifnum`#1>47 \ifnum`#1<58 \nexttrue\else\nextfalse\fi\else\nextfalse\fi\ifnext} |
| 142 |
|
| 143 |
%This macro computes length of string in parameter - result is in helplen register |
| 144 |
\def\strlen[#1#2]{\if:#2: \advance\helplen by1 \else \advance\helplen by1\strlen[#2]\fi} |
| 145 |
|
| 146 |
%Macro which computes modulo of two numbers in moda and modb registers - result in moda |
| 147 |
\def\modulo{% |
| 148 |
\ifnum\moda>\modb \advance\moda by-\modb \modulo% |
| 149 |
\else \fi\ifnum\moda=\modb \moda=0 \else \fi} |
| 150 |
|
| 151 |
%Macro which controls if parameter has length 11 or 12 characters and contains only digits |
| 152 |
\def\control[#1#2]{\ifdigit[#1]\advance\stringlength by1% |
| 153 |
\if:#2: \ifnum\stringlength=11 \check=1 \else% |
| 154 |
\ifnum\stringlength=12 \check=0% |
| 155 |
\else \message{String must have 11 or 12 characters}\badchar=1\fi\fi\else\control[#2]\fi% |
| 156 |
\else \message{Invalid characters: code can contain only digits}\badchar=1\fi} |
| 157 |
|
| 158 |
%Macro which computes the check digit |
| 159 |
\def\controlchar[#1#2]{\helplen=0 \if:#2: \else \strlen[#2]\fi \moda=\helplen \modb=2 \modulo% |
| 160 |
\ifnum\moda=0 \advance\oddcount by`#1 \advance\oddcount by-48 \else% |
| 161 |
\advance\evencount by`#1 \advance\evencount by-48 \fi% |
| 162 |
\ifnum\helplen>0 \controlchar[#2]\else% |
| 163 |
\multiply\oddcount by3 \advance\oddcount by\evencount \moda=\oddcount \modb=10 \modulo% |
| 164 |
\ifnum\moda=0 \check=0 \else \check=10 \advance\check by-\moda\fi \def\checkchar{\the\check}\fi} |
| 165 |
|
| 166 |
\endinput |