Example #1
0
 /**
  * Programming note: some properties set in parsing may not necessarily be of use at this time
  * @param DOMElement $node
  */
 public function parse(DOMElement $node)
 {
     parent::parse($node);
     $this->UID = $node->hasAttribute(IdmlAttributes::Self) ? $node->getAttribute(IdmlAttributes::Self) : null;
     $this->setTransform($node);
     $this->vertices = $this->parseVertices($node);
     if (count($this->vertices) < 2) {
         $this->visible = false;
         $this->boundary = new IdmlBoundary(0, 0, 0, 0);
         return;
     }
     $this->boundary = $this->setBoundary($this->vertices);
     $this->inline = get_class($this->parentElement) == 'IdmlCharacterRange' ? true : false;
     $visible = $node->hasAttribute(IdmlAttributes::Visible) ? $node->getAttribute(IdmlAttributes::Visible) : 'true';
     $this->visible = strtolower($visible) == 'true' ? true : false;
     $ffiList = $node->getElementsByTagName('FrameFittingOption');
     if ($ffiList->length > 0) {
         $ffiNode = $ffiList->item(0);
         $topCrop = $ffiNode->hasAttribute(IdmlAttributes::TopCrop) ? $ffiNode->getAttribute(IdmlAttributes::TopCrop) : 0;
         $leftCrop = $ffiNode->hasAttribute(IdmlAttributes::LeftCrop) ? $ffiNode->getAttribute(IdmlAttributes::LeftCrop) : 0;
         $bottomCrop = $ffiNode->hasAttribute(IdmlAttributes::BottomCrop) ? $ffiNode->getAttribute(IdmlAttributes::BottomCrop) : 0;
         $rightCrop = $ffiNode->hasAttribute(IdmlAttributes::RightCrop) ? $ffiNode->getAttribute(IdmlAttributes::RightCrop) : 0;
         $this->frameFittingOption = new IdmlFrameFitting($topCrop, $leftCrop, $bottomCrop, $rightCrop);
     }
     $this->parseChildren($node);
 }
Example #2
0
 /**
  * Constructor.
  * @param string $content
  * @param IdmlContent $parent
  */
 public function __construct($content, IdmlContent $parent)
 {
     parent::__construct();
     $this->content = $content;
     $this->parentElement = $parent;
     $parent->childrenElements[] = $this;
     $this->usesNestedClass = true;
 }
Example #3
0
 public function parse(DOMElement $node)
 {
     parent::parse($node);
     $this->headerRowCount = $node->hasAttribute('HeaderRowCount') ? intval($node->getAttribute('HeaderRowCount')) : 0;
     $this->footerRowCount = $node->hasAttribute('FooterRowCount') ? intval($node->getAttribute('FooterRowCount')) : 0;
     $this->bodyRowCount = $node->hasAttribute('BodyRowCount') ? intval($node->getAttribute('BodyRowCount')) : 0;
     $this->columnCount = $node->hasAttribute('ColumnCount') ? intval($node->getAttribute('ColumnCount')) : 0;
     $this->parseChildren($node);
 }
 /**
  * Parse from DOM node.
  *
  * @param DOMElement $node
  */
 public function parse(DOMElement $node)
 {
     parent::parse($node);
     $hyperlinkMgr = IdmlHyperlinkManager::getInstance();
     // Set the id attribute value
     $destinationKey = $this->contextualStyle->idmlKeyValues['DestinationUniqueKey'];
     $this->id = 'Hyperlink_' . $destinationKey;
     // Save this destination in the hyperlink manager.
     // After parsing the page completes, its id must be stored for all the hyperlink destinations on the page.
     $hyperlinkMgr->saveDestinationForPageData($this->id);
 }
