Skip to content

Commit

Permalink
Contribution : Fixed some errors
Browse files Browse the repository at this point in the history
  • Loading branch information
Progi1984 committed Feb 3, 2025
1 parent 84fa3f2 commit 82eefd6
Show file tree
Hide file tree
Showing 6 changed files with 42 additions and 29 deletions.
9 changes: 5 additions & 4 deletions docs/changes/1.2.0.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,15 @@

## Bug fixes

- 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)
- 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)
- CI : Fixed PHPCSFixer by [@kw-pr](https://github.com/kw-pr) in [#835](https://github.com/PHPOffice/PHPPresentation/pull/835)
- 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)
- 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)
- 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)
- 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)
- `Gd::setImageResource()` : Fixed when imagecreatetruecolor returns false by [@jaapdh](https://github.com/jaapdh) in [#843](https://github.com/PHPOffice/PHPPresentation/pull/843)
- 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)
- 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)
- `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)
- 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)
- 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)

## Miscellaneous

Expand Down
22 changes: 10 additions & 12 deletions src/PhpPresentation/Reader/PowerPoint2007.php
Original file line number Diff line number Diff line change
Expand Up @@ -492,9 +492,9 @@ protected function loadSlide(string $sPart, string $baseFile): void
file_put_contents($tmpBkgImg, $contentImg);
// Background
$oBackground = new Slide\Background\Image();
$oBackground->setPath($tmpBkgImg);
$extension = pathinfo( $pathImage, PATHINFO_EXTENSION );
$oBackground->setExtension($extension);
$oBackground
->setPath($tmpBkgImg)
->setExtension(pathinfo($pathImage, PATHINFO_EXTENSION));
// Slide Background
$oSlide = $this->oPhpPresentation->getActiveSlide();
$oSlide->setBackground($oBackground);
Expand Down Expand Up @@ -1326,25 +1326,23 @@ protected function loadParagraph(XMLReader $document, DOMElement $oElement, $oSh
);
}

// Font
$oElementFontFormat = null;
$oElementFontFormatComplexScript = $document->getElement('a:cs', $oElementrPr);
if (is_object($oElementFontFormatComplexScript)) {
$oText->getFont()->setFormat(Font::FORMAT_COMPLEX_SCRIPT);
$oElementFontFormat = $oElementFontFormatComplexScript;
}
$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;
}

$oElementFontFormatComplexScript = $document->getElement('a:cs', $oElementrPr);
if (is_object($oElementFontFormatComplexScript)) {
$oText->getFont()->setFormat(Font::FORMAT_COMPLEX_SCRIPT);
$oElementFontFormat = $oElementFontFormatComplexScript;
}
if (is_object($oElementFontFormat) && $oElementFontFormat->hasAttribute('typeface')) {
$oText->getFont()->setName($oElementFontFormat->getAttribute('typeface'));
}
Expand Down
9 changes: 4 additions & 5 deletions src/PhpPresentation/Slide/Background/Image.php
Original file line number Diff line number Diff line change
Expand Up @@ -89,12 +89,11 @@ public function setPath(string $pValue = '', bool $pVerifyFile = true)
* Set Extension.
*
* @param string $pValue File Extension
*
* @return self
*/
public function setExtension(string $pValue)
public function setExtension(string $pValue): self
{
$this->extension = $pValue;

return $this;
}

Expand All @@ -111,12 +110,12 @@ public function getFilename(): string
*/
public function getExtension(): string
{
if($this->extension){
if ($this->extension) {
return $this->extension;
}
$exploded = explode('.', $this->getFilename());
return $exploded[count($exploded) - 1];

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

/**
Expand Down
9 changes: 6 additions & 3 deletions src/PhpPresentation/Writer/PowerPoint2007/AbstractSlide.php
Original file line number Diff line number Diff line change
Expand Up @@ -678,18 +678,21 @@ protected function writeRunStyles(XMLWriter $objWriter, Run $element): void
$objWriter->startElement('a:' . $element->getFont()->getFormat());
$objWriter->writeAttribute('typeface', $element->getFont()->getName());
if ($element->getFont()->getPanose() !== '') {
$objWriter->writeAttribute('panose', $element->getFont()->getPanose());
$panose = array_map(function (string $value) {
return '0' . $value;
}, str_split($element->getFont()->getPanose()));

$objWriter->writeAttribute('panose', implode('', $panose));
}
$objWriter->writeAttributeIf(
$element->getFont()->getPitchFamily() !== 0,
'pitchFamily',
$element->getFont()->getPitchFamily()
);
$charset = $element->getFont()->getCharset();
$objWriter->writeAttributeIf(
$element->getFont()->getCharset() !== Font::CHARSET_DEFAULT,
'charset',
$charset
dechex($element->getFont()->getCharset())
);
$objWriter->endElement();

Expand Down
16 changes: 14 additions & 2 deletions tests/PhpPresentation/Tests/Slide/Background/ImageTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,19 +38,31 @@ public function testColor(): void
self::assertEmpty($object->getExtension());
self::assertEquals('background_' . $numSlide . '.', $object->getIndexedFilename($numSlide));

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

self::assertInstanceOf('PhpOffice\\PhpPresentation\\Slide\\Background\\Image', $object->setPath('', false));
self::assertInstanceOf(Image::class, $object->setPath('', false));
self::assertEquals('', $object->getPath());
self::assertEmpty($object->getFilename());
self::assertEmpty($object->getExtension());
self::assertEquals('background_' . $numSlide . '.', $object->getIndexedFilename($numSlide));
}

public function testExtension(): void
{
$object = new Image();
$imagePath = PHPPRESENTATION_TESTS_BASE_DIR . DIRECTORY_SEPARATOR . 'resources' . DIRECTORY_SEPARATOR . 'images' . DIRECTORY_SEPARATOR . 'PhpPresentationLogo.png';

self::assertEmpty($object->getExtension());
self::assertInstanceOf(Image::class, $object->setPath($imagePath));
self::assertEquals('png', $object->getExtension());
self::assertInstanceOf(Image::class, $object->setExtension('jpg'));
self::assertEquals('jpg', $object->getExtension());
}

public function testPathException(): void
{
$this->expectException(FileNotFoundException::class);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -886,7 +886,7 @@ public function testRichTextRunFontCharset(): void
$this->assertZipXmlAttributeExists('ppt/slides/slide1.xml', $latinElement, 'typeface');
$this->assertZipXmlAttributeEquals('ppt/slides/slide1.xml', $latinElement, 'typeface', 'Calibri');
$this->assertZipXmlAttributeExists('ppt/slides/slide1.xml', $latinElement, 'charset');
$this->assertZipXmlAttributeEquals('ppt/slides/slide1.xml', $latinElement, 'charset', '18');
$this->assertZipXmlAttributeEquals('ppt/slides/slide1.xml', $latinElement, 'charset', '12');
$this->assertZipXmlElementNotExists('ppt/slides/slide1.xml', $eastAsianElement);
$this->assertZipXmlElementNotExists('ppt/slides/slide1.xml', $complexScriptElement);
$this->assertIsSchemaECMA376Valid();
Expand All @@ -899,7 +899,7 @@ public function testRichTextRunFontCharset(): void
$this->assertZipXmlAttributeExists('ppt/slides/slide1.xml', $eastAsianElement, 'typeface');
$this->assertZipXmlAttributeEquals('ppt/slides/slide1.xml', $eastAsianElement, 'typeface', 'Calibri');
$this->assertZipXmlAttributeExists('ppt/slides/slide1.xml', $eastAsianElement, 'charset');
$this->assertZipXmlAttributeEquals('ppt/slides/slide1.xml', $eastAsianElement, 'charset', '18');
$this->assertZipXmlAttributeEquals('ppt/slides/slide1.xml', $eastAsianElement, 'charset', '12');
$this->assertZipXmlElementNotExists('ppt/slides/slide1.xml', $complexScriptElement);
$this->assertIsSchemaECMA376Valid();

Expand All @@ -912,7 +912,7 @@ public function testRichTextRunFontCharset(): void
$this->assertZipXmlAttributeExists('ppt/slides/slide1.xml', $complexScriptElement, 'typeface');
$this->assertZipXmlAttributeEquals('ppt/slides/slide1.xml', $complexScriptElement, 'typeface', 'Calibri');
$this->assertZipXmlAttributeExists('ppt/slides/slide1.xml', $complexScriptElement, 'charset');
$this->assertZipXmlAttributeEquals('ppt/slides/slide1.xml', $complexScriptElement, 'charset', '18');
$this->assertZipXmlAttributeEquals('ppt/slides/slide1.xml', $complexScriptElement, 'charset', '12');
$this->assertIsSchemaECMA376Valid();
}

Expand Down

0 comments on commit 82eefd6

Please sign in to comment.