Skip to content

Commit 5eaabad

Browse files
committed
Contribution : Fixed some errors
1 parent 84fa3f2 commit 5eaabad

File tree

6 files changed

+42
-29
lines changed

6 files changed

+42
-29
lines changed

docs/changes/1.2.0.md

Lines changed: 5 additions & 4 deletions
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

Lines changed: 10 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -492,9 +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);
496-
$extension = pathinfo( $pathImage, PATHINFO_EXTENSION );
497-
$oBackground->setExtension($extension);
495+
$oBackground
496+
->setPath($tmpBkgImg)
497+
->setExtension(pathinfo($pathImage, PATHINFO_EXTENSION));
498498
// Slide Background
499499
$oSlide = $this->oPhpPresentation->getActiveSlide();
500500
$oSlide->setBackground($oBackground);
@@ -1326,25 +1326,23 @@ protected function loadParagraph(XMLReader $document, DOMElement $oElement, $oSh
13261326
);
13271327
}
13281328

1329+
// Font
1330+
$oElementFontFormat = null;
1331+
$oElementFontFormatComplexScript = $document->getElement('a:cs', $oElementrPr);
1332+
if (is_object($oElementFontFormatComplexScript)) {
1333+
$oText->getFont()->setFormat(Font::FORMAT_COMPLEX_SCRIPT);
1334+
$oElementFontFormat = $oElementFontFormatComplexScript;
1335+
}
13291336
$oElementFontFormatEastAsian = $document->getElement('a:ea', $oElementrPr);
13301337
if (is_object($oElementFontFormatEastAsian)) {
13311338
$oText->getFont()->setFormat(Font::FORMAT_EAST_ASIAN);
13321339
$oElementFontFormat = $oElementFontFormatEastAsian;
13331340
}
1334-
1335-
// Font
1336-
$oElementFontFormat = null;
13371341
$oElementFontFormatLatin = $document->getElement('a:latin', $oElementrPr);
13381342
if (is_object($oElementFontFormatLatin)) {
13391343
$oText->getFont()->setFormat(Font::FORMAT_LATIN);
13401344
$oElementFontFormat = $oElementFontFormatLatin;
13411345
}
1342-
1343-
$oElementFontFormatComplexScript = $document->getElement('a:cs', $oElementrPr);
1344-
if (is_object($oElementFontFormatComplexScript)) {
1345-
$oText->getFont()->setFormat(Font::FORMAT_COMPLEX_SCRIPT);
1346-
$oElementFontFormat = $oElementFontFormatComplexScript;
1347-
}
13481346
if (is_object($oElementFontFormat) && $oElementFontFormat->hasAttribute('typeface')) {
13491347
$oText->getFont()->setName($oElementFontFormat->getAttribute('typeface'));
13501348
}

src/PhpPresentation/Slide/Background/Image.php

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -89,12 +89,11 @@ public function setPath(string $pValue = '', bool $pVerifyFile = true)
8989
* Set Extension.
9090
*
9191
* @param string $pValue File Extension
92-
*
93-
* @return self
9492
*/
95-
public function setExtension(string $pValue)
93+
public function setExtension(string $pValue): self
9694
{
9795
$this->extension = $pValue;
96+
9897
return $this;
9998
}
10099

