1<?php
2
3namespace Mpdf\Barcode;
4
5abstract class AbstractBarcode
6{
7
8	/**
9	 * @var mixed[]
10	 */
11	protected $data;
12
13	/**
14	 * @return mixed[]
15	 */
16	public function getData()
17	{
18		return $this->data;
19	}
20
21	/**
22	 * @param string $key
23	 *
24	 * @return mixed
25	 */
26	public function getKey($key)
27	{
28		return isset($this->data[$key]) ? $this->data[$key] : null;
29	}
30
31	/**
32	 * @return string
33	 */
34	public function getChecksum()
35	{
36		return $this->getKey('checkdigit');
37	}
38
39	/**
40	 * Convert binary barcode sequence to barcode array
41	 *
42	 * @param string $seq
43	 * @param mixed[] $barcodeData
44	 *
45	 * @return mixed[]
46	 */
47	protected function binseqToArray($seq, array $barcodeData)
48	{
49		$len = strlen($seq);
50		$w = 0;
51		$k = 0;
52		for ($i = 0; $i < $len; ++$i) {
53			$w += 1;
54			if (($i == ($len - 1)) or (($i < ($len - 1)) and ($seq[$i] != $seq[($i + 1)]))) {
55				if ($seq[$i] == '1') {
56					$t = true; // bar
57				} else {
58					$t = false; // space
59				}
60				$barcodeData['bcode'][$k] = ['t' => $t, 'w' => $w, 'h' => 1, 'p' => 0];
61				$barcodeData['maxw'] += $w;
62				++$k;
63				$w = 0;
64			}
65		}
66		return $barcodeData;
67	}
68
69}
70