You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

142 lines
5.4 KiB

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