Skip to content

Commit b31db88

Browse files
committed
#161 : Work from @vincentKool
1 parent f63b7f2 commit b31db88

18 files changed

+2743
-470
lines changed

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,9 +26,11 @@
2626
- ODPresentation & PowerPoint2007 Writer : Add Font Support For Chart Axis - @jrking4 GH-186
2727
- ODPresentation & PowerPoint2007 Writer : Support for video - @Progi1984 GH-123
2828
- ODPresentation & PowerPoint2007 Writer : Support for Visibility for slides - @Progi1984
29+
- PowerPoint2007 Reader : Layout Management - @vincentKool @Progi1984 GH-161
2930
- PowerPoint2007 Writer : Presentation with predefined View Type - @Progi1984 GH-120
3031
- PowerPoint2007 Writer : Implement alpha channel to Fills - @Dayjo GH-203 / @Progi1984 GH-215
3132
- PowerPoint2007 Writer : Implement Animations - @JewrassicPark GH-214 / @Progi1984 GH-217
33+
- PowerPoint2007 Writer : Layout Management - @vincentKool @Progi1984 GH-161
3234

3335
## 0.6.0 - 2016-01-24
3436

samples/Sample_19_SlideMaster.php

Lines changed: 101 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,101 @@
1+
<?php
2+
include_once 'Sample_Header.php';
3+
4+
use PhpOffice\PhpPresentation\PhpPresentation;
5+
use PhpOffice\PhpPresentation\Shape\Placeholder;
6+
use PhpOffice\PhpPresentation\Shape\RichText;
7+
use PhpOffice\PhpPresentation\Style\Alignment;
8+
use PhpOffice\PhpPresentation\Style\Color;
9+
use PhpOffice\PhpPresentation\Style\Fill;
10+
11+
// Create new PHPPresentation object
12+
echo date('H:i:s') . ' Create new PHPPresentation object' . EOL;
13+
$objPHPPresentation = new PhpPresentation();
14+
// Set properties
15+
echo date('H:i:s') . ' Set properties' . EOL;
16+
$objPHPPresentation->getDocumentProperties()->setCreator('PHPOffice')
17+
->setLastModifiedBy('PHPPresentation Team')
18+
->setTitle('Sample 01 SlideMaster')
19+
->setSubject('Sample 01 Subject')
20+
->setDescription('Sample 01 Description')
21+
->setKeywords('office 2007 openxml libreoffice odt php')
22+
->setCategory('Sample Category');
23+
24+
// Create slide
25+
echo date('H:i:s') . ' Create slide' . EOL;
26+
$currentSlide = $objPHPPresentation->getActiveSlide();
27+
28+
// Create a master layout
29+
echo date('H:i:s') . ' Create masterslide' . EOL;
30+
// Some decorative lines
31+
$oMasterSlide = $objPHPPresentation->getAllMasterSlides()[0];
32+
$shape = $oMasterSlide->createLineShape(0, 670, 960, 670)->getBorder()->setColor(new Color(Color::COLOR_RED))->setLineWidth(2);
33+
$shape = $oMasterSlide->createLineShape(0, 672, 960, 672)->getBorder()->setColor(new Color(Color::COLOR_WHITE))->setLineWidth(2);
34+
$shape = $oMasterSlide->createLineShape(0, 674, 960, 674)->getBorder()->setColor(new Color(Color::COLOR_DARKBLUE))->setLineWidth(2);
35+
// Title placeholder
36+
$shape = $oMasterSlide->createRichTextShape()->setWidthAndHeight(960, 80)->setOffsetX(0)->setOffsetY(60);
37+
$shape->getFill()->setFillType(Fill::FILL_SOLID)->setStartColor(new Color(Color::COLOR_BLUE));
38+
$shape->getActiveParagraph()->getAlignment()
39+
->setHorizontal(Alignment::HORIZONTAL_RIGHT)->setMarginLeft(200)->setMarginRight(50)
40+
->setVertical(Alignment::VERTICAL_CENTER);
41+
$shape->getShadow()->setVisible(true)
42+
->setDirection(90)
43+
->setDistance(10);
44+
$shape->setAutoFit(RichText::AUTOFIT_NORMAL);
45+
$textRun = $shape->createTextRun('Titel');
46+
$textRun->getFont()->setBold(true)->setSize(30)->setColor(new Color(Color::COLOR_WHITE));
47+
$shape->setPlaceHolder(new Placeholder(Placeholder::PH_TYPE_TITLE));
48+
// Date placeholder
49+
$shape = $oMasterSlide->createRichTextShape()->setWidthAndHeight(140, 38)->setOffsetX(50)->setOffsetY(680);
50+
$shape->getActiveParagraph()->getAlignment()
51+
->setHorizontal(Alignment::HORIZONTAL_LEFT)
52+
->setVertical(Alignment::VERTICAL_BASE);
53+
$shape->setAutoFit(RichText::AUTOFIT_NORMAL);
54+
$textRun = $shape->createTextRun('01-02-2000')->getFont()->setSize(18);
55+
$shape->setPlaceHolder(new Placeholder(Placeholder::PH_TYPE_DATETIME))->getPlaceholder()->setIdx(10);
56+
// Footer placeholder
57+
$shape = $oMasterSlide->createRichTextShape()->setWidthAndHeight(468, 38)->setOffsetX(246)->setOffsetY(680);
58+
$shape->getActiveParagraph()->getAlignment()
59+
->setHorizontal(Alignment::HORIZONTAL_CENTER)
60+
->setVertical(Alignment::VERTICAL_BASE);
61+
$shape->setAutoFit(RichText::AUTOFIT_NORMAL);
62+
$textRun = $shape->createTextRun('Placeholder for Footer')->getFont()->setSize(18);
63+
$shape->setPlaceHolder(new Placeholder(Placeholder::PH_TYPE_FOOTER))->getPlaceholder()->setIdx(11);
64+
// Slidenumber placeholder
65+
$shape = $oMasterSlide->createRichTextShape()->setWidthAndHeight(140, 38)->setOffsetX(770)->setOffsetY(680);
66+
$shape->getActiveParagraph()->getAlignment()
67+
->setHorizontal(Alignment::HORIZONTAL_RIGHT)
68+
->setVertical(Alignment::VERTICAL_BASE);
69+
$shape->setAutoFit(RichText::AUTOFIT_NORMAL);
70+
$textRun = $shape->createTextRun('')->getFont()->setSize(18);
71+
$shape->setPlaceHolder(new Placeholder(Placeholder::PH_TYPE_SLIDENUM))->getPlaceholder()->setIdx(12);
72+
73+
// Create a shape (drawing)
74+
echo date('H:i:s') . ' Create a shape (drawing)' . EOL;
75+
$shape = $currentSlide->createDrawingShape();
76+
$shape->setName('PHPPresentation logo')
77+
->setDescription('PHPPresentation logo')
78+
->setPath('./resources/phppowerpoint_logo.gif')
79+
->setHeight(36)
80+
->setOffsetX(10)
81+
->setOffsetY(10);
82+
$shape->getShadow()->setVisible(true)
83+
->setDirection(45)
84+
->setDistance(10);
85+
$shape->getHyperlink()->setUrl('https://github.com/PHPOffice/PHPPresentation/')->setTooltip('PHPPresentation');
86+
87+
// Create a shape (text)
88+
echo date('H:i:s') . ' Create a shape (rich text)' . EOL;
89+
$shape = $currentSlide->createRichTextShape()->setWidthAndHeight(960, 80)->setOffsetX(0)->setOffsetY(60);
90+
$shape->getFill()->setFillType(Fill::FILL_SOLID)->setStartColor(new Color(Color::COLOR_BLUE));
91+
$shape->getActiveParagraph()->getAlignment()
92+
->setHorizontal(Alignment::HORIZONTAL_RIGHT)->setMarginLeft(200)->setMarginRight(50)
93+
->setVertical(Alignment::VERTICAL_CENTER);
94+
$shape->setAutoFit(RichText::AUTOFIT_NORMAL);
95+
$shape->setPlaceHolder(new Placeholder(Placeholder::PH_TYPE_TITLE));
96+
97+
// Save file
98+
echo write($objPHPPresentation, basename(__FILE__, '.php'), $writers);
99+
if (!CLI) {
100+
include_once 'Sample_Footer.php';
101+
}

