PageRenderTime 28ms CodeModel.GetById 17ms app.highlight 7ms RepoModel.GetById 2ms app.codeStats 0ms

/framework/vendor/zend/Zend/Pdf/Outline/Created.php

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