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

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