Completed
Pull Request — develop (#455)
by
unknown
10:09
created

PowerPoint2007::loadShapeLine()   F

Complexity

Conditions 11
Paths 250

Size

Total Lines 41
Code Lines 25

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 132

Importance

Changes 0
Metric Value
c 0
b 0
f 0
dl 0
loc 41
ccs 0
cts 36
cp 0
rs 3.8181
cc 11
eloc 25
nc 250
nop 3
crap 132

How to fix   Complexity   

Long Method

Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.

For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.

Commonly applied refactorings include:

1
<?php
2
/**
3
 * This file is part of PHPPresentation - A pure PHP library for reading and writing
4
 * presentations documents.
5
 *
6
 * PHPPresentation 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/PHPPresentation/contributors.
12
 *
13
 * @link        https://github.com/PHPOffice/PHPPresentation
14
 * @copyright   2009-2015 PHPPresentation contributors
15
 * @license     http://www.gnu.org/licenses/lgpl.txt LGPL version 3
16
 */
17
18
namespace PhpOffice\PhpPresentation\Reader;
19
20
use PhpOffice\PhpPresentation\DocumentLayout;
21
use PhpOffice\PhpPresentation\PhpPresentation;
22
use PhpOffice\PhpPresentation\Shape\Placeholder;
23
use PhpOffice\PhpPresentation\Shape\RichText;
24
use PhpOffice\PhpPresentation\Shape\RichText\Paragraph;
25
use PhpOffice\PhpPresentation\Shape\Table\Cell;
26
use PhpOffice\PhpPresentation\Slide;
27
use PhpOffice\PhpPresentation\Slide\AbstractSlide;
28
use PhpOffice\PhpPresentation\Slide\SlideLayout;
29
use PhpOffice\PhpPresentation\Slide\SlideMaster;
30
use PhpOffice\PhpPresentation\Shape\Drawing\Gd;
31
use PhpOffice\PhpPresentation\Style\Alignment;
32
use PhpOffice\PhpPresentation\Style\Bullet;
33
use PhpOffice\PhpPresentation\Style\Border;
34
use PhpOffice\PhpPresentation\Style\Borders;
35
use PhpOffice\PhpPresentation\Style\Color;
36
use PhpOffice\PhpPresentation\Style\Fill;
37
use PhpOffice\PhpPresentation\Style\SchemeColor;
38
use PhpOffice\PhpPresentation\Style\TextStyle;
39
use PhpOffice\Common\XMLReader;
40
use PhpOffice\Common\Drawing as CommonDrawing;
41
use ZipArchive;
42
43
/**
44
 * Serialized format reader
45
 */
46
class PowerPoint2007 implements ReaderInterface
47
{
48
    /**
49
     * Output Object
50
     * @var PhpPresentation
51
     */
52
    protected $oPhpPresentation;
53
    /**
54
     * Output Object
55
     * @var \ZipArchive
56
     */
57
    protected $oZip;
58
    /**
59
     * @var array[]
60
     */
61
    protected $arrayRels = array();
62
    /**
63
     * @var SlideLayout[]
64
     */
65
    protected $arraySlideLayouts = array();
66
    /*
67
     * @var string
68
     */
69
    protected $filename;
70
    /*
71
     * @var string
72
     */
73
    protected $fileRels;
74
75
    /**
76
     * Can the current \PhpOffice\PhpPresentation\Reader\ReaderInterface read the file?
77
     *
78
     * @param  string $pFilename
79
     * @throws \Exception
80
     * @return boolean
81
     */
82 2
    public function canRead($pFilename)
83
    {
84 2
        return $this->fileSupportsUnserializePhpPresentation($pFilename);
85
    }
86
87
    /**
88
     * Does a file support UnserializePhpPresentation ?
89
     *
90
     * @param  string $pFilename
91
     * @throws \Exception
92
     * @return boolean
93
     */
94 9
    public function fileSupportsUnserializePhpPresentation($pFilename = '')
95
    {
96
        // Check if file exists
97 9
        if (!file_exists($pFilename)) {
98 2
            throw new \Exception("Could not open " . $pFilename . " for reading! File does not exist.");
99
        }
100
101 7
        $oZip = new ZipArchive();
102
        // Is it a zip ?
103 7
        if ($oZip->open($pFilename) === true) {
104
            // Is it an OpenXML Document ?
105
            // Is it a Presentation ?
106 5
            if (is_array($oZip->statName('[Content_Types].xml')) && is_array($oZip->statName('ppt/presentation.xml'))) {
107 5
                return true;
108
            }
109 1
        }
110 3
        return false;
111
    }
112
113
    /**
114
     * Loads PhpPresentation Serialized file
115
     *
116
     * @param  string $pFilename
117
     * @return \PhpOffice\PhpPresentation\PhpPresentation
118
     * @throws \Exception
119
     */
120 6
    public function load($pFilename)
121
    {
122
        // Unserialize... First make sure the file supports it!
123 6
        if (!$this->fileSupportsUnserializePhpPresentation($pFilename)) {
124 1
            throw new \Exception("Invalid file format for PhpOffice\PhpPresentation\Reader\PowerPoint2007: " . $pFilename . ".");
125
        }
126
127 4
        return $this->loadFile($pFilename);
128
    }
129
130
    /**
131
     * Load PhpPresentation Serialized file
132
     *
133
     * @param  string $pFilename
134
     * @return \PhpOffice\PhpPresentation\PhpPresentation
135
     */
136 4
    protected function loadFile($pFilename)
137
    {
138 4
        $this->oPhpPresentation = new PhpPresentation();
139 4
        $this->oPhpPresentation->removeSlideByIndex();
140 4
        $this->oPhpPresentation->setAllMasterSlides(array());
141 4
        $this->filename = $pFilename;
142
143 4
        $this->oZip = new ZipArchive();
144 4
        $this->oZip->open($this->filename);
145 4
        $this->oZip->extractTo('/Volumes/workspace/testZip/'.basename($pFilename));
146
        $docPropsCore = $this->oZip->getFromName('docProps/core.xml');
147
        if ($docPropsCore !== false) {
148
            $this->loadDocumentProperties($docPropsCore);
149
        }
150
151
        $docPropsCustom = $this->oZip->getFromName('docProps/custom.xml');
152
        if ($docPropsCustom !== false) {
153
            $this->loadCustomProperties($docPropsCustom);
154
        }
155
156
        $pptViewProps = $this->oZip->getFromName('ppt/viewProps.xml');
157
        if ($pptViewProps !== false) {
158
            $this->loadViewProperties($pptViewProps);
159
        }
160
161
        $pptPresentation = $this->oZip->getFromName('ppt/presentation.xml');
162
        if ($pptPresentation !== false) {
163
            $this->loadDocumentLayout($pptPresentation);
164
            $this->loadSlides($pptPresentation);
165
        }
166
167
        return $this->oPhpPresentation;
168
    }
169
170
    /**
171
     * Read Document Layout
172
     * @param $sPart
173
     */
174
    protected function loadDocumentLayout($sPart)
175
    {
176
        $xmlReader = new XMLReader();
177
        if ($xmlReader->getDomFromString($sPart)) {
178
            foreach ($xmlReader->getElements('/p:presentation/p:sldSz') as $oElement) {
179
                if (!($oElement instanceof \DOMElement)) {
180
                    continue;
181
                }
182
                $type = $oElement->getAttribute('type');
183
                $oLayout = $this->oPhpPresentation->getLayout();
184
                if ($type == DocumentLayout::LAYOUT_CUSTOM) {
185
                    $oLayout->setCX($oElement->getAttribute('cx'));
186
                    $oLayout->setCY($oElement->getAttribute('cy'));
187
                } else {
188
                    $oLayout->setDocumentLayout($type, true);
189
                    if ($oElement->getAttribute('cx') < $oElement->getAttribute('cy')) {
190
                        $oLayout->setDocumentLayout($type, false);
191
                    }
192
                }
193
            }
194
        }
195
    }
196
197
    /**
198
     * Read Document Properties
199
     * @param string $sPart
200
     */
201
    protected function loadDocumentProperties($sPart)
202
    {
203
        $xmlReader = new XMLReader();
204
        if ($xmlReader->getDomFromString($sPart)) {
205
            $arrayProperties = array(
206
                '/cp:coreProperties/dc:creator' => 'setCreator',
207
                '/cp:coreProperties/cp:lastModifiedBy' => 'setLastModifiedBy',
208
                '/cp:coreProperties/dc:title' => 'setTitle',
209
                '/cp:coreProperties/dc:description' => 'setDescription',
210
                '/cp:coreProperties/dc:subject' => 'setSubject',
211
                '/cp:coreProperties/cp:keywords' => 'setKeywords',
212
                '/cp:coreProperties/cp:category' => 'setCategory',
213
                '/cp:coreProperties/dcterms:created' => 'setCreated',
214
                '/cp:coreProperties/dcterms:modified' => 'setModified',
215
            );
216
            $oProperties = $this->oPhpPresentation->getDocumentProperties();
217
            foreach ($arrayProperties as $path => $property) {
218
                $oElement = $xmlReader->getElement($path);
219
                if ($oElement instanceof \DOMElement) {
220
                    if ($oElement->hasAttribute('xsi:type') && $oElement->getAttribute('xsi:type') == 'dcterms:W3CDTF') {
221
                        $oDateTime = new \DateTime();
222
                        $oDateTime->createFromFormat(\DateTime::W3C, $oElement->nodeValue);
223
                        $oProperties->{$property}($oDateTime->getTimestamp());
224
                    } else {
225
                        $oProperties->{$property}($oElement->nodeValue);
226
                    }
227
                }
228
            }
229
        }
230
    }
231
232
    /**
233
     * Read Custom Properties
234
     * @param string $sPart
235
     */
236
    protected function loadCustomProperties($sPart)
237
    {
238
        $xmlReader = new XMLReader();
239
        $sPart = str_replace(' xmlns="http://schemas.openxmlformats.org/officeDocument/2006/custom-properties"', '', $sPart);
240
        if ($xmlReader->getDomFromString($sPart)) {
241
            $pathMarkAsFinal = '/Properties/property[@pid="2"][@fmtid="{D5CDD505-2E9C-101B-9397-08002B2CF9AE}"][@name="_MarkAsFinal"]/vt:bool';
242
            if (is_object($oElement = $xmlReader->getElement($pathMarkAsFinal))) {
243
                if ($oElement->nodeValue == 'true') {
244
                    $this->oPhpPresentation->getPresentationProperties()->markAsFinal(true);
245
                }
246
            }
247
        }
248
    }
249
250
    /**
251
     * Read View Properties
252
     * @param string $sPart
253
     */
254
    protected function loadViewProperties($sPart)
255
    {
256
        $xmlReader = new XMLReader();
257
        if ($xmlReader->getDomFromString($sPart)) {
258
            $pathZoom = '/p:viewPr/p:slideViewPr/p:cSldViewPr/p:cViewPr/p:scale/a:sx';
259
            $oElement = $xmlReader->getElement($pathZoom);
260
            if ($oElement instanceof \DOMElement) {
261
                if ($oElement->hasAttribute('d') && $oElement->hasAttribute('n')) {
262
                    $this->oPhpPresentation->getPresentationProperties()->setZoom($oElement->getAttribute('n') / $oElement->getAttribute('d'));
263
                }
264
            }
265
        }
266
    }
267
268
    /**
269
     * Extract all slides
270
     */
271
    protected function loadSlides($sPart)
272
    {
273
        $xmlReader = new XMLReader();
274
        if ($xmlReader->getDomFromString($sPart)) {
275
            $fileRels = 'ppt/_rels/presentation.xml.rels';
276
            $this->loadRels($fileRels);
277
            // Load the Masterslides
278
            $this->loadMasterSlides($xmlReader, $fileRels);
279
            // Continue with loading the slides
280
            foreach ($xmlReader->getElements('/p:presentation/p:sldIdLst/p:sldId') as $oElement) {
281
                if (!($oElement instanceof \DOMElement)) {
282
                    continue;
283
                }
284
                $rId = $oElement->getAttribute('r:id');
285
                $pathSlide = isset($this->arrayRels[$fileRels][$rId]) ? $this->arrayRels[$fileRels][$rId]['Target'] : '';
286
                if (!empty($pathSlide)) {
287
                    $pptSlide = $this->oZip->getFromName('ppt/' . $pathSlide);
288
                    if ($pptSlide !== false) {
289
                        $slideRels = 'ppt/slides/_rels/' . basename($pathSlide) . '.rels';
290
                        $this->loadRels($slideRels);
291
                        $this->loadSlide($pptSlide, basename($pathSlide));
292
                        foreach ($this->arrayRels[$slideRels] as $rel) {
293
                            if ($rel['Type'] == 'http://schemas.openxmlformats.org/officeDocument/2006/relationships/notesSlide') {
294
                                $this->loadSlideNote(basename($rel['Target']), $this->oPhpPresentation->getActiveSlide());
295
                            }
296
                        }
297
                    }
298
                }
299
            }
300
        }
301
    }
302
303
    /**
304
     * Extract all MasterSlides
305
     * @param XMLReader $xmlReader
306
     * @param string $fileRels
307
     */
308
    protected function loadMasterSlides(XMLReader $xmlReader, $fileRels)
309
    {
310
        // Get all the MasterSlide Id's from the presentation.xml file
311
        foreach ($xmlReader->getElements('/p:presentation/p:sldMasterIdLst/p:sldMasterId') as $oElement) {
312
            if (!($oElement instanceof \DOMElement)) {
313
                continue;
314
            }
315
            $rId = $oElement->getAttribute('r:id');
316
            // Get the path to the masterslide from the array with _rels files
317
            $pathMasterSlide = isset($this->arrayRels[$fileRels][$rId]) ?
318
                $this->arrayRels[$fileRels][$rId]['Target'] : '';
319
            if (!empty($pathMasterSlide)) {
320
                $pptMasterSlide = $this->oZip->getFromName('ppt/' . $pathMasterSlide);
321
                if ($pptMasterSlide !== false) {
322
                    $this->loadRels('ppt/slideMasters/_rels/' . basename($pathMasterSlide) . '.rels');
323
                    $this->loadMasterSlide($pptMasterSlide, basename($pathMasterSlide));
324
                }
325
            }
326
        }
327
    }
328
329
    /**
330
     * Extract data from slide
331
     * @param string $sPart
332
     * @param string $baseFile
333
     */
334
    protected function loadSlide($sPart, $baseFile)
335
    {
336
        $xmlReader = new XMLReader();
337
        if ($xmlReader->getDomFromString($sPart)) {
338
            // Core
339
            $oSlide = $this->oPhpPresentation->createSlide();
340
            $this->oPhpPresentation->setActiveSlideIndex($this->oPhpPresentation->getSlideCount() - 1);
341
            $oSlide->setRelsIndex('ppt/slides/_rels/' . $baseFile . '.rels');
342
343
            // Background
344
            $oElement = $xmlReader->getElement('/p:sld/p:cSld/p:bg/p:bgPr');
345
            if ($oElement instanceof \DOMElement) {
346
                $oElementColor = $xmlReader->getElement('a:solidFill/a:srgbClr', $oElement);
347
                if ($oElementColor instanceof \DOMElement) {
348
                    // Color
349
                    $oColor = new Color();
350
                    $oColor->setRGB($oElementColor->hasAttribute('val') ? $oElementColor->getAttribute('val') : null);
351
                    // Background
352
                    $oBackground = new Slide\Background\Color();
353
                    $oBackground->setColor($oColor);
354
                    // Slide Background
355
                    $oSlide = $this->oPhpPresentation->getActiveSlide();
356
                    $oSlide->setBackground($oBackground);
357
                }
358
                $oElementColor = $xmlReader->getElement('a:solidFill/a:schemeClr', $oElement);
359
                if ($oElementColor instanceof \DOMElement) {
360
                    // Color
361
                    $oColor = new SchemeColor();
362
                    $oColor->setValue($oElementColor->hasAttribute('val') ? $oElementColor->getAttribute('val') : null);
363
                    // Background
364
                    $oBackground = new Slide\Background\SchemeColor();
365
                    $oBackground->setSchemeColor($oColor);
366
                    // Slide Background
367
                    $oSlide = $this->oPhpPresentation->getActiveSlide();
368
                    $oSlide->setBackground($oBackground);
369
                }
370
                $oElementImage = $xmlReader->getElement('a:blipFill/a:blip', $oElement);
371
                if ($oElementImage instanceof \DOMElement) {
372
                    $relImg = $this->arrayRels['ppt/slides/_rels/' . $baseFile . '.rels'][$oElementImage->getAttribute('r:embed')];
373
                    if (is_array($relImg)) {
374
                        // File
375
                        $pathImage = 'ppt/slides/' . $relImg['Target'];
376
                        $pathImage = explode('/', $pathImage);
377
                        foreach ($pathImage as $key => $partPath) {
378
                            if ($partPath == '..') {
379
                                unset($pathImage[$key - 1]);
380
                                unset($pathImage[$key]);
381
                            }
382
                        }
383
                        $pathImage = implode('/', $pathImage);
384
                        $contentImg = $this->oZip->getFromName($pathImage);
385
386
                        $tmpBkgImg = tempnam(sys_get_temp_dir(), 'PhpPresentationReaderPpt2007Bkg');
387
                        file_put_contents($tmpBkgImg, $contentImg);
388
                        // Background
389
                        $oBackground = new Slide\Background\Image();
390
                        $oBackground->setPath($tmpBkgImg);
391
                        // Slide Background
392
                        $oSlide = $this->oPhpPresentation->getActiveSlide();
393
                        $oSlide->setBackground($oBackground);
394
                    }
395
                }
396
            }
397
398
            // Shapes
399
            $arrayElements = $xmlReader->getElements('/p:sld/p:cSld/p:spTree/*');
400
            if ($arrayElements) {
401
                $this->loadSlideShapes($oSlide, $arrayElements, $xmlReader);
402
            }
403
404
            // Layout
405
            $oSlide = $this->oPhpPresentation->getActiveSlide();
406
            foreach ($this->arrayRels['ppt/slides/_rels/' . $baseFile . '.rels'] as $valueRel) {
407
                if ($valueRel['Type'] == 'http://schemas.openxmlformats.org/officeDocument/2006/relationships/slideLayout') {
408
                    $layoutBasename = basename($valueRel['Target']);
409
                    if (array_key_exists($layoutBasename, $this->arraySlideLayouts)) {
410
                        $oSlide->setSlideLayout($this->arraySlideLayouts[$layoutBasename]);
411
                    }
412
                    break;
413
                }
414
            }
415
        }
416
    }
417
418
    /**
419
     * @param string $sPart
420
     * @param string $baseFile
421
     */
422
    protected function loadMasterSlide($sPart, $baseFile)
423
    {
424
        $xmlReader = new XMLReader();
425
        if ($xmlReader->getDomFromString($sPart)) {
426
            // Core
427
            $oSlideMaster = $this->oPhpPresentation->createMasterSlide();
428
            $oSlideMaster->setTextStyles(new TextStyle(false));
429
            $oSlideMaster->setRelsIndex('ppt/slideMasters/_rels/' . $baseFile . '.rels');
430
431
            // Background
432
            $oElement = $xmlReader->getElement('/p:sldMaster/p:cSld/p:bg');
433
            if ($oElement instanceof \DOMElement) {
434
                $this->loadSlideBackground($xmlReader, $oElement, $oSlideMaster);
435
            }
436
437
            // Shapes
438
            $arrayElements = $xmlReader->getElements('/p:sldMaster/p:cSld/p:spTree/*');
439
            if ($arrayElements) {
440
                $this->loadSlideShapes($oSlideMaster, $arrayElements, $xmlReader);
441
            }
442
            // Header & Footer
443
444
            // ColorMapping
445
            $colorMap = array();
446
            $oElement = $xmlReader->getElement('/p:sldMaster/p:clrMap');
447
            if ($oElement->hasAttributes()) {
448
                foreach ($oElement->attributes as $attr) {
449
                    $colorMap[$attr->nodeName] = $attr->nodeValue;
450
                }
451
                $oSlideMaster->colorMap->setMapping($colorMap);
452
            }
453
454
            // TextStyles
455
            $arrayElementTxStyles = $xmlReader->getElements('/p:sldMaster/p:txStyles/*');
456
            if ($arrayElementTxStyles) {
457
                foreach ($arrayElementTxStyles as $oElementTxStyle) {
458
                    $arrayElementsLvl = $xmlReader->getElements('/p:sldMaster/p:txStyles/' . $oElementTxStyle->nodeName . '/*');
459
                    foreach ($arrayElementsLvl as $oElementLvl) {
460
                        if (!($oElementLvl instanceof \DOMElement) || $oElementLvl->nodeName == 'a:extLst') {
461
                            continue;
462
                        }
463
                        $oRTParagraph = new Paragraph();
464
465
                        if ($oElementLvl->nodeName == 'a:defPPr') {
466
                            $level = 0;
467
                        } else {
468
                            $level = str_replace('a:lvl', '', $oElementLvl->nodeName);
469
                            $level = str_replace('pPr', '', $level);
470
                        }
471
472
                        if ($oElementLvl->hasAttribute('algn')) {
473
                            $oRTParagraph->getAlignment()->setHorizontal($oElementLvl->getAttribute('algn'));
474
                        }
475
                        if ($oElementLvl->hasAttribute('marL')) {
476
                            $val = $oElementLvl->getAttribute('marL');
477
                            $val = CommonDrawing::emuToPixels($val);
478
                            $oRTParagraph->getAlignment()->setMarginLeft($val);
479
                        }
480
                        if ($oElementLvl->hasAttribute('marR')) {
481
                            $val = $oElementLvl->getAttribute('marR');
482
                            $val = CommonDrawing::emuToPixels($val);
483
                            $oRTParagraph->getAlignment()->setMarginRight($val);
484
                        }
485
                        if ($oElementLvl->hasAttribute('indent')) {
486
                            $val = $oElementLvl->getAttribute('indent');
487
                            $val = CommonDrawing::emuToPixels($val);
488
                            $oRTParagraph->getAlignment()->setIndent($val);
489
                        }
490
                        $oElementLvlDefRPR = $xmlReader->getElement('a:defRPr', $oElementLvl);
491
                        if ($oElementLvlDefRPR instanceof \DOMElement) {
492
                            if ($oElementLvlDefRPR->hasAttribute('sz')) {
493
                                $oRTParagraph->getFont()->setSize($oElementLvlDefRPR->getAttribute('sz') / 100);
494
                            }
495
                            if ($oElementLvlDefRPR->hasAttribute('b') && $oElementLvlDefRPR->getAttribute('b') == 1) {
496
                                $oRTParagraph->getFont()->setBold(true);
497
                            }
498
                            if ($oElementLvlDefRPR->hasAttribute('i') && $oElementLvlDefRPR->getAttribute('i') == 1) {
499
                                $oRTParagraph->getFont()->setItalic(true);
500
                            }
501
                        }
502
                        $oElementSchemeColor = $xmlReader->getElement('a:defRPr/a:solidFill/a:schemeClr', $oElementLvl);
503
                        if ($oElementSchemeColor instanceof \DOMElement) {
504
                            if ($oElementSchemeColor->hasAttribute('val')) {
505
                                $oSchemeColor = new SchemeColor();
506
                                $oSchemeColor->setValue($oElementSchemeColor->getAttribute('val'));
507
                                $oRTParagraph->getFont()->setColor($oSchemeColor);
508
                            }
509
                        }
510
511
                        switch ($oElementTxStyle->nodeName) {
512
                            case 'p:bodyStyle':
513
                                $oSlideMaster->getTextStyles()->setBodyStyleAtLvl($oRTParagraph, $level);
514
                                break;
515
                            case 'p:otherStyle':
516
                                $oSlideMaster->getTextStyles()->setOtherStyleAtLvl($oRTParagraph, $level);
517
                                break;
518
                            case 'p:titleStyle':
519
                                $oSlideMaster->getTextStyles()->setTitleStyleAtLvl($oRTParagraph, $level);
520
                                break;
521
                        }
522
                    }
523
                }
524
            }
525
526
            // Load the theme
527
            foreach ($this->arrayRels[$oSlideMaster->getRelsIndex()] as $arrayRel) {
528
                if ($arrayRel['Type'] == 'http://schemas.openxmlformats.org/officeDocument/2006/relationships/theme') {
529
                    $pptTheme = $this->oZip->getFromName('ppt/' . substr($arrayRel['Target'], strrpos($arrayRel['Target'], '../') + 3));
530
                    if ($pptTheme !== false) {
531
                        $this->loadTheme($pptTheme, $oSlideMaster);
532
                    }
533
                    break;
534
                }
535
            }
536
537
            // Load the Layoutslide
538
            foreach ($xmlReader->getElements('/p:sldMaster/p:sldLayoutIdLst/p:sldLayoutId') as $oElement) {
539
                if (!($oElement instanceof \DOMElement)) {
540
                    continue;
541
                }
542
                $rId = $oElement->getAttribute('r:id');
543
                // Get the path to the masterslide from the array with _rels files
544
                $pathLayoutSlide = isset($this->arrayRels[$oSlideMaster->getRelsIndex()][$rId]) ?
545
                    $this->arrayRels[$oSlideMaster->getRelsIndex()][$rId]['Target'] : '';
546
                if (!empty($pathLayoutSlide)) {
547
                    $pptLayoutSlide = $this->oZip->getFromName('ppt/' . substr($pathLayoutSlide, strrpos($pathLayoutSlide, '../') + 3));
548
                    if ($pptLayoutSlide !== false) {
549
                        $this->loadRels('ppt/slideLayouts/_rels/' . basename($pathLayoutSlide) . '.rels');
550
                        $oSlideMaster->addSlideLayout(
551
                            $this->loadLayoutSlide($pptLayoutSlide, basename($pathLayoutSlide), $oSlideMaster)
552
                        );
553
                    }
554
                }
555
            }
556
        }
557
    }
558
559
    /**
560
     * @param string $sPart
561
     * @param string $baseFile
562
     * @param SlideMaster $oSlideMaster
563
     * @return SlideLayout|null
564
     */
565
    protected function loadLayoutSlide($sPart, $baseFile, SlideMaster $oSlideMaster)
566
    {
567
        $xmlReader = new XMLReader();
568
        if ($xmlReader->getDomFromString($sPart)) {
569
            // Core
570
            $oSlideLayout = new SlideLayout($oSlideMaster);
571
            $oSlideLayout->setRelsIndex('ppt/slideLayouts/_rels/' . $baseFile . '.rels');
572
573
            // Name
574
            $oElement = $xmlReader->getElement('/p:sldLayout/p:cSld');
575
            if ($oElement instanceof \DOMElement && $oElement->hasAttribute('name')) {
576
                $oSlideLayout->setLayoutName($oElement->getAttribute('name'));
577
            }
578
579
            // Background
580
            $oElement = $xmlReader->getElement('/p:sldLayout/p:cSld/p:bg');
581
            if ($oElement instanceof \DOMElement) {
582
                $this->loadSlideBackground($xmlReader, $oElement, $oSlideLayout);
583
            }
584
585
            // ColorMapping
586
            $oElement = $xmlReader->getElement('/p:sldLayout/p:clrMapOvr/a:overrideClrMapping');
587
            if ($oElement instanceof \DOMElement && $oElement->hasAttributes()) {
588
                $colorMap = array();
589
                foreach ($oElement->attributes as $attr) {
590
                    $colorMap[$attr->nodeName] = $attr->nodeValue;
591
                }
592
                $oSlideLayout->colorMap->setMapping($colorMap);
593
            }
594
595
            // Shapes
596
            $oElements = $xmlReader->getElements('/p:sldLayout/p:cSld/p:spTree/*');
597
            if ($oElements) {
598
                $this->loadSlideShapes($oSlideLayout, $oElements, $xmlReader);
599
            }
600
            $this->arraySlideLayouts[$baseFile] = &$oSlideLayout;
601
            return $oSlideLayout;
602
        }
603
        return null;
604
    }
605
606
    /**
607
     * @param string $sPart
608
     * @param SlideMaster $oSlideMaster
609
     */
610
    protected function loadTheme($sPart, SlideMaster $oSlideMaster)
611
    {
612
        $xmlReader = new XMLReader();
613
        if ($xmlReader->getDomFromString($sPart)) {
614
            $oElements = $xmlReader->getElements('/a:theme/a:themeElements/a:clrScheme/*');
615
            if ($oElements) {
616
                foreach ($oElements as $oElement) {
617
                    $oSchemeColor = new SchemeColor();
618
                    $oSchemeColor->setValue(str_replace('a:', '', $oElement->tagName));
619
                    $colorElement = $xmlReader->getElement('*', $oElement);
620
                    if ($colorElement instanceof \DOMElement) {
621
                        if ($colorElement->hasAttribute('lastClr')) {
622
                            $oSchemeColor->setRGB($colorElement->getAttribute('lastClr'));
623
                        } elseif ($colorElement->hasAttribute('val')) {
624
                            $oSchemeColor->setRGB($colorElement->getAttribute('val'));
625
                        }
626
                    }
627
                    $oSlideMaster->addSchemeColor($oSchemeColor);
628
                }
629
            }
630
        }
631
    }
632
633
    /**
634
     * @param XMLReader $xmlReader
635
     * @param \DOMElement $oElement
636
     * @param AbstractSlide $oSlide
637
     */
638
    protected function loadSlideBackground(XMLReader $xmlReader, \DOMElement $oElement, AbstractSlide $oSlide)
639
    {
640
        // Background color
641
        $oElementColor = $xmlReader->getElement('p:bgPr/a:solidFill/a:srgbClr', $oElement);
642
        if ($oElementColor instanceof \DOMElement) {
643
            // Color
644
            $oColor = new Color();
645
            $oColor->setRGB($oElementColor->hasAttribute('val') ? $oElementColor->getAttribute('val') : null);
646
            // Background
647
            $oBackground = new Slide\Background\Color();
648
            $oBackground->setColor($oColor);
649
            // Slide Background
650
            $oSlide->setBackground($oBackground);
651
        }
652
653
        // Background scheme color
654
        $oElementSchemeColor = $xmlReader->getElement('p:bgRef/a:schemeClr', $oElement);
655
        if ($oElementSchemeColor instanceof \DOMElement) {
656
            // Color
657
            $oColor = new SchemeColor();
658
            $oColor->setValue($oElementSchemeColor->hasAttribute('val') ? $oElementSchemeColor->getAttribute('val') : null);
659
            // Background
660
            $oBackground = new Slide\Background\SchemeColor();
661
            $oBackground->setSchemeColor($oColor);
662
            // Slide Background
663
            $oSlide->setBackground($oBackground);
664
        }
665
666
        // Background image
667
        $oElementImage = $xmlReader->getElement('p:bgPr/a:blipFill/a:blip', $oElement);
668
        if ($oElementImage instanceof \DOMElement) {
669
            $relImg = $this->arrayRels[$oSlide->getRelsIndex()][$oElementImage->getAttribute('r:embed')];
670
            if (is_array($relImg)) {
671
                // File
672
                $pathImage = 'ppt/slides/' . $relImg['Target'];
673
                $pathImage = explode('/', $pathImage);
674
                foreach ($pathImage as $key => $partPath) {
675
                    if ($partPath == '..') {
676
                        unset($pathImage[$key - 1]);
677
                        unset($pathImage[$key]);
678
                    }
679
                }
680
                $pathImage = implode('/', $pathImage);
681
                $contentImg = $this->oZip->getFromName($pathImage);
682
683
                $tmpBkgImg = tempnam(sys_get_temp_dir(), 'PhpPresentationReaderPpt2007Bkg');
684
                file_put_contents($tmpBkgImg, $contentImg);
685
                // Background
686
                $oBackground = new Slide\Background\Image();
687
                $oBackground->setPath($tmpBkgImg);
688
                // Slide Background
689
                $oSlide->setBackground($oBackground);
690
            }
691
        }
692
    }
693
694
    /**
695
     * @param string $baseFile
696
     * @param Slide $oSlide
697
     */
698
    protected function loadSlideNote($baseFile, Slide $oSlide)
699
    {
700
        $sPart = $this->oZip->getFromName('ppt/notesSlides/' . $baseFile);
701
        $xmlReader = new XMLReader();
702
        if ($xmlReader->getDomFromString($sPart)) {
703
            $oNote = $oSlide->getNote();
704
705
            $arrayElements = $xmlReader->getElements('/p:notes/p:cSld/p:spTree/*');
706
            if ($arrayElements) {
707
                $this->loadSlideShapes($oNote, $arrayElements, $xmlReader);
708
            }
709
        }
710
    }
711
712
    /**
713
     * @param XMLReader $document
714
     * @param \DOMElement $node
715
     * @param AbstractSlide $oSlide
716
     */
717
    protected function loadShapeDrawing(XMLReader $document, \DOMElement $node, AbstractSlide $oSlide)
718
    {
719
        // Core
720
        $oShape = new Gd();
721
        $oShape->getShadow()->setVisible(false);
722
        // Variables
723
        $fileRels = $oSlide->getRelsIndex();
724
725
        $oElement = $document->getElement('p:nvPicPr/p:cNvPr', $node);
726
        if ($oElement instanceof \DOMElement) {
727
            $oShape->setName($oElement->hasAttribute('name') ? $oElement->getAttribute('name') : '');
728
            $oShape->setDescription($oElement->hasAttribute('descr') ? $oElement->getAttribute('descr') : '');
729
        }
730
731
        $oElement = $document->getElement('p:blipFill/a:blip', $node);
732
        if ($oElement instanceof \DOMElement) {
733
            if ($oElement->hasAttribute('r:embed') && isset($this->arrayRels[$fileRels][$oElement->getAttribute('r:embed')]['Target'])) {
734
                $pathImage = 'ppt/slides/' . $this->arrayRels[$fileRels][$oElement->getAttribute('r:embed')]['Target'];
735
                $pathImage = explode('/', $pathImage);
736
                foreach ($pathImage as $key => $partPath) {
737
                    if ($partPath == '..') {
738
                        unset($pathImage[$key - 1]);
739
                        unset($pathImage[$key]);
740
                    }
741
                }
742
                $pathImage = implode('/', $pathImage);
743
                $imageFile = $this->oZip->getFromName($pathImage);
744
                if (!empty($imageFile)) {
745
                    $oShape->setImageResource(imagecreatefromstring($imageFile));
746
                }
747
            }
748
        }
749
750
        $oElement = $document->getElement('p:spPr', $node);
751
        if ($oElement instanceof \DOMElement) {
752
            $oFill = $this->loadStyleFill($document, $oElement);
753
            $oShape->setFill($oFill);
754
        }
755
756
        $oElement = $document->getElement('p:spPr/a:xfrm', $node);
757
        if ($oElement instanceof \DOMElement) {
758
            if ($oElement->hasAttribute('rot')) {
759
                $oShape->setRotation(CommonDrawing::angleToDegrees($oElement->getAttribute('rot')));
760
            }
761
        }
762
763
        $oElement = $document->getElement('p:spPr/a:xfrm/a:off', $node);
764
        if ($oElement instanceof \DOMElement) {
765
            if ($oElement->hasAttribute('x')) {
766
                $oShape->setOffsetX(CommonDrawing::emuToPixels($oElement->getAttribute('x')));
767
            }
768
            if ($oElement->hasAttribute('y')) {
769
                $oShape->setOffsetY(CommonDrawing::emuToPixels($oElement->getAttribute('y')));
770
            }
771
        }
772
773
774
775
        $oElement = $document->getElement('p:spPr/a:xfrm/a:ext', $node);
776
        if ($oElement instanceof \DOMElement) {
777
            if ($oElement->hasAttribute('cx')) {
778
                $oShape->setWidth(CommonDrawing::emuToPixels($oElement->getAttribute('cx')));
779
            }
780
            if ($oElement->hasAttribute('cy')) {
781
                $oShape->setHeight(CommonDrawing::emuToPixels($oElement->getAttribute('cy')));
782
            }
783
        }
784
785
        $oElement = $document->getElement('p:spPr/a:effectLst', $node);
786
        if ($oElement instanceof \DOMElement) {
787
            $oShape->getShadow()->setVisible(true);
788
789
            $oSubElement = $document->getElement('a:outerShdw', $oElement);
790
            if ($oSubElement instanceof \DOMElement) {
791
                if ($oSubElement->hasAttribute('blurRad')) {
792
                    $oShape->getShadow()->setBlurRadius(CommonDrawing::emuToPixels($oSubElement->getAttribute('blurRad')));
793
                }
794
                if ($oSubElement->hasAttribute('dist')) {
795
                    $oShape->getShadow()->setDistance(CommonDrawing::emuToPixels($oSubElement->getAttribute('dist')));
796
                }
797
                if ($oSubElement->hasAttribute('dir')) {
798
                    $oShape->getShadow()->setDirection(CommonDrawing::angleToDegrees($oSubElement->getAttribute('dir')));
799
                }
800
                if ($oSubElement->hasAttribute('algn')) {
801
                    $oShape->getShadow()->setAlignment($oSubElement->getAttribute('algn'));
802
                }
803
            }
804
805
            $oSubElement = $document->getElement('a:outerShdw/a:srgbClr', $oElement);
806
            if ($oSubElement instanceof \DOMElement) {
807
                if ($oSubElement->hasAttribute('val')) {
808
                    $oColor = new Color();
809
                    $oColor->setRGB($oSubElement->getAttribute('val'));
810
                    $oShape->getShadow()->setColor($oColor);
811
                }
812
            }
813
814
            $oSubElement = $document->getElement('a:outerShdw/a:srgbClr/a:alpha', $oElement);
815
            if ($oSubElement instanceof \DOMElement) {
816
                if ($oSubElement->hasAttribute('val')) {
817
                    $oShape->getShadow()->setAlpha((int)$oSubElement->getAttribute('val') / 1000);
818
                }
819
            }
820
        }
821
822
        $oSlide->addShape($oShape);
823
    }
824
825
    /**
826
     * @param XMLReader $document
827
     * @param \DOMElement $node
828
     * @param AbstractSlide $oSlide
829
     * @throws \Exception
830
     */
831
    protected function loadShapeRichText(XMLReader $document, \DOMElement $node, $oSlide)
832
    {
833
834
//        if (!$document->elementExists('p:txBody/a:p/a:r', $node)) {
835
//            return;
836
//        }
837
838
        // Core
839
        $oShape = $oSlide->createRichTextShape();
840
        $oShape->setParagraphs(array());
841
        // Variables
842
        if ($oSlide instanceof AbstractSlide) {
843
            $this->fileRels = $oSlide->getRelsIndex();
844
        }
845
846
        $oElement = $document->getElement('p:spPr/a:xfrm', $node);
847
        if ($oElement instanceof \DOMElement && $oElement->hasAttribute('rot')) {
848
            $oShape->setRotation(CommonDrawing::angleToDegrees($oElement->getAttribute('rot')));
849
        }
850
851
        $oElement = $document->getElement('p:spPr/a:xfrm/a:off', $node);
852
        if ($oElement instanceof \DOMElement) {
853
            if ($oElement->hasAttribute('x')) {
854
                $oShape->setOffsetX(CommonDrawing::emuToPixels($oElement->getAttribute('x')));
855
            }
856
            if ($oElement->hasAttribute('y')) {
857
                $oShape->setOffsetY(CommonDrawing::emuToPixels($oElement->getAttribute('y')));
858
            }
859
        }
860
861
        $oElement = $document->getElement('p:spPr/a:xfrm/a:ext', $node);
862
        if ($oElement instanceof \DOMElement) {
863
            if ($oElement->hasAttribute('cx')) {
864
                $oShape->setWidth(CommonDrawing::emuToPixels($oElement->getAttribute('cx')));
865
            }
866
            if ($oElement->hasAttribute('cy')) {
867
                $oShape->setHeight(CommonDrawing::emuToPixels($oElement->getAttribute('cy')));
868
            }
869
        }
870
871
        $oElement = $document->getElement('p:nvSpPr/p:nvPr/p:ph', $node);
872
        if ($oElement instanceof \DOMElement) {
873
            if ($oElement->hasAttribute('type')) {
874
                $placeholder = new Placeholder($oElement->getAttribute('type'));
875
                $placeholder->setIdx($oElement->getAttribute('idx'));
876
                $oShape->setPlaceHolder($placeholder);
877
            }
878
        }
879
880
        $oElement = $document->getElement('p:txBody/a:bodyPr', $node);
881
        if ($oElement instanceof \DOMElement) {
882
            if ($oElement->hasAttribute('lIns')) {
883
                $oShape->setInsetLeft($oElement->getAttribute('lIns'));
884
            }
885
886
            if ($oElement->hasAttribute('tIns')) {
887
                $oShape->setInsetTop($oElement->getAttribute('tIns'));
888
            }
889
890
            if ($oElement->hasAttribute('rIns')) {
891
                $oShape->setInsetRight($oElement->getAttribute('rIns'));
892
            }
893
894
            if ($oElement->hasAttribute('bIns')) {
895
                $oShape->setInsetBottom($oElement->getAttribute('bIns'));
896
            }
897
898
//            if ($oElement->hasAttribute('anchor')) {
899
//                $alignment = new Alignment();
900
//                $alignment->setVertical($oElement->getAttribute('anchor'));
901
//                $oShape->getActiveParagraph()->setAlignment($alignment);
902
//            }
903
904
            if ($oElement->hasAttribute('wrap')) {
905
                $oShape->setWrap($oElement->getAttribute('wrap'));
906
            }
907
0 ignored issues
show
Coding Style introduced by
Blank line found at end of control structure
Loading history...
908
        }
909
910
        $oElement = $document->getElement('p:txBody/a:lstStyle', $node);
911
        if ($oElement instanceof \DOMElement) {
912
            $oShape->setListStyle($oElement);
913
        }
914
915
916
        $arrayElements = $document->getElements('p:txBody/a:p', $node);
917
        foreach ($arrayElements as $oElement) {
918
            $this->loadParagraph($document, $oElement, $oShape);
919
        }
920
921
        if (count($oShape->getParagraphs()) > 0) {
922
            $oShape->setActiveParagraph(0);
923
        }
924
925
        $oElement = $document->getElement('p:spPr', $node);
926
        if ($oElement instanceof \DOMElement) {
927
            $oFill = $this->loadStyleFill($document, $oElement);
928
            $oShape->setFill($oFill);
929
        }
930
931
    }
932
933
    /**
934
     * @param XMLReader $document
935
     * @param \DOMElement $node
936
     * @param AbstractSlide $oSlide
937
     * @throws \Exception
938
     */
939
    protected function loadShapeTable(XMLReader $document, \DOMElement $node, AbstractSlide $oSlide)
940
    {
941
        $this->fileRels = $oSlide->getRelsIndex();
942
943
        $oShape = $oSlide->createTableShape();
944
945
        $oElement = $document->getElement('p:cNvPr', $node);
946
        if ($oElement instanceof \DOMElement) {
947
            if ($oElement->hasAttribute('name')) {
948
                $oShape->setName($oElement->getAttribute('name'));
949
            }
950
            if ($oElement->hasAttribute('descr')) {
951
                $oShape->setDescription($oElement->getAttribute('descr'));
952
            }
953
        }
954
955
        $oElement = $document->getElement('p:xfrm/a:off', $node);
956
        if ($oElement instanceof \DOMElement) {
957
            if ($oElement->hasAttribute('x')) {
958
                $oShape->setOffsetX(CommonDrawing::emuToPixels($oElement->getAttribute('x')));
959
            }
960
            if ($oElement->hasAttribute('y')) {
961
                $oShape->setOffsetY(CommonDrawing::emuToPixels($oElement->getAttribute('y')));
962
            }
963
        }
964
965
        $oElement = $document->getElement('p:xfrm/a:ext', $node);
966
        if ($oElement instanceof \DOMElement) {
967
            if ($oElement->hasAttribute('cx')) {
968
                $oShape->setWidth(CommonDrawing::emuToPixels($oElement->getAttribute('cx')));
969
            }
970
            if ($oElement->hasAttribute('cy')) {
971
                $oShape->setHeight(CommonDrawing::emuToPixels($oElement->getAttribute('cy')));
972
            }
973
        }
974
975
        $arrayElements = $document->getElements('a:graphic/a:graphicData/a:tbl/a:tblGrid/a:gridCol', $node);
976
        $oShape->setNumColumns($arrayElements->length);
977
        $oShape->createRow();
978
        foreach ($arrayElements as $key => $oElement) {
979
            if ($oElement instanceof \DOMElement && $oElement->getAttribute('w')) {
980
                $oShape->getRow(0)->getCell($key)->setWidth(CommonDrawing::emuToPixels($oElement->getAttribute('w')));
981
            }
982
        }
983
984
        $arrayElements = $document->getElements('a:graphic/a:graphicData/a:tbl/a:tr', $node);
985
        foreach ($arrayElements as $keyRow => $oElementRow) {
986
            if (!($oElementRow instanceof \DOMElement)) {
987
                continue;
988
            }
989
            $oRow = $oShape->getRow($keyRow, true);
990
            if (is_null($oRow)) {
991
                $oRow = $oShape->createRow();
992
            }
993
            if ($oElementRow->hasAttribute('h')) {
994
                $oRow->setHeight(CommonDrawing::emuToPixels($oElementRow->getAttribute('h')));
995
            }
996
            $arrayElementsCell = $document->getElements('a:tc', $oElementRow);
997
            foreach ($arrayElementsCell as $keyCell => $oElementCell) {
998
                if (!($oElementCell instanceof \DOMElement)) {
999
                    continue;
1000
                }
1001
                $oCell = $oRow->getCell($keyCell);
1002
                $oCell->setParagraphs(array());
1003
                if ($oElementCell->hasAttribute('gridSpan')) {
1004
                    $oCell->setColSpan($oElementCell->getAttribute('gridSpan'));
1005
                }
1006
                if ($oElementCell->hasAttribute('rowSpan')) {
1007
                    $oCell->setRowSpan($oElementCell->getAttribute('rowSpan'));
1008
                }
1009
1010
                foreach ($document->getElements('a:txBody/a:p', $oElementCell) as $oElementPara) {
1011
                    $this->loadParagraph($document, $oElementPara, $oCell);
0 ignored issues
show
Bug introduced by
It seems like $oCell defined by $oRow->getCell($keyCell) on line 1001 can be null; however, PhpOffice\PhpPresentatio...nt2007::loadParagraph() does not accept null, maybe add an additional type check?

Unless you are absolutely sure that the expression can never be null because of other conditions, we strongly recommend to add an additional type check to your code:

/** @return stdClass|null */
function mayReturnNull() { }

function doesNotAcceptNull(stdClass $x) { }

// With potential error.
function withoutCheck() {
    $x = mayReturnNull();
    doesNotAcceptNull($x); // Potential error here.
}

// Safe - Alternative 1
function withCheck1() {
    $x = mayReturnNull();
    if ( ! $x instanceof stdClass) {
        throw new \LogicException('$x must be defined.');
    }
    doesNotAcceptNull($x);
}

// Safe - Alternative 2
function withCheck2() {
    $x = mayReturnNull();
    if ($x instanceof stdClass) {
        doesNotAcceptNull($x);
    }
}
Loading history...
1012
                }
1013
1014
                $oElementTcPr = $document->getElement('a:tcPr', $oElementCell);
1015
                if ($oElementTcPr instanceof \DOMElement) {
1016
                    $numParagraphs = count($oCell->getParagraphs());
1017
                    if ($numParagraphs > 0) {
1018
                        if ($oElementTcPr->hasAttribute('vert')) {
1019
                            $oCell->getParagraph(0)->getAlignment()->setTextDirection($oElementTcPr->getAttribute('vert'));
1020
                        }
1021
                        if ($oElementTcPr->hasAttribute('anchor')) {
1022
                            $oCell->getParagraph(0)->getAlignment()->setVertical($oElementTcPr->getAttribute('anchor'));
1023
                        }
1024
                        if ($oElementTcPr->hasAttribute('marB')) {
1025
                            $oCell->getParagraph(0)->getAlignment()->setMarginBottom($oElementTcPr->getAttribute('marB'));
1026
                        }
1027
                        if ($oElementTcPr->hasAttribute('marL')) {
1028
                            $oCell->getParagraph(0)->getAlignment()->setMarginLeft($oElementTcPr->getAttribute('marL'));
1029
                        }
1030
                        if ($oElementTcPr->hasAttribute('marR')) {
1031
                            $oCell->getParagraph(0)->getAlignment()->setMarginRight($oElementTcPr->getAttribute('marR'));
1032
                        }
1033
                        if ($oElementTcPr->hasAttribute('marT')) {
1034
                            $oCell->getParagraph(0)->getAlignment()->setMarginTop($oElementTcPr->getAttribute('marT'));
1035
                        }
1036
                    }
1037
1038
                    $oFill = $this->loadStyleFill($document, $oElementTcPr);
1039
                    if ($oFill instanceof Fill) {
1040
                        $oCell->setFill($oFill);
1041
                    }
1042
1043
                    $oBorders = new Borders();
1044
                    $oElementBorderL = $document->getElement('a:lnL', $oElementTcPr);
1045
                    if ($oElementBorderL instanceof \DOMElement) {
1046
                        $this->loadStyleBorder($document, $oElementBorderL, $oBorders->getLeft());
1047
                    }
1048
                    $oElementBorderR = $document->getElement('a:lnR', $oElementTcPr);
1049
                    if ($oElementBorderR instanceof \DOMElement) {
1050
                        $this->loadStyleBorder($document, $oElementBorderR, $oBorders->getRight());
1051
                    }
1052
                    $oElementBorderT = $document->getElement('a:lnT', $oElementTcPr);
1053
                    if ($oElementBorderT instanceof \DOMElement) {
1054
                        $this->loadStyleBorder($document, $oElementBorderT, $oBorders->getTop());
1055
                    }
1056
                    $oElementBorderB = $document->getElement('a:lnB', $oElementTcPr);
1057
                    if ($oElementBorderB instanceof \DOMElement) {
1058
                        $this->loadStyleBorder($document, $oElementBorderB, $oBorders->getBottom());
1059
                    }
1060
                    $oElementBorderDiagDown = $document->getElement('a:lnTlToBr', $oElementTcPr);
1061
                    if ($oElementBorderDiagDown instanceof \DOMElement) {
1062
                        $this->loadStyleBorder($document, $oElementBorderDiagDown, $oBorders->getDiagonalDown());
1063
                    }
1064
                    $oElementBorderDiagUp = $document->getElement('a:lnBlToTr', $oElementTcPr);
1065
                    if ($oElementBorderDiagUp instanceof \DOMElement) {
1066
                        $this->loadStyleBorder($document, $oElementBorderDiagUp, $oBorders->getDiagonalUp());
1067
                    }
1068
                    $oCell->setBorders($oBorders);
1069
                }
1070
            }
1071
        }
1072
    }
1073
1074
    protected function loadShapeLine(XMLReader $document, \DOMElement $node, AbstractSlide $oSlide)
1075
    {
1076
        $oElement = $document->getElement('p:spPr/a:xfrm/a:off', $node);
1077
        if ($oElement instanceof \DOMElement) {
1078
            if ($oElement->hasAttribute('x')) {
1079
                $offsetX  = CommonDrawing::emuToPixels($oElement->getAttribute('x'));
1080
            }
1081
            if ($oElement->hasAttribute('y')) {
1082
                $offsetY = CommonDrawing::emuToPixels($oElement->getAttribute('y'));
1083
            }
1084
        }
1085
1086
        $oElement = $document->getElement('p:spPr/a:xfrm/a:ext', $node);
1087
        if ($oElement instanceof \DOMElement) {
1088
            if ($oElement->hasAttribute('cx')) {
1089
                $width = CommonDrawing::emuToPixels($oElement->getAttribute('cx'));
1090
            }
1091
            if ($oElement->hasAttribute('cy')) {
1092
                $height = CommonDrawing::emuToPixels($oElement->getAttribute('cy'));
1093
            }
1094
        }
1095
1096
        $lineShape = $oSlide->createLineShape($offsetX, $offsetY,  $width + $offsetX, $height + $offsetY);
0 ignored issues
show
Bug introduced by
The variable $offsetX does not seem to be defined for all execution paths leading up to this point.

If you define a variable conditionally, it can happen that it is not defined for all execution paths.

Let’s take a look at an example:

function myFunction($a) {
    switch ($a) {
        case 'foo':
            $x = 1;
            break;

        case 'bar':
            $x = 2;
            break;
    }

    // $x is potentially undefined here.
    echo $x;
}

In the above example, the variable $x is defined if you pass “foo” or “bar” as argument for $a. However, since the switch statement has no default case statement, if you pass any other value, the variable $x would be undefined.

Available Fixes

  1. Check for existence of the variable explicitly:

    function myFunction($a) {
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
        }
    
        if (isset($x)) { // Make sure it's always set.
            echo $x;
        }
    }
    
  2. Define a default value for the variable:

    function myFunction($a) {
        $x = ''; // Set a default which gets overridden for certain paths.
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
        }
    
        echo $x;
    }
    
  3. Add a value for the missing path:

    function myFunction($a) {
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
    
            // We add support for the missing case.
            default:
                $x = '';
                break;
        }
    
        echo $x;
    }
    
