source-class-Com.Tecnick.Barcode.Type.Convert

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:  * Convert.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;
 17: 
 18: use \Com\Tecnick\Barcode\Exception as BarcodeException;
 19: use \Com\Tecnick\Color\Exception as ColorException;
 20: 
 21: /**
 22:  * Com\Tecnick\Barcode\Type\Convert
 23:  *
 24:  * Barcode Convert class
 25:  *
 26:  * @since       2015-02-21
 27:  * @category    Library
 28:  * @package     Barcode
 29:  * @author      Nicola Asuni <info@tecnick.com>
 30:  * @copyright   2010-2016 Nicola Asuni - Tecnick.com LTD
 31:  * @license     http://www.gnu.org/copyleft/lesser.html GNU-LGPL v3 (see LICENSE.TXT)
 32:  * @link        https://github.com/tecnickcom/tc-lib-barcode
 33:  */
 34: abstract class Convert
 35: {
 36:     /**
 37:      * Import a binary sequence of comma-separated 01 strings
 38:      *
 39:      * @param string $code Code to process
 40:      */
 41:     protected function processBinarySequence($code)
 42:     {
 43:         $raw = new \Com\Tecnick\Barcode\Type\Raw($code, $this->width, $this->height);
 44:         $data = $raw->getArray();
 45:         $this->ncols = $data['ncols'];
 46:         $this->nrows = $data['nrows'];
 47:         $this->bars = $data['bars'];
 48:     }
 49: 
 50:     /**
 51:      * Convert large integer number to hexadecimal representation.
 52:      *
 53:      * @param string $number Number to convert (as string)
 54:      *
 55:      * @return string hexadecimal representation
 56:      */
 57:     protected function convertDecToHex($number)
 58:     {
 59:         if ($number == 0) {
 60:             return '00';
 61:         }
 62:         $hex = array();
 63:         while ($number > 0) {
 64:             array_push($hex, strtoupper(dechex(bcmod($number, '16'))));
 65:             $number = bcdiv($number, '16', 0);
 66:         }
 67:         $hex = array_reverse($hex);
 68:         return implode($hex);
 69:     }
 70: 
 71:     /**
 72:      * Convert large hexadecimal number to decimal representation (string).
 73:      *
 74:      * @param string $hex Hexadecimal number to convert (as string)
 75:      *
 76:      * @return string hexadecimal representation
 77:      */
 78:     protected function convertHexToDec($hex)
 79:     {
 80:         $dec = 0;
 81:         $bitval = 1;
 82:         $len = strlen($hex);
 83:         for ($pos = ($len - 1); $pos >= 0; --$pos) {
 84:             $dec = bcadd($dec, bcmul(hexdec($hex[$pos]), $bitval));
 85:             $bitval = bcmul($bitval, 16);
 86:         }
 87:         return $dec;
 88:     }
 89: 
 90:     /**
 91:      * Get a raw barcode grid array
 92:      *
 93:      * @param string $space_char Character or string to use for filling empty spaces
 94:      * @param string $bar_char   Character or string to use for filling bars
 95:      *
 96:      * @return array
 97:      */
 98:     public function getGridArray($space_char = '0', $bar_char = '1')
 99:     {
100:         $raw = array_fill(0, $this->nrows, array_fill(0, $this->ncols, $space_char));
101:         foreach ($this->bars as $bar) {
102:             if (($bar[2] > 0) && ($bar[3] > 0)) {
103:                 for ($vert = 0; $vert < $bar[3]; ++$vert) {
104:                     for ($horiz = 0; $horiz < $bar[2]; ++$horiz) {
105:                         $raw[($bar[1] + $vert)][($bar[0] + $horiz)] = $bar_char;
106:                     }
107:                 }
108:             }
109:         }
110:         return $raw;
111:     }
112: 
113:     /**
114:      * Returns the bars array ordered by columns
115:      *
116:      * @return array
117:      */
118:     protected function getRotatedBarArray()
119:     {
120:         $grid = $this->getGridArray();
121:         $cols = call_user_func_array('array_map', array(-1 => null) + $grid);
122:         $bars = array();
123:         foreach ($cols as $posx => $col) {
124:             $prevrow = '';
125:             $bar_height = 0;
126:             $col[] = '0';
127:             for ($posy = 0; $posy <= $this->nrows; ++$posy) {
128:                 if ($col[$posy] != $prevrow) {
129:                     if ($prevrow == '1') {
130:                         $bars[] = array($posx, ($posy - $bar_height), 1, $bar_height);
131:                     }
132:                     $bar_height = 0;
133:                 }
134:                 ++$bar_height;
135:                 $prevrow = $col[$posy];
136:             }
137:         }
138:         return $bars;
139:     }
140: 
141:     /**
142:      * Get the adjusted rectangular coordinates (x1,y1,x2,y2) for the specified bar
143:      *
144:      * @param array Raw bar coordinates
145:      *
146:      * @return array Bar coordinates
147:      */
148:     protected function getBarRectXYXY($bar)
149:     {
150:         return array(
151:             ($this->padding['L'] + ($bar[0] * $this->width_ratio)),
152:             ($this->padding['T'] + ($bar[1] * $this->height_ratio)),
153:             ($this->padding['L'] + (($bar[0] + $bar[2]) * $this->width_ratio) - 1),
154:             ($this->padding['T'] + (($bar[1] + $bar[3]) * $this->height_ratio) - 1)
155:         );
156:     }
157: 
158:     /**
159:      * Get the adjusted rectangular coordinates (x,y,w,h) for the specified bar
160:      *
161:      * @param array Raw bar coordinates
162:      *
163:      * @return array Bar coordinates
164:      */
165:     protected function getBarRectXYWH($bar)
166:     {
167:         return array(
168:             ($this->padding['L'] + ($bar[0] * $this->width_ratio)),
169:             ($this->padding['T'] + ($bar[1] * $this->height_ratio)),
170:             ($bar[2] * $this->width_ratio),
171:             ($bar[3] * $this->height_ratio)
172:         );
173:     }
174: }
175: 
 

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