Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
90.48% |
19 / 21 |
|
0.00% |
0 / 1 |
CRAP | |
0.00% |
0 / 1 |
| Formula | |
90.48% |
19 / 21 |
|
0.00% |
0 / 1 |
3.01 | |
0.00% |
0 / 1 |
| write | |
90.48% |
19 / 21 |
|
0.00% |
0 / 1 |
3.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 version 3 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 | |
| 19 | namespace PhpOffice\PhpWord\Writer\ODText\Element; |
| 20 | |
| 21 | use PhpOffice\PhpWord\Element\Formula as ElementFormula; |
| 22 | use PhpOffice\PhpWord\Shared\Converter; |
| 23 | use PhpOffice\PhpWord\Writer\ODText\Part\AbstractPart; |
| 24 | |
| 25 | /** |
| 26 | * Formula element writer. |
| 27 | * |
| 28 | * @since 0.10.0 |
| 29 | */ |
| 30 | class Formula extends AbstractElement |
| 31 | { |
| 32 | /** |
| 33 | * Write element. |
| 34 | */ |
| 35 | public function write(): void |
| 36 | { |
| 37 | $xmlWriter = $this->getXmlWriter(); |
| 38 | $element = $this->getElement(); |
| 39 | if (!$element instanceof ElementFormula) { |
| 40 | return; |
| 41 | } |
| 42 | |
| 43 | $part = $this->getPart(); |
| 44 | if (!$part instanceof AbstractPart) { |
| 45 | return; |
| 46 | } |
| 47 | |
| 48 | $objectIdx = $part->addObject($element); |
| 49 | |
| 50 | //$style = $element->getStyle(); |
| 51 | //$width = Converter::pixelToCm($style->getWidth()); |
| 52 | //$height = Converter::pixelToCm($style->getHeight()); |
| 53 | |
| 54 | $xmlWriter->startElement('text:p'); |
| 55 | $xmlWriter->writeAttribute('text:style-name', 'OB' . $objectIdx); |
| 56 | |
| 57 | $xmlWriter->startElement('draw:frame'); |
| 58 | $xmlWriter->writeAttribute('draw:name', $element->getElementId()); |
| 59 | $xmlWriter->writeAttribute('text:anchor-type', 'as-char'); |
| 60 | //$xmlWriter->writeAttribute('svg:width', $width . 'cm'); |
| 61 | //$xmlWriter->writeAttribute('svg:height', $height . 'cm'); |
| 62 | //$xmlWriter->writeAttribute('draw:z-index', $mediaIndex); |
| 63 | |
| 64 | $xmlWriter->startElement('draw:object'); |
| 65 | $xmlWriter->writeAttribute('xlink:href', 'Formula' . $objectIdx); |
| 66 | $xmlWriter->writeAttribute('xlink:type', 'simple'); |
| 67 | $xmlWriter->writeAttribute('xlink:show', 'embed'); |
| 68 | $xmlWriter->writeAttribute('xlink:actuate', 'onLoad'); |
| 69 | $xmlWriter->endElement(); // draw:object |
| 70 | |
| 71 | $xmlWriter->endElement(); // draw:frame |
| 72 | |
| 73 | $xmlWriter->endElement(); // text:p |
| 74 | } |
| 75 | } |