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/**
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
19namespace PhpOffice\PhpWord\Writer\Word2007\Element;
20
21use PhpOffice\PhpWord\Element\Line as LineElement;
22use PhpOffice\PhpWord\Writer\Word2007\Style\Line as LineStyleWriter;
23
24/**
25 * Line element writer.
26 */
27class Line extends AbstractElement
28{
29    /**
30     * Write element.
31     */
32    public function write(): void
33    {
34        $xmlWriter = $this->getXmlWriter();
35        $element = $this->getElement();
36        if (!$element instanceof LineElement) {
37            return;
38        }
39
40        $style = $element->getStyle();
41        $styleWriter = new LineStyleWriter($xmlWriter, $style);
42
43        $elementId = $element->getElementIndex();
44
45        if (!$this->withoutP) {
46            $xmlWriter->startElement('w:p');
47            $styleWriter->writeAlignment();
48        }
49        $this->writeCommentRangeStart();
50
51        $xmlWriter->startElement('w:r');
52        $xmlWriter->startElement('w:pict');
53
54        // Shapetype could be defined for each line separately, but then a unique id would be necessary
55        if ($elementId == 1) {
56            $xmlWriter->startElement('v:shapetype');
57            $xmlWriter->writeAttribute('id', '_x0000_t32');
58            $xmlWriter->writeAttribute('coordsize', '21600,21600');
59            $xmlWriter->writeAttribute('o:spt', '32');
60            $xmlWriter->writeAttribute('o:oned', 't');
61            $xmlWriter->writeAttribute('path', 'm,l21600,21600e');
62            $xmlWriter->writeAttribute('filled', 'f');
63            $xmlWriter->startElement('v:path');
64            $xmlWriter->writeAttribute('arrowok', 't');
65            $xmlWriter->writeAttribute('fillok', 'f');
66            $xmlWriter->writeAttribute('o:connecttype', 'none');
67            $xmlWriter->endElement(); // v:path
68            $xmlWriter->startElement('o:lock');
69            $xmlWriter->writeAttribute('v:ext', 'edit');
70            $xmlWriter->writeAttribute('shapetype', 't');
71            $xmlWriter->endElement(); // o:lock
72            $xmlWriter->endElement(); // v:shapetype
73        }
74
75        $xmlWriter->startElement('v:shape');
76        $xmlWriter->writeAttribute('id', sprintf('_x0000_s1%1$03d', $elementId));
77        $xmlWriter->writeAttribute('type', '#_x0000_t32'); //type should correspond to shapetype id
78
79        $styleWriter->write();
80        $styleWriter->writeStroke();
81
82        $xmlWriter->endElement(); // v:shape
83
84        $xmlWriter->endElement(); // w:pict
85        $xmlWriter->endElement(); // w:r
86
87        $this->endElementP(); // w:p
88    }
89}