1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* This file is part of PHPPresentation - A pure PHP library for reading and writing |
4
|
|
|
* presentations documents. |
5
|
|
|
* |
6
|
|
|
* PHPPresentation is free software distributed under the terms of the GNU Lesser |
7
|
|
|
* General Public License version 3 as published by the Free Software Foundation. |
8
|
|
|
* |
9
|
|
|
* For the full copyright and license information, please read the LICENSE |
10
|
|
|
* file that was distributed with this source code. For the full list of |
11
|
|
|
* contributors, visit https://github.com/PHPOffice/PHPPresentation/contributors. |
12
|
|
|
* |
13
|
|
|
* @link https://github.com/PHPOffice/PHPPresentation |
14
|
|
|
* @copyright 2009-2015 PHPPresentation contributors |
15
|
|
|
* @license http://www.gnu.org/licenses/lgpl.txt LGPL version 3 |
16
|
|
|
*/ |
17
|
|
|
|
18
|
|
|
namespace PhpOffice\PhpPresentation; |
19
|
|
|
|
20
|
|
|
use PhpOffice\PhpPresentation\GeometryCalculator; |
21
|
|
|
use PhpOffice\PhpPresentation\Shape\Chart; |
22
|
|
|
use PhpOffice\PhpPresentation\Shape\Drawing; |
23
|
|
|
use PhpOffice\PhpPresentation\Shape\Group; |
24
|
|
|
use PhpOffice\PhpPresentation\Shape\Line; |
25
|
|
|
use PhpOffice\PhpPresentation\Shape\RichText; |
26
|
|
|
use PhpOffice\PhpPresentation\Shape\Table; |
27
|
|
|
use PhpOffice\PhpPresentation\Slide\AbstractBackground; |
28
|
|
|
use PhpOffice\PhpPresentation\Slide\Layout; |
29
|
|
|
use PhpOffice\PhpPresentation\Slide\Note; |
30
|
|
|
use PhpOffice\PhpPresentation\Slide\Transition; |
31
|
|
|
|
32
|
|
|
/** |
33
|
|
|
* Slide class |
34
|
|
|
*/ |
35
|
|
|
class Slide implements ComparableInterface, ShapeContainerInterface |
36
|
|
|
{ |
37
|
|
|
/** |
38
|
|
|
* Parent presentation |
39
|
|
|
* |
40
|
|
|
* @var PhpPresentation |
41
|
|
|
*/ |
42
|
|
|
private $parent; |
43
|
|
|
|
44
|
|
|
/** |
45
|
|
|
* Collection of shapes |
46
|
|
|
* |
47
|
|
|
* @var \ArrayObject|\PhpOffice\PhpPresentation\AbstractShape[] |
48
|
|
|
*/ |
49
|
|
|
private $shapeCollection = null; |
50
|
|
|
|
51
|
|
|
/** |
52
|
|
|
* Slide identifier |
53
|
|
|
* |
54
|
|
|
* @var string |
55
|
|
|
*/ |
56
|
|
|
private $identifier; |
57
|
|
|
|
58
|
|
|
/** |
59
|
|
|
* Slide layout |
60
|
|
|
* |
61
|
|
|
* @var string |
62
|
|
|
*/ |
63
|
|
|
private $slideLayout; |
64
|
|
|
|
65
|
|
|
/** |
66
|
|
|
* Slide master id |
67
|
|
|
* |
68
|
|
|
* @var integer |
69
|
|
|
*/ |
70
|
|
|
private $slideMasterId = 1; |
71
|
|
|
|
72
|
|
|
/** |
73
|
|
|
* |
74
|
|
|
* @var \PhpOffice\PhpPresentation\Slide\Note |
75
|
|
|
*/ |
76
|
|
|
private $slideNote; |
77
|
|
|
/** |
78
|
|
|
* |
79
|
|
|
* @var \PhpOffice\PhpPresentation\Slide\Transition |
80
|
|
|
*/ |
81
|
|
|
private $slideTransition; |
82
|
|
|
|
83
|
|
|
/** |
84
|
|
|
* |
85
|
|
|
* @var \PhpOffice\PhpPresentation\Slide\Animation |
86
|
|
|
*/ |
87
|
|
|
private $animations = ARRAY(); |
|
|
|
|
88
|
|
|
|
89
|
|
|
/** |
90
|
|
|
* Hash index |
91
|
|
|
* |
92
|
|
|
* @var string |
93
|
|
|
*/ |
94
|
|
|
private $hashIndex; |
95
|
|
|
|
96
|
|
|
/** |
97
|
|
|
* Offset X |
98
|
|
|
* |
99
|
|
|
* @var int |
100
|
|
|
*/ |
101
|
|
|
protected $offsetX; |
102
|
|
|
|
103
|
|
|
/** |
104
|
|
|
* Offset Y |
105
|
|
|
* |
106
|
|
|
* @var int |
107
|
|
|
*/ |
108
|
|
|
protected $offsetY; |
109
|
|
|
|
110
|
|
|
/** |
111
|
|
|
* Extent X |
112
|
|
|
* |
113
|
|
|
* @var int |
114
|
|
|
*/ |
115
|
|
|
protected $extentX; |
116
|
|
|
|
117
|
|
|
/** |
118
|
|
|
* Extent Y |
119
|
|
|
* |
120
|
|
|
* @var int |
121
|
|
|
*/ |
122
|
|
|
protected $extentY; |
123
|
|
|
|
124
|
|
|
/** |
125
|
|
|
* Name of the title |
126
|
|
|
* |
127
|
|
|
* @var string |
128
|
|
|
*/ |
129
|
|
|
protected $name; |
130
|
|
|
|
131
|
|
|
/** |
132
|
|
|
* Background of the slide |
133
|
|
|
* |
134
|
|
|
* @var AbstractBackground |
135
|
|
|
*/ |
136
|
|
|
protected $background; |
137
|
|
|
|
138
|
|
|
/** |
139
|
|
|
* Create a new slide |
140
|
|
|
* |
141
|
|
|
* @param PhpPresentation $pParent |
142
|
|
|
*/ |
143
|
153 |
|
public function __construct(PhpPresentation $pParent = null) |
144
|
|
|
{ |
145
|
|
|
// Set parent |
146
|
153 |
|
$this->parent = $pParent; |
147
|
|
|
|
148
|
153 |
|
$this->slideLayout = Slide\Layout::BLANK; |
149
|
|
|
|
150
|
|
|
// Shape collection |
151
|
153 |
|
$this->shapeCollection = new \ArrayObject(); |
152
|
|
|
|
153
|
|
|
// Set identifier |
154
|
153 |
|
$this->identifier = md5(rand(0, 9999) . time()); |
155
|
153 |
|
} |
156
|
|
|
|
157
|
|
|
/** |
158
|
|
|
* Get collection of shapes |
159
|
|
|
* |
160
|
|
|
* @return \ArrayObject|\PhpOffice\PhpPresentation\AbstractShape[] |
161
|
|
|
*/ |
162
|
121 |
|
public function getShapeCollection() |
163
|
|
|
{ |
164
|
121 |
|
return $this->shapeCollection; |
165
|
|
|
} |
166
|
|
|
|
167
|
|
|
/** |
168
|
|
|
* Add shape to slide |
169
|
|
|
* |
170
|
|
|
* @param \PhpOffice\PhpPresentation\AbstractShape $shape |
171
|
|
|
* @return \PhpOffice\PhpPresentation\AbstractShape |
172
|
|
|
*/ |
173
|
106 |
|
public function addShape(AbstractShape $shape) |
174
|
|
|
{ |
175
|
106 |
|
$shape->setContainer($this); |
176
|
|
|
|
177
|
106 |
|
return $shape; |
178
|
|
|
} |
179
|
|
|
|
180
|
|
|
/** |
181
|
|
|
* Create rich text shape |
182
|
|
|
* |
183
|
|
|
* @return \PhpOffice\PhpPresentation\Shape\RichText |
184
|
|
|
*/ |
185
|
40 |
|
public function createRichTextShape() |
186
|
|
|
{ |
187
|
40 |
|
$shape = new RichText(); |
188
|
40 |
|
$this->addShape($shape); |
189
|
|
|
|
190
|
40 |
|
return $shape; |
191
|
|
|
} |
192
|
|
|
|
193
|
|
|
/** |
194
|
|
|
* Create line shape |
195
|
|
|
* |
196
|
|
|
* @param int $fromX Starting point x offset |
197
|
|
|
* @param int $fromY Starting point y offset |
198
|
|
|
* @param int $toX Ending point x offset |
199
|
|
|
* @param int $toY Ending point y offset |
200
|
|
|
* @return \PhpOffice\PhpPresentation\Shape\Line |
201
|
|
|
*/ |
202
|
3 |
|
public function createLineShape($fromX, $fromY, $toX, $toY) |
203
|
|
|
{ |
204
|
3 |
|
$shape = new Line($fromX, $fromY, $toX, $toY); |
205
|
3 |
|
$this->addShape($shape); |
206
|
|
|
|
207
|
3 |
|
return $shape; |
208
|
|
|
} |
209
|
|
|
|
210
|
|
|
/** |
211
|
|
|
* Create chart shape |
212
|
|
|
* |
213
|
|
|
* @return \PhpOffice\PhpPresentation\Shape\Chart |
214
|
|
|
*/ |
215
|
34 |
|
public function createChartShape() |
216
|
|
|
{ |
217
|
34 |
|
$shape = new Chart(); |
218
|
34 |
|
$this->addShape($shape); |
219
|
|
|
|
220
|
34 |
|
return $shape; |
221
|
|
|
} |
222
|
|
|
|
223
|
|
|
/** |
224
|
|
|
* Create drawing shape |
225
|
|
|
* |
226
|
|
|
* @return \PhpOffice\PhpPresentation\Shape\Drawing |
227
|
|
|
*/ |
228
|
11 |
|
public function createDrawingShape() |
229
|
|
|
{ |
230
|
11 |
|
$shape = new Drawing(); |
231
|
11 |
|
$this->addShape($shape); |
232
|
|
|
|
233
|
11 |
|
return $shape; |
234
|
|
|
} |
235
|
|
|
|
236
|
|
|
/** |
237
|
|
|
* Create table shape |
238
|
|
|
* |
239
|
|
|
* @param int $columns Number of columns |
240
|
|
|
* @return \PhpOffice\PhpPresentation\Shape\Table |
241
|
|
|
*/ |
242
|
17 |
|
public function createTableShape($columns = 1) |
243
|
|
|
{ |
244
|
17 |
|
$shape = new Table($columns); |
245
|
17 |
|
$this->addShape($shape); |
246
|
|
|
|
247
|
17 |
|
return $shape; |
248
|
|
|
} |
249
|
|
|
|
250
|
|
|
/** |
251
|
|
|
* Creates a group within this slide |
252
|
|
|
* |
253
|
|
|
* @return \PhpOffice\PhpPresentation\Shape\Group |
254
|
|
|
*/ |
255
|
4 |
|
public function createGroup() |
256
|
|
|
{ |
257
|
4 |
|
$shape = new Group(); |
258
|
4 |
|
$this->addShape($shape); |
259
|
|
|
|
260
|
4 |
|
return $shape; |
261
|
|
|
} |
262
|
|
|
|
263
|
|
|
/** |
264
|
|
|
* Get parent |
265
|
|
|
* |
266
|
|
|
* @return PhpPresentation |
267
|
|
|
*/ |
268
|
61 |
|
public function getParent() |
269
|
|
|
{ |
270
|
61 |
|
return $this->parent; |
271
|
|
|
} |
272
|
|
|
|
273
|
|
|
/** |
274
|
|
|
* Re-bind parent |
275
|
|
|
* |
276
|
|
|
* @param \PhpOffice\PhpPresentation\PhpPresentation $parent |
277
|
|
|
* @return \PhpOffice\PhpPresentation\Slide |
278
|
|
|
*/ |
279
|
2 |
|
public function rebindParent(PhpPresentation $parent) |
280
|
|
|
{ |
281
|
2 |
|
$this->parent->removeSlideByIndex($this->parent->getIndex($this)); |
282
|
2 |
|
$this->parent = $parent; |
283
|
|
|
|
284
|
2 |
|
return $this; |
285
|
|
|
} |
286
|
|
|
|
287
|
|
|
/** |
288
|
|
|
* Get slide layout |
289
|
|
|
* |
290
|
|
|
* @return string |
291
|
|
|
*/ |
292
|
61 |
|
public function getSlideLayout() |
293
|
|
|
{ |
294
|
61 |
|
return $this->slideLayout; |
295
|
|
|
} |
296
|
|
|
|
297
|
|
|
/** |
298
|
|
|
* Set slide layout |
299
|
|
|
* |
300
|
|
|
* @param string $layout |
301
|
|
|
* @return \PhpOffice\PhpPresentation\Slide |
302
|
|
|
*/ |
303
|
4 |
|
public function setSlideLayout($layout = Layout::BLANK) |
304
|
|
|
{ |
305
|
4 |
|
$this->slideLayout = $layout; |
306
|
|
|
|
307
|
4 |
|
return $this; |
308
|
|
|
} |
309
|
|
|
|
310
|
|
|
/** |
311
|
|
|
* Get slide master id |
312
|
|
|
* |
313
|
|
|
* @return int |
314
|
|
|
*/ |
315
|
64 |
|
public function getSlideMasterId() |
316
|
|
|
{ |
317
|
64 |
|
return $this->slideMasterId; |
318
|
|
|
} |
319
|
|
|
|
320
|
|
|
/** |
321
|
|
|
* Set slide master id |
322
|
|
|
* |
323
|
|
|
* @param int $masterId |
324
|
|
|
* @return \PhpOffice\PhpPresentation\Slide |
325
|
|
|
*/ |
326
|
1 |
|
public function setSlideMasterId($masterId = 1) |
327
|
|
|
{ |
328
|
1 |
|
$this->slideMasterId = $masterId; |
329
|
|
|
|
330
|
1 |
|
return $this; |
331
|
|
|
} |
332
|
|
|
|
333
|
|
|
/** |
334
|
|
|
* Get hash code |
335
|
|
|
* |
336
|
|
|
* @return string Hash code |
337
|
|
|
*/ |
338
|
85 |
|
public function getHashCode() |
339
|
|
|
{ |
340
|
85 |
|
return md5($this->identifier . __CLASS__); |
341
|
|
|
} |
342
|
|
|
|
343
|
|
|
/** |
344
|
|
|
* Get hash index |
345
|
|
|
* |
346
|
|
|
* Note that this index may vary during script execution! Only reliable moment is |
347
|
|
|
* while doing a write of a workbook and when changes are not allowed. |
348
|
|
|
* |
349
|
|
|
* @return string Hash index |
350
|
|
|
*/ |
351
|
4 |
|
public function getHashIndex() |
352
|
|
|
{ |
353
|
4 |
|
return $this->hashIndex; |
354
|
|
|
} |
355
|
|
|
|
356
|
|
|
/** |
357
|
|
|
* Set hash index |
358
|
|
|
* |
359
|
|
|
* Note that this index may vary during script execution! Only reliable moment is |
360
|
|
|
* while doing a write of a workbook and when changes are not allowed. |
361
|
|
|
* |
362
|
|
|
* @param string $value Hash index |
363
|
|
|
*/ |
364
|
4 |
|
public function setHashIndex($value) |
365
|
|
|
{ |
366
|
4 |
|
$this->hashIndex = $value; |
367
|
4 |
|
} |
368
|
|
|
|
369
|
|
|
/** |
370
|
|
|
* Copy slide (!= clone!) |
371
|
|
|
* |
372
|
|
|
* @return \PhpOffice\PhpPresentation\Slide |
373
|
|
|
*/ |
374
|
1 |
|
public function copy() |
375
|
|
|
{ |
376
|
1 |
|
$copied = clone $this; |
377
|
|
|
|
378
|
1 |
|
return $copied; |
379
|
|
|
} |
380
|
|
|
|
381
|
|
|
/** |
382
|
|
|
* Get X Offset |
383
|
|
|
* |
384
|
|
|
* @return int |
385
|
|
|
*/ |
386
|
61 |
|
public function getOffsetX() |
387
|
|
|
{ |
388
|
61 |
|
if ($this->offsetX === null) { |
389
|
61 |
|
$offsets = GeometryCalculator::calculateOffsets($this); |
390
|
61 |
|
$this->offsetX = $offsets[GeometryCalculator::X]; |
391
|
61 |
|
$this->offsetY = $offsets[GeometryCalculator::Y]; |
392
|
|
|
} |
393
|
61 |
|
return $this->offsetX; |
394
|
|
|
} |
395
|
|
|
|
396
|
|
|
/** |
397
|
|
|
* Get Y Offset |
398
|
|
|
* |
399
|
|
|
* @return int |
400
|
|
|
*/ |
401
|
61 |
|
public function getOffsetY() |
402
|
|
|
{ |
403
|
61 |
|
if ($this->offsetY === null) { |
404
|
1 |
|
$offsets = GeometryCalculator::calculateOffsets($this); |
405
|
1 |
|
$this->offsetX = $offsets[GeometryCalculator::X]; |
406
|
1 |
|
$this->offsetY = $offsets[GeometryCalculator::Y]; |
407
|
|
|
} |
408
|
61 |
|
return $this->offsetY; |
409
|
|
|
} |
410
|
|
|
|
411
|
|
|
/** |
412
|
|
|
* Get X Extent |
413
|
|
|
* |
414
|
|
|
* @return int |
415
|
|
|
*/ |
416
|
61 |
|
public function getExtentX() |
417
|
|
|
{ |
418
|
61 |
|
if ($this->extentX === null) { |
419
|
61 |
|
$extents = GeometryCalculator::calculateExtents($this); |
420
|
61 |
|
$this->extentX = $extents[GeometryCalculator::X]; |
421
|
61 |
|
$this->extentY = $extents[GeometryCalculator::Y]; |
422
|
|
|
} |
423
|
61 |
|
return $this->extentX; |
424
|
|
|
} |
425
|
|
|
|
426
|
|
|
/** |
427
|
|
|
* Get Y Extent |
428
|
|
|
* |
429
|
|
|
* @return int |
430
|
|
|
*/ |
431
|
61 |
|
public function getExtentY() |
432
|
|
|
{ |
433
|
61 |
|
if ($this->extentY === null) { |
434
|
1 |
|
$extents = GeometryCalculator::calculateExtents($this); |
435
|
1 |
|
$this->extentX = $extents[GeometryCalculator::X]; |
436
|
1 |
|
$this->extentY = $extents[GeometryCalculator::Y]; |
437
|
|
|
} |
438
|
61 |
|
return $this->extentY; |
439
|
|
|
} |
440
|
|
|
|
441
|
|
|
/** |
442
|
|
|
* |
443
|
|
|
* @return \PhpOffice\PhpPresentation\Slide\Note |
444
|
|
|
*/ |
445
|
101 |
|
public function getNote() |
446
|
|
|
{ |
447
|
101 |
|
if (is_null($this->slideNote)) { |
448
|
101 |
|
$this->setNote(); |
449
|
|
|
} |
450
|
101 |
|
return $this->slideNote; |
451
|
|
|
} |
452
|
|
|
|
453
|
|
|
/** |
454
|
|
|
* |
455
|
|
|
* @param \PhpOffice\PhpPresentation\Slide\Note $note |
456
|
|
|
* @return \PhpOffice\PhpPresentation\Slide |
457
|
|
|
*/ |
458
|
102 |
|
public function setNote(Note $note = null) |
459
|
|
|
{ |
460
|
102 |
|
$this->slideNote = (is_null($note) ? new Note() : $note); |
461
|
102 |
|
$this->slideNote->setParent($this); |
462
|
|
|
|
463
|
102 |
|
return $this; |
464
|
|
|
} |
465
|
|
|
|
466
|
|
|
/** |
467
|
|
|
* |
468
|
|
|
* @return \PhpOffice\PhpPresentation\Slide\Transition |
469
|
|
|
*/ |
470
|
102 |
|
public function getTransition() |
471
|
|
|
{ |
472
|
102 |
|
return $this->slideTransition; |
473
|
|
|
} |
474
|
|
|
|
475
|
|
|
/** |
476
|
|
|
* |
477
|
|
|
* @param \PhpOffice\PhpPresentation\Slide\Transition $transition |
478
|
|
|
* @return \PhpOffice\PhpPresentation\Slide |
479
|
|
|
*/ |
480
|
3 |
|
public function setTransition(Transition $transition = null) |
481
|
|
|
{ |
482
|
3 |
|
$this->slideTransition = $transition; |
483
|
|
|
|
484
|
3 |
|
return $this; |
485
|
|
|
} |
486
|
|
|
|
487
|
|
|
/** |
488
|
|
|
* Get the name of the slide |
489
|
|
|
* @return string |
490
|
|
|
*/ |
491
|
43 |
|
public function getName() |
492
|
|
|
{ |
493
|
43 |
|
return $this->name; |
494
|
|
|
} |
495
|
|
|
|
496
|
|
|
/** |
497
|
|
|
* Set the name of the slide |
498
|
|
|
* @param string $name |
499
|
|
|
* @return $this |
500
|
|
|
*/ |
501
|
5 |
|
public function setName($name = null) |
502
|
|
|
{ |
503
|
5 |
|
$this->name = $name; |
504
|
5 |
|
return $this; |
505
|
|
|
} |
506
|
|
|
|
507
|
|
|
/** |
508
|
|
|
* @return AbstractBackground |
509
|
|
|
*/ |
510
|
102 |
|
public function getBackground() |
511
|
|
|
{ |
512
|
102 |
|
return $this->background; |
513
|
|
|
} |
514
|
|
|
|
515
|
|
|
/** |
516
|
|
|
* @param AbstractBackground $background |
517
|
|
|
* @return $this |
518
|
|
|
*/ |
519
|
4 |
|
public function setBackground(AbstractBackground $background = null) |
520
|
|
|
{ |
521
|
4 |
|
$this->background = $background; |
522
|
4 |
|
return $this; |
523
|
|
|
} |
524
|
|
|
|
525
|
|
|
/** |
526
|
|
|
* Add an animation to the slide |
527
|
|
|
* |
528
|
|
|
* @param \PhpOffice\PhpPresentation\Slide\Animation |
529
|
|
|
* @return \PhpOffice\PhpPresentation\Slide\Animation |
530
|
|
|
*/ |
531
|
|
|
public function addAnimation($animation){ |
532
|
|
|
$this->animations[] = $animation; |
533
|
|
|
return $animation; |
534
|
|
|
} |
535
|
|
|
|
536
|
|
|
/** |
537
|
|
|
* Get collection of animations |
538
|
|
|
* |
539
|
|
|
* @return \PhpOffice\PhpPresentation\Slide\Animation |
540
|
|
|
*/ |
541
|
|
|
|
542
|
60 |
|
public function getAnimations(){ |
543
|
60 |
|
return $this->animations; |
544
|
|
|
} |
545
|
|
|
} |
546
|
|
|
|