Skip to content
This repository has been archived by the owner on Jan 29, 2020. It is now read-only.

Commit

Permalink
Merge branch 'master' of git://git.zendframework.com/zf
Browse files Browse the repository at this point in the history
  • Loading branch information
DASPRiD committed Sep 20, 2011
Show file tree
Hide file tree
Showing 24 changed files with 20,566 additions and 7 deletions.
2 changes: 1 addition & 1 deletion src/Object/AbstractObject.php
Expand Up @@ -387,7 +387,7 @@ public function getBarThickWidth()
/**
* Set factor applying to
* thinBarWidth - thickBarWidth - barHeight - fontSize
* @param integer $value
* @param float $value
* @return \Zend\Barcode\BarcodeObject
* @throw \Zend\Barcode\Object\Exception
*/
Expand Down
96 changes: 96 additions & 0 deletions src/Object/Codabar.php
@@ -0,0 +1,96 @@
<?php
/**
* Zend Framework
*
* LICENSE
*
* This source file is subject to the new BSD license that is bundled
* with this package in the file LICENSE.txt.
* It is also available through the world-wide-web at this URL:
* http://framework.zend.com/license/new-bsd
* If you did not receive a copy of the license and are unable to
* obtain it through the world-wide-web, please send an email
* to license@zend.com so we can send you a copy immediately.
*
* @category Zend
* @package Zend_Barcode
* @subpackage Object
* @copyright Copyright (c) 2005-2011 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
*/

/**
* @namespace
*/
namespace Zend\Barcode\Object;

/**
* Class for generate Codabar barcode
*
* @uses \Zend\Barcode\Object\AbstractObject
* @category Zend
* @package Zend_Barcode
* @copyright Copyright (c) 2005-2011 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
*/
class Codabar extends AbstractObject
{
/**
* Coding map
* - 0 = space
* - 1 = bar
* @var array
*/
protected $_codingMap = array(
'0' => "101010011", '1' => "101011001", '2' => "101001011",
'3' => "110010101", '4' => "101101001", '5' => "110101001",
'6' => "100101011", '7' => "100101101", '8' => "100110101",
'9' => "110100101", '-' => "101001101", '$' => "101100101",
':' => "1101011011", '/' => "1101101011", '.' => "1101101101",
'+' => "1011011011", 'A' => "1011001001", 'B' => "1010010011",
'C' => "1001001011", 'D' => "1010011001"
);

/**
* Width of the barcode (in pixels)
* @return integer
*/
protected function _calculateBarcodeWidth()
{
$quietZone = $this->getQuietZone();
$encodedData = 0;
$barcodeChar = str_split($this->getText());
if(count($barcodeChar) > 1) {
foreach ($barcodeChar as $c) {
$encodedData += ((strlen($this->_codingMap[$c]) + 1) * $this->_barThinWidth) * $this->_factor;
}
}
$encodedData -= (1 * $this->_barThinWidth * $this->_factor);
return $quietZone + $encodedData + $quietZone;
}

/**
* Partial check of Codabar barcode
* @return void
*/
protected function _checkParams()
{}

/**
* Prepare array to draw barcode
* @return array
*/
protected function _prepareBarcode()
{
$text = str_split($this->getText());
foreach ($text as $char) {
$barcodeChar = str_split($this->_codingMap[$char]);
foreach ($barcodeChar as $c) {
// visible, width, top, length
$barcodeTable[] = array($c , $this->_barThinWidth , 0 , 1);
}
$barcodeTable[] = array(0 , $this->_barThinWidth);
}
return $barcodeTable;
}
}

0 comments on commit 01cd418

Please sign in to comment.