Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions docs/changes/1.3.0.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)

11 changes: 8 additions & 3 deletions src/PhpPresentation/Writer/PowerPoint2007/ContentTypes.php
Original file line number Diff line number Diff line change
Expand Up @@ -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');
Expand Down Expand Up @@ -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);
}
Expand All @@ -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;

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
<?php

declare(strict_types=1);

namespace PhpPresentation\Tests\Writer\PowerPoint2007;

use PhpOffice\PhpPresentation\PhpPresentation;
use PhpOffice\PhpPresentation\IOFactory;
use PHPUnit\Framework\TestCase;

class ContentTypesTest extends TestCase
{
public function testSvgDefaultContentTypeIsWritten(): void
{
$presentation = new PhpPresentation();

$pptxFile = tempnam(sys_get_temp_dir(), 'pptx_svg_test_');
$writer = IOFactory::createWriter($presentation, 'PowerPoint2007');
$writer->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'
);
}
}
Loading