3 namespace Mpdf\Barcode
;
5 use Mpdf\Utils\UtfString
;
9 * Very capable code, excellent density, high reliability; in very wide use world-wide
11 class Code128
extends \Mpdf\Barcode\AbstractBarcode
implements \Mpdf\Barcode\BarcodeInterface
19 public function __construct($code, $type = 'B', $ean = false)
21 $this->init($code, $type, $ean);
23 $this->data
['nom-X'] = 0.381; // Nominal value for X-dim (bar width) in mm (2 X min. spec.)
24 $this->data
['nom-H'] = 10; // Nominal value for Height of Full bar in mm (non-spec.)
25 $this->data
['lightmL'] = 10; // LEFT light margin = x X-dim (spec.)
26 $this->data
['lightmR'] = 10; // RIGHT light margin = x X-dim (spec.)
27 $this->data
['lightTB'] = 0; // TOP/BOTTOM light margin = x X-dim (non-spec.)
35 protected function init($code, $type, $ean)
37 $code = UtfString
::strcode2utf($code); // mPDF 5.7.1 Allows e.g. <barcode code="5432
1068" type="C128A" />
143 '211412', /* 103 START A */
144 '211214', /* 104 START B */
145 '211232', /* 105 START C */
150 switch (strtoupper($type)) {
153 $keys = ' !"#$%&\'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\\]^_';
154 for ($i = 0; $i < 32; ++
$i) {
160 $keys = ' !"#$%&\'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\\]^_`abcdefghijklmnopqrstuvwxyz{|}~' . chr(127);
165 if ((strlen($code) %
2) != 0) {
166 // The length of barcode value must be even ($code). You must pad the number with zeros
167 throw new \Mpdf\Barcode\
BarcodeException('Invalid CODE128C barcode value');
169 for ($i = 0; $i <= 99; ++
$i) {
173 $hclen = (strlen($code) / 2);
174 for ($i = 0; $i < $hclen; ++
$i) {
175 $newCode .= chr((int) ($code{(2 * $i)} . $code{(2 * $i +
1)}));
180 throw new \Mpdf\Barcode\
BarcodeException('Invalid CODE128 barcode type');
183 // calculate check character
186 // Add FNC 1 - which identifies it as EAN-128
188 $code = chr(102) . $code;
190 $clen = strlen($code);
191 for ($i = 0; $i < $clen; ++
$i) {
192 if ($ean && $i == 0) {
195 $sum +
= (strpos($keys, $code[$i]) * ($i +
1));
198 $check = ($sum %
103);
199 $checkdigit = $check;
201 // add start, check and stop codes
202 $code = chr($startid) . $code . chr($check) . chr(106) . chr(107);
203 $bararray = ['code' => $code, 'maxw' => 0, 'maxh' => 1, 'bcode' => []];
205 $len = strlen($code);
207 for ($i = 0; $i < $len; ++
$i) {
209 $ck = strpos($keys, $code[$i]);
210 if (($i == 0) ||
($ean && $i == 1) |
($i > ($len - 4))) {
211 $char_num = ord($code[$i]);
212 $seq = $chr[$char_num];
213 } elseif (($ck >= 0) && isset($chr[$ck])) {
217 throw new \Mpdf\Barcode\
BarcodeException(sprintf('Invalid character "%s" in CODE128C barcode value', $code[$i]));
219 for ($j = 0; $j < 6; ++
$j) {
226 $bararray['bcode'][$k] = ['t' => $t, 'w' => $w, 'h' => 1, 'p' => 0];
227 $bararray['maxw'] +
= $w;
232 $bararray['checkdigit'] = $checkdigit;
233 $this->data
= $bararray;
236 public function getType()