Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
93.10% covered (success)
93.10%
27 / 29
0.00% covered (danger)
0.00%
0 / 1
CRAP
0.00% covered (danger)
0.00%
0 / 1
Line
93.10% covered (success)
93.10%
27 / 29
0.00% covered (danger)
0.00%
0 / 1
7.02
0.00% covered (danger)
0.00%
0 / 1
 write
93.10% covered (success)
93.10%
27 / 29
0.00% covered (danger)
0.00%
0 / 1
7.02
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 view 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 * @license http://www.gnu.org/licenses/lgpl.txt LGPL version 3
15 */
16
17namespace PhpOffice\PhpWord\Writer\ODText\Element;
18
19use PhpOffice\PhpWord\Element\Line as LineElement;
20use PhpOffice\PhpWord\Shared\Converter;
21use PhpOffice\PhpWord\Style\Line as LineStyle;
22
23/**
24 * Line element writer.
25 */
26class Line extends AbstractElement
27{
28    public function write(): void
29    {
30        $element = $this->getElement();
31        if (!$element instanceof LineElement) {
32            return;
33        }
34
35        $style = $element->getStyle() ?: new LineStyle();
36        if (!$style->getStyleName()) {
37            $style->setStyleName($element->getElementId());
38        }
39        $width = $style->getWidth() ?? 0;
40        $height = $style->getHeight() ?? 0;
41        $left = $style->getMarginLeft();
42        $top = $style->getMarginTop();
43        $x1 = $left;
44        $y1 = $top;
45        $x2 = $left + $width;
46        $y2 = $top + $height;
47        if ($style->isFlip()) {
48            [$x1, $x2] = [$x2, $x1];
49            [$y1, $y2] = [$y2, $y1];
50        }
51
52        $xmlWriter = $this->getXmlWriter();
53        if (!$this->withoutP) {
54            $xmlWriter->startElement('text:p');
55        }
56        $xmlWriter->startElement('draw:line');
57        $xmlWriter->writeAttribute('draw:style-name', $style->getStyleName());
58        $xmlWriter->writeAttribute('svg:x1', Converter::pointToCm($x1) . 'cm');
59        $xmlWriter->writeAttribute('svg:y1', Converter::pointToCm($y1) . 'cm');
60        $xmlWriter->writeAttribute('svg:x2', Converter::pointToCm($x2) . 'cm');
61        $xmlWriter->writeAttribute('svg:y2', Converter::pointToCm($y2) . 'cm');
62        $xmlWriter->endElement(); // draw:line
63        if (!$this->withoutP) {
64            $xmlWriter->endElement(); // text:p
65        }
66    }
67}