Created.php 7.9 KB

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