Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
100.00% covered (success)
100.00%
40 / 40
100.00% covered (success)
100.00%
1 / 1
CRAP
100.00% covered (success)
100.00%
1 / 1
Line
100.00% covered (success)
100.00%
40 / 40
100.00% covered (success)
100.00%
1 / 1
4
100.00% covered (success)
100.00%
1 / 1
 write
100.00% covered (success)
100.00%
40 / 40
100.00% covered (success)
100.00%
1 / 1
4
1<?php
2/**
3 * This file is part of PHPWord - A pure PHP library for reading and writing
4 * word processing documents.
5 *
6 * PHPWord is free software distributed under the terms of the GNU Lesser
7 * General Public License version 3 as published by the Free Software Foundation.
8 *
9 * For the full copyright and license information, please read the LICENSE
10 * file that was distributed with this source code. For the full list of
11 * contributors, visit https://github.com/PHPOffice/PHPWord/contributors.
12 *
13 * @see         https://github.com/PHPOffice/PHPWord
14 *
15 * @license     http://www.gnu.org/licenses/lgpl.txt LGPL version 3
16 */
17
18namespace PhpOffice\PhpWord\Writer\Word2007\Element;
19
20use PhpOffice\PhpWord\Element\Line as LineElement;
21use PhpOffice\PhpWord\Writer\Word2007\Style\Line as LineStyleWriter;
22
23/**
24 * Line element writer.
25 */
26class Line extends AbstractElement
27{
28    /**
29     * Write element.
30     */
31    public function write(): void
32    {
33        $xmlWriter = $this->getXmlWriter();
34        $element = $this->getElement();
35        if (!$element instanceof LineElement) {
36            return;
37        }
38
39        $style = $element->getStyle();
40        $styleWriter = new LineStyleWriter($xmlWriter, $style);
41
42        $elementId = $element->getElementIndex();
43
44        if (!$this->withoutP) {
45            $xmlWriter->startElement('w:p');
46            $styleWriter->writeAlignment();
47        }
48        $this->writeCommentRangeStart();
49
50        $xmlWriter->startElement('w:r');
51        $xmlWriter->startElement('w:pict');
52
53        // Shapetype could be defined for each line separately, but then a unique id would be necessary
54        if ($elementId == 1) {
55            $xmlWriter->startElement('v:shapetype');
56            $xmlWriter->writeAttribute('id', '_x0000_t32');
57            $xmlWriter->writeAttribute('coordsize', '21600,21600');
58            $xmlWriter->writeAttribute('o:spt', '32');
59            $xmlWriter->writeAttribute('o:oned', 't');
60            $xmlWriter->writeAttribute('path', 'm,l21600,21600e');
61            $xmlWriter->writeAttribute('filled', 'f');
62            $xmlWriter->startElement('v:path');
63            $xmlWriter->writeAttribute('arrowok', 't');
64            $xmlWriter->writeAttribute('fillok', 'f');
65            $xmlWriter->writeAttribute('o:connecttype', 'none');
66            $xmlWriter->endElement(); // v:path
67            $xmlWriter->startElement('o:lock');
68            $xmlWriter->writeAttribute('v:ext', 'edit');
69            $xmlWriter->writeAttribute('shapetype', 't');
70            $xmlWriter->endElement(); // o:lock
71            $xmlWriter->endElement(); // v:shapetype
72        }
73
74        $xmlWriter->startElement('v:shape');
75        $xmlWriter->writeAttribute('id', sprintf('_x0000_s1%1$03d', $elementId));
76        $xmlWriter->writeAttribute('type', '#_x0000_t32'); //type should correspond to shapetype id
77
78        $styleWriter->write();
79        $styleWriter->writeStroke();
80
81        $xmlWriter->endElement(); // v:shape
82
83        $xmlWriter->endElement(); // w:pict
84        $xmlWriter->endElement(); // w:r
85
86        $this->endElementP(); // w:p
87    }
88}