diff --git a/src/PhpWord/Reader/Word2007/AbstractPart.php b/src/PhpWord/Reader/Word2007/AbstractPart.php index 9d49573d69..bd835f48cf 100644 --- a/src/PhpWord/Reader/Word2007/AbstractPart.php +++ b/src/PhpWord/Reader/Word2007/AbstractPart.php @@ -262,6 +262,32 @@ protected function readParagraph(XMLReader $xmlReader, DOMElement $domNode, $par } $parent->addPreserveText(htmlspecialchars($textContent, ENT_QUOTES, 'UTF-8'), $fontStyle, $paragraphStyle); + return; + } elseif ($xmlReader->elementExists('w:r/w:pict/v:shape/v:textbox', $domNode)) { + //textbox + $shapeStyle=null; + $styleVal = $xmlReader->getAttribute('style', $domNode, 'w:r/w:pict/v:shape'); + if ($styleVal!=null){ + $shapeStyle=[]; + foreach (explode(';', $styleVal) as $attribute){ + if (!empty($attribute)){ + [$attributeKey,$attributeVal] = explode(':',$attribute); + $attributeKey = str_replace('-', ' ', $attributeKey); + $attributeKey = ucwords($attributeKey); + $attributeKey = str_replace(' ', '', $attributeKey); + $attributeVal = preg_replace('/\s*pt\s*/', '', $attributeVal); + $shapeStyle[$attributeKey]=$attributeVal; + } + } + } + if (is_array($paragraphStyle) && count($paragraphStyle)>0){ + $shapeStyle = array_merge($shapeStyle, $paragraphStyle); + } + $textBox = $parent->addTextBox($shapeStyle); + $nodes = $xmlReader->getElements('w:r/w:pict/v:shape/v:textbox/w:txbxContent/*', $domNode); + foreach ($nodes as $node){ + $this->readParagraph($xmlReader,$node,$textBox,$docPart); + } return; } @@ -509,6 +535,21 @@ protected function readRunChild(XMLReader $xmlReader, DOMElement $node, Abstract $endnote = $parent->addEndnote(); $endnote->setRelationId($wId); } elseif ($node->nodeName == 'w:pict') { + $shapeStyle=null; + $styleVal = $xmlReader->getAttribute('style', $node, 'v:shape'); + if ($styleVal!=null){ + $shapeStyle=[]; + foreach (explode(';', $styleVal) as $attribute){ + if (!empty($attribute)){ + [$attributeKey,$attributeVal] = explode(':',$attribute); + $attributeKey = str_replace('-', ' ', $attributeKey); + $attributeKey = ucwords($attributeKey); + $attributeKey = str_replace(' ', '', $attributeKey); + $attributeVal = preg_replace('/\s*pt\s*/', '', $attributeVal); + $shapeStyle[$attributeKey]=$attributeVal; + } + } + } // Image $rId = $xmlReader->getAttribute('r:id', $node, 'v:shape/v:imagedata'); $target = $this->getMediaTarget($docPart, $rId); @@ -518,7 +559,7 @@ protected function readRunChild(XMLReader $xmlReader, DOMElement $node, Abstract } else { $imageSource = "zip://{$this->docFile}#{$target}"; } - $parent->addImage($imageSource); + $parent->addImage($imageSource,$shapeStyle); } } elseif ($node->nodeName == 'w:drawing') { // Office 2011 Image diff --git a/src/PhpWord/Writer/AbstractWriter.php b/src/PhpWord/Writer/AbstractWriter.php index 13859d8227..10eb565426 100644 --- a/src/PhpWord/Writer/AbstractWriter.php +++ b/src/PhpWord/Writer/AbstractWriter.php @@ -373,7 +373,7 @@ protected function addFileToPackage($zipPackage, $source, $target): void $zip = new ZipArchive(); if ($zip->open($zipFilename) !== false) { - if ($zip->locateName($imageFilename)) { + if ($zip->locateName($imageFilename) !== false) { $zip->extractTo($this->getTempDir(), $imageFilename); $actualSource = $this->getTempDir() . DIRECTORY_SEPARATOR . $imageFilename; }