コード例 #1
0
 /**
  * Read Paragraph Item
  * @param RichText $oShape
  * @param \DOMElement $oNodeParent
  */
 protected function readParagraphItem(Paragraph $oParagraph, \DOMElement $oNodeParent)
 {
     if ($this->oXMLReader->elementExists('text:line-break', $oNodeParent)) {
         $oParagraph->createBreak();
     } else {
         $oTextRun = $oParagraph->createTextRun();
         if ($oNodeParent->hasAttribute('text:style-name')) {
             $keyStyle = $oNodeParent->getAttribute('text:style-name');
             if (isset($this->arrayStyles[$keyStyle])) {
                 $oTextRun->setFont($this->arrayStyles[$keyStyle]['font']);
             }
         }
         if ($oTextRunLink = $this->oXMLReader->getElement('text:a', $oNodeParent)) {
             $oTextRun->setText($oTextRunLink->nodeValue);
             if ($oTextRunLink->hasAttribute('xlink:href')) {
                 $oTextRun->getHyperlink()->setUrl($oTextRunLink->getAttribute('xlink:href'));
             }
         } else {
             $oTextRun->setText($oNodeParent->nodeValue);
         }
     }
 }
コード例 #2
0
 /**
  * Read style definition
  *
  * @param \PhpOffice\Common\XMLReader $xmlReader
  * @param \DOMElement $parentNode
  * @param array $styleDefs
  * @ignoreScrutinizerPatch
  * @return array
  */
 protected function readStyleDefs(XMLReader $xmlReader, \DOMElement $parentNode = null, $styleDefs = array())
 {
     $styles = array();
     foreach ($styleDefs as $styleProp => $styleVal) {
         @(list($method, $element, $attribute, $expected) = $styleVal);
         if ($xmlReader->elementExists($element, $parentNode)) {
             $node = $xmlReader->getElement($element, $parentNode);
             // Use w:val as default if no attribute assigned
             $attribute = $attribute === null ? 'w:val' : $attribute;
             $attributeValue = $xmlReader->getAttribute($attribute, $node);
             $styleValue = $this->readStyleDef($method, $attributeValue, $expected);
             if ($styleValue !== null) {
                 $styles[$styleProp] = $styleValue;
             }
         }
     }
     return $styles;
 }