Allow reading of TargetMode for external images

This commit is contained in:
troosan 2017-11-05 22:48:04 +01:00
parent 200d846f61
commit a7a35c688d
4 changed files with 32 additions and 3 deletions

View File

@ -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 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 - 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 Comments - @troosan #1067
- Support for paragraph textAlignment - @troosan #1165
### Fixed ### Fixed
- Loosen dependency to Zend - 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 - Added missing options for numbering format - @troosan #1041
- Fixed impossibility to set a different footer for first page - @ctrlaltca #1116 - 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 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) v0.13.0 (31 July 2016)
------------------- -------------------

View File

@ -80,6 +80,10 @@ Available Paragraph style options:
- ``tabs``. Set of custom tab stops. - ``tabs``. Set of custom tab stops.
- ``widowControl``. Allow first/last line to display on a separate page, *true* or *false*. - ``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*. - ``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: .. _table-style:

View File

@ -147,6 +147,7 @@ class Word2007 extends AbstractReader implements ReaderInterface
$rId = $xmlReader->getAttribute('Id', $node); $rId = $xmlReader->getAttribute('Id', $node);
$type = $xmlReader->getAttribute('Type', $node); $type = $xmlReader->getAttribute('Type', $node);
$target = $xmlReader->getAttribute('Target', $node); $target = $xmlReader->getAttribute('Target', $node);
$mode = $xmlReader->getAttribute('TargetMode', $node);
// Remove URL prefixes from $type to make it easier to read // Remove URL prefixes from $type to make it easier to read
$type = str_replace($metaPrefix, '', $type); $type = str_replace($metaPrefix, '', $type);
@ -154,12 +155,12 @@ class Word2007 extends AbstractReader implements ReaderInterface
$docPart = str_replace('.xml', '', $target); $docPart = str_replace('.xml', '', $target);
// Do not add prefix to link source // Do not add prefix to link source
if (!in_array($type, array('hyperlink'))) { if ($type != 'hyperlink' && $mode != 'External') {
$target = $targetPrefix . $target; $target = $targetPrefix . $target;
} }
// Push to return array // 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); ksort($rels);

View File

@ -210,7 +210,11 @@ abstract class AbstractPart
$rId = $xmlReader->getAttribute('r:id', $domNode, 'w:pict/v:shape/v:imagedata'); $rId = $xmlReader->getAttribute('r:id', $domNode, 'w:pict/v:shape/v:imagedata');
$target = $this->getMediaTarget($docPart, $rId); $target = $this->getMediaTarget($docPart, $rId);
if (!is_null($target)) { 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); $parent->addImage($imageSource);
} }
} elseif ($xmlReader->elementExists('w:object', $domNode)) { } elseif ($xmlReader->elementExists('w:object', $domNode)) {
@ -500,4 +504,22 @@ abstract class AbstractPart
return $target; 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;
}
} }