Source for file BarcodeObject
Documentation is available at BarcodeObject
//============================================================+
// File name : c128cobject.php
// Last Update : 2004-12-29
// Author : Karim Mribti [barcode@mribti.com]
// : Sam Michaels [swampgas@swampgas.org]
// : Nicola Asuni [info@tecnick.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-C Barcode Render Class for PHP using
// the GD graphics library.
// Code 128-C is numeric only and provides the
// This version contains changes by Nicola Asuni:
// - code style and formatting
// - automatic php documentation in PhpDocumentor Style
//============================================================+
* Code 128-C Barcode Render Class for PHP using the GD graphics library.<br>
* Code 128-C is numeric only and provides the most efficiency.
* @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-C Barcode Render Class for PHP using the GD graphics library.<br>
* Code 128-C is numeric only and provides the most efficiency.
* @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
* @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) {
"00", "01", "02", "03", "04", "05", "06", "07", "08", "09",
"10", "11", "12", "13", "14", "15", "16", "17", "18", "19",
"20", "21", "22", "23", "24", "25", "26", "27", "28", "29",
"30", "31", "32", "33", "34", "35", "36", "37", "38", "39",
"40", "41", "42", "43", "44", "45", "46", "47", "48", "49",
"50", "51", "52", "53", "54", "55", "56", "57", "58", "59",
"60", "61", "62", "63", "64", "65", "66", "67", "68", "69",
"70", "71", "72", "73", "74", "75", "76", "77", "78", "79",
"80", "81", "82", "83", "84", "85", "86", "87", "88", "89",
"90", "91", "92", "93", "94", "95", "96", "97", "98", "99",
* 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 ((ord($this->mValue[$i])< 48) || (ord($this->mValue[$i])> 57)) {
$this->mError = "Code-128C is numeric only";
$this->mError = "The length of barcode value must be even. You must pad the number with zeros.";
for ($i= 0;$i< $len;$i+= 2) {
$id = $this->GetCharIndex($this->mValue[$i]. $this->mValue[$i+ 1]);
$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+= 2) {
$sum += $this->GetCharIndex($this->mValue[$i]. $this->mValue[$i+ 1]) * $m;
* @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 '211232' */
$DrawPos += $this->GetBarSize('2', $xres);
$DrawPos += $this->GetBarSize('1', $xres);
$DrawPos += $this->GetBarSize('1', $xres);
$DrawPos += $this->GetBarSize('2', $xres);
$DrawPos += $this->GetBarSize('3', $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]. $this->mValue[$cPos+ 1]);
$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);
//============================================================+
//============================================================+
|