Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
90.48% covered (success)
90.48%
19 / 21
0.00% covered (danger)
0.00%
0 / 1
CRAP
0.00% covered (danger)
0.00%
0 / 1
Formula
90.48% covered (success)
90.48%
19 / 21
0.00% covered (danger)
0.00%
0 / 1
3.01
0.00% covered (danger)
0.00%
0 / 1
 write
90.48% covered (success)
90.48%
19 / 21
0.00% covered (danger)
0.00%
0 / 1
3.01
1<?php
2/**
3 * This file is part of PHPWord - A pure PHP library for reading and writing
4 * word processing documents.
5 *
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 *
9 * For the full copyright and license information, please read the LICENSE
10 * file that was distributed with this source code. For the full list of
11 * contributors, visit https://github.com/PHPOffice/PHPWord/contributors.
12 *
13 * @see         https://github.com/PHPOffice/PHPWord
14 *
15 * @license     http://www.gnu.org/licenses/lgpl.txt LGPL version 3
16 */
17
18namespace PhpOffice\PhpWord\Writer\ODText\Element;
19
20use PhpOffice\PhpWord\Element\Formula as ElementFormula;
21use PhpOffice\PhpWord\Shared\Converter;
22use PhpOffice\PhpWord\Writer\ODText\Part\AbstractPart;
23
24/**
25 * Formula element writer.
26 *
27 * @since 0.10.0
28 */
29class Formula extends AbstractElement
30{
31    /**
32     * Write element.
33     */
34    public function write(): void
35    {
36        $xmlWriter = $this->getXmlWriter();
37        $element = $this->getElement();
38        if (!$element instanceof ElementFormula) {
39            return;
40        }
41
42        $part = $this->getPart();
43        if (!$part instanceof AbstractPart) {
44            return;
45        }
46
47        $objectIdx = $part->addObject($element);
48
49        //$style = $element->getStyle();
50        //$width = Converter::pixelToCm($style->getWidth());
51        //$height = Converter::pixelToCm($style->getHeight());
52
53        $xmlWriter->startElement('text:p');
54        $xmlWriter->writeAttribute('text:style-name', 'OB' . $objectIdx);
55
56        $xmlWriter->startElement('draw:frame');
57        $xmlWriter->writeAttribute('draw:name', $element->getElementId());
58        $xmlWriter->writeAttribute('text:anchor-type', 'as-char');
59        //$xmlWriter->writeAttribute('svg:width', $width . 'cm');
60        //$xmlWriter->writeAttribute('svg:height', $height . 'cm');
61        //$xmlWriter->writeAttribute('draw:z-index', $mediaIndex);
62
63        $xmlWriter->startElement('draw:object');
64        $xmlWriter->writeAttribute('xlink:href', 'Formula' . $objectIdx);
65        $xmlWriter->writeAttribute('xlink:type', 'simple');
66        $xmlWriter->writeAttribute('xlink:show', 'embed');
67        $xmlWriter->writeAttribute('xlink:actuate', 'onLoad');
68        $xmlWriter->endElement(); // draw:object
69
70        $xmlWriter->endElement(); // draw:frame
71
72        $xmlWriter->endElement(); // text:p
73    }
74}