Example #5
0
 /**
  * Parse from DOM node.
  *
  * @param DOMElement $node
  */
 public function parse(DOMElement $node)
 {
     parent::parse($node);
     $this->markupTag = $node->hasAttribute('MarkupTag') ? $node->getAttribute('MarkupTag') : '';
     $this->idAttribute = $node->hasAttribute(IdmlAttributes::Self) ? $node->getAttribute(IdmlAttributes::Self) : null;
     $this->xmlContent = $node->hasAttribute(IdmlAttributes::XmlContent) ? $node->getAttribute(IdmlAttributes::XmlContent) : null;
     //don't parse children of this tag if they are marked to be hidden from Chaucer (CHAUC-2866)
     if ($this->markupTag != 'XMLTag/ChaucerHidden') {
         $this->parseChildren($node);
         $this->parseAttributes($node);
     }
 }
Example #6
0
 /**
  * Parse from DOM node.
  * @param DOMElement $node
  */
 public function parse(DOMElement $node)
 {
     parent::parse($node);
     //        $this->styleInfo['inlineStyle']->translateSingleColumnWidth(); //set Css width for column
     /*
             if($this->hasIdmlProperty('SingleColumnWidth'))
             {
                 $val = $this->getIdmlProperty('SingleColumnWidth');
                 if(is_numeric($val))
                 {
                     $val = round($val);
                     $this->addCssProperty('width', $val . 'pt');
                 }
             }
     */
     /*
             //add needed column info to parent table because IdmlHtmlProducer needs this at the IdmlTable element level
             if($this->styleInfo["inlineStyle"]->hasCssProperty('width'))
             {
                 $table = $this->parentIdmlObject();
                 if(IdmlParserHelper::getIdmlObjectType($table) == "Table")
                 {
                     $table->cols[] = $this;
                     $colwidth = $this->styleInfo["inlineStyle"]->getCssPropertyString('width');
                     if($colwidth) {
                         $table->colGroupStyles[] = $colwidth;
                     }
                 }
             }
             else
             {
                 CakeLog::debug("[IdmlTableColumn::parse] column width not found? ".__FILE__." Line ".__LINE__);
             }
     */
     if ($node->hasAttribute('SingleColumnWidth')) {
         $singleColumnWidth = round($node->getAttribute('SingleColumnWidth'));
         $table = $this->parentIdmlObject();
         if (IdmlParserHelper::getIdmlObjectType($table) == "Table") {
             $table->cols[] = $this;
             $colwidth = 'width:' . $singleColumnWidth . 'pt;';
             $table->colGroupStyles[] = $colwidth;
         }
     } else {
         CakeLog::debug("[IdmlTableColumn::parse] column width not found? " . __FILE__ . " Line " . __LINE__);
     }
     //IdmlTableColumn has no children to parse
 }
Example #7
0
 /**
  * Constructor.
  */
 public function __construct(IdmlContent $contentNode, $tabIndex)
 {
     parent::__construct();
     $this->parentElement = $contentNode;
     $contentNode->childrenElements[] = $this;
     $this->paragraph = $this->getParagraph();
     $this->usesNestedClass = true;
     /* *** Hack alert!!! ***
      * In some cases, tabs need to be managed by a complex hierarchy of spans dictating position, alignment, and styling.
      * In other cases, that strategy generates HTML that doesn't position the content correctly.
      * The strategy implemented here is that if the containing paragraph has a line indent property,
      *   tabs are treated as simple content and are replaced with the html special character "&#09;".
      * If there is no line indent property, we use the complex span strategy.
      * This is based on an admittedly incomplete understanding of how InDesign works, and is subject to reevaluation.
      */
     $this->usesSpans = $this->paragraphUsesLeftIndent($this->paragraph);
     if (!$this->usesSpans) {
         return;
     }
     $this->paragraph->tabCount++;
     $tabData = $this->getTabLists();
     $this->tabData = $tabData[$tabIndex];
     $this->position = $tabData[$tabIndex]['Position'];
     $this->alignment = $tabData[$tabIndex]['Alignment'];
     $this->index = $tabIndex;
     // Save prior tab's position for determining the width of the current tab span
     if ($tabIndex > 0) {
         $this->lastPosition = $tabData[$tabIndex - 1]['Position'];
         $this->lastAlignment = $tabData[$tabIndex - 1]['Alignment'];
     } else {
         $this->lastPosition = 0;
         $this->lastAlignment = null;
         $this->paragraph->firstTabPosition = $tabData[$tabIndex]['Position'];
         $this->paragraph->firstTabAlignment = $tabData[$tabIndex]['Alignment'];
     }
     // Save next tab's position for determining width of the next tab span
     if (count($tabData) > $tabIndex + 1) {
         $this->nextPosition = $tabData[$tabIndex + 1]['Position'];
         $this->nextAlignment = $tabData[$tabIndex + 1]['Alignment'];
     } else {
         $this->nextPosition = null;
         $this->nextAlignment = null;
     }
 }
