/** * 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); }
/** * Sets the transform data, both local and cumulative, for the element * @param DOMElement $node */ public function setTransform(DOMElement $node) { $transformation = $node->hasAttribute(IdmlAttributes::ItemTransform) ? $node->getAttribute(IdmlAttributes::ItemTransform) : ''; $this->transformation = new IdmlTransformation($transformation); // If the parent element contains a transformation, accumulate the tx and ty values if (is_a($this->parentElement, 'IdmlElement') && isset($this->parentElement->transformation)) { // get the parent's cumulative transform values $cumTx = $this->transformation->xTranslate() + $this->parentElement->transformation->xTranslate(); $cumTy = $this->transformation->yTranslate() + $this->parentElement->transformation->yTranslate(); $this->transformation->setXY($cumTx, $cumTy); } }
/** * 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(); } }
/** * The transform function applies the transformation matrix to this object and returns a new coordinates object. * * @param IdmlBoundary $boundary * @param IdmlTransformation $matrix * * @return IdmlBoundary a new object */ public static function transform(IdmlBoundary $boundary, IdmlTransformation $matrix) { $a = $matrix->getA(); $b = $matrix->getB(); $c = $matrix->getC(); $d = $matrix->getD(); $tx = $matrix->xTranslate(); $ty = $matrix->yTranslate(); $left = $boundary->left; $top = $boundary->top; $right = $boundary->right; $bottom = $boundary->bottom; // Transform (x1,y1) $left2 = $left * $a + $top * $c + $tx; $top2 = $left * $b + $top * $d + $ty; // Transform (x2,y2) $right2 = $right * $a + $bottom * $c + $tx; $bottom2 = $right * $b + $bottom * $d + $ty; return new IdmlBoundary($top2, $left2, $bottom2, $right2); }