PageRenderTime 6ms CodeModel.GetById 1ms app.highlight 2ms RepoModel.GetById 1ms app.codeStats 1ms

/framework/vendor/zend/Zend/Pdf/Action/URI.php

http://zoop.googlecode.com/
PHP | 167 lines | 64 code | 18 blank | 85 comment | 6 complexity | 0534de6c9789fcc2648ee2013dfa3bc0 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: URI.php 20096 2010-01-06 02:05:09Z bkarwin $
 21 */
 22
 23/** Internally used classes */
 24require_once 'Zend/Pdf/Element/Dictionary.php';
 25require_once 'Zend/Pdf/Element/Name.php';
 26require_once 'Zend/Pdf/Element/String.php';
 27require_once 'Zend/Pdf/Element/Boolean.php';
 28
 29
 30/** Zend_Pdf_Action */
 31require_once 'Zend/Pdf/Action.php';
 32
 33
 34/**
 35 * PDF 'Resolve a uniform resource identifier' action
 36 *
 37 * A URI action causes a URI to be resolved.
 38 *
 39 * @package    Zend_Pdf
 40 * @subpackage Actions
 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_Action_URI extends Zend_Pdf_Action
 45{
 46    /**
 47     * Object constructor
 48     *
 49     * @param Zend_Pdf_Element_Dictionary $dictionary
 50     * @param SplObjectStorage            $processedActions  list of already processed action dictionaries, used to avoid cyclic references
 51     * @throws Zend_Pdf_Exception
 52     */
 53    public function __construct(Zend_Pdf_Element $dictionary, SplObjectStorage $processedActions)
 54    {
 55        parent::__construct($dictionary, $processedActions);
 56
 57        if ($dictionary->URI === null) {
 58            require_once 'Zend/Pdf/Exception.php';
 59            throw new Zend_Pdf_Exception('URI action dictionary entry is required');
 60        }
 61    }
 62
 63    /**
 64     * Validate URI
 65     *
 66     * @param string $uri
 67     * @return true
 68     * @throws Zend_Pdf_Exception
 69     */
 70    protected static function _validateUri($uri)
 71    {
 72        $scheme = parse_url((string)$uri, PHP_URL_SCHEME);
 73        if ($scheme === false || $scheme === null) {
 74            require_once 'Zend/Pdf/Exception.php';
 75            throw new Zend_Pdf_Exception('Invalid URI');
 76        }
 77    }
 78
 79    /**
 80     * Create new Zend_Pdf_Action_URI object using specified uri
 81     *
 82     * @param string  $uri    The URI to resolve, encoded in 7-bit ASCII
 83     * @param boolean $isMap  A flag specifying whether to track the mouse position when the URI is resolved
 84     * @return Zend_Pdf_Action_URI
 85     */
 86    public static function create($uri, $isMap = false)
 87    {
 88        self::_validateUri($uri);
 89
 90        $dictionary = new Zend_Pdf_Element_Dictionary();
 91        $dictionary->Type = new Zend_Pdf_Element_Name('Action');
 92        $dictionary->S    = new Zend_Pdf_Element_Name('URI');
 93        $dictionary->Next = null;
 94        $dictionary->URI  = new Zend_Pdf_Element_String($uri);
 95        if ($isMap) {
 96            $dictionary->IsMap = new Zend_Pdf_Element_Boolean(true);
 97        }
 98
 99        return new Zend_Pdf_Action_URI($dictionary, new SplObjectStorage());
100    }
101
102    /**
103     * Set URI to resolve
104     *
105     * @param string $uri   The uri to resolve, encoded in 7-bit ASCII.
106     * @return Zend_Pdf_Action_URI
107     */
108    public function setUri($uri)
109    {
110        $this->_validateUri($uri);
111
112        $this->_actionDictionary->touch();
113        $this->_actionDictionary->URI = new Zend_Pdf_Element_String($uri);
114
115        return $this;
116    }
117
118    /**
119     * Get URI to resolve
120     *
121     * @return string
122     */
123    public function getUri()
124    {
125        return $this->_actionDictionary->URI->value;
126    }
127
128    /**
129     * Set IsMap property
130     *
131     * If the IsMap flag is true and the user has triggered the URI action by clicking
132     * an annotation, the coordinates of the mouse position at the time the action is
133     * performed should be transformed from device space to user space and then offset
134     * relative to the upper-left corner of the annotation rectangle.
135     *
136     * @param boolean $isMap  A flag specifying whether to track the mouse position when the URI is resolved
137     * @return Zend_Pdf_Action_URI
138     */
139    public function setIsMap($isMap)
140    {
141        $this->_actionDictionary->touch();
142
143        if ($isMap) {
144            $this->_actionDictionary->IsMap = new Zend_Pdf_Element_Boolean(true);
145        } else {
146            $this->_actionDictionary->IsMap = null;
147        }
148
149        return $this;
150    }
151
152    /**
153     * Get IsMap property
154     *
155     * If the IsMap flag is true and the user has triggered the URI action by clicking
156     * an annotation, the coordinates of the mouse position at the time the action is
157     * performed should be transformed from device space to user space and then offset
158     * relative to the upper-left corner of the annotation rectangle.
159     *
160     * @return boolean
161     */
162    public function getIsMap()
163    {
164        return $this->_actionDictionary->IsMap !== null  &&
165               $this->_actionDictionary->IsMap->value;
166    }
167}