From 668367a0093b1b1746a746c682b948803b3bb18a Mon Sep 17 00:00:00 2001 From: ag3202 Date: Thu, 29 Feb 2024 06:25:16 +0800 Subject: [PATCH 1/3] Fixed fonts in the generated file after usiong a reader --- src/PhpPresentation/Reader/PowerPoint2007.php | 13 ++++++++----- src/PhpPresentation/Style/Font.php | 4 ---- .../Writer/PowerPoint2007/AbstractSlide.php | 9 +++------ 3 files changed, 11 insertions(+), 15 deletions(-) diff --git a/src/PhpPresentation/Reader/PowerPoint2007.php b/src/PhpPresentation/Reader/PowerPoint2007.php index 140c2f4a5..fb37606d5 100644 --- a/src/PhpPresentation/Reader/PowerPoint2007.php +++ b/src/PhpPresentation/Reader/PowerPoint2007.php @@ -1312,6 +1312,13 @@ protected function loadParagraph(XMLReader $document, DOMElement $oElement, $oSh $this->loadHyperlink($document, $oElementHlinkClick, $oText->getHyperlink()) ); } + + $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); @@ -1319,11 +1326,7 @@ protected function loadParagraph(XMLReader $document, DOMElement $oElement, $oSh $oText->getFont()->setFormat(Font::FORMAT_LATIN); $oElementFontFormat = $oElementFontFormatLatin; } - $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); diff --git a/src/PhpPresentation/Style/Font.php b/src/PhpPresentation/Style/Font.php index 2975df4ef..a18a9923f 100644 --- a/src/PhpPresentation/Style/Font.php +++ b/src/PhpPresentation/Style/Font.php @@ -214,10 +214,6 @@ public function getPanose(): string */ public function setPanose(string $pValue): self { - if (mb_strlen($pValue) !== 10) { - throw new InvalidParameterException('pValue', $pValue, 'The length is not equals to 10'); - } - $allowedChars = ['0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'A', 'B', 'C', 'D', 'E', 'F']; foreach (mb_str_split($pValue) as $char) { if (!in_array($char, $allowedChars)) { diff --git a/src/PhpPresentation/Writer/PowerPoint2007/AbstractSlide.php b/src/PhpPresentation/Writer/PowerPoint2007/AbstractSlide.php index 58ef3b244..4e088867a 100644 --- a/src/PhpPresentation/Writer/PowerPoint2007/AbstractSlide.php +++ b/src/PhpPresentation/Writer/PowerPoint2007/AbstractSlide.php @@ -677,21 +677,18 @@ protected function writeRunStyles(XMLWriter $objWriter, Run $element): void $objWriter->startElement('a:' . $element->getFont()->getFormat()); $objWriter->writeAttribute('typeface', $element->getFont()->getName()); if ($element->getFont()->getPanose() !== '') { - $panose = array_map(function (string $value) { - return '0' . $value; - }, str_split($element->getFont()->getPanose())); - - $objWriter->writeAttribute('panose', implode('', $panose)); + $objWriter->writeAttribute('panose', $element->getFont()->getPanose()); } $objWriter->writeAttributeIf( $element->getFont()->getPitchFamily() !== 0, 'pitchFamily', $element->getFont()->getPitchFamily() ); + $charset = $element->getFont()->getCharset(); $objWriter->writeAttributeIf( $element->getFont()->getCharset() !== Font::CHARSET_DEFAULT, 'charset', - dechex($element->getFont()->getCharset()) + $charset ); $objWriter->endElement(); From cdd7142d6d7e964ffd1e4258a29eaaa61d40f5e4 Mon Sep 17 00:00:00 2001 From: ag3202 Date: Thu, 29 Feb 2024 13:09:25 +0800 Subject: [PATCH 2/3] Addressing Compatibility Issues Causing Crashes --- src/PhpPresentation/Reader/PowerPoint2007.php | 2 ++ .../Slide/Background/Image.php | 23 ++++++++++++++++++- 2 files changed, 24 insertions(+), 1 deletion(-) diff --git a/src/PhpPresentation/Reader/PowerPoint2007.php b/src/PhpPresentation/Reader/PowerPoint2007.php index fb37606d5..54ac92ddc 100644 --- a/src/PhpPresentation/Reader/PowerPoint2007.php +++ b/src/PhpPresentation/Reader/PowerPoint2007.php @@ -485,6 +485,8 @@ protected function loadSlide(string $sPart, string $baseFile): void // Background $oBackground = new Slide\Background\Image(); $oBackground->setPath($tmpBkgImg); + $extension = pathinfo( $pathImage, PATHINFO_EXTENSION ); + $oBackground->setExtension($extension); // Slide Background $oSlide = $this->oPhpPresentation->getActiveSlide(); $oSlide->setBackground($oBackground); diff --git a/src/PhpPresentation/Slide/Background/Image.php b/src/PhpPresentation/Slide/Background/Image.php index d39d00901..a4feef073 100644 --- a/src/PhpPresentation/Slide/Background/Image.php +++ b/src/PhpPresentation/Slide/Background/Image.php @@ -46,6 +46,11 @@ class Image extends AbstractBackground */ protected $width; + /** + * @var string + */ + protected $extension; + /** * Get Path. */ @@ -79,6 +84,19 @@ public function setPath(string $pValue = '', bool $pVerifyFile = true) return $this; } + /** + * Set Extension. + * + * @param string $pValue File Extension + * + * @return self + */ + public function setExtension(string $pValue) + { + $this->extension = $pValue; + return $this; + } + /** * Get Filename. */ @@ -92,9 +110,12 @@ public function getFilename(): string */ public function getExtension(): string { + if($this->extension){ + return $this->extension; + } $exploded = explode('.', $this->getFilename()); - return $exploded[count($exploded) - 1]; + } /** From 947fd46382e9693ed3a352066ec1319b7ca0b712 Mon Sep 17 00:00:00 2001 From: ag3202 Date: Thu, 29 Feb 2024 22:57:53 +0800 Subject: [PATCH 3/3] Fix unit --- .../Tests/Writer/PowerPoint2007/PptSlidesTest.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/tests/PhpPresentation/Tests/Writer/PowerPoint2007/PptSlidesTest.php b/tests/PhpPresentation/Tests/Writer/PowerPoint2007/PptSlidesTest.php index 652ebd5b4..3fed3b8d8 100644 --- a/tests/PhpPresentation/Tests/Writer/PowerPoint2007/PptSlidesTest.php +++ b/tests/PhpPresentation/Tests/Writer/PowerPoint2007/PptSlidesTest.php @@ -885,7 +885,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', '12'); + $this->assertZipXmlAttributeEquals('ppt/slides/slide1.xml', $latinElement, 'charset', '18'); $this->assertZipXmlElementNotExists('ppt/slides/slide1.xml', $eastAsianElement); $this->assertZipXmlElementNotExists('ppt/slides/slide1.xml', $complexScriptElement); $this->assertIsSchemaECMA376Valid(); @@ -898,7 +898,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', '12'); + $this->assertZipXmlAttributeEquals('ppt/slides/slide1.xml', $eastAsianElement, 'charset', '18'); $this->assertZipXmlElementNotExists('ppt/slides/slide1.xml', $complexScriptElement); $this->assertIsSchemaECMA376Valid(); @@ -911,7 +911,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', '12'); + $this->assertZipXmlAttributeEquals('ppt/slides/slide1.xml', $complexScriptElement, 'charset', '18'); $this->assertIsSchemaECMA376Valid(); }