Skip to content

Commit a7a35c6

Browse files
committed
Allow reading of TargetMode for external images
1 parent 200d846 commit a7a35c6

File tree

4 files changed

+32
-3
lines changed

4 files changed

+32
-3
lines changed

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ This is the last version to support PHP 5.3
1616
- Possiblity to hide spelling and/or grammatical errors - @troosan #542
1717
- Possiblity to set default document language as well as changing the language for each text element - @troosan #1108
1818
- Support for Comments - @troosan #1067
19+
- Support for paragraph textAlignment - @troosan #1165
1920

2021
### Fixed
2122
- Loosen dependency to Zend
@@ -30,6 +31,7 @@ This is the last version to support PHP 5.3
3031
- Added missing options for numbering format - @troosan #1041
3132
- Fixed impossibility to set a different footer for first page - @ctrlaltca #1116
3233
- Fixed styles not being applied by HTML writer, better pdf output - @sarke #1047 #500 #1139
34+
- Fixed read docx error when document contains image from remote url - @FBnil #1173 #1176
3335

3436
v0.13.0 (31 July 2016)
3537
-------------------

docs/styles.rst

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,10 @@ Available Paragraph style options:
8080
- ``tabs``. Set of custom tab stops.
8181
- ``widowControl``. Allow first/last line to display on a separate page, *true* or *false*.
8282
- ``contextualSpacing``. Ignore Spacing Above and Below When Using Identical Styles, *true* or *false*.
83+
- ``bidi``. Right to Left Paragraph Layout, *true* or *false*.
84+
- ``shading``. Paragraph Shading.
85+
- ``textAlignment``. Vertical Character Alignment on Line.
86+
See ``\PhpOffice\PhpWord\SimpleType\TextAlignment`` class for possible values.
8387

8488
.. _table-style:
8589

src/PhpWord/Reader/Word2007.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -147,19 +147,20 @@ private function getRels($docFile, $xmlFile, $targetPrefix = '')
147147
$rId = $xmlReader->getAttribute('Id', $node);
148148
$type = $xmlReader->getAttribute('Type', $node);
149149
$target = $xmlReader->getAttribute('Target', $node);
150+
$mode = $xmlReader->getAttribute('TargetMode', $node);
150151

151152
// Remove URL prefixes from $type to make it easier to read
152153
$type = str_replace($metaPrefix, '', $type);
153154
$type = str_replace($officePrefix, '', $type);
154155
$docPart = str_replace('.xml', '', $target);
155156

156157
// Do not add prefix to link source
157-
if (!in_array($type, array('hyperlink'))) {
158+
if ($type != 'hyperlink' && $mode != 'External') {
158159
$target = $targetPrefix . $target;
159160
}
160161

161162
// Push to return array
162-
$rels[$rId] = array('type' => $type, 'target' => $target, 'docPart' => $docPart);
163+
$rels[$rId] = array('type' => $type, 'target' => $target, 'docPart' => $docPart, 'targetMode' => $mode);
163164
}
164165
ksort($rels);
165166

src/PhpWord/Reader/Word2007/AbstractPart.php

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -210,7 +210,11 @@ protected function readRun(XMLReader $xmlReader, \DOMElement $domNode, $parent,
210210
$rId = $xmlReader->getAttribute('r:id', $domNode, 'w:pict/v:shape/v:imagedata');
211211
$target = $this->getMediaTarget($docPart, $rId);
212212
if (!is_null($target)) {
213-
$imageSource = "zip://{$this->docFile}#{$target}";
213+
if ('External' == $this->getTargetMode($docPart, $rId)) {
214+
$imageSource = $target;
215+
} else {
216+
$imageSource = "zip://{$this->docFile}#{$target}";
217+
}
214218
$parent->addImage($imageSource);
215219
}
216220
} elseif ($xmlReader->elementExists('w:object', $domNode)) {
@@ -500,4 +504,22 @@ private function getMediaTarget($docPart, $rId)
500504

501505
return $target;
502506
}
507+
508+
/**
509+
* Returns the target mode
510+
*
511+
* @param string $docPart
512+
* @param string $rId
513+
* @return string|null
514+
*/
515+
private function getTargetMode($docPart, $rId)
516+
{
517+
$mode = null;
518+
519+
if (isset($this->rels[$docPart]) && isset($this->rels[$docPart][$rId])) {
520+
$mode = $this->rels[$docPart][$rId]['targetMode'];
521+
}
522+
523+
return $mode;
524+
}
503525
}

0 commit comments

Comments
 (0)