3 * Zend Framework (http://framework.zend.com/)
5 * @link http://github.com/zendframework/zf2 for the canonical source repository
6 * @copyright Copyright (c) 2005-2013 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 Interleaved 2 of 5 barcode
15 class Code25
extends AbstractObject
23 protected $codingMap = array(
37 * Width of the barcode (in pixels)
40 protected function calculateBarcodeWidth()
42 $quietZone = $this->getQuietZone();
43 $startCharacter = (2 * $this->barThickWidth +
4 * $this->barThinWidth
) * $this->factor
;
44 $characterLength = (3 * $this->barThinWidth +
2 * $this->barThickWidth +
5 * $this->barThinWidth
)
46 $encodedData = strlen($this->getText()) * $characterLength;
47 $stopCharacter = (2 * $this->barThickWidth +
4 * $this->barThinWidth
) * $this->factor
;
48 return $quietZone +
$startCharacter +
$encodedData +
$stopCharacter +
$quietZone;
52 * Partial check of interleaved 2 of 5 barcode
55 protected function checkSpecificParams()
61 * Prepare array to draw barcode
64 protected function prepareBarcode()
66 $barcodeTable = array();
68 // Start character (30301)
69 $barcodeTable[] = array(1, $this->barThickWidth
, 0, 1);
70 $barcodeTable[] = array(0, $this->barThinWidth
, 0, 1);
71 $barcodeTable[] = array(1, $this->barThickWidth
, 0, 1);
72 $barcodeTable[] = array(0, $this->barThinWidth
, 0, 1);
73 $barcodeTable[] = array(1, $this->barThinWidth
, 0, 1);
74 $barcodeTable[] = array(0, $this->barThinWidth
);
76 $text = str_split($this->getText());
77 foreach ($text as $char) {
78 $barcodeChar = str_split($this->codingMap
[$char]);
79 foreach ($barcodeChar as $c) {
80 /* visible, width, top, length */
81 $width = $c ?
$this->barThickWidth
: $this->barThinWidth
;
82 $barcodeTable[] = array(1, $width, 0, 1);
83 $barcodeTable[] = array(0, $this->barThinWidth
);
87 // Stop character (30103)
88 $barcodeTable[] = array(1, $this->barThickWidth
, 0, 1);
89 $barcodeTable[] = array(0, $this->barThinWidth
, 0, 1);
90 $barcodeTable[] = array(1, $this->barThinWidth
, 0, 1);
91 $barcodeTable[] = array(0, $this->barThinWidth
, 0, 1);
92 $barcodeTable[] = array(1, $this->barThickWidth
, 0, 1);
97 * Get barcode checksum
102 public function getChecksum($text)
104 $this->checkText($text);
108 for ($i = strlen($text); $i > 0; $i --) {
109 $checksum +
= intval($text{$i - 1}) * $factor;
110 $factor = 4 - $factor;
113 $checksum = (10 - ($checksum %
10)) %
10;