From a7a35c688dac969d08ea38b5fdc28ab932f8272d Mon Sep 17 00:00:00 2001 From: troosan Date: Sun, 5 Nov 2017 22:48:04 +0100 Subject: [PATCH] Allow reading of TargetMode for external images --- CHANGELOG.md | 2 ++ docs/styles.rst | 4 ++++ src/PhpWord/Reader/Word2007.php | 5 ++-- src/PhpWord/Reader/Word2007/AbstractPart.php | 24 +++++++++++++++++++- 4 files changed, 32 insertions(+), 3 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index ad046951..f21cb9d6 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -16,6 +16,7 @@ This is the last version to support PHP 5.3 - Possiblity to hide spelling and/or grammatical errors - @troosan #542 - Possiblity to set default document language as well as changing the language for each text element - @troosan #1108 - Support for Comments - @troosan #1067 +- Support for paragraph textAlignment - @troosan #1165 ### Fixed - Loosen dependency to Zend @@ -30,6 +31,7 @@ This is the last version to support PHP 5.3 - Added missing options for numbering format - @troosan #1041 - Fixed impossibility to set a different footer for first page - @ctrlaltca #1116 - Fixed styles not being applied by HTML writer, better pdf output - @sarke #1047 #500 #1139 +- Fixed read docx error when document contains image from remote url - @FBnil #1173 #1176 v0.13.0 (31 July 2016) ------------------- diff --git a/docs/styles.rst b/docs/styles.rst index e8d2aec8..4f4926a8 100644 --- a/docs/styles.rst +++ b/docs/styles.rst @@ -80,6 +80,10 @@ Available Paragraph style options: - ``tabs``. Set of custom tab stops. - ``widowControl``. Allow first/last line to display on a separate page, *true* or *false*. - ``contextualSpacing``. Ignore Spacing Above and Below When Using Identical Styles, *true* or *false*. +- ``bidi``. Right to Left Paragraph Layout, *true* or *false*. +- ``shading``. Paragraph Shading. +- ``textAlignment``. Vertical Character Alignment on Line. + See ``\PhpOffice\PhpWord\SimpleType\TextAlignment`` class for possible values. .. _table-style: diff --git a/src/PhpWord/Reader/Word2007.php b/src/PhpWord/Reader/Word2007.php index 9f9fce08..6c2178ad 100644 --- a/src/PhpWord/Reader/Word2007.php +++ b/src/PhpWord/Reader/Word2007.php @@ -147,6 +147,7 @@ class Word2007 extends AbstractReader implements ReaderInterface $rId = $xmlReader->getAttribute('Id', $node); $type = $xmlReader->getAttribute('Type', $node); $target = $xmlReader->getAttribute('Target', $node); + $mode = $xmlReader->getAttribute('TargetMode', $node); // Remove URL prefixes from $type to make it easier to read $type = str_replace($metaPrefix, '', $type); @@ -154,12 +155,12 @@ class Word2007 extends AbstractReader implements ReaderInterface $docPart = str_replace('.xml', '', $target); // Do not add prefix to link source - if (!in_array($type, array('hyperlink'))) { + if ($type != 'hyperlink' && $mode != 'External') { $target = $targetPrefix . $target; } // Push to return array - $rels[$rId] = array('type' => $type, 'target' => $target, 'docPart' => $docPart); + $rels[$rId] = array('type' => $type, 'target' => $target, 'docPart' => $docPart, 'targetMode' => $mode); } ksort($rels); diff --git a/src/PhpWord/Reader/Word2007/AbstractPart.php b/src/PhpWord/Reader/Word2007/AbstractPart.php index 21e12902..521c8a7f 100644 --- a/src/PhpWord/Reader/Word2007/AbstractPart.php +++ b/src/PhpWord/Reader/Word2007/AbstractPart.php @@ -210,7 +210,11 @@ abstract class AbstractPart $rId = $xmlReader->getAttribute('r:id', $domNode, 'w:pict/v:shape/v:imagedata'); $target = $this->getMediaTarget($docPart, $rId); if (!is_null($target)) { - $imageSource = "zip://{$this->docFile}#{$target}"; + if ('External' == $this->getTargetMode($docPart, $rId)) { + $imageSource = $target; + } else { + $imageSource = "zip://{$this->docFile}#{$target}"; + } $parent->addImage($imageSource); } } elseif ($xmlReader->elementExists('w:object', $domNode)) { @@ -500,4 +504,22 @@ abstract class AbstractPart return $target; } + + /** + * Returns the target mode + * + * @param string $docPart + * @param string $rId + * @return string|null + */ + private function getTargetMode($docPart, $rId) + { + $mode = null; + + if (isset($this->rels[$docPart]) && isset($this->rels[$docPart][$rId])) { + $mode = $this->rels[$docPart][$rId]['targetMode']; + } + + return $mode; + } }