|
1 <?php |
|
2 /** |
|
3 * Zend Framework |
|
4 * |
|
5 * LICENSE |
|
6 * |
|
7 * This source file is subject to the new BSD license that is bundled |
|
8 * with this package in the file LICENSE.txt. |
|
9 * It is also available through the world-wide-web at this URL: |
|
10 * http://framework.zend.com/license/new-bsd |
|
11 * If you did not receive a copy of the license and are unable to |
|
12 * obtain it through the world-wide-web, please send an email |
|
13 * to license@zend.com so we can send you a copy immediately. |
|
14 * |
|
15 * @category Zend |
|
16 * @package Zend_Pdf |
|
17 * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com) |
|
18 * @license http://framework.zend.com/license/new-bsd New BSD License |
|
19 * @version $Id: Image.php 20096 2010-01-06 02:05:09Z bkarwin $ |
|
20 */ |
|
21 |
|
22 |
|
23 /** Internally used classes */ |
|
24 require_once 'Zend/Pdf/Element/Object.php'; |
|
25 require_once 'Zend/Pdf/Element/Dictionary.php'; |
|
26 require_once 'Zend/Pdf/Element/Name.php'; |
|
27 require_once 'Zend/Pdf/Element/Numeric.php'; |
|
28 |
|
29 |
|
30 /** Zend_Pdf_Resource */ |
|
31 require_once 'Zend/Pdf/Resource.php'; |
|
32 |
|
33 |
|
34 /** |
|
35 * Graphics State. |
|
36 * |
|
37 * While some parameters in the graphics state can be set with individual operators, |
|
38 * as shown in Table 4.7, others cannot. The latter can only be set with the generic |
|
39 * graphics state operator gs (PDF 1.2). |
|
40 * |
|
41 * @package Zend_Pdf |
|
42 * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com) |
|
43 * @license http://framework.zend.com/license/new-bsd New BSD License |
|
44 */ |
|
45 class Zend_Pdf_Resource_GraphicsState extends Zend_Pdf_Resource |
|
46 { |
|
47 /** |
|
48 * Object constructor. |
|
49 * |
|
50 * @param Zend_Pdf_Element_Object $extGStateObject |
|
51 * @throws Zend_Pdf_Exception |
|
52 */ |
|
53 public function __construct(Zend_Pdf_Element_Object $extGStateObject = null) |
|
54 { |
|
55 if ($extGStateObject == null) { |
|
56 // Create new Graphics State object |
|
57 require_once 'Zend/Pdf/ElementFactory.php'; |
|
58 $factory = Zend_Pdf_ElementFactory::createFactory(1); |
|
59 |
|
60 $gsDictionary = new Zend_Pdf_Element_Dictionary(); |
|
61 $gsDictionary->Type = new Zend_Pdf_Element_Name('ExtGState'); |
|
62 |
|
63 $extGStateObject = $factory->newObject($gsDictionary); |
|
64 } |
|
65 |
|
66 if ($extGStateObject->getType() != Zend_Pdf_Element::TYPE_DICTIONARY) { |
|
67 require_once 'Zend/Pdf/Exception.php'; |
|
68 throw new Zend_Pdf_Exception('Graphics state PDF object must be a dictionary'); |
|
69 } |
|
70 |
|
71 parent::__construct($gsDictionary); |
|
72 } |
|
73 |
|
74 /** |
|
75 * Set the transparancy |
|
76 * |
|
77 * $alpha == 0 - transparent |
|
78 * $alpha == 1 - opaque |
|
79 * |
|
80 * Transparency modes, supported by PDF: |
|
81 * Normal (default), Multiply, Screen, Overlay, Darken, Lighten, ColorDodge, ColorBurn, HardLight, |
|
82 * SoftLight, Difference, Exclusion |
|
83 * |
|
84 * @param float $alpha |
|
85 * @param string $mode |
|
86 * @throws Zend_Pdf_Exception |
|
87 * @return Zend_Pdf_Canvas_Interface |
|
88 */ |
|
89 public function setAlpha($alpha, $mode = 'Normal') |
|
90 { |
|
91 if (!in_array($mode, array('Normal', 'Multiply', 'Screen', 'Overlay', 'Darken', 'Lighten', 'ColorDodge', |
|
92 'ColorBurn', 'HardLight', 'SoftLight', 'Difference', 'Exclusion'))) { |
|
93 require_once 'Zend/Pdf/Exception.php'; |
|
94 throw new Zend_Pdf_Exception('Unsupported transparency mode.'); |
|
95 } |
|
96 if (!is_numeric($alpha) || $alpha < 0 || $alpha > 1) { |
|
97 require_once 'Zend/Pdf/Exception.php'; |
|
98 throw new Zend_Pdf_Exception('Alpha value must be numeric between 0 (transparent) and 1 (opaque).'); |
|
99 } |
|
100 |
|
101 $this->_resource->BM = new Zend_Pdf_Element_Name($mode); |
|
102 $this->_resource->CA = new Zend_Pdf_Element_Numeric($alpha); |
|
103 $this->_resource->ca = new Zend_Pdf_Element_Numeric($alpha); |
|
104 } |
|
105 |
|
106 |
|
107 /** @todo add other Graphics State features support */ |
|
108 } |
|
109 |