source-class-Com.Tecnick.Barcode.Type.Square.Datamatrix.Modes

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:  * Modes.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\Datamatrix;
 17: 
 18: use \Com\Tecnick\Barcode\Exception as BarcodeException;
 19: 
 20: /**
 21:  * Com\Tecnick\Barcode\Type\Square\Datamatrix\Modes
 22:  *
 23:  * Modes for Datamatrix Barcode type class
 24:  *
 25:  * @since       2015-02-21
 26:  * @category    Library
 27:  * @package     Barcode
 28:  * @author      Nicola Asuni <info@tecnick.com>
 29:  * @copyright   2010-2016 Nicola Asuni - Tecnick.com LTD
 30:  * @license     http://www.gnu.org/copyleft/lesser.html GNU-LGPL v3 (see LICENSE.TXT)
 31:  * @link        https://github.com/tecnickcom/tc-lib-barcode
 32:  */
 33: abstract class Modes extends \Com\Tecnick\Barcode\Type\Square\Datamatrix\Placement
 34: {
 35:     /**
 36:      * Return the 253-state codeword
 37:      *
 38:      * @param int $cdwpad Pad codeword.
 39:      * @param int $cdwpos Number of data codewords from the beginning of encoded data.
 40:      *
 41:      * @return pad codeword
 42:      */
 43:     public function get253StateCodeword($cdwpad, $cdwpos)
 44:     {
 45:         $pad = ($cdwpad + (((149 * $cdwpos) % 253) + 1));
 46:         if ($pad > 254) {
 47:             $pad -= 254;
 48:         }
 49:         return $pad;
 50:     }
 51: 
 52:     /**
 53:      * Return the 255-state codeword
 54:      *
 55:      * @param int $cdwpad Pad codeword.
 56:      * @param int $cdwpos Number of data codewords from the beginning of encoded data.
 57:      *
 58:      * @return int pad codeword
 59:      */
 60:     protected function get255StateCodeword($cdwpad, $cdwpos)
 61:     {
 62:         $pad = ($cdwpad + (((149 * $cdwpos) % 255) + 1));
 63:         if ($pad > 255) {
 64:             $pad -= 256;
 65:         }
 66:         return $pad;
 67:     }
 68: 
 69:     /**
 70:      * Returns true if the char belongs to the selected mode
 71:      *
 72:      * @param int $chr  Character (byte) to check.
 73:      * @param int $mode Current encoding mode.
 74:      *
 75:      * @return boolean true if the char is of the selected mode.
 76:      */
 77:     protected function isCharMode($chr, $mode)
 78:     {
 79:         $map = array(
 80:             //Data::ENC_ASCII     => 'isASCIIMode',
 81:             Data::ENC_C40       => 'isC40Mode',
 82:             Data::ENC_TXT       => 'isTXTMode',
 83:             Data::ENC_X12       => 'isX12Mode',
 84:             Data::ENC_EDF       => 'isEDFMode',
 85:             Data::ENC_BASE256   => 'isBASE256Mode',
 86:             Data::ENC_ASCII_EXT => 'isASCIIEXTMode',
 87:             Data::ENC_ASCII_NUM => 'isASCIINUMMode'
 88:         );
 89:         $method = $map[$mode];
 90:         return $this->$method($chr);
 91:     }
 92: 
 93:     ///**
 94:     // * Tell if char is ASCII character 0 to 127
 95:     // *
 96:     // * @param int $chr  Character (byte) to check.
 97:     // *
 98:     // * @return boolean
 99:     // */
100:     //protected function isASCIIMode($chr)
101:     //{
102:     //    return (($chr >= 0) && ($chr <= 127));
103:     //}
104: 
105:     /**
106:      * Tell if char is Upper-case alphanumeric
107:      *
108:      * @param int $chr  Character (byte) to check.
109:      *
110:      * @return boolean
111:      */
112:     protected function isC40Mode($chr)
113:     {
114:         return (($chr == 32) || (($chr >= 48) && ($chr <= 57)) || (($chr >= 65) && ($chr <= 90)));
115:     }
116: 
117:     /**
118:      * Tell if char is Lower-case alphanumeric
119:      *
120:      * @param int $chr  Character (byte) to check.
121:      *
122:      * @return boolean
123:      */
124:     protected function isTXTMode($chr)
125:     {
126:         return (($chr == 32) || (($chr >= 48) && ($chr <= 57)) || (($chr >= 97) && ($chr <= 122)));
127:     }
128: 
129:     /**
130:      * Tell if char is ANSI X12
131:      *
132:      * @param int $chr  Character (byte) to check.
133:      *
134:      * @return boolean
135:      */
136:     protected function isX12Mode($chr)
137:     {
138:         return (($chr == 13) || ($chr == 42) || ($chr == 62));
139:     }
140: 
141:     /**
142:      * Tell if char is ASCII character 32 to 94
143:      *
144:      * @param int $chr  Character (byte) to check.
145:      *
146:      * @return boolean
147:      */
148:     protected function isEDFMode($chr)
149:     {
150:         return (($chr >= 32) && ($chr <= 94));
151:     }
152: 
153:     /**
154:      * Tell if char is Function character (FNC1, Structured Append, Reader Program, or Code Page)
155:      *
156:      * @param int $chr  Character (byte) to check.
157:      *
158:      * @return boolean
159:      */
160:     protected function isBASE256Mode($chr)
161:     {
162:         return (($chr == 232) || ($chr == 233) || ($chr == 234) || ($chr == 241));
163:     }
164: 
165:     /**
166:      * Tell if char is ASCII character 128 to 255
167:      *
168:      * @param int $chr  Character (byte) to check.
169:      *
170:      * @return boolean
171:      */
172:     protected function isASCIIEXTMode($chr)
173:     {
174:         return (($chr >= 128) && ($chr <= 255));
175:     }
176: 
177:     /**
178:      * Tell if char is ASCII digits
179:      *
180:      * @param int $chr  Character (byte) to check.
181:      *
182:      * @return boolean
183:      */
184:     protected function isASCIINUMMode($chr)
185:     {
186:         return (($chr >= 48) && ($chr <= 57));
187:     }
188: 
189:     /**
190:      * Choose the minimum matrix size and return the max number of data codewords.
191:      *
192:      * @param int $numcw Number of current codewords.
193:      *
194:      * @return number of data codewords in matrix
195:      */
196:     protected function getMaxDataCodewords($numcw)
197:     {
198:         $mdc = 0;
199:         foreach (Data::$symbattr as $matrix) {
200:             if ($matrix[11] >= $numcw) {
201:                 $mdc = $matrix[11];
202:                 break;
203:             }
204:         }
205:         return $mdc;
206:     }
207: 
208:     /**
209:      * Get the switching codeword to a new encoding mode (latch codeword)
210:      * @param $mode (int) New encoding mode.
211:      * @return (int) Switch codeword.
212:      * @protected
213:      */
214:     protected function getSwitchEncodingCodeword($mode)
215:     {
216:         $map = array(
217:             Data::ENC_ASCII   => 254,
218:             Data::ENC_C40     => 230,
219:             Data::ENC_TXT     => 239,
220:             Data::ENC_X12     => 238,
221:             Data::ENC_EDF     => 240,
222:             Data::ENC_BASE256 => 231
223:         );
224:         $cdw = $map[$mode];
225:         if (($cdw == 254) && ($this->last_enc == Data::ENC_EDF)) {
226:             $cdw = 124;
227:         }
228:         return $cdw;
229:     }
230: }
231: 
 

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