Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
92.86% covered (success)
92.86%
13 / 14
0.00% covered (danger)
0.00%
0 / 1
CRAP
0.00% covered (danger)
0.00%
0 / 1
Shape
92.86% covered (success)
92.86%
13 / 14
0.00% covered (danger)
0.00%
0 / 1
6.01
0.00% covered (danger)
0.00%
0 / 1
 write
92.86% covered (success)
92.86%
13 / 14
0.00% covered (danger)
0.00%
0 / 1
6.01
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 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\ODText\Element;
20
21use PhpOffice\PhpWord\Element\Shape as ShapeElement;
22use PhpOffice\PhpWord\Writer\ODText\Style\Graphic;
23
24/**
25 * Basic ODF shape element writer.
26 */
27class Shape extends AbstractElement
28{
29    public function write(): void
30    {
31        $element = $this->getElement();
32        if (!$element instanceof ShapeElement || !in_array($element->getType(), ['rect', 'oval', 'polyline'], true)) {
33            return;
34        }
35
36        $xmlWriter = $this->getXmlWriter();
37        $style = $element->getStyle();
38        $name = $element->getType() === 'oval' ? 'draw:ellipse' : 'draw:' . $element->getType();
39        $xmlWriter->startElement($name);
40        $xmlWriter->writeAttribute('draw:style-name', $style->getStyleName());
41        $xmlWriter->writeAttribute('text:anchor-type', 'as-char');
42        if ($style->getFrame() !== null) {
43            Graphic::writeFrameProperties($xmlWriter, $style->getFrame());
44        }
45        if ($element->getType() === 'polyline') {
46            $xmlWriter->writeAttributeIf($style->getPoints() !== null, 'draw:points', $style->getPoints());
47        }
48        $xmlWriter->endElement();
49    }
50}