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