Loading history...
Bug introduced by
The variable $offsetY does not seem to be defined for all execution paths leading up to this point.

If you define a variable conditionally, it can happen that it is not defined for all execution paths.

Let’s take a look at an example:

function myFunction($a) {
    switch ($a) {
        case 'foo':
            $x = 1;
            break;

        case 'bar':
            $x = 2;
            break;
    }

    // $x is potentially undefined here.
    echo $x;
}

In the above example, the variable $x is defined if you pass “foo” or “bar” as argument for $a. However, since the switch statement has no default case statement, if you pass any other value, the variable $x would be undefined.

Available Fixes

  1. Check for existence of the variable explicitly:

    function myFunction($a) {
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
        }
    
        if (isset($x)) { // Make sure it's always set.
            echo $x;
        }
    }
    
  2. Define a default value for the variable:

    function myFunction($a) {
        $x = ''; // Set a default which gets overridden for certain paths.
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
        }
    
        echo $x;
    }
    
  3. Add a value for the missing path:

    function myFunction($a) {
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
    
            // We add support for the missing case.
            default:
                $x = '';
                break;
        }
    
        echo $x;
    }
    
Loading history...
Bug introduced by
The variable $width does not seem to be defined for all execution paths leading up to this point.

If you define a variable conditionally, it can happen that it is not defined for all execution paths.

