Skip to content

Commit 6e9f78e

Browse files
committed
#246 : PowerPoint : Reading Slide Size
1 parent 5d23e65 commit 6e9f78e

File tree

6 files changed

+54
-19
lines changed

6 files changed

+54
-19
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
- ODPresentation & PowerPoint2007 Writer : Support for video - @Progi1984 GH-123
2929
- ODPresentation & PowerPoint2007 Writer : Support for Visibility for slides - @Progi1984
3030
- PowerPoint2007 Reader : Layout Management - @vincentKool @Progi1984 GH-161
31+
- PowerPoint2007 Reader : Slide size - @loverslcn @Progi1984 GH-246
3132
- PowerPoint2007 Reader : Bullet Color - @Progi1984 GH-257
3233
- PowerPoint2007 Reader : Line Spacing - @Progi1984 GH-257
3334
- PowerPoint2007 Writer : Presentation with predefined View Type - @Progi1984 GH-120

samples/Sample_Header.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -260,6 +260,7 @@ protected function displayPhpPresentationInfo(PhpPresentation $oPHPPpt)
260260
$this->append('<div class="infoBlk" id="divPhpPresentationInfo">');
261261
$this->append('<dl>');
262262
$this->append('<dt>Number of slides</dt><dd>'.$oPHPPpt->getSlideCount().'</dd>');
263+
$this->append('<dt>Document Layout Name</dt><dd>'.(empty($oPHPPpt->getLayout()->getDocumentLayout()) ? 'Custom' : $oPHPPpt->getLayout()->getDocumentLayout()).'</dd>');
263264
$this->append('<dt>Document Layout Height</dt><dd>'.$oPHPPpt->getLayout()->getCY(DocumentLayout::UNIT_MILLIMETER).' mm</dd>');
264265
$this->append('<dt>Document Layout Width</dt><dd>'.$oPHPPpt->getLayout()->getCX(DocumentLayout::UNIT_MILLIMETER).' mm</dd>');
265266
$this->append('<dt>Properties : Category</dt><dd>'.$oPHPPpt->getDocumentProperties()->getCategory().'</dd>');

