adding zend project folders into old campcaster.

This commit is contained in:
naomiaro 2010-12-07 14:19:27 -05:00
parent 56abfaf28e
commit 7ef0c18b26
4045 changed files with 1054952 additions and 0 deletions

View file

@ -0,0 +1,143 @@
<?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-2010 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
* @version $Id: Code25.php 20096 2010-01-06 02:05:09Z bkarwin $
*/
/**
* @see Zend_Barcode_Object_ObjectAbstract
*/
require_once 'Zend/Barcode/Object/ObjectAbstract.php';
/**
* @see Zend_Validate_Barcode
*/
require_once 'Zend/Validate/Barcode.php';
/**
* Class for generate Interleaved 2 of 5 barcode
*
* @category Zend
* @package Zend_Barcode
* @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
*/
class Zend_Barcode_Object_Code25 extends Zend_Barcode_Object_ObjectAbstract
{
/**
* Coding map
* - 0 = narrow bar
* - 1 = wide bar
* @var array
*/
protected $_codingMap = array(
'0' => '00110',
'1' => '10001',
'2' => '01001',
'3' => '11000',
'4' => '00101',
'5' => '10100',
'6' => '01100',
'7' => '00011',
'8' => '10010',
'9' => '01010',
);
/**
* Width of the barcode (in pixels)
* @return integer
*/
protected function _calculateBarcodeWidth()
{
$quietZone = $this->getQuietZone();
$startCharacter = (2 * $this->_barThickWidth + 4 * $this->_barThinWidth) * $this->_factor;
$characterLength = (3 * $this->_barThinWidth + 2 * $this->_barThickWidth + 5 * $this->_barThinWidth)
* $this->_factor;
$encodedData = strlen($this->getText()) * $characterLength;
$stopCharacter = (2 * $this->_barThickWidth + 4 * $this->_barThinWidth) * $this->_factor;
return $quietZone + $startCharacter + $encodedData + $stopCharacter + $quietZone;
}
/**
* Partial check of interleaved 2 of 5 barcode
* @return void
*/
protected function _checkParams()
{
$this->_checkRatio();
}
/**
* Prepare array to draw barcode
* @return array
*/
protected function _prepareBarcode()
{
$barcodeTable = array();
// Start character (30301)
$barcodeTable[] = array(1 , $this->_barThickWidth , 0 , 1);
$barcodeTable[] = array(0 , $this->_barThinWidth , 0 , 1);
$barcodeTable[] = array(1 , $this->_barThickWidth , 0 , 1);
$barcodeTable[] = array(0 , $this->_barThinWidth , 0 , 1);
$barcodeTable[] = array(1 , $this->_barThinWidth , 0 , 1);
$barcodeTable[] = array(0 , 1);
$text = str_split($this->getText());
foreach ($text as $char) {
$barcodeChar = str_split($this->_codingMap[$char]);
foreach ($barcodeChar as $c) {
/* visible, width, top, length */
$width = $c ? $this->_barThickWidth : $this->_barThinWidth;
$barcodeTable[] = array(1 , $width , 0 , 1);
$barcodeTable[] = array(0 , 1);
}
}
// Stop character (30103)
$barcodeTable[] = array(1 , $this->_barThickWidth , 0 , 1);
$barcodeTable[] = array(0 , $this->_barThinWidth , 0 , 1);
$barcodeTable[] = array(1 , $this->_barThinWidth , 0 , 1);
$barcodeTable[] = array(0 , $this->_barThinWidth , 0 , 1);
$barcodeTable[] = array(1 , $this->_barThickWidth , 0 , 1);
return $barcodeTable;
}
/**
* Get barcode checksum
*
* @param string $text
* @return int
*/
public function getChecksum($text)
{
$this->_checkText($text);
$factor = 3;
$checksum = 0;
for ($i = strlen($text); $i > 0; $i --) {
$checksum += intval($text{$i - 1}) * $factor;
$factor = 4 - $factor;
}
$checksum = (10 - ($checksum % 10)) % 10;
return $checksum;
}
}

View file

@ -0,0 +1,179 @@
<?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-2010 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
* @version $Id: Code25interleaved.php 20096 2010-01-06 02:05:09Z bkarwin $
*/
/** @see Zend_Barcode_Object_Code25 */
require_once 'Zend/Barcode/Object/Code25.php';
/** @see Zend_Validate_Barcode */
require_once 'Zend/Validate/Barcode.php';
/**
* Class for generate Interleaved 2 of 5 barcode
*
* @category Zend
* @package Zend_Barcode
* @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
*/
class Zend_Barcode_Object_Code25interleaved extends Zend_Barcode_Object_Code25
{
/**
* Drawing of bearer bars
* @var boolean
*/
private $_withBearerBars = false;
/**
* Default options for Code25interleaved barcode
* @return void
*/
protected function _getDefaultOptions()
{
$this->_barcodeLength = 'even';
}
/**
* Activate/deactivate drawing of bearer bars
* @param boolean $value
* @return Zend_Barcode_Object_Int25
*/
public function setWithBearerBars($value)
{
$this->_withBearerBars = (bool) $value;
return $this;
}
/**
* Retrieve if bearer bars are enabled
* @return boolean
*/
public function getWithBearerBars()
{
return $this->_withBearerBars;
}
/**
* Width of the barcode (in pixels)
* @return integer
*/
protected function _calculateBarcodeWidth()
{
$quietZone = $this->getQuietZone();
$startCharacter = (4 * $this->_barThinWidth) * $this->_factor;
$characterLength = (3 * $this->_barThinWidth + 2 * $this->_barThickWidth) * $this->_factor;
$encodedData = strlen($this->getText()) * $characterLength;
$stopCharacter = ($this->_barThickWidth + 2 * $this->_barThinWidth) * $this->_factor;
return $quietZone + $startCharacter + $encodedData + $stopCharacter + $quietZone;
}
/**
* Prepare array to draw barcode
* @return array
*/
protected function _prepareBarcode()
{
if ($this->_withBearerBars) {
$this->_withBorder = false;
}
// Start character (0000)
$barcodeTable[] = array(1, $this->_barThinWidth, 0, 1);
$barcodeTable[] = array(0, $this->_barThinWidth, 0, 1);
$barcodeTable[] = array(1, $this->_barThinWidth, 0, 1);
$barcodeTable[] = array(0, $this->_barThinWidth, 0, 1);
// Encoded $text
$text = $this->getText();
for ($i = 0; $i < strlen($text); $i += 2) { // Draw 2 chars at a time
$char1 = substr($text, $i, 1);
$char2 = substr($text, $i + 1, 1);
// Interleave
for ($ibar = 0; $ibar < 5; $ibar ++) {
// Draws char1 bar (fore color)
$barWidth = (substr($this->_codingMap[$char1], $ibar, 1))
? $this->_barThickWidth
: $this->_barThinWidth;
$barcodeTable[] = array(1, $barWidth, 0, 1);
// Left space corresponding to char2 (background color)
$barWidth = (substr($this->_codingMap[$char2], $ibar, 1))
? $this->_barThickWidth
: $this->_barThinWidth;
$barcodeTable[] = array(0, $barWidth, 0 , 1);
}
}
// Stop character (100)
$barcodeTable[] = array(1 , $this->_barThickWidth, 0, 1);
$barcodeTable[] = array(0 , $this->_barThinWidth, 0, 1);
$barcodeTable[] = array(1 , $this->_barThinWidth, 0, 1);
return $barcodeTable;
}
/**
* Drawing of bearer bars (if enabled)
*
* @return void
*/
protected function _postDrawBarcode()
{
if (!$this->_withBearerBars) {
return;
}
$width = $this->_barThickWidth * $this->_factor;
$point1 = $this->_rotate(-1, -1);
$point2 = $this->_rotate($this->_calculateWidth() - 1, -1);
$point3 = $this->_rotate($this->_calculateWidth() - 1, $width - 1);
$point4 = $this->_rotate(-1, $width - 1);
$this->_addPolygon(array(
$point1,
$point2,
$point3,
$point4,
));
$point1 = $this->_rotate(
0,
0 + $this->_barHeight * $this->_factor - 1
);
$point2 = $this->_rotate(
$this->_calculateWidth() - 1,
0 + $this->_barHeight * $this->_factor - 1
);
$point3 = $this->_rotate(
$this->_calculateWidth() - 1,
0 + $this->_barHeight * $this->_factor - $width
);
$point4 = $this->_rotate(
0,
0 + $this->_barHeight * $this->_factor - $width
);
$this->_addPolygon(array(
$point1,
$point2,
$point3,
$point4,
));
}
}

