2
0

Text.php 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  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-2009 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. /** Zend_Pdf_Annotation */
  23. require_once 'Zend/Pdf/Annotation.php';
  24. /**
  25. * A text annotation represents a "sticky note" attached to a point in the PDF document.
  26. *
  27. * @package Zend_Pdf
  28. * @subpackage Annotation
  29. * @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com)
  30. * @license http://framework.zend.com/license/new-bsd New BSD License
  31. */
  32. class Zend_Pdf_Annotation_Text extends Zend_Pdf_Annotation
  33. {
  34. /**
  35. * Annotation object constructor
  36. *
  37. * @throws Zend_Pdf_Exception
  38. */
  39. public function __construct(Zend_Pdf_Element $annotationDictionary)
  40. {
  41. if ($annotationDictionary->getType() != Zend_Pdf_Element::TYPE_DICTIONARY) {
  42. require_once 'Zend/Pdf/Exception.php';
  43. throw new Zend_Pdf_Exception('Annotation dictionary resource has to be a dictionary.');
  44. }
  45. if ($annotationDictionary->Subtype === null ||
  46. $annotationDictionary->Subtype->getType() != Zend_Pdf_Element::TYPE_NAME ||
  47. $annotationDictionary->Subtype->value != 'Text') {
  48. require_once 'Zend/Pdf/Exception.php';
  49. throw new Zend_Pdf_Exception('Subtype => Text entry is requires');
  50. }
  51. parent::__construct($annotationDictionary);
  52. }
  53. /**
  54. * Create link annotation object
  55. *
  56. * @param float $x1
  57. * @param float $y1
  58. * @param float $x2
  59. * @param float $y2
  60. * @param string $text
  61. * @return Zend_Pdf_Annotation_Text
  62. */
  63. public static function create($x1, $y1, $x2, $y2, $text)
  64. {
  65. $annotationDictionary = new Zend_Pdf_Element_Dictionary();
  66. $annotationDictionary->Type = new Zend_Pdf_Element_Name('Annot');
  67. $annotationDictionary->Subtype = new Zend_Pdf_Element_Name('Text');
  68. $rectangle = new Zend_Pdf_Element_Array();
  69. $rectangle->items[] = new Zend_Pdf_Element_Numeric($x1);
  70. $rectangle->items[] = new Zend_Pdf_Element_Numeric($y1);
  71. $rectangle->items[] = new Zend_Pdf_Element_Numeric($x2);
  72. $rectangle->items[] = new Zend_Pdf_Element_Numeric($y2);
  73. $annotationDictionary->Rect = $rectangle;
  74. $annotationDictionary->Contents = new Zend_Pdf_Element_String($text);
  75. return new Zend_Pdf_Annotation_Text($annotationDictionary);
  76. }
  77. }