Example #8
0
 /**
  * Parse from DOM node.
  * 
  * @param DOMElement $node
  */
 public function parse(DOMElement $node)
 {
     parent::parse($node);
     $link = IdmlAssembler::getInstance()->getCurrentPackage()->getHyperlinkBySource($node->getAttribute("Self"));
     $this->idAttribute = $node->hasAttribute(IdmlAttributes::Self) ? $node->getAttribute(IdmlAttributes::Self) : null;
     $this->name = $node->hasAttribute(IdmlAttributes::Name) ? $node->getAttribute(IdmlAttributes::Name) : null;
     if (count($link) > 0) {
         if (is_array($link['Destination'])) {
             $this->linkType = $link['Destination']['DestinationType'];
             if (array_key_exists('DestinationURL', $link['Destination'])) {
                 $this->href = $link['Destination']['DestinationURL'];
             }
         } else {
             $this->href = $link['Destination'];
         }
         if (!strlen($this->idmlTag)) {
             $this->idmlTag = 'a';
         }
     }
     $this->parseChildren($node);
 }
Example #9
0
 public function parse(DOMElement $node)
 {
     parent::parse($node);
     //parse and set row attributes that are based upon parent table
     $rownum = $node->hasAttribute('Name') ? intval($node->getAttribute('Name')) : 0;
     $table = $this->parentIdmlObject();
     if (IdmlParserHelper::getIdmlObjectType($table) == "Table") {
         //set this row in the table rows array by index
         $table->rows[$rownum] = $this;
         //from Indesign the order of rows is header, body, footer
         //we must set what type of row this is and whether it is first and/or last in its group
         if ($table->headerRowCount && $rownum < $table->headerRowCount) {
             $this->rowType = 'thead';
             $rowGroupStart = 0;
             $rowGroupEnd = $table->headerRowCount - 1;
         } elseif ($table->bodyRowCount && $rownum < $table->headerRowCount + $table->bodyRowCount) {
             $this->rowType = 'tbody';
             $rowGroupStart = $table->headerRowCount;
             $rowGroupEnd = $table->headerRowCount + $table->bodyRowCount - 1;
         } elseif ($table->footerRowCount && $rownum < $table->headerRowCount + $table->bodyRowCount + $table->footerRowCount) {
             $this->rowType = 'tfoot';
             $rowGroupStart = $table->headerRowCount + $table->bodyRowCount;
             $rowGroupEnd = $table->headerRowCount + $table->bodyRowCount + $table->footerRowCount - 1;
         } else {
             //this is a problem as we can't place the row?
             CakeLog::debug("[IdmlTableRow::parse] unable to identify tablerow type and place in group " . __FILE__ . " Line " . __LINE__);
         }
         if ($rownum == $rowGroupStart) {
             $this->isFirstRow = true;
         }
         if ($rownum == $rowGroupEnd) {
             $this->isLastRow = true;
         }
     } else {
         //something is wrong so log this?
         CakeLog::debug("[IdmlTableRow::parse] parent is not an IdmlTable?" . __FILE__ . " Line " . __LINE__);
     }
     //TableRow has no children to parse
 }
