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

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:  * Placement.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\Placement
 22:  *
 23:  * Placement methods 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 Placement
 34: {
 35:     /**
 36:      * Places "chr+bit" with appropriate wrapping within array[].
 37:      * (Annex F - ECC 200 symbol character placement)
 38:      *
 39:      * @param array $marr  Array of symbols.
 40:      * @param int   $nrow  Number of rows.
 41:      * @param int   $ncol  Number of columns.
 42:      * @param int   $row   Row number.
 43:      * @param int   $col   Column number.
 44:      * @param int   $chr   Char byte.
 45:      * @param int   $bit   Bit.
 46:      *
 47:      * @return array
 48:      */
 49:     protected function placeModule($marr, $nrow, $ncol, $row, $col, $chr, $bit)
 50:     {
 51:         if ($row < 0) {
 52:             $row += $nrow;
 53:             $col += (4 - (($nrow + 4) % 8));
 54:         }
 55:         if ($col < 0) {
 56:             $col += $ncol;
 57:             $row += (4 - (($ncol + 4) % 8));
 58:         }
 59:         $marr[(($row * $ncol) + $col)] = ((10 * $chr) + $bit);
 60:         return $marr;
 61:     }
 62: 
 63:     /**
 64:      * Places the 8 bits of a utah-shaped symbol character.
 65:      * (Annex F - ECC 200 symbol character placement)
 66:      *
 67:      * @param array $marr  Array of symbols.
 68:      * @param int   $nrow  Number of rows.
 69:      * @param int   $ncol  Number of columns.
 70:      * @param int   $row   Row number.
 71:      * @param int   $col   Column number.
 72:      * @param int   $chr   Char byte.
 73:      *
 74:      * @return array
 75:      */
 76:     protected function placeUtah($marr, $nrow, $ncol, $row, $col, $chr)
 77:     {
 78:         $marr = $this->placeModule($marr, $nrow, $ncol, $row-2, $col-2, $chr, 1);
 79:         $marr = $this->placeModule($marr, $nrow, $ncol, $row-2, $col-1, $chr, 2);
 80:         $marr = $this->placeModule($marr, $nrow, $ncol, $row-1, $col-2, $chr, 3);
 81:         $marr = $this->placeModule($marr, $nrow, $ncol, $row-1, $col-1, $chr, 4);
 82:         $marr = $this->placeModule($marr, $nrow, $ncol, $row-1, $col, $chr, 5);
 83:         $marr = $this->placeModule($marr, $nrow, $ncol, $row, $col-2, $chr, 6);
 84:         $marr = $this->placeModule($marr, $nrow, $ncol, $row, $col-1, $chr, 7);
 85:         $marr = $this->placeModule($marr, $nrow, $ncol, $row, $col, $chr, 8);
 86:         return $marr;
 87:     }
 88: 
 89:     /**
 90:      * Places the 8 bits of the first special corner case.
 91:      * (Annex F - ECC 200 symbol character placement)
 92:      *
 93:      * @param array $marr  Array of symbols
 94:      * @param int   $nrow  Number of rows
 95:      * @param int   $ncol  Number of columns
 96:      * @param int   $chr   Char byte
 97:      * @param int   $row   Current row
 98:      * @param int   $col   Current column
 99:      *
100:      * @return array
101:      */
102:     protected function placeCornerA($marr, $nrow, $ncol, &$chr, $row, $col)
103:     {
104:         if (($row != $nrow) || ($col != 0)) {
105:             return $marr;
106:         }
107:         $marr = $this->placeModule($marr, $nrow, $ncol, $nrow-1, 0, $chr, 1);
108:         $marr = $this->placeModule($marr, $nrow, $ncol, $nrow-1, 1, $chr, 2);
109:         $marr = $this->placeModule($marr, $nrow, $ncol, $nrow-1, 2, $chr, 3);
110:         $marr = $this->placeModule($marr, $nrow, $ncol, 0, $ncol-2, $chr, 4);
111:         $marr = $this->placeModule($marr, $nrow, $ncol, 0, $ncol-1, $chr, 5);
112:         $marr = $this->placeModule($marr, $nrow, $ncol, 1, $ncol-1, $chr, 6);
113:         $marr = $this->placeModule($marr, $nrow, $ncol, 2, $ncol-1, $chr, 7);
114:         $marr = $this->placeModule($marr, $nrow, $ncol, 3, $ncol-1, $chr, 8);
115:         ++$chr;
116:         return $marr;
117:     }
118: 
119:     /**
120:      * Places the 8 bits of the second special corner case.
121:      * (Annex F - ECC 200 symbol character placement)
122:      *
123:      * @param array $marr  Array of symbols
124:      * @param int   $nrow  Number of rows
125:      * @param int   $ncol  Number of columns
126:      * @param int   $chr   Char byte
127:      * @param int   $row   Current row
128:      * @param int   $col   Current column
129:      *
130:      * @return array
131:      */
132:     protected function placeCornerB($marr, $nrow, $ncol, &$chr, $row, $col)
133:     {
134:         if (($row != ($nrow - 2)) || ($col != 0) || (($ncol % 4) == 0)) {
135:             return $marr;
136:         }
137:         $marr = $this->placeModule($marr, $nrow, $ncol, $nrow-3, 0, $chr, 1);
138:         $marr = $this->placeModule($marr, $nrow, $ncol, $nrow-2, 0, $chr, 2);
139:         $marr = $this->placeModule($marr, $nrow, $ncol, $nrow-1, 0, $chr, 3);
140:         $marr = $this->placeModule($marr, $nrow, $ncol, 0, $ncol-4, $chr, 4);
141:         $marr = $this->placeModule($marr, $nrow, $ncol, 0, $ncol-3, $chr, 5);
142:         $marr = $this->placeModule($marr, $nrow, $ncol, 0, $ncol-2, $chr, 6);
143:         $marr = $this->placeModule($marr, $nrow, $ncol, 0, $ncol-1, $chr, 7);
144:         $marr = $this->placeModule($marr, $nrow, $ncol, 1, $ncol-1, $chr, 8);
145:         ++$chr;
146:         return $marr;
147:     }
148: 
149:     /**
150:      * Places the 8 bits of the third special corner case.
151:      * (Annex F - ECC 200 symbol character placement)
152:      *
153:      * @param array $marr  Array of symbols
154:      * @param int   $nrow  Number of rows
155:      * @param int   $ncol  Number of columns
156:      * @param int   $chr   Char byte
157:      * @param int   $row   Current row
158:      * @param int   $col   Current column
159:      *
160:      * @return array
161:      */
162:     protected function placeCornerC($marr, $nrow, $ncol, &$chr, $row, $col)
163:     {
164:         if (($row != ($nrow - 2)) || ($col != 0) || (($ncol % 8) != 4)) {
165:             return $marr;
166:         }
167:         $marr = $this->placeModule($marr, $nrow, $ncol, $nrow-3, 0, $chr, 1);
168:         $marr = $this->placeModule($marr, $nrow, $ncol, $nrow-2, 0, $chr, 2);
169:         $marr = $this->placeModule($marr, $nrow, $ncol, $nrow-1, 0, $chr, 3);
170:         $marr = $this->placeModule($marr, $nrow, $ncol, 0, $ncol-2, $chr, 4);
171:         $marr = $this->placeModule($marr, $nrow, $ncol, 0, $ncol-1, $chr, 5);
172:         $marr = $this->placeModule($marr, $nrow, $ncol, 1, $ncol-1, $chr, 6);
173:         $marr = $this->placeModule($marr, $nrow, $ncol, 2, $ncol-1, $chr, 7);
174:         $marr = $this->placeModule($marr, $nrow, $ncol, 3, $ncol-1, $chr, 8);
175:         ++$chr;
176:         return $marr;
177:     }
178: 
179:     /**
180:      * Places the 8 bits of the fourth special corner case.
181:      * (Annex F - ECC 200 symbol character placement)
182:      *
183:      * @param array $marr  Array of symbols
184:      * @param int   $nrow  Number of rows
185:      * @param int   $ncol  Number of columns
186:      * @param int   $chr   Char byte
187:      * @param int   $row   Current row
188:      * @param int   $col   Current column
189:      *
190:      * @return array
191:      */
192:     protected function placeCornerD($marr, $nrow, $ncol, &$chr, $row, $col)
193:     {
194:         if (($row != ($nrow + 4)) || ($col != 2) || ($ncol % 8)) {
195:             return $marr;
196:         }
197:         $marr = $this->placeModule($marr, $nrow, $ncol, $nrow-1, 0, $chr, 1);
198:         $marr = $this->placeModule($marr, $nrow, $ncol, $nrow-1, $ncol-1, $chr, 2);
199:         $marr = $this->placeModule($marr, $nrow, $ncol, 0, $ncol-3, $chr, 3);
200:         $marr = $this->placeModule($marr, $nrow, $ncol, 0, $ncol-2, $chr, 4);
201:         $marr = $this->placeModule($marr, $nrow, $ncol, 0, $ncol-1, $chr, 5);
202:         $marr = $this->placeModule($marr, $nrow, $ncol, 1, $ncol-3, $chr, 6);
203:         $marr = $this->placeModule($marr, $nrow, $ncol, 1, $ncol-2, $chr, 7);
204:         $marr = $this->placeModule($marr, $nrow, $ncol, 1, $ncol-1, $chr, 8);
205:         ++$chr;
206:         return $marr;
207:     }
208: 
209:     
210: 
211:     /**
212:      * Sweep upward diagonally, inserting successive characters,
213:      * (Annex F - ECC 200 symbol character placement)
214:      *
215:      * @param array $marr  Array of symbols
216:      * @param int   $nrow  Number of rows
217:      * @param int   $ncol  Number of columns
218:      * @param int   $chr   Char byte
219:      * @param int   $row   Current row
220:      * @param int   $col   Current column
221:      *
222:      * @return array
223:      */
224:     protected function placeSweepUpward($marr, $nrow, $ncol, &$chr, &$row, &$col)
225:     {
226:         do {
227:             if (($row < $nrow) && ($col >= 0) && (!$marr[(($row * $ncol) + $col)])) {
228:                 $marr = $this->placeUtah($marr, $nrow, $ncol, $row, $col, $chr);
229:                 ++$chr;
230:             }
231:             $row -= 2;
232:             $col += 2;
233:         } while (($row >= 0) && ($col < $ncol));
234:         ++$row;
235:         $col += 3;
236:         return $marr;
237:     }
238: 
239:     /**
240:      * Sweep upward diagonally, inserting successive characters,
241:      * (Annex F - ECC 200 symbol character placement)
242:      *
243:      * @param array $marr  Array of symbols
244:      * @param int   $nrow  Number of rows
245:      * @param int   $ncol  Number of columns
246:      * @param int   $chr   Char byte
247:      * @param int   $row   Current row
248:      * @param int   $col   Current column
249:      *
250:      * @return array
251:      */
252:     protected function placeSweepDownward($marr, $nrow, $ncol, &$chr, &$row, &$col)
253:     {
254:         do {
255:             if (($row >= 0) && ($col < $ncol) && (!$marr[(($row * $ncol) + $col)])) {
256:                 $marr = $this->placeUtah($marr, $nrow, $ncol, $row, $col, $chr);
257:                 ++$chr;
258:             }
259:             $row += 2;
260:             $col -= 2;
261:         } while (($row < $nrow) && ($col >= 0));
262:         $row += 3;
263:         ++$col;
264:         return $marr;
265:     }
266: 
267:     /**
268:      * Build a placement map.
269:      * (Annex F - ECC 200 symbol character placement)
270:      *
271:      * @param int $nrow  Number of rows.
272:      * @param int $ncol  Number of columns.
273:      *
274:      * @return array
275:      */
276:     public function getPlacementMap($nrow, $ncol)
277:     {
278:         // initialize array with zeros
279:         $marr = array_fill(0, ($nrow * $ncol), 0);
280:         // set starting values
281:         $chr = 1;
282:         $row = 4;
283:         $col = 0;
284:         do {
285:             // repeatedly first check for one of the special corner cases, then
286:             $marr = $this->placeCornerA($marr, $nrow, $ncol, $chr, $row, $col);
287:             $marr = $this->placeCornerB($marr, $nrow, $ncol, $chr, $row, $col);
288:             $marr = $this->placeCornerC($marr, $nrow, $ncol, $chr, $row, $col);
289:             $marr = $this->placeCornerD($marr, $nrow, $ncol, $chr, $row, $col);
290:             // sweep upward diagonally, inserting successive characters,
291:             $marr = $this->placeSweepUpward($marr, $nrow, $ncol, $chr, $row, $col);
292:             // & then sweep downward diagonally, inserting successive characters,...
293:             $marr = $this->placeSweepDownward($marr, $nrow, $ncol, $chr, $row, $col);
294:             // ... until the entire array is scanned
295:         } while (($row < $nrow) || ($col < $ncol));
296:         // lastly, if the lower righthand corner is untouched, fill in fixed pattern
297:         if (!$marr[(($nrow * $ncol) - 1)]) {
298:             $marr[(($nrow * $ncol) - 1)] = 1;
299:             $marr[(($nrow * $ncol) - $ncol - 2)] = 1;
300:         }
301:         return $marr;
302:     }
303: }
304: 
 

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