Source for file BarcodeObject
Documentation is available at BarcodeObject
//============================================================+
// File name : c128aobject.php
// Last Update : 2004-12-29
// Author : Karim Mribti [barcode@mribti.com]
// Version : 0.0.8a 2001-04-01 (original code)
// License : GNU LGPL (Lesser General Public License) 2.1
// http://www.gnu.org/copyleft/lesser.txt
// Source Code : http://www.mribti.com/barcode/
// Description : Code 128-A Barcode Render Class for PHP using
// the GD graphics library.
// Code 128-A is a continuous, multilevel and
// include all upper case alphanumeric characters
// and ASCII control characters.
// This version contains changes by Nicola Asuni:
// - code style and formatting
// - automatic php documentation in PhpDocumentor Style
//============================================================+
* Code 128-A Barcode Render Class for PHP using the GD graphics library.<br>
* Code 128-A is a continuous, multilevel and include all upper case alphanumeric characters and ASCII control characters.
* @author Karim Mribti, Nicola Asuni
* @package linea21.externals
* @subpackage com.tecnick.tcpdf
* @version 0.0.8a 2001-04-01 (original code)
* @license http://www.gnu.org/copyleft/lesser.html LGPL
* Code 128-A Barcode Render Class for PHP using the GD graphics library.<br>
* Code 128-A is a continuous, multilevel and include all upper case alphanumeric characters and ASCII control characters.
* @author Karim Mribti, Nicola Asuni
* @package linea21.externals
* @version 0.0.8a 2001-04-01 (original code)
* @license http://www.gnu.org/copyleft/lesser.html LGPL
* @param int $Width Image width in pixels.
* @param int $Height Image height in pixels.
* @param int $Style Barcode style.
* @param int $Value value to print on barcode.
public function __construct($Width, $Height, $Style, $Value) {
$this->mChars = " !\"#$%&'()*+�-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\\]^_";
* Returns the character index.
* @param char $char character.
* @return int character index or -1 in case of error.
private function GetCharIndex($char) {
if ($this->mChars[$i] == $char) {
* @param int $xres Horizontal resolution.
* @param char $char Character.
* @return int barcode size.
private function GetBarSize($xres, $char) {
* @param int $xres Horizontal resolution.
private function GetSize($xres) {
for ($i= 0;$i< $len;$i++ ) {
if (($id = $this->GetCharIndex($this->mValue[$i])) == - 1) {
$this->mError = "C128A not include the char '". $this->mValue[$i]. "'";
$ret += $this->GetBarSize($xres, $cset[0]);
$ret += $this->GetBarSize($xres, $cset[1]);
$ret += $this->GetBarSize($xres, $cset[2]);
$ret += $this->GetBarSize($xres, $cset[3]);
$ret += $this->GetBarSize($xres, $cset[4]);
$ret += $this->GetBarSize($xres, $cset[5]);
/* length of Check character */
$cset = $this->GetCheckCharValue();
$CheckSize += $this->GetBarSize($cset[$i], $xres);
return $StartSize + $ret + $CheckSize + $StopSize;
* Returns the check-char value.
private function GetCheckCharValue() {
for ($i= 0;$i< $len;$i++ ) {
$sum += $this->GetCharIndex($this->mValue[$i]) * ($i+ 1);
* @param int $DrawPos Drawing position.
* @param int $yPos Vertical position.
* @param int $ySize Vertical size.
* @param int $xres Horizontal resolution.
* @return int drawing position.
private function DrawStart($DrawPos, $yPos, $ySize, $xres) {
/* Start code is '211412' */
$DrawPos += $this->GetBarSize('2', $xres);
$DrawPos += $this->GetBarSize('1', $xres);
$DrawPos += $this->GetBarSize('1', $xres);
$DrawPos += $this->GetBarSize('4', $xres);
$DrawPos += $this->GetBarSize('1', $xres);
$DrawPos += $this->GetBarSize('2', $xres);
* @param int $DrawPos Drawing position.
* @param int $yPos Vertical position.
* @param int $ySize Vertical size.
* @param int $xres Horizontal resolution.
* @return int drawing position.
private function DrawStop($DrawPos, $yPos, $ySize, $xres) {
/* Stop code is '2331112' */
$DrawPos += $this->GetBarSize('2', $xres);
$DrawPos += $this->GetBarSize('3', $xres);
$DrawPos += $this->GetBarSize('3', $xres);
$DrawPos += $this->GetBarSize('1', $xres);
$DrawPos += $this->GetBarSize('1', $xres);
$DrawPos += $this->GetBarSize('1', $xres);
$DrawPos += $this->GetBarSize('2', $xres);
* Draws the check-char code.
* @param int $DrawPos Drawing position.
* @param int $yPos Vertical position.
* @param int $ySize Vertical size.
* @param int $xres Horizontal resolution.
* @return int drawing position.
private function DrawCheckChar($DrawPos, $yPos, $ySize, $xres) {
$cset = $this->GetCheckCharValue();
$DrawPos += $this->GetBarSize($cset[0], $xres);
$DrawPos += $this->GetBarSize($cset[1], $xres);
$DrawPos += $this->GetBarSize($cset[2], $xres);
$DrawPos += $this->GetBarSize($cset[3], $xres);
$DrawPos += $this->GetBarSize($cset[4], $xres);
$DrawPos += $this->GetBarSize($cset[5], $xres);
* Draws the barcode object.
* @param int $xres Horizontal resolution.
* @return bool true in case of success.
if (($size = $this->GetSize($xres))== 0) {
/* Total height of bar code -Bars only- */
for ($i= 0;$i< $len;$i++ ) {
$c = $this->GetCharIndex($this->mValue[$cPos]);
$DrawPos += $this->GetBarSize($cset[0], $xres);
$DrawPos += $this->GetBarSize($cset[1], $xres);
$DrawPos += $this->GetBarSize($cset[2], $xres);
$DrawPos += $this->GetBarSize($cset[3], $xres);
$DrawPos += $this->GetBarSize($cset[4], $xres);
$DrawPos += $this->GetBarSize($cset[5], $xres);
//============================================================+
//============================================================+
|