Example #10
0
 public function parse(DOMElement $node)
 {
     parent::parse($node);
     //we must set the <col style='width:...' /> for this column in the table
     $this->rowspan = $node->hasAttribute('RowSpan') ? intval($node->getAttribute('RowSpan')) : -1;
     $this->colspan = $node->hasAttribute('ColumnSpan') ? intval($node->getAttribute('ColumnSpan')) : -1;
     // Right now the parent is a table element, but we need the parent to be the corresponding row for this cell.
     // Find the right row in the table array and assign it as this cell's parent ImdlElement.
     $colrow = $node->hasAttribute('Name') ? $node->getAttribute('Name') : '0:0';
     $colrowArray = explode(":", $colrow);
     // <col>:<row>
     $this->colnumber = intval($colrowArray[0]);
     $this->rownumber = intval($colrowArray[1]);
     $row = $this->parentElement->rows[$this->rownumber];
     if (IdmlParserHelper::getIdmlObjectType($row) == "TableRow") {
         /*@var $row IdmlTableRow*/
         $row->childrenElements[] = $this;
         $this->parentElement = $row;
         //assign this cell as child of the table row
     } else {
         CakeLog::debug("[IdmlTableCell::parse] cannot find parent row in table for cell? " . __FILE__ . " Line " . __LINE__);
     }
     $this->parseChildren($node);
 }
 /**
  * The getDimensionCSS function should return a CSS declaration for the element's width and height.
  */
 public function getDimensionCSS(IdmlElement $element)
 {
     $weight = $element->getComputedBorders();
     $twice_weight = $weight * 2;
     switch (get_class($element)) {
         case 'IdmlTextFrame':
             if ($element->isEmbedded()) {
                 return sprintf("width:%spx; height:%spx;", round($twice_weight + $element->boundary->getWidth()), round($twice_weight + $element->boundary->getHeight()));
             } else {
                 return '';
             }
         case 'IdmlRectangle':
             // If a rectangle's sole child is a video or audio, don't set the dimensions, since IDML does not account for controls.
             // Otherwise, fall through to the default behavior.
             if (count($element->childrenElements) == 1 && in_array(get_class($element->childrenElements[0]), array('IdmlMovie', 'IdmlSound'))) {
                 return '';
             }
         case 'IdmlGroup':
             return sprintf("width:%spx; height:%spx;", round($twice_weight + $element->boundary->getWidth()), round($twice_weight + $element->boundary->getHeight()));
         default:
             return '';
     }
 }
Example #12
0
 /**
  * Parse from DOM node.
  *
  * @param DOMElement $node
  */
 public function parse(DOMElement $node)
 {
     parent::parse($node);
     $this->UID = $node->hasAttribute(IdmlAttributes::Self) ? $node->getAttribute(IdmlAttributes::Self) : null;
     $this->setTransform($node);
     $visible = $node->hasAttribute(IdmlAttributes::Visible) ? $node->getAttribute(IdmlAttributes::Visible) : 'true';
     $this->visible = strtolower($visible) == 'true' ? true : false;
     $this->boundary = IdmlParserHelper::parseBoundary($node);
     $ffiList = $node->getElementsByTagName('FrameFittingOption');
     if ($ffiList->length > 0) {
         $ffiNode = $ffiList->item(0);
         $topCrop = $ffiNode->hasAttribute(IdmlAttributes::TopCrop) ? $ffiNode->getAttribute(IdmlAttributes::TopCrop) : 0;
         $leftCrop = $ffiNode->hasAttribute(IdmlAttributes::LeftCrop) ? $ffiNode->getAttribute(IdmlAttributes::LeftCrop) : 0;
         $bottomCrop = $ffiNode->hasAttribute(IdmlAttributes::BottomCrop) ? $ffiNode->getAttribute(IdmlAttributes::BottomCrop) : 0;
         $rightCrop = $ffiNode->hasAttribute(IdmlAttributes::RightCrop) ? $ffiNode->getAttribute(IdmlAttributes::RightCrop) : 0;
         $this->frameFittingOption = new IdmlFrameFitting($topCrop, $leftCrop, $bottomCrop, $rightCrop);
     }
     $this->parseChildren($node);
 }
Example #13
0
 /**
  * Parse from DOM node.
  *
  * @param DOMElement $node
  */
 public function parse(DOMElement $node)
 {
     parent::parse($node);
     $this->setAttributes($node);
 }
