Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
96.55% covered (success)
96.55%
28 / 29
0.00% covered (danger)
0.00%
0 / 1
CRAP
0.00% covered (danger)
0.00%
0 / 1
TextBox
96.55% covered (success)
96.55%
28 / 29
0.00% covered (danger)
0.00%
0 / 1
4
0.00% covered (danger)
0.00%
0 / 1
 write
96.55% covered (success)
96.55%
28 / 29
0.00% covered (danger)
0.00%
0 / 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 * PHPWord is free software distributed under the terms of the GNU Lesser
6 * General Public License version 3 as published by the Free Software Foundation.
7 * For the full copyright and license information, please read the LICENSE
8 * file that was distributed with this source code. For the full list of
9 * contributors, visit https://github.com/PHPOffice/PHPWord/contributors.
10 *
11 * @see         https://github.com/PHPOffice/PHPWord
12 *
13 * @license     http://www.gnu.org/licenses/lgpl.txt LGPL version 3
14 */
15
16namespace PhpOffice\PhpWord\Writer\Word2007\Element;
17
18use PhpOffice\PhpWord\Writer\Word2007\Style\TextBox as TextBoxStyleWriter;
19
20/**
21 * TextBox element writer.
22 *
23 * @since 0.11.0
24 */
25class TextBox extends Image
26{
27    /**
28     * Write element.
29     */
30    public function write(): void
31    {
32        $xmlWriter = $this->getXmlWriter();
33        $element = $this->getElement();
34        if (!$element instanceof \PhpOffice\PhpWord\Element\TextBox) {
35            return;
36        }
37        $style = $element->getStyle();
38        $styleWriter = new TextBoxStyleWriter($xmlWriter, $style);
39
40        if (!$this->withoutP) {
41            $xmlWriter->startElement('w:p');
42            $styleWriter->writeAlignment();
43        }
44        $this->writeCommentRangeStart();
45
46        $xmlWriter->startElement('w:r');
47        $xmlWriter->startElement('w:pict');
48        $xmlWriter->startElement('v:shape');
49        $xmlWriter->writeAttribute('type', '#_x0000_t0202');
50
51        if ($style->getBgColor()) {
52            $xmlWriter->writeAttribute('fillcolor', $style->getBgColor());
53        }
54
55        $styleWriter->write();
56        $styleWriter->writeBorder();
57
58        $xmlWriter->startElement('v:textbox');
59        $styleWriter->writeInnerMargin();
60
61        // TextBox content, serving as a container
62        $xmlWriter->startElement('w:txbxContent');
63        $containerWriter = new Container($xmlWriter, $element);
64        $containerWriter->write();
65        $xmlWriter->endElement(); // w:txbxContent
66
67        $xmlWriter->endElement(); // v: textbox
68
69        $xmlWriter->endElement(); // v:shape
70        $xmlWriter->endElement(); // w:pict
71        $xmlWriter->endElement(); // w:r
72
73        $this->endElementP();
74    }
75}