You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

109 lines
3.8 KiB

11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
  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-2014 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. /** Internally used classes */
  22. // require_once 'Zend/Pdf/Element/Object.php';
  23. // require_once 'Zend/Pdf/Element/Dictionary.php';
  24. // require_once 'Zend/Pdf/Element/Name.php';
  25. // require_once 'Zend/Pdf/Element/Numeric.php';
  26. /** Zend_Pdf_Resource */
  27. // require_once 'Zend/Pdf/Resource.php';
  28. /**
  29. * Graphics State.
  30. *
  31. * While some parameters in the graphics state can be set with individual operators,
  32. * as shown in Table 4.7, others cannot. The latter can only be set with the generic
  33. * graphics state operator gs (PDF 1.2).
  34. *
  35. * @package Zend_Pdf
  36. * @copyright Copyright (c) 2005-2014 Zend Technologies USA Inc. (http://www.zend.com)
  37. * @license http://framework.zend.com/license/new-bsd New BSD License
  38. */
  39. class Zend_Pdf_Resource_GraphicsState extends Zend_Pdf_Resource
  40. {
  41. /**
  42. * Object constructor.
  43. *
  44. * @param Zend_Pdf_Element_Object $extGStateObject
  45. * @throws Zend_Pdf_Exception
  46. */
  47. public function __construct(Zend_Pdf_Element_Object $extGStateObject = null)
  48. {
  49. if ($extGStateObject == null) {
  50. // Create new Graphics State object
  51. // require_once 'Zend/Pdf/ElementFactory.php';
  52. $factory = Zend_Pdf_ElementFactory::createFactory(1);
  53. $gsDictionary = new Zend_Pdf_Element_Dictionary();
  54. $gsDictionary->Type = new Zend_Pdf_Element_Name('ExtGState');
  55. $extGStateObject = $factory->newObject($gsDictionary);
  56. }
  57. if ($extGStateObject->getType() != Zend_Pdf_Element::TYPE_DICTIONARY) {
  58. // require_once 'Zend/Pdf/Exception.php';
  59. throw new Zend_Pdf_Exception('Graphics state PDF object must be a dictionary');
  60. }
  61. parent::__construct($gsDictionary);
  62. }
  63. /**
  64. * Set the transparancy
  65. *
  66. * $alpha == 0 - transparent
  67. * $alpha == 1 - opaque
  68. *
  69. * Transparency modes, supported by PDF:
  70. * Normal (default), Multiply, Screen, Overlay, Darken, Lighten, ColorDodge, ColorBurn, HardLight,
  71. * SoftLight, Difference, Exclusion
  72. *
  73. * @param float $alpha
  74. * @param string $mode
  75. * @throws Zend_Pdf_Exception
  76. * @return Zend_Pdf_Canvas_Interface
  77. */
  78. public function setAlpha($alpha, $mode = 'Normal')
  79. {
  80. if (!in_array($mode, array('Normal', 'Multiply', 'Screen', 'Overlay', 'Darken', 'Lighten', 'ColorDodge',
  81. 'ColorBurn', 'HardLight', 'SoftLight', 'Difference', 'Exclusion'))) {
  82. // require_once 'Zend/Pdf/Exception.php';
  83. throw new Zend_Pdf_Exception('Unsupported transparency mode.');
  84. }
  85. if (!is_numeric($alpha) || $alpha < 0 || $alpha > 1) {
  86. // require_once 'Zend/Pdf/Exception.php';
  87. throw new Zend_Pdf_Exception('Alpha value must be numeric between 0 (transparent) and 1 (opaque).');
  88. }
  89. $this->_resource->BM = new Zend_Pdf_Element_Name($mode);
  90. $this->_resource->CA = new Zend_Pdf_Element_Numeric($alpha);
  91. $this->_resource->ca = new Zend_Pdf_Element_Numeric($alpha);
  92. }
  93. /** @todo add other Graphics State features support */
  94. }