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 e6275ce23..16f4ddcca 100644 --- a/src/PhpPresentation/Reader/PowerPoint2007.php +++ b/src/PhpPresentation/Reader/PowerPoint2007.php @@ -492,9 +492,9 @@ protected function loadSlide(string $sPart, string $baseFile): void file_put_contents($tmpBkgImg, $contentImg); // Background $oBackground = new Slide\Background\Image(); - $oBackground->setPath($tmpBkgImg); - $extension = pathinfo( $pathImage, PATHINFO_EXTENSION ); - $oBackground->setExtension($extension); + $oBackground + ->setPath($tmpBkgImg) + ->setExtension(pathinfo($pathImage, PATHINFO_EXTENSION)); // Slide Background $oSlide = $this->oPhpPresentation->getActiveSlide(); $oSlide->setBackground($oBackground); @@ -1326,25 +1326,23 @@ protected function loadParagraph(XMLReader $document, DOMElement $oElement, $oSh ); } + // Font + $oElementFontFormat = null; + $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; } - - // 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; - } 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 2a21a0184..801464dc0 100644 --- a/src/PhpPresentation/Slide/Background/Image.php +++ b/src/PhpPresentation/Slide/Background/Image.php @@ -89,12 +89,11 @@ public function setPath(string $pValue = '', bool $pVerifyFile = true) * Set Extension. * * @param string $pValue File Extension - * - * @return self */ - public function setExtension(string $pValue) + public function setExtension(string $pValue): self { $this->extension = $pValue; + return $this; } @@ -111,12 +110,12 @@ public function getFilename(): string */ public function getExtension(): string { - if($this->extension){ + if ($this->extension) { return $this->extension; } $exploded = explode('.', $this->getFilename()); - return $exploded[count($exploded) - 1]; + return $exploded[count($exploded) - 1]; } /** diff --git a/src/PhpPresentation/Writer/PowerPoint2007/AbstractSlide.php b/src/PhpPresentation/Writer/PowerPoint2007/AbstractSlide.php index bf8b7570e..e6d085ac7 100644 --- a/src/PhpPresentation/Writer/PowerPoint2007/AbstractSlide.php +++ b/src/PhpPresentation/Writer/PowerPoint2007/AbstractSlide.php @@ -678,18 +678,21 @@ protected function writeRunStyles(XMLWriter $objWriter, Run $element): void $objWriter->startElement('a:' . $element->getFont()->getFormat()); $objWriter->writeAttribute('typeface', $element->getFont()->getName()); if ($element->getFont()->getPanose() !== '') { - $objWriter->writeAttribute('panose', $element->getFont()->getPanose()); + $panose = array_map(function (string $value) { + return '0' . $value; + }, str_split($element->getFont()->getPanose())); + + $objWriter->writeAttribute('panose', implode('', $panose)); } $objWriter->writeAttributeIf( $element->getFont()->getPitchFamily() !== 0, 'pitchFamily', $element->getFont()->getPitchFamily() ); - $charset = $element->getFont()->getCharset(); $objWriter->writeAttributeIf( $element->getFont()->getCharset() !== Font::CHARSET_DEFAULT, 'charset', - $charset + dechex($element->getFont()->getCharset()) ); $objWriter->endElement(); 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); diff --git a/tests/PhpPresentation/Tests/Writer/PowerPoint2007/PptSlidesTest.php b/tests/PhpPresentation/Tests/Writer/PowerPoint2007/PptSlidesTest.php index 6acfb7c6a..663bb6015 100644 --- a/tests/PhpPresentation/Tests/Writer/PowerPoint2007/PptSlidesTest.php +++ b/tests/PhpPresentation/Tests/Writer/PowerPoint2007/PptSlidesTest.php @@ -886,7 +886,7 @@ public function testRichTextRunFontCharset(): void $this->assertZipXmlAttributeExists('ppt/slides/slide1.xml', $latinElement, 'typeface'); $this->assertZipXmlAttributeEquals('ppt/slides/slide1.xml', $latinElement, 'typeface', 'Calibri'); $this->assertZipXmlAttributeExists('ppt/slides/slide1.xml', $latinElement, 'charset'); - $this->assertZipXmlAttributeEquals('ppt/slides/slide1.xml', $latinElement, 'charset', '18'); + $this->assertZipXmlAttributeEquals('ppt/slides/slide1.xml', $latinElement, 'charset', '12'); $this->assertZipXmlElementNotExists('ppt/slides/slide1.xml', $eastAsianElement); $this->assertZipXmlElementNotExists('ppt/slides/slide1.xml', $complexScriptElement); $this->assertIsSchemaECMA376Valid(); @@ -899,7 +899,7 @@ public function testRichTextRunFontCharset(): void $this->assertZipXmlAttributeExists('ppt/slides/slide1.xml', $eastAsianElement, 'typeface'); $this->assertZipXmlAttributeEquals('ppt/slides/slide1.xml', $eastAsianElement, 'typeface', 'Calibri'); $this->assertZipXmlAttributeExists('ppt/slides/slide1.xml', $eastAsianElement, 'charset'); - $this->assertZipXmlAttributeEquals('ppt/slides/slide1.xml', $eastAsianElement, 'charset', '18'); + $this->assertZipXmlAttributeEquals('ppt/slides/slide1.xml', $eastAsianElement, 'charset', '12'); $this->assertZipXmlElementNotExists('ppt/slides/slide1.xml', $complexScriptElement); $this->assertIsSchemaECMA376Valid(); @@ -912,7 +912,7 @@ public function testRichTextRunFontCharset(): void $this->assertZipXmlAttributeExists('ppt/slides/slide1.xml', $complexScriptElement, 'typeface'); $this->assertZipXmlAttributeEquals('ppt/slides/slide1.xml', $complexScriptElement, 'typeface', 'Calibri'); $this->assertZipXmlAttributeExists('ppt/slides/slide1.xml', $complexScriptElement, 'charset'); - $this->assertZipXmlAttributeEquals('ppt/slides/slide1.xml', $complexScriptElement, 'charset', '18'); + $this->assertZipXmlAttributeEquals('ppt/slides/slide1.xml', $complexScriptElement, 'charset', '12'); $this->assertIsSchemaECMA376Valid(); }