View file

@ -0,0 +1,177 @@
<?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-2010 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
* @version $Id: Code39.php 21658 2010-03-27 14:29:57Z mikaelkael $
*/
/**
* @see Zend_Barcode_Object_ObjectAbstract
*/
require_once 'Zend/Barcode/Object/ObjectAbstract.php';
/**
* @see 'Zend_Validate_Barcode'
*/
require_once 'Zend/Validate/Barcode.php';
/**
* Class for generate Code39 barcode
*
* @category Zend
* @package Zend_Barcode
* @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
*/
class Zend_Barcode_Object_Code39 extends Zend_Barcode_Object_ObjectAbstract
{
/**
* Coding map
* @var array
*/
protected $_codingMap = array(
'0' => '000110100',
'1' => '100100001',
'2' => '001100001',
'3' => '101100000',
'4' => '000110001',
'5' => '100110000',
'6' => '001110000',
'7' => '000100101',
'8' => '100100100',
'9' => '001100100',
'A' => '100001001',
'B' => '001001001',
'C' => '101001000',
'D' => '000011001',
'E' => '100011000',
'F' => '001011000',
'G' => '000001101',
'H' => '100001100',
'I' => '001001100',
'J' => '000011100',
'K' => '100000011',
'L' => '001000011',
'M' => '101000010',
'N' => '000010011',
'O' => '100010010',
'P' => '001010010',
'Q' => '000000111',
'R' => '100000110',
'S' => '001000110',
'T' => '000010110',
'U' => '110000001',
'V' => '011000001',
'W' => '111000000',
'X' => '010010001',
'Y' => '110010000',
'Z' => '011010000',
'-' => '010000101',
'.' => '110000100',
' ' => '011000100',
'$' => '010101000',
'/' => '010100010',
'+' => '010001010',
'%' => '000101010',
'*' => '010010100',
);
/**
* Partial check of Code39 barcode
* @return void
*/
protected function _checkParams()
{
$this->_checkRatio();
}
/**
* Width of the barcode (in pixels)
* @return int
*/
protected function _calculateBarcodeWidth()
{
$quietZone = $this->getQuietZone();
$characterLength = (6 * $this->_barThinWidth + 3 * $this->_barThickWidth + 1) * $this->_factor;
$encodedData = strlen($this->getText()) * $characterLength - $this->_factor;
return $quietZone + $encodedData + $quietZone;
}
/**
* Retrieve text to display
* @return string
*/
public function getText()
{
return '*' . parent::getText() . '*';
}
/**
* Retrieve text to display
* @return string
*/
public function getTextToDisplay()
{
$text = parent::getTextToDisplay();
if (substr($text, 0, 1) != '*' && substr($text, -1) != '*') {
return '*' . $text . '*';
} else {
return $text;
}
}
/**
* Prepare array to draw barcode
* @return array
*/
protected function _prepareBarcode()
{
$text = str_split($this->getText());
$barcodeTable = array();
foreach ($text as $char) {
$barcodeChar = str_split($this->_codingMap[$char]);
$visible = true;
foreach ($barcodeChar as $c) {
/* visible, width, top, length */
$width = $c ? $this->_barThickWidth : $this->_barThinWidth;
$barcodeTable[] = array((int) $visible, $width, 0, 1);
$visible = ! $visible;
}
$barcodeTable[] = array(0 , 1);
}
return $barcodeTable;
}
/**
* Get barcode checksum
*
* @param string $text
* @return int
*/
public function getChecksum($text)
{
$this->_checkText($text);
$text = str_split($text);
$charset = array_flip(array_keys($this->_codingMap));
$checksum = 0;
foreach ($text as $character) {
$checksum += $charset[$character];
}
return array_search(($checksum % 43), $charset);
}
}

View file