Let’s take a look at an example:

function myFunction($a) {
    switch ($a) {
        case 'foo':
            $x = 1;
            break;

        case 'bar':
            $x = 2;
            break;
    }

    // $x is potentially undefined here.
    echo $x;
}

In the above example, the variable $x is defined if you pass “foo” or “bar” as argument for $a. However, since the switch statement has no default case statement, if you pass any other value, the variable $x would be undefined.

Available Fixes

  1. Check for existence of the variable explicitly:

    function myFunction($a) {
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
        }
    
        if (isset($x)) { // Make sure it's always set.
            echo $x;
        }
    }
    
  2. Define a default value for the variable:

    function myFunction($a) {
        $x = ''; // Set a default which gets overridden for certain paths.
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
        }
    
        echo $x;
    }
    
  3. Add a value for the missing path:

    function myFunction($a) {
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
    
            // We add support for the missing case.
            default:
                $x = '';
                break;
        }
    
        echo $x;
    }
    
Loading history...
Bug introduced by
The variable $height does not seem to be defined for all execution paths leading up to this point.

If you define a variable conditionally, it can happen that it is not defined for all execution paths.

Let’s take a look at an example:

function myFunction($a) {
    switch ($a) {
        case 'foo':
            $x = 1;
            break;

        case 'bar':
            $x = 2;
            break;
    }

    // $x is potentially undefined here.
    echo $x;
}

