diff --git a/docs/changes/1.2.0.md b/docs/changes/1.2.0.md index e5c656fc9..70556575e 100644 --- a/docs/changes/1.2.0.md +++ b/docs/changes/1.2.0.md @@ -13,14 +13,15 @@ ## Bug fixes -- Word2007 Reader: Fixed cast of spacing by [@Progi1984](https://github.com/Progi1984) fixing [#729](https://github.com/PHPOffice/PHPPresentation/pull/729), [#796](https://github.com/PHPOffice/PHPPresentation/pull/796) in [#818](https://github.com/PHPOffice/PHPPresentation/pull/818) +- PowerPoint2007 Reader: Fixed cast of spacing by [@Progi1984](https://github.com/Progi1984) fixing [#729](https://github.com/PHPOffice/PHPPresentation/pull/729), [#796](https://github.com/PHPOffice/PHPPresentation/pull/796) in [#818](https://github.com/PHPOffice/PHPPresentation/pull/818) - CI : Fixed PHPCSFixer by [@kw-pr](https://github.com/kw-pr) in [#835](https://github.com/PHPOffice/PHPPresentation/pull/835) -- Word2007 Reader: Fixed cast of color by [@Progi1984](https://github.com/Progi1984) fixing [#826](https://github.com/PHPOffice/PHPPresentation/pull/826) in [#840](https://github.com/PHPOffice/PHPPresentation/pull/840) -- Word2007 Reader: Fixed panose with 20 characters by [@Progi1984](https://github.com/Progi1984) fixing [#798](https://github.com/PHPOffice/PHPPresentation/pull/798) in [#842](https://github.com/PHPOffice/PHPPresentation/pull/842) +- PowerPoint2007 Reader: Fixed cast of color by [@Progi1984](https://github.com/Progi1984) fixing [#826](https://github.com/PHPOffice/PHPPresentation/pull/826) in [#840](https://github.com/PHPOffice/PHPPresentation/pull/840) +- PowerPoint2007 Reader: Fixed panose with 20 characters by [@Progi1984](https://github.com/Progi1984) fixing [#798](https://github.com/PHPOffice/PHPPresentation/pull/798) in [#842](https://github.com/PHPOffice/PHPPresentation/pull/842) - `Gd::setImageResource()` : Fixed when imagecreatetruecolor returns false by [@jaapdh](https://github.com/jaapdh) in [#843](https://github.com/PHPOffice/PHPPresentation/pull/843) -- Word2007 Writer: LineChart supports LabelPosition for Series by [@pal-software](https://github.com/pal-software) fixing [#606](https://github.com/PHPOffice/PHPPresentation/pull/606) in [#8434](https://github.com/PHPOffice/PHPPresentation/pull/844) +- PowerPoint2007 Writer: LineChart supports LabelPosition for Series by [@pal-software](https://github.com/pal-software) fixing [#606](https://github.com/PHPOffice/PHPPresentation/pull/606) in [#8434](https://github.com/PHPOffice/PHPPresentation/pull/844) - `createDrawingShape` has no container defined by [@Progi1984](https://github.com/Progi1984) fixing [#820](https://github.com/PHPOffice/PHPPresentation/pull/820) in [#845](https://github.com/PHPOffice/PHPPresentation/pull/845) - ODPresentation Reader : Read differents units for margin by [@Progi1984](https://github.com/Progi1984) fixing [#830](https://github.com/PHPOffice/PHPPresentation/pull/830) in [#847](https://github.com/PHPOffice/PHPPresentation/pull/847) +- PowerPoint2007 Reader : Fixed loading of fonts by [@ag3202](https://github.com/ag3202) and [@Progi1984](https://github.com/Progi1984) in [#851](https://github.com/PHPOffice/PHPPresentation/pull/851) ## Miscellaneous diff --git a/src/PhpPresentation/Reader/PowerPoint2007.php b/src/PhpPresentation/Reader/PowerPoint2007.php index 8659206c9..16f4ddcca 100644 --- a/src/PhpPresentation/Reader/PowerPoint2007.php +++ b/src/PhpPresentation/Reader/PowerPoint2007.php @@ -492,7 +492,9 @@ protected function loadSlide(string $sPart, string $baseFile): void file_put_contents($tmpBkgImg, $contentImg); // Background $oBackground = new Slide\Background\Image(); - $oBackground->setPath($tmpBkgImg); + $oBackground + ->setPath($tmpBkgImg) + ->setExtension(pathinfo($pathImage, PATHINFO_EXTENSION)); // Slide Background $oSlide = $this->oPhpPresentation->getActiveSlide(); $oSlide->setBackground($oBackground); @@ -1323,22 +1325,23 @@ protected function loadParagraph(XMLReader $document, DOMElement $oElement, $oSh $this->loadHyperlink($document, $oElementHlinkClick, $oText->getHyperlink()) ); } + // Font $oElementFontFormat = null; - $oElementFontFormatLatin = $document->getElement('a:latin', $oElementrPr); - if (is_object($oElementFontFormatLatin)) { - $oText->getFont()->setFormat(Font::FORMAT_LATIN); - $oElementFontFormat = $oElementFontFormatLatin; + $oElementFontFormatComplexScript = $document->getElement('a:cs', $oElementrPr); + if (is_object($oElementFontFormatComplexScript)) { + $oText->getFont()->setFormat(Font::FORMAT_COMPLEX_SCRIPT); + $oElementFontFormat = $oElementFontFormatComplexScript; } $oElementFontFormatEastAsian = $document->getElement('a:ea', $oElementrPr); if (is_object($oElementFontFormatEastAsian)) { $oText->getFont()->setFormat(Font::FORMAT_EAST_ASIAN); $oElementFontFormat = $oElementFontFormatEastAsian; } - $oElementFontFormatComplexScript = $document->getElement('a:cs', $oElementrPr); - if (is_object($oElementFontFormatComplexScript)) { - $oText->getFont()->setFormat(Font::FORMAT_COMPLEX_SCRIPT); - $oElementFontFormat = $oElementFontFormatComplexScript; + $oElementFontFormatLatin = $document->getElement('a:latin', $oElementrPr); + if (is_object($oElementFontFormatLatin)) { + $oText->getFont()->setFormat(Font::FORMAT_LATIN); + $oElementFontFormat = $oElementFontFormatLatin; } if (is_object($oElementFontFormat) && $oElementFontFormat->hasAttribute('typeface')) { $oText->getFont()->setName($oElementFontFormat->getAttribute('typeface')); diff --git a/src/PhpPresentation/Slide/Background/Image.php b/src/PhpPresentation/Slide/Background/Image.php index 093fd005d..801464dc0 100644 --- a/src/PhpPresentation/Slide/Background/Image.php +++ b/src/PhpPresentation/Slide/Background/Image.php @@ -47,6 +47,11 @@ class Image extends AbstractBackground */ protected $width; + /** + * @var string + */ + protected $extension; + /** * Get Path. */ @@ -80,6 +85,18 @@ public function setPath(string $pValue = '', bool $pVerifyFile = true) return $this; } + /** + * Set Extension. + * + * @param string $pValue File Extension + */ + public function setExtension(string $pValue): self + { + $this->extension = $pValue; + + return $this; + } + /** * Get Filename. */ @@ -93,6 +110,9 @@ public function getFilename(): string */ public function getExtension(): string { + if ($this->extension) { + return $this->extension; + } $exploded = explode('.', $this->getFilename()); return $exploded[count($exploded) - 1]; diff --git a/tests/PhpPresentation/Tests/Slide/Background/ImageTest.php b/tests/PhpPresentation/Tests/Slide/Background/ImageTest.php index c3c0e31be..6d043782d 100644 --- a/tests/PhpPresentation/Tests/Slide/Background/ImageTest.php +++ b/tests/PhpPresentation/Tests/Slide/Background/ImageTest.php @@ -38,19 +38,31 @@ public function testColor(): void self::assertEmpty($object->getExtension()); self::assertEquals('background_' . $numSlide . '.', $object->getIndexedFilename($numSlide)); - self::assertInstanceOf('PhpOffice\\PhpPresentation\\Slide\\Background\\Image', $object->setPath($imagePath)); + self::assertInstanceOf(Image::class, $object->setPath($imagePath)); self::assertEquals($imagePath, $object->getPath()); self::assertEquals('PhpPresentationLogo.png', $object->getFilename()); self::assertEquals('png', $object->getExtension()); self::assertEquals('background_' . $numSlide . '.png', $object->getIndexedFilename($numSlide)); - self::assertInstanceOf('PhpOffice\\PhpPresentation\\Slide\\Background\\Image', $object->setPath('', false)); + self::assertInstanceOf(Image::class, $object->setPath('', false)); self::assertEquals('', $object->getPath()); self::assertEmpty($object->getFilename()); self::assertEmpty($object->getExtension()); self::assertEquals('background_' . $numSlide . '.', $object->getIndexedFilename($numSlide)); } + public function testExtension(): void + { + $object = new Image(); + $imagePath = PHPPRESENTATION_TESTS_BASE_DIR . DIRECTORY_SEPARATOR . 'resources' . DIRECTORY_SEPARATOR . 'images' . DIRECTORY_SEPARATOR . 'PhpPresentationLogo.png'; + + self::assertEmpty($object->getExtension()); + self::assertInstanceOf(Image::class, $object->setPath($imagePath)); + self::assertEquals('png', $object->getExtension()); + self::assertInstanceOf(Image::class, $object->setExtension('jpg')); + self::assertEquals('jpg', $object->getExtension()); + } + public function testPathException(): void { $this->expectException(FileNotFoundException::class);