"Fossies" - the Fresh Open Source Software Archive

Member "OCSNG_UNIX_SERVER_2.6/ocsreports/libraries/tclib/Barcode/Type/Linear/Codabar.php" (17 Apr 2019, 2809 Bytes) of package /linux/privat/OCSNG_UNIX_SERVER_2.6.tar.gz:


As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) PHP source code syntax highlighting (style: standard) with prefixed line numbers and code folding option. Alternatively you can here view or download the uninterpreted source code file.

    1 <?php
    2 /**
    3  * Codabar.php
    4  *
    5  * @since       2015-02-21
    6  * @category    Library
    7  * @package     Barcode
    8  * @author      Nicola Asuni <info@tecnick.com>
    9  * @copyright   2015-2015 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/tecnick.com/tc-lib-barcode
   12  *
   13  * This file is part of tc-lib-barcode software library.
   14  */
   15 
   16 namespace Com\Tecnick\Barcode\Type\Linear;
   17 
   18 use \Com\Tecnick\Barcode\Exception as BarcodeException;
   19 
   20 /**
   21  * Com\Tecnick\Barcode\Type\Linear\Codabar;
   22  *
   23  * Codabar Barcode type class
   24  *
   25  * @since       2015-02-21
   26  * @category    Library
   27  * @package     Barcode
   28  * @author      Nicola Asuni <info@tecnick.com>
   29  * @copyright   2015-2015 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/tecnick.com/tc-lib-barcode
   32  */
   33 class Codabar extends \Com\Tecnick\Barcode\Type\Linear
   34 {
   35     /**
   36      * Barcode format
   37      *
   38      * @var string
   39      */
   40     protected $format = 'CODABAR';
   41 
   42     /**
   43      * Map characters to barcodes
   44      *
   45      * @var array
   46      */
   47     protected $chbar = array(
   48         '0' => '11111221',
   49         '1' => '11112211',
   50         '2' => '11121121',
   51         '3' => '22111111',
   52         '4' => '11211211',
   53         '5' => '21111211',
   54         '6' => '12111121',
   55         '7' => '12112111',
   56         '8' => '12211111',
   57         '9' => '21121111',
   58         '-' => '11122111',
   59         '$' => '11221111',
   60         ':' => '21112121',
   61         '/' => '21211121',
   62         '.' => '21212111',
   63         '+' => '11222221',
   64         'A' => '11221211',
   65         'B' => '12121121',
   66         'C' => '11121221',
   67         'D' => '11122211'
   68     );
   69 
   70     /**
   71      * Get the pre-formatted code
   72      *
   73      * @return string
   74      */
   75     protected function formatCode()
   76     {
   77         return 'A'.strtoupper($this->code).'A';
   78     }
   79 
   80     /**
   81      * Get the bars array
   82      *
   83      * @return array
   84      *
   85      * @throws BarcodeException in case of error
   86      */
   87     protected function setBars()
   88     {
   89         $this->ncols = 0;
   90         $this->nrows = 1;
   91         $this->bars = array();
   92         $code = $this->formatCode();
   93         $clen = strlen($code);
   94         for ($chr = 0; $chr < $clen; ++$chr) {
   95             $char = $code[$chr];
   96             if (!isset($this->chbar[$char])) {
   97                 throw new BarcodeException('Invalid character: chr('.ord($char).')');
   98             }
   99             for ($pos = 0; $pos < 8; ++$pos) {
  100                 $bar_width = intval($this->chbar[$char][$pos]);
  101                 if (($pos % 2) == 0) {
  102                     $this->bars[] = array($this->ncols, 0, $bar_width, 1);
  103                 }
  104                 $this->ncols += $bar_width;
  105             }
  106         }
  107         --$this->ncols;
  108     }
  109 }