|
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\Shape\Hyperlink; |
|
21
|
|
|
use PhpOffice\PhpPresentation\Shape\Placeholder; |
|
22
|
|
|
use PhpOffice\PhpPresentation\Style\Fill; |
|
23
|
|
|
use PhpOffice\PhpPresentation\Style\Shadow; |
|
24
|
|
|
|
|
25
|
|
|
/** |
|
26
|
|
|
* Abstract shape |
|
27
|
|
|
*/ |
|
28
|
|
|
abstract class AbstractShape implements ComparableInterface |
|
29
|
|
|
{ |
|
30
|
|
|
/** |
|
31
|
|
|
* Container |
|
32
|
|
|
* |
|
33
|
|
|
* @var \PhpOffice\PhpPresentation\ShapeContainerInterface |
|
34
|
|
|
*/ |
|
35
|
|
|
protected $container; |
|
36
|
|
|
|
|
37
|
|
|
/** |
|
38
|
|
|
* Offset X |
|
39
|
|
|
* |
|
40
|
|
|
* @var int |
|
41
|
|
|
*/ |
|
42
|
|
|
protected $offsetX; |
|
43
|
|
|
|
|
44
|
|
|
/** |
|
45
|
|
|
* Offset Y |
|
46
|
|
|
* |
|
47
|
|
|
* @var int |
|
48
|
|
|
*/ |
|
49
|
|
|
protected $offsetY; |
|
50
|
|
|
|
|
51
|
|
|
/** |
|
52
|
|
|
* Width |
|
53
|
|
|
* |
|
54
|
|
|
* @var int |
|
55
|
|
|
*/ |
|
56
|
|
|
protected $width; |
|
57
|
|
|
|
|
58
|
|
|
/** |
|
59
|
|
|
* Height |
|
60
|
|
|
* |
|
61
|
|
|
* @var int |
|
62
|
|
|
*/ |
|
63
|
|
|
protected $height; |
|
64
|
|
|
|
|
65
|
|
|
/** |
|
66
|
|
|
* Fill |
|
67
|
|
|
* |
|
68
|
|
|
* @var \PhpOffice\PhpPresentation\Style\Fill |
|
69
|
|
|
*/ |
|
70
|
|
|
private $fill; |
|
71
|
|
|
|
|
72
|
|
|
/** |
|
73
|
|
|
* Border |
|
74
|
|
|
* |
|
75
|
|
|
* @var \PhpOffice\PhpPresentation\Style\Border |
|
76
|
|
|
*/ |
|
77
|
|
|
private $border; |
|
78
|
|
|
|
|
79
|
|
|
/** |
|
80
|
|
|
* Rotation |
|
81
|
|
|
* |
|
82
|
|
|
* @var int |
|
83
|
|
|
*/ |
|
84
|
|
|
protected $rotation; |
|
85
|
|
|
|
|
86
|
|
|
/** |
|
87
|
|
|
* Shadow |
|
88
|
|
|
* |
|
89
|
|
|
* @var \PhpOffice\PhpPresentation\Style\Shadow |
|
90
|
|
|
*/ |
|
91
|
|
|
protected $shadow; |
|
92
|
|
|
|
|
93
|
|
|
/** |
|
94
|
|
|
* Hyperlink |
|
95
|
|
|
* |
|
96
|
|
|
* @var \PhpOffice\PhpPresentation\Shape\Hyperlink |
|
97
|
|
|
*/ |
|
98
|
|
|
protected $hyperlink; |
|
99
|
|
|
|
|
100
|
|
|
/** |
|
101
|
|
|
* PlaceHolder |
|
102
|
|
|
* @var \PhpOffice\PhpPresentation\Shape\Placeholder |
|
103
|
|
|
*/ |
|
104
|
|
|
protected $placeholder; |
|
105
|
|
|
|
|
106
|
|
|
/** |
|
107
|
|
|
* Hash index |
|
108
|
|
|
* |
|
109
|
|
|
* @var string |
|
110
|
|
|
*/ |
|
111
|
|
|
private $hashIndex; |
|
112
|
|
|
|
|
113
|
|
|
/** |
|
114
|
|
|
* Create a new self |
|
115
|
|
|
*/ |
|
116
|
238 |
|
public function __construct() |
|
117
|
|
|
{ |
|
118
|
|
|
// Initialise values |
|
119
|
238 |
|
$this->container = null; |
|
120
|
238 |
|
$this->offsetX = 0; |
|
121
|
238 |
|
$this->offsetY = 0; |
|
122
|
238 |
|
$this->width = 0; |
|
123
|
238 |
|
$this->height = 0; |
|
124
|
238 |
|
$this->rotation = 0; |
|
125
|
238 |
|
$this->fill = new Style\Fill(); |
|
126
|
238 |
|
$this->border = new Style\Border(); |
|
127
|
238 |
|
$this->shadow = new Style\Shadow(); |
|
128
|
|
|
|
|
129
|
238 |
|
$this->border->setLineStyle(Style\Border::LINE_NONE); |
|
130
|
238 |
|
} |
|
131
|
|
|
|
|
132
|
|
|
/** |
|
133
|
|
|
* Magic Method : clone |
|
134
|
|
|
*/ |
|
135
|
1 |
|
public function __clone() |
|
136
|
|
|
{ |
|
137
|
1 |
|
$this->container = null; |
|
138
|
1 |
|
$this->fill = clone $this->fill; |
|
139
|
1 |
|
$this->border = clone $this->border; |
|
140
|
1 |
|
$this->shadow = clone $this->shadow; |
|
141
|
1 |
|
} |
|
142
|
|
|
|
|
143
|
|
|
/** |
|
144
|
|
|
* Get Container, Slide or Group |
|
145
|
|
|
* |
|
146
|
|
|
* @return \PhpOffice\PhpPresentation\ShapeContainerInterface |
|
147
|
|
|
*/ |
|
148
|
2 |
|
public function getContainer() |
|
149
|
|
|
{ |
|
150
|
2 |
|
return $this->container; |
|
151
|
|
|
} |
|
152
|
|
|
|
|
153
|
|
|
/** |
|
154
|
|
|
* Set Container, Slide or Group |
|
155
|
|
|
* |
|
156
|
|
|
* @param \PhpOffice\PhpPresentation\ShapeContainerInterface $pValue |
|
157
|
|
|
* @param bool $pOverrideOld If a Slide has already been assigned, overwrite it and remove image from old Slide? |
|
158
|
|
|
* @throws \Exception |
|
159
|
|
|
* @return $this |
|
160
|
|
|
*/ |
|
161
|
173 |
|
public function setContainer(ShapeContainerInterface $pValue = null, $pOverrideOld = false) |
|
162
|
|
|
{ |
|
163
|
173 |
|
if (is_null($this->container)) { |
|
164
|
|
|
// Add drawing to \PhpOffice\PhpPresentation\ShapeContainerInterface |
|
165
|
173 |
|
$this->container = $pValue; |
|
166
|
173 |
|
if (!is_null($this->container)) { |
|
167
|
173 |
|
$this->container->getShapeCollection()->append($this); |
|
168
|
|
|
} |
|
169
|
|
|
} else { |
|
170
|
2 |
|
if ($pOverrideOld) { |
|
171
|
|
|
// Remove drawing from old \PhpOffice\PhpPresentation\ShapeContainerInterface |
|
172
|
1 |
|
$iterator = $this->container->getShapeCollection()->getIterator(); |
|
173
|
|
|
|
|
174
|
1 |
|
while ($iterator->valid()) { |
|
175
|
1 |
|
if ($iterator->current()->getHashCode() == $this->getHashCode()) { |
|
176
|
1 |
|
$this->container->getShapeCollection()->offsetUnset($iterator->key()); |
|
177
|
1 |
|
$this->container = null; |
|
178
|
1 |
|
break; |
|
179
|
|
|
} |
|
180
|
1 |
|
$iterator->next(); |
|
181
|
|
|
} |
|
182
|
|
|
|
|
183
|
|
|
// Set new \PhpOffice\PhpPresentation\Slide |
|
184
|
1 |
|
$this->setContainer($pValue); |
|
185
|
|
|
} else { |
|
186
|
1 |
|
throw new \Exception("A \PhpOffice\PhpPresentation\ShapeContainerInterface has already been assigned. Shapes can only exist on one \PhpOffice\PhpPresentation\ShapeContainerInterface."); |
|
187
|
|
|
} |
|
188
|
|
|
} |
|
189
|
|
|
|
|
190
|
173 |
|
return $this; |
|
191
|
|
|
} |
|
192
|
|
|
|
|
193
|
|
|
/** |
|
194
|
|
|
* Get OffsetX |
|
195
|
|
|
* |
|
196
|
|
|
* @return int |
|
197
|
|
|
*/ |
|
198
|
154 |
|
public function getOffsetX() |
|
199
|
|
|
{ |
|
200
|
154 |
|
return $this->offsetX; |
|
201
|
|
|
} |
|
202
|
|
|
|
|
203
|
|
|
/** |
|
204
|
|
|
* Set OffsetX |
|
205
|
|
|
* |
|
206
|
|
|
* @param int $pValue |
|
207
|
|
|
* @return $this |
|
208
|
|
|
*/ |
|
209
|
68 |
|
public function setOffsetX($pValue = 0) |
|
210
|
|
|
{ |
|
211
|
68 |
|
$this->offsetX = $pValue; |
|
212
|
|
|
|
|
213
|
68 |
|
return $this; |
|
214
|
|
|
} |
|
215
|
|
|
|
|
216
|
|
|
/** |
|
217
|
|
|
* Get OffsetY |
|
218
|
|
|
* |
|
219
|
|
|
* @return int |
|
220
|
|
|
*/ |
|
221
|
154 |
|
public function getOffsetY() |
|
222
|
|
|
{ |
|
223
|
154 |
|
return $this->offsetY; |
|
224
|
|
|
} |
|
225
|
|
|
|
|
226
|
|
|
/** |
|
227
|
|
|
* Set OffsetY |
|
228
|
|
|
* |
|
229
|
|
|
* @param int $pValue |
|
230
|
|
|
* @return $this |
|
231
|
|
|
*/ |
|
232
|
68 |
|
public function setOffsetY($pValue = 0) |
|
233
|
|
|
{ |
|
234
|
68 |
|
$this->offsetY = $pValue; |
|
235
|
|
|
|
|
236
|
68 |
|
return $this; |
|
237
|
|
|
} |
|
238
|
|
|
|
|
239
|
|
|
/** |
|
240
|
|
|
* Get Width |
|
241
|
|
|
* |
|
242
|
|
|
* @return int |
|
243
|
|
|
*/ |
|
244
|
148 |
|
public function getWidth() |
|
245
|
|
|
{ |
|
246
|
148 |
|
return $this->width; |
|
247
|
|
|
} |
|
248
|
|
|
|
|
249
|
|
|
/** |
|
250
|
|
|
* Set Width |
|
251
|
|
|
* |
|
252
|
|
|
* @param int $pValue |
|
253
|
|
|
* @return $this |
|
254
|
|
|
*/ |
|
255
|
32 |
|
public function setWidth($pValue = 0) |
|
256
|
|
|
{ |
|
257
|
32 |
|
$this->width = $pValue; |
|
258
|
32 |
|
return $this; |
|
259
|
|
|
} |
|
260
|
|
|
|
|
261
|
|
|
/** |
|
262
|
|
|
* Get Height |
|
263
|
|
|
* |
|
264
|
|
|
* @return int |
|
265
|
|
|
*/ |
|
266
|
148 |
|
public function getHeight() |
|
267
|
|
|
{ |
|
268
|
148 |
|
return $this->height; |
|
269
|
|
|
} |
|
270
|
|
|
|
|
271
|
|
|
/** |
|
272
|
|
|
* Set Height |
|
273
|
|
|
* |
|
274
|
|
|
* @param int $pValue |
|
275
|
|
|
* @return $this |
|
276
|
|
|
*/ |
|
277
|
32 |
|
public function setHeight($pValue = 0) |
|
278
|
|
|
{ |
|
279
|
32 |
|
$this->height = $pValue; |
|
280
|
32 |
|
return $this; |
|
281
|
|
|
} |
|
282
|
|
|
|
|
283
|
|
|
/** |
|
284
|
|
|
* Set width and height with proportional resize |
|
285
|
|
|
* |
|
286
|
|
|
* @param int $width |
|
287
|
|
|
* @param int $height |
|
288
|
|
|
* @example $objDrawing->setWidthAndHeight(160,120); |
|
289
|
|
|
* @return $this |
|
290
|
|
|
*/ |
|
291
|
1 |
|
public function setWidthAndHeight($width = 0, $height = 0) |
|
292
|
|
|
{ |
|
293
|
1 |
|
$this->width = $width; |
|
294
|
1 |
|
$this->height = $height; |
|
295
|
1 |
|
return $this; |
|
296
|
|
|
} |
|
297
|
|
|
|
|
298
|
|
|
/** |
|
299
|
|
|
* Get Rotation |
|
300
|
|
|
* |
|
301
|
|
|
* @return int |
|
302
|
|
|
*/ |
|
303
|
69 |
|
public function getRotation() |
|
304
|
|
|
{ |
|
305
|
69 |
|
return $this->rotation; |
|
306
|
|
|
} |
|
307
|
|
|
|
|
308
|
|
|
/** |
|
309
|
|
|
* Set Rotation |
|
310
|
|
|
* |
|
311
|
|
|
* @param int $pValue |
|
312
|
|
|
* @return $this |
|
313
|
|
|
*/ |
|
314
|
5 |
|
public function setRotation($pValue = 0) |
|
315
|
|
|
{ |
|
316
|
5 |
|
$this->rotation = $pValue; |
|
317
|
5 |
|
return $this; |
|
318
|
|
|
} |
|
319
|
|
|
|
|
320
|
|
|
/** |
|
321
|
|
|
* Get Fill |
|
322
|
|
|
* |
|
323
|
|
|
* @return \PhpOffice\PhpPresentation\Style\Fill |
|
324
|
|
|
*/ |
|
325
|
122 |
|
public function getFill() |
|
326
|
|
|
{ |
|
327
|
122 |
|
return $this->fill; |
|
328
|
|
|
} |
|
329
|
|
|
|
|
330
|
|
|
/** |
|
331
|
|
|
* Set Fill |
|
332
|
|
|
* @param \PhpOffice\PhpPresentation\Style\Fill $pValue |
|
333
|
|
|
* @return \PhpOffice\PhpPresentation\AbstractShape |
|
334
|
|
|
*/ |
|
335
|
6 |
|
public function setFill(Fill $pValue = null) |
|
336
|
|
|
{ |
|
337
|
6 |
|
$this->fill = $pValue; |
|
338
|
6 |
|
return $this; |
|
339
|
|
|
} |
|
340
|
|
|
|
|
341
|
|
|
/** |
|
342
|
|
|
* Get Border |
|
343
|
|
|
* |
|
344
|
|
|
* @return \PhpOffice\PhpPresentation\Style\Border |
|
345
|
|
|
*/ |
|
346
|
92 |
|
public function getBorder() |
|
347
|
|
|
{ |
|
348
|
92 |
|
return $this->border; |
|
349
|
|
|
} |
|
350
|
|
|
|
|
351
|
|
|
/** |
|
352
|
|
|
* Get Shadow |
|
353
|
|
|
* |
|
354
|
|
|
* @return \PhpOffice\PhpPresentation\Style\Shadow |
|
355
|
|
|
*/ |
|
356
|
102 |
|
public function getShadow() |
|
357
|
|
|
{ |
|
358
|
102 |
|
return $this->shadow; |
|
359
|
|
|
} |
|
360
|
|
|
|
|
361
|
|
|
/** |
|
362
|
|
|
* Set Shadow |
|
363
|
|
|
* |
|
364
|
|
|
* @param \PhpOffice\PhpPresentation\Style\Shadow $pValue |
|
365
|
|
|
* @throws \Exception |
|
366
|
|
|
* @return $this |
|
367
|
|
|
*/ |
|
368
|
3 |
|
public function setShadow(Shadow $pValue = null) |
|
369
|
|
|
{ |
|
370
|
3 |
|
$this->shadow = $pValue; |
|
371
|
3 |
|
return $this; |
|
372
|
|
|
} |
|
373
|
|
|
|
|
374
|
|
|
/** |
|
375
|
|
|
* Has Hyperlink? |
|
376
|
|
|
* |
|
377
|
|
|
* @return boolean |
|
378
|
|
|
*/ |
|
379
|
96 |
|
public function hasHyperlink() |
|
380
|
|
|
{ |
|
381
|
96 |
|
return !is_null($this->hyperlink); |
|
382
|
|
|
} |
|
383
|
|
|
|
|
384
|
|
|
/** |
|
385
|
|
|
* Get Hyperlink |
|
386
|
|
|
* |
|
387
|
|
|
* @return \PhpOffice\PhpPresentation\Shape\Hyperlink |
|
388
|
|
|
* @throws \Exception |
|
389
|
|
|
*/ |
|
390
|
6 |
|
public function getHyperlink() |
|
391
|
|
|
{ |
|
392
|
6 |
|
if (is_null($this->hyperlink)) { |
|
393
|
6 |
|
$this->hyperlink = new Hyperlink(); |
|
394
|
|
|
} |
|
395
|
6 |
|
return $this->hyperlink; |
|
396
|
|
|
} |
|
397
|
|
|
|
|
398
|
|
|
/** |
|
399
|
|
|
* Set Hyperlink |
|
400
|
|
|
* |
|
401
|
|
|
* @param \PhpOffice\PhpPresentation\Shape\Hyperlink $pHyperlink |
|
402
|
|
|
* @throws \Exception |
|
403
|
|
|
* @return $this |
|
404
|
|
|
*/ |
|
405
|
1 |
|
public function setHyperlink(Hyperlink $pHyperlink = null) |
|
406
|
|
|
{ |
|
407
|
1 |
|
$this->hyperlink = $pHyperlink; |
|
408
|
1 |
|
return $this; |
|
409
|
|
|
} |
|
410
|
|
|
|
|
411
|
|
|
/** |
|
412
|
|
|
* Get hash code |
|
413
|
|
|
* |
|
414
|
|
|
* @return string Hash code |
|
415
|
|
|
*/ |
|
416
|
84 |
|
public function getHashCode() |
|
417
|
|
|
{ |
|
418
|
84 |
|
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__); |
|
419
|
|
|
} |
|
420
|
|
|
|
|
421
|
|
|
/** |
|
422
|
|
|
* Get hash index |
|
423
|
|
|
* |
|
424
|
|
|
* Note that this index may vary during script execution! Only reliable moment is |
|
425
|
|
|
* while doing a write of a workbook and when changes are not allowed. |
|
426
|
|
|
* |
|
427
|
|
|
* @return string Hash index |
|
428
|
|
|
*/ |
|
429
|
80 |
|
public function getHashIndex() |
|
430
|
|
|
{ |
|
431
|
80 |
|
return $this->hashIndex; |
|
432
|
|
|
} |
|
433
|
|
|
|
|
434
|
|
|
/** |
|
435
|
|
|
* Set hash index |
|
436
|
|
|
* |
|
437
|
|
|
* Note that this index may vary during script execution! Only reliable moment is |
|
438
|
|
|
* while doing a write of a workbook and when changes are not allowed. |
|
439
|
|
|
* |
|
440
|
|
|
* @param string $value Hash index |
|
441
|
|
|
*/ |
|
442
|
80 |
|
public function setHashIndex($value) |
|
443
|
|
|
{ |
|
444
|
80 |
|
$this->hashIndex = $value; |
|
445
|
80 |
|
} |
|
446
|
|
|
|
|
447
|
70 |
|
public function isPlaceholder() |
|
448
|
|
|
{ |
|
449
|
70 |
|
return !is_null($this->placeholder); |
|
450
|
|
|
} |
|
451
|
|
|
|
|
452
|
1 |
|
public function getPlaceholder() |
|
453
|
|
|
{ |
|
454
|
1 |
|
if (!$this->isPlaceholder()) { |
|
455
|
1 |
|
return null; |
|
456
|
|
|
} |
|
457
|
1 |
|
return $this->placeholder; |
|
458
|
|
|
} |
|
459
|
|
|
|
|
460
|
|
|
/** |
|
461
|
|
|
* @param \PhpOffice\PhpPresentation\Shape\Placeholder $placeholder |
|
462
|
|
|
* @return $this |
|
463
|
|
|
*/ |
|
464
|
5 |
|
public function setPlaceHolder(Placeholder $placeholder) |
|
465
|
|
|
{ |
|
466
|
5 |
|
$this->placeholder = $placeholder; |
|
467
|
5 |
|
return $this; |
|
468
|
|
|
} |
|
469
|
|
|
} |
|
470
|
|
|
|