samples/Sample_Header.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -324,6 +324,7 @@ protected function displayShapeInfo(AbstractShape $oShape)
324324
$this->append('<dt>Hyperlink</dt><dd>'.ucfirst(var_export($oShape->hasHyperlink(), true)).'</dd>');
325325
$this->append('<dt>Fill</dt><dd>@Todo</dd>');
326326
$this->append('<dt>Border</dt><dd>@Todo</dd>');
327+
$this->append('<dt>IsPlaceholder</dt><dd>' . ($oShape->isPlaceholder() ? 'true' : 'false') . '</dd>');
327328
if($oShape instanceof MemoryDrawing) {
328329
$this->append('<dt>Name</dt><dd>'.$oShape->getName().'</dd>');
329330
$this->append('<dt>Description</dt><dd>'.$oShape->getDescription().'</dd>');

src/PhpPresentation/AbstractShape.php

Lines changed: 51 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
namespace PhpOffice\PhpPresentation;
1919

2020
use PhpOffice\PhpPresentation\Shape\Hyperlink;
21+
use PhpOffice\PhpPresentation\Shape\Placeholder;
2122
use PhpOffice\PhpPresentation\Style\Fill;
2223
use PhpOffice\PhpPresentation\Style\Shadow;
2324

@@ -96,6 +97,12 @@ abstract class AbstractShape implements ComparableInterface
9697
*/
9798
protected $hyperlink;
9899

100+
/**
101+
* PlaceHolder
102+
* @var \PhpOffice\PhpPresentation\Shape\Placeholder
103+
*/
104+
protected $placeholder;
105+
99106
/**
100107
* Hash index
101108
*
@@ -110,14 +117,14 @@ public function __construct()
110117
{
111118
// Initialise values
112119
$this->container = null;
113-
$this->offsetX = 0;
114-
$this->offsetY = 0;
115-
$this->width = 0;
116-
$this->height = 0;
117-
$this->rotation = 0;
118-
$this->fill = new Style\Fill();
119-
$this->border = new Style\Border();
120-
$this->shadow = new Style\Shadow();
120+
$this->offsetX = 0;
121+
$this->offsetY = 0;
122+
$this->width = 0;
123+
$this->height = 0;
124+
$this->rotation = 0;
125+
$this->fill = new Style\Fill();
126+
$this->border = new Style\Border();
127+
$this->shadow = new Style\Shadow();
121128

122129
$this->border->setLineStyle(Style\Border::LINE_NONE);
123130
}
@@ -128,9 +135,9 @@ public function __construct()
128135
public function __clone()
129136
{
130137
$this->container = null;
131-
$this->fill = clone $this->fill;
132-
$this->border = clone $this->border;
133-
$this->shadow = clone $this->shadow;
138+
$this->fill = clone $this->fill;
139+
$this->border = clone $this->border;
140+
$this->shadow = clone $this->shadow;
134141
}
135142

136143
/**
@@ -147,7 +154,7 @@ public function getContainer()
147154
* Set Container, Slide or Group
148155
*
149156
* @param \PhpOffice\PhpPresentation\ShapeContainerInterface $pValue
150-
* @param bool $pOverrideOld If a Slide has already been assigned, overwrite it and remove image from old Slide?
157+
* @param bool $pOverrideOld If a Slide has already been assigned, overwrite it and remove image from old Slide?
151158
* @throws \Exception
152159
* @return self
153160
*/
@@ -196,7 +203,7 @@ public function getOffsetX()
196203
/**
197204
* Set OffsetX
198205
*
199-
* @param int $pValue
206+
* @param int $pValue
200207
* @return self
201208
*/
202209
public function setOffsetX($pValue = 0)
@@ -219,7 +226,7 @@ public function getOffsetY()
219226
/**
220227
* Set OffsetY
221228
*
222-
* @param int $pValue
229+
* @param int $pValue
223230
* @return self
224231
*/
225232
public function setOffsetY($pValue = 0)
@@ -242,7 +249,7 @@ public function getWidth()
242249
/**
243250
* Set Width
244251
*
245-
* @param int $pValue
252+
* @param int $pValue
246253
* @return self
247254
*/
248255
public function setWidth($pValue = 0)
@@ -264,7 +271,7 @@ public function getHeight()
264271
/**
265272
* Set Height
266273
*
267-
* @param int $pValue
274+
* @param int $pValue
268275
* @return self
269276
*/
270277
public function setHeight($pValue = 0)
@@ -276,14 +283,14 @@ public function setHeight($pValue = 0)
276283
/**
277284
* Set width and height with proportional resize
278285
*
279-
* @param int $width
280-
* @param int $height
286+
* @param int $width
287+
* @param int $height
281288
* @example $objDrawing->setWidthAndHeight(160,120);
282289
* @return self
283290
*/
284291
public function setWidthAndHeight($width = 0, $height = 0)
285292
{
286-
$this->width = $width;
293+
$this->width = $width;
287294
$this->height = $height;
288295
return $this;
289296
}
@@ -301,7 +308,7 @@ public function getRotation()
301308
/**
302309
* Set Rotation
303310
*
304-
* @param int $pValue
311+
* @param int $pValue
305312
* @return self
306313
*/
307314
public function setRotation($pValue = 0)
@@ -407,7 +414,7 @@ public function setHyperlink(Hyperlink $pHyperlink = null)
407414
*/
408415
public function getHashCode()
409416
{
410-
return md5((is_object($this->container)?$this->container->getHashCode():'') . $this->offsetX . $this->offsetY . $this->width . $this->height . $this->rotation . (is_null($this->getFill()) ? '' : $this->getFill()->getHashCode()) . (is_null($this->shadow) ? '' : $this->shadow->getHashCode()) . (is_null($this->hyperlink) ? '' : $this->hyperlink->getHashCode()) . __CLASS__);
417+
return md5((is_object($this->container) ? $this->container->getHashCode() : '') . $this->offsetX . $this->offsetY . $this->width . $this->height . $this->rotation . (is_null($this->getFill()) ? '' : $this->getFill()->getHashCode()) . (is_null($this->shadow) ? '' : $this->shadow->getHashCode()) . (is_null($this->hyperlink) ? '' : $this->hyperlink->getHashCode()) . __CLASS__);
411418
}
412419

413420
/**
@@ -435,4 +442,27 @@ public function setHashIndex($value)
435442
{
436443
$this->hashIndex = $value;
437444
}
445+
446+
public function isPlaceholder()
447+
{
448+
return !is_null($this->placeholder);
449+
}
450+
451+
public function getPlaceholder()
452+
{
453+
if (!$this->isPlaceholder()) {
454+
return null;
455+
}
456+
return $this->placeholder;
457+
}
458+
459+
/**
460+
* @param \PhpOffice\PhpPresentation\Shape\Placeholder $placeholder
461+
* @return $this
462+
*/
463+
public function setPlaceHolder(Placeholder $placeholder)
464+
{
465+
$this->placeholder = $placeholder;
466+
return $this;
467+
}
438468
}