In the above example, the variable $x is defined if you pass “foo” or “bar” as argument for $a. However, since the switch statement has no default case statement, if you pass any other value, the variable $x would be undefined.

Available Fixes

  1. Check for existence of the variable explicitly:

    function myFunction($a) {
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
        }
    
        if (isset($x)) { // Make sure it's always set.
            echo $x;
        }
    }
    
  2. Define a default value for the variable:

    function myFunction($a) {
        $x = ''; // Set a default which gets overridden for certain paths.
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
        }
    
        echo $x;
    }
    
  3. Add a value for the missing path:

    function myFunction($a) {
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
    
            // We add support for the missing case.
            default:
                $x = '';
                break;
        }
    
        echo $x;
    }
    
Loading history...
Coding Style introduced by
Expected 1 space instead of 2 after comma in function call.
Loading history...
1097
1098
        $oElement = $document->getElement('p:nvCxnSpPr', $node);
1099
        if ($oElement instanceof \DOMElement) {
1100
            if ($oElement->hasAttribute('name')) {
1101
                $lineShape->setName($oElement->getAttribute('name'));
0 ignored issues
show
Bug introduced by
The method setName() does not seem to exist on object<PhpOffice\PhpPresentation\Shape\Line>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
1102
            }
1103
            if ($oElement->hasAttribute('descr')) {
1104
                $lineShape->setDescription($oElement->getAttribute('descr'));
0 ignored issues
show
Bug introduced by
The method setDescription() does not seem to exist on object<PhpOffice\PhpPresentation\Shape\Line>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
1105
            }
1106
        }
