• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

PHPOffice / PHPWord / 25414441731

06 May 2026 03:12AM UTC coverage: 94.696% (-2.1%) from 96.757%
25414441731

Pull #2874

github

web-flow
Merge 3fa85d6e3 into 0ab0b4940
Pull Request #2874: Addresses issue #12

135 of 420 new or added lines in 30 files covered. (32.14%)

1 existing line in 1 file now uncovered.

12588 of 13293 relevant lines covered (94.7%)

34.84 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

93.65
/src/PhpWord/Style/Section.php
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
     * Page Numbering Array.
112
     *
113
     * @var array
114
     */
115
    private $pageNumbering = [];
116

117
    /**
118
     * Section columns count.
119
     *
120
     * @var int
121
     */
122
    private $colsNum = self::DEFAULT_COLUMN_COUNT;
123

124
    /**
125
     * Section spacing between columns.
126
     *
127
     * @var float|int
128
     */
129
    private $colsSpace = self::DEFAULT_COLUMN_SPACING;
130

131
    /**
132
     * Section break type.
133
     *
134
     * Options:
135
     * - nextPage: Next page section break
136
     * - nextColumn: Column section break
137
     * - continuous: Continuous section break
138
     * - evenPage: Even page section break
139
     * - oddPage: Odd page section break
140
     *
141
     * @var ?string
142
     */
143
    private $breakType;
144

145
    /**
146
     * Line numbering.
147
     *
148
     * @var LineNumbering
149
     *
150
     * @see  http://www.schemacentral.com/sc/ooxml/e-w_lnNumType-1.html
151
     */
152
    private $lineNumbering;
153

154
    /**
155
     * Vertical Text Alignment on Page
156
     * One of \PhpOffice\PhpWord\SimpleType\VerticalJc.
157
     *
158
     * @var ?string
159
     */
160
    private $vAlign;
161

162
    /**
163
     * Create new instance.
164
     */
165
    public function __construct()
166
    {
167
        $this->setPaperSize();
330✔
168
    }
169

170
    /**
171
     * Get paper size.
172
     *
173
     * @return string
174
     */
175
    public function getPaperSize()
176
    {
177
        return $this->paper->getSize();
35✔
178
    }
179

180
    /**
181
     * Set paper size.
182
     *
183
     * @param string $value
184
     *
185
     * @return self
186
     */
187
    public function setPaperSize($value = '')
188
    {
189
        if (!$value) {
330✔
190
            $value = Settings::getDefaultPaper();
330✔
191
        }
192
        if ($this->paper === null) {
330✔
193
            $this->paper = new Paper();
330✔
194
        }
195
        $this->paper->setSize($value);
330✔
196
        $this->pageSizeW = $this->paper->getWidth();
330✔
197
        $this->pageSizeH = $this->paper->getHeight();
330✔
198

199
        return $this;
330✔
200
    }
201

202
    /**
203
     * Set Setting Value.
204
     *
205
     * @param string $key
206
     * @param array|int|string $value
207
     *
208
     * @return self
209
     */
210
    public function setSettingValue($key, $value)
211
    {
212
        return $this->setStyleValue($key, $value);
5✔
213
    }
214

215
    /**
216
     * Set orientation.
217
     *
218
     * @param string $value
219
     *
220
     * @return self
221
     */
222
    public function setOrientation($value = null)
223
    {
224
        $enum = [self::ORIENTATION_PORTRAIT, self::ORIENTATION_LANDSCAPE];
13✔
225
        $this->orientation = $this->setEnumVal($value, $enum, $this->orientation);
13✔
226

227
        /** @var float|int $longSide Type hint */
228
        $longSide = $this->pageSizeW >= $this->pageSizeH ? $this->pageSizeW : $this->pageSizeH;
13✔
229

230
        /** @var float|int $shortSide Type hint */
231
        $shortSide = $this->pageSizeW < $this->pageSizeH ? $this->pageSizeW : $this->pageSizeH;
13✔
232

233
        if ($this->orientation == self::ORIENTATION_PORTRAIT) {
13✔
234
            $this->pageSizeW = $shortSide;
4✔
235
            $this->pageSizeH = $longSide;
4✔
236
        } else {
237
            $this->pageSizeW = $longSide;
11✔
238
            $this->pageSizeH = $shortSide;
11✔
239
        }
240

241
        return $this;
13✔
242
    }
