Skip to content

Commit e7fa00f

Browse files
Progi1984ag3202
andauthored
PowerPoint2007 Reader : Fixed loading of fonts (#851)
* Fixed fonts in the generated file after usiong a reader * Addressing Compatibility Issues Causing Crashes * Fix unit * Contribution : Fixed some errors --------- Co-authored-by: ag3202 <[email protected]>
1 parent b926b71 commit e7fa00f

File tree

4 files changed

+51
-15
lines changed

4 files changed

+51
-15
lines changed

docs/changes/1.2.0.md

+5-4
Original file line numberDiff line numberDiff line change
@@ -13,14 +13,15 @@
1313

1414
## Bug fixes
1515

16-
- 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)
16+
- 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)
1717
- CI : Fixed PHPCSFixer by [@kw-pr](https://github.com/kw-pr) in [#835](https://github.com/PHPOffice/PHPPresentation/pull/835)
18-
- 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)
19-
- 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)
18+
- 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)
19+
- 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)
2020
- `Gd::setImageResource()` : Fixed when imagecreatetruecolor returns false by [@jaapdh](https://github.com/jaapdh) in [#843](https://github.com/PHPOffice/PHPPresentation/pull/843)
21-
- 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)
21+
- 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)
2222
- `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)
2323
- 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)
24+
- 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)
2425

2526
## Miscellaneous
2627

src/PhpPresentation/Reader/PowerPoint2007.php

+12-9
Original file line numberDiff line numberDiff line change
@@ -492,7 +492,9 @@ protected function loadSlide(string $sPart, string $baseFile): void
492492
file_put_contents($tmpBkgImg, $contentImg);
493493
// Background
494494
$oBackground = new Slide\Background\Image();
495-
$oBackground->setPath($tmpBkgImg);
495+
$oBackground
496+
->setPath($tmpBkgImg)
497+
->setExtension(pathinfo($pathImage, PATHINFO_EXTENSION));
496498
// Slide Background
497499
$oSlide = $this->oPhpPresentation->getActiveSlide();
498500
$oSlide->setBackground($oBackground);
@@ -1323,22 +1325,23 @@ protected function loadParagraph(XMLReader $document, DOMElement $oElement, $oSh
13231325
$this->loadHyperlink($document, $oElementHlinkClick, $oText->getHyperlink())
13241326
);
13251327
}
1328+
13261329
// Font
13271330
$oElementFontFormat = null;
1328-
$oElementFontFormatLatin = $document->getElement('a:latin', $oElementrPr);
1329-
if (is_object($oElementFontFormatLatin)) {
1330-
$oText->getFont()->setFormat(Font::FORMAT_LATIN);
1331-
$oElementFontFormat = $oElementFontFormatLatin;
1331+
$oElementFontFormatComplexScript = $document->getElement('a:cs', $oElementrPr);
1332+
if (is_object($oElementFontFormatComplexScript)) {
1333+
$oText->getFont()->setFormat(Font::FORMAT_COMPLEX_SCRIPT);
1334+
$oElementFontFormat = $oElementFontFormatComplexScript;
13321335
}
13331336
$oElementFontFormatEastAsian = $document->getElement('a:ea', $oElementrPr);
13341337
if (is_object($oElementFontFormatEastAsian)) {
13351338
$oText->getFont()->setFormat(Font::FORMAT_EAST_ASIAN);
13361339
$oElementFontFormat = $oElementFontFormatEastAsian;
13371340
}
1338-
$oElementFontFormatComplexScript = $document->getElement('a:cs', $oElementrPr);
1339-
if (is_object($oElementFontFormatComplexScript)) {
1340-
$oText->getFont()->setFormat(Font::FORMAT_COMPLEX_SCRIPT);
1341-
$oElementFontFormat = $oElementFontFormatComplexScript;
1341+
$oElementFontFormatLatin = $document->getElement('a:latin', $oElementrPr);
1342+
if (is_object($oElementFontFormatLatin)) {
1343+
$oText->getFont()->setFormat(Font::FORMAT_LATIN);
1344+
$oElementFontFormat = $oElementFontFormatLatin;
13421345
}
13431346
if (is_object($oElementFontFormat) && $oElementFontFormat->hasAttribute('typeface')) {
13441347
$oText->getFont()->setName($oElementFontFormat->getAttribute('typeface'));

src/PhpPresentation/Slide/Background/Image.php

+20
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,11 @@ class Image extends AbstractBackground
4747
*/
4848
protected $width;
4949

50+
/**
51+
* @var string
52+
*/
53+
protected $extension;
54+
5055
/**
5156
* Get Path.
5257
*/
@@ -80,6 +85,18 @@ public function setPath(string $pValue = '', bool $pVerifyFile = true)
8085
return $this;
8186
}
8287

88+
/**
89+
* Set Extension.
90+
*
91+
* @param string $pValue File Extension
92+
*/
93+
public function setExtension(string $pValue): self
94+
{
95+
$this->extension = $pValue;
96+
97+
return $this;
98+
}
99+
83100
/**
84101
* Get Filename.
85102
*/
@@ -93,6 +110,9 @@ public function getFilename(): string
93110
*/
94111
public function getExtension(): string
95112
{
113+
if ($this->extension) {
114+
return $this->extension;
115+
}
96116
$exploded = explode('.', $this->getFilename());
97117

98118
return $exploded[count($exploded) - 1];

tests/PhpPresentation/Tests/Slide/Background/ImageTest.php

+14-2
Original file line numberDiff line numberDiff line change
@@ -38,19 +38,31 @@ public function testColor(): void
3838
self::assertEmpty($object->getExtension());
3939
self::assertEquals('background_' . $numSlide . '.', $object->getIndexedFilename($numSlide));
4040

41-
self::assertInstanceOf('PhpOffice\\PhpPresentation\\Slide\\Background\\Image', $object->setPath($imagePath));
41+
self::assertInstanceOf(Image::class, $object->setPath($imagePath));
4242
self::assertEquals($imagePath, $object->getPath());
4343
self::assertEquals('PhpPresentationLogo.png', $object->getFilename());
4444
self::assertEquals('png', $object->getExtension());
4545
self::assertEquals('background_' . $numSlide . '.png', $object->getIndexedFilename($numSlide));
4646

47-
self::assertInstanceOf('PhpOffice\\PhpPresentation\\Slide\\Background\\Image', $object->setPath('', false));
47+
self::assertInstanceOf(Image::class, $object->setPath('', false));
4848
self::assertEquals('', $object->getPath());
4949
self::assertEmpty($object->getFilename());
5050
self::assertEmpty($object->getExtension());
5151
self::assertEquals('background_' . $numSlide . '.', $object->getIndexedFilename($numSlide));
5252
}
5353

54+
public function testExtension(): void
55+
{
56+
$object = new Image();
57+
$imagePath = PHPPRESENTATION_TESTS_BASE_DIR . DIRECTORY_SEPARATOR . 'resources' . DIRECTORY_SEPARATOR . 'images' . DIRECTORY_SEPARATOR . 'PhpPresentationLogo.png';
58+
59+
self::assertEmpty($object->getExtension());
60+
self::assertInstanceOf(Image::class, $object->setPath($imagePath));
61+
self::assertEquals('png', $object->getExtension());
62+
self::assertInstanceOf(Image::class, $object->setExtension('jpg'));
63+
self::assertEquals('jpg', $object->getExtension());
64+
}
65+
5466
public function testPathException(): void
5567
{
5668
$this->expectException(FileNotFoundException::class);

0 commit comments

Comments
 (0)