Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
100.00% covered (success)
100.00%
25 / 25
100.00% covered (success)
100.00%
1 / 1
CRAP
100.00% covered (success)
100.00%
1 / 1
Line
100.00% covered (success)
100.00%
25 / 25
100.00% covered (success)
100.00%
1 / 1
5
100.00% covered (success)
100.00%
1 / 1
 writeStroke
100.00% covered (success)
100.00%
25 / 25
100.00% covered (success)
100.00%
1 / 1
5
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\Style;
20
21use PhpOffice\PhpWord\Style\Line as LineStyle;
22
23/**
24 * Line style writer.
25 */
26class Line extends Frame
27{
28    /**
29     * Write Line stroke.
30     *
31     * @todo Merge with `Stroke` style
32     */
33    public function writeStroke(): void
34    {
35        $xmlWriter = $this->getXmlWriter();
36        $style = $this->getStyle();
37        if (!$style instanceof LineStyle) {
38            return;
39        }
40
41        $dash = $style->getDash();
42        $dashStyles = [
43            LineStyle::DASH_STYLE_DASH => 'dash',
44            LineStyle::DASH_STYLE_ROUND_DOT => '1 1',
45            LineStyle::DASH_STYLE_SQUARE_DOT => '1 1',
46            LineStyle::DASH_STYLE_DASH_DOT => 'dashDot',
47            LineStyle::DASH_STYLE_LONG_DASH => 'longDash',
48            LineStyle::DASH_STYLE_LONG_DASH_DOT => 'longDashDot',
49            LineStyle::DASH_STYLE_LONG_DASH_DOT_DOT => 'longDashDotDot',
50        ];
51
52        $xmlWriter->startElement('v:stroke');
53
54        $xmlWriter->writeAttributeIf($style->getWeight() !== null, 'weight', $style->getWeight() . 'pt');
55        $xmlWriter->writeAttributeIf($style->getColor() !== null, 'color', $style->getColor());
56        $xmlWriter->writeAttributeIf($style->getBeginArrow() !== null, 'startarrow', $style->getBeginArrow());
57        $xmlWriter->writeAttributeIf($style->getEndArrow() !== null, 'endarrow', $style->getEndArrow());
58
59        if ($dash !== null) {
60            if (isset($dashStyles[$dash])) {
61                $xmlWriter->writeAttribute('dashstyle', $dashStyles[$dash]);
62            }
63            if ($dash == LineStyle::DASH_STYLE_ROUND_DOT) {
64                $xmlWriter->writeAttribute('endcap', 'round');
65            }
66        }
67
68        $xmlWriter->endElement(); //v:stroke
69    }
70}