1107
1108
        $oElement = $document->getElement('p:spPr/a:ln/a:solidFill/a:srgbClr', $node);
1109
        if ($oElement instanceof \DOMElement) {
1110
            $oColor = new Color();
1111
            $oColor->setRGB($oElement->getAttribute('val'));
1112
            $lineShape->getBorder()->setColor($oColor);
1113
        }
1114
    }
1115
1116
    /**
1117
     * @param XMLReader $document
1118
     * @param \DOMElement $oElement
1119
     * @param Cell|RichText $oShape
1120
     * @throws \Exception
1121
     */
1122
    protected function loadParagraph(XMLReader $document, \DOMElement $oElement, $oShape)
1123
    {
1124
        // Core
1125
        $oParagraph = $oShape->createParagraph();
1126
        $oParagraph->setRichTextElements(array());
1127
1128
        $oSubElement = $document->getElement('a:pPr', $oElement);
1129
        if ($oSubElement instanceof \DOMElement) {
1130
            if ($oSubElement->hasAttribute('algn')) {
1131
                $oParagraph->getAlignment()->setHorizontal($oSubElement->getAttribute('algn'));
1132
            }
1133
            if ($oSubElement->hasAttribute('fontAlgn')) {
1134
                $oParagraph->getAlignment()->setVertical($oSubElement->getAttribute('fontAlgn'));
1135
            }
1136
            if ($oSubElement->hasAttribute('marL')) {
1137
                $oParagraph->getAlignment()->setMarginLeft(CommonDrawing::emuToPixels($oSubElement->getAttribute('marL')));
1138
            }
1139
            if ($oSubElement->hasAttribute('marR')) {
1140
                $oParagraph->getAlignment()->setMarginRight(CommonDrawing::emuToPixels($oSubElement->getAttribute('marR')));
1141
            }
1142
            if ($oSubElement->hasAttribute('indent')) {
1143
                $oParagraph->getAlignment()->setIndent(CommonDrawing::emuToPixels($oSubElement->getAttribute('indent')));
1144
            }
1145
            if ($oSubElement->hasAttribute('lvl')) {
1146
                $oParagraph->getAlignment()->setLevel($oSubElement->getAttribute('lvl'));
1147
            }
1148
1149
            $oParagraph->getBulletStyle()->setBulletType(Bullet::TYPE_NONE);
1150
1151
            $oElementBuFont = $document->getElement('a:buFont', $oSubElement);
1152
            if ($oElementBuFont instanceof \DOMElement) {
1153
                if ($oElementBuFont->hasAttribute('typeface')) {
1154
                    $oParagraph->getBulletStyle()->setBulletFont($oElementBuFont->getAttribute('typeface'));
1155
                }
1156
            }
1157
            $oElementBuChar = $document->getElement('a:buChar', $oSubElement);
1158
            if ($oElementBuChar instanceof \DOMElement) {
1159
                $oParagraph->getBulletStyle()->setBulletType(Bullet::TYPE_BULLET);
1160
                if ($oElementBuChar->hasAttribute('char')) {
1161
                    $oParagraph->getBulletStyle()->setBulletChar($oElementBuChar->getAttribute('char'));
1162
                }
1163
            }
1164
            $oElementBuAutoNum = $document->getElement('a:buAutoNum', $oSubElement);
1165
            if ($oElementBuAutoNum instanceof \DOMElement) {
1166
                $oParagraph->getBulletStyle()->setBulletType(Bullet::TYPE_NUMERIC);
1167
                if ($oElementBuAutoNum->hasAttribute('type')) {
1168
                    $oParagraph->getBulletStyle()->setBulletNumericStyle($oElementBuAutoNum->getAttribute('type'));
1169
                }
1170
                if ($oElementBuAutoNum->hasAttribute('startAt') && $oElementBuAutoNum->getAttribute('startAt') != 1) {
1171
                    $oParagraph->getBulletStyle()->setBulletNumericStartAt($oElementBuAutoNum->getAttribute('startAt'));
1172
                }
1173
            }
1174
            $oElementBuClr = $document->getElement('a:buClr', $oSubElement);
1175
            if ($oElementBuClr instanceof \DOMElement) {
1176
                $oColor = new Color();
1177
                /**
1178
                 * @todo Create protected for reading Color
1179
                 */
1180
                $oElementColor = $document->getElement('a:srgbClr', $oElementBuClr);
1181
                if ($oElementColor instanceof \DOMElement) {
1182
                    $oColor->setRGB($oElementColor->hasAttribute('val') ? $oElementColor->getAttribute('val') : null);
1183
                }
1184
                $oParagraph->getBulletStyle()->setBulletColor($oColor);
1185
            }
1186
        }
1187
        $arraySubElements = $document->getElements('(a:r|a:br)', $oElement);
1188
        foreach ($arraySubElements as $oSubElement) {
1189
            if ($oSubElement->tagName == 'a:br') {
1190
                $oParagraph->createBreak();
1191
            }
1192
            if ($oSubElement->tagName == 'a:r') {
1193
                $oElementrPr = $document->getElement('a:rPr', $oSubElement);
1194
                if (is_object($oElementrPr)) {
1195
                    $oText = $oParagraph->createTextRun();
1196
1197
                    if ($oElementrPr->hasAttribute('b')) {
0 ignored issues
show
Bug introduced by
The method hasAttribute() does not exist on DOMNode. Did you maybe mean hasAttributes()?

This check marks calls to methods that do not seem to exist on an object.

This is most likely the result of a method being renamed without all references to it being renamed likewise.

Loading history...
1198
                        $att = $oElementrPr->getAttribute('b');
1199
                        $oText->getFont()->setBold($att == 'true' || $att == '1' ? true : false);
1200
                    }
1201
                    if ($oElementrPr->hasAttribute('i')) {
0 ignored issues
show
Bug introduced by
The method hasAttribute() does not exist on DOMNode. Did you maybe mean hasAttributes()?

This check marks calls to methods that do not seem to exist on an object.

This is most likely the result of a method being renamed without all references to it being renamed likewise.

Loading history...
1202
                        $att = $oElementrPr->getAttribute('i');
1203
                        $oText->getFont()->setItalic($att == 'true' || $att == '1' ? true : false);
1204
                    }
1205
                    if ($oElementrPr->hasAttribute('strike')) {
0 ignored issues
show
Bug introduced by
The method hasAttribute() does not exist on DOMNode. Did you maybe mean hasAttributes()?

This check marks calls to methods that do not seem to exist on an object.

This is most likely the result of a method being renamed without all references to it being renamed likewise.

Loading history...
1206
                        $oText->getFont()->setStrikethrough($oElementrPr->getAttribute('strike') == 'noStrike' ? false : true);
1207
                    }
1208
                    if ($oElementrPr->hasAttribute('sz')) {
0 ignored issues
show
Bug introduced by
The method hasAttribute() does not exist on DOMNode. Did you maybe mean hasAttributes()?

This check marks calls to methods that do not seem to exist on an object.

This is most likely the result of a method being renamed without all references to it being renamed likewise.

Loading history...
1209
                        $oText->getFont()->setSize((int)($oElementrPr->getAttribute('sz') / 100));
1210
                    }
1211
                    if ($oElementrPr->hasAttribute('u')) {
0 ignored issues
show
Bug introduced by
The method hasAttribute() does not exist on DOMNode. Did you maybe mean hasAttributes()?

This check marks calls to methods that do not seem to exist on an object.

This is most likely the result of a method being renamed without all references to it being renamed likewise.

Loading history...
1212
                        $oText->getFont()->setUnderline($oElementrPr->getAttribute('u'));
1213
                    }
1214
                    if ($oElementrPr->hasAttribute('dirty')) {
0 ignored issues
show
Bug introduced by
The method hasAttribute() does not exist on DOMNode. Did you maybe mean hasAttributes()?

This check marks calls to methods that do not seem to exist on an object.

This is most likely the result of a method being renamed without all references to it being renamed likewise.

Loading history...
1215
                        $oText->setDirty($oElementrPr->getAttribute('dirty'));
1216
                    }
1217
                    
1218
                    $fontType = $document->getElement('a:latin', $oElementrPr);
0 ignored issues
show
Documentation introduced by
$oElementrPr is of type object<DOMNode>, but the function expects a null|object<DOMElement>.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
1219
                    if (is_object($fontType) && $fontType->hasAttribute('typeface')) {
0 ignored issues
show
Bug introduced by
The method hasAttribute() does not exist on DOMNode. Did you maybe mean hasAttributes()?

This check marks calls to methods that do not seem to exist on an object.

This is most likely the result of a method being renamed without all references to it being renamed likewise.

Loading history...
1220
                        $oText->getFont()->setName($fontType->getAttribute('typeface'));
1221
                    }
1222
                    
1223
                    // Color
1224
                    $oElementSrgbClr = $document->getElement('a:solidFill/a:srgbClr', $oElementrPr);
0 ignored issues
show
Documentation introduced by
$oElementrPr is of type object<DOMNode>, but the function expects a null|object<DOMElement>.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
1225
                    if (is_object($oElementSrgbClr) && $oElementSrgbClr->hasAttribute('val')) {
0 ignored issues
show
Bug introduced by
The method hasAttribute() does not exist on DOMNode. Did you maybe mean hasAttributes()?

This check marks calls to methods that do not seem to exist on an object.

This is most likely the result of a method being renamed without all references to it being renamed likewise.

Loading history...
1226
                        $oColor = new Color();
1227
                        $oColor->setRGB($oElementSrgbClr->getAttribute('val'));
1228
                        $oText->getFont()->setColor($oColor);
1229
                    }
1230
1231
                    // Hyperlink
1232
                    $oElementHlinkClick = $document->getElement('a:hlinkClick', $oElementrPr);
0 ignored issues
show
Documentation introduced by
$oElementrPr is of type object<DOMNode>, but the function expects a null|object<DOMElement>.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
1233
                    if (is_object($oElementHlinkClick)) {
1234
                        if ($oElementHlinkClick->hasAttribute('tooltip')) {
0 ignored issues
show
Bug introduced by
The method hasAttribute() does not exist on DOMNode. Did you maybe mean hasAttributes()?

This check marks calls to methods that do not seem to exist on an object.

This is most likely the result of a method being renamed without all references to it being renamed likewise.

Loading history...
1235
                            $oText->getHyperlink()->setTooltip($oElementHlinkClick->getAttribute('tooltip'));
1236
                        }
1237
                        if ($oElementHlinkClick->hasAttribute('r:id') && isset($this->arrayRels[$this->fileRels][$oElementHlinkClick->getAttribute('r:id')]['Target'])) {
0 ignored issues
show
Bug introduced by
The method hasAttribute() does not exist on DOMNode. Did you maybe mean hasAttributes()?

This check marks calls to methods that do not seem to exist on an object.

This is most likely the result of a method being renamed without all references to it being renamed likewise.

Loading history...
1238
                            $oText->getHyperlink()->setUrl($this->arrayRels[$this->fileRels][$oElementHlinkClick->getAttribute('r:id')]['Target']);
1239
                        }
1240
                    }
1241
                    //} else {
1242
                    // $oText = $oParagraph->createText();
1243
1244
                    $oSubSubElement = $document->getElement('a:t', $oSubElement);
1245
                    $oText->setText($oSubSubElement->nodeValue);
1246
                }
1247
            }
1248
        }
1249
    }
