Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
94.12% covered (success)
94.12%
16 / 17
0.00% covered (danger)
0.00%
0 / 1
CRAP
0.00% covered (danger)
0.00%
0 / 1
TextBox
94.12% covered (success)
94.12%
16 / 17
0.00% covered (danger)
0.00%
0 / 1
6.01
0.00% covered (danger)
0.00%
0 / 1
 write
94.12% covered (success)
94.12%
16 / 17
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\Style;
20
21use PhpOffice\PhpWord\Shared\Converter;
22
23/**
24 * Text box graphic style writer.
25 */
26class TextBox extends AbstractStyle
27{
28    public function write(): void
29    {
30        $style = $this->getStyle();
31        if (!$style instanceof \PhpOffice\PhpWord\Style\TextBox) {
32            return;
33        }
34
35        $xmlWriter = $this->getXmlWriter();
36        $xmlWriter->startElement('style:style');
37        $xmlWriter->writeAttribute('style:name', $style->getStyleName());
38        $xmlWriter->writeAttribute('style:family', 'graphic');
39        $xmlWriter->startElement('style:graphic-properties');
40        Graphic::writeFillAndStroke($xmlWriter, $style->getBgColor() === null ? null : new \PhpOffice\PhpWord\Style\Fill(['color' => $style->getBgColor()]), $style->getBorderColor() === null ? null : new \PhpOffice\PhpWord\Style\Outline(['weight' => $style->getBorderSize(), 'color' => $style->getBorderColor()]));
41        if ($style->hasInnerMargins()) {
42            $margins = $style->getInnerMargin();
43            $padding = [];
44            foreach ([$margins[1], $margins[2], $margins[3], $margins[0]] as $margin) {
45                $padding[] = Converter::pointToCm($margin / 20) . 'cm';
46            }
47            $xmlWriter->writeAttribute('fo:padding', implode(' ', $padding));
48        }
49        $xmlWriter->endElement();
50        $xmlWriter->endElement();
51    }
52}