Example #1
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 #2
0
 /**
  * Parse children. We override this because the xml DOM hierarchy has rows, columns, and cells as children of table
  * we need to change the idml element hierarchy so tables are parents of rows which are parents of cells
  * @param DOMElement $parentNode
  */
 protected function parseChildren($parentNode)
 {
     foreach ($parentNode->childNodes as $childNode) {
         if (IdmlParserHelper::isParsableChildIdmlObjectNode($childNode)) {
             $parsableObject = IdmlElementFactory::createFromNode($childNode);
             if (is_object($parsableObject)) {
                 //set the parent first since sometimes parse requires or sets parent data
                 $parsableObject->parentElement = $this;
                 if (!IdmlParserHelper::isIdmlTagNode($childNode) && IdmlParserHelper::getIdmlObjectType($parsableObject) != "TableCell") {
                     $this->childrenElements[] = $parsableObject;
                     //don't set IdmlTable as parent for IdmlTableCell
                 }
                 $parsableObject->parse($childNode);
             }
         }
     }
 }
Example #3
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 #4
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);
 }
 public function visitTableCell(IdmlTableCell $element, $depth = 0)
 {
     $cssClassNames = array();
     $element->attribs['class'] = implode(' ', $cssClassNames);
     $strAttr = $this->getHTMLAttributesString($element, $element->attribs);
     $span = '';
     if ($element->rowspan == 0 || $element->rowspan > 1) {
         $span .= 'rowspan="' . $element->rowspan . '"';
         // rowspan of 0 tells the browser to span the cell to the last row
     }
     if ($element->colspan == 0 || $element->colspan > 1) {
         $span .= ' colspan="' . $element->colspan . '"';
         // colspan of 0 tells the browser to span the cell to the last column of the colgroup
     }
     $row = $element->parentIdmlObject();
     if (IdmlParserHelper::getIdmlObjectType($row) == "TableRow") {
         /*@var $row IdmlTableRow*/
         if ($row->rowType == 'thead') {
             $html = "<th {$span} {$strAttr}>";
             $element->idmlTag = 'th';
         } else {
             $html = "<td {$span} {$strAttr}>";
             $element->idmlTag = 'td';
         }
         $this->addPageElement($html, $depth);
     } else {
         CakeLog::debug("[IdmlProduceHtml::visitTableCell] parent element is not a TableRow ");
     }
 }
Example #6
0
 /**
  * this logic is needed in more than one location since the hierarchy is being navigated and used in several ways
  * at this point it only filters out XMLElements that are really just duplicate structures that sometimes get created
  * when Tags are applied in an Indesign document
  * @param IdmlElement $element
  * @return boolean
  */
 private function shouldProcessElement(IdmlElement $element)
 {
     $elementType = IdmlParserHelper::getIdmlObjectType($element);
     if ($elementType != 'XmlElement' || $elementType == 'XmlElement' && (!$element->xmlContent || $element->xmlContent == $this->currentStoryID)) {
         return true;
     } else {
         return false;
     }
 }