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