|
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: Markup.php 20785 2010-01-31 09:43:03Z mikaelkael $ |
|
21 */ |
|
22 |
|
23 /** Internally used classes */ |
|
24 require_once 'Zend/Pdf/Element.php'; |
|
25 require_once 'Zend/Pdf/Element/Array.php'; |
|
26 require_once 'Zend/Pdf/Element/Dictionary.php'; |
|
27 require_once 'Zend/Pdf/Element/Name.php'; |
|
28 require_once 'Zend/Pdf/Element/Numeric.php'; |
|
29 require_once 'Zend/Pdf/Element/String.php'; |
|
30 |
|
31 |
|
32 /** Zend_Pdf_Annotation */ |
|
33 require_once 'Zend/Pdf/Annotation.php'; |
|
34 |
|
35 /** |
|
36 * A markup annotation |
|
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 */ |
|
43 class Zend_Pdf_Annotation_Markup extends Zend_Pdf_Annotation |
|
44 { |
|
45 /** |
|
46 * Annotation subtypes |
|
47 */ |
|
48 const SUBTYPE_HIGHLIGHT = 'Highlight'; |
|
49 const SUBTYPE_UNDERLINE = 'Underline'; |
|
50 const SUBTYPE_SQUIGGLY = 'Squiggly'; |
|
51 const SUBTYPE_STRIKEOUT = 'StrikeOut'; |
|
52 |
|
53 /** |
|
54 * Annotation object constructor |
|
55 * |
|
56 * @throws Zend_Pdf_Exception |
|
57 */ |
|
58 public function __construct(Zend_Pdf_Element $annotationDictionary) |
|
59 { |
|
60 if ($annotationDictionary->getType() != Zend_Pdf_Element::TYPE_DICTIONARY) { |
|
61 require_once 'Zend/Pdf/Exception.php'; |
|
62 throw new Zend_Pdf_Exception('Annotation dictionary resource has to be a dictionary.'); |
|
63 } |
|
64 |
|
65 if ($annotationDictionary->Subtype === null || |
|
66 $annotationDictionary->Subtype->getType() != Zend_Pdf_Element::TYPE_NAME || |
|
67 !in_array( $annotationDictionary->Subtype->value, |
|
68 array(self::SUBTYPE_HIGHLIGHT, |
|
69 self::SUBTYPE_UNDERLINE, |
|
70 self::SUBTYPE_SQUIGGLY, |
|
71 self::SUBTYPE_STRIKEOUT) )) { |
|
72 require_once 'Zend/Pdf/Exception.php'; |
|
73 throw new Zend_Pdf_Exception('Subtype => Markup entry is omitted or has wrong value.'); |
|
74 } |
|
75 |
|
76 parent::__construct($annotationDictionary); |
|
77 } |
|
78 |
|
79 /** |
|
80 * Create markup annotation object |
|
81 * |
|
82 * Text markup annotations appear as highlights, underlines, strikeouts or |
|
83 * jagged ("squiggly") underlines in the text of a document. When opened, |
|
84 * they display a pop-up window containing the text of the associated note. |
|
85 * |
|
86 * $subType parameter may contain |
|
87 * Zend_Pdf_Annotation_Markup::SUBTYPE_HIGHLIGHT |
|
88 * Zend_Pdf_Annotation_Markup::SUBTYPE_UNDERLINE |
|
89 * Zend_Pdf_Annotation_Markup::SUBTYPE_SQUIGGLY |
|
90 * Zend_Pdf_Annotation_Markup::SUBTYPE_STRIKEOUT |
|
91 * for for a highlight, underline, squiggly-underline, or strikeout annotation, |
|
92 * respectively. |
|
93 * |
|
94 * $quadPoints is an array of 8xN numbers specifying the coordinates of |
|
95 * N quadrilaterals default user space. Each quadrilateral encompasses a word or |
|
96 * group of contiguous words in the text underlying the annotation. |
|
97 * The coordinates for each quadrilateral are given in the order |
|
98 * x1 y1 x2 y2 x3 y3 x4 y4 |
|
99 * specifying the quadrilateral’s four vertices in counterclockwise order |
|
100 * starting from left bottom corner. |
|
101 * The text is oriented with respect to the edge connecting points |
|
102 * (x1, y1) and (x2, y2). |
|
103 * |
|
104 * @param float $x1 |
|
105 * @param float $y1 |
|
106 * @param float $x2 |
|
107 * @param float $y2 |
|
108 * @param string $text |
|
109 * @param string $subType |
|
110 * @param array $quadPoints [x1 y1 x2 y2 x3 y3 x4 y4] |
|
111 * @return Zend_Pdf_Annotation_Markup |
|
112 * @throws Zend_Pdf_Exception |
|
113 */ |
|
114 public static function create($x1, $y1, $x2, $y2, $text, $subType, $quadPoints) |
|
115 { |
|
116 $annotationDictionary = new Zend_Pdf_Element_Dictionary(); |
|
117 |
|
118 $annotationDictionary->Type = new Zend_Pdf_Element_Name('Annot'); |
|
119 $annotationDictionary->Subtype = new Zend_Pdf_Element_Name($subType); |
|
120 |
|
121 $rectangle = new Zend_Pdf_Element_Array(); |
|
122 $rectangle->items[] = new Zend_Pdf_Element_Numeric($x1); |
|
123 $rectangle->items[] = new Zend_Pdf_Element_Numeric($y1); |
|
124 $rectangle->items[] = new Zend_Pdf_Element_Numeric($x2); |
|
125 $rectangle->items[] = new Zend_Pdf_Element_Numeric($y2); |
|
126 $annotationDictionary->Rect = $rectangle; |
|
127 |
|
128 $annotationDictionary->Contents = new Zend_Pdf_Element_String($text); |
|
129 |
|
130 if (!is_array($quadPoints) || count($quadPoints) == 0 || count($quadPoints) % 8 != 0) { |
|
131 require_once 'Zend/Pdf/Exception.php'; |
|
132 throw new Zend_Pdf_Exception('$quadPoints parameter must be an array of 8xN numbers'); |
|
133 } |
|
134 $points = new Zend_Pdf_Element_Array(); |
|
135 foreach ($quadPoints as $quadPoint) { |
|
136 $points->items[] = new Zend_Pdf_Element_Numeric($quadPoint); |
|
137 } |
|
138 $annotationDictionary->QuadPoints = $points; |
|
139 |
|
140 return new Zend_Pdf_Annotation_Markup($annotationDictionary); |
|
141 } |
|
142 } |