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

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:  * SpecRs.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\SpecRs
 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 SpecRs
 33: {
 34:     /**
 35:      * Return block number 0
 36:      *
 37:      * @param array $spec
 38:      *
 39:      * @return int value
 40:      */
 41:     public function rsBlockNum($spec)
 42:     {
 43:         return ($spec[0] + $spec[3]);
 44:     }
 45: 
 46:     /**
 47:      * Return block number 1
 48:      *
 49:      * @param array $spec
 50:      *
 51:      * @return int value
 52:      */
 53:     public function rsBlockNum1($spec)
 54:     {
 55:         return $spec[0];
 56:     }
 57: 
 58:     /**
 59:      * Return data codes 1
 60:      *
 61:      * @param array $spec
 62:      *
 63:      * @return int value
 64:      */
 65:     public function rsDataCodes1($spec)
 66:     {
 67:         return $spec[1];
 68:     }
 69: 
 70:     /**
 71:      * Return ecc codes 1
 72:      *
 73:      * @param array $spec
 74:      *
 75:      * @return int value
 76:      */
 77:     public function rsEccCodes1($spec)
 78:     {
 79:         return $spec[2];
 80:     }
 81: 
 82:     /**
 83:      * Return block number 2
 84:      *
 85:      * @param array $spec
 86:      *
 87:      * @return int value
 88:      */
 89:     public function rsBlockNum2($spec)
 90:     {
 91:         return $spec[3];
 92:     }
 93: 
 94:     /**
 95:      * Return data codes 2
 96:      *
 97:      * @param array $spec
 98:      *
 99:      * @return int value
100:      */
101:     public function rsDataCodes2($spec)
102:     {
103:         return $spec[4];
104:     }
105: 
106:     /**
107:      * Return ecc codes 2
108:      *
109:      * @param array $spec
110:      *
111:      * @return int value
112:      */
113:     public function rsEccCodes2($spec)
114:     {
115:         return $spec[2];
116:     }
117: 
118:     /**
119:      * Return data length
120:      *
121:      * @param array $spec
122:      *
123:      * @return int value
124:      */
125:     public function rsDataLength($spec)
126:     {
127:         return ($spec[0] * $spec[1]) + ($spec[3] * $spec[4]);
128:     }
129: 
130:     /**
131:      * Return ecc length
132:      *
133:      * @param array $spec
134:      *
135:      * @return int value
136:      */
137:     public function rsEccLength($spec)
138:     {
139:         return ($spec[0] + $spec[3]) * $spec[2];
140:     }
141: 
142:     /**
143:      * Return a copy of initialized frame.
144:      *
145:      * @param int $version Version
146:      *
147:      * @return Array of unsigned char.
148:      */
149:     public function createFrame($version)
150:     {
151:         $width = Data::$capacity[$version][Data::QRCAP_WIDTH];
152:         $frameLine = str_repeat("\0", $width);
153:         $frame = array_fill(0, $width, $frameLine);
154:         // Finder pattern
155:         $frame = $this->putFinderPattern($frame, 0, 0);
156:         $frame = $this->putFinderPattern($frame, $width - 7, 0);
157:         $frame = $this->putFinderPattern($frame, 0, $width - 7);
158:         // Separator
159:         $yOffset = $width - 7;
160:         for ($ypos = 0; $ypos < 7; ++$ypos) {
161:             $frame[$ypos][7] = "\xc0";
162:             $frame[$ypos][$width - 8] = "\xc0";
163:             $frame[$yOffset][7] = "\xc0";
164:             ++$yOffset;
165:         }
166:         $setPattern = str_repeat("\xc0", 8);
167:         $frame = $this->qrstrset($frame, 0, 7, $setPattern);
168:         $frame = $this->qrstrset($frame, $width-8, 7, $setPattern);
169:         $frame = $this->qrstrset($frame, 0, $width - 8, $setPattern);
170:         // Format info
171:         $setPattern = str_repeat("\x84", 9);
172:         $frame = $this->qrstrset($frame, 0, 8, $setPattern);
173:         $frame = $this->qrstrset($frame, $width - 8, 8, $setPattern, 8);
174:         $yOffset = $width - 8;
175:         for ($ypos = 0; $ypos < 8; ++$ypos, ++$yOffset) {
176:             $frame[$ypos][8] = "\x84";
177:             $frame[$yOffset][8] = "\x84";
178:         }
179:         // Timing pattern
180:         $wdo = $width - 15;
181:         for ($idx = 1; $idx < $wdo; ++$idx) {
182:             $frame[6][(7 + $idx)] = chr(0x90 | ($idx & 1));
183:             $frame[(7 + $idx)][6] = chr(0x90 | ($idx & 1));
184:         }
185:         // Alignment pattern
186:         $frame = $this->putAlignmentPattern($version, $frame, $width);
187:         // Version information
188:         if ($version >= 7) {
189:             $vinf = $this->getVersionPattern($version);
190:             $val = $vinf;
191:             for ($xpos = 0; $xpos < 6; ++$xpos) {
192:                 for ($ypos = 0; $ypos < 3; ++$ypos) {
193:                     $frame[(($width - 11) + $ypos)][$xpos] = chr(0x88 | ($val & 1));
194:                     $val = $val >> 1;
195:                 }
196:             }
197:             $val = $vinf;
198:             for ($ypos = 0; $ypos < 6; ++$ypos) {
199:                 for ($xpos = 0; $xpos < 3; ++$xpos) {
200:                     $frame[$ypos][($xpos + ($width - 11))] = chr(0x88 | ($val & 1));
201:                     $val = $val >> 1;
202:                 }
203:             }
204:         }
205:         // and a little bit...
206:         $frame[$width - 8][8] = "\x81";
207:         return $frame;
208:     }
209: }
210: 
 

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