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