From 476fe540fadd2b9e26182099225d31c09eb4bf01 Mon Sep 17 00:00:00 2001 From: Sean Date: Mon, 8 Sep 2025 17:17:03 +0100 Subject: [PATCH 1/4] fix svgs --- .../Writer/PowerPoint2007/ContentTypes.php | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/src/PhpPresentation/Writer/PowerPoint2007/ContentTypes.php b/src/PhpPresentation/Writer/PowerPoint2007/ContentTypes.php index 87e4d5b57..0a89c37cc 100644 --- a/src/PhpPresentation/Writer/PowerPoint2007/ContentTypes.php +++ b/src/PhpPresentation/Writer/PowerPoint2007/ContentTypes.php @@ -49,8 +49,7 @@ public function render(): ZipInterface // XML $this->writeDefaultContentType($objWriter, 'xml', 'application/xml'); - // SVG - $this->writeDefaultContentType($objWriter, 'svg', 'image/svg+xml'); + // SVG will pre-register in $aMediaContentTypes // Presentation $this->writeOverrideContentType($objWriter, '/ppt/presentation.xml', 'application/vnd.openxmlformats-officedocument.presentationml.presentation.main+xml'); @@ -106,11 +105,12 @@ public function render(): ZipInterface // Add media content-types $aMediaContentTypes = []; - // GIF, JPEG, PNG + // GIF, JPEG, PNG, SVG $aMediaContentTypes['gif'] = 'image/gif'; $aMediaContentTypes['jpg'] = 'image/jpeg'; $aMediaContentTypes['jpeg'] = 'image/jpeg'; $aMediaContentTypes['png'] = 'image/png'; + $aMediaContentTypes['svg'] = 'image/svg+xml'; foreach ($aMediaContentTypes as $key => $value) { $this->writeDefaultContentType($objWriter, $key, $value); } @@ -133,6 +133,11 @@ public function render(): ZipInterface $extension = strtolower($shapeIndex->getExtension()); $mimeType = $shapeIndex->getMimeType(); + // Normalize any odd returns (some environments report "image/svg") + if ($extension === 'svg') { + $mimeType = 'image/svg+xml'; + } + if (!isset($aMediaContentTypes[$extension])) { $aMediaContentTypes[$extension] = $mimeType; From 6ae84da911b8127831901c05468b319419757aba Mon Sep 17 00:00:00 2001 From: Sean Date: Mon, 22 Sep 2025 10:19:15 +0100 Subject: [PATCH 2/4] update changelog 1.2.0 --- docs/changes/1.2.0.md | 1 + 1 file changed, 1 insertion(+) diff --git a/docs/changes/1.2.0.md b/docs/changes/1.2.0.md index 4247f38b8..3be80952c 100644 --- a/docs/changes/1.2.0.md +++ b/docs/changes/1.2.0.md @@ -30,6 +30,7 @@ - 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) - PhpOffice\PhpPresentation\Style\TextStyle : Fixed typo for default indent by [@Progi1984](https://github.com/Progi1984) in [#857](https://github.com/PHPOffice/PHPPresentation/pull/857) +- Fixed adding custom SVGs by [@seanlynchwv](http://github.com/seanlynchwv) in [#881](https://github.com/PHPOffice/PHPPresentation/pull/881) ## Miscellaneous - CI: Added ODFValidator by [@Progi1984](https://github.com/Progi1984) fixing [#678](https://github.com/PHPOffice/PHPWord/issues/678) in [#653](https://github.com/PHPOffice/PHPWord/pull/653) From 2d77d5cb329460605164d6fa4f4742c731dd550f Mon Sep 17 00:00:00 2001 From: Sean Date: Mon, 17 Nov 2025 12:37:27 +0000 Subject: [PATCH 3/4] update changelog --- docs/changes/1.2.0.md | 1 - docs/changes/1.3.0.md | 1 + 2 files changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/changes/1.2.0.md b/docs/changes/1.2.0.md index 3be80952c..4247f38b8 100644 --- a/docs/changes/1.2.0.md +++ b/docs/changes/1.2.0.md @@ -30,7 +30,6 @@ - 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) - PhpOffice\PhpPresentation\Style\TextStyle : Fixed typo for default indent by [@Progi1984](https://github.com/Progi1984) in [#857](https://github.com/PHPOffice/PHPPresentation/pull/857) -- Fixed adding custom SVGs by [@seanlynchwv](http://github.com/seanlynchwv) in [#881](https://github.com/PHPOffice/PHPPresentation/pull/881) ## Miscellaneous - CI: Added ODFValidator by [@Progi1984](https://github.com/Progi1984) fixing [#678](https://github.com/PHPOffice/PHPWord/issues/678) in [#653](https://github.com/PHPOffice/PHPWord/pull/653) diff --git a/docs/changes/1.3.0.md b/docs/changes/1.3.0.md index 33b870b7a..cbf2bd7de 100644 --- a/docs/changes/1.3.0.md +++ b/docs/changes/1.3.0.md @@ -6,4 +6,5 @@ - `phpoffice/phpspreadsheet`: Allow version 5.0 by [@seanlynchwv](http://github.com/seanlynchwv) in [#879](https://github.com/PHPOffice/PHPPresentation/pull/879) ## Bug fixes +- Fixed adding custom SVGs by [@seanlynchwv](http://github.com/seanlynchwv) in [#881](https://github.com/PHPOffice/PHPPresentation/pull/881) From 880a7a41c95797a319243a64ace5135d49bc5929 Mon Sep 17 00:00:00 2001 From: Sean Date: Mon, 17 Nov 2025 14:41:51 +0000 Subject: [PATCH 4/4] add new test --- .../PowerPoint2007/ContentTypesTest.php | 48 +++++++++++++++++++ 1 file changed, 48 insertions(+) create mode 100644 tests/PhpPresentation/Tests/Writer/PowerPoint2007/ContentTypesTest.php diff --git a/tests/PhpPresentation/Tests/Writer/PowerPoint2007/ContentTypesTest.php b/tests/PhpPresentation/Tests/Writer/PowerPoint2007/ContentTypesTest.php new file mode 100644 index 000000000..0576bf2a0 --- /dev/null +++ b/tests/PhpPresentation/Tests/Writer/PowerPoint2007/ContentTypesTest.php @@ -0,0 +1,48 @@ +save($pptxFile); + + $zip = new \ZipArchive(); + $this->assertTrue( + $zip->open($pptxFile), + 'Could not open generated PPTX as ZipArchive' + ); + + $contentTypesXml = $zip->getFromName('[Content_Types].xml'); + $zip->close(); + @unlink($pptxFile); + + $this->assertIsString( + $contentTypesXml, + '[Content_Types].xml not found in archive' + ); + + $this->assertStringContainsString( + 'Extension="svg"', + $contentTypesXml, + 'SVG extension not registered in [Content_Types].xml' + ); + + $this->assertStringContainsString( + 'image/svg+xml', + $contentTypesXml, + 'SVG MIME type not registered correctly in [Content_Types].xml' + ); + } +}