1250
1251
    /**
1252
     * @param XMLReader $xmlReader
1253
     * @param \DOMElement $oElement
1254
     * @param Border $oBorder
1255
     */
1256
    protected function loadStyleBorder(XMLReader $xmlReader, \DOMElement $oElement, Border $oBorder)
1257
    {
1258
        if ($oElement->hasAttribute('w')) {
1259
            $oBorder->setLineWidth($oElement->getAttribute('w') / 12700);
1260
        }
1261
        if ($oElement->hasAttribute('cmpd')) {
1262
            $oBorder->setLineStyle($oElement->getAttribute('cmpd'));
1263
        }
1264
1265
        $oElementNoFill = $xmlReader->getElement('a:noFill', $oElement);
1266
        if ($oElementNoFill instanceof \DOMElement && $oBorder->getLineStyle() == Border::LINE_SINGLE) {
1267
            $oBorder->setLineStyle(Border::LINE_NONE);
1268
        }
1269
1270
        $oElementColor = $xmlReader->getElement('a:solidFill/a:srgbClr', $oElement);
1271
        if ($oElementColor instanceof \DOMElement) {
1272
            $oBorder->setColor($this->loadStyleColor($xmlReader, $oElementColor));
1273
        }
1274
1275
        $oElementDashStyle = $xmlReader->getElement('a:prstDash', $oElement);
1276
        if ($oElementDashStyle instanceof \DOMElement && $oElementDashStyle->hasAttribute('val')) {
1277
            $oBorder->setDashStyle($oElementDashStyle->getAttribute('val'));
1278
        }
1279
    }
