Skip to content

Commit

Permalink
Merge pull request #146 from Progi1984/develop
Browse files Browse the repository at this point in the history
Fix bug in ODP Reader
  • Loading branch information
Progi1984 committed Nov 15, 2015
2 parents aeab64a + edbebec commit cc6d377
Show file tree
Hide file tree
Showing 7 changed files with 51 additions and 17 deletions.
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,12 @@
# Changelog
## 0.6.0 - WIP

### Bugfix
- ODPresentation : Exclude SVM files for reader - @Progi1984 GH-141

### Changes
- PhpOffice\PhpPowerpoint\Style\Alignment::setLevel can now be defined great than 8 - @Progi1984 GH-141

### Features
- ODPresentation Reader/Writer : Name of the slide - @Progi1984 GH-121
- PowerPoint2007 Reader/Writer : Mark as final - @Progi1984 GH-118
Expand Down
2 changes: 1 addition & 1 deletion src/PhpPresentation/AbstractShape.php
Original file line number Diff line number Diff line change
Expand Up @@ -404,7 +404,7 @@ public function setHyperlink(Hyperlink $pHyperlink = null)
*/
public function getHashCode()
{
return md5((is_object($this->container)?$this->container->getHashCode():'') . $this->offsetX . $this->offsetY . $this->width . $this->height . $this->rotation . $this->getFill()->getHashCode() . $this->shadow->getHashCode() . (is_null($this->hyperlink) ? '' : $this->hyperlink->getHashCode()) . __CLASS__);
return md5((is_object($this->container)?$this->container->getHashCode():'') . $this->offsetX . $this->offsetY . $this->width . $this->height . $this->rotation . $this->getFill()->getHashCode() . (is_null($this->shadow) ? '' : $this->shadow->getHashCode()) . (is_null($this->hyperlink) ? '' : $this->hyperlink->getHashCode()) . __CLASS__);
}

/**
Expand Down
16 changes: 13 additions & 3 deletions src/PhpPresentation/Reader/ODPresentation.php
Original file line number Diff line number Diff line change
Expand Up @@ -330,7 +330,12 @@ protected function loadShapeDrawing(\DOMElement $oNodeFrame)
$oNodeImage = $this->oXMLReader->getElement('draw:image', $oNodeFrame);
if ($oNodeImage) {
if ($oNodeImage->hasAttribute('xlink:href')) {
$imageFile = $this->oZip->getFromName($oNodeImage->getAttribute('xlink:href'));
$sFilename = $oNodeImage->getAttribute('xlink:href');
// svm = StarView Metafile
if (pathinfo($sFilename, PATHINFO_EXTENSION) == 'svm') {
return;
}
$imageFile = $this->oZip->getFromName($sFilename);
if (!empty($imageFile)) {
$oShape->setImageResource(imagecreatefromstring($imageFile));
}
Expand Down Expand Up @@ -396,8 +401,13 @@ protected function loadShapeRichText(\DOMElement $oNodeFrame)
protected function readParagraph(RichText $oShape, \DOMElement $oNodeParent)
{
$oParagraph = $oShape->createParagraph();
foreach ($this->oXMLReader->getElements('text:span', $oNodeParent) as $oNodeRichTextElement) {
$this->readParagraphItem($oParagraph, $oNodeRichTextElement);
$oDomList = $this->oXMLReader->getElements('text:span', $oNodeParent);
if ($oDomList->length == 0) {
$this->readParagraphItem($oParagraph, $oNodeParent);
} else {
foreach ($oDomList as $oNodeRichTextElement) {
$this->readParagraphItem($oParagraph, $oNodeRichTextElement);
}
}
}

Expand Down
4 changes: 2 additions & 2 deletions src/PhpPresentation/Style/Alignment.php
Original file line number Diff line number Diff line change
Expand Up @@ -173,8 +173,8 @@ public function getLevel()
*/
public function setLevel($pValue = 0)
{
if ($pValue < 0 || $pValue > 8) {
throw new \Exception("Invalid value: shoul be range 0 - 8.");
if ($pValue < 0) {
throw new \Exception("Invalid value should be more than 0.");
}
$this->level = $pValue;

Expand Down
27 changes: 27 additions & 0 deletions tests/PhpPresentation/Tests/Reader/ODPresentationTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -474,4 +474,31 @@ public function testSlideName()

$this->assertEquals('MaDiapo', $oPhpPresentation->getSlide(0)->getName());
}

public function testIssue00141()
{
$file = PHPPRESENTATION_TESTS_BASE_DIR . '/resources/files/Issue_00141.odp';
$object = new ODPresentation();
$oPhpPresentation = $object->load($file);
$this->assertInstanceOf('PhpOffice\\PhpPresentation\\PhpPresentation', $oPhpPresentation);

$this->assertCount(3, $oPhpPresentation->getAllSlides());

// Slide 1
$oSlide = $oPhpPresentation->getSlide(1);
$arrayShape = $oSlide->getShapeCollection();
$this->assertCount(2, $arrayShape);
// Slide 1 : Shape 1
$oShape = reset($arrayShape);
$this->assertInstanceOf('PhpOffice\\PhpPresentation\\Shape\\RichText', $oShape);
// Slide 1 : Shape 1 : Paragraph 1
$oParagraph = $oShape->getParagraph();
$this->assertInstanceOf('PhpOffice\\PhpPresentation\\Shape\\RichText\\Paragraph', $oParagraph);
// Slide 1 : Shape 1 : Paragraph 1 : RichText Elements
$arrayElements = $oParagraph->getRichTextElements();
$this->assertCount(1, $arrayElements);
$oElement = reset($arrayElements);
$this->assertInstanceOf('PhpOffice\\PhpPresentation\\Shape\\RichText\\TextElement', $oElement);
$this->assertEquals('TEST IMAGE', $oElement->getText());
}
}
12 changes: 1 addition & 11 deletions tests/PhpPresentation/Tests/Style/AlignmentTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -70,20 +70,10 @@ public function testSetGetVertical()
public function testSetGetLevelExceptionMin()
{
$object = new Alignment();
$this->setExpectedException('\Exception', 'Invalid value: shoul be range 0 - 8.');
$this->setExpectedException('\Exception', 'Invalid value should be more than 0.');
$object->setLevel(-1);
}

/**
* Test get/set max level exception
*/
public function testSetGetLevelExceptionMax()
{
$object = new Alignment();
$this->setExpectedException('\Exception', 'Invalid value: shoul be range 0 - 8.');
$object->setLevel(9);
}

/**
* Test get/set level
*/
Expand Down
Binary file added tests/resources/files/Issue_00141.odp
Binary file not shown.

0 comments on commit cc6d377

Please sign in to comment.