Skip to content

Commit 5de5693

Browse files
committed
#161 : Improvements (Reading & Writing Background & some Styles)
1 parent 60cfde7 commit 5de5693

22 files changed

+947
-530
lines changed

samples/Sample_19_SlideMaster.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,9 @@
1515
echo date('H:i:s') . ' Set properties' . EOL;
1616
$objPHPPresentation->getDocumentProperties()->setCreator('PHPOffice')
1717
->setLastModifiedBy('PHPPresentation Team')
18-
->setTitle('Sample 01 SlideMaster')
19-
->setSubject('Sample 01 Subject')
20-
->setDescription('Sample 01 Description')
18+
->setTitle('Sample 19 SlideMaster')
19+
->setSubject('Sample 19 Subject')
20+
->setDescription('Sample 19 Description')
2121
->setKeywords('office 2007 openxml libreoffice odt php')
2222
->setCategory('Sample Category');
2323

@@ -84,7 +84,7 @@
8484
->setDistance(10);
8585
$shape->getHyperlink()->setUrl('https://github.com/PHPOffice/PHPPresentation/')->setTooltip('PHPPresentation');
8686

87-
// Create a shape (text)
87+
// Create a shape (text) linked to a PlaceHolder
8888
echo date('H:i:s') . ' Create a shape (rich text)' . EOL;
8989
$shape = $currentSlide->createRichTextShape()->setWidthAndHeight(960, 80)->setOffsetX(0)->setOffsetY(60);
9090
$shape->getFill()->setFillType(Fill::FILL_SOLID)->setStartColor(new Color(Color::COLOR_BLUE));

src/PhpPresentation/PhpPresentation.php

Lines changed: 20 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,9 @@ class PhpPresentation
7272
*/
7373
public function __construct()
7474
{
75+
// Set empty Master & SlideLayout
76+
$this->createMasterSlide()->createSlideLayout();
77+
7578
// Initialise slide collection and add one slide
7679
$this->createSlide();
7780
$this->setActiveSlideIndex();
@@ -80,9 +83,6 @@ public function __construct()
8083
$this->setDocumentProperties(new DocumentProperties());
8184
$this->setPresentationProperties(new PresentationProperties());
8285
$this->setLayout(new DocumentLayout());
83-
84-
// Set empty Master & SlideLayout
85-
$this->createMasterSlide()->createSlideLayout();
8686
}
8787

8888
/**
@@ -259,11 +259,11 @@ public function getAllSlides()
259259
/**
260260
* Get index for slide
261261
*
262-
* @param \PhpOffice\PhpPresentation\Slide $slide
262+
* @param \PhpOffice\PhpPresentation\Slide\AbstractSlide $slide
263263
* @return int
264264
* @throws \Exception
265265
*/
266-
public function getIndex(Slide $slide)
266+
public function getIndex(Slide\AbstractSlide $slide)
267267
{
268268
$index = null;
269269
foreach ($this->slideCollection as $key => $value) {
@@ -423,8 +423,23 @@ public function getZoom()
423423
return $this->getPresentationProperties()->getZoom();
424424
}
425425

426+
/**
427+
* @return \ArrayObject|Slide\SlideMaster[]
428+
*/
426429
public function getAllMasterSlides()
427430
{
428431
return $this->slideMasters;
429432
}
433+
434+
/**
435+
* @param \ArrayObject|Slide\SlideMaster[] $slideMasters
436+
* @return $this
437+
*/
438+
public function setAllMasterSlides($slideMasters = array())
439+
{
440+
if ($slideMasters instanceof \ArrayObject || is_array($slideMasters)) {
441+
$this->slideMasters = $slideMasters;
442+
}
443+
return $this;
444+
}
430445
}

src/PhpPresentation/Reader/PowerPoint2007.php

Lines changed: 169 additions & 24 deletions
Large diffs are not rendered by default.

src/PhpPresentation/Slide.php

Lines changed: 6 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -20,11 +20,9 @@
2020
use PhpOffice\PhpPresentation\Shape\Chart;
2121
use PhpOffice\PhpPresentation\Shape\RichText;
2222
use PhpOffice\PhpPresentation\Shape\Table;
23-
use PhpOffice\PhpPresentation\Slide\AbstractBackground;
2423
use PhpOffice\PhpPresentation\Slide\AbstractSlide;
25-
use PhpOffice\PhpPresentation\Slide\Layout;
2624
use PhpOffice\PhpPresentation\Slide\Note;
27-
use PhpOffice\PhpPresentation\Slide\Transition;
25+
use PhpOffice\PhpPresentation\Slide\SlideLayout;
2826

2927
/**
3028
* Slide class
@@ -40,7 +38,7 @@ class Slide extends AbstractSlide implements ComparableInterface, ShapeContainer
4038
/**
4139
* Slide layout
4240
*
43-
* @var string
41+
* @var SlideLayout
4442
*/
4543
private $slideLayout;
4644

@@ -79,20 +77,16 @@ public function __construct(PhpPresentation $pParent = null)
7977
{
8078
// Set parent
8179
$this->parent = $pParent;
82-
83-
$this->slideLayout = Slide\Layout::BLANK;
84-
8580
// Shape collection
8681
$this->shapeCollection = new \ArrayObject();
87-
8882
// Set identifier
8983
$this->identifier = md5(rand(0, 9999) . time());
9084
}
9185