@ -0,0 +1,224 @@
<?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-2010 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
* @version $Id: Ean13.php 20096 2010-01-06 02:05:09Z bkarwin $
*/
/**
* @see Zend_Barcode_Object_ObjectAbstract
*/
require_once 'Zend/Barcode/Object/ObjectAbstract.php';
/**
* @see Zend_Validate_Barcode
*/
require_once 'Zend/Validate/Barcode.php';
/**
* Class for generate Ean13 barcode
*
* @category Zend
* @package Zend_Barcode
* @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
*/
class Zend_Barcode_Object_Ean13 extends Zend_Barcode_Object_ObjectAbstract
{
/**
* Coding map
* - 0 = narrow bar
* - 1 = wide bar
* @var array
*/
protected $_codingMap = array(
'A' => array(
0 => "0001101", 1 => "0011001", 2 => "0010011", 3 => "0111101", 4 => "0100011",
5 => "0110001", 6 => "0101111", 7 => "0111011", 8 => "0110111", 9 => "0001011"
),
'B' => array(
0 => "0100111", 1 => "0110011", 2 => "0011011", 3 => "0100001", 4 => "0011101",
5 => "0111001", 6 => "0000101", 7 => "0010001", 8 => "0001001", 9 => "0010111"
),
'C' => array(
0 => "1110010", 1 => "1100110", 2 => "1101100", 3 => "1000010", 4 => "1011100",
5 => "1001110", 6 => "1010000", 7 => "1000100", 8 => "1001000", 9 => "1110100"
));
protected $_parities = array(
0 => array('A','A','A','A','A','A'),
1 => array('A','A','B','A','B','B'),
2 => array('A','A','B','B','A','B'),
3 => array('A','A','B','B','B','A'),
4 => array('A','B','A','A','B','B'),
5 => array('A','B','B','A','A','B'),
6 => array('A','B','B','B','A','A'),
7 => array('A','B','A','B','A','B'),
8 => array('A','B','A','B','B','A'),
9 => array('A','B','B','A','B','A')
);
/**
* Default options for Postnet barcode
* @return void
*/
protected function _getDefaultOptions()
{
$this->_barcodeLength = 13;
$this->_mandatoryChecksum = true;
}
/**
* Width of the barcode (in pixels)
* @return integer
*/
protected function _calculateBarcodeWidth()
{
$quietZone = $this->getQuietZone();
$startCharacter = (3 * $this->_barThinWidth) * $this->_factor;
$middleCharacter = (5 * $this->_barThinWidth) * $this->_factor;
$stopCharacter = (3 * $this->_barThinWidth) * $this->_factor;
$encodedData = (7 * $this->_barThinWidth) * $this->_factor * 12;
return $quietZone + $startCharacter + $middleCharacter + $encodedData + $stopCharacter + $quietZone;
}
/**
* Partial check of interleaved EAN/UPC barcode
* @return void
*/
protected function _checkParams()
{}
/**
* Prepare array to draw barcode
* @return array
*/
protected function _prepareBarcode()
{
$barcodeTable = array();
$height = ($this->_drawText) ? 1.1 : 1;
// Start character (101)
$barcodeTable[] = array(1 , $this->_barThinWidth , 0 , $height);
$barcodeTable[] = array(0 , $this->_barThinWidth , 0 , $height);
$barcodeTable[] = array(1 , $this->_barThinWidth , 0 , $height);
$textTable = str_split($this->getText());
$parity = $this->_parities[$textTable[0]];
// First part
for ($i = 1; $i < 7; $i++) {
$bars = str_split($this->_codingMap[$parity[$i - 1]][$textTable[$i]]);
foreach ($bars as $b) {
$barcodeTable[] = array($b , $this->_barThinWidth , 0 , 1);
}
}
// Middle character (01010)
$barcodeTable[] = array(0 , $this->_barThinWidth , 0 , $height);
$barcodeTable[] = array(1 , $this->_barThinWidth , 0 , $height);
$barcodeTable[] = array(0 , $this->_barThinWidth , 0 , $height);
$barcodeTable[] = array(1 , $this->_barThinWidth , 0 , $height);
$barcodeTable[] = array(0 , $this->_barThinWidth , 0 , $height);
// Second part
for ($i = 7; $i < 13; $i++) {
$bars = str_split($this->_codingMap['C'][$textTable[$i]]);
foreach ($bars as $b) {
$barcodeTable[] = array($b , $this->_barThinWidth , 0 , 1);
}
}
// Stop character (101)
$barcodeTable[] = array(1 , $this->_barThinWidth , 0 , $height);
$barcodeTable[] = array(0 , $this->_barThinWidth , 0 , $height);
$barcodeTable[] = array(1 , $this->_barThinWidth , 0 , $height);
return $barcodeTable;
}
/**
* Get barcode checksum
*
* @param string $text
* @return int
*/
public function getChecksum($text)
{
$this->_checkText($text);
$factor = 3;
$checksum = 0;
for ($i = strlen($text); $i > 0; $i --) {
$checksum += intval($text{$i - 1}) * $factor;
$factor = 4 - $factor;
}
$checksum = (10 - ($checksum % 10)) % 10;
return $checksum;
}
/**
* Partial function to draw text
* @return void
*/
protected function _drawText()
{
if (get_class($this) == 'Zend_Barcode_Object_Ean13') {
$this->_drawEan13Text();
} else {
parent::_drawText();
}
}
protected function _drawEan13Text()
{
if ($this->_drawText) {
$text = $this->getTextToDisplay();
$characterWidth = (7 * $this->_barThinWidth) * $this->_factor;
$leftPosition = $this->getQuietZone() - $characterWidth;
for ($i = 0; $i < $this->_barcodeLength; $i ++) {
$this->_addText(
$text{$i},
$this->_fontSize * $this->_factor,
$this->_rotate(
$leftPosition,
(int) $this->_withBorder * 2
+ $this->_factor * ($this->_barHeight + $this->_fontSize) + 1
),
$this->_font,
$this->_foreColor,
'left',
- $this->_orientation
);
switch ($i) {
case 0:
$factor = 3;
break;
case 6:
$factor = 4;
break;
default:
$factor = 0;
}
$leftPosition = $leftPosition + $characterWidth + ($factor * $this->_barThinWidth * $this->_factor);
}
}
}
}

View file

@ -0,0 +1,65 @@
<?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-2010 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
* @version $Id: Ean2.php 20096 2010-01-06 02:05:09Z bkarwin $
*/
/**
* @see Zend_Barcode_Object_Ean5
*/
require_once 'Zend/Barcode/Object/Ean5.php';
/**
* @see Zend_Validate_Barcode
*/
require_once 'Zend/Validate/Barcode.php';
/**
* Class for generate Ean2 barcode
*
* @category Zend
* @package Zend_Barcode
* @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
*/
class Zend_Barcode_Object_Ean2 extends Zend_Barcode_Object_Ean5
{
protected $_parities = array(
0 => array('A','A'),
1 => array('A','B'),
2 => array('B','A'),
3 => array('B','B')
);
/**
* Default options for Ean2 barcode
* @return void
*/
protected function _getDefaultOptions()
{
$this->_barcodeLength = 2;
}
protected function _getParity($i)
{
$modulo = $this->getText() % 4;
return $this->_parities[$modulo][$i];
}
}

View file

