File indexing completed on 2024-12-22 05:36:56
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 /** 0025 * Abstract PDF outline representation class 0026 * 0027 * @todo Implement an ability to associate an outline item with a structure element (PDF 1.3 feature) 0028 * 0029 * @package Zend_Pdf 0030 * @subpackage Outlines 0031 * @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com) 0032 * @license http://framework.zend.com/license/new-bsd New BSD License 0033 */ 0034 abstract class Zend_Pdf_Outline implements RecursiveIterator, Countable 0035 { 0036 /** 0037 * True if outline is open. 0038 * 0039 * @var boolean 0040 */ 0041 protected $_open = false; 0042 0043 /** 0044 * Array of child outlines (array of Zend_Pdf_Outline objects) 0045 * 0046 * @var array 0047 */ 0048 public $childOutlines = array(); 0049 0050 0051 /** 0052 * Get outline title. 0053 * 0054 * @return string 0055 */ 0056 abstract public function getTitle(); 0057 0058 /** 0059 * Set outline title 0060 * 0061 * @param string $title 0062 * @return Zend_Pdf_Outline 0063 */ 0064 abstract public function setTitle($title); 0065 0066 /** 0067 * Returns true if outline item is open by default 0068 * 0069 * @return boolean 0070 */ 0071 public function isOpen() 0072 { 0073 return $this->_open; 0074 } 0075 0076 /** 0077 * Sets 'isOpen' outline flag 0078 * 0079 * @param boolean $isOpen 0080 * @return Zend_Pdf_Outline 0081 */ 0082 public function setIsOpen($isOpen) 0083 { 0084 $this->_open = $isOpen; 0085 return $this; 0086 } 0087 0088 /** 0089 * Returns true if outline item is displayed in italic 0090 * 0091 * @return boolean 0092 */ 0093 abstract public function isItalic(); 0094 0095 /** 0096 * Sets 'isItalic' outline flag 0097 * 0098 * @param boolean $isItalic 0099 * @return Zend_Pdf_Outline 0100 */ 0101 abstract public function setIsItalic($isItalic); 0102 0103 /** 0104 * Returns true if outline item is displayed in bold 0105 * 0106 * @return boolean 0107 */ 0108 abstract public function isBold(); 0109 0110 /** 0111 * Sets 'isBold' outline flag 0112 * 0113 * @param boolean $isBold 0114 * @return Zend_Pdf_Outline 0115 */ 0116 abstract public function setIsBold($isBold); 0117 0118 0119 /** 0120 * Get outline text color. 0121 * 0122 * @return Zend_Pdf_Color_Rgb 0123 */ 0124 abstract public function getColor(); 0125 0126 /** 0127 * Set outline text color. 0128 * (null means default color which is black) 0129 * 0130 * @param Zend_Pdf_Color_Rgb $color 0131 * @return Zend_Pdf_Outline 0132 */ 0133 abstract public function setColor(Zend_Pdf_Color_Rgb $color); 0134 0135 /** 0136 * Get outline target. 0137 * 0138 * @return Zend_Pdf_Target 0139 */ 0140 abstract public function getTarget(); 0141 0142 /** 0143 * Set outline target. 0144 * Null means no target 0145 * 0146 * @param Zend_Pdf_Target|string $target 0147 * @return Zend_Pdf_Outline 0148 */ 0149 abstract public function setTarget($target = null); 0150 0151 /** 0152 * Get outline options 0153 * 0154 * @return array 0155 */ 0156 public function getOptions() 0157 { 0158 return array('title' => $this->_title, 0159 'open' => $this->_open, 0160 'color' => $this->_color, 0161 'italic' => $this->_italic, 0162 'bold' => $this->_bold, 0163 'target' => $this->_target); 0164 } 0165 0166 /** 0167 * Set outline options 0168 * 0169 * @param array $options 0170 * @return Zend_Pdf_Action 0171 * @throws Zend_Pdf_Exception 0172 */ 0173 public function setOptions(array $options) 0174 { 0175 foreach ($options as $key => $value) { 0176 switch ($key) { 0177 case 'title': 0178 $this->setTitle($value); 0179 break; 0180 0181 case 'open': 0182 $this->setIsOpen($value); 0183 break; 0184 0185 case 'color': 0186 $this->setColor($value); 0187 break; 0188 case 'italic': 0189 $this->setIsItalic($value); 0190 break; 0191 0192 case 'bold': 0193 $this->setIsBold($value); 0194 break; 0195 0196 case 'target': 0197 $this->setTarget($value); 0198 break; 0199 0200 default: 0201 // require_once 'Zend/Pdf/Exception.php'; 0202 throw new Zend_Pdf_Exception("Unknown option name - '$key'."); 0203 break; 0204 } 0205 } 0206 0207 return $this; 0208 } 0209 0210 /** 0211 * Create new Outline object 0212 * 0213 * It provides two forms of input parameters: 0214 * 0215 * 1. Zend_Pdf_Outline::create(string $title[, Zend_Pdf_Target $target]) 0216 * 2. Zend_Pdf_Outline::create(array $options) 0217 * 0218 * Second form allows to provide outline options as an array. 0219 * The followed options are supported: 0220 * 'title' - string, outline title, required 0221 * 'open' - boolean, true if outline entry is open (default value is false) 0222 * 'color' - Zend_Pdf_Color_Rgb object, true if outline entry is open (default value is null - black) 0223 * 'italic' - boolean, true if outline entry is displayed in italic (default value is false) 0224 * 'bold' - boolean, true if outline entry is displayed in bold (default value is false) 0225 * 'target' - Zend_Pdf_Target object or string, outline item destination 0226 * 0227 * @return Zend_Pdf_Outline 0228 * @throws Zend_Pdf_Exception 0229 */ 0230 public static function create($param1, $param2 = null) 0231 { 0232 // require_once 'Zend/Pdf/Outline/Created.php'; 0233 if (is_string($param1)) { 0234 if ($param2 !== null && !($param2 instanceof Zend_Pdf_Target || is_string($param2))) { 0235 // require_once 'Zend/Pdf/Exception.php'; 0236 throw new Zend_Pdf_Exception('Outline create method takes $title (string) and $target (Zend_Pdf_Target or string) or an array as an input'); 0237 } 0238 0239 return new Zend_Pdf_Outline_Created(array('title' => $param1, 0240 'target' => $param2)); 0241 } else { 0242 if (!is_array($param1) || $param2 !== null) { 0243 // require_once 'Zend/Pdf/Exception.php'; 0244 throw new Zend_Pdf_Exception('Outline create method takes $title (string) and $destination (Zend_Pdf_Destination) or an array as an input'); 0245 } 0246 0247 return new Zend_Pdf_Outline_Created($param1); 0248 } 0249 } 0250 0251 /** 0252 * Returns number of the total number of open items at all levels of the outline. 0253 * 0254 * @internal 0255 * @return integer 0256 */ 0257 public function openOutlinesCount() 0258 { 0259 $count = 1; // Include this outline 0260 0261 if ($this->isOpen()) { 0262 foreach ($this->childOutlines as $child) { 0263 $count += $child->openOutlinesCount(); 0264 } 0265 } 0266 0267 return $count; 0268 } 0269 0270 /** 0271 * Dump Outline and its child outlines into PDF structures 0272 * 0273 * Returns dictionary indirect object or reference 0274 * 0275 * @param Zend_Pdf_ElementFactory $factory object factory for newly created indirect objects 0276 * @param boolean $updateNavigation Update navigation flag 0277 * @param Zend_Pdf_Element $parent Parent outline dictionary reference 0278 * @param Zend_Pdf_Element $prev Previous outline dictionary reference 0279 * @param SplObjectStorage $processedOutlines List of already processed outlines 0280 * @return Zend_Pdf_Element 0281 */ 0282 abstract public function dumpOutline(Zend_Pdf_ElementFactory_Interface $factory, 0283 $updateNavigation, 0284 Zend_Pdf_Element $parent, 0285 Zend_Pdf_Element $prev = null, 0286 SplObjectStorage $processedOutlines = null); 0287 0288 0289 //////////////////////////////////////////////////////////////////////// 0290 // RecursiveIterator interface methods 0291 ////////////// 0292 0293 /** 0294 * Returns the child outline. 0295 * 0296 * @return Zend_Pdf_Outline 0297 */ 0298 public function current() 0299 { 0300 return current($this->childOutlines); 0301 } 0302 0303 /** 0304 * Returns current iterator key 0305 * 0306 * @return integer 0307 */ 0308 public function key() 0309 { 0310 return key($this->childOutlines); 0311 } 0312 0313 /** 0314 * Go to next child 0315 */ 0316 public function next() 0317 { 0318 return next($this->childOutlines); 0319 } 0320 0321 /** 0322 * Rewind children 0323 */ 0324 public function rewind() 0325 { 0326 return reset($this->childOutlines); 0327 } 0328 0329 /** 0330 * Check if current position is valid 0331 * 0332 * @return boolean 0333 */ 0334 public function valid() 0335 { 0336 return current($this->childOutlines) !== false; 0337 } 0338 0339 /** 0340 * Returns the child outline. 0341 * 0342 * @return Zend_Pdf_Outline|null 0343 */ 0344 public function getChildren() 0345 { 0346 return current($this->childOutlines); 0347 } 0348 0349 /** 0350 * Implements RecursiveIterator interface. 0351 * 0352 * @return bool whether container has any pages 0353 */ 0354 public function hasChildren() 0355 { 0356 return count($this->childOutlines) > 0; 0357 } 0358 0359 0360 //////////////////////////////////////////////////////////////////////// 0361 // Countable interface methods 0362 ////////////// 0363 0364 /** 0365 * count() 0366 * 0367 * @return int 0368 */ 0369 public function count() 0370 { 0371 return count($this->childOutlines); 0372 } 0373 }