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