@ -0,0 +1,147 @@
<?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-2010 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
* @version $Id: Ean5.php 20096 2010-01-06 02:05:09Z bkarwin $
*/
/**
* @see Zend_Barcode_Object_Ean13
*/
require_once 'Zend/Barcode/Object/Ean13.php';
/**
* @see Zend_Validate_Barcode
*/
require_once 'Zend/Validate/Barcode.php';
/**
* Class for generate Ean5 barcode
*
* @category Zend
* @package Zend_Barcode
* @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
*/
class Zend_Barcode_Object_Ean5 extends Zend_Barcode_Object_Ean13
{
protected $_parities = array(
0 => array('B','B','A','A','A'),
1 => array('B','A','B','A','A'),
2 => array('B','A','A','B','A'),
3 => array('B','A','A','A','B'),
4 => array('A','B','B','A','A'),
5 => array('A','A','B','B','A'),
6 => array('A','A','A','B','B'),
7 => array('A','B','A','B','A'),
8 => array('A','B','A','A','B'),
9 => array('A','A','B','A','B')
);
/**
* Default options for Ean5 barcode
* @return void
*/
protected function _getDefaultOptions()
{
$this->_barcodeLength = 5;
}
/**
* Width of the barcode (in pixels)
* @return integer
*/
protected function _calculateBarcodeWidth()
{
$quietZone = $this->getQuietZone();
$startCharacter = (5 * $this->_barThinWidth) * $this->_factor;
$middleCharacter = (2 * $this->_barThinWidth) * $this->_factor;
$encodedData = (7 * $this->_barThinWidth) * $this->_factor;
return $quietZone + $startCharacter + ($this->_barcodeLength - 1) * $middleCharacter + $this->_barcodeLength * $encodedData + $quietZone;
}
/**
* Prepare array to draw barcode
* @return array
*/
protected function _prepareBarcode()
{
$barcodeTable = array();
// Start character (01011)
$barcodeTable[] = array(0 , $this->_barThinWidth , 0 , 1);
$barcodeTable[] = array(1 , $this->_barThinWidth , 0 , 1);
$barcodeTable[] = array(0 , $this->_barThinWidth , 0 , 1);
$barcodeTable[] = array(1 , $this->_barThinWidth , 0 , 1);
$barcodeTable[] = array(1 , $this->_barThinWidth , 0 , 1);
$firstCharacter = true;
$textTable = str_split($this->getText());
// Characters
for ($i = 0; $i < $this->_barcodeLength; $i++) {
if ($firstCharacter) {
$firstCharacter = false;
} else {
// Intermediate character (01)
$barcodeTable[] = array(0 , $this->_barThinWidth , 0 , 1);
$barcodeTable[] = array(1 , $this->_barThinWidth , 0 , 1);
}
$bars = str_split($this->_codingMap[$this->_getParity($i)][$textTable[$i]]);
foreach ($bars as $b) {
$barcodeTable[] = array($b , $this->_barThinWidth , 0 , 1);
}
}
return $barcodeTable;
}
/**
* Get barcode checksum
*
* @param string $text
* @return int
*/
public function getChecksum($text)
{
$this->_checkText($text);
$checksum = 0;
for ($i = 0 ; $i < $this->_barcodeLength; $i ++) {
$checksum += intval($text{$i}) * ($i % 2 ? 9 : 3);
}
return ($checksum % 10);
}
protected function _getParity($i)
{
$checksum = $this->getChecksum($this->getText());
return $this->_parities[$checksum][$i];
}
/**
* Retrieve text to encode
* @return string
*/
public function getText()
{
return $this->_addLeadingZeros($this->_text);
}
}

View file

@ -0,0 +1,174 @@
<?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-2010 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
* @version $Id: Ean8.php 20096 2010-01-06 02:05:09Z bkarwin $
*/
/**
* @see Zend_Barcode_Object_Ean13
*/
require_once 'Zend/Barcode/Object/Ean13.php';
/**
* @see Zend_Validate_Barcode
*/
require_once 'Zend/Validate/Barcode.php';
/**
* Class for generate Ean8 barcode
*
* @category Zend
* @package Zend_Barcode
* @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
*/
class Zend_Barcode_Object_Ean8 extends Zend_Barcode_Object_Ean13
{
/**
* Default options for Postnet barcode
* @return void
*/
protected function _getDefaultOptions()
{
$this->_barcodeLength = 8;
$this->_mandatoryChecksum = true;
}
/**
* Width of the barcode (in pixels)
* @return integer
*/
protected function _calculateBarcodeWidth()
{
$quietZone = $this->getQuietZone();
$startCharacter = (3 * $this->_barThinWidth) * $this->_factor;
$stopCharacter = (3 * $this->_barThinWidth) * $this->_factor;
$encodedData = (7 * $this->_barThinWidth) * $this->_factor * 8;
return $quietZone + $startCharacter + $encodedData + $stopCharacter + $quietZone;
}
/**
* Prepare array to draw barcode
* @return array
*/
protected function _prepareBarcode()
{
$barcodeTable = array();
$height = ($this->_drawText) ? 1.1 : 1;
// Start character (101)
$barcodeTable[] = array(1 , $this->_barThinWidth , 0 , $height);
$barcodeTable[] = array(0 , $this->_barThinWidth , 0 , $height);
$barcodeTable[] = array(1 , $this->_barThinWidth , 0 , $height);
$textTable = str_split($this->getText());
// First part
for ($i = 0; $i < 4; $i++) {
$bars = str_split($this->_codingMap['A'][$textTable[$i]]);
foreach ($bars as $b) {
$barcodeTable[] = array($b , $this->_barThinWidth , 0 , 1);
}
}
// Middle character (01010)
$barcodeTable[] = array(0 , $this->_barThinWidth , 0 , $height);
$barcodeTable[] = array(1 , $this->_barThinWidth , 0 , $height);
$barcodeTable[] = array(0 , $this->_barThinWidth , 0 , $height);
$barcodeTable[] = array(1 , $this->_barThinWidth , 0 , $height);
$barcodeTable[] = array(0 , $this->_barThinWidth , 0 , $height);
// Second part
for ($i = 4; $i < 8; $i++) {
$bars = str_split($this->_codingMap['C'][$textTable[$i]]);
foreach ($bars as $b) {
$barcodeTable[] = array($b , $this->_barThinWidth , 0 , 1);
}
}
// Stop character (101)
$barcodeTable[] = array(1 , $this->_barThinWidth , 0 , $height);
$barcodeTable[] = array(0 , $this->_barThinWidth , 0 , $height);
$barcodeTable[] = array(1 , $this->_barThinWidth , 0 , $height);
return $barcodeTable;
}
/**
* Partial function to draw text
* @return void
*/
protected function _drawText()
{
if ($this->_drawText) {
$text = $this->getTextToDisplay();
$characterWidth = (7 * $this->_barThinWidth) * $this->_factor;
$leftPosition = $this->getQuietZone() + (3 * $this->_barThinWidth) * $this->_factor;
for ($i = 0; $i < $this->_barcodeLength; $i ++) {
$this->_addText(
$text{$i},
$this->_fontSize * $this->_factor,
$this->_rotate(
$leftPosition,
(int) $this->_withBorder * 2
+ $this->_factor * ($this->_barHeight + $this->_fontSize) + 1
),
$this->_font,
$this->_foreColor,
'left',
- $this->_orientation
);
switch ($i) {
case 3:
$factor = 4;
break;
default:
$factor = 0;
}
$leftPosition = $leftPosition + $characterWidth + ($factor * $this->_barThinWidth * $this->_factor);
}
}
}
/**
* Particular validation for Ean8 barcode objects
* (to suppress checksum character substitution)
* @param string $value
* @param array $options
*/
protected function _validateText($value, $options = array())
{
$validator = new Zend_Validate_Barcode(array(
'adapter' => 'ean8',
'checksum' => false,
));
$value = $this->_addLeadingZeros($value, true);
if (!$validator->isValid($value)) {
$message = implode("\n", $validator->getMessages());
/**
* @see Zend_Barcode_Object_Exception
*/
require_once 'Zend/Barcode/Object/Exception.php';
throw new Zend_Barcode_Object_Exception($message);
}
}
}