243

244
    /**
245
     * Get Page Orientation.
246
     *
247
     * @return string
248
     */
249
    public function getOrientation()
250
    {
251
        return $this->orientation;
246✔
252
    }
253

254
    /**
255
     * Set Portrait Orientation.
256
     *
257
     * @return self
258
     */
259
    public function setPortrait()
260
    {
261
        return $this->setOrientation(self::ORIENTATION_PORTRAIT);
2✔
262
    }
263

264
    /**
265
     * Set Landscape Orientation.
266
     *
267
     * @return self
268
     */
269
    public function setLandscape()
270
    {
271
        return $this->setOrientation(self::ORIENTATION_LANDSCAPE);
3✔
272
    }
273

274
    /**
275
     * Get Page Size Width.
276
     *
277
     * @return null|float|int
278
     *
279
     * @since 0.12.0
280
     */
281
    public function getPageSizeW()
282
    {
283
        return $this->pageSizeW;
220✔
284
    }
285

286
    /**
287
     * @param null|float|int $value
288
     *
289
     * @return Section
290
     *
291
     * @since 0.12.0
292
     */
293
    public function setPageSizeW($value = null)
294
    {
295
        $this->pageSizeW = $this->setNumericVal($value, self::DEFAULT_WIDTH);
16✔
296

297
        return $this;
16✔
298
    }
299

300
    /**
301
     * Get Page Size Height.
302
     *
303
     * @return null|float|int
304
     *
305
     * @since 0.12.0
306
     */
307
    public function getPageSizeH()
308
    {
309
        return $this->pageSizeH;
220✔
310
    }
311

312
    /**
313
     * @param null|float|int $value
314
     *
315
     * @return Section
316
     *
317
     * @since 0.12.0
318
     */
319
    public function setPageSizeH($value = null)
320
    {
321
        $this->pageSizeH = $this->setNumericVal($value, self::DEFAULT_HEIGHT);
16✔
322

323
        return $this;
16✔
324
    }
325

326
    /**
327
     * Get gutter.
328
     *
329
     * @return float|int
330
     */
331
    public function getGutter()
332
    {
333
        return $this->gutter;
155✔
334
    }
335

336
    /**
337
     * Set gutter.
338
     *
339
     * @param float|int $value
340
     *
341
     * @return self
342
     */
343
    public function setGutter($value = null)
344
    {
345
        $this->gutter = $this->setNumericVal($value, self::DEFAULT_GUTTER);
11✔
346

347
        return $this;
11✔
348
    }
349

350
    /**
351
     * Get Header Height.
352
     *
353
     * @return float|int
354
     */
355
    public function getHeaderHeight()
356
    {
357
        return $this->headerHeight;
157✔
358
    }
359

360
    /**
361
     * Set Header Height.
362
     *
363
     * @param float|int $value
364
     *
365
     * @return self
366
     */
367
    public function setHeaderHeight($value = null)
368
    {
369
        $this->headerHeight = $this->setNumericVal($value, self::DEFAULT_HEADER_HEIGHT);
12✔
370

371
        return $this;
12✔
372
    }
373

374
    /**
375
     * Get Footer Height.
376
     *
377
     * @return float|int
378
     */
379
    public function getFooterHeight()
380
    {
381
        return $this->footerHeight;
156✔
382
    }
383

384
    /**
385
     * Set Footer Height.
386
     *
387
     * @param float|int $value
388
     *
389
     * @return self
390
     */
391
    public function setFooterHeight($value = null)
392
    {
393
        $this->footerHeight = $this->setNumericVal($value, self::DEFAULT_FOOTER_HEIGHT);
11✔
394

395
        return $this;
11✔
396
    }
397

