Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
100.00% covered (success)
100.00%
39 / 39
100.00% covered (success)
100.00%
1 / 1
CRAP
100.00% covered (success)
100.00%
1 / 1
OLEObject
100.00% covered (success)
100.00%
39 / 39
100.00% covered (success)
100.00%
1 / 1
5
100.00% covered (success)
100.00%
1 / 1
 write
100.00% covered (success)
100.00%
39 / 39
100.00% covered (success)
100.00%
1 / 1
5
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\Word2007\Element;
19
20use PhpOffice\PhpWord\Writer\Word2007\Style\Image as ImageStyleWriter;
21
22/**
23 * OLEObject element writer.
24 *
25 * @since 0.10.0
26 */
27class OLEObject extends AbstractElement
28{
29    /**
30     * Write object element.
31     */
32    public function write(): void
33    {
34        $xmlWriter = $this->getXmlWriter();
35        $element = $this->getElement();
36        if (!$element instanceof \PhpOffice\PhpWord\Element\OLEObject) {
37            return;
38        }
39
40        $rIdObject = $element->getRelationId() + ($element->isInSection() ? 6 : 0);
41        $rIdImage = $element->getImageRelationId() + ($element->isInSection() ? 6 : 0);
42        $shapeId = md5($rIdObject . '_' . $rIdImage);
43        $objectId = $element->getRelationId() + 1325353440;
44
45        $style = $element->getStyle();
46        $styleWriter = new ImageStyleWriter($xmlWriter, $style);
47
48        if (!$this->withoutP) {
49            $xmlWriter->startElement('w:p');
50            $styleWriter->writeAlignment();
51        }
52        $this->writeCommentRangeStart();
53
54        $xmlWriter->startElement('w:r');
55        $xmlWriter->startElement('w:object');
56        $xmlWriter->writeAttribute('w:dxaOrig', '249');
57        $xmlWriter->writeAttribute('w:dyaOrig', '160');
58
59        // Icon
60        $xmlWriter->startElement('v:shape');
61        $xmlWriter->writeAttribute('id', $shapeId);
62        $xmlWriter->writeAttribute('type', '#_x0000_t75');
63        $xmlWriter->writeAttribute('style', 'width:104px;height:67px');
64        $xmlWriter->writeAttribute('o:ole', '');
65
66        $xmlWriter->startElement('v:imagedata');
67        $xmlWriter->writeAttribute('r:id', 'rId' . $rIdImage);
68        $xmlWriter->writeAttribute('o:title', '');
69        $xmlWriter->endElement(); // v:imagedata
70
71        $xmlWriter->endElement(); // v:shape
72
73        // Object
74        $xmlWriter->startElement('o:OLEObject');
75        $xmlWriter->writeAttribute('Type', 'Embed');
76        $xmlWriter->writeAttribute('ProgID', 'Package');
77        $xmlWriter->writeAttribute('ShapeID', $shapeId);
78        $xmlWriter->writeAttribute('DrawAspect', 'Icon');
79        $xmlWriter->writeAttribute('ObjectID', '_' . $objectId);
80        $xmlWriter->writeAttribute('r:id', 'rId' . $rIdObject);
81        $xmlWriter->endElement(); // o:OLEObject
82
83        $xmlWriter->endElement(); // w:object
84        $xmlWriter->endElement(); // w:r
85
86        $this->endElementP(); // w:p
87    }
88}