View file

@ -0,0 +1,100 @@
<?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-2010 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
* @version $Id: Error.php 20096 2010-01-06 02:05:09Z bkarwin $
*/
/** @see Zend_Barcode_Object_ObjectAbstract */
require_once 'Zend/Barcode/Object/ObjectAbstract.php';
/**
* Class for generate Barcode
*
* @category Zend
* @package Zend_Barcode
* @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
*/
class Zend_Barcode_Object_Error extends Zend_Barcode_Object_ObjectAbstract
{
/**
* All texts are accepted
* @param string $value
* @return boolean
*/
public function validateText($value)
{
return true;
}
/**
* Height is forced
* @return integer
*/
public function getHeight($recalculate = false)
{
return 40;
}
/**
* Width is forced
* @return integer
*/
public function getWidth($recalculate = false)
{
return 400;
}
/**
* Reset precedent instructions
* and draw the error message
* @return array
*/
public function draw()
{
$this->_instructions = array();
$this->_addText('ERROR:', 10, array(5 , 18), $this->_font, 0, 'left');
$this->_addText($this->_text, 10, array(5 , 32), $this->_font, 0, 'left');
return $this->_instructions;
}
/**
* For compatibility reason
* @return void
*/
protected function _prepareBarcode()
{
}
/**
* For compatibility reason
* @return void
*/
protected function _checkParams()
{
}
/**
* For compatibility reason
* @return void
*/
protected function _calculateBarcodeWidth()
{
}
}

View file

@ -0,0 +1,35 @@
<?php
/**
* Zend Framework
*
* LICENSE
*
* This source file is subject to version 1.0 of the Zend Framework
* license, that is bundled with this package in the file LICENSE.txt, and
* is available through the world-wide-web at the following URL:
* http://framework.zend.com/license/new-bsd. If you did not receive
* a copy of the Zend Framework license and are unable to obtain it
* through the world-wide-web, please send a note to license@zend.com
* so we can mail you a copy immediately.
*
* @category Zend
* @package Zend_Barcode
* @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
* @version $Id: Exception.php 20096 2010-01-06 02:05:09Z bkarwin $
*/
/** @see Zend_Barcode_Exception */
require_once 'Zend/Barcode/Exception.php';
/**
* Zend_Barcode_Renderer_Exception
*
* @category Zend
* @package Zend_Barcode
* @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
*/
class Zend_Barcode_Object_Exception extends Zend_Barcode_Exception
{
}

View file

@ -0,0 +1,95 @@
<?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-2010 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
* @version $Id: Identcode.php 20096 2010-01-06 02:05:09Z bkarwin $
*/
/**
* @see Zend_Barcode_Object_Code25interleaved
*/
require_once 'Zend/Barcode/Object/Code25interleaved.php';
/**
* @see Zend_Validate_Barcode
*/
require_once 'Zend/Validate/Barcode.php';
/**
* Class for generate Identcode barcode
*
* @category Zend
* @package Zend_Barcode
* @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
*/
class Zend_Barcode_Object_Identcode extends Zend_Barcode_Object_Code25interleaved
{
/**
* Default options for Identcode barcode
* @return void
*/
protected function _getDefaultOptions()
{
$this->_barcodeLength = 12;
$this->_mandatoryChecksum = true;
}
/**
* Retrieve text to display
* @return string
*/
public function getTextToDisplay()
{
return preg_replace('/([0-9]{2})([0-9]{3})([0-9]{3})([0-9]{3})([0-9])/',
'$1.$2 $3.$4 $5',
$this->getText());
}
/**
* Check allowed characters
* @param string $value
* @return string
* @throw Zend_Barcode_Object_Exception
*/
public function validateText($value)
{
$this->_validateText($value, array('validator' => $this->getType()));
}
/**
* Get barcode checksum
*
* @param string $text
* @return int
*/
public function getChecksum($text)
{
$this->_checkText($text);
$checksum = 0;
for ($i = strlen($text); $i > 0; $i --) {
$checksum += intval($text{$i - 1}) * (($i % 2) ? 4 : 9);
}
$checksum = (10 - ($checksum % 10)) % 10;
return $checksum;
}
}

View file

@ -0,0 +1,49 @@
<?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-2010 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
* @version $Id: Itf14.php 20096 2010-01-06 02:05:09Z bkarwin $
*/
/** @see Zend_Barcode_Object_Code25interleaved */
require_once 'Zend/Barcode/Object/Code25interleaved.php';
/** @see Zend_Validate_Barcode */
require_once 'Zend/Validate/Barcode.php';
/**
* Class for generate Itf14 barcode
*
* @category Zend
* @package Zend_Barcode
* @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
*/
class Zend_Barcode_Object_Itf14 extends Zend_Barcode_Object_Code25interleaved
{
/**
* Default options for Identcode barcode
* @return void
*/
protected function _getDefaultOptions()
{
$this->_barcodeLength = 14;
$this->_mandatoryChecksum = true;
}
}

View file

@ -0,0 +1,64 @@
<?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-2010 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
* @version $Id: Leitcode.php 20096 2010-01-06 02:05:09Z bkarwin $
*/
/**
* @see Zend_Barcode_Object_Identcode
*/
require_once 'Zend/Barcode/Object/Identcode.php';
/**
* @see Zend_Validate_Barcode
*/
require_once 'Zend/Validate/Barcode.php';
/**
* Class for generate Identcode barcode
*
* @category Zend
* @package Zend_Barcode
* @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
*/
class Zend_Barcode_Object_Leitcode extends Zend_Barcode_Object_Identcode
{
/**
* Default options for Leitcode barcode
* @return void
*/
protected function _getDefaultOptions()
{
$this->_barcodeLength = 14;
$this->_mandatoryChecksum = true;
}
/**
* Retrieve text to display
* @return string
*/
public function getTextToDisplay()
{
return preg_replace('/([0-9]{5})([0-9]{3})([0-9]{3})([0-9]{2})([0-9])/',
'$1.$2.$3.$4 $5',
$this->getText());
}
}

