Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Float passed to setSize on load() causing exception #740

Closed
websuasive opened this issue May 24, 2023 · 1 comment
Closed

Float passed to setSize on load() causing exception #740

websuasive opened this issue May 24, 2023 · 1 comment

Comments

@websuasive
Copy link

Exception thrown trying to load a presentation due to $oElementLvlDefRPR->getAttribute('sz') / 100) passing a float to $oRTParagraph->getFont()->setSize().

Exception:

PhpOffice\PhpPresentation\Style\Font::setSize(): Argument #1 ($pValue) must be of type int, float given, called in /var/www/html/vendor/phpoffice/phppresentation/src/PhpPresentation/Reader/PowerPoint2007.php on line 559 {"cx":3,"userId":3,"exception":"[object] (TypeError(code: 0): PhpOffice\PhpPresentation\Style\Font::setSize(): Argument #1 ($pValue) must be of type int, float given, called in /var/www/html/vendor/phpoffice/phppresentation/src/PhpPresentation/Reader/PowerPoint2007.php on line 560 at /var/www/html/vendor/phpoffice/phppresentation/src/PhpPresentation/Style/Font.php:206)

[stacktrace]
#0 /var/www/html/vendor/phpoffice/phppresentation/src/PhpPresentation/Reader/PowerPoint2007.php(559): PhpOffice\PhpPresentation\Style\Font->setSize()
#1 /var/www/html/vendor/phpoffice/phppresentation/src/PhpPresentation/Reader/PowerPoint2007.php(397): PhpOffice\PhpPresentation\Reader\PowerPoint2007->loadMasterSlide()
#2 /var/www/html/vendor/phpoffice/phppresentation/src/PhpPresentation/Reader/PowerPoint2007.php(354): PhpOffice\PhpPresentation\Reader\PowerPoint2007->loadMasterSlides()
#3 /var/www/html/vendor/phpoffice/phppresentation/src/PhpPresentation/Reader/PowerPoint2007.php(170): PhpOffice\PhpPresentation\Reader\PowerPoint2007->loadSlides()
#4 /var/www/html/vendor/phpoffice/phppresentation/src/PhpPresentation/Reader/PowerPoint2007.php(137): PhpOffice\PhpPresentation\Reader\PowerPoint2007->loadFile()
#5 /var/www/html/app/Helpers/ParsePptx.php(35): PhpOffice\PhpPresentation\Reader\PowerPoint2007->load()

The code with issue:

$oElementLvlDefRPR = $xmlReader->getElement('a:defRPr', $oElementLvl);
if ($oElementLvlDefRPR instanceof DOMElement) {
if ($oElementLvlDefRPR->hasAttribute('sz')) {
$oRTParagraph->getFont()->setSize($oElementLvlDefRPR->getAttribute('sz') / 100); <===============
}
if ($oElementLvlDefRPR->hasAttribute('b') && 1 == $oElementLvlDefRPR->getAttribute('b')) {
$oRTParagraph->getFont()->setBold(true);
}
if ($oElementLvlDefRPR->hasAttribute('i') && 1 == $oElementLvlDefRPR->getAttribute('i')) {
$oRTParagraph->getFont()->setItalic(true);
}
}

Is the fix as simple as:

oRTParagraph->getFont()->setSize((int) round($oElementLvlDefRPR->getAttribute('sz') / 100,0));

@websuasive
Copy link
Author

Realised duplicate of issue #738

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

No branches or pull requests

1 participant