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\Style; |
19
|
|
|
|
20
|
|
|
use PhpOffice\PhpPresentation\ComparableInterface; |
21
|
|
|
|
22
|
|
|
/** |
23
|
|
|
* \PhpOffice\PhpPresentation\Style\Alignment |
24
|
|
|
*/ |
25
|
|
|
class Alignment implements ComparableInterface |
26
|
|
|
{ |
27
|
|
|
/* Horizontal alignment */ |
28
|
|
|
const HORIZONTAL_GENERAL = 'l'; |
29
|
|
|
const HORIZONTAL_LEFT = 'l'; |
30
|
|
|
const HORIZONTAL_RIGHT = 'r'; |
31
|
|
|
const HORIZONTAL_CENTER = 'ctr'; |
32
|
|
|
const HORIZONTAL_JUSTIFY = 'just'; |
33
|
|
|
const HORIZONTAL_DISTRIBUTED = 'dist'; |
34
|
|
|
|
35
|
|
|
/* Vertical alignment */ |
36
|
|
|
const VERTICAL_BASE = 'base'; |
37
|
|
|
const VERTICAL_AUTO = 'auto'; |
38
|
|
|
const VERTICAL_BOTTOM = 'b'; |
39
|
|
|
const VERTICAL_TOP = 't'; |
40
|
|
|
const VERTICAL_CENTER = 'ctr'; |
41
|
|
|
|
42
|
|
|
/* Text direction */ |
43
|
|
|
const TEXT_DIRECTION_HORIZONTAL = 'horz'; |
44
|
|
|
const TEXT_DIRECTION_VERTICAL_90 = 'vert'; |
45
|
|
|
const TEXT_DIRECTION_VERTICAL_270 = 'vert270'; |
46
|
|
|
const TEXT_DIRECTION_STACKED = 'wordArtVert'; |
47
|
|
|
|
48
|
|
|
private $supportedStyles = array( |
49
|
|
|
self::HORIZONTAL_GENERAL, |
50
|
|
|
self::HORIZONTAL_LEFT, |
51
|
|
|
self::HORIZONTAL_RIGHT, |
52
|
|
|
); |
53
|
|
|
|
54
|
|
|
/** |
55
|
|
|
* RTL Direction Support |
56
|
|
|
* @var boolean |
57
|
|
|
*/ |
58
|
|
|
private $RTL; |
59
|
|
|
|
60
|
|
|
/** |
61
|
|
|
* Horizontal |
62
|
|
|
* @var string |
63
|
|
|
*/ |
64
|
|
|
private $horizontal; |
65
|
|
|
|
66
|
|
|
/** |
67
|
|
|
* Vertical |
68
|
|
|
* @var string |
69
|
|
|
*/ |
70
|
|
|
private $vertical; |
71
|
|
|
|
72
|
|
|
/** |
73
|
|
|
* Text Direction |
74
|
|
|
* @var string |
75
|
|
|
*/ |
76
|
|
|
private $textDirection = self::TEXT_DIRECTION_HORIZONTAL; |
77
|
|
|
|
78
|
|
|
/** |
79
|
|
|
* Level |
80
|
|
|
* @var int |
81
|
|
|
*/ |
82
|
|
|
private $level = 0; |
83
|
|
|
|
84
|
|
|
/** |
85
|
|
|
* Indent - only possible with horizontal alignment left and right |
86
|
|
|
* @var int |
87
|
|
|
*/ |
88
|
|
|
private $indent = 0; |
89
|
|
|
|
90
|
|
|
/** |
91
|
|
|
* Margin left - only possible with horizontal alignment left and right |
92
|
|
|
* @var int |
93
|
|
|
*/ |
94
|
|
|
private $marginLeft = 0; |
95
|
|
|
|
96
|
|
|
/** |
97
|
|
|
* Margin right - only possible with horizontal alignment left and right |
98
|
|
|
* @var int |
99
|
|
|
*/ |
100
|
|
|
private $marginRight = 0; |
101
|
|
|
|
102
|
|
|
/** |
103
|
|
|
* Margin top |
104
|
|
|
* @var int |
105
|
|
|
*/ |
106
|
|
|
private $marginTop = 0; |
107
|
|
|
|
108
|
|
|
/** |
109
|
|
|
* Margin bottom |
110
|
|
|
* @var int |
111
|
|
|
*/ |
112
|
|
|
private $marginBottom = 0; |
113
|
|
|
|
114
|
|
|
/** |
115
|
|
|
* Hash index |
116
|
|
|
* @var string |
117
|
|
|
*/ |
118
|
|
|
private $hashIndex; |
119
|
|
|
|
120
|
|
|
/** |
121
|
|
|
* Create a new \PhpOffice\PhpPresentation\Style\Alignment |
122
|
|
|
*/ |
123
|
337 |
|
public function __construct() |
124
|
|
|
{ |
125
|
|
|
// Initialise values |
126
|
337 |
|
$this->horizontal = self::HORIZONTAL_LEFT; |
127
|
337 |
|
$this->vertical = self::VERTICAL_BASE; |
128
|
337 |
|
$this->RTL = false; |
129
|
337 |
|
} |
130
|
|
|
|
131
|
|
|
/** |
132
|
|
|
* Get RTL |
133
|
|
|
* |
134
|
|
|
* @return boolean |
135
|
|
|
*/ |
136
|
35 |
|
public function isRTL() |
137
|
|
|
{ |
138
|
35 |
|
return $this->RTL; |
139
|
|
|
} |
140
|
|
|
|
141
|
|
|
/** |
142
|
|
|
* Set RTL |
143
|
|
|
* |
144
|
|
|
* @param boolean $pValue |
145
|
|
|
* @return \PhpOffice\PhpPresentation\Style\Alignment |
146
|
|
|
*/ |
147
|
|
|
public function setRTL($pValue = false) |
148
|
|
|
{ |
149
|
|
|
if ($pValue == '') { |
150
|
|
|
$pValue = false; |
151
|
|
|
} |
152
|
|
|
$this->RTL = $pValue; |
153
|
|
|
|
154
|
|
|
return $this; |
155
|
|
|
} |
156
|
|
|
|
157
|
|
|
/** |
158
|
|
|
* Get Horizontal |
159
|
|
|
* |
160
|
|
|
* @return string |
161
|
|
|
*/ |
162
|
236 |
|
public function getHorizontal() |
163
|
|
|
{ |
164
|
236 |
|
return $this->horizontal; |
165
|
|
|
} |
166
|
|
|
|
167
|
|
|
/** |
168
|
|
|
* Set Horizontal |
169
|
|
|
* |
170
|
|
|
* @param string $pValue |
171
|
|
|
* @return \PhpOffice\PhpPresentation\Style\Alignment |
172
|
|
|
*/ |
173
|
235 |
|
public function setHorizontal($pValue = self::HORIZONTAL_LEFT) |
174
|
|
|
{ |
175
|
235 |
|
if ($pValue == '') { |
176
|
1 |
|
$pValue = self::HORIZONTAL_LEFT; |
177
|
|
|
} |
178
|
235 |
|
$this->horizontal = $pValue; |
179
|
|
|
|
180
|
235 |
|
return $this; |
181
|
|
|
} |
182
|
|
|
|
183
|
|
|
/** |
184
|
|
|
* Get Vertical |
185
|
|
|
* |
186
|
|
|
* @return string |
187
|
|
|
*/ |
188
|
72 |
|
public function getVertical() |
189
|
|
|
{ |
190
|
72 |
|
return $this->vertical; |
191
|
|
|
} |
192
|
|
|
|
193
|
|
|
/** |
194
|
|
|
* Set Vertical |
195
|
|
|
* |
196
|
|
|
* @param string $pValue |
197
|
|
|
* @return \PhpOffice\PhpPresentation\Style\Alignment |
198
|
|
|
*/ |
199
|
10 |
|
public function setVertical($pValue = self::VERTICAL_BASE) |
200
|
|
|
{ |
201
|
10 |
|
if ($pValue == '') { |
202
|
1 |
|
$pValue = self::VERTICAL_BASE; |
203
|
|
|
} |
204
|
10 |
|
$this->vertical = $pValue; |
205
|
|
|
|
206
|
10 |
|
return $this; |
207
|
|
|
} |
208
|
|
|
|
209
|
|
|
/** |
210
|
|
|
* Get Level |
211
|
|
|
* |
212
|
|
|
* @return int |
213
|
|
|
*/ |
214
|
90 |
|
public function getLevel() |
215
|
|
|
{ |
216
|
90 |
|
return $this->level; |
217
|
|
|
} |
218
|
|
|
|
219
|
|
|
/** |
220
|
|
|
* Set Level |
221
|
|
|
* |
222
|
|
|
* @param int $pValue Ranging 0 - 8 |
223
|
|
|
* @throws \Exception |
224
|
|
|
* @return \PhpOffice\PhpPresentation\Style\Alignment |
225
|
|
|
*/ |
226
|
10 |
|
public function setLevel($pValue = 0) |
227
|
|
|
{ |
228
|
10 |
|
if ($pValue < 0) { |
229
|
1 |
|
throw new \Exception("Invalid value should be more than 0."); |
230
|
|
|
} |
231
|
9 |
|
$this->level = $pValue; |
232
|
|
|
|
233
|
9 |
|
return $this; |
234
|
|
|
} |
235
|
|
|
|
236
|
|
|
/** |
237
|
|
|
* Get indent |
238
|
|
|
* |
239
|
|
|
* @return int |
240
|
|
|
*/ |
241
|
133 |
|
public function getIndent() |
242
|
|
|
{ |
243
|
133 |
|
return $this->indent; |
244
|
|
|
} |
245
|
|
|
|
246
|
|
|
/** |
247
|
|
|
* Set indent |
248
|
|
|
* |
249
|
|
|
* @param int $pValue |
250
|
|
|
* @return \PhpOffice\PhpPresentation\Style\Alignment |
251
|
|
|
*/ |
252
|
232 |
|
public function setIndent($pValue = 0) |
253
|
|
|
{ |
254
|
232 |
|
if ($pValue > 0 && !in_array($this->getHorizontal(), $this->supportedStyles)) { |
255
|
1 |
|
$pValue = 0; // indent not supported |
256
|
|
|
} |
257
|
|
|
|
258
|
232 |
|
$this->indent = $pValue; |
259
|
|
|
|
260
|
232 |
|
return $this; |
261
|
|
|
} |
262
|
|
|
|
263
|
|
|
/** |
264
|
|
|
* Get margin left |
265
|
|
|
* |
266
|
|
|
* @return int |
267
|
|
|
*/ |
268
|
131 |
|
public function getMarginLeft() |
269
|
|
|
{ |
270
|
131 |
|
return $this->marginLeft; |
271
|
|
|
} |
272
|
|
|
|
273
|
|
|
/** |
274
|
|
|
* Set margin left |
275
|
|
|
* |
276
|
|
|
* @param int $pValue |
277
|
|
|
* @return \PhpOffice\PhpPresentation\Style\Alignment |
278
|
|
|
*/ |
279
|
232 |
|
public function setMarginLeft($pValue = 0) |
280
|
|
|
{ |
281
|
232 |
|
if ($pValue > 0 && !in_array($this->getHorizontal(), $this->supportedStyles)) { |
282
|
232 |
|
$pValue = 0; // margin left not supported |
283
|
|
|
} |
284
|
|
|
|
285
|
232 |
|
$this->marginLeft = $pValue; |
286
|
|
|
|
287
|
232 |
|
return $this; |
288
|
|
|
} |
289
|
|
|
|
290
|
|
|
/** |
291
|
|
|
* Get margin right |
292
|
|
|
* |
293
|
|
|
* @return int |
294
|
|
|
*/ |
295
|
115 |
|
public function getMarginRight() |
296
|
|
|
{ |
297
|
115 |
|
return $this->marginRight; |
298
|
|
|
} |
299
|
|
|
|
300
|
|
|
/** |
301
|
|
|
* Set margin ight |
302
|
|
|
* |
303
|
|
|
* @param int $pValue |
304
|
|
|
* @return \PhpOffice\PhpPresentation\Style\Alignment |
305
|
|
|
*/ |
306
|
5 |
|
public function setMarginRight($pValue = 0) |
307
|
|
|
{ |
308
|
5 |
|
if ($pValue > 0 && !in_array($this->getHorizontal(), $this->supportedStyles)) { |
309
|
1 |
|
$pValue = 0; // margin right not supported |
310
|
|
|
} |
311
|
|
|
|
312
|
5 |
|
$this->marginRight = $pValue; |
313
|
|
|
|
314
|
5 |
|
return $this; |
315
|
|
|
} |
316
|
|
|
|
317
|
|
|
/** |
318
|
|
|
* Get margin top |
319
|
|
|
* |
320
|
|
|
* @return int |
321
|
|
|
*/ |
322
|
12 |
|
public function getMarginTop() |
323
|
|
|
{ |
324
|
12 |
|
return $this->marginTop; |
325
|
|
|
} |
326
|
|
|
|
327
|
|
|
/** |
328
|
|
|
* Set margin top |
329
|
|
|
* |
330
|
|
|
* @param int $pValue |
331
|
|
|
* @return \PhpOffice\PhpPresentation\Style\Alignment |
332
|
|
|
*/ |
333
|
2 |
|
public function setMarginTop($pValue = 0) |
334
|
|
|
{ |
335
|
2 |
|
$this->marginTop = $pValue; |
336
|
|
|
|
337
|
2 |
|
return $this; |
338
|
|
|
} |
339
|
|
|
|
340
|
|
|
/** |
341
|
|
|
* Get margin bottom |
342
|
|
|
* |
343
|
|
|
* @return int |
344
|
|
|
*/ |
345
|
12 |
|
public function getMarginBottom() |
346
|
|
|
{ |
347
|
12 |
|
return $this->marginBottom; |
348
|
|
|
} |
349
|
|
|
|
350
|
|
|
/** |
351
|
|
|
* Set margin bottom |
352
|
|
|
* |
353
|
|
|
* @param int $pValue |
354
|
|
|
* @return \PhpOffice\PhpPresentation\Style\Alignment |
355
|
|
|
*/ |
356
|
2 |
|
public function setMarginBottom($pValue = 0) |
357
|
|
|
{ |
358
|
2 |
|
$this->marginBottom = $pValue; |
359
|
|
|
|
360
|
2 |
|
return $this; |
361
|
|
|
} |
362
|
|
|
|
363
|
|
|
/** |
364
|
|
|
* @return string |
365
|
|
|
*/ |
366
|
12 |
|
public function getTextDirection() |
367
|
|
|
{ |
368
|
12 |
|
return $this->textDirection; |
369
|
|
|
} |
370
|
|
|
|
371
|
|
|
/** |
372
|
|
|
* @param string $pValue |
373
|
|
|
* @return Alignment |
374
|
|
|
*/ |
375
|
2 |
|
public function setTextDirection($pValue = self::TEXT_DIRECTION_HORIZONTAL) |
376
|
|
|
{ |
377
|
2 |
|
if (empty($pValue)) { |
378
|
1 |
|
$pValue = self::TEXT_DIRECTION_HORIZONTAL; |
379
|
|
|
} |
380
|
2 |
|
$this->textDirection = $pValue; |
381
|
2 |
|
return $this; |
382
|
|
|
} |
383
|
|
|
|
384
|
|
|
/** |
385
|
|
|
* Get hash code |
386
|
|
|
* |
387
|
|
|
* @return string Hash code |
388
|
|
|
*/ |
389
|
59 |
|
public function getHashCode() |
390
|
|
|
{ |
391
|
59 |
|
return md5( |
392
|
59 |
|
$this->horizontal |
393
|
59 |
|
. ($this->RTL ? 't' : 'f') |
394
|
59 |
|
. $this->vertical |
395
|
59 |
|
. $this->level |
396
|
59 |
|
. $this->indent |
397
|
59 |
|
. $this->marginLeft |
398
|
59 |
|
. $this->marginRight |
399
|
59 |
|
. __CLASS__ |
400
|
|
|
); |
401
|
|
|
} |
402
|
|
|
|
403
|
|
|
/** |
404
|
|
|
* Get hash index |
405
|
|
|
* |
406
|
|
|
* Note that this index may vary during script execution! Only reliable moment is |
407
|
|
|
* while doing a write of a workbook and when changes are not allowed. |
408
|
|
|
* |
409
|
|
|
* @return string Hash index |
410
|
|
|
*/ |
411
|
1 |
|
public function getHashIndex() |
412
|
|
|
{ |
413
|
1 |
|
return $this->hashIndex; |
414
|
|
|
} |
415
|
|
|
|
416
|
|
|
/** |
417
|
|
|
* Set hash index |
418
|
|
|
* |
419
|
|
|
* Note that this index may vary during script execution! Only reliable moment is |
420
|
|
|
* while doing a write of a workbook and when changes are not allowed. |
421
|
|
|
* |
422
|
|
|
* @param string $value Hash index |
423
|
|
|
*/ |
424
|
1 |
|
public function setHashIndex($value) |
425
|
|
|
{ |
426
|
1 |
|
$this->hashIndex = $value; |
427
|
1 |
|
} |
428
|
|
|
} |
429
|
|
|
|