File indexing completed on 2024-12-22 05:36:55
0001 <?php 0002 /** 0003 * Zend Framework 0004 * 0005 * LICENSE 0006 * 0007 * This source file is subject to the new BSD license that is bundled 0008 * with this package in the file LICENSE.txt. 0009 * It is also available through the world-wide-web at this URL: 0010 * http://framework.zend.com/license/new-bsd 0011 * If you did not receive a copy of the license and are unable to 0012 * obtain it through the world-wide-web, please send an email 0013 * to license@zend.com so we can send you a copy immediately. 0014 * 0015 * @category Zend 0016 * @package Zend_Pdf 0017 * @subpackage Actions 0018 * @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com) 0019 * @license http://framework.zend.com/license/new-bsd New BSD License 0020 * @version $Id$ 0021 */ 0022 0023 0024 /** Internally used classes */ 0025 // require_once 'Zend/Pdf/Element/Array.php'; 0026 // require_once 'Zend/Pdf/Element/Dictionary.php'; 0027 // require_once 'Zend/Pdf/Element/Numeric.php'; 0028 // require_once 'Zend/Pdf/Element/String.php'; 0029 0030 0031 /** Zend_Pdf_Outline */ 0032 // require_once 'Zend/Pdf/Outline.php'; 0033 0034 /** 0035 * PDF outline representation class 0036 * 0037 * @todo Implement an ability to associate an outline item with a structure element (PDF 1.3 feature) 0038 * 0039 * @package Zend_Pdf 0040 * @subpackage Outlines 0041 * @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com) 0042 * @license http://framework.zend.com/license/new-bsd New BSD License 0043 */ 0044 class Zend_Pdf_Outline_Created extends Zend_Pdf_Outline 0045 { 0046 /** 0047 * Outline title. 0048 * 0049 * @var string 0050 */ 0051 protected $_title; 0052 0053 /** 0054 * Color to be used for the outline entry’s text. 0055 0056 * It uses the DeviceRGB color space for color representation. 0057 * Null means default value - black ([0.0 0.0 0.0] in RGB representation). 0058 * 0059 * @var Zend_Pdf_Color_Rgb 0060 */ 0061 protected $_color = null; 0062 0063 /** 0064 * True if outline item is displayed in italic. 0065 * Default value is false. 0066 * 0067 * @var boolean 0068 */ 0069 protected $_italic = false; 0070 0071 /** 0072 * True if outline item is displayed in bold. 0073 * Default value is false. 0074 * 0075 * @var boolean 0076 */ 0077 protected $_bold = false; 0078 0079 /** 0080 * Target destination or action. 0081 * String means named destination 0082 * 0083 * Null means no target. 0084 * 0085 * @var Zend_Pdf_Destination|Zend_Pdf_Action 0086 */ 0087 protected $_target = null; 0088 0089 0090 /** 0091 * Get outline title. 0092 * 0093 * @return string 0094 */ 0095 public function getTitle() 0096 { 0097 return $this->_title; 0098 } 0099 0100 /** 0101 * Set outline title 0102 * 0103 * @param string $title 0104 * @return Zend_Pdf_Outline 0105 */ 0106 public function setTitle($title) 0107 { 0108 $this->_title = $title; 0109 return $this; 0110 } 0111 0112 /** 0113 * Returns true if outline item is displayed in italic 0114 * 0115 * @return boolean 0116 */ 0117 public function isItalic() 0118 { 0119 return $this->_italic; 0120 } 0121 0122 /** 0123 * Sets 'isItalic' outline flag 0124 * 0125 * @param boolean $isItalic 0126 * @return Zend_Pdf_Outline 0127 */ 0128 public function setIsItalic($isItalic) 0129 { 0130 $this->_italic = $isItalic; 0131 return $this; 0132 } 0133 0134 /** 0135 * Returns true if outline item is displayed in bold 0136 * 0137 * @return boolean 0138 */ 0139 public function isBold() 0140 { 0141 return $this->_bold; 0142 } 0143 0144 /** 0145 * Sets 'isBold' outline flag 0146 * 0147 * @param boolean $isBold 0148 * @return Zend_Pdf_Outline 0149 */ 0150 public function setIsBold($isBold) 0151 { 0152 $this->_bold = $isBold; 0153 return $this; 0154 } 0155 0156 0157 /** 0158 * Get outline text color. 0159 * 0160 * @return Zend_Pdf_Color_Rgb 0161 */ 0162 public function getColor() 0163 { 0164 return $this->_color; 0165 } 0166 0167 /** 0168 * Set outline text color. 0169 * (null means default color which is black) 0170 * 0171 * @param Zend_Pdf_Color_Rgb $color 0172 * @return Zend_Pdf_Outline 0173 */ 0174 public function setColor(Zend_Pdf_Color_Rgb $color) 0175 { 0176 $this->_color = $color; 0177 return $this; 0178 } 0179 0180 /** 0181 * Get outline target. 0182 * 0183 * @return Zend_Pdf_Target 0184 */ 0185 public function getTarget() 0186 { 0187 return $this->_target; 0188 } 0189 0190 /** 0191 * Set outline target. 0192 * Null means no target 0193 * 0194 * @param Zend_Pdf_Target|string $target 0195 * @return Zend_Pdf_Outline 0196 * @throws Zend_Pdf_Exception 0197 */ 0198 public function setTarget($target = null) 0199 { 0200 if (is_string($target)) { 0201 // require_once 'Zend/Pdf/Destination/Named.php'; 0202 $target = new Zend_Pdf_Destination_Named($target); 0203 } 0204 0205 if ($target === null || $target instanceof Zend_Pdf_Target) { 0206 $this->_target = $target; 0207 } else { 0208 // require_once 'Zend/Pdf/Exception.php'; 0209 throw new Zend_Pdf_Exception('Outline target has to be Zend_Pdf_Destination or Zend_Pdf_Action object or string'); 0210 } 0211 0212 return $this; 0213 } 0214 0215 0216 /** 0217 * Object constructor 0218 * 0219 * @param array $options 0220 * @throws Zend_Pdf_Exception 0221 */ 0222 public function __construct($options = array()) 0223 { 0224 if (!isset($options['title'])) { 0225 // require_once 'Zend/Pdf/Exception.php'; 0226 throw new Zend_Pdf_Exception('Title parameter is required.'); 0227 } 0228 0229 $this->setOptions($options); 0230 } 0231 0232 /** 0233 * Dump Outline and its child outlines into PDF structures 0234 * 0235 * Returns dictionary indirect object or reference 0236 * 0237 * @internal 0238 * @param Zend_Pdf_ElementFactory $factory object factory for newly created indirect objects 0239 * @param boolean $updateNavigation Update navigation flag 0240 * @param Zend_Pdf_Element $parent Parent outline dictionary reference 0241 * @param Zend_Pdf_Element $prev Previous outline dictionary reference 0242 * @param SplObjectStorage $processedOutlines List of already processed outlines 0243 * @return Zend_Pdf_Element 0244 * @throws Zend_Pdf_Exception 0245 */ 0246 public function dumpOutline(Zend_Pdf_ElementFactory_Interface $factory, 0247 $updateNavigation, 0248 Zend_Pdf_Element $parent, 0249 Zend_Pdf_Element $prev = null, 0250 SplObjectStorage $processedOutlines = null) 0251 { 0252 if ($processedOutlines === null) { 0253 $processedOutlines = new SplObjectStorage(); 0254 } 0255 $processedOutlines->attach($this); 0256 0257 $outlineDictionary = $factory->newObject(new Zend_Pdf_Element_Dictionary()); 0258 0259 $outlineDictionary->Title = new Zend_Pdf_Element_String($this->getTitle()); 0260 0261 $target = $this->getTarget(); 0262 if ($target === null) { 0263 // Do nothing 0264 } else if ($target instanceof Zend_Pdf_Destination) { 0265 $outlineDictionary->Dest = $target->getResource(); 0266 } else if ($target instanceof Zend_Pdf_Action) { 0267 $outlineDictionary->A = $target->getResource(); 0268 } else { 0269 // require_once 'Zend/Pdf/Exception.php'; 0270 throw new Zend_Pdf_Exception('Outline target has to be Zend_Pdf_Destination, Zend_Pdf_Action object or null'); 0271 } 0272 0273 $color = $this->getColor(); 0274 if ($color !== null) { 0275 $components = $color->getComponents(); 0276 $colorComponentElements = array(new Zend_Pdf_Element_Numeric($components[0]), 0277 new Zend_Pdf_Element_Numeric($components[1]), 0278 new Zend_Pdf_Element_Numeric($components[2])); 0279 $outlineDictionary->C = new Zend_Pdf_Element_Array($colorComponentElements); 0280 } 0281 0282 if ($this->isItalic() || $this->isBold()) { 0283 $outlineDictionary->F = new Zend_Pdf_Element_Numeric(($this->isItalic()? 1 : 0) | // Bit 1 - Italic 0284 ($this->isBold()? 2 : 0)); // Bit 2 - Bold 0285 } 0286 0287 0288 $outlineDictionary->Parent = $parent; 0289 $outlineDictionary->Prev = $prev; 0290 0291 $lastChild = null; 0292 foreach ($this->childOutlines as $childOutline) { 0293 if ($processedOutlines->contains($childOutline)) { 0294 // require_once 'Zend/Pdf/Exception.php'; 0295 throw new Zend_Pdf_Exception('Outlines cyclyc reference is detected.'); 0296 } 0297 0298 if ($lastChild === null) { 0299 $lastChild = $childOutline->dumpOutline($factory, true, $outlineDictionary, null, $processedOutlines); 0300 $outlineDictionary->First = $lastChild; 0301 } else { 0302 $childOutlineDictionary = $childOutline->dumpOutline($factory, true, $outlineDictionary, $lastChild, $processedOutlines); 0303 $lastChild->Next = $childOutlineDictionary; 0304 $lastChild = $childOutlineDictionary; 0305 } 0306 } 0307 $outlineDictionary->Last = $lastChild; 0308 0309 if (count($this->childOutlines) != 0) { 0310 $outlineDictionary->Count = new Zend_Pdf_Element_Numeric(($this->isOpen()? 1 : -1)*count($this->childOutlines)); 0311 } 0312 0313 return $outlineDictionary; 0314 } 0315 }