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.

315 lines
9.0 KiB

11 years ago
10 years ago
11 years ago
11 years ago
11 years ago
10 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. * @subpackage Actions
  18. * @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com)
  19. * @license http://framework.zend.com/license/new-bsd New BSD License
  20. * @version $Id$
  21. */
  22. /** Internally used classes */
  23. // require_once 'Zend/Pdf/Element/Array.php';
  24. // require_once 'Zend/Pdf/Element/Dictionary.php';
  25. // require_once 'Zend/Pdf/Element/Numeric.php';
  26. // require_once 'Zend/Pdf/Element/String.php';
  27. /** Zend_Pdf_Outline */
  28. // require_once 'Zend/Pdf/Outline.php';
  29. /**
  30. * PDF outline representation class
  31. *
  32. * @todo Implement an ability to associate an outline item with a structure element (PDF 1.3 feature)
  33. *
  34. * @package Zend_Pdf
  35. * @subpackage Outlines
  36. * @copyright Copyright (c) 2005-2015 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_Outline_Created extends Zend_Pdf_Outline
  40. {
  41. /**
  42. * Outline title.
  43. *
  44. * @var string
  45. */
  46. protected $_title;
  47. /**
  48. * Color to be used for the outline entry’s text.
  49. * It uses the DeviceRGB color space for color representation.
  50. * Null means default value - black ([0.0 0.0 0.0] in RGB representation).
  51. *
  52. * @var Zend_Pdf_Color_Rgb
  53. */
  54. protected $_color = null;
  55. /**
  56. * True if outline item is displayed in italic.
  57. * Default value is false.
  58. *
  59. * @var boolean
  60. */
  61. protected $_italic = false;
  62. /**
  63. * True if outline item is displayed in bold.
  64. * Default value is false.
  65. *
  66. * @var boolean
  67. */
  68. protected $_bold = false;
  69. /**
  70. * Target destination or action.
  71. * String means named destination
  72. *
  73. * Null means no target.
  74. *
  75. * @var Zend_Pdf_Destination|Zend_Pdf_Action
  76. */
  77. protected $_target = null;
  78. /**
  79. * Get outline title.
  80. *
  81. * @return string
  82. */
  83. public function getTitle()
  84. {
  85. return $this->_title;
  86. }
  87. /**
  88. * Set outline title
  89. *
  90. * @param string $title
  91. * @return Zend_Pdf_Outline
  92. */
  93. public function setTitle($title)
  94. {
  95. $this->_title = $title;
  96. return $this;
  97. }
  98. /**
  99. * Returns true if outline item is displayed in italic
  100. *
  101. * @return boolean
  102. */
  103. public function isItalic()
  104. {
  105. return $this->_italic;
  106. }
  107. /**
  108. * Sets 'isItalic' outline flag
  109. *
  110. * @param boolean $isItalic
  111. * @return Zend_Pdf_Outline
  112. */
  113. public function setIsItalic($isItalic)
  114. {
  115. $this->_italic = $isItalic;
  116. return $this;
  117. }
  118. /**
  119. * Returns true if outline item is displayed in bold
  120. *
  121. * @return boolean
  122. */
  123. public function isBold()
  124. {
  125. return $this->_bold;
  126. }
  127. /**
  128. * Sets 'isBold' outline flag
  129. *
  130. * @param boolean $isBold
  131. * @return Zend_Pdf_Outline
  132. */
  133. public function setIsBold($isBold)
  134. {
  135. $this->_bold = $isBold;
  136. return $this;
  137. }
  138. /**
  139. * Get outline text color.
  140. *
  141. * @return Zend_Pdf_Color_Rgb
  142. */
  143. public function getColor()
  144. {
  145. return $this->_color;
  146. }
  147. /**
  148. * Set outline text color.
  149. * (null means default color which is black)
  150. *
  151. * @param Zend_Pdf_Color_Rgb $color
  152. * @return Zend_Pdf_Outline
  153. */
  154. public function setColor(Zend_Pdf_Color_Rgb $color)
  155. {
  156. $this->_color = $color;
  157. return $this;
  158. }
  159. /**
  160. * Get outline target.
  161. *
  162. * @return Zend_Pdf_Target
  163. */
  164. public function getTarget()
  165. {
  166. return $this->_target;
  167. }
  168. /**
  169. * Set outline target.
  170. * Null means no target
  171. *
  172. * @param Zend_Pdf_Target|string $target
  173. * @return Zend_Pdf_Outline
  174. * @throws Zend_Pdf_Exception
  175. */
  176. public function setTarget($target = null)
  177. {
  178. if (is_string($target)) {
  179. // require_once 'Zend/Pdf/Destination/Named.php';
  180. $target = new Zend_Pdf_Destination_Named($target);
  181. }
  182. if ($target === null || $target instanceof Zend_Pdf_Target) {
  183. $this->_target = $target;
  184. } else {
  185. // require_once 'Zend/Pdf/Exception.php';
  186. throw new Zend_Pdf_Exception('Outline target has to be Zend_Pdf_Destination or Zend_Pdf_Action object or string');
  187. }
  188. return $this;
  189. }
  190. /**
  191. * Object constructor
  192. *
  193. * @param array $options
  194. * @throws Zend_Pdf_Exception
  195. */
  196. public function __construct($options = array())
  197. {
  198. if (!isset($options['title'])) {
  199. // require_once 'Zend/Pdf/Exception.php';
  200. throw new Zend_Pdf_Exception('Title parameter is required.');
  201. }
  202. $this->setOptions($options);
  203. }
  204. /**
  205. * Dump Outline and its child outlines into PDF structures
  206. *
  207. * Returns dictionary indirect object or reference
  208. *
  209. * @internal
  210. * @param Zend_Pdf_ElementFactory $factory object factory for newly created indirect objects
  211. * @param boolean $updateNavigation Update navigation flag
  212. * @param Zend_Pdf_Element $parent Parent outline dictionary reference
  213. * @param Zend_Pdf_Element $prev Previous outline dictionary reference
  214. * @param SplObjectStorage $processedOutlines List of already processed outlines
  215. * @return Zend_Pdf_Element
  216. * @throws Zend_Pdf_Exception
  217. */
  218. public function dumpOutline(Zend_Pdf_ElementFactory_Interface $factory,
  219. $updateNavigation,
  220. Zend_Pdf_Element $parent,
  221. Zend_Pdf_Element $prev = null,
  222. SplObjectStorage $processedOutlines = null)
  223. {
  224. if ($processedOutlines === null) {
  225. $processedOutlines = new SplObjectStorage();
  226. }
  227. $processedOutlines->attach($this);
  228. $outlineDictionary = $factory->newObject(new Zend_Pdf_Element_Dictionary());
  229. $outlineDictionary->Title = new Zend_Pdf_Element_String($this->getTitle());
  230. $target = $this->getTarget();
  231. if ($target === null) {
  232. // Do nothing
  233. } else if ($target instanceof Zend_Pdf_Destination) {
  234. $outlineDictionary->Dest = $target->getResource();
  235. } else if ($target instanceof Zend_Pdf_Action) {
  236. $outlineDictionary->A = $target->getResource();
  237. } else {
  238. // require_once 'Zend/Pdf/Exception.php';
  239. throw new Zend_Pdf_Exception('Outline target has to be Zend_Pdf_Destination, Zend_Pdf_Action object or null');
  240. }
  241. $color = $this->getColor();
  242. if ($color !== null) {
  243. $components = $color->getComponents();
  244. $colorComponentElements = array(new Zend_Pdf_Element_Numeric($components[0]),
  245. new Zend_Pdf_Element_Numeric($components[1]),
  246. new Zend_Pdf_Element_Numeric($components[2]));
  247. $outlineDictionary->C = new Zend_Pdf_Element_Array($colorComponentElements);
  248. }
  249. if ($this->isItalic() || $this->isBold()) {
  250. $outlineDictionary->F = new Zend_Pdf_Element_Numeric(($this->isItalic()? 1 : 0) | // Bit 1 - Italic
  251. ($this->isBold()? 2 : 0)); // Bit 2 - Bold
  252. }
  253. $outlineDictionary->Parent = $parent;
  254. $outlineDictionary->Prev = $prev;
  255. $lastChild = null;
  256. foreach ($this->childOutlines as $childOutline) {
  257. if ($processedOutlines->contains($childOutline)) {
  258. // require_once 'Zend/Pdf/Exception.php';
  259. throw new Zend_Pdf_Exception('Outlines cyclyc reference is detected.');
  260. }
  261. if ($lastChild === null) {
  262. $lastChild = $childOutline->dumpOutline($factory, true, $outlineDictionary, null, $processedOutlines);
  263. $outlineDictionary->First = $lastChild;
  264. } else {
  265. $childOutlineDictionary = $childOutline->dumpOutline($factory, true, $outlineDictionary, $lastChild, $processedOutlines);
  266. $lastChild->Next = $childOutlineDictionary;
  267. $lastChild = $childOutlineDictionary;
  268. }
  269. }
  270. $outlineDictionary->Last = $lastChild;
  271. if (count($this->childOutlines) != 0) {
  272. $outlineDictionary->Count = new Zend_Pdf_Element_Numeric(($this->isOpen()? 1 : -1)*count($this->childOutlines));
  273. }
  274. return $outlineDictionary;
  275. }
  276. }