web/lib/Zend/Barcode/Renderer/RendererAbstract.php
changeset 1230 68c69c656a2c
parent 807 877f952ae2bd
equal deleted inserted replaced
1229:5a6b6e770365 1230:68c69c656a2c
    13  * to license@zend.com so we can send you a copy immediately.
    13  * to license@zend.com so we can send you a copy immediately.
    14  *
    14  *
    15  * @category   Zend
    15  * @category   Zend
    16  * @package    Zend_Barcode
    16  * @package    Zend_Barcode
    17  * @subpackage Renderer
    17  * @subpackage Renderer
    18  * @copyright  Copyright (c) 2005-2012 Zend Technologies USA Inc. (http://www.zend.com)
    18  * @copyright  Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com)
    19  * @license    http://framework.zend.com/license/new-bsd     New BSD License
    19  * @license    http://framework.zend.com/license/new-bsd     New BSD License
    20  * @version    $Id: RendererAbstract.php 24593 2012-01-05 20:35:02Z matthew $
    20  * @version    $Id$
    21  */
    21  */
    22 
    22 
    23 /**
    23 /**
    24  * Class for rendering the barcode
    24  * Class for rendering the barcode
    25  *
    25  *
    26  * @category   Zend
    26  * @category   Zend
    27  * @package    Zend_Barcode
    27  * @package    Zend_Barcode
    28  * @copyright  Copyright (c) 2005-2012 Zend Technologies USA Inc. (http://www.zend.com)
    28  * @copyright  Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com)
    29  * @license    http://framework.zend.com/license/new-bsd     New BSD License
    29  * @license    http://framework.zend.com/license/new-bsd     New BSD License
    30  */
    30  */
    31 abstract class Zend_Barcode_Renderer_RendererAbstract
    31 abstract class Zend_Barcode_Renderer_RendererAbstract
    32 {
    32 {
    33     /**
    33     /**
    89      */
    89      */
    90     protected $_resource;
    90     protected $_resource;
    91 
    91 
    92     /**
    92     /**
    93      * Constructor
    93      * Constructor
       
    94      *
    94      * @param array|Zend_Config $options
    95      * @param array|Zend_Config $options
    95      * @return void
    96      * @return Zend_Barcode_Renderer_RendererAbstract
    96      */
    97      */
    97     public function __construct($options = null)
    98     public function __construct($options = null)
    98     {
    99     {
    99         if ($options instanceof Zend_Config) {
   100         if ($options instanceof Zend_Config) {
   100             $options = $options->toArray();
   101             $options = $options->toArray();
   167 
   168 
   168     /**
   169     /**
   169      * Manually adjust top position
   170      * Manually adjust top position
   170      * @param integer $value
   171      * @param integer $value
   171      * @return Zend_Barcode_Renderer
   172      * @return Zend_Barcode_Renderer
   172      * @throw Zend_Barcode_Renderer_Exception
   173      * @throws Zend_Barcode_Renderer_Exception
   173      */
   174      */
   174     public function setTopOffset($value)
   175     public function setTopOffset($value)
   175     {
   176     {
   176         if (!is_numeric($value) || intval($value) < 0) {
   177         if (!is_numeric($value) || intval($value) < 0) {
   177             require_once 'Zend/Barcode/Renderer/Exception.php';
   178             require_once 'Zend/Barcode/Renderer/Exception.php';
   194 
   195 
   195     /**
   196     /**
   196      * Manually adjust left position
   197      * Manually adjust left position
   197      * @param integer $value
   198      * @param integer $value
   198      * @return Zend_Barcode_Renderer
   199      * @return Zend_Barcode_Renderer
   199      * @throw Zend_Barcode_Renderer_Exception
   200      * @throws Zend_Barcode_Renderer_Exception
   200      */
   201      */
   201     public function setLeftOffset($value)
   202     public function setLeftOffset($value)
   202     {
   203     {
   203         if (!is_numeric($value) || intval($value) < 0) {
   204         if (!is_numeric($value) || intval($value) < 0) {
   204             require_once 'Zend/Barcode/Renderer/Exception.php';
   205             require_once 'Zend/Barcode/Renderer/Exception.php';
   219         return $this->_leftOffset;
   220         return $this->_leftOffset;
   220     }
   221     }
   221 
   222 
   222     /**
   223     /**
   223      * Activate/Deactivate the automatic rendering of exception
   224      * Activate/Deactivate the automatic rendering of exception
       
   225      *
   224      * @param boolean $value
   226      * @param boolean $value
       
   227      * @return $this
   225      */
   228      */
   226     public function setAutomaticRenderError($value)
   229     public function setAutomaticRenderError($value)
   227     {
   230     {
   228         $this->_automaticRenderError = (bool) $value;
   231         $this->_automaticRenderError = (bool) $value;
   229         return $this;
   232         return $this;
   230     }
   233     }
   231 
   234 
   232     /**
   235     /**
   233      * Horizontal position of the barcode in the rendering resource
   236      * Horizontal position of the barcode in the rendering resource
       
   237      *
   234      * @param string $value
   238      * @param string $value
   235      * @return Zend_Barcode_Renderer
   239      * @return Zend_Barcode_Renderer
   236      * @throw Zend_Barcode_Renderer_Exception
   240      * @throws Zend_Barcode_Renderer_Exception
   237      */
   241      */
   238     public function setHorizontalPosition($value)
   242     public function setHorizontalPosition($value)
   239     {
   243     {
   240         if (!in_array($value, array('left' , 'center' , 'right'))) {
   244         if (!in_array($value, array('left' , 'center' , 'right'))) {
   241             require_once 'Zend/Barcode/Renderer/Exception.php';
   245             require_once 'Zend/Barcode/Renderer/Exception.php';
   256         return $this->_horizontalPosition;
   260         return $this->_horizontalPosition;
   257     }
   261     }
   258 
   262 
   259     /**
   263     /**
   260      * Vertical position of the barcode in the rendering resource
   264      * Vertical position of the barcode in the rendering resource
       
   265      *
   261      * @param string $value
   266      * @param string $value
   262      * @return Zend_Barcode_Renderer
   267      * @return self
   263      * @throw Zend_Barcode_Renderer_Exception
   268      * @throws Zend_Barcode_Renderer_Exception
   264      */
   269      */
   265     public function setVerticalPosition($value)
   270     public function setVerticalPosition($value)
   266     {
   271     {
   267         if (!in_array($value, array('top' , 'middle' , 'bottom'))) {
   272         if (!in_array($value, array('top' , 'middle' , 'bottom'))) {
   268             require_once 'Zend/Barcode/Renderer/Exception.php';
   273             require_once 'Zend/Barcode/Renderer/Exception.php';
   285 
   290 
   286     /**
   291     /**
   287      * Set the size of a module
   292      * Set the size of a module
   288      * @param float $value
   293      * @param float $value
   289      * @return Zend_Barcode_Renderer
   294      * @return Zend_Barcode_Renderer
   290      * @throw Zend_Barcode_Renderer_Exception
   295      * @throws Zend_Barcode_Renderer_Exception
   291      */
   296      */
   292     public function setModuleSize($value)
   297     public function setModuleSize($value)
   293     {
   298     {
   294         if (!is_numeric($value) || floatval($value) <= 0) {
   299         if (!is_numeric($value) || floatval($value) <= 0) {
   295             require_once 'Zend/Barcode/Renderer/Exception.php';
   300             require_once 'Zend/Barcode/Renderer/Exception.php';
   320         return $this->_automaticRenderError;
   325         return $this->_automaticRenderError;
   321     }
   326     }
   322 
   327 
   323     /**
   328     /**
   324      * Set the barcode object
   329      * Set the barcode object
       
   330      *
   325      * @param Zend_Barcode_Object $barcode
   331      * @param Zend_Barcode_Object $barcode
   326      * @return Zend_Barcode_Renderer
   332      * @return Zend_Barcode_Renderer
       
   333      * @throws Zend_Barcode_Renderer_Exception
   327      */
   334      */
   328     public function setBarcode($barcode)
   335     public function setBarcode($barcode)
   329     {
   336     {
   330         if (!$barcode instanceof Zend_Barcode_Object_ObjectAbstract) {
   337         if (!$barcode instanceof Zend_Barcode_Object_ObjectAbstract) {
   331             require_once 'Zend/Barcode/Renderer/Exception.php';
   338             require_once 'Zend/Barcode/Renderer/Exception.php';
   358     }
   365     }
   359 
   366 
   360     /**
   367     /**
   361      * Check if a barcode object is correctly provided
   368      * Check if a barcode object is correctly provided
   362      * @return void
   369      * @return void
   363      * @throw Zend_Barcode_Renderer_Exception
   370      * @throws Zend_Barcode_Renderer_Exception
   364      */
   371      */
   365     protected function _checkBarcodeObject()
   372     protected function _checkBarcodeObject()
   366     {
   373     {
   367         if ($this->_barcode === null) {
   374         if ($this->_barcode === null) {
   368             /**
   375             /**
   419         }
   426         }
   420     }
   427     }
   421 
   428 
   422     /**
   429     /**
   423      * Draw the barcode in the rendering resource
   430      * Draw the barcode in the rendering resource
       
   431      *
   424      * @return mixed
   432      * @return mixed
       
   433      * @throws Zend_Exception
       
   434      * @throws Zend_Barcode_Exception
   425      */
   435      */
   426     public function draw()
   436     public function draw()
   427     {
   437     {
   428         try {
   438         try {
   429             $this->checkParams();
   439             $this->checkParams();
   484                     /**
   494                     /**
   485                      * @see Zend_Barcode_Renderer_Exception
   495                      * @see Zend_Barcode_Renderer_Exception
   486                      */
   496                      */
   487                     require_once 'Zend/Barcode/Renderer/Exception.php';
   497                     require_once 'Zend/Barcode/Renderer/Exception.php';
   488                     throw new Zend_Barcode_Renderer_Exception(
   498                     throw new Zend_Barcode_Renderer_Exception(
   489                         'Unkown drawing command'
   499                         'Unknown drawing command'
   490                     );
   500                     );
   491             }
   501             }
   492         }
   502         }
   493     }
   503     }
   494 
   504 
   518      */
   528      */
   519     abstract protected function _drawPolygon($points, $color, $filled = true);
   529     abstract protected function _drawPolygon($points, $color, $filled = true);
   520 
   530 
   521     /**
   531     /**
   522      * Draw a polygon in the rendering resource
   532      * Draw a polygon in the rendering resource
   523      * @param string $text
   533      *
   524      * @param float $size
   534      * @param string    $text
   525      * @param array $position
   535      * @param float     $size
   526      * @param string $font
   536      * @param array     $position
   527      * @param integer $color
   537      * @param string    $font
   528      * @param string $alignment
   538      * @param integer   $color
   529      * @param float $orientation
   539      * @param string    $alignment
       
   540      * @param float|int $orientation
   530      */
   541      */
   531     abstract protected function _drawText(
   542     abstract protected function _drawText(
   532         $text,
   543         $text,
   533         $size,
   544         $size,
   534         $position,
   545         $position,