Skip to content

Commit 566e625

Browse files
committed
merge/add test/cleanup
1 parent 9b722a5 commit 566e625

File tree

8 files changed

+73
-200
lines changed

8 files changed

+73
-200
lines changed

composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@
6161
"php": "^5.3.3 || ^7.0",
6262
"ext-xml": "*",
6363
"zendframework/zend-escaper": "^2.2",
64-
"phpoffice/common": "^0.2"
64+
"phpoffice/common": "dev-develop"
6565
},
6666
"require-dev": {
6767
"phpunit/phpunit": "^4.8.36 || ^5.0",

src/PhpWord/Element/AbstractContainer.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@
3535
* @method TOC addTOC(mixed $fontStyle = null, mixed $tocStyle = null, int $minDepth = 1, int $maxDepth = 9)
3636
* @method PageBreak addPageBreak()
3737
* @method Table addTable(mixed $style = null)
38-
* @method Image addImage(string $source, mixed $style = null, bool $isWatermark = false)
38+
* @method Image addImage(string $source, mixed $style = null, bool $isWatermark = false, $name = null)
3939
* @method OLEObject addOLEObject(string $source, mixed $style = null)
4040
* @method TextBox addTextBox(mixed $style = null)
4141
* @method Field addField(string $type = null, array $properties = array(), array $options = array(), mixed $text = null)

src/PhpWord/Element/Image.php

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -134,16 +134,17 @@ class Image extends AbstractElement
134134
* @param string $source
135135
* @param mixed $style
136136
* @param bool $watermark
137+
* @param string $name
137138
*
138139
* @throws \PhpOffice\PhpWord\Exception\InvalidImageException
139140
* @throws \PhpOffice\PhpWord\Exception\UnsupportedImageTypeException
140141
*/
141142
public function __construct($source, $style = null, $watermark = false, $name = null)
142143
{
143144
$this->source = $source;
144-
$this->setIsWatermark($watermark);
145145
$this->style = $this->setNewStyle(new ImageStyle(), $style, true);
146-
$this->name = $name;
146+
$this->setIsWatermark($watermark);
147+
$this->setName($name);
147148

148149
$this->checkImage();
149150
}
@@ -178,6 +179,16 @@ public function getSourceType()
178179
return $this->sourceType;
179180
}
180181

182+
/**
183+
* Sets the image name
184+
*
185+
* @param string $value
186+
*/
187+
public function setName($value)
188+
{
189+
$this->name = $value;
190+
}
191+
181192
/**
182193
* Get image name
183194
*

src/PhpWord/Reader/Word2007/AbstractPart.php

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -261,7 +261,12 @@ protected function readRunChild(XMLReader $xmlReader, \DOMElement $node, Abstrac
261261
$parent->addImage($imageSource);
262262
}
263263
} elseif ($node->nodeName == 'w:drawing') {
264-
// Office 2011 Images
264+
// Office 2011 Image
265+
$xmlReader->registerNamespace('wp', 'http://schemas.openxmlformats.org/drawingml/2006/wordprocessingDrawing');
266+
$xmlReader->registerNamespace('r', 'http://schemas.openxmlformats.org/officeDocument/2006/relationships');
267+
$xmlReader->registerNamespace('pic', 'http://schemas.openxmlformats.org/drawingml/2006/picture');
268+
$xmlReader->registerNamespace('a', 'http://schemas.openxmlformats.org/drawingml/2006/main');
269+
265270
$name = $xmlReader->getAttribute('name', $node, 'wp:inline/a:graphic/a:graphicData/pic:pic/pic:nvPicPr/pic:cNvPr');
266271
$embedId = $xmlReader->getAttribute('r:embed', $node, 'wp:inline/a:graphic/a:graphicData/pic:pic/pic:blipFill/a:blip');
267272
$target = $this->getMediaTarget($docPart, $embedId);
@@ -573,6 +578,8 @@ private function findPossibleAttribute(XMLReader $xmlReader, \DOMElement $node,
573578
return $possibleAttribute;
574579
}
575580
}
581+
582+
return null;
576583
}
577584

578585
return $attributes;

src/PhpWord/Shared/XMLReader.php

Lines changed: 0 additions & 195 deletions
This file was deleted.

tests/PhpWord/Reader/Word2007/ElementTest.php

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -236,4 +236,40 @@ public function testReadTitleStyle()
236236
$this->assertEquals('Title', $formattedTitle->getStyle());
237237
$this->assertInstanceOf('PhpOffice\PhpWord\Element\TextRun', $formattedTitle->getText());
238238
}
239+
240+
/**
241+
* Test reading Drawing
242+
*/
243+
public function testReadDrawing()
244+
{
245+
$documentXml = '<w:p>
246+
<w:r>
247+
<w:drawing xmlns:wp="http://schemas.openxmlformats.org/drawingml/2006/wordprocessingDrawing">
248+
<wp:inline distT="0" distB="0" distL="0" distR="0">
249+
<wp:extent cx="5727700" cy="6621145"/>
250+
<wp:docPr id="1" name="Picture 1"/>
251+
<a:graphic xmlns:a="http://schemas.openxmlformats.org/drawingml/2006/main">
252+
<a:graphicData uri="http://schemas.openxmlformats.org/drawingml/2006/picture">
253+
<pic:pic xmlns:pic="http://schemas.openxmlformats.org/drawingml/2006/picture">
254+
<pic:nvPicPr>
255+
<pic:cNvPr id="1" name="file_name.jpg"/>
256+
<pic:cNvPicPr/>
257+
</pic:nvPicPr>
258+
<pic:blipFill>
259+
<a:blip r:embed="rId4" xmlns:r="http://schemas.openxmlformats.org/officeDocument/2006/relationships">
260+
</a:blip>
261+
</pic:blipFill>
262+
</pic:pic>
263+
</a:graphicData>
264+
</a:graphic>
265+
</wp:inline>
266+
</w:drawing>
267+
</w:r>
268+
</w:p>';
269+
270+
$phpWord = $this->getDocumentFromString(array('document' => $documentXml));
271+
272+
$elements = $phpWord->getSection(0)->getElements();
273+
$this->assertInstanceOf('PhpOffice\PhpWord\Element\TextRun', $elements[0]);
274+
}
239275
}

tests/PhpWord/Reader/Word2007Test.php

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,4 +64,18 @@ public function testLoad()
6464
$doc = TestHelperDOCX::getDocument($phpWord);
6565
$this->assertFalse($doc->elementExists('/w:document/w:body/w:p/w:r[w:t/node()="italics"]/w:rPr/w:b'));
6666
}
67+
68+
/**
69+
* Load a Word 2011 file
70+
*/
71+
public function testLoadWord2011()
72+
{
73+
$filename = __DIR__ . '/../_files/documents/reader-2011.docx';
74+
$phpWord = IOFactory::load($filename);
75+
76+
$this->assertInstanceOf('PhpOffice\\PhpWord\\PhpWord', $phpWord);
77+
78+
$doc = TestHelperDOCX::getDocument($phpWord);
79+
$this->assertTrue($doc->elementExists('/w:document/w:body/w:p[3]/w:r/w:pict/v:shape/v:imagedata'));
80+
}
6781
}
36.1 KB
Binary file not shown.

0 commit comments

Comments
 (0)