File indexing completed on 2025-01-19 05:21:21

0001 <?php
0002 /**
0003  * Zend Framework
0004  *
0005  * LICENSE
0006  *
0007  * This source file is subject to the new BSD license that is bundled
0008  * with this package in the file LICENSE.txt.
0009  * It is also available through the world-wide-web at this URL:
0010  * http://framework.zend.com/license/new-bsd
0011  * If you did not receive a copy of the license and are unable to
0012  * obtain it through the world-wide-web, please send an email
0013  * to license@zend.com so we can send you a copy immediately.
0014  *
0015  * @category   Zend
0016  * @package    Zend_Pdf
0017  * @copyright  Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com)
0018  * @license    http://framework.zend.com/license/new-bsd     New BSD License
0019  * @version    $Id$
0020  */
0021 
0022 
0023 /** Zend_Pdf_Element */
0024 // require_once 'Zend/Pdf/Element.php';
0025 
0026 
0027 /**
0028  * PDF file 'numeric' element implementation
0029  *
0030  * @category   Zend
0031  * @package    Zend_Pdf
0032  * @copyright  Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com)
0033  * @license    http://framework.zend.com/license/new-bsd     New BSD License
0034  */
0035 class Zend_Pdf_Element_Numeric extends Zend_Pdf_Element
0036 {
0037     /**
0038      * Object value
0039      *
0040      * @var numeric
0041      */
0042     public $value;
0043 
0044 
0045     /**
0046      * Object constructor
0047      *
0048      * @param numeric $val
0049      * @throws Zend_Pdf_Exception
0050      */
0051     public function __construct($val)
0052     {
0053         if ( !is_numeric($val) ) {
0054             // require_once 'Zend/Pdf/Exception.php';
0055             throw new Zend_Pdf_Exception('Argument must be numeric');
0056         }
0057 
0058         $this->value = $val;
0059     }
0060 
0061 
0062     /**
0063      * Return type of the element.
0064      *
0065      * @return integer
0066      */
0067     public function getType()
0068     {
0069         return Zend_Pdf_Element::TYPE_NUMERIC;
0070     }
0071 
0072 
0073     /**
0074      * Return object as string
0075      *
0076      * @param Zend_Pdf_Factory $factory
0077      * @return string
0078      */
0079     public function toString($factory = null)
0080     {
0081         if (is_integer($this->value)) {
0082             return (string)$this->value;
0083         }
0084 
0085         /**
0086          * PDF doesn't support exponental format.
0087          * Fixed point format must be used instead
0088          */
0089         $prec = 0; $v = $this->value;
0090         while (abs( floor($v) - $v ) > 1e-10) {
0091             $prec++; $v *= 10;
0092         }
0093         return sprintf("%.{$prec}F", $this->value);
0094     }
0095 }