src/PhpPresentation/DocumentLayout.php

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -150,7 +150,7 @@ public function setDocumentLayout($pValue = self::LAYOUT_SCREEN_4X3, $isLandscap
150150
/**
151151
* Get Document Layout cx
152152
*
153-
* @param float $unit
153+
* @param string $unit
154154
* @return integer
155155
*/
156156
public function getCX($unit = self::UNIT_EMU)
@@ -161,7 +161,7 @@ public function getCX($unit = self::UNIT_EMU)
161161
/**
162162
* Get Document Layout cy
163163
*
164-
* @param float $unit
164+
* @param string $unit
165165
* @return integer
166166
*/
167167
public function getCY($unit = self::UNIT_EMU)
@@ -173,8 +173,8 @@ public function getCY($unit = self::UNIT_EMU)
173173
* Get Document Layout cx
174174
*
175175
* @param float $value
176-
* @param float $unit
177-
* @return integer
176+
* @param string $unit
177+
* @return DocumentLayout
178178
*/
179179
public function setCX($value, $unit = self::UNIT_EMU)
180180
{
@@ -187,8 +187,8 @@ public function setCX($value, $unit = self::UNIT_EMU)
187187
* Get Document Layout cy
188188
*
189189
* @param float $value
190-
* @param float $unit
191-
* @return integer
190+
* @param string $unit
191+
* @return DocumentLayout
192192
*/
193193
public function setCY($value, $unit = self::UNIT_EMU)
194194
{
@@ -202,6 +202,7 @@ public function setCY($value, $unit = self::UNIT_EMU)
202202
* @param float $value
203203
* @param string $fromUnit
204204
* @param string $toUnit
205+
* @return float
205206
*/
206207
protected function convertUnit($value, $fromUnit, $toUnit)
207208
{

src/PhpPresentation/Reader/PowerPoint2007.php

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717

1818
namespace PhpOffice\PhpPresentation\Reader;
1919

20+
use PhpOffice\PhpPresentation\DocumentLayout;
2021
use PhpOffice\PhpPresentation\Shape\RichText\Paragraph;
2122
use PhpOffice\PhpPresentation\Slide\AbstractSlide;
2223
use PhpOffice\PhpPresentation\Shape\Placeholder;
@@ -148,12 +149,37 @@ protected function loadFile($pFilename)
148149

149150
$pptPresentation = $this->oZip->getFromName('ppt/presentation.xml');
150151
if ($pptPresentation !== false) {
152+
$this->loadDocumentLayout($pptPresentation);
151153
$this->loadSlides($pptPresentation);
152154
}
153155

154156
return $this->oPhpPresentation;
155157
}
156158

159+
/**
160+
* Read Document Layout
161+
* @param $sPart
162+
*/
163+
protected function loadDocumentLayout($sPart)
164+
{
165+
$xmlReader = new XMLReader();
166+
if ($xmlReader->getDomFromString($sPart)) {
167+
foreach ($xmlReader->getElements('/p:presentation/p:sldSz') as $oElement) {
168+
$type = $oElement->getAttribute('type');
169+
$oLayout = $this->oPhpPresentation->getLayout();
170+
if ($type == DocumentLayout::LAYOUT_CUSTOM) {
171+
$oLayout->setCX($oElement->getAttribute('cx'));
172+
$oLayout->setCY($oElement->getAttribute('cy'));
173+
} else {
174+
$oLayout->setDocumentLayout($type, true);
175+
if ($oElement->getAttribute('cx') < $oElement->getAttribute('cy')) {
176+
$oLayout->setDocumentLayout($type, false);
177+
}
178+
}
179+
}
180+
}
181+
}
182+
157183
/**
158184
* Read Document Properties
159185
* @param string $sPart

src/PhpPresentation/Writer/PowerPoint2007/PptPresentation.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ public function render()
7575
$objWriter->writeAttribute('cy', '9144000');
7676
$objWriter->endElement();
7777

78-
$objWriter->writeRaw(' <p:defaultTextStyle>
78+
$objWriter->writeRaw('<p:defaultTextStyle>
7979
<a:defPPr>
8080
<a:defRPr lang="fr-FR"/>
8181
</a:defPPr>

tests/PhpPresentation/Tests/Reader/PowerPoint2007Test.php

Lines changed: 18 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717

1818
namespace PhpOffice\PhpPresentation\Tests\Reader;
1919

20+
use PhpOffice\PhpPresentation\DocumentLayout;
2021
use PhpOffice\PhpPresentation\Reader\PowerPoint2007;
2122
use PhpOffice\PhpPresentation\Style\Alignment;
2223
use PhpOffice\PhpPresentation\Style\Bullet;
@@ -83,14 +84,19 @@ public function testLoadFile01()
8384
$oPhpPresentation = $object->load($file);
8485
$this->assertInstanceOf('PhpOffice\\PhpPresentation\\PhpPresentation', $oPhpPresentation);
8586
// Document Properties
86-
$this->assertEquals('PHPOffice', $oPhpPresentation->getProperties()->getCreator());
87-
$this->assertEquals('PHPPresentation Team', $oPhpPresentation->getProperties()->getLastModifiedBy());
88-
$this->assertEquals('Sample 02 Title', $oPhpPresentation->getProperties()->getTitle());
89-
$this->assertEquals('Sample 02 Subject', $oPhpPresentation->getProperties()->getSubject());
90-
$this->assertEquals('Sample 02 Description', $oPhpPresentation->getProperties()->getDescription());
91-
$this->assertEquals('office 2007 openxml libreoffice odt php', $oPhpPresentation->getProperties()->getKeywords());
92-
$this->assertEquals('Sample Category', $oPhpPresentation->getProperties()->getCategory());
93-
//
87+
$this->assertEquals('PHPOffice', $oPhpPresentation->getDocumentProperties()->getCreator());
88+
$this->assertEquals('PHPPresentation Team', $oPhpPresentation->getDocumentProperties()->getLastModifiedBy());
89+
$this->assertEquals('Sample 02 Title', $oPhpPresentation->getDocumentProperties()->getTitle());
90+
$this->assertEquals('Sample 02 Subject', $oPhpPresentation->getDocumentProperties()->getSubject());
91+
$this->assertEquals('Sample 02 Description', $oPhpPresentation->getDocumentProperties()->getDescription());
92+
$this->assertEquals('office 2007 openxml libreoffice odt php', $oPhpPresentation->getDocumentProperties()->getKeywords());
93+
$this->assertEquals('Sample Category', $oPhpPresentation->getDocumentProperties()->getCategory());
94+
// Document Layout
95+
$this->assertEquals(DocumentLayout::LAYOUT_SCREEN_4X3, $oPhpPresentation->getLayout()->getDocumentLayout());
96+
$this->assertEquals(254, $oPhpPresentation->getLayout()->getCX(DocumentLayout::UNIT_MILLIMETER));
97+
$this->assertEquals(190.5, $oPhpPresentation->getLayout()->getCY(DocumentLayout::UNIT_MILLIMETER));
98+
99+
// Slides
94100
$this->assertCount(4, $oPhpPresentation->getAllSlides());
95101

96102
// Slide 1
@@ -469,14 +475,14 @@ public function testMarkAsFinal()
469475
$object = new PowerPoint2007();
470476
$oPhpPresentation = $object->load($file);
471477
$this->assertInstanceOf('PhpOffice\\PhpPresentation\\PhpPresentation', $oPhpPresentation);
472-
$this->assertFalse($oPhpPresentation->isMarkedAsFinal());
478+
$this->assertFalse($oPhpPresentation->getPresentationProperties()->isMarkedAsFinal());
473479

474480

475481
$file = PHPPRESENTATION_TESTS_BASE_DIR . '/resources/files/PPTX_MarkAsFinal.pptx';
476482
$object = new PowerPoint2007();
477483
$oPhpPresentation = $object->load($file);
478484
$this->assertInstanceOf('PhpOffice\\PhpPresentation\\PhpPresentation', $oPhpPresentation);
479-
$this->assertTrue($oPhpPresentation->isMarkedAsFinal());
485+
$this->assertTrue($oPhpPresentation->getPresentationProperties()->isMarkedAsFinal());
480486
}
481487

482488
public function testZoom()
@@ -485,14 +491,14 @@ public function testZoom()
485491
$object = new PowerPoint2007();
486492
$oPhpPresentation = $object->load($file);
487493
$this->assertInstanceOf('PhpOffice\\PhpPresentation\\PhpPresentation', $oPhpPresentation);
488-
$this->assertEquals(1, $oPhpPresentation->getZoom());
494+
$this->assertEquals(1, $oPhpPresentation->getPresentationProperties()->getZoom());
489495

490496

491497
$file = PHPPRESENTATION_TESTS_BASE_DIR . '/resources/files/PPTX_Zoom.pptx';
492498
$object = new PowerPoint2007();
493499
$oPhpPresentation = $object->load($file);
494500
$this->assertInstanceOf('PhpOffice\\PhpPresentation\\PhpPresentation', $oPhpPresentation);
495-
$this->assertEquals(2.68, $oPhpPresentation->getZoom());
501+
$this->assertEquals(2.68, $oPhpPresentation->getPresentationProperties()->getZoom());
496502
}
497503

498504
public function testSlideLayout()

0 commit comments

Comments
 (0)