9286
/**
9387
* Get slide layout
9488
*
95-
* @return string
89+
* @return SlideLayout
9690
*/
9791
public function getSlideLayout()
9892
{
@@ -102,13 +96,12 @@ public function getSlideLayout()
10296
/**
10397
* Set slide layout
10498
*
105-
* @param string $layout
99+
* @param SlideLayout $layout
106100
* @return \PhpOffice\PhpPresentation\Slide
107101
*/
108-
public function setSlideLayout($layout = Layout::BLANK)
102+
public function setSlideLayout(SlideLayout $layout)
109103
{
110104
$this->slideLayout = $layout;
111-
112105
return $this;
113106
}
114107

@@ -225,7 +218,7 @@ public function addAnimation($animation)
225218
/**
226219
* Get collection of animations
227220
*
228-
* @return \PhpOffice\PhpPresentation\Slide\Animation
221+
* @return \PhpOffice\PhpPresentation\Slide\Animation[]
229222
*/
230223
public function getAnimations()
231224
{

src/PhpPresentation/Slide/AbstractSlide.php

Lines changed: 22 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
use PhpOffice\PhpPresentation\GeometryCalculator;
2222
use PhpOffice\PhpPresentation\PhpPresentation;
2323
use PhpOffice\PhpPresentation\Shape\Chart;
24-
use PhpOffice\PhpPresentation\Shape\Drawing;
24+
use PhpOffice\PhpPresentation\Shape\Drawing\File;
2525
use PhpOffice\PhpPresentation\Shape\Group;
2626
use PhpOffice\PhpPresentation\Shape\Line;
2727
use PhpOffice\PhpPresentation\Shape\RichText;
@@ -31,23 +31,16 @@
3131

3232
abstract class AbstractSlide implements ComparableInterface, ShapeContainerInterface
3333
{
34+
/**
35+
* @var string
36+
*/
3437
protected $relsIndex;
3538
/**
3639
*
3740
* @var \PhpOffice\PhpPresentation\Slide\Transition
3841
*/
3942
protected $slideTransition;
4043

41-
public function getRelsIndex()
42-
{
43-
return $this->relsIndex;
44-
}
45-
46-
public function setRelsIndex($indexName)
47-
{
48-
$this->relsIndex = $indexName;
49-
}
50-
5144
/**
5245
* Collection of shapes
5346
*
@@ -264,11 +257,11 @@ public function createChartShape()
264257
/**
265258
* Create drawing shape
266259
*
267-
* @return \PhpOffice\PhpPresentation\Shape\Drawing
260+
* @return \PhpOffice\PhpPresentation\Shape\Drawing\File
268261
*/
269262
public function createDrawingShape()
270263
{
271-
$shape = new Drawing();
264+
$shape = new File();
272265
$this->addShape($shape);
273266
return $shape;
274267
}
@@ -358,4 +351,20 @@ public function setTransition(Transition $transition = null)
358351
$this->slideTransition = $transition;
359352
return $this;
360353
}
354+
355+
/**
356+
* @return string
357+
*/
358+
public function getRelsIndex()
359+
{
360+
return $this->relsIndex;
361+
}
362+
363+
/**
364+
* @param string $indexName
365+
*/
366+
public function setRelsIndex($indexName)
367+
{
368+
$this->relsIndex = $indexName;
369+
}
361370
}
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
<?php
2+
3+
namespace PhpOffice\PhpPresentation\Slide\Background;
4+
5+
use PhpOffice\PhpPresentation\Slide\AbstractBackground;
6+
use PhpOffice\PhpPresentation\Style\SchemeColor as StyleSchemeColor;
7+
8+
class SchemeColor extends AbstractBackground
9+
{
10+
/**
11+
* @var StyleSchemeColor
12+
*/
13+
protected $schemeColor;
14+
15+
/**
16+
* @param StyleSchemeColor|null $color
17+
* @return $this
18+
*/
19+
public function setSchemeColor(StyleSchemeColor $color = null)
20+
{
21+
$this->schemeColor = $color;
22+
return $this;
23+
}
24+
25+
/**
26+
* @return StyleSchemeColor
27+
*/
28+
public function getSchemeColor()
29+
{
30+
return $this->schemeColor;
31+
}
32+
}

src/PhpPresentation/Slide/SlideLayout.php

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818

1919
use PhpOffice\PhpPresentation\ComparableInterface;
2020
use PhpOffice\PhpPresentation\ShapeContainerInterface;
21+
use PhpOffice\PhpPresentation\Style\ColorMap;
2122

2223
class SlideLayout extends AbstractSlide implements ComparableInterface, ShapeContainerInterface
2324
{
@@ -34,6 +35,24 @@ class SlideLayout extends AbstractSlide implements ComparableInterface, ShapeCon
3435
* @var int
3536
*/
3637
public $layoutNr;
38+
/**
39+
* Slide layout ID (should not be used by user code!)
40+
*
41+
* @var int
42+
*/
43+
public $layoutId;
44+
/**
45+
* Slide layout ID (should not be used by user code!)
46+
*
47+
* @var int
48+
*/
49+
protected $layoutName;
50+
/**
51+
* Mapping of colors to the theme
52+
*
53+
* @var \PhpOffice\PhpPresentation\Style\ColorMap
54+
*/
55+
public $colorMap;
3756

3857
/**
3958
* Create a new slideLayout
@@ -48,5 +67,25 @@ public function __construct(SlideMaster $pSlideMaster)
4867
$this->shapeCollection = new \ArrayObject();
4968
// Set identifier
5069
$this->identifier = md5(rand(0, 9999) . time());
70+
// Set a basic colorMap
71+
$this->colorMap = new ColorMap();
72+
}
73+
74+
/**
75+
* @return int
76+
*/
77+
public function getLayoutName()
78+
{
79+
return $this->layoutName;
80+
}
81+
82+
/**
83+
* @param int $layoutName
84+
* @return SlideLayout
85+
*/
86+
public function setLayoutName($layoutName)
87+
{
88+
$this->layoutName = $layoutName;
89+
return $this;
5190
}
5291
}

0 commit comments

Comments
 (0)