Exemplo n.º 1
0
 /**
  * Get all styles of each elements in container recursively
  *
  * Table style can be null or string of the style name
  *
  * @param \PhpOffice\PhpWord\Element\AbstractContainer $container
  * @param int &$paragraphStyleCount
  * @param int &$fontStyleCount
  * @return void
  * @todo Simplify the logic
  */
 private function getContainerStyle($container, &$paragraphStyleCount, &$fontStyleCount)
 {
     $elements = $container->getElements();
     foreach ($elements as $element) {
         if ($element instanceof TextRun) {
             $this->getContainerStyle($element, $paragraphStyleCount, $fontStyleCount);
         } elseif ($element instanceof Text) {
             $this->getElementStyle($element, $paragraphStyleCount, $fontStyleCount);
         } elseif ($element instanceof Image) {
             $style = $element->getStyle();
             $style->setStyleName('fr' . $element->getMediaIndex());
             $this->autoStyles['Image'][] = $style;
         } elseif ($element instanceof Table) {
             $style = $element->getStyle();
             if ($style === null) {
                 $style = new TableStyle();
             } elseif (is_string($style)) {
                 $style = Style::getStyle($style);
             }
             $style->setStyleName($element->getElementId());
             $this->autoStyles['Table'][] = $style;
         }
     }
 }
Exemplo n.º 2
0
 /**
  * Parse list item node
  *
  * @param \DOMNode $node
  * @param \PhpOffice\PhpWord\Element\AbstractContainer $element
  * @param array &$styles
  * @param array $data
  * @return null
  *
  * @todo This function is almost the same like `parseChildNodes`. Merged?
  * @todo As soon as ListItem inherits from AbstractContainer or TextRun delete parsing part of childNodes
  */
 private static function parseListItem($node, $element, &$styles, $data)
 {
     $cNodes = $node->childNodes;
     if (count($cNodes) > 0) {
         $text = '';
         foreach ($cNodes as $cNode) {
             if ($cNode->nodeName == '#text') {
                 $text = $cNode->nodeValue;
             }
         }
         $element->addListItem($text, $data['listdepth'], $styles['font'], $styles['list'], $styles['paragraph']);
     }
     return null;
 }
Exemplo n.º 3
0
 /**
  * Parse list item node
  *
  * @param \DOMNode $node
  * @param \PhpOffice\PhpWord\Element\AbstractContainer $element
  * @param array $styles
  * @param mixed $data
  * @param mixed $argument1
  * @param mixed $argument2
  * @param \DOMNode $parentNode
  * @return \PhpOffice\PhpWord\Element\AbstractContainer
  *
  * @todo This function is almost the same like `parseChildNodes`. Merged?
  * @todo As soon as ListItem inherits from AbstractContainer or TextRun delete parsing part of childNodes
  */
 private static function parseListItem($node, $element, $styles, $data, $argument1, $argument2, $parentNode)
 {
     $styles = self::parseInlineStyle($node, $styles, $parentNode);
     $cNodes = $node->childNodes;
     if ($cNodes->length > 0) {
         $text = '';
         foreach ($cNodes as $cNode) {
             if ($cNode->nodeName == '#text') {
                 $text = $cNode->nodeValue;
             }
         }
         $element->addListItem($text, $data['listdepth'], $styles, $styles, $styles);
     }
     return null;
 }