web/lib/Zend/Barcode/Object/Code25interleaved.php
changeset 64 162c1de6545a
parent 19 1c2f13fd785c
child 68 ecaf28ffe26e
equal deleted inserted replaced
63:5b37998e522e 64:162c1de6545a
       
     1 <?php
       
     2 /**
       
     3  * Zend Framework
       
     4  *
       
     5  * LICENSE
       
     6  *
       
     7  * This source file is subject to the new BSD license that is bundled
       
     8  * with this package in the file LICENSE.txt.
       
     9  * It is also available through the world-wide-web at this URL:
       
    10  * http://framework.zend.com/license/new-bsd
       
    11  * If you did not receive a copy of the license and are unable to
       
    12  * obtain it through the world-wide-web, please send an email
       
    13  * to license@zend.com so we can send you a copy immediately.
       
    14  *
       
    15  * @category   Zend
       
    16  * @package    Zend_Barcode
       
    17  * @subpackage Object
       
    18  * @copyright  Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
       
    19  * @license    http://framework.zend.com/license/new-bsd     New BSD License
       
    20  * @version    $Id: Code25interleaved.php 20096 2010-01-06 02:05:09Z bkarwin $
       
    21  */
       
    22 
       
    23 /** @see Zend_Barcode_Object_Code25 */
       
    24 require_once 'Zend/Barcode/Object/Code25.php';
       
    25 
       
    26 /** @see Zend_Validate_Barcode */
       
    27 require_once 'Zend/Validate/Barcode.php';
       
    28 
       
    29 /**
       
    30  * Class for generate Interleaved 2 of 5 barcode
       
    31  *
       
    32  * @category   Zend
       
    33  * @package    Zend_Barcode
       
    34  * @copyright  Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
       
    35  * @license    http://framework.zend.com/license/new-bsd     New BSD License
       
    36  */
       
    37 class Zend_Barcode_Object_Code25interleaved extends Zend_Barcode_Object_Code25
       
    38 {
       
    39     /**
       
    40      * Drawing of bearer bars
       
    41      * @var boolean
       
    42      */
       
    43     private $_withBearerBars = false;
       
    44 
       
    45     /**
       
    46      * Default options for Code25interleaved barcode
       
    47      * @return void
       
    48      */
       
    49     protected function _getDefaultOptions()
       
    50     {
       
    51         $this->_barcodeLength = 'even';
       
    52     }
       
    53 
       
    54     /**
       
    55      * Activate/deactivate drawing of bearer bars
       
    56      * @param boolean $value
       
    57      * @return Zend_Barcode_Object_Int25
       
    58      */
       
    59     public function setWithBearerBars($value)
       
    60     {
       
    61         $this->_withBearerBars = (bool) $value;
       
    62         return $this;
       
    63     }
       
    64 
       
    65     /**
       
    66      * Retrieve if bearer bars are enabled
       
    67      * @return boolean
       
    68      */
       
    69     public function getWithBearerBars()
       
    70     {
       
    71         return $this->_withBearerBars;
       
    72     }
       
    73 
       
    74     /**
       
    75      * Width of the barcode (in pixels)
       
    76      * @return integer
       
    77      */
       
    78     protected function _calculateBarcodeWidth()
       
    79     {
       
    80         $quietZone       = $this->getQuietZone();
       
    81         $startCharacter  = (4 * $this->_barThinWidth) * $this->_factor;
       
    82         $characterLength = (3 * $this->_barThinWidth + 2 * $this->_barThickWidth) * $this->_factor;
       
    83         $encodedData     = strlen($this->getText()) * $characterLength;
       
    84         $stopCharacter   = ($this->_barThickWidth + 2 * $this->_barThinWidth) * $this->_factor;
       
    85         return $quietZone + $startCharacter + $encodedData + $stopCharacter + $quietZone;
       
    86     }
       
    87 
       
    88     /**
       
    89      * Prepare array to draw barcode
       
    90      * @return array
       
    91      */
       
    92     protected function _prepareBarcode()
       
    93     {
       
    94         if ($this->_withBearerBars) {
       
    95             $this->_withBorder = false;
       
    96         }
       
    97 
       
    98         // Start character (0000)
       
    99         $barcodeTable[] = array(1, $this->_barThinWidth, 0, 1);
       
   100         $barcodeTable[] = array(0, $this->_barThinWidth, 0, 1);
       
   101         $barcodeTable[] = array(1, $this->_barThinWidth, 0, 1);
       
   102         $barcodeTable[] = array(0, $this->_barThinWidth, 0, 1);
       
   103 
       
   104         // Encoded $text
       
   105         $text = $this->getText();
       
   106         for ($i = 0; $i < strlen($text); $i += 2) { // Draw 2 chars at a time
       
   107             $char1 = substr($text, $i, 1);
       
   108             $char2 = substr($text, $i + 1, 1);
       
   109 
       
   110             // Interleave
       
   111             for ($ibar = 0; $ibar < 5; $ibar ++) {
       
   112                 // Draws char1 bar (fore color)
       
   113                 $barWidth = (substr($this->_codingMap[$char1], $ibar, 1))
       
   114                           ? $this->_barThickWidth
       
   115                           : $this->_barThinWidth;
       
   116 
       
   117                 $barcodeTable[] = array(1, $barWidth, 0, 1);
       
   118 
       
   119                 // Left space corresponding to char2 (background color)
       
   120                 $barWidth = (substr($this->_codingMap[$char2], $ibar, 1))
       
   121                           ? $this->_barThickWidth
       
   122                           : $this->_barThinWidth;
       
   123                 $barcodeTable[] = array(0, $barWidth, 0 , 1);
       
   124             }
       
   125         }
       
   126 
       
   127         // Stop character (100)
       
   128         $barcodeTable[] = array(1 , $this->_barThickWidth, 0, 1);
       
   129         $barcodeTable[] = array(0 , $this->_barThinWidth,  0, 1);
       
   130         $barcodeTable[] = array(1 , $this->_barThinWidth,  0, 1);
       
   131         return $barcodeTable;
       
   132     }
       
   133 
       
   134     /**
       
   135      * Drawing of bearer bars (if enabled)
       
   136      *
       
   137      * @return void
       
   138      */
       
   139     protected function _postDrawBarcode()
       
   140     {
       
   141         if (!$this->_withBearerBars) {
       
   142             return;
       
   143         }
       
   144 
       
   145         $width  = $this->_barThickWidth * $this->_factor;
       
   146         $point1 = $this->_rotate(-1, -1);
       
   147         $point2 = $this->_rotate($this->_calculateWidth() - 1, -1);
       
   148         $point3 = $this->_rotate($this->_calculateWidth() - 1, $width - 1);
       
   149         $point4 = $this->_rotate(-1, $width - 1);
       
   150         $this->_addPolygon(array(
       
   151             $point1,
       
   152             $point2,
       
   153             $point3,
       
   154             $point4,
       
   155         ));
       
   156         $point1 = $this->_rotate(
       
   157             0,
       
   158             0 + $this->_barHeight * $this->_factor - 1
       
   159         );
       
   160         $point2 = $this->_rotate(
       
   161             $this->_calculateWidth() - 1,
       
   162             0 + $this->_barHeight * $this->_factor - 1
       
   163         );
       
   164         $point3 = $this->_rotate(
       
   165             $this->_calculateWidth() - 1,
       
   166             0 + $this->_barHeight * $this->_factor - $width
       
   167         );
       
   168         $point4 = $this->_rotate(
       
   169             0,
       
   170             0 + $this->_barHeight * $this->_factor - $width
       
   171         );
       
   172         $this->_addPolygon(array(
       
   173             $point1,
       
   174             $point2,
       
   175             $point3,
       
   176             $point4,
       
   177         ));
       
   178     }
       
   179 }