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 / Royalmail.php
blobed38d7b857074faae2b3e4c4100d6d580b0ed028
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 Royal maim barcode
15 class Royalmail extends AbstractObject
18 /**
19 * Coding map
20 * - 0 = Tracker, Ascender and Descender
21 * - 1 = Tracker and Ascender
22 * - 2 = Tracker and Descender
23 * - 3 = Tracker
24 * @var array
26 protected $codingMap = array(
27 '0' => '3300', '1' => '3210', '2' => '3201', '3' => '2310', '4' => '2301', '5' => '2211',
28 '6' => '3120', '7' => '3030', '8' => '3021', '9' => '2130', 'A' => '2121', 'B' => '2031',
29 'C' => '3102', 'D' => '3012', 'E' => '3003', 'F' => '2112', 'G' => '2103', 'H' => '2013',
30 'I' => '1320', 'J' => '1230', 'K' => '1221', 'L' => '0330', 'M' => '0321', 'N' => '0231',
31 'O' => '1302', 'P' => '1212', 'Q' => '1203', 'R' => '0312', 'S' => '0303', 'T' => '0213',
32 'U' => '1122', 'V' => '1032', 'W' => '1023', 'X' => '0132', 'Y' => '0123', 'Z' => '0033'
35 protected $rows = array(
36 '0' => 1, '1' => 1, '2' => 1, '3' => 1, '4' => 1, '5' => 1,
37 '6' => 2, '7' => 2, '8' => 2, '9' => 2, 'A' => 2, 'B' => 2,
38 'C' => 3, 'D' => 3, 'E' => 3, 'F' => 3, 'G' => 3, 'H' => 3,
39 'I' => 4, 'J' => 4, 'K' => 4, 'L' => 4, 'M' => 4, 'N' => 4,
40 'O' => 5, 'P' => 5, 'Q' => 5, 'R' => 5, 'S' => 5, 'T' => 5,
41 'U' => 0, 'V' => 0, 'W' => 0, 'X' => 0, 'Y' => 0, 'Z' => 0,
44 protected $columns = array(
45 '0' => 1, '1' => 2, '2' => 3, '3' => 4, '4' => 5, '5' => 0,
46 '6' => 1, '7' => 2, '8' => 3, '9' => 4, 'A' => 5, 'B' => 0,
47 'C' => 1, 'D' => 2, 'E' => 3, 'F' => 4, 'G' => 5, 'H' => 0,
48 'I' => 1, 'J' => 2, 'K' => 3, 'L' => 4, 'M' => 5, 'N' => 0,
49 'O' => 1, 'P' => 2, 'Q' => 3, 'R' => 4, 'S' => 5, 'T' => 0,
50 'U' => 1, 'V' => 2, 'W' => 3, 'X' => 4, 'Y' => 5, 'Z' => 0,
53 /**
54 * Default options for Postnet barcode
55 * @return void
57 protected function getDefaultOptions()
59 $this->barThinWidth = 2;
60 $this->barHeight = 20;
61 $this->drawText = false;
62 $this->stretchText = true;
63 $this->mandatoryChecksum = true;
66 /**
67 * Width of the barcode (in pixels)
68 * @return int
70 protected function calculateBarcodeWidth()
72 $quietZone = $this->getQuietZone();
73 $startCharacter = (2 * $this->barThinWidth) * $this->factor;
74 $stopCharacter = (1 * $this->barThinWidth) * $this->factor;
75 $encodedData = (8 * $this->barThinWidth) * $this->factor * strlen($this->getText());
76 return $quietZone + $startCharacter + $encodedData + $stopCharacter + $quietZone;
79 /**
80 * Partial check of interleaved Postnet barcode
81 * @return void
83 protected function checkSpecificParams()
86 /**
87 * Prepare array to draw barcode
88 * @return array
90 protected function prepareBarcode()
92 $barcodeTable = array();
94 // Start character (1)
95 $barcodeTable[] = array(1, $this->barThinWidth, 0, 5/8);
96 $barcodeTable[] = array(0, $this->barThinWidth, 0, 1);
98 // Text to encode
99 $textTable = str_split($this->getText());
100 foreach ($textTable as $char) {
101 $bars = str_split($this->codingMap[$char]);
102 foreach ($bars as $b) {
103 $barcodeTable[] = array(1, $this->barThinWidth, ($b > 1 ? 3/8 : 0), ($b % 2 ? 5/8 : 1));
104 $barcodeTable[] = array(0, $this->barThinWidth, 0, 1);
108 // Stop character (1)
109 $barcodeTable[] = array(1, $this->barThinWidth, 0, 1);
110 return $barcodeTable;
114 * Get barcode checksum
116 * @param string $text
117 * @return int
119 public function getChecksum($text)
121 $this->checkText($text);
122 $values = str_split($text);
123 $rowvalue = 0;
124 $colvalue = 0;
125 foreach ($values as $row) {
126 $rowvalue += $this->rows[$row];
127 $colvalue += $this->columns[$row];
130 $rowvalue %= 6;
131 $colvalue %= 6;
133 $rowchkvalue = array_keys($this->rows, $rowvalue);
134 $colchkvalue = array_keys($this->columns, $colvalue);
135 return current(array_intersect($rowchkvalue, $colchkvalue));