1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373
|
<?php
/**
* Zend Framework
*
* LICENSE
*
* This source file is subject to the new BSD license that is bundled
* with this package in the file LICENSE.txt.
* It is also available through the world-wide-web at this URL:
* http://framework.zend.com/license/new-bsd
* If you did not receive a copy of the license and are unable to
* obtain it through the world-wide-web, please send an email
* to license@zend.com so we can send you a copy immediately.
*
* @category Zend
* @package Zend_Pdf
* @subpackage Actions
* @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
* @version $Id: Outline.php 20096 2010-01-06 02:05:09Z bkarwin $
*/
/**
* Abstract PDF outline representation class
*
* @todo Implement an ability to associate an outline item with a structure element (PDF 1.3 feature)
*
* @package Zend_Pdf
* @subpackage Outlines
* @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
*/
abstract class Zend_Pdf_Outline implements RecursiveIterator, Countable
{
/**
* True if outline is open.
*
* @var boolean
*/
protected $_open = false;
/**
* Array of child outlines (array of Zend_Pdf_Outline objects)
*
* @var array
*/
public $childOutlines = array();
/**
* Get outline title.
*
* @return string
*/
abstract public function getTitle();
/**
* Set outline title
*
* @param string $title
* @return Zend_Pdf_Outline
*/
abstract public function setTitle($title);
/**
* Returns true if outline item is open by default
*
* @return boolean
*/
public function isOpen()
{
return $this->_open;
}
/**
* Sets 'isOpen' outline flag
*
* @param boolean $isOpen
* @return Zend_Pdf_Outline
*/
public function setIsOpen($isOpen)
{
$this->_open = $isOpen;
return $this;
}
/**
* Returns true if outline item is displayed in italic
*
* @return boolean
*/
abstract public function isItalic();
/**
* Sets 'isItalic' outline flag
*
* @param boolean $isItalic
* @return Zend_Pdf_Outline
*/
abstract public function setIsItalic($isItalic);
/**
* Returns true if outline item is displayed in bold
*
* @return boolean
*/
abstract public function isBold();
/**
* Sets 'isBold' outline flag
*
* @param boolean $isBold
* @return Zend_Pdf_Outline
*/
abstract public function setIsBold($isBold);
/**
* Get outline text color.
*
* @return Zend_Pdf_Color_Rgb
*/
abstract public function getColor();
/**
* Set outline text color.
* (null means default color which is black)
*
* @param Zend_Pdf_Color_Rgb $color
* @return Zend_Pdf_Outline
*/
abstract public function setColor(Zend_Pdf_Color_Rgb $color);
/**
* Get outline target.
*
* @return Zend_Pdf_Target
*/
abstract public function getTarget();
/**
* Set outline target.
* Null means no target
*
* @param Zend_Pdf_Target|string $target
* @return Zend_Pdf_Outline
*/
abstract public function setTarget($target = null);
/**
* Get outline options
*
* @return array
*/
public function getOptions()
{
return array('title' => $this->_title,
'open' => $this->_open,
'color' => $this->_color,
'italic' => $this->_italic,
'bold' => $this->_bold,
'target' => $this->_target);
}
/**
* Set outline options
*
* @param array $options
* @return Zend_Pdf_Action
* @throws Zend_Pdf_Exception
*/
public function setOptions(array $options)
{
foreach ($options as $key => $value) {
switch ($key) {
case 'title':
$this->setTitle($value);
break;
case 'open':
$this->setIsOpen($value);
break;
case 'color':
$this->setColor($value);
break;
case 'italic':
$this->setIsItalic($value);
break;
case 'bold':
$this->setIsBold($value);
break;
case 'target':
$this->setTarget($value);
break;
default:
require_once 'Zend/Pdf/Exception.php';
throw new Zend_Pdf_Exception("Unknown option name - '$key'.");
break;
}
}
return $this;
}
/**
* Create new Outline object
*
* It provides two forms of input parameters:
*
* 1. Zend_Pdf_Outline::create(string $title[, Zend_Pdf_Target $target])
* 2. Zend_Pdf_Outline::create(array $options)
*
* Second form allows to provide outline options as an array.
* The followed options are supported:
* 'title' - string, outline title, required
* 'open' - boolean, true if outline entry is open (default value is false)
* 'color' - Zend_Pdf_Color_Rgb object, true if outline entry is open (default value is null - black)
* 'italic' - boolean, true if outline entry is displayed in italic (default value is false)
* 'bold' - boolean, true if outline entry is displayed in bold (default value is false)
* 'target' - Zend_Pdf_Target object or string, outline item destination
*
* @return Zend_Pdf_Outline
* @throws Zend_Pdf_Exception
*/
public static function create($param1, $param2 = null)
{
require_once 'Zend/Pdf/Outline/Created.php';
if (is_string($param1)) {
if ($param2 !== null && !($param2 instanceof Zend_Pdf_Target || is_string($param2))) {
require_once 'Zend/Pdf/Exception.php';
throw new Zend_Pdf_Exception('Outline create method takes $title (string) and $target (Zend_Pdf_Target or string) or an array as an input');
}
return new Zend_Pdf_Outline_Created(array('title' => $param1,
'target' => $param2));
} else {
if (!is_array($param1) || $param2 !== null) {
require_once 'Zend/Pdf/Exception.php';
throw new Zend_Pdf_Exception('Outline create method takes $title (string) and $destination (Zend_Pdf_Destination) or an array as an input');
}
return new Zend_Pdf_Outline_Created($param1);
}
}
/**
* Returns number of the total number of open items at all levels of the outline.
*
* @internal
* @return integer
*/
public function openOutlinesCount()
{
$count = 1; // Include this outline
if ($this->isOpen()) {
foreach ($this->childOutlines as $child) {
$count += $child->openOutlinesCount();
}
}
return $count;
}
/**
* Dump Outline and its child outlines into PDF structures
*
* Returns dictionary indirect object or reference
*
* @param Zend_Pdf_ElementFactory $factory object factory for newly created indirect objects
* @param boolean $updateNavigation Update navigation flag
* @param Zend_Pdf_Element $parent Parent outline dictionary reference
* @param Zend_Pdf_Element $prev Previous outline dictionary reference
* @param SplObjectStorage $processedOutlines List of already processed outlines
* @return Zend_Pdf_Element
*/
abstract public function dumpOutline(Zend_Pdf_ElementFactory_Interface $factory,
$updateNavigation,
Zend_Pdf_Element $parent,
Zend_Pdf_Element $prev = null,
SplObjectStorage $processedOutlines = null);
////////////////////////////////////////////////////////////////////////
// RecursiveIterator interface methods
//////////////
/**
* Returns the child outline.
*
* @return Zend_Pdf_Outline
*/
public function current()
{
return current($this->childOutlines);
}
/**
* Returns current iterator key
*
* @return integer
*/
public function key()
{
return key($this->childOutlines);
}
/**
* Go to next child
*/
public function next()
{
return next($this->childOutlines);
}
/**
* Rewind children
*/
public function rewind()
{
return reset($this->childOutlines);
}
/**
* Check if current position is valid
*
* @return boolean
*/
public function valid()
{
return current($this->childOutlines) !== false;
}
/**
* Returns the child outline.
*
* @return Zend_Pdf_Outline|null
*/
public function getChildren()
{
return current($this->childOutlines);
}
/**
* Implements RecursiveIterator interface.
*
* @return bool whether container has any pages
*/
public function hasChildren()
{
return count($this->childOutlines) > 0;
}
////////////////////////////////////////////////////////////////////////
// Countable interface methods
//////////////
/**
* count()
*
* @return int
*/
public function count()
{
return count($this->childOutlines);
}
}
|