@@ -111,12 +110,12 @@ public function getFilename(): string
111110
*/
112111
public function getExtension(): string
113112
{
114-
if($this->extension){
113+
if ($this->extension) {
115114
return $this->extension;
116115
}
117116
$exploded = explode('.', $this->getFilename());
118-
return $exploded[count($exploded) - 1];
119117

118+
return $exploded[count($exploded) - 1];
120119
}
121120

122121
/**

src/PhpPresentation/Writer/PowerPoint2007/AbstractSlide.php

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -678,18 +678,21 @@ protected function writeRunStyles(XMLWriter $objWriter, Run $element): void
678678
$objWriter->startElement('a:' . $element->getFont()->getFormat());
679679
$objWriter->writeAttribute('typeface', $element->getFont()->getName());
680680
if ($element->getFont()->getPanose() !== '') {
681-
$objWriter->writeAttribute('panose', $element->getFont()->getPanose());
681+
$panose = array_map(function (string $value) {
682+
return '0' . $value;
683+
}, str_split($element->getFont()->getPanose()));
684+
685+
$objWriter->writeAttribute('panose', implode('', $panose));
682686
}
683687
$objWriter->writeAttributeIf(
684688
$element->getFont()->getPitchFamily() !== 0,
685689
'pitchFamily',
686690
$element->getFont()->getPitchFamily()
687691
);
688-
$charset = $element->getFont()->getCharset();
689692
$objWriter->writeAttributeIf(
690693
$element->getFont()->getCharset() !== Font::CHARSET_DEFAULT,
691694
'charset',
692-
$charset
695+
dechex($element->getFont()->getCharset())
693696
);
694697
$objWriter->endElement();
695698

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

Lines changed: 14 additions & 2 deletions
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);

tests/PhpPresentation/Tests/Writer/PowerPoint2007/PptSlidesTest.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -886,7 +886,7 @@ public function testRichTextRunFontCharset(): void
886886
$this->assertZipXmlAttributeExists('ppt/slides/slide1.xml', $latinElement, 'typeface');
887887
$this->assertZipXmlAttributeEquals('ppt/slides/slide1.xml', $latinElement, 'typeface', 'Calibri');
888888
$this->assertZipXmlAttributeExists('ppt/slides/slide1.xml', $latinElement, 'charset');
889-
$this->assertZipXmlAttributeEquals('ppt/slides/slide1.xml', $latinElement, 'charset', '18');
889+
$this->assertZipXmlAttributeEquals('ppt/slides/slide1.xml', $latinElement, 'charset', '12');
890890
$this->assertZipXmlElementNotExists('ppt/slides/slide1.xml', $eastAsianElement);
891891
$this->assertZipXmlElementNotExists('ppt/slides/slide1.xml', $complexScriptElement);
892892
$this->assertIsSchemaECMA376Valid();
@@ -899,7 +899,7 @@ public function testRichTextRunFontCharset(): void
899899
$this->assertZipXmlAttributeExists('ppt/slides/slide1.xml', $eastAsianElement, 'typeface');
900900
$this->assertZipXmlAttributeEquals('ppt/slides/slide1.xml', $eastAsianElement, 'typeface', 'Calibri');
901901
$this->assertZipXmlAttributeExists('ppt/slides/slide1.xml', $eastAsianElement, 'charset');
902-
$this->assertZipXmlAttributeEquals('ppt/slides/slide1.xml', $eastAsianElement, 'charset', '18');
902+
$this->assertZipXmlAttributeEquals('ppt/slides/slide1.xml', $eastAsianElement, 'charset', '12');
903903
$this->assertZipXmlElementNotExists('ppt/slides/slide1.xml', $complexScriptElement);
904904
$this->assertIsSchemaECMA376Valid();
905905

@@ -912,7 +912,7 @@ public function testRichTextRunFontCharset(): void
912912
$this->assertZipXmlAttributeExists('ppt/slides/slide1.xml', $complexScriptElement, 'typeface');
913913
$this->assertZipXmlAttributeEquals('ppt/slides/slide1.xml', $complexScriptElement, 'typeface', 'Calibri');
914914
$this->assertZipXmlAttributeExists('ppt/slides/slide1.xml', $complexScriptElement, 'charset');
915-
$this->assertZipXmlAttributeEquals('ppt/slides/slide1.xml', $complexScriptElement, 'charset', '18');
915+
$this->assertZipXmlAttributeEquals('ppt/slides/slide1.xml', $complexScriptElement, 'charset', '12');
916916
$this->assertIsSchemaECMA376Valid();
917917
}
918918

0 commit comments

Comments
 (0)