1280
1281
    /**
1282
     * @param XMLReader $xmlReader
1283
     * @param \DOMElement $oElement
1284
     * @return Color
1285
     */
1286
    protected function loadStyleColor(XMLReader $xmlReader, \DOMElement $oElement)
1287
    {
1288
        $oColor = new Color();
1289
        $oColor->setRGB($oElement->getAttribute('val'));
1290
        $oElementAlpha = $xmlReader->getElement('a:alpha', $oElement);
1291
        if ($oElementAlpha instanceof \DOMElement && $oElementAlpha->hasAttribute('val')) {
1292
            $alpha = strtoupper(dechex((($oElementAlpha->getAttribute('val') / 1000) / 100) * 255));
1293
            $oColor->setRGB($oElement->getAttribute('val'), $alpha);
1294
        }
1295
        return $oColor;
1296
    }
1297
1298
    /**
1299
     * @param XMLReader $xmlReader
1300
     * @param \DOMElement $oElement
1301
     * @return null|Fill
1302
     */
1303
    protected function loadStyleFill(XMLReader $xmlReader, \DOMElement $oElement)
1304
    {
1305
        // Gradient fill
1306
        $oElementFill = $xmlReader->getElement('a:gradFill', $oElement);
1307
        if ($oElementFill instanceof \DOMElement) {
1308
            $oFill = new Fill();
1309
            $oFill->setFillType(Fill::FILL_GRADIENT_LINEAR);
1310
1311
            $oElementColor = $xmlReader->getElement('a:gsLst/a:gs[@pos="0"]/a:srgbClr', $oElementFill);
1312
            if ($oElementColor instanceof \DOMElement && $oElementColor->hasAttribute('val')) {
1313
                $oFill->setStartColor($this->loadStyleColor($xmlReader, $oElementColor));
1314
            }
1315
1316
            $oElementColor = $xmlReader->getElement('a:gsLst/a:gs[@pos="100000"]/a:srgbClr', $oElementFill);
1317
            if ($oElementColor instanceof \DOMElement && $oElementColor->hasAttribute('val')) {
1318
                $oFill->setEndColor($this->loadStyleColor($xmlReader, $oElementColor));
1319
            }
1320
1321
            $oRotation = $xmlReader->getElement('a:lin', $oElementFill);
1322
            if ($oRotation instanceof \DOMElement && $oRotation->hasAttribute('ang')) {
1323
                $oFill->setRotation(CommonDrawing::angleToDegrees($oRotation->getAttribute('ang')));
1324
            }
1325
            return $oFill;
1326
        }
1327
1328
        // Solid fill
1329
        $oElementFill = $xmlReader->getElement('a:solidFill', $oElement);
1330
        if ($oElementFill instanceof \DOMElement) {
1331
            $oFill = new Fill();
1332
            $oFill->setFillType(Fill::FILL_SOLID);
1333
1334
            $oElementColor = $xmlReader->getElement('a:srgbClr', $oElementFill);
1335
            if ($oElementColor instanceof \DOMElement) {
1336
                $oFill->setStartColor($this->loadStyleColor($xmlReader, $oElementColor));
1337
            }
1338
            return $oFill;
1339
        }
1340
        return null;
1341
    }