Example #14
0
 /**
  * Constructor.
  * @param IdmlStory $story
  */
 public function __construct(IdmlStory $story = null)
 {
     parent::__construct();
     $this->story = $story;
 }
Example #15
0
 /**
  * Parse children.
  * @param DOMElement $parentNode
  */
 protected function parseChildren($parentNode)
 {
     foreach ($parentNode->childNodes as $childNode) {
         if ($childNode->nodeType == XML_ELEMENT_NODE && $childNode->nodeName == 'Properties') {
             $this->parseProperties($childNode);
         }
     }
     parent::parseChildren($parentNode);
 }
Example #16
0
 /**
  * Walk the IDML tree back to the IdmlPage, getting all ancestral objects
  * @param IdmlElement $idmlObject
  * @param string $stopAt The classname of the highest Idml object that we are interested in, should be 'IdmlPage' or 'IdmlStory'
  * @return array[IdmlElement] 
  */
 public function getAncestors($idmlObject, $stopAt)
 {
     $stack = array();
     // start by skipping the current element
     $obj = $idmlObject->parentIdmlObject();
     // now collect all ancestors: parent, grandparent, ... back to (but not including) the IdmlPage/IdmlStory
     while (!is_null($obj) && get_class($obj) != $stopAt) {
         $stack[] = $obj;
         $obj = $obj->parentIdmlObject();
     }
     return $stack;
 }
 /**
  * Utility function to create an array of position styles and convert to a string.
  * @param IdmlElement $element
  * @param float $left
  * @param float $top
  * @param string $vertRefPoint - used only for embedded elements
  * @return string representation of styles
  */
 public function getStyleString(IdmlElement $element, $left, $top, $vertRefPoint)
 {
     // Create and populate the array with position, left, and top
     $styles = array('position' => 'absolute');
     // Assign final left and top offset values
     if (!is_null($left)) {
         $styles['left'] = $left . 'px';
     }
     // Don't supply a top value for an embedded element if the VerticalReferencePoint is unsupported.
     if (!$element->isEmbedded() || !is_null($top) && !in_array($vertRefPoint, array('LineBaseline', 'Capheight', 'TopOfLeading'))) {
         $styles['top'] = $top . 'px';
     }
     // Now convert the array to a string and return it.
     $styleString = "";
     foreach ($styles as $name => $value) {
         if (strlen($value) > 0) {
             $styleString .= sprintf("%s:%s;", $name, $value);
         }
     }
     return trim($styleString);
 }
Example #18
0
 /**
  * Parse function.
  * @param DOMElement $node
  */
 public function parse(DOMElement $node)
 {
     parent::parse($node);
     $this->changeType = $node->hasAttribute(IdmlAttributes::ChangeType) ? $node->getAttribute(IdmlAttributes::ChangeType) : 'undefined';
     $this->parseChildren($node);
 }
Example #19
0
 /**
  * Parse from DOM node.
  * 
  * @param DOMElement $node
  */
 public function parse(DOMElement $node)
 {
     parent::parse($node);
     $justification = $node->hasAttribute(IdmlAttributes::Justification) ? $node->getAttribute(IdmlAttributes::Justification) : 'left';
     if (isset($this->story->page)) {
         $pagePosition = $this->story->page->pagePosition;
     } else {
         $pagePosition = 'left';
     }
     $this->textAlign = IdmlParserHelper::convertJustification($justification, $pagePosition);
     // Change the TabList property cluster into an array for easier handling
     IdmlDeclarationParser::arrayifyDupes($this->contextualStyle->idmlContextualElement, $this->contextualStyle);
     // Check for nested styles; if any exist, set up the helper class object
     $this->parseNestedStyle();
     $this->parseChildren($node);
 }
Example #20
0
 public function clearParentElementWithHash(IdmlElement $element, $parentHashValue)
 {
     $bCleared = false;
     $parentElement = $element->parentIdmlObject();
     while (!$bCleared && is_object($parentElement)) {
         if (IdmlPxeHelper::getPxeHash($parentElement) == $parentHashValue) {
             IdmlPxeHelper::clearPxeData($parentElement);
             $bCleared = true;
         }
         $parentElement = $parentElement->parentIdmlObject();
     }
     return $bCleared;
 }
 /**
  * @param DOMElement $node
  */
 public function parse(DOMElement $node)
 {
     parent::parse($node);
     $this->content = $node->hasAttribute('ResultText') ? $node->getAttribute('ResultText') : '';
 }
