Added the zend framework 2 library, the path is specified in line no.26 in zend_modul...
[openemr.git] / interface / modules / zend_modules / library / Zend / Barcode / Object / Ean8.php
blobcbdeba9e240b07e3f17e52bc62fefcd4c4f2331a
1 <?php
2 /**
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
8 */
10 namespace Zend\Barcode\Object;
12 use Zend\Validator\Barcode as BarcodeValidator;
14 /**
15 * Class for generate Ean8 barcode
17 class Ean8 extends Ean13
20 /**
21 * Default options for Postnet barcode
22 * @return void
24 protected function getDefaultOptions()
26 $this->barcodeLength = 8;
27 $this->mandatoryChecksum = true;
30 /**
31 * Width of the barcode (in pixels)
32 * @return int
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;
44 /**
45 * Prepare array to draw barcode
46 * @return array
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());
60 // First part
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);
75 // Second part
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);
87 return $barcodeTable;
90 /**
91 * Partial function to draw text
92 * @return void
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 ++) {
101 $this->addText(
102 $text{$i},
103 $this->fontSize * $this->factor,
104 $this->rotate(
105 $leftPosition,
106 (int) $this->withBorder * 2
107 + $this->factor * ($this->barHeight + $this->fontSize) + 1
109 $this->font,
110 $this->foreColor,
111 'left',
112 - $this->orientation
114 switch ($i) {
115 case 3:
116 $factor = 4;
117 break;
118 default:
119 $factor = 0;
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(
137 'adapter' => 'ean8',
138 'checksum' => false,
141 $value = $this->addLeadingZeros($value, true);
143 if (!$validator->isValid($value)) {
144 $message = implode("\n", $validator->getMessages());
145 throw new Exception\BarcodeValidationException($message);