source-class-Com.Tecnick.Barcode.Type.Square.QrCode.Encode

It appears that you are using AdBlocking software. The cost of running this website is covered by advertisements. If you like it please feel free to a small amount of money to secure the future of this website.
Overview

Classes

Exceptions

  1: <?php
  2: /**
  3:  * Encode.php
  4:  *
  5:  * @since       2015-02-21
  6:  * @category    Library
  7:  * @package     Barcode
  8:  * @author      Nicola Asuni <info@tecnick.com>
  9:  * @copyright   2010-2016 Nicola Asuni - Tecnick.com LTD
 10:  * @license     http://www.gnu.org/copyleft/lesser.html GNU-LGPL v3 (see LICENSE.TXT)
 11:  * @link        https://github.com/tecnickcom/tc-lib-barcode
 12:  *
 13:  * This file is part of tc-lib-barcode software library.
 14:  */
 15: 
 16: namespace Com\Tecnick\Barcode\Type\Square\QrCode;
 17: 
 18: use \Com\Tecnick\Barcode\Exception as BarcodeException;
 19: use \Com\Tecnick\Barcode\Type\Square\QrCode\Data;
 20: 
 21: /**
 22:  * Com\Tecnick\Barcode\Type\Square\QrCode\Encode
 23:  *
 24:  * @since       2015-02-21
 25:  * @category    Library
 26:  * @package     Barcode
 27:  * @author      Nicola Asuni <info@tecnick.com>
 28:  * @copyright   2010-2016 Nicola Asuni - Tecnick.com LTD
 29:  * @license     http://www.gnu.org/copyleft/lesser.html GNU-LGPL v3 (see LICENSE.TXT)
 30:  * @link        https://github.com/tecnickcom/tc-lib-barcode
 31:  */
 32: abstract class Encode extends \Com\Tecnick\Barcode\Type\Square\QrCode\EncodingMode
 33: {
 34:     /**
 35:      * encode Mode Num
 36:      *
 37:      * @param array $inputitem
 38:      * @param int   $version
 39:      *
 40:      * @return array input item
 41:      */
 42:     protected function encodeModeNum($inputitem, $version)
 43:     {
 44:         $words = (int)($inputitem['size'] / 3);
 45:         $inputitem['bstream'] = array();
 46:         $val = 0x1;
 47:         $inputitem['bstream'] = $this->appendNum($inputitem['bstream'], 4, $val);
 48:         $inputitem['bstream'] = $this->appendNum(
 49:             $inputitem['bstream'],
 50:             $this->getLengthIndicator(Data::$encodingModes['NM'], $version),
 51:             $inputitem['size']
 52:         );
 53:         for ($i=0; $i < $words; ++$i) {
 54:             $val  = (ord($inputitem['data'][$i*3  ]) - ord('0')) * 100;
 55:             $val += (ord($inputitem['data'][$i*3+1]) - ord('0')) * 10;
 56:             $val += (ord($inputitem['data'][$i*3+2]) - ord('0'));
 57:             $inputitem['bstream'] = $this->appendNum($inputitem['bstream'], 10, $val);
 58:         }
 59:         if ($inputitem['size'] - $words * 3 == 1) {
 60:             $val = ord($inputitem['data'][$words*3]) - ord('0');
 61:             $inputitem['bstream'] = $this->appendNum($inputitem['bstream'], 4, $val);
 62:         } elseif (($inputitem['size'] - ($words * 3)) == 2) {
 63:             $val  = (ord($inputitem['data'][$words*3  ]) - ord('0')) * 10;
 64:             $val += (ord($inputitem['data'][$words*3+1]) - ord('0'));
 65:             $inputitem['bstream'] = $this->appendNum($inputitem['bstream'], 7, $val);
 66:         }
 67:         return $inputitem;
 68:     }
 69: 
 70:     /**
 71:      * encode Mode An
 72:      *
 73:      * @param array $inputitem
 74:      * @param int   $version
 75:      *
 76:      * @return array input item
 77:      */
 78:     protected function encodeModeAn($inputitem, $version)
 79:     {
 80:         $words = (int)($inputitem['size'] / 2);
 81:         $inputitem['bstream'] = array();
 82:         $inputitem['bstream'] = $this->appendNum($inputitem['bstream'], 4, 0x02);
 83:         $inputitem['bstream'] = $this->appendNum(
 84:             $inputitem['bstream'],
 85:             $this->getLengthIndicator(Data::$encodingModes['AN'], $version),
 86:             $inputitem['size']
 87:         );
 88:         for ($idx = 0; $idx < $words; ++$idx) {
 89:             $val  = (int)($this->lookAnTable(ord($inputitem['data'][($idx * 2)])) * 45);
 90:             $val += (int)($this->lookAnTable(ord($inputitem['data'][($idx * 2)+1])));
 91:             $inputitem['bstream'] = $this->appendNum($inputitem['bstream'], 11, $val);
 92:         }
 93:         if ($inputitem['size'] & 1) {
 94:             $val = $this->lookAnTable(ord($inputitem['data'][($words * 2)]));
 95:             $inputitem['bstream'] = $this->appendNum($inputitem['bstream'], 6, $val);
 96:         }
 97:         return $inputitem;
 98:     }
 99: 
100:     /**
101:      * encode Mode 8
102:      *
103:      * @param array $inputitem
104:      * @param int   $version
105:      *
106:      * @return array input item
107:      */
108:     protected function encodeMode8($inputitem, $version)
109:     {
110:         $inputitem['bstream'] = array();
111:         $inputitem['bstream'] = $this->appendNum($inputitem['bstream'], 4, 0x4);
112:         $inputitem['bstream'] = $this->appendNum(
113:             $inputitem['bstream'],
114:             $this->getLengthIndicator(Data::$encodingModes['8B'], $version),
115:             $inputitem['size']
116:         );
117:         for ($idx = 0; $idx < $inputitem['size']; ++$idx) {
118:             $inputitem['bstream'] = $this->appendNum($inputitem['bstream'], 8, ord($inputitem['data'][$idx]));
119:         }
120:         return $inputitem;
121:     }
122: 
123:     /**
124:      * encode Mode Kanji
125:      *
126:      * @param array $inputitem
127:      * @param int   $version
128:      *
129:      * @return array input item
130:      */
131:     protected function encodeModeKanji($inputitem, $version)
132:     {
133:         $inputitem['bstream'] = array();
134:         $inputitem['bstream'] = $this->appendNum($inputitem['bstream'], 4, 0x8);
135:         $inputitem['bstream'] = $this->appendNum(
136:             $inputitem['bstream'],
137:             $this->getLengthIndicator(Data::$encodingModes['KJ'], $version),
138:             (int)($inputitem['size'] / 2)
139:         );
140:         for ($idx = 0; $idx < $inputitem['size']; $idx += 2) {
141:             $val = (ord($inputitem['data'][$idx]) << 8) | ord($inputitem['data'][($idx + 1)]);
142:             if ($val <= 0x9ffc) {
143:                 $val -= 0x8140;
144:             } else {
145:                 $val -= 0xc140;
146:             }
147:             $val = ($val & 0xff) + (($val >> 8) * 0xc0);
148:             $inputitem['bstream'] = $this->appendNum($inputitem['bstream'], 13, $val);
149:         }
150:         return $inputitem;
151:     }
152: 
153:     /**
154:      * encode Mode Structure
155:      *
156:      * @param array $inputitem
157:      *
158:      * @return array input item
159:      */
160:     protected function encodeModeStructure($inputitem)
161:     {
162:         $inputitem['bstream'] = array();
163:         $inputitem['bstream'] = $this->appendNum($inputitem['bstream'], 4, 0x03);
164:         $inputitem['bstream'] = $this->appendNum($inputitem['bstream'], 4, ord($inputitem['data'][1]) - 1);
165:         $inputitem['bstream'] = $this->appendNum($inputitem['bstream'], 4, ord($inputitem['data'][0]) - 1);
166:         $inputitem['bstream'] = $this->appendNum($inputitem['bstream'], 8, ord($inputitem['data'][2]));
167:         return $inputitem;
168:     }
169: }
170: 
 

© 2004-2017 – Nicola Asuni - Tecnick.com - All rights reserved.
about - disclaimer - privacy