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

PHPOffice / PHPWord / 12764732518

14 Jan 2025 09:28AM UTC coverage: 96.946%. Remained the same
12764732518

Pull #2310

github

web-flow
Merge f9a348c3e into 639f39635
Pull Request #2310: Add function addcell

1 of 1 new or added line in 1 file covered. (100.0%)

11903 of 12278 relevant lines covered (96.95%)

33.21 hits per line

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

90.0
/src/PhpWord/Writer/HTML/Style/Paragraph.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\HTML\Style;
20

21
use PhpOffice\PhpWord\Shared\Converter;
22
use PhpOffice\PhpWord\SimpleType\Jc;
23
use PhpOffice\PhpWord\Writer\PDF\TCPDF;
24

25
/**
26
 * Paragraph style HTML writer.
27
 *
28
 * @since 0.10.0
29
 */
30
class Paragraph extends AbstractStyle
31
{
32
    /**
33
     * Write style.
34
     *
35
     * @return string
36
     */
37
    public function write()
38
    {
39
        $style = $this->getStyle();
32✔
40
        if (!$style instanceof \PhpOffice\PhpWord\Style\Paragraph) {
32✔
41
            return '';
1✔
42
        }
43
        $css = [];
31✔
44

45
        // Alignment
46
        if ('' !== $style->getAlignment()) {
31✔
47
            $textAlign = '';
2✔
48

49
            switch ($style->getAlignment()) {
2✔
50
                case Jc::CENTER:
51
                    $textAlign = 'center';
1✔
52

53
                    break;
1✔
54
                case Jc::END:
55
                    $textAlign = $style->isBidi() ? 'left' : 'right';
1✔
56

57
                    break;
1✔
58
                case Jc::MEDIUM_KASHIDA:
59
                case Jc::HIGH_KASHIDA:
60
                case Jc::LOW_KASHIDA:
61
                case Jc::RIGHT:
62
                    $textAlign = 'right';
×
63

64
                    break;
×
65
                case Jc::BOTH:
66
                case Jc::DISTRIBUTE:
67
                case Jc::THAI_DISTRIBUTE:
68
                case Jc::JUSTIFY:
69
                    $textAlign = 'justify';
1✔
70

71
                    break;
1✔
72
                case Jc::LEFT:
73
                    $textAlign = 'left';
×
74

75
                    break;
×
76
                default: //all others, including Jc::START
77
                    $textAlign = $style->isBidi() ? 'right' : 'left';
2✔
78

79
                    break;
2✔
80
            }
81

82
            $css['text-align'] = $textAlign;
2✔
83
        }
84

85
        // Spacing
86
        $spacing = $style->getSpace();
31✔
87
        if (null !== $spacing) {
31✔
88
            $before = $spacing->getBefore();
7✔
89
            $after = $spacing->getAfter();
7✔
90
            $css['margin-top'] = $this->getValueIf(null !== $before, ($before / 20) . 'pt');
7✔
91
            $css['margin-bottom'] = $this->getValueIf(null !== $after, ($after / 20) . 'pt');
7✔
92
        }
93

94
        // Line Height
95
        $lineHeight = $style->getLineHeight();
31✔
96
        if (!empty($lineHeight)) {
31✔
97
            $css['line-height'] = $lineHeight;
3✔
98
        }
99

100
        // Indentation (Margin)
101
        $indentation = $style->getIndentation();
31✔
102
        if ($indentation) {
31✔
103
            $inches = $indentation->getLeft() * 1.0 / Converter::INCH_TO_TWIP;
2✔
104
            $css[$this->getParentWriter() instanceof TCPDF ? 'text-indent' : 'margin-left'] = ((string) $inches) . 'in';
2✔
105

106
            $inches = $indentation->getRight() * 1.0 / Converter::INCH_TO_TWIP;
2✔
107
            $css['margin-right'] = ((string) $inches) . 'in';
2✔
108
        }
109

110
        // Page Break Before
111
        if ($style->hasPageBreakBefore()) {
31✔
112
            $css['page-break-before'] = 'always';
1✔
113
        }
114

115
        // Bidirectional
116
        if ($style->isBidi()) {
31✔
117
            $css['direction'] = 'rtl';
1✔
118
        }
119

120
        return $this->assembleCss($css);
31✔
121
    }
122
}
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