File diff suppressed because it is too large Load diff

View file

@ -0,0 +1,62 @@
<?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-2010 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
* @version $Id: Planet.php 20096 2010-01-06 02:05:09Z bkarwin $
*/
/**
* @see Zend_Barcode_Object_Postnet
*/
require_once 'Zend/Barcode/Object/Postnet.php';
/**
* @see Zend_Validate_Barcode
*/
require_once 'Zend/Validate/Barcode.php';
/**
* Class for generate Planet barcode
*
* @category Zend
* @package Zend_Barcode
* @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
*/
class Zend_Barcode_Object_Planet extends Zend_Barcode_Object_Postnet
{
/**
* Coding map
* - 0 = half bar
* - 1 = complete bar
* @var array
*/
protected $_codingMap = array(
0 => "00111",
1 => "11100",
2 => "11010",
3 => "11001",
4 => "10110",
5 => "10101",
6 => "10011",
7 => "01110",
8 => "01101",
9 => "01011"
);
}

View file

@ -0,0 +1,136 @@
<?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-2010 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
* @version $Id: Postnet.php 20096 2010-01-06 02:05:09Z bkarwin $
*/
/**
* @see Zend_Barcode_Object_ObjectAbstract
*/
require_once 'Zend/Barcode/Object/ObjectAbstract.php';
/**
* @see Zend_Validate_Barcode
*/
require_once 'Zend/Validate/Barcode.php';
/**
* Class for generate Postnet barcode
*
* @category Zend
* @package Zend_Barcode
* @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
*/
class Zend_Barcode_Object_Postnet extends Zend_Barcode_Object_ObjectAbstract
{
/**
* Coding map
* - 0 = half bar
* - 1 = complete bar
* @var array
*/
protected $_codingMap = array(
0 => "11000",
1 => "00011",
2 => "00101",
3 => "00110",
4 => "01001",
5 => "01010",
6 => "01100",
7 => "10001",
8 => "10010",
9 => "10100"
);
/**
* Default options for Postnet barcode
* @return void
*/
protected function _getDefaultOptions()
{
$this->_barThinWidth = 2;
$this->_barHeight = 20;
$this->_drawText = false;
$this->_stretchText = true;
$this->_mandatoryChecksum = true;
}
/**
* Width of the barcode (in pixels)
* @return integer
*/
protected function _calculateBarcodeWidth()
{
$quietZone = $this->getQuietZone();
$startCharacter = (2 * $this->_barThinWidth) * $this->_factor;
$stopCharacter = (1 * $this->_barThinWidth) * $this->_factor;
$encodedData = (10 * $this->_barThinWidth) * $this->_factor * strlen($this->getText());
return $quietZone + $startCharacter + $encodedData + $stopCharacter + $quietZone;
}
/**
* Partial check of interleaved Postnet barcode
* @return void
*/
protected function _checkParams()
{}
/**
* Prepare array to draw barcode
* @return array
*/
protected function _prepareBarcode()
{
$barcodeTable = array();
// Start character (1)
$barcodeTable[] = array(1 , $this->_barThinWidth , 0 , 1);
$barcodeTable[] = array(0 , $this->_barThinWidth , 0 , 1);
// Text to encode
$textTable = str_split($this->getText());
foreach ($textTable as $char) {
$bars = str_split($this->_codingMap[$char]);
foreach ($bars as $b) {
$barcodeTable[] = array(1 , $this->_barThinWidth , 0.5 - $b * 0.5 , 1);
$barcodeTable[] = array(0 , $this->_barThinWidth , 0 , 1);
}
}
// Stop character (1)
$barcodeTable[] = array(1 , $this->_barThinWidth , 0 , 1);
return $barcodeTable;
}
/**
* Get barcode checksum
*
* @param string $text
* @return int
*/
public function getChecksum($text)
{
$this->_checkText($text);
$sum = array_sum(str_split($text));
$checksum = (10 - ($sum % 10)) % 10;
return $checksum;
}
}

View file

