[ Index ]

PHP Cross Reference of vtigercrm-6.1.0

title

Body

[close]

/libraries/tcpdf/barcode/ -> barcode.php (source)

   1  <?php
   2  //============================================================+
   3  // File name   : barcode.php
   4  // Begin       : 2002-07-31
   5  // Last Update : 2005-01-02
   6  // Author      : Karim Mribti [[email protected]]
   7  // Version     : 1.1 [0.0.8a (original code)]
   8  // License     : GNU LGPL (Lesser General Public License) 2.1
   9  //               http://www.gnu.org/copyleft/lesser.txt
  10  // Source Code : http://www.mribti.com/barcode/
  11  //
  12  // Description : Generic Barcode Render Class for PHP using
  13  //               the GD graphics library.
  14  //
  15  // NOTE:
  16  // This version contains changes by Nicola Asuni:
  17  //  - porting to PHP5
  18  //  - code style and formatting
  19  //  - automatic php documentation in PhpDocumentor Style
  20  //    (www.phpdoc.org)
  21  //  - minor bug fixing
  22  //  - $mCharSet and $mChars variables were added here
  23  //============================================================+
  24  
  25  /**
  26   * Barcode Render Class for PHP using the GD graphics library.
  27   * @author Karim Mribti, Nicola Asuni
  28   * @name BarcodeObject
  29   * @package com.tecnick.tcpdf
  30   * @version 0.0.8a 2001-04-01 (original code)
  31   * @since 2001-03-25
  32   * @license http://www.gnu.org/copyleft/lesser.html LGPL
  33   */
  34  
  35  // Styles
  36  // Global
  37  
  38  /**
  39   * option: generate barcode border
  40   */
  41  define("BCS_BORDER", 1);
  42  
  43  /**
  44   * option: use transparent background
  45   */
  46  define("BCS_TRANSPARENT", 2);
  47  
  48  /**
  49   * option: center barcode
  50   */
  51  define("BCS_ALIGN_CENTER", 4);
  52  
  53  /**
  54   * option: align left
  55   */
  56  define("BCS_ALIGN_LEFT", 8);
  57  
  58  /**
  59   * option: align right
  60   */
  61  define("BCS_ALIGN_RIGHT", 16);
  62  
  63  /**
  64   * option: generate JPEG image
  65   */
  66  define("BCS_IMAGE_JPEG", 32);
  67  
  68  /**
  69   * option: generate PNG image
  70   */
  71  define("BCS_IMAGE_PNG", 64);
  72  
  73  /**
  74   * option: draw text
  75   */
  76  define("BCS_DRAW_TEXT", 128);
  77  
  78  /**
  79   * option: stretch text
  80   */
  81  define("BCS_STRETCH_TEXT", 256);
  82  
  83  /**
  84   * option: reverse color
  85   */
  86  define("BCS_REVERSE_COLOR", 512);
  87  
  88  /**
  89   * option: draw check
  90   * (only for I25 code)
  91   */
  92  define("BCS_I25_DRAW_CHECK", 2048);
  93  
  94  /**
  95   * set default background color
  96   */
  97  define("BCD_DEFAULT_BACKGROUND_COLOR", 0xFFFFFF);
  98  
  99  /**
 100   * set default foreground color
 101   */
 102  define("BCD_DEFAULT_FOREGROUND_COLOR", 0x000000);
 103  
 104  /**
 105   * set default style options
 106   */
 107  define("BCD_DEFAULT_STYLE", BCS_BORDER | BCS_ALIGN_CENTER | BCS_IMAGE_PNG);
 108  
 109  /**
 110   * set default width
 111   */
 112  define("BCD_DEFAULT_WIDTH", 460);
 113  
 114  /**
 115   * set default height
 116   */
 117  define("BCD_DEFAULT_HEIGHT", 120);
 118  
 119  /**
 120   * set default font
 121   */
 122  define("BCD_DEFAULT_FONT", 5);
 123  
 124  /**
 125   * st default horizontal resolution
 126   */
 127  define("BCD_DEFAULT_XRES", 2);
 128  
 129  // Margins
 130  
 131  /**
 132   * set default margin
 133   */
 134  define("BCD_DEFAULT_MAR_Y1", 0);
 135  
 136  /**
 137   * set default margin
 138   */
 139  define("BCD_DEFAULT_MAR_Y2", 0);
 140  
 141  /**
 142   * set default text offset
 143   */
 144  define("BCD_DEFAULT_TEXT_OFFSET", 2);
 145  
 146  // For the I25 Only
 147  
 148  /**
 149   * narrow bar option
 150   * (only for I25 code)
 151   */
 152  define("BCD_I25_NARROW_BAR", 1);
 153  
 154  /**
 155   * wide bar option
 156   * (only for I25 code)
 157   */
 158  define("BCD_I25_WIDE_BAR", 2);
 159  
 160  // For the C39 Only
 161  
 162  /**
 163   * narrow bar option
 164   * (only for c39 code)
 165   */
 166  define("BCD_C39_NARROW_BAR", 1);
 167  
 168  /**
 169   * wide bar option
 170   * (only for c39 code)
 171   */
 172  define("BCD_C39_WIDE_BAR", 2);
 173  
 174  // For Code 128
 175  
 176  /**
 177   * set type 1 bar
 178   * (only for c128 code)
 179   */
 180  define("BCD_C128_BAR_1", 1);
 181  
 182  /**
 183   * set type 2 bar
 184   * (only for c128 code)
 185   */
 186  define("BCD_C128_BAR_2", 2);
 187  
 188  /**
 189   * set type 3 bar
 190   * (only for c128 code)
 191   */
 192  define("BCD_C128_BAR_3", 3);
 193  
 194  /**
 195   * set type 4 bar
 196   * (only for c128 code)
 197   */
 198  define("BCD_C128_BAR_4", 4);
 199  
 200  /**
 201   * Barcode Render Class for PHP using the GD graphics library.
 202   * @author Karim Mribti, Nicola Asuni
 203   * @name BarcodeObject
 204   * @package com.tecnick.tcpdf
 205   * @version 0.0.8a 2001-04-01 (original code)
 206   * @since 2001-03-25
 207   * @license http://www.gnu.org/copyleft/lesser.html LGPL
 208   */
 209  class BarcodeObject {
 210      /**
 211       * @var Image width in pixels.
 212       * @access protected
 213       */
 214      protected $mWidth;
 215      
 216      /**
 217       * @var Image height in pixels.
 218       * @access protected
 219       */
 220      protected $mHeight;
 221      
 222      /**
 223       * @var Numeric code for Barcode style.
 224       * @access protected
 225       */
 226      protected $mStyle;
 227      
 228      /**
 229       * @var Background color.
 230       * @access protected
 231       */
 232      protected $mBgcolor;
 233      
 234      /**
 235       * @var Brush color.
 236       * @access protected
 237       */
 238      protected $mBrush;
 239      
 240      /**
 241       * @var Image object.
 242       * @access protected
 243       */
 244      protected $mImg;
 245      
 246      /**
 247       * @var Numeric code for character font.
 248       * @access protected
 249       */
 250      protected $mFont;
 251      
 252      /**
 253       * @var Error message.
 254       * @access protected
 255       */
 256      protected $mError;
 257      
 258      /**
 259       * @var Character Set.
 260       * @access protected
 261       */
 262      protected $mCharSet;
 263      
 264      /**
 265       * @var Allowed symbols.
 266       * @access protected
 267       */
 268      protected $mChars;
 269  
 270      /**
 271       * Class Constructor.
 272       * @param int $Width Image width in pixels.
 273       * @param int $Height Image height in pixels. 
 274       * @param int $Style Barcode style.
 275       */
 276  	public function __construct($Width=BCD_DEFAULT_WIDTH, $Height=BCD_DEFAULT_HEIGHT, $Style=BCD_DEFAULT_STYLE) {
 277          $this->mWidth = $Width;
 278          $this->mHeight = $Height;
 279          $this->mStyle = $Style;
 280          $this->mFont = BCD_DEFAULT_FONT;
 281          $this->mImg = ImageCreate($this->mWidth, $this->mHeight);
 282          $dbColor = $this->mStyle & BCS_REVERSE_COLOR ? BCD_DEFAULT_FOREGROUND_COLOR : BCD_DEFAULT_BACKGROUND_COLOR;
 283          $dfColor = $this->mStyle & BCS_REVERSE_COLOR ? BCD_DEFAULT_BACKGROUND_COLOR : BCD_DEFAULT_FOREGROUND_COLOR;
 284          $this->mBgcolor = ImageColorAllocate($this->mImg, ($dbColor & 0xFF0000) >> 16,
 285          ($dbColor & 0x00FF00) >> 8, $dbColor & 0x0000FF);
 286          $this->mBrush = ImageColorAllocate($this->mImg, ($dfColor & 0xFF0000) >> 16,
 287          ($dfColor & 0x00FF00) >> 8, $dfColor & 0x0000FF);
 288          if (!($this->mStyle & BCS_TRANSPARENT)) {
 289              ImageFill($this->mImg, $this->mWidth, $this->mHeight, $this->mBgcolor);
 290          }
 291      }
 292      
 293      /**
 294       * Class Destructor.
 295       * Destroy image object.
 296       */
 297  	public function __destructor() {
 298          $this->DestroyObject();
 299      }
 300  
 301      /**
 302       * Returns the image object.
 303       * @return object image.
 304       * @author Nicola Asuni
 305       * @since 1.5.2
 306       */
 307  	public function getImage() {
 308          return $this->mImg;
 309      }
 310      
 311      /**
 312       * Abstract method used to draw the barcode image.
 313       * @param int $xres Horizontal resolution.
 314       */
 315  	public function DrawObject($xres)    {
 316          /* there is not implementation neded, is simply the asbsract function. */
 317          return false;
 318      }
 319      
 320      /**
 321       * Draws the barcode border.
 322       * @access protected
 323       */
 324  	protected function DrawBorder() {
 325          ImageRectangle($this->mImg, 0, 0, $this->mWidth-1, $this->mHeight-1, $this->mBrush);
 326      }
 327      
 328      /**
 329       * Draws the alphanumeric code.
 330       * @param int $Font Font type.
 331       * @param int $xPos Horiziontal position.
 332       * @param int $yPos Vertical position.
 333       * @param int $Char Alphanumeric code to write.
 334       * @access protected
 335       */
 336  	protected function DrawChar($Font, $xPos, $yPos, $Char) {
 337          ImageString($this->mImg,$Font,$xPos,$yPos,$Char,$this->mBrush);
 338      }
 339      
 340      /**
 341       * Draws a character string.
 342       * @param int $Font Font type.
 343       * @param int $xPos Horiziontal position.
 344       * @param int $yPos Vertical position.
 345       * @param int $Char string to write.
 346       * @access protected
 347       */
 348  	protected function DrawText($Font, $xPos, $yPos, $Char) {
 349          ImageString($this->mImg,$Font,$xPos,$yPos,$Char,$this->mBrush);
 350      }
 351  
 352      /**
 353       * Draws a single barcode bar.
 354       * @param int $xPos Horiziontal position.
 355       * @param int $yPos Vertical position.
 356       * @param int $xSize Horizontal size.
 357       * @param int $xSize Vertical size.
 358       * @return bool trur in case of success, false otherwise.
 359       * @access protected
 360       */
 361  	protected function DrawSingleBar($xPos, $yPos, $xSize, $ySize) {
 362          if ($xPos>=0 && $xPos<=$this->mWidth && ($xPos+$xSize)<=$this->mWidth &&
 363          $yPos>=0 && $yPos<=$this->mHeight && ($yPos+$ySize)<=$this->mHeight) {
 364              for ($i=0;$i<$xSize;$i++) {
 365                  ImageLine($this->mImg, $xPos+$i, $yPos, $xPos+$i, $yPos+$ySize, $this->mBrush);
 366              }
 367              return true;
 368          }
 369          return false;
 370      }
 371      
 372      /**
 373       * Returns the current error message.
 374       * @return string error message.
 375       */
 376  	public function GetError() {
 377          return $this->mError;
 378      }
 379      
 380      /**
 381       * Returns the font height.
 382       * @param int $font font type.
 383       * @return int font height.
 384       */
 385  	public function GetFontHeight($font) {
 386          return ImageFontHeight($font);
 387      }
 388      
 389      /**
 390       * Returns the font width.
 391       * @param int $font font type.
 392       * @return int font width.
 393       */
 394  	public function GetFontWidth($font) {
 395          return ImageFontWidth($font);
 396      }
 397      
 398      /**
 399       * Set font type.
 400       * @param int $font font type.
 401       */
 402  	public function SetFont($font) {
 403          $this->mFont = $font;
 404      }
 405      
 406      /**
 407       * Returns barcode style.
 408       * @return int barcode style.
 409       */
 410  	public function GetStyle() {
 411          return $this->mStyle;
 412      }
 413  
 414      /**
 415       * Set barcode style.
 416       * @param int $Style barcode style.
 417       */
 418  	public function SetStyle ($Style) {
 419          $this->mStyle = $Style;
 420      }
 421  
 422      /**
 423       * Flush the barcode image.
 424       */
 425  	public function FlushObject() {
 426          if (($this->mStyle & BCS_BORDER)) {
 427              $this->DrawBorder();
 428          }
 429          if ($this->mStyle & BCS_IMAGE_PNG) {
 430              Header("Content-Type: image/png");
 431              ImagePng($this->mImg);
 432          } else if ($this->mStyle & BCS_IMAGE_JPEG) {
 433              Header("Content-Type: image/jpeg");
 434              ImageJpeg($this->mImg);
 435          }
 436      }
 437      
 438      /**
 439       * Destroy the barcode image.
 440       */
 441  	public function DestroyObject() {
 442          ImageDestroy($this->mImg);
 443      }
 444  }
 445  
 446  //============================================================+
 447  // END OF FILE
 448  //============================================================+
 449  ?>


Generated: Fri Nov 28 20:08:37 2014 Cross-referenced by PHPXref 0.7.1