src/PhpPresentation/PhpPresentation.php

Lines changed: 45 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919

2020
use PhpOffice\PhpPresentation\Slide;
2121
use PhpOffice\PhpPresentation\Slide\Iterator;
22+
use PhpOffice\PhpPresentation\Slide\SlideMaster;
2223

2324
/**
2425
* PhpPresentation
@@ -60,6 +61,12 @@ class PhpPresentation
6061
*/
6162
protected $activeSlideIndex = 0;
6263

64+
/**
65+
* Collection of Master Slides
66+
* @var \ArrayObject|\PhpOffice\PhpPresentation\Slide\SlideMaster[]
67+
*/
68+
protected $slideMasters;
69+
6370
/**
6471
* Create a new PhpPresentation with one Slide
6572
*/
@@ -73,6 +80,9 @@ public function __construct()
7380
$this->setDocumentProperties(new DocumentProperties());
7481
$this->setPresentationProperties(new PresentationProperties());
7582
$this->setLayout(new DocumentLayout());
83+
84+
// Set empty Master & SlideLayout
85+
$this->createMasterSlide()->createSlideLayout();
7686
}
7787

7888
/**
@@ -97,7 +107,7 @@ public function setProperties(DocumentProperties $value)
97107
{
98108
return $this->setDocumentProperties($value);
99109
}
100-
110+
101111
/**
102112
* Get properties
103113
*
@@ -205,7 +215,7 @@ public function addSlide(Slide $slide = null)
205215
/**
206216
* Remove slide by index
207217
*
208-
* @param int $index Slide index
218+
* @param int $index Slide index
209219
* @throws \Exception
210220
* @return PhpPresentation
211221
*/
@@ -223,7 +233,7 @@ public function removeSlideByIndex($index = 0)
223233
/**
224234
* Get slide by index
225235
*
226-
* @param int $index Slide index
236+
* @param int $index Slide index
227237
* @return \PhpOffice\PhpPresentation\Slide
228238
* @throws \Exception
229239
*/
@@ -288,7 +298,7 @@ public function getActiveSlideIndex()
288298
/**
289299
* Set active slide index
290300
*
291-
* @param int $index Active slide index
301+
* @param int $index Active slide index
292302
* @throws \Exception
293303
* @return \PhpOffice\PhpPresentation\Slide
294304
*/
@@ -327,6 +337,32 @@ public function getSlideIterator()
327337
return new Iterator($this);
328338
}
329339

340+
/**
341+
* Create a masterslide and add it to this presentation
342+
*
343+
* @return \PhpOffice\PhpPresentation\Slide\SlideMaster
344+
*/
345+
public function createMasterSlide()
346+
{
347+
$newMasterSlide = new SlideMaster($this);
348+
$this->addMasterSlide($newMasterSlide);
349+
return $newMasterSlide;
350+
}
351+
352+
/**
353+
* Add masterslide
354+
*
355+
* @param \PhpOffice\PhpPresentation\Slide\SlideMaster $slide
356+
* @throws \Exception
357+
* @retun \PhpOffice\PhpPresentation\Slide\SlideMaster
358+
*/
359+
public function addMasterSlide(SlideMaster $slide = null)
360+
{
361+
$this->slideMasters[] = $slide;
362+
363+
return $slide;
364+
}
365+
330366
/**
331367
* Copy presentation (!= clone!)
332368
*
@@ -386,4 +422,9 @@ public function getZoom()
386422
{
387423
return $this->getPresentationProperties()->getZoom();
388424
}
425+
426+
public function getAllMasterSlides()
427+
{
428+
return $this->slideMasters;
429+
}
389430
}

0 commit comments

Comments
 (0)