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