/** * Constructor. * @param IdmlPage $page Could be null * @param IdmlStory $story Could be null if rectangle is not part of story. */ public function __construct(IdmlPage $page = null, IdmlStory $story = null) { parent::__construct(); $this->UID = ''; $this->page = $page; $this->story = $story; $this->transformation = new IdmlTransformation(); $this->boundary = IdmlBoundary::createDefault(); $this->visible = true; $this->frameFittingOption = new IdmlFrameFitting(0, 0, 0, 0); }
/** * Constructor. */ public function __construct() { parent::__construct(); $this->UID = ''; $this->parentStoryUID = ''; $this->contentType = ''; $this->visible = true; $this->story = null; $this->transformation = new IdmlTransformation(); $this->boundary = IdmlBoundary::createDefault(); $this->properties = array(); }
/** * Constructor. * * @param IdmlResourceManager $resourceManager Default is null or if you want to inject the object you can pass the param. */ public function __construct(IdmlResourceManager $resourceManager = null) { if (is_null($resourceManager)) { $this->resourceManager = IdmlAssembler::getInstance()->resourceManager; } else { $this->resourceManager = $resourceManager; } $this->boundary = IdmlBoundary::createDefault(); $this->height = null; $this->width = null; $this->ppiX = null; $this->ppiY = null; $this->idmlTag = "img"; }
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; }
/** * Constructor. * @param IdmlPage $page Could be null * @param IdmlStory $story Could be null if rectangle is not part of story. */ public function __construct(IdmlPage $page = null, IdmlStory $story = null) { parent::__construct(); $this->tag = ''; $this->controls = true; $this->loop = false; $this->mediaFilename = ''; $this->autoplay = false; $this->UID = ''; $this->page = $page; $this->story = $story; $this->transformation = new IdmlTransformation(); $this->boundary = IdmlBoundary::createDefault(); $this->visible = true; }
/** * Parse boundary. * @param DOMNode $element * @return IdmlBoundary */ public static function parseBoundary(DOMNode $element) { $points = array(); $xpath = new DOMXPath($element->ownerDocument); // Get four <PathPointType> tags which define the objects corners (or more than four, // for complex polygons, which we treat as rectangles anyway) $corners = $xpath->query('Properties/PathGeometry/GeometryPathType/PathPointArray//PathPointType', $element); foreach ($corners as $corner) { $attributes = $corner->attributes; $anchor = $attributes->getNamedItem('Anchor')->value; $parts = explode(' ', $anchor); assert(count($parts) == 2); $points[] = array('x' => (double) $parts[0], 'y' => (double) $parts[1]); } return IdmlBoundary::createFromCornerPoints($points); }
/** * 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(); } }
/** * 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" }
/** * Returns the height of the offset attribute for a rotated element. * Using this height, we'll construct a div before and after the rotated element * @param IdmlElement $element * @return string */ public static function getOffsetHeight(IdmlElement $element) { $containingBoundary = new IdmlBoundary($element->boundary->top, $element->boundary->left, $element->boundary->bottom, $element->boundary->right); $containingBoundary->rotate($element->transformation->getB()); $elementHeight = $element->boundary->getHeight(); $containerHeight = $containingBoundary->getHeight(); $offsetHeight = ($containerHeight - $elementHeight) / 2; if ($offsetHeight < 0) { $offsetHeight = 0; } return $offsetHeight; }
/** * 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); }