3 * Zend Framework (http://framework.zend.com/)
5 * @link http://github.com/zendframework/zf2 for the canonical source repository
6 * @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com)
7 * @license http://framework.zend.com/license/new-bsd New BSD License
10 namespace Zend\Barcode\
Object;
13 * Class for generate Codabar barcode
15 class Codabar
extends AbstractObject
23 protected $codingMap = array(
24 '0' => "101010011", '1' => "101011001", '2' => "101001011",
25 '3' => "110010101", '4' => "101101001", '5' => "110101001",
26 '6' => "100101011", '7' => "100101101", '8' => "100110101",
27 '9' => "110100101", '-' => "101001101", '$' => "101100101",
28 ':' => "1101011011", '/' => "1101101011", '.' => "1101101101",
29 '+' => "1011011011", 'A' => "1011001001", 'B' => "1010010011",
30 'C' => "1001001011", 'D' => "1010011001"
34 * Width of the barcode (in pixels)
37 protected function calculateBarcodeWidth()
39 $quietZone = $this->getQuietZone();
41 $barcodeChar = str_split($this->getText());
42 if (count($barcodeChar) > 1) {
43 foreach ($barcodeChar as $c) {
44 $encodedData +
= ((strlen($this->codingMap
[$c]) +
1) * $this->barThinWidth
) * $this->factor
;
47 $encodedData -= (1 * $this->barThinWidth
* $this->factor
);
48 return $quietZone +
$encodedData +
$quietZone;
52 * Partial check of Codabar barcode
55 protected function checkSpecificParams()
60 * Prepare array to draw barcode
63 protected function prepareBarcode()
65 $text = str_split($this->getText());
66 $barcodeTable = array();
67 foreach ($text as $char) {
68 $barcodeChar = str_split($this->codingMap
[$char]);
69 foreach ($barcodeChar as $c) {
70 // visible, width, top, length
71 $barcodeTable[] = array($c, $this->barThinWidth
, 0, 1);
73 $barcodeTable[] = array(0, $this->barThinWidth
);