Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
Loaded.php
Go to the documentation of this file.
1 <?php
25 #require_once 'Zend/Pdf/Element.php';
26 #require_once 'Zend/Pdf/Element/Array.php';
27 #require_once 'Zend/Pdf/Element/Numeric.php';
28 #require_once 'Zend/Pdf/Element/String.php';
29 
30 
32 #require_once 'Zend/Pdf/Outline.php';
33 
46 {
53 
59  protected $_originalChildOutlines = array();
60 
67  public function getTitle()
68  {
69  if ($this->_outlineDictionary->Title === null) {
70  #require_once 'Zend/Pdf/Exception.php';
71  throw new Zend_Pdf_Exception('Outline dictionary Title entry is required.');
72  }
73  return $this->_outlineDictionary->Title->value;
74  }
75 
82  public function setTitle($title)
83  {
84  $this->_outlineDictionary->Title->touch();
85  $this->_outlineDictionary->Title = new Zend_Pdf_Element_String($title);
86  return $this;
87  }
88 
95  public function setIsOpen($isOpen)
96  {
97  parent::setIsOpen($isOpen);
98 
99  if ($this->_outlineDictionary->Count === null) {
100  // Do Nothing.
101  return this;
102  }
103 
104  $childrenCount = $this->_outlineDictionary->Count->value;
105  $isOpenCurrentState = ($childrenCount > 0);
106  if ($isOpen != $isOpenCurrentState) {
107  $this->_outlineDictionary->Count->touch();
108  $this->_outlineDictionary->Count->value = ($isOpen? 1 : -1)*abs($childrenCount);
109  }
110 
111  return $this;
112  }
113 
119  public function isItalic()
120  {
121  if ($this->_outlineDictionary->F === null) {
122  return false;
123  }
124  return $this->_outlineDictionary->F->value & 1;
125  }
126 
133  public function setIsItalic($isItalic)
134  {
135  if ($this->_outlineDictionary->F === null) {
136  $this->_outlineDictionary->touch();
137  $this->_outlineDictionary->F = new Zend_Pdf_Element_Numeric($isItalic? 1 : 0);
138  } else {
139  $this->_outlineDictionary->F->touch();
140  if ($isItalic) {
141  $this->_outlineDictionary->F->value = $this->_outlineDictionary->F->value | 1;
142  } else {
143  $this->_outlineDictionary->F->value = $this->_outlineDictionary->F->value | ~1;
144  }
145  }
146  return $this;
147  }
148 
154  public function isBold()
155  {
156  if ($this->_outlineDictionary->F === null) {
157  return false;
158  }
159  return $this->_outlineDictionary->F->value & 2;
160  }
161 
168  public function setIsBold($isBold)
169  {
170  if ($this->_outlineDictionary->F === null) {
171  $this->_outlineDictionary->touch();
172  $this->_outlineDictionary->F = new Zend_Pdf_Element_Numeric($isBold? 2 : 0);
173  } else {
174  $this->_outlineDictionary->F->touch();
175  if ($isBold) {
176  $this->_outlineDictionary->F->value = $this->_outlineDictionary->F->value | 2;
177  } else {
178  $this->_outlineDictionary->F->value = $this->_outlineDictionary->F->value | ~2;
179  }
180  }
181  return $this;
182  }
183 
184 
190  public function getColor()
191  {
192  if ($this->_outlineDictionary->C === null) {
193  return null;
194  }
195 
196  $components = $this->_outlineDictionary->C->items;
197 
198  #require_once 'Zend/Pdf/Color/Rgb.php';
199  return new Zend_Pdf_Color_Rgb($components[0], $components[1], $components[2]);
200  }
201 
209  public function setColor(Zend_Pdf_Color_Rgb $color)
210  {
211  $this->_outlineDictionary->touch();
212 
213  if ($color === null) {
214  $this->_outlineDictionary->C = null;
215  } else {
216  $components = $color->getComponents();
217  $colorComponentElements = array(new Zend_Pdf_Element_Numeric($components[0]),
218  new Zend_Pdf_Element_Numeric($components[1]),
219  new Zend_Pdf_Element_Numeric($components[2]));
220  $this->_outlineDictionary->C = new Zend_Pdf_Element_Array($colorComponentElements);
221  }
222 
223  return $this;
224  }
225 
232  public function getTarget()
233  {
234  if ($this->_outlineDictionary->Dest !== null) {
235  if ($this->_outlineDictionary->A !== null) {
236  #require_once 'Zend/Pdf/Exception.php';
237  throw new Zend_Pdf_Exception('Outline dictionary may contain Dest or A entry, but not both.');
238  }
239 
240  #require_once 'Zend/Pdf/Destination.php';
241  return Zend_Pdf_Destination::load($this->_outlineDictionary->Dest);
242  } else if ($this->_outlineDictionary->A !== null) {
243  #require_once 'Zend/Pdf/Action.php';
244  return Zend_Pdf_Action::load($this->_outlineDictionary->A);
245  }
246 
247  return null;
248  }
249 
258  public function setTarget($target = null)
259  {
260  $this->_outlineDictionary->touch();
261 
262  if (is_string($target)) {
263  #require_once 'Zend/Pdf/Destination/Named.php';
265  }
266 
267  if ($target === null) {
268  $this->_outlineDictionary->Dest = null;
269  $this->_outlineDictionary->A = null;
270  } else if ($target instanceof Zend_Pdf_Destination) {
271  $this->_outlineDictionary->Dest = $target->getResource();
272  $this->_outlineDictionary->A = null;
273  } else if ($target instanceof Zend_Pdf_Action) {
274  $this->_outlineDictionary->Dest = null;
275  $this->_outlineDictionary->A = $target->getResource();
276  } else {
277  #require_once 'Zend/Pdf/Exception.php';
278  throw new Zend_Pdf_Exception('Outline target has to be Zend_Pdf_Destination or Zend_Pdf_Action object or string');
279  }
280 
281  return $this;
282  }
283 
291  public function setOptions(array $options)
292  {
293  parent::setOptions($options);
294 
295  return $this;
296  }
297 
298 
299 
311  public function __construct(Zend_Pdf_Element $dictionary, SplObjectStorage $processedDictionaries = null)
312  {
313  if ($dictionary->getType() != Zend_Pdf_Element::TYPE_DICTIONARY) {
314  #require_once 'Zend/Pdf/Exception.php';
315  throw new Zend_Pdf_Exception('$dictionary mast be an indirect dictionary object.');
316  }
317 
318  if ($processedDictionaries === null) {
319  $processedDictionaries = new SplObjectStorage();
320  }
321  $processedDictionaries->attach($dictionary);
322 
323  $this->_outlineDictionary = $dictionary;
324 
325  if ($dictionary->Count !== null) {
326  if ($dictionary->Count->getType() != Zend_Pdf_Element::TYPE_NUMERIC) {
327  #require_once 'Zend/Pdf/Exception.php';
328  throw new Zend_Pdf_Exception('Outline dictionary Count entry must be a numeric element.');
329  }
330 
331  $childOutlinesCount = $dictionary->Count->value;
332  if ($childOutlinesCount > 0) {
333  $this->_open = true;
334  }
335  $childOutlinesCount = abs($childOutlinesCount);
336 
337  $childDictionary = $dictionary->First;
338 
339  $children = new SplObjectStorage();
340  while ($childDictionary !== null) {
341  // Check children structure for cyclic references
342  if ($children->contains($childDictionary)) {
343  #require_once 'Zend/Pdf/Exception.php';
344  throw new Zend_Pdf_Exception('Outline childs load error.');
345  }
346 
347  if (!$processedDictionaries->contains($childDictionary)) {
348  $this->childOutlines[] = new Zend_Pdf_Outline_Loaded($childDictionary, $processedDictionaries);
349  }
350 
351  $childDictionary = $childDictionary->Next;
352  }
353 
354  $this->_originalChildOutlines = $this->childOutlines;
355  }
356  }
357 
373  $updateNavigation,
374  Zend_Pdf_Element $parent,
375  Zend_Pdf_Element $prev = null,
376  SplObjectStorage $processedOutlines = null)
377  {
378  if ($processedOutlines === null) {
379  $processedOutlines = new SplObjectStorage();
380  }
381  $processedOutlines->attach($this);
382 
383  if ($updateNavigation) {
384  $this->_outlineDictionary->touch();
385 
386  $this->_outlineDictionary->Parent = $parent;
387  $this->_outlineDictionary->Prev = $prev;
388  $this->_outlineDictionary->Next = null;
389  }
390 
391  $updateChildNavigation = false;
392  if (count($this->_originalChildOutlines) != count($this->childOutlines)) {
393  // If original and current children arrays have different size then children list was updated
394  $updateChildNavigation = true;
395  } else if ( !(array_keys($this->_originalChildOutlines) === array_keys($this->childOutlines)) ) {
396  // If original and current children arrays have different keys (with a glance to an order) then children list was updated
397  $updateChildNavigation = true;
398  } else {
399  foreach ($this->childOutlines as $key => $childOutline) {
400  if ($this->_originalChildOutlines[$key] !== $childOutline) {
401  $updateChildNavigation = true;
402  break;
403  }
404  }
405  }
406 
407  $lastChild = null;
408  if ($updateChildNavigation) {
409  $this->_outlineDictionary->touch();
410  $this->_outlineDictionary->First = null;
411 
412  foreach ($this->childOutlines as $childOutline) {
413  if ($processedOutlines->contains($childOutline)) {
414  #require_once 'Zend/Pdf/Exception.php';
415  throw new Zend_Pdf_Exception('Outlines cyclyc reference is detected.');
416  }
417 
418  if ($lastChild === null) {
419  // First pass. Update Outlines dictionary First entry using corresponding value
420  $lastChild = $childOutline->dumpOutline($factory, $updateChildNavigation, $this->_outlineDictionary, null, $processedOutlines);
421  $this->_outlineDictionary->First = $lastChild;
422  } else {
423  // Update previous outline dictionary Next entry (Prev is updated within dumpOutline() method)
424  $childOutlineDictionary = $childOutline->dumpOutline($factory, $updateChildNavigation, $this->_outlineDictionary, $lastChild, $processedOutlines);
425  $lastChild->Next = $childOutlineDictionary;
426  $lastChild = $childOutlineDictionary;
427  }
428  }
429 
430  $this->_outlineDictionary->Last = $lastChild;
431 
432  if (count($this->childOutlines) != 0) {
433  $this->_outlineDictionary->Count = new Zend_Pdf_Element_Numeric(($this->isOpen()? 1 : -1)*count($this->childOutlines));
434  } else {
435  $this->_outlineDictionary->Count = null;
436  }
437  } else {
438  foreach ($this->childOutlines as $childOutline) {
439  if ($processedOutlines->contains($childOutline)) {
440  #require_once 'Zend/Pdf/Exception.php';
441  throw new Zend_Pdf_Exception('Outlines cyclyc reference is detected.');
442  }
443  $lastChild = $childOutline->dumpOutline($factory, $updateChildNavigation, $this->_outlineDictionary, $lastChild, $processedOutlines);
444  }
445  }
446 
448  }
449 
450  public function dump($level = 0)
451  {
452  printf(":%3d:%s:%s:%s%s :\n", count($this->childOutlines),$this->isItalic()? 'i':' ', $this->isBold()? 'b':' ', str_pad('', 4*$level), $this->getTitle());
453 
454  if ($this->isOpen() || true) {
455  foreach ($this->childOutlines as $child) {
456  $child->dump($level + 1);
457  }
458  }
459  }
460 }
$title
Definition: default.phtml:14
const TYPE_NUMERIC
Definition: Element.php:33
$target
Definition: skip.phtml:8
const TYPE_DICTIONARY
Definition: Element.php:37
setOptions(array $options)
Definition: Loaded.php:291
__construct(Zend_Pdf_Element $dictionary, SplObjectStorage $processedDictionaries=null)
Definition: Loaded.php:311
setColor(Zend_Pdf_Color_Rgb $color)
Definition: Loaded.php:209
dumpOutline(Zend_Pdf_ElementFactory_Interface $factory, $updateNavigation, Zend_Pdf_Element $parent, Zend_Pdf_Element $prev=null, SplObjectStorage $processedOutlines=null)
Definition: Loaded.php:372
setTarget($target=null)
Definition: Loaded.php:258
static create($name)
Definition: Named.php:76
$children
Definition: actions.phtml:11
setIsItalic($isItalic)
Definition: Loaded.php:133
static load(Zend_Pdf_Element $resource)
Definition: Destination.php:49
static load(Zend_Pdf_Element $dictionary, SplObjectStorage $processedActions=null)
Definition: Action.php:115