Exemplo n.º 1
0
 /**
  * Calculate elements position using parent and posref
  *
  * @param ElementInterface $elm
  */
 public function placeElement(ElementInterface $elm)
 {
     // element real bbox
     $bbox = $elm->getBbox();
     // element requested pos and size
     list($nodeX, $nodeY) = $elm->getPos();
     list($nodeW, $nodeH) = $elm->getSize();
     if ($nodeW === null) {
         $nodeW = $bbox[2];
     }
     if ($nodeH === null) {
         $nodeH = $bbox[3];
     }
     // final size (only image is resized,
     // text/polygon will not be clipped or resized)
     $elm->setSize($nodeW, $nodeH);
     $parent = $this->getParent($elm);
     if (!empty($parent)) {
         list($parentX, $parentY) = $parent->getPos();
         list($parentW, $parentH) = $parent->getSize();
     } else {
         // root element
         $parentX = 0;
         $parentY = 0;
         $parentW = $this->width;
         $parentH = $this->height;
     }
     // first is parent, second is node
     $posref = explode(' ', $elm->getPosref());
     if (empty($posref)) {
         $posref = array('TL', 'TL');
     } elseif (empty($posref[1])) {
         $posref[1] = 'TL';
     }
     // modify parent x/y so that x/y points to anchor
     list($offsetX, $offsetY) = $this->evalPosref($posref[0], $parentW, $parentH);
     $parentX += $offsetX;
     $parentY += $offsetY;
     // modify element x/y so that x/y points to anchor
     list($offsetX, $offsetY) = $this->evalPosref($posref[1], $nodeW, $nodeH);
     $x = $nodeX - $offsetX + $parentX;
     $y = $nodeY - $offsetY + $parentY;
     // final position
     $elm->setPos($x, $y);
 }
Exemplo n.º 2
0
 /**
  * {@inheritdoc}
  */
 public function add(ElementInterface $elm)
 {
     $id = $elm->getId();
     $this->elements[$id] = $elm;
 }