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 Code25interleaved
extends Code25
18 * Drawing of bearer bars
21 private $withBearerBars = false;
24 * Default options for Code25interleaved barcode
27 protected function getDefaultOptions()
29 $this->barcodeLength
= 'even';
33 * Activate/deactivate drawing of bearer bars
37 public function setWithBearerBars($value)
39 $this->withBearerBars
= (bool) $value;
44 * Retrieve if bearer bars are enabled
47 public function getWithBearerBars()
49 return $this->withBearerBars
;
53 * Width of the barcode (in pixels)
56 protected function calculateBarcodeWidth()
58 $quietZone = $this->getQuietZone();
59 $startCharacter = (4 * $this->barThinWidth
) * $this->factor
;
60 $characterLength = (3 * $this->barThinWidth +
2 * $this->barThickWidth
) * $this->factor
;
61 $encodedData = strlen($this->getText()) * $characterLength;
62 $stopCharacter = ($this->barThickWidth +
2 * $this->barThinWidth
) * $this->factor
;
63 return $quietZone +
$startCharacter +
$encodedData +
$stopCharacter +
$quietZone;
67 * Prepare array to draw barcode
70 protected function prepareBarcode()
72 if ($this->withBearerBars
) {
73 $this->withBorder
= false;
76 // Start character (0000)
77 $barcodeTable[] = array(1, $this->barThinWidth
, 0, 1);
78 $barcodeTable[] = array(0, $this->barThinWidth
, 0, 1);
79 $barcodeTable[] = array(1, $this->barThinWidth
, 0, 1);
80 $barcodeTable[] = array(0, $this->barThinWidth
, 0, 1);
83 $text = $this->getText();
84 for ($i = 0, $len = strlen($text); $i < $len; $i +
= 2) { // Draw 2 chars at a time
85 $char1 = substr($text, $i, 1);
86 $char2 = substr($text, $i +
1, 1);
89 for ($ibar = 0; $ibar < 5; $ibar ++
) {
90 // Draws char1 bar (fore color)
91 $barWidth = (substr($this->codingMap
[$char1], $ibar, 1))
92 ?
$this->barThickWidth
93 : $this->barThinWidth
;
95 $barcodeTable[] = array(1, $barWidth, 0, 1);
97 // Left space corresponding to char2 (background color)
98 $barWidth = (substr($this->codingMap
[$char2], $ibar, 1))
99 ?
$this->barThickWidth
100 : $this->barThinWidth
;
101 $barcodeTable[] = array(0, $barWidth, 0, 1);
105 // Stop character (100)
106 $barcodeTable[] = array(1, $this->barThickWidth
, 0, 1);
107 $barcodeTable[] = array(0, $this->barThinWidth
, 0, 1);
108 $barcodeTable[] = array(1, $this->barThinWidth
, 0, 1);
109 return $barcodeTable;
113 * Drawing of bearer bars (if enabled)
117 protected function postDrawBarcode()
119 if (!$this->withBearerBars
) {
123 $width = $this->barThickWidth
* $this->factor
;
124 $point1 = $this->rotate(-1, -1);
125 $point2 = $this->rotate($this->calculateWidth() - 1, -1);
126 $point3 = $this->rotate($this->calculateWidth() - 1, $width - 1);
127 $point4 = $this->rotate(-1, $width - 1);
128 $this->addPolygon(array(
134 $point1 = $this->rotate(
136 0 +
$this->barHeight
* $this->factor
- 1
138 $point2 = $this->rotate(
139 $this->calculateWidth() - 1,
140 0 +
$this->barHeight
* $this->factor
- 1
142 $point3 = $this->rotate(
143 $this->calculateWidth() - 1,
144 0 +
$this->barHeight
* $this->factor
- $width
146 $point4 = $this->rotate(
148 0 +
$this->barHeight
* $this->factor
- $width
150 $this->addPolygon(array(