@ -0,0 +1,163 @@
<?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-2010 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
* @version $Id: Royalmail.php 20096 2010-01-06 02:05:09Z bkarwin $
*/
/**
* @see Zend_Barcode_Object_ObjectAbstract
*/
require_once 'Zend/Barcode/Object/ObjectAbstract.php';
/**
* @see Zend_Validate_Barcode
*/
require_once 'Zend/Validate/Barcode.php';
/**
* Class for generate Royal maim barcode
*
* @category Zend
* @package Zend_Barcode
* @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
*/
class Zend_Barcode_Object_Royalmail extends Zend_Barcode_Object_ObjectAbstract
{
/**
* Coding map
* - 0 = Tracker, Ascender and Descender
* - 1 = Tracker and Ascender
* - 2 = Tracker and Descender
* - 3 = Tracker
* @var array
*/
protected $_codingMap = array(
'0' => '3300', '1' => '3210', '2' => '3201', '3' => '2310', '4' => '2301', '5' => '2211',
'6' => '3120', '7' => '3030', '8' => '3021', '9' => '2130', 'A' => '2121', 'B' => '2031',
'C' => '3102', 'D' => '3012', 'E' => '3003', 'F' => '2112', 'G' => '2103', 'H' => '2013',
'I' => '1320', 'J' => '1230', 'K' => '1221', 'L' => '0330', 'M' => '0321', 'N' => '0231',
'O' => '1302', 'P' => '1212', 'Q' => '1203', 'R' => '0312', 'S' => '0303', 'T' => '0213',
'U' => '1122', 'V' => '1032', 'W' => '1023', 'X' => '0132', 'Y' => '0123', 'Z' => '0033'
);
protected $_rows = array(
'0' => 1, '1' => 1, '2' => 1, '3' => 1, '4' => 1, '5' => 1,
'6' => 2, '7' => 2, '8' => 2, '9' => 2, 'A' => 2, 'B' => 2,
'C' => 3, 'D' => 3, 'E' => 3, 'F' => 3, 'G' => 3, 'H' => 3,
'I' => 4, 'J' => 4, 'K' => 4, 'L' => 4, 'M' => 4, 'N' => 4,
'O' => 5, 'P' => 5, 'Q' => 5, 'R' => 5, 'S' => 5, 'T' => 5,
'U' => 0, 'V' => 0, 'W' => 0, 'X' => 0, 'Y' => 0, 'Z' => 0,
);
protected $_columns = array(
'0' => 1, '1' => 2, '2' => 3, '3' => 4, '4' => 5, '5' => 0,
'6' => 1, '7' => 2, '8' => 3, '9' => 4, 'A' => 5, 'B' => 0,
'C' => 1, 'D' => 2, 'E' => 3, 'F' => 4, 'G' => 5, 'H' => 0,
'I' => 1, 'J' => 2, 'K' => 3, 'L' => 4, 'M' => 5, 'N' => 0,
'O' => 1, 'P' => 2, 'Q' => 3, 'R' => 4, 'S' => 5, 'T' => 0,
'U' => 1, 'V' => 2, 'W' => 3, 'X' => 4, 'Y' => 5, 'Z' => 0,
);
/**
* Default options for Postnet barcode
* @return void
*/
protected function _getDefaultOptions()
{
$this->_barThinWidth = 2;
$this->_barHeight = 20;
$this->_drawText = false;
$this->_stretchText = true;
$this->_mandatoryChecksum = true;
}
/**
* Width of the barcode (in pixels)
* @return integer
*/
protected function _calculateBarcodeWidth()
{
$quietZone = $this->getQuietZone();
$startCharacter = (2 * $this->_barThinWidth) * $this->_factor;
$stopCharacter = (1 * $this->_barThinWidth) * $this->_factor;
$encodedData = (8 * $this->_barThinWidth) * $this->_factor * strlen($this->getText());
return $quietZone + $startCharacter + $encodedData + $stopCharacter + $quietZone;
}
/**
* Partial check of interleaved Postnet barcode
* @return void
*/
protected function _checkParams()
{}
/**
* Prepare array to draw barcode
* @return array
*/
protected function _prepareBarcode()
{
$barcodeTable = array();
// Start character (1)
$barcodeTable[] = array(1 , $this->_barThinWidth , 0 , 5/8);
$barcodeTable[] = array(0 , $this->_barThinWidth , 0 , 1);
// Text to encode
$textTable = str_split($this->getText());
foreach ($textTable as $char) {
$bars = str_split($this->_codingMap[$char]);
foreach ($bars as $b) {
$barcodeTable[] = array(1 , $this->_barThinWidth , ($b > 1 ? 3/8 : 0) , ($b % 2 ? 5/8 : 1));
$barcodeTable[] = array(0 , $this->_barThinWidth , 0 , 1);
}
}
// Stop character (1)
$barcodeTable[] = array(1 , $this->_barThinWidth , 0 , 1);
return $barcodeTable;
}
/**
* Get barcode checksum
*
* @param string $text
* @return int
*/
public function getChecksum($text)
{
$this->_checkText($text);
$values = str_split($text);
$rowvalue = 0;
$colvalue = 0;
foreach($values as $row) {
$rowvalue += $this->_rows[$row];
$colvalue += $this->_columns[$row];
}
$rowvalue %= 6;
$colvalue %= 6;
$rowchkvalue = array_keys($this->_rows, $rowvalue);
$colchkvalue = array_keys($this->_columns, $colvalue);
return current(array_intersect($rowchkvalue, $colchkvalue));
}
}

View file

@ -0,0 +1,171 @@
<?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-2010 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
* @version $Id: Upca.php 20096 2010-01-06 02:05:09Z bkarwin $
*/
/**
* @see Zend_Barcode_Object_Ean13
*/
require_once 'Zend/Barcode/Object/Ean13.php';
/**
* @see Zend_Validate_Barcode
*/
require_once 'Zend/Validate/Barcode.php';
/**
* Class for generate UpcA barcode
*
* @category Zend
* @package Zend_Barcode
* @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
*/
class Zend_Barcode_Object_Upca extends Zend_Barcode_Object_Ean13
{
/**
* Default options for Postnet barcode
* @return void
*/
protected function _getDefaultOptions()
{
$this->_barcodeLength = 12;
$this->_mandatoryChecksum = true;
}
/**
* Width of the barcode (in pixels)
* @return integer
*/
protected function _calculateBarcodeWidth()
{
$quietZone = $this->getQuietZone();
$startCharacter = (3 * $this->_barThinWidth) * $this->_factor;
$middleCharacter = (5 * $this->_barThinWidth) * $this->_factor;
$stopCharacter = (3 * $this->_barThinWidth) * $this->_factor;
$encodedData = (7 * $this->_barThinWidth) * $this->_factor * 12;
return $quietZone + $startCharacter + $middleCharacter + $encodedData + $stopCharacter + $quietZone;
}
/**
* Prepare array to draw barcode
* @return array
*/
protected function _prepareBarcode()
{
$barcodeTable = array();
$height = ($this->_drawText) ? 1.1 : 1;
// Start character (101)
$barcodeTable[] = array(1 , $this->_barThinWidth , 0 , $height);
$barcodeTable[] = array(0 , $this->_barThinWidth , 0 , $height);
$barcodeTable[] = array(1 , $this->_barThinWidth , 0 , $height);
$textTable = str_split($this->getText());
// First character
$bars = str_split($this->_codingMap['A'][$textTable[0]]);
foreach ($bars as $b) {
$barcodeTable[] = array($b , $this->_barThinWidth , 0 , $height);
}
// First part
for ($i = 1; $i < 6; $i++) {
$bars = str_split($this->_codingMap['A'][$textTable[$i]]);
foreach ($bars as $b) {
$barcodeTable[] = array($b , $this->_barThinWidth , 0 , 1);
}
}
// Middle character (01010)
$barcodeTable[] = array(0 , $this->_barThinWidth , 0 , $height);
$barcodeTable[] = array(1 , $this->_barThinWidth , 0 , $height);
$barcodeTable[] = array(0 , $this->_barThinWidth , 0 , $height);
$barcodeTable[] = array(1 , $this->_barThinWidth , 0 , $height);
$barcodeTable[] = array(0 , $this->_barThinWidth , 0 , $height);
// Second part
for ($i = 6; $i < 11; $i++) {
$bars = str_split($this->_codingMap['C'][$textTable[$i]]);
foreach ($bars as $b) {
$barcodeTable[] = array($b , $this->_barThinWidth , 0 , 1);
}
}
// Last character
$bars = str_split($this->_codingMap['C'][$textTable[11]]);
foreach ($bars as $b) {
$barcodeTable[] = array($b , $this->_barThinWidth , 0 , $height);
}
// Stop character (101)
$barcodeTable[] = array(1 , $this->_barThinWidth , 0 , $height);
$barcodeTable[] = array(0 , $this->_barThinWidth , 0 , $height);
$barcodeTable[] = array(1 , $this->_barThinWidth , 0 , $height);
return $barcodeTable;
}
/**
* Partial function to draw text
* @return void
*/
protected function _drawText()
{
if ($this->_drawText) {
$text = $this->getTextToDisplay();
$characterWidth = (7 * $this->_barThinWidth) * $this->_factor;
$leftPosition = $this->getQuietZone() - $characterWidth;
for ($i = 0; $i < $this->_barcodeLength; $i ++) {
$fontSize = $this->_fontSize;
if ($i == 0 || $i == 11) {
$fontSize *= 0.8;
}
$this->_addText(
$text{$i},
$fontSize * $this->_factor,
$this->_rotate(
$leftPosition,
(int) $this->_withBorder * 2
+ $this->_factor * ($this->_barHeight + $fontSize) + 1
),
$this->_font,
$this->_foreColor,
'left',
- $this->_orientation
);
switch ($i) {
case 0:
$factor = 10;
break;
case 5:
$factor = 4;
break;
case 10:
$factor = 11;
break;
default:
$factor = 0;
}
$leftPosition = $leftPosition + $characterWidth + ($factor * $this->_barThinWidth * $this->_factor);
}
}
}
}

