PageRenderTime 20ms CodeModel.GetById 11ms app.highlight 6ms RepoModel.GetById 1ms app.codeStats 0ms

/framework/vendor/zend/Zend/Pdf/Annotation/Text.php

http://zoop.googlecode.com/
PHP | 95 lines | 39 code | 11 blank | 45 comment | 5 complexity | e5e54cba473c3c9a1b4a8b1b1ecfac82 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 Annotation
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: Text.php 20096 2010-01-06 02:05:09Z bkarwin $
21 */
22
23/** Internally used classes */
24require_once 'Zend/Pdf/Element.php';
25require_once 'Zend/Pdf/Element/Array.php';
26require_once 'Zend/Pdf/Element/Dictionary.php';
27require_once 'Zend/Pdf/Element/Name.php';
28require_once 'Zend/Pdf/Element/Numeric.php';
29require_once 'Zend/Pdf/Element/String.php';
30
31
32/** Zend_Pdf_Annotation */
33require_once 'Zend/Pdf/Annotation.php';
34
35/**
36 * A text annotation represents a "sticky note" attached to a point in the PDF document.
37 *
38 * @package    Zend_Pdf
39 * @subpackage Annotation
40 * @copyright  Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
41 * @license    http://framework.zend.com/license/new-bsd     New BSD License
42 */
43class Zend_Pdf_Annotation_Text extends Zend_Pdf_Annotation
44{
45    /**
46     * Annotation object constructor
47     *
48     * @throws Zend_Pdf_Exception
49     */
50    public function __construct(Zend_Pdf_Element $annotationDictionary)
51    {
52        if ($annotationDictionary->getType() != Zend_Pdf_Element::TYPE_DICTIONARY) {
53            require_once 'Zend/Pdf/Exception.php';
54            throw new Zend_Pdf_Exception('Annotation dictionary resource has to be a dictionary.');
55        }
56
57        if ($annotationDictionary->Subtype === null  ||
58            $annotationDictionary->Subtype->getType() != Zend_Pdf_Element::TYPE_NAME  ||
59            $annotationDictionary->Subtype->value != 'Text') {
60            require_once 'Zend/Pdf/Exception.php';
61            throw new Zend_Pdf_Exception('Subtype => Text entry is requires');
62        }
63
64        parent::__construct($annotationDictionary);
65    }
66
67    /**
68     * Create link annotation object
69     *
70     * @param float $x1
71     * @param float $y1
72     * @param float $x2
73     * @param float $y2
74     * @param string $text
75     * @return Zend_Pdf_Annotation_Text
76     */
77    public static function create($x1, $y1, $x2, $y2, $text)
78    {
79        $annotationDictionary = new Zend_Pdf_Element_Dictionary();
80
81        $annotationDictionary->Type    = new Zend_Pdf_Element_Name('Annot');
82        $annotationDictionary->Subtype = new Zend_Pdf_Element_Name('Text');
83
84        $rectangle = new Zend_Pdf_Element_Array();
85        $rectangle->items[] = new Zend_Pdf_Element_Numeric($x1);
86        $rectangle->items[] = new Zend_Pdf_Element_Numeric($y1);
87        $rectangle->items[] = new Zend_Pdf_Element_Numeric($x2);
88        $rectangle->items[] = new Zend_Pdf_Element_Numeric($y2);
89        $annotationDictionary->Rect = $rectangle;
90
91        $annotationDictionary->Contents = new Zend_Pdf_Element_String($text);
92
93        return new Zend_Pdf_Annotation_Text($annotationDictionary);
94    }
95}