|
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
|
|
|
namespace PhpOffice\PhpPresentation\Slide; |
|
18
|
|
|
|
|
19
|
|
|
use PhpOffice\PhpPresentation\AbstractShape; |
|
20
|
|
|
use PhpOffice\PhpPresentation\ComparableInterface; |
|
21
|
|
|
use PhpOffice\PhpPresentation\GeometryCalculator; |
|
22
|
|
|
use PhpOffice\PhpPresentation\PhpPresentation; |
|
23
|
|
|
use PhpOffice\PhpPresentation\Shape\Chart; |
|
24
|
|
|
use PhpOffice\PhpPresentation\Shape\Drawing\File; |
|
25
|
|
|
use PhpOffice\PhpPresentation\Shape\Group; |
|
26
|
|
|
use PhpOffice\PhpPresentation\Shape\Line; |
|
27
|
|
|
use PhpOffice\PhpPresentation\Shape\RichText; |
|
28
|
|
|
use PhpOffice\PhpPresentation\Shape\Table; |
|
29
|
|
|
use PhpOffice\PhpPresentation\ShapeContainerInterface; |
|
30
|
|
|
use PhpOffice\PhpPresentation\Slide; |
|
31
|
|
|
|
|
32
|
|
|
abstract class AbstractSlide implements ComparableInterface, ShapeContainerInterface |
|
33
|
|
|
{ |
|
34
|
|
|
/** |
|
35
|
|
|
* @var string |
|
36
|
|
|
*/ |
|
37
|
|
|
protected $relsIndex; |
|
38
|
|
|
/** |
|
39
|
|
|
* |
|
40
|
|
|
* @var \PhpOffice\PhpPresentation\Slide\Transition |
|
41
|
|
|
*/ |
|
42
|
|
|
protected $slideTransition; |
|
43
|
|
|
|
|
44
|
|
|
/** |
|
45
|
|
|
* Collection of shapes |
|
46
|
|
|
* |
|
47
|
|
|
* @var \ArrayObject|\PhpOffice\PhpPresentation\AbstractShape[] |
|
48
|
|
|
*/ |
|
49
|
|
|
protected $shapeCollection = null; |
|
50
|
|
|
/** |
|
51
|
|
|
* Extent Y |
|
52
|
|
|
* |
|
53
|
|
|
* @var int |
|
54
|
|
|
*/ |
|
55
|
|
|
protected $extentY; |
|
56
|
|
|
/** |
|
57
|
|
|
* Extent X |
|
58
|
|
|
* |
|
59
|
|
|
* @var int |
|
60
|
|
|
*/ |
|
61
|
|
|
protected $extentX; |
|
62
|
|
|
/** |
|
63
|
|
|
* Offset X |
|
64
|
|
|
* |
|
65
|
|
|
* @var int |
|
66
|
|
|
*/ |
|
67
|
|
|
protected $offsetX; |
|
68
|
|
|
/** |
|
69
|
|
|
* Offset Y |
|
70
|
|
|
* |
|
71
|
|
|
* @var int |
|
72
|
|
|
*/ |
|
73
|
|
|
protected $offsetY; |
|
74
|
|
|
/** |
|
75
|
|
|
* Slide identifier |
|
76
|
|
|
* |
|
77
|
|
|
* @var string |
|
78
|
|
|
*/ |
|
79
|
|
|
protected $identifier; |
|
80
|
|
|
/** |
|
81
|
|
|
* Hash index |
|
82
|
|
|
* |
|
83
|
|
|
* @var string |
|
84
|
|
|
*/ |
|
85
|
|
|
protected $hashIndex; |
|
86
|
|
|
/** |
|
87
|
|
|
* Parent presentation |
|
88
|
|
|
* |
|
89
|
|
|
* @var PhpPresentation |
|
90
|
|
|
*/ |
|
91
|
|
|
protected $parent; |
|
92
|
|
|
/** |
|
93
|
|
|
* Background of the slide |
|
94
|
|
|
* |
|
95
|
|
|
* @var AbstractBackground |
|
96
|
|
|
*/ |
|
97
|
|
|
protected $background; |
|
98
|
|
|
|
|
99
|
|
|
/** |
|
100
|
|
|
* Get collection of shapes |
|
101
|
|
|
* |
|
102
|
|
|
* @return \ArrayObject|\PhpOffice\PhpPresentation\AbstractShape[] |
|
103
|
|
|
*/ |
|
104
|
177 |
|
public function getShapeCollection() |
|
105
|
|
|
{ |
|
106
|
177 |
|
return $this->shapeCollection; |
|
107
|
|
|
} |
|
108
|
|
|
|
|
109
|
|
|
/** |
|
110
|
|
|
* Get collection of shapes |
|
111
|
|
|
* |
|
112
|
|
|
* @return AbstractSlide |
|
113
|
|
|
*/ |
|
114
|
|
|
public function setShapeCollection($shapeCollection = array()) |
|
115
|
|
|
{ |
|
116
|
|
|
$this->shapeCollection = $shapeCollection; |
|
117
|
|
|
return $this; |
|
118
|
|
|
} |
|
119
|
|
|
|
|
120
|
|
|
/** |
|
121
|
|
|
* Add shape to slide |
|
122
|
|
|
* |
|
123
|
|
|
* @param \PhpOffice\PhpPresentation\AbstractShape $shape |
|
124
|
|
|
* @return \PhpOffice\PhpPresentation\AbstractShape |
|
125
|
|
|
*/ |
|
126
|
141 |
|
public function addShape(AbstractShape $shape) |
|
127
|
|
|
{ |
|
128
|
141 |
|
$shape->setContainer($this); |
|
129
|
141 |
|
return $shape; |
|
130
|
|
|
} |
|
131
|
|
|
|
|
132
|
|
|
/** |
|
133
|
|
|
* Get X Offset |
|
134
|
|
|
* |
|
135
|
|
|
* @return int |
|
136
|
|
|
*/ |
|
137
|
96 |
|
public function getOffsetX() |
|
138
|
|
|
{ |
|
139
|
96 |
|
if ($this->offsetX === null) { |
|
140
|
96 |
|
$offsets = GeometryCalculator::calculateOffsets($this); |
|
141
|
96 |
|
$this->offsetX = $offsets[GeometryCalculator::X]; |
|
142
|
96 |
|
$this->offsetY = $offsets[GeometryCalculator::Y]; |
|
143
|
|
|
} |
|
144
|
96 |
|
return $this->offsetX; |
|
145
|
|
|
} |
|
146
|
|
|
|
|
147
|
|
|
/** |
|
148
|
|
|
* Get Y Offset |
|
149
|
|
|
* |
|
150
|
|
|
* @return int |
|
151
|
|
|
*/ |
|
152
|
96 |
|
public function getOffsetY() |
|
153
|
|
|
{ |
|
154
|
96 |
|
if ($this->offsetY === null) { |
|
155
|
1 |
|
$offsets = GeometryCalculator::calculateOffsets($this); |
|
156
|
1 |
|
$this->offsetX = $offsets[GeometryCalculator::X]; |
|
157
|
1 |
|
$this->offsetY = $offsets[GeometryCalculator::Y]; |
|
158
|
|
|
} |
|
159
|
96 |
|
return $this->offsetY; |
|
160
|
|
|
} |
|
161
|
|
|
|
|
162
|
|
|
/** |
|
163
|
|
|
* Get X Extent |
|
164
|
|
|
* |
|
165
|
|
|
* @return int |
|
166
|
|
|
*/ |
|
167
|
96 |
|
public function getExtentX() |
|
168
|
|
|
{ |
|
169
|
96 |
|
if ($this->extentX === null) { |
|
170
|
96 |
|
$extents = GeometryCalculator::calculateExtents($this); |
|
171
|
96 |
|
$this->extentX = $extents[GeometryCalculator::X]; |
|
172
|
96 |
|
$this->extentY = $extents[GeometryCalculator::Y]; |
|
173
|
|
|
} |
|
174
|
96 |
|
return $this->extentX; |
|
175
|
|
|
} |
|
176
|
|
|
|
|
177
|
|
|
/** |
|
178
|
|
|
* Get Y Extent |
|
179
|
|
|
* |
|
180
|
|
|
* @return int |
|
181
|
|
|
*/ |
|
182
|
96 |
|
public function getExtentY() |
|
183
|
|
|
{ |
|
184
|
96 |
|
if ($this->extentY === null) { |
|
185
|
1 |
|
$extents = GeometryCalculator::calculateExtents($this); |
|
186
|
1 |
|
$this->extentX = $extents[GeometryCalculator::X]; |
|
187
|
1 |
|
$this->extentY = $extents[GeometryCalculator::Y]; |
|
188
|
|
|
} |
|
189
|
96 |
|
return $this->extentY; |
|
190
|
|
|
} |
|
191
|
|
|
|
|
192
|
|
|
/** |
|
193
|
|
|
* Get hash code |
|
194
|
|
|
* |
|
195
|
|
|
* @return string Hash code |
|
196
|
|
|
*/ |
|
197
|
135 |
|
public function getHashCode() |
|
198
|
|
|
{ |
|
199
|
135 |
|
return md5($this->identifier . __CLASS__); |
|
200
|
|
|
} |
|
201
|
|
|
|
|
202
|
|
|
/** |
|
203
|
|
|
* Get hash index |
|
204
|
|
|
* |
|
205
|
|
|
* Note that this index may vary during script execution! Only reliable moment is |
|
206
|
|
|
* while doing a write of a workbook and when changes are not allowed. |
|
207
|
|
|
* |
|
208
|
|
|
* @return string Hash index |
|
209
|
|
|
*/ |
|
210
|
4 |
|
public function getHashIndex() |
|
211
|
|
|
{ |
|
212
|
4 |
|
return $this->hashIndex; |
|
213
|
|
|
} |
|
214
|
|
|
|
|
215
|
|
|
/** |
|
216
|
|
|
* Set hash index |
|
217
|
|
|
* |
|
218
|
|
|
* Note that this index may vary during script execution! Only reliable moment is |
|
219
|
|
|
* while doing a write of a workbook and when changes are not allowed. |
|
220
|
|
|
* |
|
221
|
|
|
* @param string $value Hash index |
|
222
|
|
|
*/ |
|
223
|
4 |
|
public function setHashIndex($value) |
|
224
|
|
|
{ |
|
225
|
4 |
|
$this->hashIndex = $value; |
|
226
|
4 |
|
} |
|
227
|
|
|
|
|
228
|
|
|
/** |
|
229
|
|
|
* Create rich text shape |
|
230
|
|
|
* |
|
231
|
|
|
* @return \PhpOffice\PhpPresentation\Shape\RichText |
|
232
|
|
|
*/ |
|
233
|
43 |
|
public function createRichTextShape() |
|
234
|
|
|
{ |
|
235
|
43 |
|
$shape = new RichText(); |
|
236
|
43 |
|
$this->addShape($shape); |
|
237
|
43 |
|
return $shape; |
|
238
|
|
|
} |
|
239
|
|
|
|
|
240
|
|
|
/** |
|
241
|
|
|
* Create line shape |
|
242
|
|
|
* |
|
243
|
|
|
* @param int $fromX Starting point x offset |
|
244
|
|
|
* @param int $fromY Starting point y offset |
|
245
|
|
|
* @param int $toX Ending point x offset |
|
246
|
|
|
* @param int $toY Ending point y offset |
|
247
|
|
|
* @return \PhpOffice\PhpPresentation\Shape\Line |
|
248
|
|
|
*/ |
|
249
|
2 |
|
public function createLineShape($fromX, $fromY, $toX, $toY) |
|
250
|
|
|
{ |
|
251
|
2 |
|
$shape = new Line($fromX, $fromY, $toX, $toY); |
|
252
|
2 |
|
$this->addShape($shape); |
|
253
|
2 |
|
return $shape; |
|
254
|
|
|
} |
|
255
|
|
|
|
|
256
|
|
|
/** |
|
257
|
|
|
* Create chart shape |
|
258
|
|
|
* |
|
259
|
|
|
* @return \PhpOffice\PhpPresentation\Shape\Chart |
|
260
|
|
|
*/ |
|
261
|
46 |
|
public function createChartShape() |
|
262
|
|
|
{ |
|
263
|
46 |
|
$shape = new Chart(); |
|
264
|
46 |
|
$this->addShape($shape); |
|
265
|
46 |
|
return $shape; |
|
266
|
|
|
} |
|
267
|
|
|
|
|
268
|
|
|
/** |
|
269
|
|
|
* Create drawing shape |
|
270
|
|
|
* |
|
271
|
|
|
* @return \PhpOffice\PhpPresentation\Shape\Drawing\File |
|
272
|
|
|
*/ |
|
273
|
13 |
|
public function createDrawingShape() |
|
274
|
|
|
{ |
|
275
|
13 |
|
$shape = new File(); |
|
276
|
13 |
|
$this->addShape($shape); |
|
277
|
13 |
|
return $shape; |
|
278
|
|
|
} |
|
279
|
|
|
|
|
280
|
|
|
/** |
|
281
|
|
|
* Create table shape |
|
282
|
|
|
* |
|
283
|
|
|
* @param int $columns Number of columns |
|
284
|
|
|
* @return \PhpOffice\PhpPresentation\Shape\Table |
|
285
|
|
|
*/ |
|
286
|
16 |
|
public function createTableShape($columns = 1) |
|
287
|
|
|
{ |
|
288
|
16 |
|
$shape = new Table($columns); |
|
289
|
16 |
|
$this->addShape($shape); |
|
290
|
16 |
|
return $shape; |
|
291
|
|
|
} |
|
292
|
|
|
|
|
293
|
|
|
/** |
|
294
|
|
|
* Creates a group within this slide |
|
295
|
|
|
* |
|
296
|
|
|
* @return \PhpOffice\PhpPresentation\Shape\Group |
|
297
|
|
|
*/ |
|
298
|
2 |
|
public function createGroup() |
|
299
|
|
|
{ |
|
300
|
2 |
|
$shape = new Group(); |
|
301
|
2 |
|
$this->addShape($shape); |
|
302
|
2 |
|
return $shape; |
|
303
|
|
|
} |
|
304
|
|
|
|
|
305
|
|
|
/** |
|
306
|
|
|
* Get parent |
|
307
|
|
|
* |
|
308
|
|
|
* @return PhpPresentation |
|
309
|
|
|
*/ |
|
310
|
97 |
|
public function getParent() |
|
311
|
|
|
{ |
|
312
|
97 |
|
return $this->parent; |
|
313
|
|
|
} |
|
314
|
|
|
|
|
315
|
|
|
/** |
|
316
|
|
|
* Re-bind parent |
|
317
|
|
|
* |
|
318
|
|
|
* @param \PhpOffice\PhpPresentation\PhpPresentation $parent |
|
319
|
|
|
* @return \PhpOffice\PhpPresentation\Slide |
|
320
|
|
|
*/ |
|
321
|
2 |
|
public function rebindParent(PhpPresentation $parent) |
|
322
|
|
|
{ |
|
323
|
2 |
|
$this->parent->removeSlideByIndex($this->parent->getIndex($this)); |
|
324
|
2 |
|
$this->parent = $parent; |
|
325
|
2 |
|
return $this; |
|
326
|
|
|
} |
|
327
|
|
|
|
|
328
|
|
|
/** |
|
329
|
|
|
* @return AbstractBackground |
|
330
|
|
|
*/ |
|
331
|
156 |
|
public function getBackground() |
|
332
|
|
|
{ |
|
333
|
156 |
|
return $this->background; |
|
334
|
|
|
} |
|
335
|
|
|
|
|
336
|
|
|
/** |
|
337
|
|
|
* @param AbstractBackground $background |
|
338
|
|
|
* @return Slide |
|
339
|
|
|
*/ |
|
340
|
9 |
|
public function setBackground(AbstractBackground $background = null) |
|
341
|
|
|
{ |
|
342
|
9 |
|
$this->background = $background; |
|
343
|
9 |
|
return $this; |
|
344
|
|
|
} |
|
345
|
|
|
|
|
346
|
|
|
/** |
|
347
|
|
|
* |
|
348
|
|
|
* @return \PhpOffice\PhpPresentation\Slide\Transition |
|
349
|
|
|
*/ |
|
350
|
155 |
|
public function getTransition() |
|
351
|
|
|
{ |
|
352
|
155 |
|
return $this->slideTransition; |
|
353
|
|
|
} |
|
354
|
|
|
|
|
355
|
|
|
/** |
|
356
|
|
|
* |
|
357
|
|
|
* @param \PhpOffice\PhpPresentation\Slide\Transition $transition |
|
358
|
|
|
* @return \PhpOffice\PhpPresentation\Slide |
|
359
|
|
|
*/ |
|
360
|
3 |
|
public function setTransition(Transition $transition = null) |
|
361
|
|
|
{ |
|
362
|
3 |
|
$this->slideTransition = $transition; |
|
363
|
3 |
|
return $this; |
|
364
|
|
|
} |
|
365
|
|
|
|
|
366
|
|
|
/** |
|
367
|
|
|
* @return string |
|
368
|
|
|
*/ |
|
369
|
102 |
|
public function getRelsIndex() |
|
370
|
|
|
{ |
|
371
|
102 |
|
return $this->relsIndex; |
|
372
|
|
|
} |
|
373
|
|
|
|
|
374
|
|
|
/** |
|
375
|
|
|
* @param string $indexName |
|
376
|
|
|
*/ |
|
377
|
102 |
|
public function setRelsIndex($indexName) |
|
378
|
|
|
{ |
|
379
|
102 |
|
$this->relsIndex = $indexName; |
|
380
|
102 |
|
} |
|
381
|
|
|
} |
|
382
|
|
|
|