Example #22
0
 /**
  * Parse function.
  * @param DOMElement $node
  */
 public function parse(DOMElement $node)
 {
     parent::parse($node);
     $this->UID = $node->hasAttribute(IdmlAttributes::Self) ? $node->getAttribute(IdmlAttributes::Self) : null;
     $this->setTransform($node);
     $visible = $node->hasAttribute(IdmlAttributes::Visible) ? $node->getAttribute(IdmlAttributes::Visible) : 'true';
     $this->visible = strtolower($visible) == 'true' ? true : false;
     $this->parseChildren($node);
     // Groups can be nested within groups, so this needs to be determined now, after any inner groups have
     // had _their_ bounds determined.
     $this->determineBounds();
 }
Example #23
0
 /**
  * Parse the portion of a spread.xml file that contains a <TextFrame>
  *
  * @param DOMElement $node is a single <TextFrame> node within the IDML document
  */
 public function parse(DOMElement $node)
 {
     parent::parse($node);
     $attributes = $node->attributes;
     $this->UID = $attributes->getNamedItem('Self')->value;
     // like 'uf9'
     $this->parentStoryUID = $attributes->getNamedItem('ParentStory')->value;
     // like 'ue5'
     $this->contentType = $attributes->getNamedItem('ContentType')->value;
     // like 'TextType'
     $this->visible = $attributes->getNamedItem('Visible')->value == 'false' ? false : true;
     // like 'true'
     $this->setTransform($node);
     $this->boundary = IdmlParserHelper::parseBoundary($node);
     $this->prevTextFrame = $attributes->getNamedItem(IdmlAttributes::PreviousTextFrame)->value == 'n' ? null : $attributes->getNamedItem(IdmlAttributes::PreviousTextFrame)->value;
     $this->nextTextFrame = $attributes->getNamedItem(IdmlAttributes::NextTextFrame)->value == 'n' ? null : $attributes->getNamedItem(IdmlAttributes::NextTextFrame)->value;
     $this->textColumnCount = isset($this->contextualStyle->idmlKeyValues['TextFramePreference->TextColumnCount']) ? (int) $this->contextualStyle->idmlKeyValues['TextFramePreference->TextColumnCount'] : null;
     $this->columnWidth = isset($this->contextualStyle->idmlKeyValues['TextFramePreference->TextColumnFixedWidth']) ? $this->contextualStyle->idmlKeyValues['TextFramePreference->TextColumnFixedWidth'] : null;
     // If we *do_not_have* a previous text frame then it is either a single text frame or the first of a series of
     // linked ones. In case of linked ones we output only the first one.
     if (!$this->prevTextFrame) {
         $this->loadParentStory();
     } else {
         if (IdmlAssembler::getInstance()->isFixedLayout()) {
             CakeLog::debug("[IdmlTextFrame::parse] Encountered an InDesign threaded frame in a fixed layout book (story {$this->parentStoryUID}). Run Chaucer FixedLayoutPreflight.jsx script within InDesign and re-export the IDML.");
         }
     }
 }
Example #24
0
 /**
  * Determines if an element has an XmlElement as a parent somewhere
  * @param IdmlElement $element
  * @return boolean
  */
 public static function hasXmlElementParent(IdmlElement $element)
 {
     $hasParent = false;
     if ($element->parentIdmlObject()) {
         $parent = $element->parentIdmlObject();
         while (is_object($parent) && !is_a($parent, "IdmlXmlElement")) {
             $parent = $parent->parentIdmlObject();
         }
         if (is_object($parent) && is_a($parent, "IdmlXmlElement") && $parent->markupTag != "XMLTag/Story") {
             $hasParent = true;
         }
     }
     return $hasParent;
 }