Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
Total | |
100.00% |
58 / 58 |
|
100.00% |
30 / 30 |
CRAP | |
100.00% |
1 / 1 |
Section | |
100.00% |
58 / 58 |
|
100.00% |
30 / 30 |
35 | |
100.00% |
1 / 1 |
__construct | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
getPaperSize | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
setPaperSize | |
100.00% |
8 / 8 |
|
100.00% |
1 / 1 |
3 | |||
setSettingValue | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
setOrientation | |
100.00% |
10 / 10 |
|
100.00% |
1 / 1 |
4 | |||
getOrientation | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
setPortrait | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
setLandscape | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
getPageSizeW | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
setPageSizeW | |
100.00% |
2 / 2 |
|
100.00% |
1 / 1 |
1 | |||
getPageSizeH | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
setPageSizeH | |
100.00% |
2 / 2 |
|
100.00% |
1 / 1 |
1 | |||
getGutter | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
setGutter | |
100.00% |
2 / 2 |
|
100.00% |
1 / 1 |
1 | |||
getHeaderHeight | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
setHeaderHeight | |
100.00% |
2 / 2 |
|
100.00% |
1 / 1 |
1 | |||
getFooterHeight | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
setFooterHeight | |
100.00% |
2 / 2 |
|
100.00% |
1 / 1 |
1 | |||
getPageNumberingStart | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
setPageNumberingStart | |
100.00% |
2 / 2 |
|
100.00% |
1 / 1 |
1 | |||
getColsNum | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
setColsNum | |
100.00% |
2 / 2 |
|
100.00% |
1 / 1 |
1 | |||
getColsSpace | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
setColsSpace | |
100.00% |
2 / 2 |
|
100.00% |
1 / 1 |
1 | |||
getBreakType | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
setBreakType | |
100.00% |
2 / 2 |
|
100.00% |
1 / 1 |
1 | |||
getLineNumbering | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
setLineNumbering | |
100.00% |
2 / 2 |
|
100.00% |
1 / 1 |
1 | |||
getVAlign | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
setVAlign | |
100.00% |
3 / 3 |
|
100.00% |
1 / 1 |
1 |
1 | <?php |
2 | /** |
3 | * This file is part of PHPWord - A pure PHP library for reading and writing |
4 | * word processing documents. |
5 | * |
6 | * PHPWord 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/PHPWord/contributors. |
12 | * |
13 | * @see https://github.com/PHPOffice/PHPWord |
14 | * |
15 | * @license http://www.gnu.org/licenses/lgpl.txt LGPL version 3 |
16 | */ |
17 | |
18 | namespace PhpOffice\PhpWord\Style; |
19 | |
20 | use PhpOffice\PhpWord\Settings; |
21 | use PhpOffice\PhpWord\SimpleType\VerticalJc; |
22 | |
23 | /** |
24 | * Section settings. |
25 | */ |
26 | class Section extends Border |
27 | { |
28 | /** |
29 | * Page orientation. |
30 | * |
31 | * @const string |
32 | */ |
33 | const ORIENTATION_PORTRAIT = 'portrait'; |
34 | const ORIENTATION_LANDSCAPE = 'landscape'; |
35 | |
36 | /** |
37 | * Page default constants. |
38 | * |
39 | * @const int|float |
40 | */ |
41 | const DEFAULT_WIDTH = 11905.511811024; // In twips. |
42 | const DEFAULT_HEIGHT = 16837.79527559; // In twips. |
43 | const DEFAULT_GUTTER = 0; // In twips. |
44 | const DEFAULT_HEADER_HEIGHT = 720; // In twips. |
45 | const DEFAULT_FOOTER_HEIGHT = 720; // In twips. |
46 | const DEFAULT_COLUMN_COUNT = 1; |
47 | const DEFAULT_COLUMN_SPACING = 720; // In twips. |
48 | |
49 | /** |
50 | * Page Orientation. |
51 | * |
52 | * @var string |
53 | * |
54 | * @see http://www.schemacentral.com/sc/ooxml/a-w_orient-1.html |
55 | */ |
56 | private $orientation = self::ORIENTATION_PORTRAIT; |
57 | |
58 | /** |
59 | * Paper size. |
60 | * |
61 | * @var \PhpOffice\PhpWord\Style\Paper |
62 | */ |
63 | private $paper; |
64 | |
65 | /** |
66 | * Page Size Width. |
67 | * |
68 | * @var float|int |
69 | */ |
70 | private $pageSizeW = self::DEFAULT_WIDTH; |
71 | |
72 | /** |
73 | * Page Size Height. |
74 | * |
75 | * @var float|int |
76 | */ |
77 | private $pageSizeH = self::DEFAULT_HEIGHT; |
78 | |
79 | /** |
80 | * Page gutter spacing. |
81 | * |
82 | * @var float|int |
83 | * |
84 | * @see http://www.schemacentral.com/sc/ooxml/e-w_pgMar-1.html |
85 | */ |
86 | private $gutter = self::DEFAULT_GUTTER; |
87 | |
88 | /** |
89 | * Header height. |
90 | * |
91 | * @var float|int |
92 | */ |
93 | private $headerHeight = self::DEFAULT_HEADER_HEIGHT; |
94 | |
95 | /** |
96 | * Footer height. |
97 | * |
98 | * @var float|int |
99 | */ |
100 | private $footerHeight = self::DEFAULT_FOOTER_HEIGHT; |
101 | |
102 | /** |
103 | * Page Numbering Start. |
104 | * |
105 | * @var int |
106 | */ |
107 | private $pageNumberingStart; |
108 | |
109 | /** |
110 | * Section columns count. |
111 | * |
112 | * @var int |
113 | */ |
114 | private $colsNum = self::DEFAULT_COLUMN_COUNT; |
115 | |
116 | /** |
117 | * Section spacing between columns. |
118 | * |
119 | * @var float|int |
120 | */ |
121 | private $colsSpace = self::DEFAULT_COLUMN_SPACING; |
122 | |
123 | /** |
124 | * Section break type. |
125 | * |
126 | * Options: |
127 | * - nextPage: Next page section break |
128 | * - nextColumn: Column section break |
129 | * - continuous: Continuous section break |
130 | * - evenPage: Even page section break |
131 | * - oddPage: Odd page section break |
132 | * |
133 | * @var ?string |
134 | */ |
135 | private $breakType; |
136 | |
137 | /** |
138 | * Line numbering. |
139 | * |
140 | * @var \PhpOffice\PhpWord\Style\LineNumbering |
141 | * |
142 | * @see http://www.schemacentral.com/sc/ooxml/e-w_lnNumType-1.html |
143 | */ |
144 | private $lineNumbering; |
145 | |
146 | /** |
147 | * Vertical Text Alignment on Page |
148 | * One of \PhpOffice\PhpWord\SimpleType\VerticalJc. |
149 | * |
150 | * @var ?string |
151 | */ |
152 | private $vAlign; |
153 | |
154 | /** |
155 | * Create new instance. |
156 | */ |
157 | public function __construct() |
158 | { |
159 | $this->setPaperSize(); |
160 | } |
161 | |
162 | /** |
163 | * Get paper size. |
164 | * |
165 | * @return string |
166 | */ |
167 | public function getPaperSize() |
168 | { |
169 | return $this->paper->getSize(); |
170 | } |
171 | |
172 | /** |
173 | * Set paper size. |
174 | * |
175 | * @param string $value |
176 | * |
177 | * @return self |
178 | */ |
179 | public function setPaperSize($value = '') |
180 | { |
181 | if (!$value) { |
182 | $value = Settings::getDefaultPaper(); |
183 | } |
184 | if ($this->paper === null) { |
185 | $this->paper = new Paper(); |
186 | } |
187 | $this->paper->setSize($value); |
188 | $this->pageSizeW = $this->paper->getWidth(); |
189 | $this->pageSizeH = $this->paper->getHeight(); |
190 | |
191 | return $this; |
192 | } |
193 | |
194 | /** |
195 | * Set Setting Value. |
196 | * |
197 | * @param string $key |
198 | * @param array|int|string $value |
199 | * |
200 | * @return self |
201 | */ |
202 | public function setSettingValue($key, $value) |
203 | { |
204 | return $this->setStyleValue($key, $value); |
205 | } |
206 | |
207 | /** |
208 | * Set orientation. |
209 | * |
210 | * @param string $value |
211 | * |
212 | * @return self |
213 | */ |
214 | public function setOrientation($value = null) |
215 | { |
216 | $enum = [self::ORIENTATION_PORTRAIT, self::ORIENTATION_LANDSCAPE]; |
217 | $this->orientation = $this->setEnumVal($value, $enum, $this->orientation); |
218 | |
219 | /** @var float|int $longSide Type hint */ |
220 | $longSide = $this->pageSizeW >= $this->pageSizeH ? $this->pageSizeW : $this->pageSizeH; |
221 | |
222 | /** @var float|int $shortSide Type hint */ |
223 | $shortSide = $this->pageSizeW < $this->pageSizeH ? $this->pageSizeW : $this->pageSizeH; |
224 | |
225 | if ($this->orientation == self::ORIENTATION_PORTRAIT) { |
226 | $this->pageSizeW = $shortSide; |
227 | $this->pageSizeH = $longSide; |
228 | } else { |
229 | $this->pageSizeW = $longSide; |
230 | $this->pageSizeH = $shortSide; |
231 | } |
232 | |
233 | return $this; |
234 | } |
235 | |
236 | /** |
237 | * Get Page Orientation. |
238 | * |
239 | * @return string |
240 | */ |
241 | public function getOrientation() |
242 | { |
243 | return $this->orientation; |
244 | } |
245 | |
246 | /** |
247 | * Set Portrait Orientation. |
248 | * |
249 | * @return self |
250 | */ |
251 | public function setPortrait() |
252 | { |
253 | return $this->setOrientation(self::ORIENTATION_PORTRAIT); |
254 | } |
255 | |
256 | /** |
257 | * Set Landscape Orientation. |
258 | * |
259 | * @return self |
260 | */ |
261 | public function setLandscape() |
262 | { |
263 | return $this->setOrientation(self::ORIENTATION_LANDSCAPE); |
264 | } |
265 | |
266 | /** |
267 | * Get Page Size Width. |
268 | * |
269 | * @return null|float|int |
270 | * |
271 | * @since 0.12.0 |
272 | */ |
273 | public function getPageSizeW() |
274 | { |
275 | return $this->pageSizeW; |
276 | } |
277 | |
278 | /** |
279 | * @param null|float|int $value |
280 | * |
281 | * @return \PhpOffice\PhpWord\Style\Section |
282 | * |
283 | * @since 0.12.0 |
284 | */ |
285 | public function setPageSizeW($value = null) |
286 | { |
287 | $this->pageSizeW = $this->setNumericVal($value, self::DEFAULT_WIDTH); |
288 | |
289 | return $this; |
290 | } |
291 | |
292 | /** |
293 | * Get Page Size Height. |
294 | * |
295 | * @return null|float|int |
296 | * |
297 | * @since 0.12.0 |
298 | */ |
299 | public function getPageSizeH() |
300 | { |
301 | return $this->pageSizeH; |
302 | } |
303 | |
304 | /** |
305 | * @param null|float|int $value |
306 | * |
307 | * @return \PhpOffice\PhpWord\Style\Section |
308 | * |
309 | * @since 0.12.0 |
310 | */ |
311 | public function setPageSizeH($value = null) |
312 | { |
313 | $this->pageSizeH = $this->setNumericVal($value, self::DEFAULT_HEIGHT); |
314 | |
315 | return $this; |
316 | } |
317 | |
318 | /** |
319 | * Get gutter. |
320 | * |
321 | * @return float|int |
322 | */ |
323 | public function getGutter() |
324 | { |
325 | return $this->gutter; |
326 | } |
327 | |
328 | /** |
329 | * Set gutter. |
330 | * |
331 | * @param float|int $value |
332 | * |
333 | * @return self |
334 | */ |
335 | public function setGutter($value = null) |
336 | { |
337 | $this->gutter = $this->setNumericVal($value, self::DEFAULT_GUTTER); |
338 | |
339 | return $this; |
340 | } |
341 | |
342 | /** |
343 | * Get Header Height. |
344 | * |
345 | * @return float|int |
346 | */ |
347 | public function getHeaderHeight() |
348 | { |
349 | return $this->headerHeight; |
350 | } |
351 | |
352 | /** |
353 | * Set Header Height. |
354 | * |
355 | * @param float|int $value |
356 | * |
357 | * @return self |
358 | */ |
359 | public function setHeaderHeight($value = null) |
360 | { |
361 | $this->headerHeight = $this->setNumericVal($value, self::DEFAULT_HEADER_HEIGHT); |
362 | |
363 | return $this; |
364 | } |
365 | |
366 | /** |
367 | * Get Footer Height. |
368 | * |
369 | * @return float|int |
370 | */ |
371 | public function getFooterHeight() |
372 | { |
373 | return $this->footerHeight; |
374 | } |
375 | |
376 | /** |
377 | * Set Footer Height. |
378 | * |
379 | * @param float|int $value |
380 | * |
381 | * @return self |
382 | */ |
383 | public function setFooterHeight($value = null) |
384 | { |
385 | $this->footerHeight = $this->setNumericVal($value, self::DEFAULT_FOOTER_HEIGHT); |
386 | |
387 | return $this; |
388 | } |
389 | |
390 | /** |
391 | * Get page numbering start. |
392 | * |
393 | * @return null|int |
394 | */ |
395 | public function getPageNumberingStart() |
396 | { |
397 | return $this->pageNumberingStart; |
398 | } |
399 | |
400 | /** |
401 | * Set page numbering start. |
402 | * |
403 | * @param null|int $pageNumberingStart |
404 | * |
405 | * @return self |
406 | */ |
407 | public function setPageNumberingStart($pageNumberingStart = null) |
408 | { |
409 | $this->pageNumberingStart = $pageNumberingStart; |
410 | |
411 | return $this; |
412 | } |
413 | |
414 | /** |
415 | * Get Section Columns Count. |
416 | * |
417 | * @return int |
418 | */ |
419 | public function getColsNum() |
420 | { |
421 | return $this->colsNum; |
422 | } |
423 | |
424 | /** |
425 | * Set Section Columns Count. |
426 | * |
427 | * @param int $value |
428 | * |
429 | * @return self |
430 | */ |
431 | public function setColsNum($value = null) |
432 | { |
433 | $this->colsNum = $this->setIntVal($value, self::DEFAULT_COLUMN_COUNT); |
434 | |
435 | return $this; |
436 | } |
437 | |
438 | /** |
439 | * Get Section Space Between Columns. |
440 | * |
441 | * @return float|int |
442 | */ |
443 | public function getColsSpace() |
444 | { |
445 | return $this->colsSpace; |
446 | } |
447 | |
448 | /** |
449 | * Set Section Space Between Columns. |
450 | * |
451 | * @param float|int $value |
452 | * |
453 | * @return self |
454 | */ |
455 | public function setColsSpace($value = null) |
456 | { |
457 | $this->colsSpace = $this->setNumericVal($value, self::DEFAULT_COLUMN_SPACING); |
458 | |
459 | return $this; |
460 | } |
461 | |
462 | /** |
463 | * Get Break Type. |
464 | * |
465 | * @return ?string |
466 | */ |
467 | public function getBreakType() |
468 | { |
469 | return $this->breakType; |
470 | } |
471 | |
472 | /** |
473 | * Set Break Type. |
474 | * |
475 | * @param string $value |
476 | * |
477 | * @return self |
478 | */ |
479 | public function setBreakType($value = null) |
480 | { |
481 | $this->breakType = $value; |
482 | |
483 | return $this; |
484 | } |
485 | |
486 | /** |
487 | * Get line numbering. |
488 | * |
489 | * @return \PhpOffice\PhpWord\Style\LineNumbering |
490 | */ |
491 | public function getLineNumbering() |
492 | { |
493 | return $this->lineNumbering; |
494 | } |
495 | |
496 | /** |
497 | * Set line numbering. |
498 | * |
499 | * @param mixed $value |
500 | * |
501 | * @return self |
502 | */ |
503 | public function setLineNumbering($value = null) |
504 | { |
505 | $this->setObjectVal($value, 'LineNumbering', $this->lineNumbering); |
506 | |
507 | return $this; |
508 | } |
509 | |
510 | /** |
511 | * Get vertical alignment. |
512 | * |
513 | * @return ?string |
514 | */ |
515 | public function getVAlign() |
516 | { |
517 | return $this->vAlign; |
518 | } |
519 | |
520 | /** |
521 | * Set vertical alignment. |
522 | * |
523 | * @param string $value |
524 | * |
525 | * @return self |
526 | */ |
527 | public function setVAlign($value = null) |
528 | { |
529 | VerticalJc::validate($value); |
530 | $this->vAlign = $value; |
531 | |
532 | return $this; |
533 | } |
534 | } |