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.

182 lines
5.0 KiB

11 years ago
9 years ago
11 years ago
9 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-2015 Zend Technologies USA Inc. (http://www.zend.com)
  18. * @license http://framework.zend.com/license/new-bsd New BSD License
  19. * @version $Id: Style.php 20096 2010-01-06 02:05:09Z bkarwin $
  20. */
  21. // require_once 'Zend/Pdf/Canvas/Abstract.php';
  22. /**
  23. * Canvas is an abstract rectangle drawing area which can be dropped into
  24. * page object at specified place.
  25. *
  26. * @package Zend_Pdf
  27. * @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com)
  28. * @license http://framework.zend.com/license/new-bsd New BSD License
  29. */
  30. class Zend_Pdf_Canvas extends Zend_Pdf_Canvas_Abstract
  31. {
  32. /**
  33. * Canvas procedure sets.
  34. *
  35. * Allowed values: 'PDF', 'Text', 'ImageB', 'ImageC', 'ImageI'.
  36. *
  37. * @var array
  38. */
  39. protected $_procSet = array();
  40. /**
  41. * Canvas width expressed in default user space units (1/72 inch)
  42. *
  43. * @var float
  44. */
  45. protected $_width;
  46. /**
  47. * Canvas height expressed in default user space units (1/72 inch)
  48. *
  49. * @var float
  50. */
  51. protected $_height;
  52. protected $_resources = array('Font' => array(),
  53. 'XObject' => array(),
  54. 'ExtGState' => array());
  55. /**
  56. * Object constructor
  57. *
  58. * @param float $width
  59. * @param float $height
  60. */
  61. public function __construct($width, $height)
  62. {
  63. $this->_width = $width;
  64. $this->_height = $height;
  65. }
  66. /**
  67. * Add procedure set to the canvas description
  68. *
  69. * @param string $procSetName
  70. */
  71. protected function _addProcSet($procSetName)
  72. {
  73. $this->_procset[$procSetName] = 1;
  74. }
  75. /**
  76. * Attach resource to the canvas
  77. *
  78. * Method returns a name of the resource which can be used
  79. * as a resource reference within drawing instructions stream
  80. * Allowed types: 'ExtGState', 'ColorSpace', 'Pattern', 'Shading',
  81. * 'XObject', 'Font', 'Properties'
  82. *
  83. * @param string $type
  84. * @param Zend_Pdf_Resource $resource
  85. * @return string
  86. */
  87. protected function _attachResource($type, Zend_Pdf_Resource $resource)
  88. {
  89. // Check, that resource is already attached to resource set.
  90. $resObject = $resource->getResource();
  91. foreach ($this->_resources[$type] as $resName => $collectedResObject) {
  92. if ($collectedResObject === $resObject) {
  93. return $resName;
  94. }
  95. }
  96. $idCounter = 1;
  97. do {
  98. $newResName = $type[0] . $idCounter++;
  99. } while (isset($this->_resources[$type][$newResName]));
  100. $this->_resources[$type][$newResName] = $resObject;
  101. return $newResName;
  102. }
  103. /**
  104. * Returns dictionaries of used resources.
  105. *
  106. * Used for canvas implementations interoperability
  107. *
  108. * Structure of the returned array:
  109. * array(
  110. * <resTypeName> => array(
  111. * <resName> => <Zend_Pdf_Resource object>,
  112. * <resName> => <Zend_Pdf_Resource object>,
  113. * <resName> => <Zend_Pdf_Resource object>,
  114. * ...
  115. * ),
  116. * <resTypeName> => array(
  117. * <resName> => <Zend_Pdf_Resource object>,
  118. * <resName> => <Zend_Pdf_Resource object>,
  119. * <resName> => <Zend_Pdf_Resource object>,
  120. * ...
  121. * ),
  122. * ...
  123. * 'ProcSet' => array()
  124. * )
  125. *
  126. * where ProcSet array is a list of used procedure sets names (strings).
  127. * Allowed procedure set names: 'PDF', 'Text', 'ImageB', 'ImageC', 'ImageI'
  128. *
  129. * @internal
  130. * @return array
  131. */
  132. public function getResources()
  133. {
  134. $this->_resources['ProcSet'] = array_keys($this->_procSet);
  135. return $this->_resources;
  136. }
  137. /**
  138. * Get drawing instructions stream
  139. *
  140. * It has to be returned as a PDF stream object to make it reusable.
  141. *
  142. * @internal
  143. * @returns Zend_Pdf_Resource_ContentStream
  144. */
  145. public function getContents()
  146. {
  147. /** @todo implementation */
  148. }
  149. /**
  150. * Return the height of this page in points.
  151. *
  152. * @return float
  153. */
  154. public function getHeight()
  155. {
  156. return $this->_height;
  157. }
  158. /**
  159. * Return the width of this page in points.
  160. *
  161. * @return float
  162. */
  163. public function getWidth()
  164. {
  165. return $this->_width;
  166. }
  167. }