File indexing completed on 2024-12-22 05:36:53
0001 <?php 0002 /** 0003 * Zend Framework 0004 * 0005 * LICENSE 0006 * 0007 * This source file is subject to the new BSD license that is bundled 0008 * with this package in the file LICENSE.txt. 0009 * It is also available through the world-wide-web at this URL: 0010 * http://framework.zend.com/license/new-bsd 0011 * If you did not receive a copy of the license and are unable to 0012 * obtain it through the world-wide-web, please send an email 0013 * to license@zend.com so we can send you a copy immediately. 0014 * 0015 * @category Zend 0016 * @package Zend_Pdf 0017 * @subpackage Annotation 0018 * @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com) 0019 * @license http://framework.zend.com/license/new-bsd New BSD License 0020 * @version $Id$ 0021 */ 0022 0023 /** Internally used classes */ 0024 // require_once 'Zend/Pdf/Element.php'; 0025 // require_once 'Zend/Pdf/Element/Array.php'; 0026 // require_once 'Zend/Pdf/Element/Dictionary.php'; 0027 // require_once 'Zend/Pdf/Element/Name.php'; 0028 // require_once 'Zend/Pdf/Element/Numeric.php'; 0029 // require_once 'Zend/Pdf/Element/String.php'; 0030 0031 0032 /** Zend_Pdf_Annotation */ 0033 // require_once 'Zend/Pdf/Annotation.php'; 0034 0035 /** 0036 * A markup annotation 0037 * 0038 * @package Zend_Pdf 0039 * @subpackage Annotation 0040 * @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com) 0041 * @license http://framework.zend.com/license/new-bsd New BSD License 0042 */ 0043 class Zend_Pdf_Annotation_Markup extends Zend_Pdf_Annotation 0044 { 0045 /** 0046 * Annotation subtypes 0047 */ 0048 const SUBTYPE_HIGHLIGHT = 'Highlight'; 0049 const SUBTYPE_UNDERLINE = 'Underline'; 0050 const SUBTYPE_SQUIGGLY = 'Squiggly'; 0051 const SUBTYPE_STRIKEOUT = 'StrikeOut'; 0052 0053 /** 0054 * Annotation object constructor 0055 * 0056 * @throws Zend_Pdf_Exception 0057 */ 0058 public function __construct(Zend_Pdf_Element $annotationDictionary) 0059 { 0060 if ($annotationDictionary->getType() != Zend_Pdf_Element::TYPE_DICTIONARY) { 0061 // require_once 'Zend/Pdf/Exception.php'; 0062 throw new Zend_Pdf_Exception('Annotation dictionary resource has to be a dictionary.'); 0063 } 0064 0065 if ($annotationDictionary->Subtype === null || 0066 $annotationDictionary->Subtype->getType() != Zend_Pdf_Element::TYPE_NAME || 0067 !in_array( $annotationDictionary->Subtype->value, 0068 array(self::SUBTYPE_HIGHLIGHT, 0069 self::SUBTYPE_UNDERLINE, 0070 self::SUBTYPE_SQUIGGLY, 0071 self::SUBTYPE_STRIKEOUT) )) { 0072 // require_once 'Zend/Pdf/Exception.php'; 0073 throw new Zend_Pdf_Exception('Subtype => Markup entry is omitted or has wrong value.'); 0074 } 0075 0076 parent::__construct($annotationDictionary); 0077 } 0078 0079 /** 0080 * Create markup annotation object 0081 * 0082 * Text markup annotations appear as highlights, underlines, strikeouts or 0083 * jagged ("squiggly") underlines in the text of a document. When opened, 0084 * they display a pop-up window containing the text of the associated note. 0085 * 0086 * $subType parameter may contain 0087 * Zend_Pdf_Annotation_Markup::SUBTYPE_HIGHLIGHT 0088 * Zend_Pdf_Annotation_Markup::SUBTYPE_UNDERLINE 0089 * Zend_Pdf_Annotation_Markup::SUBTYPE_SQUIGGLY 0090 * Zend_Pdf_Annotation_Markup::SUBTYPE_STRIKEOUT 0091 * for for a highlight, underline, squiggly-underline, or strikeout annotation, 0092 * respectively. 0093 * 0094 * $quadPoints is an array of 8xN numbers specifying the coordinates of 0095 * N quadrilaterals default user space. Each quadrilateral encompasses a word or 0096 * group of contiguous words in the text underlying the annotation. 0097 * The coordinates for each quadrilateral are given in the order 0098 * x1 y1 x2 y2 x3 y3 x4 y4 0099 * specifying the quadrilateral’s four vertices in counterclockwise order 0100 * starting from left bottom corner. 0101 * The text is oriented with respect to the edge connecting points 0102 * (x1, y1) and (x2, y2). 0103 * 0104 * @param float $x1 0105 * @param float $y1 0106 * @param float $x2 0107 * @param float $y2 0108 * @param string $text 0109 * @param string $subType 0110 * @param array $quadPoints [x1 y1 x2 y2 x3 y3 x4 y4] 0111 * @return Zend_Pdf_Annotation_Markup 0112 * @throws Zend_Pdf_Exception 0113 */ 0114 public static function create($x1, $y1, $x2, $y2, $text, $subType, $quadPoints) 0115 { 0116 $annotationDictionary = new Zend_Pdf_Element_Dictionary(); 0117 0118 $annotationDictionary->Type = new Zend_Pdf_Element_Name('Annot'); 0119 $annotationDictionary->Subtype = new Zend_Pdf_Element_Name($subType); 0120 0121 $rectangle = new Zend_Pdf_Element_Array(); 0122 $rectangle->items[] = new Zend_Pdf_Element_Numeric($x1); 0123 $rectangle->items[] = new Zend_Pdf_Element_Numeric($y1); 0124 $rectangle->items[] = new Zend_Pdf_Element_Numeric($x2); 0125 $rectangle->items[] = new Zend_Pdf_Element_Numeric($y2); 0126 $annotationDictionary->Rect = $rectangle; 0127 0128 $annotationDictionary->Contents = new Zend_Pdf_Element_String($text); 0129 0130 if (!is_array($quadPoints) || count($quadPoints) == 0 || count($quadPoints) % 8 != 0) { 0131 // require_once 'Zend/Pdf/Exception.php'; 0132 throw new Zend_Pdf_Exception('$quadPoints parameter must be an array of 8xN numbers'); 0133 } 0134 $points = new Zend_Pdf_Element_Array(); 0135 foreach ($quadPoints as $quadPoint) { 0136 $points->items[] = new Zend_Pdf_Element_Numeric($quadPoint); 0137 } 0138 $annotationDictionary->QuadPoints = $points; 0139 0140 return new Zend_Pdf_Annotation_Markup($annotationDictionary); 0141 } 0142 }