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 / Code25.php
blob2efbb58f6fb10e353d6460d6b44adfdd7db32304
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 /**
13 * Class for generate Interleaved 2 of 5 barcode
15 class Code25 extends AbstractObject
17 /**
18 * Coding map
19 * - 0 = narrow bar
20 * - 1 = wide bar
21 * @var array
23 protected $codingMap = array(
24 '0' => '00110',
25 '1' => '10001',
26 '2' => '01001',
27 '3' => '11000',
28 '4' => '00101',
29 '5' => '10100',
30 '6' => '01100',
31 '7' => '00011',
32 '8' => '10010',
33 '9' => '01010',
36 /**
37 * Width of the barcode (in pixels)
38 * @return int
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)
45 * $this->factor;
46 $encodedData = strlen($this->getText()) * $characterLength;
47 $stopCharacter = (2 * $this->barThickWidth + 4 * $this->barThinWidth) * $this->factor;
48 return $quietZone + $startCharacter + $encodedData + $stopCharacter + $quietZone;
51 /**
52 * Partial check of interleaved 2 of 5 barcode
53 * @return void
55 protected function checkSpecificParams()
57 $this->checkRatio();
60 /**
61 * Prepare array to draw barcode
62 * @return array
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);
93 return $barcodeTable;
96 /**
97 * Get barcode checksum
99 * @param string $text
100 * @return int
102 public function getChecksum($text)
104 $this->checkText($text);
105 $factor = 3;
106 $checksum = 0;
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;
115 return $checksum;