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