1342
1343
    /**
1344
     * @param string $fileRels
1345
     * @return string
1346
     */
1347
    protected function loadRels($fileRels)
1348
    {
1349
        $sPart = $this->oZip->getFromName($fileRels);
1350
        if ($sPart !== false) {
1351
            $xmlReader = new XMLReader();
1352
            if ($xmlReader->getDomFromString($sPart)) {
1353
                foreach ($xmlReader->getElements('*') as $oNode) {
1354
                    if (!($oNode instanceof \DOMElement)) {
1355
                        continue;
1356
                    }
1357
                    $this->arrayRels[$fileRels][$oNode->getAttribute('Id')] = array(
1358
                        'Target' => $oNode->getAttribute('Target'),
1359
                        'Type' => $oNode->getAttribute('Type'),
1360
                    );
1361
                }
1362
            }
1363
        }
1364
    }
1365
1366
    /**
1367
     * @param $oSlide
1368
     * @param \DOMNodeList $oElements
1369
     * @param XMLReader $xmlReader
1370
     * @internal param $baseFile
1371
     */
1372
    protected function loadSlideShapes($oSlide, $oElements, $xmlReader)
1373
    {
1374
        foreach ($oElements as $oNode) {
1375
            switch ($oNode->tagName) {
1376
                case 'p:graphicFrame':
1377
                    $this->loadShapeTable($xmlReader, $oNode, $oSlide);
1378
                    break;
1379
                case 'p:pic':
1380
                    $this->loadShapeDrawing($xmlReader, $oNode, $oSlide);
1381
                    break;
1382
                case 'p:sp':
1383
                    $this->loadShapeRichText($xmlReader, $oNode, $oSlide);
1384
                    break;
1385
                case 'p:cxnSp':
1386
                    $this->loadShapeLine($xmlReader, $oNode, $oSlide);
1387
                    break;
1388
                default:
1389
                    //var_export($oNode->tagName);
1390
            }
1391
        }
1392
    }
1393
}
1394