[ Index ] |
PHP Cross Reference of vtigercrm-6.1.0 |
[Summary view] [Print] [Text view]
1 <?php 2 //============================================================+ 3 // File name : i25aobject.php 4 // Begin : 2002-07-31 5 // Last Update : 2004-12-29 6 // Author : Karim Mribti [[email protected]] 7 // : Nicola Asuni [[email protected]] 8 // Version : 0.0.8a 2001-04-01 (original code) 9 // License : GNU LGPL (Lesser General Public License) 2.1 10 // http://www.gnu.org/copyleft/lesser.txt 11 // Source Code : http://www.mribti.com/barcode/ 12 // 13 // Description : I25 Barcode Render Class for PHP using 14 // the GD graphics library. 15 // Interleaved 2 of 5 is a numeric only bar code 16 // with a optional check number. 17 // 18 // NOTE: 19 // This version contains changes by Nicola Asuni: 20 // - porting to PHP5 21 // - code style and formatting 22 // - automatic php documentation in PhpDocumentor Style 23 // (www.phpdoc.org) 24 // - minor bug fixing 25 //============================================================+ 26 27 /** 28 * I25 Barcode Render Class for PHP using the GD graphics library.<br< 29 * Interleaved 2 of 5 is a numeric only bar code with a optional check number. 30 * @author Karim Mribti, Nicola Asuni 31 * @name BarcodeObject 32 * @package com.tecnick.tcpdf 33 * @version 0.0.8a 2001-04-01 (original code) 34 * @since 2001-03-25 35 * @license http://www.gnu.org/copyleft/lesser.html LGPL 36 */ 37 38 /** 39 * I25 Barcode Render Class for PHP using the GD graphics library.<br< 40 * Interleaved 2 of 5 is a numeric only bar code with a optional check number. 41 * @author Karim Mribti, Nicola Asuni 42 * @name BarcodeObject 43 * @package com.tecnick.tcpdf 44 * @version 0.0.8a 2001-04-01 (original code) 45 * @since 2001-03-25 46 * @license http://www.gnu.org/copyleft/lesser.html LGPL 47 */ 48 class I25Object extends BarcodeObject { 49 50 /** 51 * Class Constructor. 52 * @param int $Width Image width in pixels. 53 * @param int $Height Image height in pixels. 54 * @param int $Style Barcode style. 55 * @param int $Value value to print on barcode. 56 */ 57 public function __construct($Width, $Height, $Style, $Value) { 58 parent::__construct($Width, $Height, $Style); 59 $this->mValue = $Value; 60 $this->mCharSet = array ( 61 /* 0 */ "00110", 62 /* 1 */ "10001", 63 /* 2 */ "01001", 64 /* 3 */ "11000", 65 /* 4 */ "00101", 66 /* 5 */ "10100", 67 /* 6 */ "01100", 68 /* 7 */ "00011", 69 /* 8 */ "10010", 70 /* 9 */ "01010" 71 ); 72 } 73 74 /** 75 * Returns barcode size. 76 * @param int $xres Horizontal resolution. 77 * @return barcode size. 78 * @access private 79 */ 80 private function GetSize($xres) { 81 $len = strlen($this->mValue); 82 83 if ($len == 0) { 84 $this->mError = "Null value"; 85 return false; 86 } 87 88 for ($i=0;$i<$len;$i++) { 89 if ((ord($this->mValue[$i])<48) || (ord($this->mValue[$i])>57)) { 90 $this->mError = "I25 is numeric only"; 91 return false; 92 } 93 } 94 95 if (($len%2) != 0) { 96 $this->mError = "The length of barcode value must be even"; 97 return false; 98 } 99 $StartSize = BCD_I25_NARROW_BAR * 4 * $xres; 100 $StopSize = BCD_I25_WIDE_BAR * $xres + 2 * BCD_I25_NARROW_BAR * $xres; 101 $cPos = 0; 102 $sPos = 0; 103 do { 104 $c1 = $this->mValue[$cPos]; 105 $c2 = $this->mValue[$cPos+1]; 106 $cset1 = $this->mCharSet[$c1]; 107 $cset2 = $this->mCharSet[$c2]; 108 109 for ($i=0;$i<5;$i++) { 110 $type1 = ($cset1[$i]==0) ? (BCD_I25_NARROW_BAR * $xres) : (BCD_I25_WIDE_BAR * $xres); 111 $type2 = ($cset2[$i]==0) ? (BCD_I25_NARROW_BAR * $xres) : (BCD_I25_WIDE_BAR * $xres); 112 $sPos += ($type1 + $type2); 113 } 114 $cPos+=2; 115 } while ($cPos<$len); 116 117 return $sPos + $StartSize + $StopSize; 118 } 119 120 /** 121 * Draws the start code. 122 * @param int $DrawPos Drawing position. 123 * @param int $yPos Vertical position. 124 * @param int $ySize Vertical size. 125 * @param int $xres Horizontal resolution. 126 * @return int drawing position. 127 * @access private 128 */ 129 private function DrawStart($DrawPos, $yPos, $ySize, $xres) { 130 /* Start code is "0000" */ 131 $this->DrawSingleBar($DrawPos, $yPos, BCD_I25_NARROW_BAR * $xres , $ySize); 132 $DrawPos += BCD_I25_NARROW_BAR * $xres; 133 $DrawPos += BCD_I25_NARROW_BAR * $xres; 134 $this->DrawSingleBar($DrawPos, $yPos, BCD_I25_NARROW_BAR * $xres , $ySize); 135 $DrawPos += BCD_I25_NARROW_BAR * $xres; 136 $DrawPos += BCD_I25_NARROW_BAR * $xres; 137 return $DrawPos; 138 } 139 140 /** 141 * Draws the stop code. 142 * @param int $DrawPos Drawing position. 143 * @param int $yPos Vertical position. 144 * @param int $ySize Vertical size. 145 * @param int $xres Horizontal resolution. 146 * @return int drawing position. 147 * @access private 148 */ 149 private function DrawStop($DrawPos, $yPos, $ySize, $xres) { 150 /* Stop code is "100" */ 151 $this->DrawSingleBar($DrawPos, $yPos, BCD_I25_WIDE_BAR * $xres , $ySize); 152 $DrawPos += BCD_I25_WIDE_BAR * $xres; 153 $DrawPos += BCD_I25_NARROW_BAR * $xres; 154 $this->DrawSingleBar($DrawPos, $yPos, BCD_I25_NARROW_BAR * $xres , $ySize); 155 $DrawPos += BCD_I25_NARROW_BAR * $xres; 156 return $DrawPos; 157 } 158 159 /** 160 * Draws the barcode object. 161 * @param int $xres Horizontal resolution. 162 * @return bool true in case of success. 163 */ 164 public function DrawObject($xres) { 165 $len = strlen($this->mValue); 166 167 if (($size = $this->GetSize($xres))==0) { 168 return false; 169 } 170 171 $cPos = 0; 172 173 if ($this->mStyle & BCS_DRAW_TEXT) $ysize = $this->mHeight - BCD_DEFAULT_MAR_Y1 - BCD_DEFAULT_MAR_Y2 - $this->GetFontHeight($this->mFont); 174 else $ysize = $this->mHeight - BCD_DEFAULT_MAR_Y1 - BCD_DEFAULT_MAR_Y2; 175 176 if ($this->mStyle & BCS_ALIGN_CENTER) $sPos = (integer)(($this->mWidth - $size ) / 2); 177 else if ($this->mStyle & BCS_ALIGN_RIGHT) $sPos = $this->mWidth - $size; 178 else $sPos = 0; 179 180 if ($this->mStyle & BCS_DRAW_TEXT) { 181 if ($this->mStyle & BCS_STRETCH_TEXT) { 182 /* Stretch */ 183 for ($i=0;$i<$len;$i++) { 184 $this->DrawChar($this->mFont, $sPos+BCD_I25_NARROW_BAR*4*$xres+($size/$len)*$i, 185 $ysize + BCD_DEFAULT_MAR_Y1 + BCD_DEFAULT_TEXT_OFFSET , $this->mValue[$i]); 186 } 187 }else {/* Center */ 188 $text_width = $this->GetFontWidth($this->mFont) * strlen($this->mValue); 189 $this->DrawText($this->mFont, $sPos+(($size-$text_width)/2)+(BCD_I25_NARROW_BAR*4*$xres), 190 $ysize + BCD_DEFAULT_MAR_Y1 + BCD_DEFAULT_TEXT_OFFSET, $this->mValue); 191 } 192 } 193 194 $sPos = $this->DrawStart($sPos, BCD_DEFAULT_MAR_Y1, $ysize, $xres); 195 do { 196 $c1 = $this->mValue[$cPos]; 197 $c2 = $this->mValue[$cPos+1]; 198 $cset1 = $this->mCharSet[$c1]; 199 $cset2 = $this->mCharSet[$c2]; 200 201 for ($i=0;$i<5;$i++) { 202 $type1 = ($cset1[$i]==0) ? (BCD_I25_NARROW_BAR * $xres) : (BCD_I25_WIDE_BAR * $xres); 203 $type2 = ($cset2[$i]==0) ? (BCD_I25_NARROW_BAR * $xres) : (BCD_I25_WIDE_BAR * $xres); 204 $this->DrawSingleBar($sPos, BCD_DEFAULT_MAR_Y1, $type1 , $ysize); 205 $sPos += ($type1 + $type2); 206 } 207 $cPos+=2; 208 } while ($cPos<$len); 209 $sPos = $this->DrawStop($sPos, BCD_DEFAULT_MAR_Y1, $ysize, $xres); 210 return true; 211 } 212 } 213 214 //============================================================+ 215 // END OF FILE 216 //============================================================+ 217 ?>
title
Description
Body
title
Description
Body
title
Description
Body
title
Body
Generated: Fri Nov 28 20:08:37 2014 | Cross-referenced by PHPXref 0.7.1 |