From 668367a0093b1b1746a746c682b948803b3bb18a Mon Sep 17 00:00:00 2001 From: ag3202 Date: Thu, 29 Feb 2024 06:25:16 +0800 Subject: [PATCH] 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();