View file

@ -0,0 +1,227 @@
<?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-2010 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
* @version $Id: Upce.php 20096 2010-01-06 02:05:09Z bkarwin $
*/
/**
* @see Zend_Barcode_Object_Ean13
*/
require_once 'Zend/Barcode/Object/Ean13.php';
/**
* @see Zend_Validate_Barcode
*/
require_once 'Zend/Validate/Barcode.php';
/**
* Class for generate UpcA barcode
*
* @category Zend
* @package Zend_Barcode
* @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
*/
class Zend_Barcode_Object_Upce extends Zend_Barcode_Object_Ean13
{
protected $_parities = array(
0 => array(
0 => array('B','B','B','A','A','A'),
1 => array('B','B','A','B','A','A'),
2 => array('B','B','A','A','B','A'),
3 => array('B','B','A','A','A','B'),
4 => array('B','A','B','B','A','A'),
5 => array('B','A','A','B','B','A'),
6 => array('B','A','A','A','B','B'),
7 => array('B','A','B','A','B','A'),
8 => array('B','A','B','A','A','B'),
9 => array('B','A','A','B','A','B')),
1 => array(
0 => array('A','A','A','B','B','B'),
1 => array('A','A','B','A','B','B'),
2 => array('A','A','B','B','A','B'),
3 => array('A','A','B','B','B','A'),
4 => array('A','B','A','A','B','B'),
5 => array('A','B','B','A','A','B'),
6 => array('A','B','B','B','A','A'),
7 => array('A','B','A','B','A','B'),
8 => array('A','B','A','B','B','A'),
9 => array('A','B','B','A','B','A'))
);
/**
* Default options for Postnet barcode
* @return void
*/
protected function _getDefaultOptions()
{
$this->_barcodeLength = 8;
$this->_mandatoryChecksum = true;
}
/**
* Retrieve text to encode
* @return string
*/
public function getText()
{
$text = parent::getText();
if ($text{0} != 1) {
$text{0} = 0;
}
return $text;
}
/**
* Width of the barcode (in pixels)
* @return integer
*/
protected function _calculateBarcodeWidth()
{
$quietZone = $this->getQuietZone();
$startCharacter = (3 * $this->_barThinWidth) * $this->_factor;
$stopCharacter = (6 * $this->_barThinWidth) * $this->_factor;
$encodedData = (7 * $this->_barThinWidth) * $this->_factor * 6;
return $quietZone + $startCharacter + $encodedData + $stopCharacter + $quietZone;
}
/**
* Prepare array to draw barcode
* @return array
*/
protected function _prepareBarcode()
{
$barcodeTable = array();
$height = ($this->_drawText) ? 1.1 : 1;
// Start character (101)
$barcodeTable[] = array(1 , $this->_barThinWidth , 0 , $height);
$barcodeTable[] = array(0 , $this->_barThinWidth , 0 , $height);
$barcodeTable[] = array(1 , $this->_barThinWidth , 0 , $height);
$textTable = str_split($this->getText());
$system = 0;
if ($textTable[0] == 1) {
$system = 1;
}
$checksum = $textTable[7];
$parity = $this->_parities[$system][$checksum];
for ($i = 1; $i < 7; $i++) {
$bars = str_split($this->_codingMap[$parity[$i - 1]][$textTable[$i]]);
foreach ($bars as $b) {
$barcodeTable[] = array($b , $this->_barThinWidth , 0 , 1);
}
}
// Stop character (10101)
$barcodeTable[] = array(0 , $this->_barThinWidth , 0 , $height);
$barcodeTable[] = array(1 , $this->_barThinWidth , 0 , $height);
$barcodeTable[] = array(0 , $this->_barThinWidth , 0 , $height);
$barcodeTable[] = array(1 , $this->_barThinWidth , 0 , $height);
$barcodeTable[] = array(0 , $this->_barThinWidth , 0 , $height);
$barcodeTable[] = array(1 , $this->_barThinWidth , 0 , $height);
return $barcodeTable;
}
/**
* Partial function to draw text
* @return void
*/
protected function _drawText()
{
if ($this->_drawText) {
$text = $this->getTextToDisplay();
$characterWidth = (7 * $this->_barThinWidth) * $this->_factor;
$leftPosition = $this->getQuietZone() - $characterWidth;
for ($i = 0; $i < $this->_barcodeLength; $i ++) {
$fontSize = $this->_fontSize;
if ($i == 0 || $i == 7) {
$fontSize *= 0.8;
}
$this->_addText(
$text{$i},
$fontSize * $this->_factor,
$this->_rotate(
$leftPosition,
(int) $this->_withBorder * 2
+ $this->_factor * ($this->_barHeight + $fontSize) + 1
),
$this->_font,
$this->_foreColor,
'left',
- $this->_orientation
);
switch ($i) {
case 0:
$factor = 3;
break;
case 6:
$factor = 5;
break;
default:
$factor = 0;
}
$leftPosition = $leftPosition + $characterWidth + ($factor * $this->_barThinWidth * $this->_factor);
}
}
}
/**
* Particular validation for Upce barcode objects
* (to suppress checksum character substitution)
* @param string $value
* @param array $options
*/
protected function _validateText($value, $options = array())
{
$validator = new Zend_Validate_Barcode(array(
'adapter' => 'upce',
'checksum' => false,
));
$value = $this->_addLeadingZeros($value, true);
if (!$validator->isValid($value)) {
$message = implode("\n", $validator->getMessages());
/**
* @see Zend_Barcode_Object_Exception
*/
require_once 'Zend/Barcode/Object/Exception.php';
throw new Zend_Barcode_Object_Exception($message);
}
}
/**
* Get barcode checksum
*
* @param string $text
* @return int
*/
public function getChecksum($text)
{
$text = $this->_addLeadingZeros($text, true);
if ($text{0} != 1) {
$text{0} = 0;
}
return parent::getChecksum($text);
}
}