398
    /**
399
     * Get page numbering start.
400
     *
401
     * @return null|int
402
     */
403
    public function getPageNumberingStart()
404
    {
405
        return $this->pageNumberingStart;
217✔
406
    }
407

408
    /**
409
     * Set page numbering start.
410
     *
411
     * @param null|int $pageNumberingStart
412
     *
413
     * @return self
414
     */
415
    public function setPageNumberingStart($pageNumberingStart = null)
416
    {
417
        $this->pageNumberingStart = $pageNumberingStart;
5✔
418

419
        return $this;
5✔
420
    }
421

422
    /**
423
     * Get page numbering array.
424
     *
425
     * @return null|array
426
     */
427
    public function getPageNumbering()
428
    {
429
        return $this->pageNumbering;
149✔
430
    }
431

432
    /**
433
     * Set page numbering array.
434
     *
435
     * @param null|array $pageNumbering
436
     *
437
     * @return self
438
     */
439
    public function setPageNumbering($pageNumbering = [])
440
    {
NEW
441
        $this->pageNumbering = $pageNumbering;
×
442

NEW
443
        if (array_key_exists('start', $pageNumbering)) {
×
NEW
444
            $this->setPageNumberingStart($pageNumbering['start']);
×
445
        }
446

NEW
447
        return $this;
×
448
    }
449

450
    /**
451
     * Get Section Columns Count.
452
     *
453
     * @return int
454
     */
455
    public function getColsNum()
456
    {
457
        return $this->colsNum;
211✔
458
    }
459

460
    /**
461
     * Set Section Columns Count.
462
     *
463
     * @param int $value
464
     *
465
     * @return self
466
     */
467
    public function setColsNum($value = null)
468
    {
469
        $this->colsNum = $this->setIntVal($value, self::DEFAULT_COLUMN_COUNT);
6✔
470

471
        return $this;
6✔
472
    }
473

474
    /**
475
     * Get Section Space Between Columns.
476
     *
477
     * @return float|int
478
     */
479
    public function getColsSpace()
480
    {
481
        return $this->colsSpace;
150✔
482
    }
483

484
    /**
485
     * Set Section Space Between Columns.
486
     *
487
     * @param float|int $value
488
     *
489
     * @return self
490
     */
491
    public function setColsSpace($value = null)
492
    {
493
        $this->colsSpace = $this->setNumericVal($value, self::DEFAULT_COLUMN_SPACING);
9✔
494

495
        return $this;
9✔
496
    }
497

498
    /**
499
     * Get Break Type.
500
     *
501
     * @return ?string
502
     */
503
    public function getBreakType()
504
    {
505
        return $this->breakType;
150✔
506
    }
507

508
    /**
509
     * Set Break Type.
510
     *
511
     * @param string $value
512
     *
513
     * @return self
514
     */
515
    public function setBreakType($value = null)
516
    {
517
        $this->breakType = $value;
6✔
518

519
        return $this;
6✔
520
    }
521

522
    /**
523
     * Get line numbering.
524
     *
525
     * @return LineNumbering
526
     */
527
    public function getLineNumbering()
528
    {
529
        return $this->lineNumbering;
150✔
530
    }
531

532
    /**
533
     * Set line numbering.
534
     *
535
     * @param mixed $value
536
     *
537
     * @return self
538
     */
539
    public function setLineNumbering($value = null)
540
    {
541
        $this->setObjectVal($value, 'LineNumbering', $this->lineNumbering);
2✔
542

543
        return $this;
2✔
544
    }
545

546
    /**
547
     * Get vertical alignment.
548
     *
549
     * @return ?string
550
     */
551
    public function getVAlign()
552
    {
553
        return $this->vAlign;
151✔
554
    }
555

556
    /**
557
     * Set vertical alignment.
558
     *
559
     * @param string $value
560
     *
561
     * @return self
562
     */
563
    public function setVAlign($value = null)
564
    {
565
        VerticalJc::validate($value);
2✔
566
        $this->vAlign = $value;
2✔
567

568
        return $this;
2✔
569
    }
570
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc