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

PHPOffice / PHPWord / 17391978595

02 Sep 2025 03:01AM UTC coverage: 96.751% (-0.006%) from 96.757%
17391978595

Pull #2817

github

web-flow
Merge 9640e6198 into 0ab0b4940
Pull Request #2817: RTF: Add verticalAlign for Section

7 of 8 new or added lines in 1 file covered. (87.5%)

12508 of 12928 relevant lines covered (96.75%)

35.42 hits per line

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

81.25
/src/PhpWord/Writer/RTF/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\Writer\RTF\Style;
20

21
use PhpOffice\PhpWord\Style\Section as SectionStyle;
22

23
/**
24
 * RTF section style writer.
25
 *
26
 * @since 0.12.0
27
 */
28
class Section extends AbstractStyle
29
{
30
    /**
31
     * Write style.
32
     *
33
     * @return string
34
     */
35
    public function write()
36
    {
37
        $style = $this->getStyle();
7✔
38
        if (!$style instanceof SectionStyle) {
7✔
39
            return '';
1✔
40
        }
41

42
        $content = '';
6✔
43

44
        $content .= '\sectd ';
6✔
45

46
        // Size & margin
47
        $content .= $this->getValueIf($style->getPageSizeW() !== null, '\pgwsxn' . round($style->getPageSizeW()));
6✔
48
        $content .= $this->getValueIf($style->getPageSizeH() !== null, '\pghsxn' . round($style->getPageSizeH()));
6✔
49
        $content .= ' ';
6✔
50
        $content .= $this->getValueIf($style->getMarginTop() !== null, '\margtsxn' . round($style->getMarginTop()));
6✔
51
        $content .= $this->getValueIf($style->getMarginRight() !== null, '\margrsxn' . round($style->getMarginRight()));
6✔
52
        $content .= $this->getValueIf($style->getMarginBottom() !== null, '\margbsxn' . round($style->getMarginBottom()));
6✔
53
        $content .= $this->getValueIf($style->getMarginLeft() !== null, '\marglsxn' . round($style->getMarginLeft()));
6✔
54
        $content .= $this->getValueIf($style->getHeaderHeight() !== null, '\headery' . round($style->getHeaderHeight()));
6✔
55
        $content .= $this->getValueIf($style->getFooterHeight() !== null, '\footery' . round($style->getFooterHeight()));
6✔
56
        $content .= $this->getValueIf($style->getGutter() !== null, '\guttersxn' . round($style->getGutter()));
6✔
57
        $content .= $this->getValueIf($style->getPageNumberingStart() !== null, '\pgnstarts' . $style->getPageNumberingStart() . '\pgnrestart');
6✔
58

59
        // Vertical Align
60
        $verticalAlign = [
6✔
61
            \PhpOffice\PhpWord\SimpleType\VerticalJc::TOP => '\vertalt',
6✔
62
            \PhpOffice\PhpWord\SimpleType\VerticalJc::CENTER => '\vertalc',
6✔
63
            \PhpOffice\PhpWord\SimpleType\VerticalJc::BOTH => '\vertalj',
6✔
64
            \PhpOffice\PhpWord\SimpleType\VerticalJc::BOTTOM => '\vertalb',
6✔
65
        ];
6✔
66
        if (isset($verticalAlign[$style->getVAlign()])) {
6✔
NEW
67
            $content .= $verticalAlign[$style->getVAlign()];
×
68
        }
69
        $content .= ' ';
6✔
70

71
        // Borders
72
        if ($style->hasBorder()) {
6✔
73
            $styleWriter = new Border($style);
×
74
            $styleWriter->setParentWriter($this->getParentWriter());
×
75
            $styleWriter->setSizes($style->getBorderSize());
×
76
            $styleWriter->setColors($style->getBorderColor());
×
77
            $content .= $styleWriter->write();
×
78
        }
79

80
        return $content . PHP_EOL;
6✔
81
    }
82
}
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

© 2025 Coveralls, Inc