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;
12 use Zend\Validator\Barcode
as BarcodeValidator
;
15 * Class for generate Ean8 barcode
17 class Ean8
extends Ean13
21 * Default options for Postnet barcode
24 protected function getDefaultOptions()
26 $this->barcodeLength
= 8;
27 $this->mandatoryChecksum
= true;
31 * Width of the barcode (in pixels)
34 protected function calculateBarcodeWidth()
36 $quietZone = $this->getQuietZone();
37 $startCharacter = (3 * $this->barThinWidth
) * $this->factor
;
38 $middleCharacter = (5 * $this->barThinWidth
) * $this->factor
;
39 $stopCharacter = (3 * $this->barThinWidth
) * $this->factor
;
40 $encodedData = (7 * $this->barThinWidth
) * $this->factor
* 8;
41 return $quietZone +
$startCharacter +
$middleCharacter +
$encodedData +
$stopCharacter +
$quietZone;
45 * Prepare array to draw barcode
48 protected function prepareBarcode()
50 $barcodeTable = array();
51 $height = ($this->drawText
) ?
1.1 : 1;
53 // Start character (101)
54 $barcodeTable[] = array(1, $this->barThinWidth
, 0, $height);
55 $barcodeTable[] = array(0, $this->barThinWidth
, 0, $height);
56 $barcodeTable[] = array(1, $this->barThinWidth
, 0, $height);
58 $textTable = str_split($this->getText());
61 for ($i = 0; $i < 4; $i++
) {
62 $bars = str_split($this->codingMap
['A'][$textTable[$i]]);
63 foreach ($bars as $b) {
64 $barcodeTable[] = array($b, $this->barThinWidth
, 0, 1);
68 // Middle character (01010)
69 $barcodeTable[] = array(0, $this->barThinWidth
, 0, $height);
70 $barcodeTable[] = array(1, $this->barThinWidth
, 0, $height);
71 $barcodeTable[] = array(0, $this->barThinWidth
, 0, $height);
72 $barcodeTable[] = array(1, $this->barThinWidth
, 0, $height);
73 $barcodeTable[] = array(0, $this->barThinWidth
, 0, $height);
76 for ($i = 4; $i < 8; $i++
) {
77 $bars = str_split($this->codingMap
['C'][$textTable[$i]]);
78 foreach ($bars as $b) {
79 $barcodeTable[] = array($b, $this->barThinWidth
, 0, 1);
83 // Stop character (101)
84 $barcodeTable[] = array(1, $this->barThinWidth
, 0, $height);
85 $barcodeTable[] = array(0, $this->barThinWidth
, 0, $height);
86 $barcodeTable[] = array(1, $this->barThinWidth
, 0, $height);
91 * Partial function to draw text
94 protected function drawText()
96 if ($this->drawText
) {
97 $text = $this->getTextToDisplay();
98 $characterWidth = (7 * $this->barThinWidth
) * $this->factor
;
99 $leftPosition = $this->getQuietZone() +
(3 * $this->barThinWidth
) * $this->factor
;
100 for ($i = 0; $i < $this->barcodeLength
; $i ++
) {
103 $this->fontSize
* $this->factor
,
106 (int) $this->withBorder
* 2
107 +
$this->factor
* ($this->barHeight +
$this->fontSize
) +
1
121 $leftPosition = $leftPosition +
$characterWidth +
($factor * $this->barThinWidth
* $this->factor
);
127 * Particular validation for Ean8 barcode objects
128 * (to suppress checksum character substitution)
130 * @param string $value
131 * @param array $options
132 * @throws Exception\BarcodeValidationException
134 protected function validateSpecificText($value, $options = array())
136 $validator = new BarcodeValidator(array(
141 $value = $this->addLeadingZeros($value, true);
143 if (!$validator->isValid($value)) {
144 $message = implode("\n", $validator->getMessages());
145 throw new Exception\
BarcodeValidationException($message);