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  * RGB 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_Rgb extends Zend_Pdf_Color
0039 {
0040     /**
0041      * Red level.
0042      * 0.0 (zero concentration) - 1.0 (maximum concentration)
0043      *
0044      * @var Zend_Pdf_Element_Numeric
0045      */
0046     private $_r;
0047 
0048     /**
0049      * Green level.
0050      * 0.0 (zero concentration) - 1.0 (maximum concentration)
0051      *
0052      * @var Zend_Pdf_Element_Numeric
0053      */
0054     private $_g;
0055 
0056     /**
0057      * Blue level.
0058      * 0.0 (zero concentration) - 1.0 (maximum concentration)
0059      *
0060      * @var Zend_Pdf_Element_Numeric
0061      */
0062     private $_b;
0063 
0064 
0065     /**
0066      * Object constructor
0067      *
0068      * @param float $r
0069      * @param float $g
0070      * @param float $b
0071      */
0072     public function __construct($r, $g, $b)
0073     {
0074         /** Clamp values to legal limits. */
0075         if ($r < 0) { $r = 0; }
0076         if ($r > 1) { $r = 1; }
0077 
0078         if ($g < 0) { $g = 0; }
0079         if ($g > 1) { $g = 1; }
0080 
0081         if ($b < 0) { $b = 0; }
0082         if ($b > 1) { $b = 1; }
0083 
0084         $this->_r = new Zend_Pdf_Element_Numeric($r);
0085         $this->_g = new Zend_Pdf_Element_Numeric($g);
0086         $this->_b = new Zend_Pdf_Element_Numeric($b);
0087     }
0088 
0089     /**
0090      * Instructions, which can be directly inserted into content stream
0091      * to switch color.
0092      * Color set instructions differ for stroking and nonstroking operations.
0093      *
0094      * @param boolean $stroking
0095      * @return string
0096      */
0097     public function instructions($stroking)
0098     {
0099         return $this->_r->toString() . ' '
0100              . $this->_g->toString() . ' '
0101              . $this->_b->toString() .     ($stroking? " RG\n" : " rg\n");
0102     }
0103 
0104     /**
0105      * Get color components (color space dependent)
0106      *
0107      * @return array
0108      */
0109     public function getComponents()
0110     {
0111         return array($this->_r->value, $this->_g->value, $this->_b->value);
0112     }
0113 }
0114