Example #1
0
 protected function getElementPosition($element)
 {
     // apply the transformation to the boundary to arrive at coordinates in InDesign Spread Space (idss)
     $idssCoordinates = IdmlBoundary::transform($element->boundary, $element->transformation);
     $page = $this->getPage($element);
     $pageIDSS = $page->idssCoordinates;
     $pageAdjustedBoundary = $idssCoordinates->applyOffset($pageIDSS->left, $pageIDSS->top);
     $pageAdjustedBoundary->roundToIntegers();
     $weight = $element->getComputedBorders();
     $position = array();
     $position['top'] = $pageAdjustedBoundary->top - $weight;
     $position['left'] = $pageAdjustedBoundary->left - $weight;
     return $position;
 }
Example #2
0
 /**
  * Parse the portion of a spread.xml file that contains a <Page>
  * 
  * @param DOMNode $domNode is a single <Page> node within the document
  */
 public function parse($domNode)
 {
     $attributes = $domNode->attributes;
     $this->UID = $attributes->getNamedItem('Self')->value;
     // like 'ud3'
     $this->appliedMasterUID = $attributes->getNamedItem('AppliedMaster')->value;
     // like 'ud3' or 'n'
     $this->inDesignPageName = $attributes->getNamedItem('Name')->value;
     // ordinary pages are numbers, master spreads are letters
     $itemTransform = $attributes->getNamedItem('ItemTransform')->value;
     // like "1 0 0 1 0 -396"
     $masterPageTransform = $attributes->getNamedItem('MasterPageTransform')->value;
     // like "1 0 0 1 0 0"
     $geometricBounds = $attributes->getNamedItem('GeometricBounds')->value;
     // like "0 0 792 612"
     $overrideList = $attributes->getNamedItem('OverrideList')->value;
     // like "ufb u174"
     $this->transformation = new IdmlTransformation($itemTransform);
     $this->masterPageTransform = new IdmlTransformation($masterPageTransform);
     $this->boundary = IdmlBoundary::createFromIDMLString($geometricBounds);
     $this->idssCoordinates = IdmlBoundary::transform($this->boundary, $this->transformation);
     if ($overrideList != '') {
         $this->masterSpreadOverrides = explode(' ', $overrideList);
     }
     $pageX = $this->transformation->xTranslate();
     if ($pageX < 0) {
         $this->pagePosition = 'left';
     } else {
         $this->pagePosition = 'right';
     }
     // Increment progress step.
     $p = IdmlAssembler::getProgressUpdater();
     if ($p) {
         $p->incrementStep();
     }
 }
Example #3
0
 /**
  * Since a spread contains one or two (or more) pages, we need a way to determine which spread objects are on
  * which page. Do this by passing in the center point of the object in question. Determine which page the point
  * falls on, and return that page. Note that a point may not fall on any page because it is on the
  * InDesign "artboard" -- these should be ignored. Also note that pages never overlap, so a point can never fall
  * on more than one page.
  * 
  * This algorithm does not look to see if the object is wholly on the page. This is intentional because it is quite
  * common for objects to be stretched a few pixels off the page by the designer. Also designers like to have bleeds
  * that fully go off the page. When an object is bled off like this the resulting CSS might have negative values for
  * top and left, or values for right and bottom that are larger than the page size. The resultant CSS should use
  * "overflow:hidden" for these cases.
  * 
  * @param float $xcenter is x value of the center point to test -- using this IdmlSpread's frame of reference.
  * @param float $xyenter is y value of the center point to test -- using this IdmlSpread's frame of reference.
  * 
  * @return IdmlPage|null The return may be an IdmlPage or may be null. The caller must test for this,
  * since both are valid.
  */
 public function determinePageFromCoordinates($coordinates)
 {
     foreach ($this->pages as $page) {
         $boundary = IdmlBoundary::transform($page->boundary, $page->transformation);
         if ($boundary->isPointInside($coordinates->getCenterX(), $coordinates->getCenterY()) == true) {
             return $page;
         }
     }
     return null;
     // not on either page, probably on the "artboard"
 }
Example #4
0
 /**
  * IdmlGroups do not have <PathGeometry> or <GeometricBounds> so their overall bounds must be determined
  * after reading all children by getting the outer bounds of all encompassed children.
  * The true bounds of the children must take into account their transformation: their true boundaries are
  * determined by call IdmlBoundary::transform.
  * Once the group's absolute boundary is computed from the children's boundaries, the group's own transformation
  * must be accounted for by subtracting the tx and ty from the boundary points.
  */
 public function determineBounds()
 {
     $boundary = null;
     foreach ($this->childrenElements as $child) {
         // If the child's boundary is not set, go to the next child.
         if (!isset($child->boundary)) {
             continue;
         }
         $childBoundary = IdmlBoundary::transform($child->boundary, $child->transformation);
         // For the first child's boundary, duplicate it
         if (is_null($boundary)) {
             $boundary = new IdmlBoundary($childBoundary->top, $childBoundary->left, $childBoundary->bottom, $childBoundary->right);
             continue;
         }
         // Add the child's dimensions to the group's boundary.
         if (get_class($child) == 'IdmlTextFrame') {
             // Add the height of the text frame, which stacks vertically.
             $boundary->bottom += $childBoundary->getHeight();
         } else {
             // Use that new boundary to expand the bounds of the group.
             $boundary->encompass($childBoundary);
         }
     }
     // Now subtract the group's tx and ty from the boundary points to determine its actual position.
     $top = $boundary->top - $this->transformation->yTranslate();
     $left = $boundary->left - $this->transformation->xTranslate();
     $bottom = $boundary->bottom - $this->transformation->yTranslate();
     $right = $boundary->right - $this->transformation->xTranslate();
     $this->boundary = new IdmlBoundary($top, $left, $bottom, $right);
 }
 /**
  * @param IdmlElement $element
  * @param IdmlPage $page
  * @return array - top and left position offsets for the element
  */
 protected function getElementPosition(IdmlElement $element, $page)
 {
     $idssCoordinates = IdmlBoundary::transform($element->boundary, $element->transformation);
     $pageIDSS = $page->idssCoordinates;
     $pageAdjustedBoundary = $idssCoordinates->applyOffset($pageIDSS->left, $pageIDSS->top);
     $pageAdjustedBoundary->roundToIntegers();
     $weight = $element->getComputedBorders();
     $top = $pageAdjustedBoundary->top - $weight;
     $left = $pageAdjustedBoundary->left - $weight;
     $element->setPosition(array('left' => $left, 'top' => $top));
     return $this->adjustOffsetsToRefPoint($element);
 }