File indexing completed on 2024-12-22 05:36:56
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: Image.php 20096 2010-01-06 02:05:09Z bkarwin $ 0020 */ 0021 0022 0023 /** Internally used classes */ 0024 // require_once 'Zend/Pdf/Element/Object.php'; 0025 // require_once 'Zend/Pdf/Element/Dictionary.php'; 0026 // require_once 'Zend/Pdf/Element/Name.php'; 0027 // require_once 'Zend/Pdf/Element/Numeric.php'; 0028 0029 0030 /** Zend_Pdf_Resource */ 0031 // require_once 'Zend/Pdf/Resource.php'; 0032 0033 0034 /** 0035 * Graphics State. 0036 * 0037 * While some parameters in the graphics state can be set with individual operators, 0038 * as shown in Table 4.7, others cannot. The latter can only be set with the generic 0039 * graphics state operator gs (PDF 1.2). 0040 * 0041 * @package Zend_Pdf 0042 * @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com) 0043 * @license http://framework.zend.com/license/new-bsd New BSD License 0044 */ 0045 class Zend_Pdf_Resource_GraphicsState extends Zend_Pdf_Resource 0046 { 0047 /** 0048 * Object constructor. 0049 * 0050 * @param Zend_Pdf_Element_Object $extGStateObject 0051 * @throws Zend_Pdf_Exception 0052 */ 0053 public function __construct(Zend_Pdf_Element_Object $extGStateObject = null) 0054 { 0055 if ($extGStateObject == null) { 0056 // Create new Graphics State object 0057 // require_once 'Zend/Pdf/ElementFactory.php'; 0058 $factory = Zend_Pdf_ElementFactory::createFactory(1); 0059 0060 $gsDictionary = new Zend_Pdf_Element_Dictionary(); 0061 $gsDictionary->Type = new Zend_Pdf_Element_Name('ExtGState'); 0062 0063 $extGStateObject = $factory->newObject($gsDictionary); 0064 } 0065 0066 if ($extGStateObject->getType() != Zend_Pdf_Element::TYPE_DICTIONARY) { 0067 // require_once 'Zend/Pdf/Exception.php'; 0068 throw new Zend_Pdf_Exception('Graphics state PDF object must be a dictionary'); 0069 } 0070 0071 parent::__construct($gsDictionary); 0072 } 0073 0074 /** 0075 * Set the transparancy 0076 * 0077 * $alpha == 0 - transparent 0078 * $alpha == 1 - opaque 0079 * 0080 * Transparency modes, supported by PDF: 0081 * Normal (default), Multiply, Screen, Overlay, Darken, Lighten, ColorDodge, ColorBurn, HardLight, 0082 * SoftLight, Difference, Exclusion 0083 * 0084 * @param float $alpha 0085 * @param string $mode 0086 * @throws Zend_Pdf_Exception 0087 * @return Zend_Pdf_Canvas_Interface 0088 */ 0089 public function setAlpha($alpha, $mode = 'Normal') 0090 { 0091 if (!in_array($mode, array('Normal', 'Multiply', 'Screen', 'Overlay', 'Darken', 'Lighten', 'ColorDodge', 0092 'ColorBurn', 'HardLight', 'SoftLight', 'Difference', 'Exclusion'))) { 0093 // require_once 'Zend/Pdf/Exception.php'; 0094 throw new Zend_Pdf_Exception('Unsupported transparency mode.'); 0095 } 0096 if (!is_numeric($alpha) || $alpha < 0 || $alpha > 1) { 0097 // require_once 'Zend/Pdf/Exception.php'; 0098 throw new Zend_Pdf_Exception('Alpha value must be numeric between 0 (transparent) and 1 (opaque).'); 0099 } 0100 0101 $this->_resource->BM = new Zend_Pdf_Element_Name($mode); 0102 $this->_resource->CA = new Zend_Pdf_Element_Numeric($alpha); 0103 $this->_resource->ca = new Zend_Pdf_Element_Numeric($alpha); 0104 } 0105 0106 0107 /** @todo add other Graphics State features support */ 0108 } 0109