Skip to content

Commit

Permalink
Fixed fonts in the generated file after usiong a reader
Browse files Browse the repository at this point in the history
  • Loading branch information
ag3202 committed Feb 28, 2024
1 parent ec4700e commit 668367a
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 15 deletions.
13 changes: 8 additions & 5 deletions src/PhpPresentation/Reader/PowerPoint2007.php
Original file line number Diff line number Diff line change
Expand Up @@ -1312,18 +1312,21 @@ 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);
if (is_object($oElementFontFormatLatin)) {
$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);
Expand Down
4 changes: 0 additions & 4 deletions src/PhpPresentation/Style/Font.php
Original file line number Diff line number Diff line change
Expand Up @@ -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)) {
Expand Down
9 changes: 3 additions & 6 deletions src/PhpPresentation/Writer/PowerPoint2007/AbstractSlide.php
Original file line number Diff line number Diff line change
Expand Up @@ -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();

Expand Down

0 comments on commit 668367a

Please sign in to comment.