Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
Link.php
Go to the documentation of this file.
1 <?php
24 #require_once 'Zend/Pdf/Element.php';
25 #require_once 'Zend/Pdf/Element/Array.php';
26 #require_once 'Zend/Pdf/Element/Dictionary.php';
27 #require_once 'Zend/Pdf/Element/Name.php';
28 #require_once 'Zend/Pdf/Element/Numeric.php';
29 
30 
32 #require_once 'Zend/Pdf/Annotation.php';
33 
47 {
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 
60  if ($annotationDictionary->Subtype === null ||
61  $annotationDictionary->Subtype->getType() != Zend_Pdf_Element::TYPE_NAME ||
62  $annotationDictionary->Subtype->value != 'Link') {
63  #require_once 'Zend/Pdf/Exception.php';
64  throw new Zend_Pdf_Exception('Subtype => Link entry is requires');
65  }
66 
67  parent::__construct($annotationDictionary);
68  }
69 
81  public static function create($x1, $y1, $x2, $y2, $target)
82  {
83  if (is_string($target)) {
84  #require_once 'Zend/Pdf/Destination/Named.php';
86  }
87  if (!$target instanceof Zend_Pdf_Target) {
88  #require_once 'Zend/Pdf/Exception.php';
89  throw new Zend_Pdf_Exception('$target parameter must be a Zend_Pdf_Target object or a string.');
90  }
91 
92  $annotationDictionary = new Zend_Pdf_Element_Dictionary();
93 
94  $annotationDictionary->Type = new Zend_Pdf_Element_Name('Annot');
95  $annotationDictionary->Subtype = new Zend_Pdf_Element_Name('Link');
96 
97  $rectangle = new Zend_Pdf_Element_Array();
98  $rectangle->items[] = new Zend_Pdf_Element_Numeric($x1);
99  $rectangle->items[] = new Zend_Pdf_Element_Numeric($y1);
100  $rectangle->items[] = new Zend_Pdf_Element_Numeric($x2);
101  $rectangle->items[] = new Zend_Pdf_Element_Numeric($y2);
102  $annotationDictionary->Rect = $rectangle;
103 
104  if ($target instanceof Zend_Pdf_Destination) {
105  $annotationDictionary->Dest = $target->getResource();
106  } else {
107  $annotationDictionary->A = $target->getResource();
108  }
109 
110  return new Zend_Pdf_Annotation_Link($annotationDictionary);
111  }
112 
119  public function setDestination($target)
120  {
121  if (is_string($target)) {
122  #require_once 'Zend/Pdf/Destination/Named.php';
124  }
125  if (!$target instanceof Zend_Pdf_Target) {
126  #require_once 'Zend/Pdf/Exception.php';
127  throw new Zend_Pdf_Exception('$target parameter must be a Zend_Pdf_Target object or a string.');
128  }
129 
130  $this->_annotationDictionary->touch();
131  $this->_annotationDictionary->Dest = $destination->getResource();
132  if ($target instanceof Zend_Pdf_Destination) {
133  $this->_annotationDictionary->Dest = $target->getResource();
134  $this->_annotationDictionary->A = null;
135  } else {
136  $this->_annotationDictionary->Dest = null;
137  $this->_annotationDictionary->A = $target->getResource();
138  }
139 
140  return $this;
141  }
142 
148  public function getDestination()
149  {
150  if ($this->_annotationDictionary->Dest === null &&
151  $this->_annotationDictionary->A === null) {
152  return null;
153  }
154 
155  if ($this->_annotationDictionary->Dest !== null) {
156  #require_once 'Zend/Pdf/Destination.php';
157  return Zend_Pdf_Destination::load($this->_annotationDictionary->Dest);
158  } else {
159  #require_once 'Zend/Pdf/Action.php';
160  return Zend_Pdf_Action::load($this->_annotationDictionary->A);
161  }
162  }
163 }
const TYPE_NAME
Definition: Element.php:35
$target
Definition: skip.phtml:8
const TYPE_DICTIONARY
Definition: Element.php:37
static create($name)
Definition: Named.php:76
static load(Zend_Pdf_Element $resource)
Definition: Destination.php:49
static load(Zend_Pdf_Element $dictionary, SplObjectStorage $processedActions=null)
Definition: Action.php:115