File indexing completed on 2024-12-22 05:36:54

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 /** Internally used classes */
0024 // require_once 'Zend/Pdf/Element/Numeric.php';
0025 
0026 
0027 /** Zend_Pdf_Color */
0028 // require_once 'Zend/Pdf/Color.php';
0029 
0030 /**
0031  * GrayScale color implementation
0032  *
0033  * @category   Zend
0034  * @package    Zend_Pdf
0035  * @copyright  Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com)
0036  * @license    http://framework.zend.com/license/new-bsd     New BSD License
0037  */
0038 class Zend_Pdf_Color_GrayScale extends Zend_Pdf_Color
0039 {
0040     /**
0041      * GrayLevel.
0042      * 0.0 (black) - 1.0 (white)
0043      *
0044      * @var Zend_Pdf_Element_Numeric
0045      */
0046     private $_grayLevel;
0047 
0048     /**
0049      * Object constructor
0050      *
0051      * @param float $grayLevel
0052      */
0053     public function __construct($grayLevel)
0054     {
0055         if ($grayLevel < 0) { $grayLevel = 0; }
0056         if ($grayLevel > 1) { $grayLevel = 1; }
0057 
0058         $this->_grayLevel = new Zend_Pdf_Element_Numeric($grayLevel);
0059     }
0060 
0061     /**
0062      * Instructions, which can be directly inserted into content stream
0063      * to switch color.
0064      * Color set instructions differ for stroking and nonstroking operations.
0065      *
0066      * @param boolean $stroking
0067      * @return string
0068      */
0069     public function instructions($stroking)
0070     {
0071         return $this->_grayLevel->toString() . ($stroking? " G\n" : " g\n");
0072     }
0073 
0074     /**
0075      * Get color components (color space dependent)
0076      *
0077      * @return array
0078      */
0079     public function getComponents()
0080     {
0081         return array($this->_grayLevel->value);
0082     }
0083 }
0084