Completed
Pull Request — develop (#208)
by Franck
08:10
created

PowerPoint97::readStructureTextSIRun()   B

Complexity

Conditions 7
Paths 32

Size

Total Lines 52
Code Lines 37

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 37
CRAP Score 7.0206

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 52
ccs 37
cts 40
cp 0.925
rs 7.2396
cc 7
eloc 37
nc 32
nop 3
crap 7.0206

How to fix   Long Method   

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\Common\Microsoft\OLERead;
21
use PhpOffice\PhpPresentation\Shape\Drawing;
22
use PhpOffice\PhpPresentation\PhpPresentation;
23
use PhpOffice\PhpPresentation\Shape\MemoryDrawing;
24
use PhpOffice\PhpPresentation\Style\Alignment;
25
use PhpOffice\PhpPresentation\Style\Color;
26
use PhpOffice\PhpPresentation\Shape\RichText;
27
use PhpOffice\PhpPresentation\AbstractShape;
28
use PhpOffice\PhpPresentation\Style\Bullet;
29
use PhpOffice\PhpPresentation\Shape\Hyperlink;
30
use PhpOffice\PhpPresentation\Shape\Line;
31
use PhpOffice\Common\Text;
32
use PhpOffice\PhpPresentation\Shape\Group;
33
use PhpOffice\PhpPresentation\Shape\PhpOffice\PhpPresentation\Shape;
34
35
/**
36
 * Serialized format reader
37
 */
38
class PowerPoint97 implements ReaderInterface
39
{
40
    const OFFICEARTBLIPEMF = 0xF01A;
41
    const OFFICEARTBLIPWMF = 0xF01B;
42
    const OFFICEARTBLIPPICT = 0xF01C;
43
    const OFFICEARTBLIPJPG = 0xF01D;
44
    const OFFICEARTBLIPPNG = 0xF01E;
45
    const OFFICEARTBLIPDIB = 0xF01F;
46
    const OFFICEARTBLIPTIFF = 0xF029;
47
    const OFFICEARTBLIPJPEG = 0xF02A;
48
49
    /**
50
     * @link http://msdn.microsoft.com/en-us/library/dd945336(v=office.12).aspx
51
     */
52
    const RT_ANIMATIONINFO = 0x1014;
53
    const RT_ANIMATIONINFOATOM = 0x0FF1;
54
    const RT_BINARYTAGDATABLOB = 0x138B;
55
    const RT_BLIPCOLLECTION9 = 0x07F8;
56
    const RT_BLIPENTITY9ATOM = 0x07F9;
57
    const RT_BOOKMARKCOLLECTION = 0x07E3;
58
    const RT_BOOKMARKENTITYATOM = 0x0FD0;
59
    const RT_BOOKMARKSEEDATOM = 0x07E9;
60
    const RT_BROADCASTDOCINFO9 = 0x177E;
61
    const RT_BROADCASTDOCINFO9ATOM = 0x177F;
62
    const RT_BUILDATOM = 0x2B03;
63
    const RT_BUILDLIST = 0x2B02;
64
    const RT_CHARTBUILD = 0x2B04;
65
    const RT_CHARTBUILDATOM = 0x2B05;
66
    const RT_COLORSCHEMEATOM = 0x07F0;
67
    const RT_COMMENT10 = 0x2EE0;
68
    const RT_COMMENT10ATOM = 0x2EE1;
69
    const RT_COMMENTINDEX10 = 0x2EE4;
70
    const RT_COMMENTINDEX10ATOM = 0x2EE5;
71
    const RT_CRYPTSESSION10CONTAINER = 0x2F14;
72
    const RT_CURRENTUSERATOM = 0x0FF6;
73
    const RT_CSTRING = 0x0FBA;
74
    const RT_DATETIMEMETACHARATOM = 0x0FF7;
75
    const RT_DEFAULTRULERATOM = 0x0FAB;
76
    const RT_DOCROUTINGSLIPATOM = 0x0406;
77
    const RT_DIAGRAMBUILD = 0x2B06;
78
    const RT_DIAGRAMBUILDATOM = 0x2B07;
79
    const RT_DIFF10 = 0x2EED;
80
    const RT_DIFF10ATOM = 0x2EEE;
81
    const RT_DIFFTREE10 = 0x2EEC;
82
    const RT_DOCTOOLBARSTATES10ATOM = 0x36B1;
83
    const RT_DOCUMENT = 0x03E8;
84
    const RT_DOCUMENTATOM = 0x03E9;
85
    const RT_DRAWING = 0x040C;
86
    const RT_DRAWINGGROUP = 0x040B;
87
    const RT_ENDDOCUMENTATOM = 0x03EA;
88
    const RT_EXTERNALAVIMOVIE = 0x1006;
89
    const RT_EXTERNALCDAUDIO = 0x100E;
90
    const RT_EXTERNALCDAUDIOATOM = 0x1012;
91
    const RT_EXTERNALHYPERLINK = 0x0FD7;
92
    const RT_EXTERNALHYPERLINK9 = 0x0FE4;
93
    const RT_EXTERNALHYPERLINKATOM = 0x0FD3;
94
    const RT_EXTERNALHYPERLINKFLAGSATOM = 0x1018;
95
    const RT_EXTERNALMCIMOVIE = 0x1007;
96
    const RT_EXTERNALMEDIAATOM = 0x1004;
97
    const RT_EXTERNALMIDIAUDIO = 0x100D;
98
    const RT_EXTERNALOBJECTLIST = 0x0409;
99
    const RT_EXTERNALOBJECTLISTATOM = 0x040A;
100
    const RT_EXTERNALOBJECTREFATOM = 0x0BC1;
101
    const RT_EXTERNALOLECONTROL = 0x0FEE;
102
    const RT_EXTERNALOLECONTROLATOM = 0x0FFB;
103
    const RT_EXTERNALOLEEMBED = 0x0FCC;
104
    const RT_EXTERNALOLEEMBEDATOM = 0x0FCD;
105
    const RT_EXTERNALOLELINK = 0x0FCE;
106
    const RT_EXTERNALOLELINKATOM = 0x0FD1;
107
    const RT_EXTERNALOLEOBJECTATOM = 0x0FC3;
108
    const RT_EXTERNALOLEOBJECTSTG = 0x1011;
109
    const RT_EXTERNALVIDEO = 0x1005;
110
    const RT_EXTERNALWAVAUDIOEMBEDDED = 0x100F;
111
    const RT_EXTERNALWAVAUDIOEMBEDDEDATOM = 0x1013;
112
    const RT_EXTERNALWAVAUDIOLINK = 0x1010;
113
    const RT_ENVELOPEDATA9ATOM = 0x1785;
114
    const RT_ENVELOPEFLAGS9ATOM = 0x1784;
115
    const RT_ENVIRONMENT = 0x03F2;
116
    const RT_FONTCOLLECTION = 0x07D5;
117
    const RT_FONTCOLLECTION10 = 0x07D6;
118
    const RT_FONTEMBEDDATABLOB = 0x0FB8;
119
    const RT_FONTEMBEDFLAGS10ATOM = 0x32C8;
120
    const RT_FILTERPRIVACYFLAGS10ATOM = 0x36B0;
121
    const RT_FONTENTITYATOM = 0x0FB7;
122
    const RT_FOOTERMETACHARATOM = 0x0FFA;
123
    const RT_GENERICDATEMETACHARATOM = 0x0FF8;
124
    const RT_GRIDSPACING10ATOM = 0x040D;
125
    const RT_GUIDEATOM = 0x03FB;
126
    const RT_HANDOUT = 0x0FC9;
127
    const RT_HASHCODEATOM = 0x2B00;
128
    const RT_HEADERSFOOTERS = 0x0FD9;
129
    const RT_HEADERSFOOTERSATOM = 0x0FDA;
130
    const RT_HEADERMETACHARATOM = 0x0FF9;
131
    const RT_HTMLDOCINFO9ATOM = 0x177B;
132
    const RT_HTMLPUBLISHINFOATOM = 0x177C;
133
    const RT_HTMLPUBLISHINFO9 = 0x177D;
134
    const RT_INTERACTIVEINFO = 0x0FF2;
135
    const RT_INTERACTIVEINFOATOM = 0x0FF3;
136
    const RT_KINSOKU = 0x0FC8;
137
    const RT_KINSOKUATOM = 0x0FD2;
138
    const RT_LEVELINFOATOM = 0x2B0A;
139
    const RT_LINKEDSHAPE10ATOM = 0x2EE6;
140
    const RT_LINKEDSLIDE10ATOM = 0x2EE7;
141
    const RT_LIST = 0x07D0;
142
    const RT_MAINMASTER = 0x03F8;
143
    const RT_MASTERTEXTPROPATOM = 0x0FA2;
144
    const RT_METAFILE = 0x0FC1;
145
    const RT_NAMEDSHOW = 0x0411;
146
    const RT_NAMEDSHOWS = 0x0410;
147
    const RT_NAMEDSHOWSLIDESATOM = 0x0412;
148
    const RT_NORMALVIEWSETINFO9 = 0x0414;
149
    const RT_NORMALVIEWSETINFO9ATOM = 0x0415;
150
    const RT_NOTES= 0x03F0;
151
    const RT_NOTESATOM = 0x03F1;
152
    const RT_NOTESTEXTVIEWINFO9 = 0x0413;
153
    const RT_OUTLINETEXTPROPS9 = 0x0FAE;
154
    const RT_OUTLINETEXTPROPS10 = 0x0FB3;
155
    const RT_OUTLINETEXTPROPS11 = 0x0FB5;
156
    const RT_OUTLINETEXTPROPSHEADER9ATOM = 0x0FAF;
157
    const RT_OUTLINETEXTREFATOM = 0x0F9E;
158
    const RT_OUTLINEVIEWINFO = 0x0407;
159
    const RT_PERSISTDIRECTORYATOM = 0x1772;
160
    const RT_PARABUILD = 0x2B08;
161
    const RT_PARABUILDATOM = 0x2B09;
162
    const RT_PHOTOALBUMINFO10ATOM = 0x36B2;
163
    const RT_PLACEHOLDERATOM = 0x0BC3;
164
    const RT_PRESENTATIONADVISORFLAGS9ATOM = 0x177A;
165
    const RT_PRINTOPTIONSATOM = 0x1770;
166
    const RT_PROGBINARYTAG = 0x138A;
167
    const RT_PROGSTRINGTAG = 0x1389;
168
    const RT_PROGTAGS = 0x1388;
169
    const RT_RECOLORINFOATOM = 0x0FE7;
170
    const RT_RTFDATETIMEMETACHARATOM = 0x1015;
171
    const RT_ROUNDTRIPANIMATIONATOM12ATOM = 0x2B0B;
172
    const RT_ROUNDTRIPANIMATIONHASHATOM12ATOM = 0x2B0D;
173
    const RT_ROUNDTRIPCOLORMAPPING12ATOM = 0x040F;
174
    const RT_ROUNDTRIPCOMPOSITEMASTERID12ATOM = 0x041D;
175
    const RT_ROUNDTRIPCONTENTMASTERID12ATOM = 0x0422;
176
    const RT_ROUNDTRIPCONTENTMASTERINFO12ATOM = 0x041E;
177
    const RT_ROUNDTRIPCUSTOMTABLESTYLES12ATOM = 0x0428;
178
    const RT_ROUNDTRIPDOCFLAGS12ATOM = 0x0425;
179
    const RT_ROUNDTRIPHEADERFOOTERDEFAULTS12ATOM = 0x0424;
180
    const RT_ROUNDTRIPHFPLACEHOLDER12ATOM = 0x0420;
181
    const RT_ROUNDTRIPNEWPLACEHOLDERID12ATOM = 0x0BDD;
182
    const RT_ROUNDTRIPNOTESMASTERTEXTSTYLES12ATOM = 0x0427;
183
    const RT_ROUNDTRIPOARTTEXTSTYLES12ATOM = 0x0423;
184
    const RT_ROUNDTRIPORIGINALMAINMASTERID12ATOM = 0x041C;
185
    const RT_ROUNDTRIPSHAPECHECKSUMFORCL12ATOM = 0x0426;
186
    const RT_ROUNDTRIPSHAPEID12ATOM = 0x041F;
187
    const RT_ROUNDTRIPSLIDESYNCINFO12 = 0x3714;
188
    const RT_ROUNDTRIPSLIDESYNCINFOATOM12 = 0x3715;
189
    const RT_ROUNDTRIPTHEME12ATOM = 0x040E;
190
    const RT_SHAPEATOM = 0x0BDB;
191
    const RT_SHAPEFLAGS10ATOM = 0x0BDC;
192
    const RT_SLIDE = 0x03EE;
193
    const RT_SLIDEATOM = 0x03EF;
194
    const RT_SLIDEFLAGS10ATOM = 0x2EEA;
195
    const RT_SLIDELISTENTRY10ATOM = 0x2EF0;
196
    const RT_SLIDELISTTABLE10 = 0x2EF1;
197
    const RT_SLIDELISTWITHTEXT = 0x0FF0;
198
    const RT_SLIDELISTTABLESIZE10ATOM = 0x2EEF;
199
    const RT_SLIDENUMBERMETACHARATOM = 0x0FD8;
200
    const RT_SLIDEPERSISTATOM = 0x03F3;
201
    const RT_SLIDESHOWDOCINFOATOM = 0x0401;
202
    const RT_SLIDESHOWSLIDEINFOATOM = 0x03F9;
203
    const RT_SLIDETIME10ATOM = 0x2EEB;
204
    const RT_SLIDEVIEWINFO = 0x03FA;
205
    const RT_SLIDEVIEWINFOATOM = 0x03FE;
206
    const RT_SMARTTAGSTORE11CONTAINER = 0x36B3;
207
    const RT_SOUND = 0x07E6;
208
    const RT_SOUNDCOLLECTION = 0x07E4;
209
    const RT_SOUNDCOLLECTIONATOM = 0x07E5;
210
    const RT_SOUNDDATABLOB = 0x07E7;
211
    const RT_SORTERVIEWINFO = 0x0408;
212
    const RT_STYLETEXTPROPATOM = 0x0FA1;
213
    const RT_STYLETEXTPROP10ATOM = 0x0FB1;
214
    const RT_STYLETEXTPROP11ATOM = 0x0FB6;
215
    const RT_STYLETEXTPROP9ATOM = 0x0FAC;
216
    const RT_SUMMARY = 0x0402;
217
    const RT_TEXTBOOKMARKATOM = 0x0FA7;
218
    const RT_TEXTBYTESATOM = 0x0FA8;
219
    const RT_TEXTCHARFORMATEXCEPTIONATOM = 0x0FA4;
220
    const RT_TEXTCHARSATOM = 0x0FA0;
221
    const RT_TEXTDEFAULTS10ATOM = 0x0FB4;
222
    const RT_TEXTDEFAULTS9ATOM = 0x0FB0;
223
    const RT_TEXTHEADERATOM = 0x0F9F;
224
    const RT_TEXTINTERACTIVEINFOATOM = 0x0FDF;
225
    const RT_TEXTMASTERSTYLEATOM = 0x0FA3;
226
    const RT_TEXTMASTERSTYLE10ATOM = 0x0FB2;
227
    const RT_TEXTMASTERSTYLE9ATOM = 0x0FAD;
228
    const RT_TEXTPARAGRAPHFORMATEXCEPTIONATOM = 0x0FA5;
229
    const RT_TEXTRULERATOM = 0x0FA6;
230
    const RT_TEXTSPECIALINFOATOM = 0x0FAA;
231
    const RT_TEXTSPECIALINFODEFAULTATOM = 0x0FA9;
232
    const RT_TIMEANIMATEBEHAVIOR = 0xF134;
233
    const RT_TIMEANIMATEBEHAVIORCONTAINER = 0xF12B;
234
    const RT_TIMEANIMATIONVALUE = 0xF143;
235
    const RT_TIMEANIMATIONVALUELIST = 0xF13F;
236
    const RT_TIMEBEHAVIOR = 0xF133;
237
    const RT_TIMEBEHAVIORCONTAINER = 0xF12A;
238
    const RT_TIMECOLORBEHAVIOR = 0xF135;
239
    const RT_TIMECOLORBEHAVIORCONTAINER = 0xF12C;
240
    const RT_TIMECLIENTVISUALELEMENT = 0xF13C;
241
    const RT_TIMECOMMANDBEHAVIOR = 0xF13B;
242
    const RT_TIMECOMMANDBEHAVIORCONTAINER = 0xF132;
243
    const RT_TIMECONDITION = 0xF128;
244
    const RT_TIMECONDITIONCONTAINER = 0xF125;
245
    const RT_TIMEEFFECTBEHAVIOR = 0xF136;
246
    const RT_TIMEEFFECTBEHAVIORCONTAINER = 0xF12D;
247
    const RT_TIMEEXTTIMENODECONTAINER = 0xF144;
248
    const RT_TIMEITERATEDATA = 0xF140;
249
    const RT_TIMEMODIFIER = 0xF129;
250
    const RT_TIMEMOTIONBEHAVIOR = 0xF137;
251
    const RT_TIMEMOTIONBEHAVIORCONTAINER = 0xF12E;
252
    const RT_TIMENODE = 0xF127;
253
    const RT_TIMEPROPERTYLIST = 0xF13D;
254
    const RT_TIMEROTATIONBEHAVIOR = 0xF138;
255
    const RT_TIMEROTATIONBEHAVIORCONTAINER = 0xF12F;
256
    const RT_TIMESCALEBEHAVIOR = 0xF139;
257
    const RT_TIMESCALEBEHAVIORCONTAINER = 0xF130;
258
    const RT_TIMESEQUENCEDATA = 0xF141;
259
    const RT_TIMESETBEHAVIOR = 0xF13A;
260
    const RT_TIMESETBEHAVIORCONTAINER = 0xF131;
261
    const RT_TIMESUBEFFECTCONTAINER = 0xF145;
262
    const RT_TIMEVARIANT = 0xF142;
263
    const RT_TIMEVARIANTLIST = 0xF13E;
264
    const RT_USEREDITATOM = 0x0FF5;
265
    const RT_VBAINFO = 0x03FF;
266
    const RT_VBAINFOATOM = 0x0400;
267
    const RT_VIEWINFOATOM = 0x03FD;
268
    const RT_VISUALPAGEATOM = 0x2B01;
269
    const RT_VISUALSHAPEATOM = 0x2AFB;
270
271
    /**
272
     * @var http://msdn.microsoft.com/en-us/library/dd926394(v=office.12).aspx
273
     */
274
    const SL_BIGOBJECT = 0x0000000F;
275
    const SL_BLANK = 0x00000010;
276
    const SL_COLUMNTWOROWS = 0x0000000A;
277
    const SL_FOUROBJECTS = 0x0000000E;
278
    const SL_MASTERTITLE = 0x00000002;
279
    const SL_TITLEBODY = 0x00000001;
280
    const SL_TITLEONLY = 0x00000007;
281
    const SL_TITLESLIDE = 0x00000000;
282
    const SL_TWOCOLUMNS = 0x00000008;
283
    const SL_TWOCOLUMNSROW = 0x0000000D;
284
    const SL_TWOROWS = 0x00000009;
285
    const SL_TWOROWSCOLUMN = 0x0000000B;
286
    const SL_VERTICALTITLEBODY = 0x00000011;
287
    const SL_VERTICALTWOROWS = 0x00000012;
288
289
    /**
290
     * Array with Fonts
291
     */
292
    private $arrayFonts = array();
293
    /**
294
     * Array with Hyperlinks
295
     */
296
    private $arrayHyperlinks = array();
297
    /**
298
     * Array with Pictures
299
     */
300
    private $arrayPictures = array();
301
    /**
302
     * Offset (in bytes) from the beginning of the PowerPoint Document Stream to the UserEditAtom record for the most recent user edit.
303
     * @var int
304
     */
305
    private $offsetToCurrentEdit;
306
    /**
307
     * A structure that specifies a compressed table of sequential persist object identifiers and stream offsets to associated persist objects.
308
     * @var int[]
309
     */
310
    private $rgPersistDirEntry;
311
    /**
312
     * Offset (in bytes) from the beginning of the PowerPoint Document Stream to the PersistDirectoryAtom record for this user edit
313
     * @var int
314
     */
315
    private $offsetPersistDirectory;
316
    /**
317
     * Output Object
318
     * @var PhpPresentation
319
     */
320
    private $oPhpPresentation;
321
    /**
322
     * Group Object
323
     * @var Group
324
     */
325
    private $oCurrentGroup;
326
    /**
327
     * @var boolean
328
     */
329
    private $bFirstShapeGroup = false;
330
    /**
331
     * Stream "Powerpoint Document"
332
     * @var string
333
     */
334
    private $streamPowerpointDocument;
335
    /**
336
     * Stream "Current User"
337
     * @var string
338
     */
339
    private $streamCurrentUser;
340
    /**
341
     * Stream "Summary Information"
342
     * @var string
343
     */
344
    private $streamSummaryInformation;
345
    /**
346
     * Stream "Document Summary Information"
347
     * @var string
348
     */
349
    private $streamDocumentSummaryInformation;
350
    /**
351
     * Stream "Pictures"
352
     * @var string
353
     */
354
    private $streamPictures;
355
356
    /**
357
     * Can the current \PhpOffice\PhpPresentation\Reader\ReaderInterface read the file?
358
     *
359
     * @param  string $pFilename
360
     * @throws \Exception
361
     * @return boolean
362
     */
363 3
    public function canRead($pFilename)
364
    {
365 3
        return $this->fileSupportsUnserializePhpPresentation($pFilename);
366
    }
367
368
    /**
369
     * Does a file support UnserializePhpPresentation ?
370
     *
371
     * @param  string    $pFilename
372
     * @throws \Exception
373
     * @return boolean
374
     */
375 10
    public function fileSupportsUnserializePhpPresentation($pFilename = '')
376
    {
377
        // Check if file exists
378 10
        if (!file_exists($pFilename)) {
379 2
            throw new \Exception("Could not open " . $pFilename . " for reading! File does not exist.");
380
        }
381
382
        try {
383
            // Use ParseXL for the hard work.
384 8
            $ole = new OLERead();
385
            // get excel data
386 8
            $ole->read($pFilename);
387 5
            return true;
388 3
        } catch (\Exception $e) {
389 3
            return false;
390
        }
391
    }
392
393
    /**
394
     * Loads PhpPresentation Serialized file
395
     *
396
     * @param  string        $pFilename
397
     * @return \PhpOffice\PhpPresentation\PhpPresentation
398
     * @throws \Exception
399
     */
400 6
    public function load($pFilename)
401
    {
402
        // Unserialize... First make sure the file supports it!
403 6
        if (!$this->fileSupportsUnserializePhpPresentation($pFilename)) {
404 1
            throw new \Exception("Invalid file format for PhpOffice\PhpPresentation\Reader\PowerPoint97: " . $pFilename . ".");
405
        }
406
407 4
        return $this->loadFile($pFilename);
408
    }
409
410
    /**
411
     * Load PhpPresentation Serialized file
412
     *
413
     * @param  string        $pFilename
414
     * @return \PhpOffice\PhpPresentation\PhpPresentation
415
     */
416 4
    private function loadFile($pFilename)
417
    {
418 4
        $this->oPhpPresentation = new PhpPresentation();
419 4
        $this->oPhpPresentation->removeSlideByIndex();
420
421
        // Read OLE Blocks
422 4
        $this->loadOLE($pFilename);
423
        // Read pictures in the Pictures Stream
424 4
        $this->loadPicturesStream();
425
        // Read information in the Current User Stream
426 4
        $this->loadCurrentUserStream();
427
        // Read information in the PowerPoint Document Stream
428 4
        $this->loadPowerpointDocumentStream();
429
430 4
        return $this->oPhpPresentation;
431
    }
432
433
    /**
434
     * Read OLE Part
435
     * @param string $pFilename
436
     */
437 4
    private function loadOLE($pFilename)
438
    {
439
        // OLE reader
440 4
        $oOLE = new OLERead();
441 4
        $oOLE->read($pFilename);
442
443
        // PowerPoint Document Stream
444 4
        $this->streamPowerpointDocument = $oOLE->getStream($oOLE->powerpointDocument);
445
446
        // Current User Stream
447 4
        $this->streamCurrentUser = $oOLE->getStream($oOLE->currentUser);
448
449
        // Get summary information data
450 4
        $this->streamSummaryInformation = $oOLE->getStream($oOLE->summaryInformation);
451
452
        // Get additional document summary information data
453 4
        $this->streamDocumentSummaryInformation = $oOLE->getStream($oOLE->docSummaryInfos);
454
455
        // Get pictures data
456 4
        $this->streamPictures = $oOLE->getStream($oOLE->pictures);
457 4
    }
458
459
    /**
460
     * Stream Pictures
461
     * @link http://msdn.microsoft.com/en-us/library/dd920746(v=office.12).aspx
462
     */
463 4
    private function loadPicturesStream()
464
    {
465 4
        $stream = $this->streamPictures;
466
467 4
        $pos = 0;
468
        do {
469 4
            $arrayRH = $this->loadRecordHeader($stream, $pos);
470 4
            $pos += 8;
471 4
            $readSuccess = false;
472 4
            if ($arrayRH['recVer'] == 0x00 && ($arrayRH['recType'] == 0xF007 || ($arrayRH['recType'] >= 0xF018 && $arrayRH['recType'] <= 0xF117))) {
473
                //@link : http://msdn.microsoft.com/en-us/library/dd950560(v=office.12).aspx
474 4
                if ($arrayRH['recType'] == 0xF007) {
475
                    // OfficeArtFBSE
476
                    throw new \Exception('Feature not implemented (l.'.__LINE__.')');
477
                }
478 4
                if ($arrayRH['recType'] >= 0xF018 && $arrayRH['recType'] <= 0xF117) {
479 4
                    $arrayRecord = $this->readRecordOfficeArtBlip($stream, $pos - 8);
480 4
                    if ($arrayRecord['length'] > 0) {
481 4
                        $pos += $arrayRecord['length'];
482 4
                        $this->arrayPictures[] = $arrayRecord['picture'];
483 4
                    }
484 4
                }
485 4
                $readSuccess = true;
486 4
            }
487 4
        } while ($readSuccess === true);
488 4
    }
489
490
    /**
491
     * Stream Current User
492
     * @link http://msdn.microsoft.com/en-us/library/dd908567(v=office.12).aspx
493
     */
494 4
    private function loadCurrentUserStream()
495
    {
496 4
        $pos = 0;
497
498
        /**
499
         * CurrentUserAtom : http://msdn.microsoft.com/en-us/library/dd948895(v=office.12).aspx
500
         */
501
        // RecordHeader : http://msdn.microsoft.com/en-us/library/dd926377(v=office.12).aspx
502 4
        $rHeader = $this->loadRecordHeader($this->streamCurrentUser, $pos);
503 4
        $pos += 8;
504 4
        if ($rHeader['recVer'] != 0x0 || $rHeader['recInstance'] != 0x000 || $rHeader['recType'] != self::RT_CURRENTUSERATOM) {
505
            throw new \Exception('File PowerPoint 97 in error (Location : CurrentUserAtom > RecordHeader).');
506
        }
507
508
        // Size
509 4
        $size = self::getInt4d($this->streamCurrentUser, $pos);
510 4
        $pos += 4;
511 4
        if ($size !=  0x00000014) {
512
            throw new \Exception('File PowerPoint 97 in error (Location : CurrentUserAtom > Size).');
513
        }
514
515
        // headerToken
516 4
        $headerToken = self::getInt4d($this->streamCurrentUser, $pos);
517 4
        $pos += 4;
518 4
        if ($headerToken == 0xF3D1C4DF && $headerToken != 0xE391C05F) {
519
            throw new \Exception('Feature not implemented (l.'.__LINE__.') : Encrypted file');
520
        }
521
522
        // offsetToCurrentEdit
523 4
        $this->offsetToCurrentEdit = self::getInt4d($this->streamCurrentUser, $pos);
524 4
        $pos += 4;
525
526
        // lenUserName
527 4
        $lenUserName = self::getInt2d($this->streamCurrentUser, $pos);
528 4
        $pos += 2;
529 4
        if ($lenUserName > 255) {
530
            throw new \Exception('File PowerPoint 97 in error (Location : CurrentUserAtom > lenUserName).');
531
        }
532
533
        // docFileVersion
534 4
        $docFileVersion = self::getInt2d($this->streamCurrentUser, $pos);
535 4
        $pos += 2;
536 4
        if ($docFileVersion != 0x03F4) {
537
            throw new \Exception('File PowerPoint 97 in error (Location : CurrentUserAtom > docFileVersion).');
538
        }
539
540
        // majorVersion
541 4
        $majorVersion = self::getInt1d($this->streamCurrentUser, $pos);
542 4
        $pos += 1;
543 4
        if ($majorVersion != 0x03) {
544
            throw new \Exception('File PowerPoint 97 in error (Location : CurrentUserAtom > majorVersion).');
545
        }
546
547
        // minorVersion
548 4
        $minorVersion = self::getInt1d($this->streamCurrentUser, $pos);
549 4
        $pos += 1;
550 4
        if ($minorVersion != 0x00) {
551
            throw new \Exception('File PowerPoint 97 in error (Location : CurrentUserAtom > minorVersion).');
552
        }
553
554
        // unused
555 4
        $pos += 2;
556
557
        // ansiUserName
558 4
        $ansiUserName = '';
559
        do {
560 4
            $char = self::getInt1d($this->streamCurrentUser, $pos);
561 4
            if (($char >= 0x00 && $char <= 0x1F) || ($char >= 0x7F && $char <= 0x9F)) {
562 4
                $char = false;
563 4
            } else {
564 4
                $ansiUserName .= chr($char);
565 4
                $pos += 1;
566
            }
567 4
        } while ($char !== false);
568
569
        // relVersion
570 4
        $relVersion = self::getInt4d($this->streamCurrentUser, $pos);
571 4
        $pos += 4;
572 4
        if ($relVersion != 0x00000008 && $relVersion != 0x00000009) {
573
            throw new \Exception('File PowerPoint 97 in error (Location : CurrentUserAtom > relVersion).');
574
        }
575
576
        // unicodeUserName
577 4
        $unicodeUserName = '';
578 4
        for ($inc = 0; $inc < $lenUserName; $inc++) {
579 4
            $char = self::getInt2d($this->streamCurrentUser, $pos);
580 4
            if (($char >= 0x00 && $char <= 0x1F) || ($char >= 0x7F && $char <= 0x9F)) {
581 4
                break;
582
            }
583
            $unicodeUserName .= chr($char);
584
            $pos += 2;
585
        }
586 4
    }
587
588
    /**
589
     * Stream Powerpoint Document
590
     * @link http://msdn.microsoft.com/en-us/library/dd921564(v=office.12).aspx
591
     */
592 4
    private function loadPowerpointDocumentStream()
593
    {
594 4
        $this->readRecordUserEditAtom($this->streamPowerpointDocument, $this->offsetToCurrentEdit);
595
596 4
        $this->readRecordPersistDirectoryAtom($this->streamPowerpointDocument, $this->offsetPersistDirectory);
597
598 4
        foreach ($this->rgPersistDirEntry as $offsetDir) {
599 4
            $pos = $offsetDir;
600
601 4
            $rh = $this->loadRecordHeader($this->streamPowerpointDocument, $pos);
602 4
            $pos += 8;
603 4
            switch ($rh['recType']) {
604 4
                case self::RT_DOCUMENT:
605 4
                    $this->readRecordDocumentContainer($this->streamPowerpointDocument, $pos);
606 4
                    break;
607 4
                case self::RT_SLIDE:
608 4
                    $this->readRecordSlideContainer($this->streamPowerpointDocument, $pos);
609 4
                    break;
610 4
                default:
611
                    // throw new \Exception('Feature not implemented : l.'.__LINE__.'('.dechex($rh['recType']).')');
612 4
                    break;
613 4
            }
614 4
        }
615 4
    }
616
617
    /**
618
     * Read a record header
619
     * @param string $stream
620
     * @param integer $pos
621
     * @return multitype
622
     */
623 4
    private function loadRecordHeader($stream, $pos)
624
    {
625 4
        $rec = self::getInt2d($stream, $pos);
626 4
        $recType = self::getInt2d($stream, $pos + 2);
627 4
        $recLen = self::getInt4d($stream, $pos + 4);
628
//         var_export(array(
629
//             'recVer' => ($rec >> 0) & bindec('1111'),
630
//             'recInstance' => ($rec >> 4) & bindec('111111111111'),
631
//             'recType' => $recType,
632
//             'recLen' => $recLen,
633
//         ));
634
//         echo EOL;
635
        return array(
636 4
            'recVer' => ($rec >> 0) & bindec('1111'),
637 4
            'recInstance' => ($rec >> 4) & bindec('111111111111'),
638 4
            'recType' => $recType,
639 4
            'recLen' => $recLen,
640 4
        );
641
    }
642
643
    /**
644
     * Read 8-bit unsigned integer
645
     *
646
     * @param string $data
647
     * @param int $pos
648
     * @return int
649
     */
650 4
    public static function getInt1d($data, $pos)
651
    {
652 4
        return ord($data[$pos]);
653
    }
654
655
    /**
656
     * Read 16-bit unsigned integer
657
     *
658
     * @param string $data
659
     * @param int $pos
660
     * @return int
661
     */
662 4
    public static function getInt2d($data, $pos)
663
    {
664 4
        return ord($data[$pos]) | (ord($data[$pos+1]) << 8);
665
    }
666
667
    /**
668
     * Read 32-bit signed integer
669
     *
670
     * @param string $data
671
     * @param int $pos
672
     * @return int
673
     */
674 4
    public static function getInt4d($data, $pos)
675
    {
676
        // FIX: represent numbers correctly on 64-bit system
677
        // http://sourceforge.net/tracker/index.php?func=detail&aid=1487372&group_id=99160&atid=623334
678
        // Hacked by Andreas Rehm 2006 to ensure correct result of the <<24 block on 32 and 64bit systems
679 4
        $or24 = ord($data[$pos + 3]);
680
681 4
        $ord24 = ($or24 & 127) << 24;
682 4
        if ($or24 >= 128) {
683
            // negative number
684 4
            $ord24 = -abs((256 - $or24) << 24);
685 4
        }
686 4
        return ord($data[$pos]) | (ord($data[$pos+1]) << 8) | (ord($data[$pos+2]) << 16) | $ord24;
687
    }
688
689
    /**
690
     * A container record that specifies the animation and sound information for a shape.
691
     * @param string $stream
692
     * @param integer $pos
693
     * @link https://msdn.microsoft.com/en-us/library/dd772900(v=office.12).aspx
694
     */
695
    private function readRecordAnimationInfoContainer($stream, $pos)
696
    {
697
        $arrayReturn = array(
698
            'length' => 0,
699
        );
700
701
        $data = $this->loadRecordHeader($stream, $pos);
702
        if ($data['recVer'] == 0xF && $data['recInstance'] == 0x000 && $data['recType'] == self::RT_ANIMATIONINFO) {
703
            // Record Header
704
            $arrayReturn['length'] += 8;
705
            // animationAtom
706
            // animationSound
707
            throw new \Exception('Feature not implemented (l.'.__LINE__.')');
708
        }
709
710
        return $arrayReturn;
711
    }
712
713
    /**
714
     * A container record that specifies information about the document.
715
     * @param string $stream
716
     * @param integer $pos
717
     * @link http://msdn.microsoft.com/en-us/library/dd947357(v=office.12).aspx
718
     */
719 4
    private function readRecordDocumentContainer($stream, $pos)
720
    {
721 4
        $documentAtom = $this->loadRecordHeader($stream, $pos);
722 4
        $pos += 8;
723 4
        if ($documentAtom['recVer'] != 0x1 || $documentAtom['recInstance'] != 0x000 || $documentAtom['recType'] != self::RT_DOCUMENTATOM) {
724
            throw new \Exception('File PowerPoint 97 in error (Location : RTDocument > DocumentAtom).');
725
        }
726 4
        $pos += $documentAtom['recLen'];
727
728 4
        $exObjList = $this->loadRecordHeader($stream, $pos);
729 4
        if ($exObjList['recVer'] == 0xF && $exObjList['recInstance'] == 0x000 && $exObjList['recType'] == self::RT_EXTERNALOBJECTLIST) {
730 1
            $pos += 8;
731
            // exObjListAtom > rh
732 1
            $exObjListAtom = $this->loadRecordHeader($stream, $pos);
733 1
            if ($exObjListAtom['recVer'] != 0x0 || $exObjListAtom['recInstance'] != 0x000 || $exObjListAtom['recType'] != self::RT_EXTERNALOBJECTLISTATOM || $exObjListAtom['recLen'] != 0x00000004) {
734
                throw new \Exception('File PowerPoint 97 in error (Location : RTDocument > DocumentAtom > exObjList > exObjListAtom).');
735
            }
736 1
            $pos += 8;
737
            // exObjListAtom > exObjIdSeed
738 1
            $pos += 4;
739
            // rgChildRec
740 1
            $exObjList['recLen'] -= 12;
741
            do {
742 1
                $childRec = $this->loadRecordHeader($stream, $pos);
743 1
                $pos += 8;
744 1
                $exObjList['recLen'] -= 8;
745 1
                switch ($childRec['recType']) {
746 1
                    case self::RT_EXTERNALHYPERLINK:
747
                        //@link : http://msdn.microsoft.com/en-us/library/dd944995(v=office.12).aspx
748
                        // exHyperlinkAtom > rh
749 1
                        $exHyperlinkAtom = $this->loadRecordHeader($stream, $pos);
750 1
                        if ($exHyperlinkAtom['recVer'] != 0x0 || $exHyperlinkAtom['recInstance'] != 0x000 || $exHyperlinkAtom['recType'] != self::RT_EXTERNALHYPERLINKATOM || $exObjListAtom['recLen'] != 0x00000004) {
751
                            throw new \Exception('File PowerPoint 97 in error (Location : RTDocument > DocumentAtom > exObjList > rgChildRec > RT_ExternalHyperlink).');
752
                        }
753 1
                        $pos += 8;
754 1
                        $exObjList['recLen'] -= 8;
755
                        // exHyperlinkAtom > exHyperlinkId
756 1
                        $exHyperlinkId = self::getInt4d($stream, $pos);
757 1
                        $pos += 4;
758 1
                        $exObjList['recLen'] -= 4;
759
760 1
                        $this->arrayHyperlinks[$exHyperlinkId] = array();
761
                        // friendlyNameAtom
762 1
                        $friendlyNameAtom  = $this->loadRecordHeader($stream, $pos);
763 1
                        if ($friendlyNameAtom['recVer'] == 0x0 && $friendlyNameAtom['recInstance'] == 0x000 && $friendlyNameAtom['recType'] == self::RT_CSTRING && $friendlyNameAtom['recLen'] % 2 == 0) {
764 1
                            $pos += 8;
765 1
                            $exObjList['recLen'] -= 8;
766 1
                            $this->arrayHyperlinks[$exHyperlinkId]['text'] = '';
767 1
                            for ($inc = 0; $inc < ($friendlyNameAtom['recLen'] / 2); $inc++) {
768 1
                                $char = self::getInt2d($stream, $pos);
769 1
                                $pos += 2;
770 1
                                $exObjList['recLen'] -= 2;
771 1
                                $this->arrayHyperlinks[$exHyperlinkId]['text'] .= chr($char);
772 1
                            }
773 1
                        }
774
                        // targetAtom
775 1
                        $targetAtom  = $this->loadRecordHeader($stream, $pos);
776 1
                        if ($targetAtom['recVer'] == 0x0 && $targetAtom['recInstance'] == 0x001 && $targetAtom['recType'] == self::RT_CSTRING && $targetAtom['recLen'] % 2 == 0) {
777 1
                            $pos += 8;
778 1
                            $exObjList['recLen'] -= 8;
779 1
                            $this->arrayHyperlinks[$exHyperlinkId]['url'] = '';
780 1
                            for ($inc = 0; $inc < ($targetAtom['recLen'] / 2); $inc++) {
781 1
                                $char = self::getInt2d($stream, $pos);
782 1
                                $pos += 2;
783 1
                                $exObjList['recLen'] -= 2;
784 1
                                $this->arrayHyperlinks[$exHyperlinkId]['url'] .= chr($char);
785 1
                            }
786 1
                        }
787
                        // locationAtom
788 1
                        $locationAtom  = $this->loadRecordHeader($stream, $pos);
789 1
                        if ($locationAtom['recVer'] == 0x0 && $locationAtom['recInstance'] == 0x003 && $locationAtom['recType'] == self::RT_CSTRING && $locationAtom['recLen'] % 2 == 0) {
790
                            $pos += 8;
791
                            $exObjList['recLen'] -= 8;
792
                            $string = '';
793
                            for ($inc = 0; $inc < ($locationAtom['recLen'] / 2); $inc++) {
794
                                $char = self::getInt2d($stream, $pos);
795
                                $pos += 2;
796
                                $exObjList['recLen'] -= 2;
797
                                $string .= chr($char);
798
                            }
799
                        }
800 1
                        break;
801
                    default:
802
                        throw new \Exception('Feature not implemented (l.'.__LINE__.' : '.dechex($childRec['recType'].')'));
803 1
                }
804 1
            } while ($exObjList['recLen'] > 0);
805 1
        }
806
807
        //@link : http://msdn.microsoft.com/en-us/library/dd907813(v=office.12).aspx
808 4
        $documentTextInfo = $this->loadRecordHeader($stream, $pos);
809 4
        if ($documentTextInfo['recVer'] == 0xF && $documentTextInfo['recInstance'] == 0x000 && $documentTextInfo['recType'] == self::RT_ENVIRONMENT) {
810 4
            $pos += 8;
811
            //@link : http://msdn.microsoft.com/en-us/library/dd952717(v=office.12).aspx
812 4
            $kinsoku = $this->loadRecordHeader($stream, $pos);
813 4
            if ($kinsoku['recVer'] == 0xF && $kinsoku['recInstance'] == 0x002 && $kinsoku['recType'] == self::RT_KINSOKU) {
814 4
                $pos += 8;
815 4
                $pos += $kinsoku['recLen'];
816 4
            }
817
818
            //@link : http://msdn.microsoft.com/en-us/library/dd948152(v=office.12).aspx
819 4
            $fontCollection = $this->loadRecordHeader($stream, $pos);
820 4
            if ($fontCollection['recVer'] == 0xF && $fontCollection['recInstance'] == 0x000 && $fontCollection['recType'] == self::RT_FONTCOLLECTION) {
821 4
                $pos += 8;
822
                do {
823 4
                    $fontEntityAtom = $this->loadRecordHeader($stream, $pos);
824 4
                    $pos += 8;
825 4
                    $fontCollection['recLen'] -= 8;
826 4
                    if ($fontEntityAtom['recVer'] != 0x0 || $fontEntityAtom['recInstance'] > 128 || $fontEntityAtom['recType'] != self::RT_FONTENTITYATOM) {
827
                        throw new \Exception('File PowerPoint 97 in error (Location : RTDocument > RT_Environment > RT_FontCollection > RT_FontEntityAtom).');
828
                    }
829 4
                    $string = '';
830 4
                    for ($inc = 0; $inc < 32; $inc++) {
831 4
                        $char = self::getInt2d($stream, $pos);
832 4
                        $pos += 2;
833 4
                        $fontCollection['recLen'] -= 2;
834 4
                        $string .= chr($char);
835 4
                    }
836 4
                    $this->arrayFonts[] = $string;
837
838
                    // lfCharSet (1 byte)
839 4
                    $pos += 1;
840 4
                    $fontCollection['recLen'] -= 1;
841
842
                    // fEmbedSubsetted (1 bit)
843
                    // unused (7 bits)
844 4
                    $pos += 1;
845 4
                    $fontCollection['recLen'] -= 1;
846
847
                    // rasterFontType (1 bit)
848
                    // deviceFontType (1 bit)
849
                    // truetypeFontType (1 bit)
850
                    // fNoFontSubstitution (1 bit)
851
                    // reserved (4 bits)
852 4
                    $pos += 1;
853 4
                    $fontCollection['recLen'] -= 1;
854
855
                    // lfPitchAndFamily (1 byte)
856 4
                    $pos += 1;
857 4
                    $fontCollection['recLen'] -= 1;
858
859 4
                    $fontEmbedData1 = $this->loadRecordHeader($stream, $pos);
860 4
                    if ($fontEmbedData1['recVer'] == 0x0 && $fontEmbedData1['recInstance'] >= 0x000 && $fontEmbedData1['recInstance'] <= 0x003 && $fontEmbedData1['recType'] == self::RT_FONTEMBEDDATABLOB) {
861
                        $pos += 8;
862
                        $fontCollection['recLen'] -= 8;
863
                        $pos += $fontEmbedData1['recLen'];
864
                        $fontCollection['recLen'] -= $fontEmbedData1['recLen'];
865
                    }
866
867 4
                    $fontEmbedData2 = $this->loadRecordHeader($stream, $pos);
868 4
                    if ($fontEmbedData2['recVer'] == 0x0 && $fontEmbedData2['recInstance'] >= 0x000 && $fontEmbedData2['recInstance'] <= 0x003 && $fontEmbedData2['recType'] == self::RT_FONTEMBEDDATABLOB) {
869
                        $pos += 8;
870
                        $fontCollection['recLen'] -= 8;
871
                        $pos += $fontEmbedData2['recLen'];
872
                        $fontCollection['recLen'] -= $fontEmbedData2['recLen'];
873
                    }
874
875 4
                    $fontEmbedData3 = $this->loadRecordHeader($stream, $pos);
876 4
                    if ($fontEmbedData3['recVer'] == 0x0 && $fontEmbedData3['recInstance'] >= 0x000 && $fontEmbedData3['recInstance'] <= 0x003 && $fontEmbedData3['recType'] == self::RT_FONTEMBEDDATABLOB) {
877
                        $pos += 8;
878
                        $fontCollection['recLen'] -= 8;
879
                        $pos += $fontEmbedData3['recLen'];
880
                        $fontCollection['recLen'] -= $fontEmbedData3['recLen'];
881
                    }
882
883 4
                    $fontEmbedData4 = $this->loadRecordHeader($stream, $pos);
884 4
                    if ($fontEmbedData4['recVer'] == 0x0 && $fontEmbedData4['recInstance'] >= 0x000 && $fontEmbedData4['recInstance'] <= 0x003 && $fontEmbedData4['recType'] == self::RT_FONTEMBEDDATABLOB) {
885
                        $pos += 8;
886
                        $fontCollection['recLen'] -= 8;
887
                        $pos += $fontEmbedData4['recLen'];
888
                        $fontCollection['recLen'] -= $fontEmbedData4['recLen'];
889
                    }
890
0 ignored issues
show
Coding Style introduced by
Blank line found at end of control structure
Loading history...
891 4
                } while ($fontCollection['recLen'] > 0);
892 4
            }
893 4
        }
894 4
    }
895
896
    /**
897
     * An atom record that specifies information about a slide.
898
     * @param string $stream
899
     * @param integer $pos
900
     * @link https://msdn.microsoft.com/en-us/library/dd923801(v=office.12).aspx
901
     */
902 4
    private function readRecordDrawingContainer($stream, $pos)
903
    {
904
        $arrayReturn = array(
905 4
            'length' => 0,
906 4
        );
907
908 4
        $data = $this->loadRecordHeader($stream, $pos);
909 4
        if ($data['recVer'] == 0xF && $data['recInstance'] == 0x000 && $data['recType'] == self::RT_DRAWING) {
910
            // Record Header
911 4
            $arrayReturn['length'] += 8;
912
913 4
            $officeArtDg = $this->readRecordOfficeArtDgContainer($stream, $pos + $arrayReturn['length']);
914 4
            $arrayReturn['length'] += $officeArtDg['length'];
915 4
        }
916
917 4
        return $arrayReturn;
918
    }
919
920
    /**
921
     * An atom record that specifies a reference to an external object.
922
     * @param string $stream
923
     * @param integer $pos
924
     * @link https://msdn.microsoft.com/en-us/library/dd910388(v=office.12).aspx
925
     */
926
    private function readRecordExObjRefAtom($stream, $pos)
927
    {
928
        $arrayReturn = array(
929
            'length' => 0,
930
        );
931
932
        $data = $this->loadRecordHeader($stream, $pos);
933
        if ($data['recVer'] == 0x0 && $data['recInstance'] == 0x000 && $data['recType'] == self::RT_EXTERNALOBJECTREFATOM && $data['recLen'] == 0x00000004) {
934
            // Record Header
935
            $arrayReturn['length'] += 8;
936
            // Datas
937
            $arrayReturn['length'] += $data['recLen'];
938
        }
939
940
        return $arrayReturn;
941
    }
942
943
    /**
944
     * An atom record that specifies a type of action to be performed.
945
     * @param string $stream
946
     * @param integer $pos
947
     * @link https://msdn.microsoft.com/en-us/library/dd953300(v=office.12).aspx
948
     */
949 1
    private function readRecordInteractiveInfoAtom($stream, $pos)
950
    {
951
        $arrayReturn = array(
952 1
            'length' => 0,
953 1
        );
954
955 1
        $data = $this->loadRecordHeader($stream, $pos);
956 1
        if ($data['recVer'] == 0x0 && $data['recInstance'] == 0x000 && $data['recType'] == self::RT_INTERACTIVEINFOATOM && $data['recLen'] == 0x00000010) {
957
            // Record Header
958 1
            $arrayReturn['length'] += 8;
959
            // soundIdRef
960 1
            $arrayReturn['length'] += 4;
961
            // exHyperlinkIdRef
962 1
            $arrayReturn['exHyperlinkIdRef'] = self::getInt4d($stream, $pos + $arrayReturn['length']);
963 1
            $arrayReturn['length'] += 4;
964
            // action
965 1
            $arrayReturn['length'] += 1;
966
            // oleVerb
967 1
            $arrayReturn['length'] += 1;
968
            // jump
969 1
            $arrayReturn['length'] += 1;
970
            // fAnimated (1 bit)
971
            // fStopSound (1 bit)
972
            // fCustomShowReturn (1 bit)
973
            // fVisited (1 bit)
974
            // reserved (4 bits)
975 1
            $arrayReturn['length'] += 1;
976
            // hyperlinkType
977 1
            $arrayReturn['length'] += 1;
978
            // unused
979 1
            $arrayReturn['length'] += 3;
980 1
        }
981
982 1
        return $arrayReturn;
983
    }
984
985
    /**
986
     * An atom record that specifies the name of a macro, a file name, or a named show.
987
     * @param string $stream
988
     * @param integer $pos
989
     * @link https://msdn.microsoft.com/en-us/library/dd925121(v=office.12).aspx
990
     */
991 1
    private function readRecordMacroNameAtom($stream, $pos)
992
    {
993
        $arrayReturn = array(
994 1
            'length' => 0,
995 1
        );
996
997 1
        $data = $this->loadRecordHeader($stream, $pos);
998 1
        if ($data['recVer'] == 0x0 && $data['recInstance'] == 0x002 && $data['recType'] == self::RT_CSTRING && $data['recLen'] % 2 == 0) {
999
            // Record Header
1000
            $arrayReturn['length'] += 8;
1001
            // Datas
1002
            $arrayReturn['length'] += $data['recLen'];
1003
        }
1004
1005 1
        return $arrayReturn;
1006
    }
1007
1008
    /**
1009
     * A container record that specifies what actions to perform when interacting with an object by means of a mouse click.
1010
     * @param string $stream
1011
     * @param integer $pos
1012
     * @link https://msdn.microsoft.com/en-us/library/dd952348(v=office.12).aspx
1013
     */
1014 1
    private function readRecordMouseClickInteractiveInfoContainer($stream, $pos)
1015
    {
1016
        $arrayReturn = array(
1017 1
            'length' => 0,
1018 1
        );
1019
1020 1
        $data = $this->loadRecordHeader($stream, $pos);
1021 1
        if ($data['recVer'] == 0xF && $data['recInstance'] == 0x000 && $data['recType'] == self::RT_INTERACTIVEINFO) {
1022
            // Record Header
1023 1
            $arrayReturn['length'] += 8;
1024
            // interactiveInfoAtom
1025 1
            $interactiveInfoAtom = $this->readRecordInteractiveInfoAtom($stream, $pos + $arrayReturn['length']);
1026 1
            $arrayReturn['length'] += $interactiveInfoAtom['length'];
1027 1
            if ($interactiveInfoAtom['length'] > 0) {
1028 1
                $arrayReturn['exHyperlinkIdRef'] = $interactiveInfoAtom['exHyperlinkIdRef'];
1029 1
            }
1030
            // macroNameAtom
1031 1
            $macroNameAtom = $this->readRecordMacroNameAtom($stream, $pos + $arrayReturn['length']);
1032 1
            $arrayReturn['length'] += $macroNameAtom['length'];
1033 1
        }
1034
1035 1
        return $arrayReturn;
1036
    }
1037
1038
    /**
1039
     * A container record that specifies what actions to perform when interacting with an object by moving the mouse cursor over it.
1040
     * @param string $stream
1041
     * @param integer $pos
1042
     * @link https://msdn.microsoft.com/en-us/library/dd925811(v=office.12).aspx
1043
     */
1044
    private function readRecordMouseOverInteractiveInfoContainer($stream, $pos)
1045
    {
1046
        $arrayReturn = array(
1047
            'length' => 0,
1048
        );
1049
1050
        $data = $this->loadRecordHeader($stream, $pos);
1051
        if ($data['recVer'] == 0xF && $data['recInstance'] == 0x001 && $data['recType'] == self::RT_INTERACTIVEINFO) {
1052
            // Record Header
1053
            $arrayReturn['length'] += 8;
1054
            // interactiveInfoAtom
1055
            // macroNameAtom
1056
            throw new \Exception('Feature not implemented (l.'.__LINE__.')');
1057
        }
1058
1059
        return $arrayReturn;
1060
    }
1061
1062
    /**
1063
     * The OfficeArtBlip record specifies BLIP file data.
1064
     * @param string $stream
1065
     * @param integer $pos
1066
     * @link https://msdn.microsoft.com/en-us/library/dd910081(v=office.12).aspx
1067
     */
1068 4
    private function readRecordOfficeArtBlip($stream, $pos)
1069
    {
1070
        $arrayReturn = array(
1071 4
            'length' => 0,
1072
            'picture' => null
1073 4
        );
1074
1075 4
        $data = $this->loadRecordHeader($stream, $pos);
1076 4
        if ($data['recVer'] == 0x0 && ($data['recType'] >= 0xF018 && $data['recType'] <= 0xF117)) {
1077
            // Record Header
1078 4
            $arrayReturn['length'] += 8;
1079
            // Datas
1080 4
            switch ($data['recType']) {
1081 4
                case self::OFFICEARTBLIPJPG:
1082 4
                case self::OFFICEARTBLIPPNG:
1083
                    // rgbUid1
1084 4
                    $arrayReturn['length'] += 16;
1085 4
                    $data['recLen'] -= 16;
1086 4
                    if ($data['recInstance'] == 0x6E1) {
1087
                        // rgbUid2
1088
                        $arrayReturn['length'] += 16;
1089
                        $data['recLen'] -= 16;
1090
                    }
1091
                    // tag
1092 4
                    $arrayReturn['length'] += 1;
1093 4
                    $data['recLen'] -= 1;
1094
                    // BLIPFileData
1095 4
                    $arrayReturn['picture'] = substr($this->streamPictures, $pos + $arrayReturn['length'], $data['recLen']);
1096 4
                    $arrayReturn['length'] += $data['recLen'];
1097 4
                    break;
1098
                default:
1099
                    throw new \Exception('Feature not implemented (l.'.__LINE__.' : '.dechex($data['recType'].')'));
1100 4
            }
1101 4
        }
1102
1103 4
        return $arrayReturn;
1104
    }
1105
1106
    /**
1107
     * The OfficeArtChildAnchor record specifies four signed integers that specify the anchor for the shape that contains this record.
1108
     * @param string $stream
1109
     * @param integer $pos
1110
     * @link https://msdn.microsoft.com/en-us/library/dd922720(v=office.12).aspx
1111
     */
1112 4
    private function readRecordOfficeArtChildAnchor($stream, $pos)
1113
    {
1114
        $arrayReturn = array(
1115
            'length' => 0
1116 4
        );
1117
1118 4
        $data = $this->loadRecordHeader($stream, $pos);
1119 4
        if ($data['recVer'] == 0x0 && $data['recInstance'] == 0x000 && $data['recType'] == 0xF00F && $data['recLen'] == 0x00000010) {
1120
            // Record Header
1121
            $arrayReturn['length'] += 8;
1122
            // Datas
1123
            $arrayReturn['left'] = (int) self::getInt4d($stream, $pos + $arrayReturn['length']);
1124
            $arrayReturn['length'] += 4;
1125
            $arrayReturn['top'] = (int) self::getInt4d($stream, $pos + $arrayReturn['length']);
1126
            $arrayReturn['length'] += 4;
1127
            $arrayReturn['width'] = (int) self::getInt4d($stream, $pos + $arrayReturn['length']) - $arrayReturn['left'];
1128
            $arrayReturn['length'] += 4;
1129
            $arrayReturn['height'] = (int) self::getInt4d($stream, $pos + $arrayReturn['length']) - $arrayReturn['top'];
1130
            $arrayReturn['length'] += 4;
1131
        }
1132
1133 4
        return $arrayReturn;
1134
    }
1135
1136
1137
1138
    /**
1139
     * An atom record that specifies the location of a shape.
1140
     * @param string $stream
1141
     * @param integer $pos
1142
     * @link https://msdn.microsoft.com/en-us/library/dd922797(v=office.12).aspx
1143
     */
1144 4
    private function readRecordOfficeArtClientAnchor($stream, $pos)
1145
    {
1146
        $arrayReturn = array(
1147
            'length' => 0
1148 4
        );
1149
1150 4
        $data = $this->loadRecordHeader($stream, $pos);
1151 4
        if ($data['recVer'] == 0x0 && $data['recInstance'] == 0x000 && $data['recType'] == 0xF010 && ($data['recLen'] == 0x00000008 || $data['recLen'] == 0x00000010)) {
1152
            // Record Header
1153 4
            $arrayReturn['length'] += 8;
1154
            // Datas
1155 4
            switch ($data['recLen']) {
1156 4
                case 0x00000008:
1157 4
                    $arrayReturn['top'] = (int) (self::getInt2d($stream, $pos + $arrayReturn['length']) / 6);
1158 4
                    $arrayReturn['length'] += 2;
1159 4
                    $arrayReturn['left'] = (int) (self::getInt2d($stream, $pos + $arrayReturn['length']) / 6);
1160 4
                    $arrayReturn['length'] += 2;
1161 4
                    $arrayReturn['width'] = (int) (self::getInt2d($stream, $pos + $arrayReturn['length']) / 6) - $arrayReturn['left'];
1162 4
                    $arrayReturn['length'] += 2;
1163 4
                    $arrayReturn['height'] = (int) (self::getInt2d($stream, $pos + $arrayReturn['length']) / 6) - $arrayReturn['left'];
1164 4
                    $arrayReturn['length'] += 2;
1165 4
                    $pos += 8;
1166 4
                    break;
1167
                case 0x00000010:
1168
                    throw new \Exception('PowerPoint97 Reader : record OfficeArtClientAnchor (0x00000010)');
1169 4
            }
1170 4
        }
1171
1172 4
        return $arrayReturn;
1173
    }
1174
    /**
1175
     * A container record that specifies text related data for a shape.
1176
     * @param string $stream
1177
     * @param integer $pos
1178
     * @link https://msdn.microsoft.com/en-us/library/dd910958(v=office.12).aspx
1179
     */
1180 4
    private function readRecordOfficeArtClientTextbox($stream, $pos)
1181
    {
1182
        $arrayReturn = array(
1183 4
            'length' => 0,
1184 4
            'text' => '',
1185 4
            'numParts' => 0,
1186 4
            'numTexts' => 0,
1187 4
            'hyperlink' => array(),
1188 4
        );
1189
1190 4
        $data = $this->loadRecordHeader($stream, $pos);
1191
        // recVer 0xF
1192
        // Doc : 0x0    https://msdn.microsoft.com/en-us/library/dd910958(v=office.12).aspx
1193
        // Sample : 0xF https://msdn.microsoft.com/en-us/library/dd953497(v=office.12).aspx
1194 4
        if ($data['recVer'] == 0xF && $data['recInstance'] == 0x000 && $data['recType'] == 0xF00D) {
1195
            // Record Header
1196 3
            $arrayReturn['length'] += 8;
1197
            // Datas
1198 3
            $strLen = 0;
1199
            do {
1200 3
                $rhChild = $this->loadRecordHeader($stream, $pos + $arrayReturn['length']);
1201
                /**
1202
                 * @link : https://msdn.microsoft.com/en-us/library/dd947039(v=office.12).aspx
1203
                 */
1204
                // echo dechex($rhChild['recType']).'-'.$rhChild['recType'].EOL;
1205 3
                switch ($rhChild['recType']) {
1206 3
                    case self::RT_INTERACTIVEINFO:
1207
                        //@link : http://msdn.microsoft.com/en-us/library/dd948623(v=office.12).aspx
1208 1
                        if ($rhChild['recInstance'] == 0x0000) {
1209 1
                            $mouseClickInfo = $this->readRecordMouseClickInteractiveInfoContainer($stream, $pos + $arrayReturn['length']);
1210 1
                            $arrayReturn['length'] += $mouseClickInfo['length'];
1211 1
                            $arrayReturn['hyperlink'][]['id'] = $mouseClickInfo['exHyperlinkIdRef'];
1212 1
                        }
1213 1
                        if ($rhChild['recInstance'] == 0x0001) {
1214
                            $mouseOverInfo = $this->readRecordMouseOverInteractiveInfoContainer($stream, $pos + $arrayReturn['length']);
1215
                            $arrayReturn['length'] += $mouseOverInfo['length'];
1216
                        }
1217 1
                        break;
1218 3
                    case self::RT_STYLETEXTPROPATOM:
1219 3
                        $arrayReturn['length'] += 8;
1220
                        // @link : http://msdn.microsoft.com/en-us/library/dd950647(v=office.12).aspx
1221
                        // rgTextPFRun
1222 3
                        $strLenRT = $strLen + 1;
1223
                        do {
1224 3
                            $strucTextPFRun = $this->readStructureTextPFRun($stream, $pos + $arrayReturn['length'], $strLenRT);
1225 3
                            $arrayReturn['numTexts']++;
1226 3
                            $arrayReturn['text'.$arrayReturn['numTexts']] = $strucTextPFRun;
1227 3
                            if (isset($strucTextPFRun['alignH'])) {
1228 3
                                $arrayReturn['alignH'] = $strucTextPFRun['alignH'];
1229 3
                            }
1230 3
                            $strLenRT = $strucTextPFRun['strLenRT'];
1231 3
                            $arrayReturn['length'] += $strucTextPFRun['length'];
1232 3
                        } while ($strLenRT > 0);
1233
                        // rgTextCFRun
1234 3
                        $strLenRT = $strLen + 1;
1235
                        do {
1236 3
                            $strucTextCFRun = $this->readStructureTextCFRun($stream, $pos + $arrayReturn['length'], $strLenRT);
1237 3
                            $arrayReturn['numParts']++;
1238 3
                            $arrayReturn['part'.$arrayReturn['numParts']] = $strucTextCFRun;
1239 3
                            $strLenRT = $strucTextCFRun['strLenRT'];
1240 3
                            $arrayReturn['length'] += $strucTextCFRun['length'];
1241 3
                        } while ($strLenRT > 0);
1242 3
                        break;
1243 3
                    case self::RT_TEXTBYTESATOM:
1244
                        $arrayReturn['length'] += 8;
1245
                        // @link : https://msdn.microsoft.com/en-us/library/dd947905(v=office.12).aspx
1246
                        $strLen = (int)$rhChild['recLen'];
1247
                        for ($inc = 0; $inc < $strLen; $inc++) {
1248
                            $char = self::getInt1d($stream, $pos + $arrayReturn['length']);
1249
                            if ($char == 0x0B) {
1250
                                $char = 0x20;
1251
                            }
1252
                            $arrayReturn['text'] .= Text::chr($char);
1253
                            $arrayReturn['length'] += 1;
1254
                        }
1255
                        break;
1256 3
                    case self::RT_TEXTCHARSATOM:
1257 3
                        $arrayReturn['length'] += 8;
1258
                        // @link : http://msdn.microsoft.com/en-us/library/dd772921(v=office.12).aspx
1259 3
                        $strLen = (int)($rhChild['recLen']/2);
1260 3
                        for ($inc = 0; $inc < $strLen; $inc++) {
1261 3
                            $char = self::getInt2d($stream, $pos + $arrayReturn['length']);
1262 3
                            if ($char == 0x0B) {
1263 1
                                $char = 0x20;
1264 1
                            }
1265 3
                            $arrayReturn['text'] .= Text::chr($char);
1266 3
                            $arrayReturn['length'] += 2;
1267 3
                        }
1268 3
                        break;
1269 3
                    case self::RT_TEXTHEADERATOM:
1270 3
                        $arrayReturn['length'] += 8;
1271
                        // @link : http://msdn.microsoft.com/en-us/library/dd905272(v=office.12).aspx
1272
                        // textType
1273 3
                        $arrayReturn['length'] += 4;
1274 3
                        break;
1275 3
                    case self::RT_TEXTINTERACTIVEINFOATOM:
1276 1
                        $arrayReturn['length'] += 8;
1277
                        //@link : http://msdn.microsoft.com/en-us/library/dd947973(v=office.12).aspx
1278 1
                        if ($rhChild['recInstance'] == 0x0000) {
1279
                            //@todo : MouseClickTextInteractiveInfoAtom
1280 1
                            $arrayReturn['hyperlink'][count($arrayReturn['hyperlink']) - 1]['start'] = self::getInt4d($stream, $pos +  + $arrayReturn['length']);
1281 1
                            $arrayReturn['length'] += 4;
1282
1283 1
                            $arrayReturn['hyperlink'][count($arrayReturn['hyperlink']) - 1]['end'] = self::getInt4d($stream, $pos +  + $arrayReturn['length']);
1284 1
                            $arrayReturn['length'] += 4;
1285 1
                        }
1286 1
                        if ($rhChild['recInstance'] == 0x0001) {
1287
                            throw new \Exception('Feature not implemented (l.'.__LINE__.')');
1288
                        }
1289 1
                        break;
1290 3
                    case self::RT_TEXTSPECIALINFOATOM:
1291 3
                        $arrayReturn['length'] += 8;
1292
                        // @link : http://msdn.microsoft.com/en-us/library/dd945296(v=office.12).aspx
1293 3
                        $strLenRT = $strLen + 1;
1294
                        do {
1295 3
                            $structTextSIRun = $this->readStructureTextSIRun($stream, $pos + $arrayReturn['length'], $strLenRT);
1296 3
                            $strLenRT = $structTextSIRun['strLenRT'];
1297 3
                            $arrayReturn['length'] += $structTextSIRun['length'];
1298 3
                        } while ($strLenRT > 0);
1299 3
                        break;
1300 3
                    case self::RT_TEXTRULERATOM:
1301 3
                        $arrayReturn['length'] += 8;
1302
                        // @link : http://msdn.microsoft.com/en-us/library/dd953212(v=office.12).aspx
1303 3
                        $structRuler = $this->readStructureTextRuler($stream, $pos + $arrayReturn['length']);
1304 3
                        $arrayReturn['length'] += $structRuler['length'];
1305 3
                        break;
1306
                    case self::RT_SLIDENUMBERMETACHARATOM:
1307
                        $datasRecord = $this->readRecordSlideNumberMCAtom($stream, $pos + $arrayReturn['length']);
1308
                        $arrayReturn['length'] += $datasRecord['length'];
1309
                        break;
1310
                    default:
1311
                        throw new \Exception('Feature not implemented (l.'.__LINE__.' : 0x'.dechex($rhChild['recType']).')');
1312 3
                }
1313 3
            } while (($data['recLen'] - $arrayReturn['length']) > 0);
1314 3
        }
1315 4
        return $arrayReturn;
1316
    }
1317
1318
    /**
1319
     * The OfficeArtSpContainer record specifies a shape container.
1320
     * @param string $stream
1321
     * @param integer $pos
1322
     * @link https://msdn.microsoft.com/en-us/library/dd943794(v=office.12).aspx
1323
     */
1324 4
    private function readRecordOfficeArtSpContainer($stream, $pos)
1325
    {
1326
        $arrayReturn = array(
1327 4
            'length' => 0,
1328 4
            'shape' => null,
1329 4
        );
1330
1331 4
        $data = $this->loadRecordHeader($stream, $pos);
1332 4
        if ($data['recVer'] == 0xF && $data['recInstance'] == 0x000 && $data['recType'] == 0xF004) {
1333
            // Record Header
1334 4
            $arrayReturn['length'] += 8;
1335
            // shapeGroup
1336 4
            $shapeGroup = $this->readRecordOfficeArtFSPGR($stream, $pos + $arrayReturn['length']);
1337 4
            $arrayReturn['length'] += $shapeGroup['length'];
1338
1339
            // shapeProp
1340 4
            $shapeProp = $this->readRecordOfficeArtFSP($stream, $pos + $arrayReturn['length']);
1341 4
            if ($shapeProp['length'] == 0) {
1342
                throw new \Exception('PowerPoint97 Reader : record OfficeArtFSP');
1343
            }
1344 4
            $arrayReturn['length'] += $shapeProp['length'];
1345
1346 4
            if ($shapeProp['fDeleted'] == 0x1 && $shapeProp['fChild'] == 0x0) {
1347
                // deletedShape
1348
                $deletedShape = $this->readRecordOfficeArtFPSPL($stream, $pos + $arrayReturn['length']);
1349
                $arrayReturn['length'] += $deletedShape['length'];
1350
            }
1351
1352
            // shapePrimaryOptions
1353 4
            $shpPrimaryOptions = $this->readRecordOfficeArtFOPT($stream, $pos + $arrayReturn['length']);
1354 4
            $arrayReturn['length'] += $shpPrimaryOptions['length'];
1355
1356
            // shapeSecondaryOptions1
1357 4
            $shpSecondaryOptions1 = $this->readRecordOfficeArtSecondaryFOPT($stream, $pos + $arrayReturn['length']);
1358 4
            $arrayReturn['length'] += $shpSecondaryOptions1['length'];
1359
1360
            // shapeTertiaryOptions1
1361 4
            $shpTertiaryOptions1 = $this->readRecordOfficeArtTertiaryFOPT($stream, $pos + $arrayReturn['length']);
1362 4
            $arrayReturn['length'] += $shpTertiaryOptions1['length'];
1363
1364
            // childAnchor
1365 4
            $childAnchor = $this->readRecordOfficeArtChildAnchor($stream, $pos + $arrayReturn['length']);
1366 4
            $arrayReturn['length'] += $childAnchor['length'];
1367
1368
            // clientAnchor
1369 4
            $clientAnchor = $this->readRecordOfficeArtClientAnchor($stream, $pos + $arrayReturn['length']);
1370 4
            $arrayReturn['length'] += $clientAnchor['length'];
1371
1372
            // clientData
1373 4
            $clientData = $this->readRecordOfficeArtClientData($stream, $pos + $arrayReturn['length']);
1374 4
            $arrayReturn['length'] += $clientData['length'];
1375
1376
            // clientTextbox
1377 4
            $clientTextbox = $this->readRecordOfficeArtClientTextbox($stream, $pos + $arrayReturn['length']);
1378 4
            $arrayReturn['length'] += $clientTextbox['length'];
1379
1380
            // shapeSecondaryOptions2
1381 4
            if ($shpSecondaryOptions1['length'] == 0) {
1382 4
                $shpSecondaryOptions2 = $this->readRecordOfficeArtSecondaryFOPT($stream, $pos + $arrayReturn['length']);
1383 4
                $arrayReturn['length'] += $shpSecondaryOptions2['length'];
1384 4
            }
1385
1386
            // shapeTertiaryOptions2
1387 4
            if ($shpTertiaryOptions1['length'] == 0) {
1388 4
                $shpTertiaryOptions2 = $this->readRecordOfficeArtTertiaryFOPT($stream, $pos + $arrayReturn['length']);
1389 4
                $arrayReturn['length'] += $shpTertiaryOptions2['length'];
1390 4
            }
1391
1392
            // Core : Shape
1393
            // Informations about group are not defined
1394 4
            $arrayDimensions = array();
1395 4
            $bIsGroup = false;
1396 4
            if (is_object($this->oCurrentGroup)) {
1397
                if (!$this->bFirstShapeGroup) {
1398
                    if ($clientAnchor['length'] > 0) {
1399
                        // $this->oCurrentGroup->setOffsetX($clientAnchor['left']);
1400
                        // $this->oCurrentGroup->setOffsetY($clientAnchor['top']);
1401
                        // $this->oCurrentGroup->setHeight($clientAnchor['height']);
1402
                        // $this->oCurrentGroup->setWidth($clientAnchor['width']);
1403
                    }
1404
                    $bIsGroup = true;
1405
                    $this->bFirstShapeGroup = true;
1406
                } else {
1407
                    if ($childAnchor['length'] > 0) {
1408
                        $arrayDimensions = $childAnchor;
1409
                    }
1410
                }
1411
            } else {
1412 4
                if ($clientAnchor['length'] > 0) {
1413 4
                    $arrayDimensions = $clientAnchor;
1414 4
                }
1415
            }
1416 4
            if (!$bIsGroup) {
1417
                // *** Shape ***
1418 4
                if (isset($shpPrimaryOptions['pib'])) {
1419
                    // isDrawing
1420 4
                    $drawingPib = $shpPrimaryOptions['pib'];
1421 4
                    if (isset($this->arrayPictures[$drawingPib - 1])) {
1422 4
                        $gdImage = imagecreatefromstring($this->arrayPictures[$drawingPib - 1]);
1423 4
                        $arrayReturn['shape'] = new MemoryDrawing();
1424 4
                        $arrayReturn['shape']->setImageResource($gdImage);
1425 4
                    }
1426 4
                } elseif (isset($shpPrimaryOptions['line']) && $shpPrimaryOptions['line']) {
1427
                    // isLine
1428 1
                    $arrayReturn['shape'] = new Line(0, 0, 0, 0);
1429 4
                } elseif ($clientTextbox['length'] > 0) {
1430 3
                    $arrayReturn['shape'] = new RichText();
1431 3
                    if (isset($clientTextbox['alignH'])) {
1432 3
                        $arrayReturn['shape']->getActiveParagraph()->getAlignment()->setHorizontal($clientTextbox['alignH']);
1433 3
                    }
1434
1435 3
                    $start = 0;
1436 3
                    $lastLevel = -1;
1437 3
                    $lastMarginLeft = 0;
1438 3
                    for ($inc = 1; $inc <= $clientTextbox['numParts']; $inc++) {
1439 3
                        if ($clientTextbox['numParts'] == $clientTextbox['numTexts'] && isset($clientTextbox['text'.$inc])) {
1440 2
                            if (isset($clientTextbox['text'.$inc]['bulletChar'])) {
1441 1
                                $arrayReturn['shape']->getActiveParagraph()->getBulletStyle()->setBulletType(Bullet::TYPE_BULLET);
1442 1
                                $arrayReturn['shape']->getActiveParagraph()->getBulletStyle()->setBulletChar($clientTextbox['text'.$inc]['bulletChar']);
1443 1
                            }
1444
                            // Indent
1445 2
                            $indent = 0;
1446 2
                            if (isset($clientTextbox['text'.$inc]['indent'])) {
1447 1
                                $indent = $clientTextbox['text'.$inc]['indent'];
1448 1
                            }
1449 2
                            if (isset($clientTextbox['text'.$inc]['leftMargin'])) {
1450 1
                                if ($lastMarginLeft > $clientTextbox['text'.$inc]['leftMargin']) {
1451 1
                                    $lastLevel--;
1452 1
                                }
1453 1
                                if ($lastMarginLeft < $clientTextbox['text'.$inc]['leftMargin']) {
1454 1
                                    $lastLevel++;
1455 1
                                }
1456 1
                                $arrayReturn['shape']->getActiveParagraph()->getAlignment()->setLevel($lastLevel);
1457 1
                                $lastMarginLeft = $clientTextbox['text'.$inc]['leftMargin'];
1458
1459 1
                                $arrayReturn['shape']->getActiveParagraph()->getAlignment()->setMarginLeft($clientTextbox['text'.$inc]['leftMargin']);
1460 1
                                $arrayReturn['shape']->getActiveParagraph()->getAlignment()->setIndent($indent - $clientTextbox['text'.$inc]['leftMargin']);
1461 1
                            }
1462 2
                        }
1463
                        // Texte
1464 3
                        $sText = substr(isset($clientTextbox['text']) ? $clientTextbox['text'] : '', $start, $clientTextbox['part'.$inc]['partLength']);
1465 3
                        $sHyperlinkURL = '';
1466 3
                        if (empty($sText)) {
1467
                            // Is there a hyperlink ?
1468 1
                            if (isset($clientTextbox['hyperlink']) && is_array($clientTextbox['hyperlink']) && !empty($clientTextbox['hyperlink'])) {
1469 1
                                foreach ($clientTextbox['hyperlink'] as $itmHyperlink) {
1470 1
                                    if ($itmHyperlink['start'] == $start && ($itmHyperlink['end'] - $itmHyperlink['start']) == $clientTextbox['part'.$inc]['partLength']) {
1471 1
                                        $sText = $this->arrayHyperlinks[$itmHyperlink['id']]['text'];
1472 1
                                        $sHyperlinkURL = $this->arrayHyperlinks[$itmHyperlink['id']]['url'];
1473 1
                                        break;
1474
                                    }
1475 1
                                }
1476 1
                            }
1477 1
                        }
1478
                        // New paragraph
1479 3
                        $bCreateParagraph = false;
1480 3
                        if (strpos($sText, "\r") !== false) {
1481 1
                            $bCreateParagraph = true;
1482 1
                            $sText = str_replace("\r", '', $sText);
1483 1
                        }
1484
                        // TextRun
1485 3
                        $txtRun = $arrayReturn['shape']->createTextRun($sText);
1486 3
                        if (isset($clientTextbox['part'.$inc]['bold'])) {
1487 3
                            $txtRun->getFont()->setBold($clientTextbox['part'.$inc]['bold']);
1488 3
                        }
1489 3
                        if (isset($clientTextbox['part'.$inc]['italic'])) {
1490 3
                            $txtRun->getFont()->setItalic($clientTextbox['part'.$inc]['italic']);
1491 3
                        }
1492 3
                        if (isset($clientTextbox['part'.$inc]['underline'])) {
1493 3
                            $txtRun->getFont()->setUnderline($clientTextbox['part'.$inc]['underline']);
1494 3
                        }
1495 3
                        if (isset($clientTextbox['part'.$inc]['fontName'])) {
1496 3
                            $txtRun->getFont()->setName($clientTextbox['part'.$inc]['fontName']);
1497 3
                        }
1498 3
                        if (isset($clientTextbox['part'.$inc]['fontSize'])) {
1499 3
                            $txtRun->getFont()->setSize($clientTextbox['part'.$inc]['fontSize']);
1500 3
                        }
1501 3
                        if (isset($clientTextbox['part'.$inc]['color'])) {
1502 3
                            $txtRun->getFont()->setColor($clientTextbox['part'.$inc]['color']);
1503 3
                        }
1504
                        // Hyperlink
1505 3
                        if (!empty($sHyperlinkURL)) {
1506 1
                            $txtRun->setHyperlink(new Hyperlink($sHyperlinkURL));
1507 1
                        }
1508
1509 3
                        $start += $clientTextbox['part'.$inc]['partLength'];
1510 3
                        if ($bCreateParagraph) {
1511 1
                            $arrayReturn['shape']->createParagraph();
1512 1
                        }
1513 3
                    }
1514 3
                }
1515
1516
                // *** Properties ***
1517
                // Dimensions
1518 4
                if ($arrayReturn['shape'] instanceof AbstractShape) {
1519 4
                    if (!empty($arrayDimensions)) {
1520 4
                        $arrayReturn['shape']->setOffsetX($arrayDimensions['left']);
1521 4
                        $arrayReturn['shape']->setOffsetY($arrayDimensions['top']);
1522 4
                        $arrayReturn['shape']->setHeight($arrayDimensions['height']);
1523 4
                        $arrayReturn['shape']->setWidth($arrayDimensions['width']);
1524 4
                    }
1525
                    // Rotation
1526 4
                    if (isset($shpPrimaryOptions['rotation'])) {
1527
                        $rotation = $shpPrimaryOptions['rotation'];
1528
                        $arrayReturn['shape']->setRotation($rotation);
1529
                    }
1530
                    // Shadow
1531 4
                    if (isset($shpPrimaryOptions['shadowOffsetX']) && isset($shpPrimaryOptions['shadowOffsetY'])) {
1532 3
                        $shadowOffsetX = $shpPrimaryOptions['shadowOffsetX'];
1533 3
                        $shadowOffsetY = $shpPrimaryOptions['shadowOffsetY'];
1534 3
                        if ($shadowOffsetX != 0 && $shadowOffsetX != 0) {
1535 3
                            $arrayReturn['shape']->getShadow()->setVisible(true);
1536 3
                            if ($shadowOffsetX > 0 && $shadowOffsetX == $shadowOffsetY) {
1537 3
                                $arrayReturn['shape']->getShadow()->setDistance($shadowOffsetX)->setDirection(45);
1538 3
                            }
1539 3
                        }
1540 3
                    }
1541
                    // Specific Line
1542 4
                    if ($arrayReturn['shape'] instanceof Line) {
1543 1
                        if (isset($shpPrimaryOptions['lineColor'])) {
1544 1
                            $arrayReturn['shape']->getBorder()->getColor()->setARGB('FF'.$shpPrimaryOptions['lineColor']);
1545 1
                        }
1546 1
                        if (isset($shpPrimaryOptions['lineWidth'])) {
1547 1
                            $arrayReturn['shape']->setHeight($shpPrimaryOptions['lineWidth']);
1548 1
                        }
1549 1
                    }
1550
                    // Specific RichText
1551 4
                    if ($arrayReturn['shape'] instanceof RichText) {
1552 3
                        if (isset($shpPrimaryOptions['insetBottom'])) {
1553 3
                            $arrayReturn['shape']->setInsetBottom($shpPrimaryOptions['insetBottom']);
1554 3
                        }
1555 3
                        if (isset($shpPrimaryOptions['insetLeft'])) {
1556 3
                            $arrayReturn['shape']->setInsetLeft($shpPrimaryOptions['insetLeft']);
1557 3
                        }
1558 3
                        if (isset($shpPrimaryOptions['insetRight'])) {
1559 3
                            $arrayReturn['shape']->setInsetRight($shpPrimaryOptions['insetRight']);
1560 3
                        }
1561 3
                        if (isset($shpPrimaryOptions['insetTop'])) {
1562 3
                            $arrayReturn['shape']->setInsetTop($shpPrimaryOptions['insetTop']);
1563 3
                        }
1564 3
                    }
1565 4
                }
1566 4
            } else {
1567
                // Rotation
1568
                if (isset($shpPrimaryOptions['rotation'])) {
1569
                    $rotation = $shpPrimaryOptions['rotation'];
1570
                    $this->oCurrentGroup->setRotation($rotation);
1571
                }
1572
            }
1573 4
        }
1574
1575 4
        return $arrayReturn;
1576
    }
1577
1578
    /**
1579
     * The OfficeArtSpgrContainer record specifies a container for groups of shapes.
1580
     * @param string $stream
1581
     * @param integer $pos
1582
     * @param boolean $bInGroup
1583
     * @link : https://msdn.microsoft.com/en-us/library/dd910416(v=office.12).aspx
1584
     */
1585 4
    private function readRecordOfficeArtSpgrContainer($stream, $pos, $bInGroup = false)
1586
    {
1587
        $arrayReturn = array(
1588 4
            'length' => 0,
1589 4
        );
1590
1591 4
        $data = $this->loadRecordHeader($stream, $pos);
1592 4
        if ($data['recVer'] == 0xF && $data['recInstance'] == 0x000 && $data['recType'] == 0xF003) {
1593 4
            $arrayReturn['length'] += 8;
1594
1595
            do {
1596 4
                $rhFileBlock = $this->loadRecordHeader($stream, $pos + $arrayReturn['length']);
1597 4
                if (!($rhFileBlock['recVer'] == 0xF && $rhFileBlock['recInstance'] == 0x0000 && ($rhFileBlock['recType'] == 0xF003 || $rhFileBlock['recType'] == 0xF004))) {
1598
                    throw new \Exception('PowerPoint97 Reader : readRecordOfficeArtSpgrContainer.');
1599
                }
1600
1601 4
                switch ($rhFileBlock['recType']) {
1602 4
                    case 0xF003:
1603
                        // Core
1604
                        $this->oCurrentGroup = $this->oPhpPresentation->getActiveSlide()->createGroup();
1605
                        $this->bFirstShapeGroup = false;
1606
                        // OfficeArtSpgrContainer
1607
                        $fileBlock = $this->readRecordOfficeArtSpgrContainer($stream, $pos + $arrayReturn['length'], true);
1608
                        $arrayReturn['length'] += $fileBlock['length'];
1609
                        $data['recLen'] -= $fileBlock['length'];
1610
                        break;
1611 4
                    case 0xF004:
1612
                        // Core
1613 4
                        if (!$bInGroup) {
1614 4
                            $this->oCurrentGroup = null;
1615 4
                        }
1616
                        // OfficeArtSpContainer
1617 4
                        $fileBlock = $this->readRecordOfficeArtSpContainer($stream, $pos + $arrayReturn['length']);
1618 4
                        $arrayReturn['length'] += $fileBlock['length'];
1619 4
                        $data['recLen'] -= $fileBlock['length'];
1620
                        // Core
1621
                        //@todo
1622 4
                        if (!is_null($fileBlock['shape'])) {
1623 4
                            if ($bInGroup) {
1624
                                $this->oCurrentGroup->addShape($fileBlock['shape']);
1625
                            } else {
1626 4
                                $this->oPhpPresentation->getActiveSlide()->addShape($fileBlock['shape']);
1627
                            }
1628 4
                        }
1629
1630 4
                        break;
1631 4
                }
1632 4
            } while ($data['recLen'] > 0);
1633 4
        }
1634 4
        return $arrayReturn;
1635
    }
1636
1637
    /**
1638
     * The OfficeArtTertiaryFOPT record specifies a table of OfficeArtRGFOPTE records,.
1639
     * @param string $stream
1640
     * @param integer $pos
1641
     * @link https://msdn.microsoft.com/en-us/library/dd950206(v=office.12).aspx
1642
     */
1643 4
    private function readRecordOfficeArtTertiaryFOPT($stream, $pos)
1644
    {
1645
        $arrayReturn = array(
1646 4
            'length' => 0,
1647 4
        );
1648
1649 4
        $data = $this->loadRecordHeader($stream, $pos);
1650 4
        if ($data['recVer'] == 0x3 && $data['recType'] == 0xF122) {
1651
            // Record Header
1652
            $arrayReturn['length'] += 8;
1653
1654
            $officeArtFOPTE = array();
1655
            for ($inc = 0; $inc < $data['recInstance']; $inc++) {
1656
                $opid = self::getInt2d($this->streamPowerpointDocument, $pos + $arrayReturn['length']);
1657
                $arrayReturn['length'] += 2;
1658
                $optOp = self::getInt4d($this->streamPowerpointDocument, $pos + $arrayReturn['length']);
1659
                $arrayReturn['length'] += 4;
1660
                $officeArtFOPTE[] = array(
1661
                    'opid' => ($opid >> 0) & bindec('11111111111111'),
1662
                    'fBid' => ($opid >> 14) & bindec('1'),
1663
                    'fComplex' => ($opid >> 15) & bindec('1'),
1664
                    'op' => $optOp,
1665
                );
1666
            }
1667
            //@link : http://code.metager.de/source/xref/kde/calligra/filters/libmso/OPID
1668
            foreach ($officeArtFOPTE as $opt) {
1669
                switch ($opt['opid']) {
1670
                    case 0x039F:
1671
                        // Table properties
1672
                        //@link : https://msdn.microsoft.com/en-us/library/dd922773(v=office.12).aspx
1673
                        break;
1674
                    case 0x03A0:
1675
                        // Table Row Properties
1676
                        //@link : https://msdn.microsoft.com/en-us/library/dd923419(v=office.12).aspx
1677
                        if ($opt['fComplex'] == 0x1) {
1678
                            $arrayReturn['length'] += $opt['op'];
1679
                        }
1680
                        break;
1681
                    case 0x03A9:
1682
                        // GroupShape : metroBlob
1683
                        //@link : https://msdn.microsoft.com/en-us/library/dd943388(v=office.12).aspx
1684
                        if ($opt['fComplex'] == 0x1) {
1685
                            $arrayReturn['length'] += $opt['op'];
1686
                        }
1687
                        break;
1688
                    case 0x01FF:
1689
                        // Line Style Boolean
1690
                        //@link : https://msdn.microsoft.com/en-us/library/dd951605(v=office.12).aspx
1691
                        break;
1692
                    default:
1693
                        throw new \Exception('Feature not implemented (l.'.__LINE__.' : 0x'.dechex($opt['opid']).')');
1694
                }
1695
            }
1696
        }
1697 4
        return $arrayReturn;
1698
    }
1699
1700
    /**
1701
     * The OfficeArtDgContainer record specifies the container for all the file records for the objects in a drawing.
1702
     * @param string $stream
1703
     * @param integer $pos
1704
     * @link : https://msdn.microsoft.com/en-us/library/dd924455(v=office.12).aspx
1705
     */
1706 4
    private function readRecordOfficeArtDgContainer($stream, $pos)
1707
    {
1708
        $arrayReturn = array(
1709 4
            'length' => 0,
1710 4
        );
1711
1712 4
        $data = $this->loadRecordHeader($stream, $pos);
1713 4
        if ($data['recVer'] == 0xF && $data['recInstance'] == 0x000 && $data['recType'] == 0xF002) {
1714
            // Record Header
1715 4
            $arrayReturn['length'] += 8;
1716
            // drawingData
1717 4
            $drawingData  = $this->readRecordOfficeArtFDG($stream, $pos + $arrayReturn['length']);
1718 4
            $arrayReturn['length'] += $drawingData['length'];
1719
            // regroupItems
1720
            //@todo
1721
            // groupShape
1722 4
            $groupShape = $this->readRecordOfficeArtSpgrContainer($stream, $pos + $arrayReturn['length']);
1723 4
            $arrayReturn['length'] += $groupShape['length'];
1724
            // shape
1725 4
            $shape = $this->readRecordOfficeArtSpContainer($stream, $pos + $arrayReturn['length']);
1726 4
            $arrayReturn['length'] += $shape['length'];
1727
            // solvers1
1728
            //@todo
1729
            // deletedShapes
1730
            //@todo
1731
            // solvers1
1732
            //@todo
1733 4
        }
1734
1735 4
        return $arrayReturn;
1736
    }
1737
1738
    /**
1739
     * The OfficeArtFDG record specifies the number of shapes, the drawing identifier, and the shape identifier of the last shape in a drawing.
1740
     * @param string $stream
1741
     * @param integer $pos
1742
     * @link : https://msdn.microsoft.com/en-us/library/dd946757(v=office.12).aspx
1743
     */
1744 4
    private function readRecordOfficeArtFDG($stream, $pos)
1745
    {
1746
        $arrayReturn = array(
1747 4
            'length' => 0,
1748 4
        );
1749
1750 4
        $data = $this->loadRecordHeader($stream, $pos);
1751 4
        if ($data['recVer'] == 0x0 && $data['recInstance'] <= 0xFFE && $data['recType'] == 0xF008 && $data['recLen'] == 0x00000008) {
1752
            // Record Header
1753 4
            $arrayReturn['length'] += 8;
1754
            // Length
1755 4
            $arrayReturn['length'] += $data['recLen'];
1756 4
        }
1757
1758 4
        return $arrayReturn;
1759
    }
1760
1761
    /**
1762
     * The OfficeArtFOPT record specifies a table of OfficeArtRGFOPTE records.
1763
     * @param string $stream
1764
     * @param integer $pos
1765
     * @link https://msdn.microsoft.com/en-us/library/dd943404(v=office.12).aspx
1766
     */
1767 4
    private function readRecordOfficeArtFOPT($stream, $pos)
1768
    {
1769
        $arrayReturn = array(
1770 4
            'length' => 0,
1771 4
        );
1772
1773 4
        $data = $this->loadRecordHeader($stream, $pos);
1774 4
        if ($data['recVer'] == 0x3 && $data['recType'] == 0xF00B) {
1775
            // Record Header
1776 4
            $arrayReturn['length'] += 8;
1777
1778
            //@link : http://msdn.microsoft.com/en-us/library/dd906086(v=office.12).aspx
1779 4
            $officeArtFOPTE = array();
1780 4
            for ($inc = 0; $inc < $data['recInstance']; $inc++) {
1781 4
                $opid = self::getInt2d($this->streamPowerpointDocument, $pos + $arrayReturn['length']);
1782 4
                $arrayReturn['length'] += 2;
1783 4
                $data['recLen'] -= 2;
1784 4
                $optOp = self::getInt4d($this->streamPowerpointDocument, $pos + $arrayReturn['length']);
1785 4
                $arrayReturn['length'] += 4;
1786 4
                $data['recLen'] -= 4;
1787 4
                $officeArtFOPTE[] = array(
1788 4
                    'opid' => ($opid >> 0) & bindec('11111111111111'),
1789 4
                    'fBid' => ($opid >> 14) & bindec('1'),
1790 4
                    'fComplex' => ($opid >> 15) & bindec('1'),
1791 4
                    'op' => $optOp,
1792
                );
1793 4
            }
1794
            //@link : http://code.metager.de/source/xref/kde/calligra/filters/libmso/OPID
1795 4
            foreach ($officeArtFOPTE as $opt) {
1796
                // echo $opt['opid'].'-0x'.dechex($opt['opid']).EOL;
1797 4
                switch ($opt['opid']) {
1798 4
                    case 0x0004:
1799
                        // Transform : rotation
1800
                        //@link : https://msdn.microsoft.com/en-us/library/dd949750(v=office.12).aspx
1801
                        $arrayReturn['rotation'] = $opt['op'];
1802
                        break;
1803 4
                    case 0x007F:
1804
                        // Transform : Protection Boolean Properties
1805
                        //@link : http://msdn.microsoft.com/en-us/library/dd909131(v=office.12).aspx
1806 4
                        break;
1807 4
                    case 0x0080:
1808
                        // Text : ltxid
1809
                        //@link : http://msdn.microsoft.com/en-us/library/dd947446(v=office.12).aspx
1810 3
                        break;
1811 4
                    case 0x0081:
1812
                        // Text : dxTextLeft
1813
                        //@link : http://msdn.microsoft.com/en-us/library/dd953234(v=office.12).aspx
1814 3
                        $arrayReturn['insetLeft'] = \PhpOffice\Common\Drawing::emuToPixels($opt['op']);
1815 3
                        break;
1816 4
                    case 0x0082:
1817
                        // Text : dyTextTop
1818
                        //@link : http://msdn.microsoft.com/en-us/library/dd925068(v=office.12).aspx
1819 3
                        $arrayReturn['insetTop'] = \PhpOffice\Common\Drawing::emuToPixels($opt['op']);
1820 3
                        break;
1821 4
                    case 0x0083:
1822
                        // Text : dxTextRight
1823
                        //@link : http://msdn.microsoft.com/en-us/library/dd906782(v=office.12).aspx
1824 3
                        $arrayReturn['insetRight'] = \PhpOffice\Common\Drawing::emuToPixels($opt['op']);
1825 3
                        break;
1826 4
                    case 0x0084:
1827
                        // Text : dyTextBottom
1828
                        //@link : http://msdn.microsoft.com/en-us/library/dd772858(v=office.12).aspx
1829 3
                        $arrayReturn['insetBottom'] = \PhpOffice\Common\Drawing::emuToPixels($opt['op']);
1830 3
                        break;
1831 4
                    case 0x0085:
1832
                        // Text : WrapText
1833
                        //@link : http://msdn.microsoft.com/en-us/library/dd924770(v=office.12).aspx
1834 4
                        break;
1835 4
                    case 0x0087:
1836
                        // Text : anchorText
1837
                        //@link : http://msdn.microsoft.com/en-us/library/dd948575(v=office.12).aspx
1838 4
                        break;
1839 4
                    case 0x00BF:
1840
                        // Text : Text Boolean Properties
1841
                        //@link : http://msdn.microsoft.com/en-us/library/dd950905(v=office.12).aspx
1842 3
                        break;
1843 4
                    case 0x0104:
1844
                        // Blip : pib
1845
                        //@link : http://msdn.microsoft.com/en-us/library/dd772837(v=office.12).aspx
1846 4
                        if ($opt['fComplex'] == 0) {
1847 4
                            $arrayReturn['pib'] = $opt['op'];
1848 4
                            $data['recLen'] -= $opt['op'];
1849 4
                        } else {
1850
                            // pib Complex
1851
                        }
1852 4
                        break;
1853 4
                    case 0x13F:
1854
                        // Blip Boolean Properties
1855
                        //@link : https://msdn.microsoft.com/en-us/library/dd944215(v=office.12).aspx
1856
                        break;
1857 4
                    case 0x140:
1858
                        // Geometry : geoLeft
1859
                        //@link : http://msdn.microsoft.com/en-us/library/dd947489(v=office.12).aspx
1860
                        // print_r('geoLeft : '.$opt['op'].EOL);
1861 2
                        break;
1862 4
                    case 0x141:
1863
                        // Geometry : geoTop
1864
                        //@link : http://msdn.microsoft.com/en-us/library/dd949459(v=office.12).aspx
1865
                        // print_r('geoTop : '.$opt['op'].EOL);
1866 2
                        break;
1867 4
                    case 0x142:
1868
                        // Geometry : geoRight
1869
                        //@link : http://msdn.microsoft.com/en-us/library/dd947117(v=office.12).aspx
1870
                        // print_r('geoRight : '.$opt['op'].EOL);
1871 2
                        break;
1872 4
                    case 0x143:
1873
                        // Geometry : geoBottom
1874
                        //@link : http://msdn.microsoft.com/en-us/library/dd948602(v=office.12).aspx
1875
                        // print_r('geoBottom : '.$opt['op'].EOL);
1876 2
                        break;
1877 4
                    case 0x144:
1878
                        // Geometry : shapePath
1879
                        //@link : http://msdn.microsoft.com/en-us/library/dd945249(v=office.12).aspx
1880 1
                        $arrayReturn['line'] = true;
1881 1
                        break;
1882 4
                    case 0x145:
1883
                        // Geometry : pVertices
1884
                        //@link : http://msdn.microsoft.com/en-us/library/dd949814(v=office.12).aspx
1885 2
                        if ($opt['fComplex'] == 1) {
1886 2
                            $arrayReturn['length'] += $opt['op'];
1887 2
                            $data['recLen'] -= $opt['op'];
1888 2
                        }
1889 2
                        break;
1890 4
                    case 0x146:
1891
                        // Geometry : pSegmentInfo
1892
                        //@link : http://msdn.microsoft.com/en-us/library/dd905742(v=office.12).aspx
1893 2
                        if ($opt['fComplex'] == 1) {
1894 2
                            $arrayReturn['length'] += $opt['op'];
1895 2
                            $data['recLen'] -= $opt['op'];
1896 2
                        }
1897 2
                        break;
1898 4
                    case 0x155:
1899
                        // Geometry : pAdjustHandles
1900
                        //@link : http://msdn.microsoft.com/en-us/library/dd905890(v=office.12).aspx
1901 2
                        if ($opt['fComplex'] == 1) {
1902 2
                            $arrayReturn['length'] += $opt['op'];
1903 2
                            $data['recLen'] -= $opt['op'];
1904 2
                        }
1905 2
                        break;
1906 4
                    case 0x156:
1907
                        // Geometry : pGuides
1908
                        //@link : http://msdn.microsoft.com/en-us/library/dd910801(v=office.12).aspx
1909 2
                        if ($opt['fComplex'] == 1) {
1910 2
                            $arrayReturn['length'] += $opt['op'];
1911 2
                            $data['recLen'] -= $opt['op'];
1912 2
                        }
1913 2
                        break;
1914 4
                    case 0x157:
1915
                        // Geometry : pInscribe
1916
                        //@link : http://msdn.microsoft.com/en-us/library/dd904889(v=office.12).aspx
1917 2
                        if ($opt['fComplex'] == 1) {
1918 2
                            $arrayReturn['length'] += $opt['op'];
1919 2
                            $data['recLen'] -= $opt['op'];
1920 2
                        }
1921 2
                        break;
1922 4
                    case 0x17F:
1923
                        // Geometry Boolean Properties
1924
                        //@link : http://msdn.microsoft.com/en-us/library/dd944968(v=office.12).aspx
1925 1
                        break;
1926 4
                    case 0x0180:
1927
                        // Fill : fillType
1928
                        //@link : http://msdn.microsoft.com/en-us/library/dd947909(v=office.12).aspx
1929 4
                        break;
1930 4
                    case 0x0181:
1931
                        // Fill : fillColor
1932
                        //@link : http://msdn.microsoft.com/en-us/library/dd921332(v=office.12).aspx
1933 1
                        $strColor = str_pad(dechex(($opt['op'] >> 0) & bindec('11111111')), 2, STR_PAD_LEFT, '0');
1934 1
                        $strColor .= str_pad(dechex(($opt['op'] >> 8) & bindec('11111111')), 2, STR_PAD_LEFT, '0');
1935 1
                        $strColor .= str_pad(dechex(($opt['op'] >> 16) & bindec('11111111')), 2, STR_PAD_LEFT, '0');
1936
                        // echo 'fillColor  : '.$strColor.EOL;
1937 1
                        break;
1938 4
                    case 0x0183:
1939
                        // Fill : fillBackColor
1940
                        //@link : http://msdn.microsoft.com/en-us/library/dd950634(v=office.12).aspx
1941 1
                        $strColor = str_pad(dechex(($opt['op'] >> 0) & bindec('11111111')), 2, STR_PAD_LEFT, '0');
1942 1
                        $strColor .= str_pad(dechex(($opt['op'] >> 8) & bindec('11111111')), 2, STR_PAD_LEFT, '0');
1943 1
                        $strColor .= str_pad(dechex(($opt['op'] >> 16) & bindec('11111111')), 2, STR_PAD_LEFT, '0');
1944
                        // echo 'fillBackColor  : '.$strColor.EOL;
1945 1
                        break;
1946 4
                    case 0x0193:
1947
                        // Fill : fillRectRight
1948
                        //@link : http://msdn.microsoft.com/en-us/library/dd951294(v=office.12).aspx
1949
                        // echo 'fillRectRight  : '.\PhpOffice\Common\Drawing::emuToPixels($opt['op']).EOL;
1950 4
                        break;
1951 4
                    case 0x0194:
1952
                        // Fill : fillRectBottom
1953
                        //@link : http://msdn.microsoft.com/en-us/library/dd910194(v=office.12).aspx
1954
                        // echo 'fillRectBottom   : '.\PhpOffice\Common\Drawing::emuToPixels($opt['op']).EOL;
1955 4
                        break;
1956 4
                    case 0x01BF:
1957
                        // Fill : Fill Style Boolean Properties
1958
                        //@link : http://msdn.microsoft.com/en-us/library/dd909380(v=office.12).aspx
1959 4
                        break;
1960 4
                    case 0x01C0:
1961
                        // Line Style : lineColor
1962
                        //@link : http://msdn.microsoft.com/en-us/library/dd920397(v=office.12).aspx
1963 4
                        $strColor = str_pad(dechex(($opt['op'] >> 0) & bindec('11111111')), 2, STR_PAD_LEFT, '0');
1964 4
                        $strColor .= str_pad(dechex(($opt['op'] >> 8) & bindec('11111111')), 2, STR_PAD_LEFT, '0');
1965 4
                        $strColor .= str_pad(dechex(($opt['op'] >> 16) & bindec('11111111')), 2, STR_PAD_LEFT, '0');
1966 4
                        $arrayReturn['lineColor'] = $strColor;
1967 4
                        break;
1968 4
                    case 0x01C1:
1969
                        // Line Style : lineOpacity
1970
                        //@link : http://msdn.microsoft.com/en-us/library/dd923433(v=office.12).aspx
1971
                        // echo 'lineOpacity : '.dechex($opt['op']).EOL;
1972 4
                        break;
1973 4
                    case 0x01C2:
1974
                        // Line Style : lineBackColor
1975
                        //@link : http://msdn.microsoft.com/en-us/library/dd947669(v=office.12).aspx
1976 4
                        break;
1977 4
                    case 0x01CB:
1978
                        // Line Style : lineWidth
1979
                        //@link : http://msdn.microsoft.com/en-us/library/dd926964(v=office.12).aspx
1980 1
                        $arrayReturn['lineWidth'] = \PhpOffice\Common\Drawing::emuToPixels($opt['op']);
1981 1
                        break;
1982 4
                    case 0x01D6:
1983
                        // Line Style : lineJoinStyle
1984
                        //@link : http://msdn.microsoft.com/en-us/library/dd909643(v=office.12).aspx
1985 4
                        break;
1986 4
                    case 0x01D7:
1987
                        // Line Style : lineEndCapStyle
1988
                        //@link : http://msdn.microsoft.com/en-us/library/dd925071(v=office.12).aspx
1989 4
                        break;
1990 4
                    case 0x01FF:
1991
                        // Line Style : Line Style Boolean Properties
1992
                        //@link : http://msdn.microsoft.com/en-us/library/dd951605(v=office.12).aspx
1993 4
                        break;
1994 4
                    case 0x0201:
1995
                        // Shadow Style : shadowColor
1996
                        //@link : http://msdn.microsoft.com/en-us/library/dd923454(v=office.12).aspx
1997 3
                        break;
1998 4
                    case 0x0204:
1999
                        // Shadow Style : shadowOpacity
2000
                        //@link : http://msdn.microsoft.com/en-us/library/dd920720(v=office.12).aspx
2001 3
                        break;
2002 4
                    case 0x0205:
2003
                        // Shadow Style : shadowOffsetX
2004
                        //@link : http://msdn.microsoft.com/en-us/library/dd945280(v=office.12).aspx
2005 3
                        $arrayReturn['shadowOffsetX'] = \PhpOffice\Common\Drawing::emuToPixels($opt['op']);
2006 3
                        break;
2007 4
                    case 0x0206:
2008
                        // Shadow Style : shadowOffsetY
2009
                        //@link : http://msdn.microsoft.com/en-us/library/dd907855(v=office.12).aspx
2010 3
                        $arrayReturn['shadowOffsetY'] = \PhpOffice\Common\Drawing::emuToPixels($opt['op']);
2011 3
                        break;
2012 4
                    case 0x023F:
2013
                        // Shadow Style : Shadow Style Boolean Properties
2014
                        //@link : http://msdn.microsoft.com/en-us/library/dd947887(v=office.12).aspx
2015 4
                        break;
2016 4
                    case 0x0304:
2017
                        // Shape : bWMode
2018
                        //@link : http://msdn.microsoft.com/en-us/library/dd947659(v=office.12).aspx
2019 4
                        break;
2020 4
                    case 0x033F:
2021
                        // Shape Boolean Properties
2022
                        //@link : http://msdn.microsoft.com/en-us/library/dd951345(v=office.12).aspx
2023 4
                        break;
2024
                    case 0x0380:
2025
                        // Group Shape Property Set : wzName
2026
                        //@link : http://msdn.microsoft.com/en-us/library/dd950681(v=office.12).aspx
2027
                        if ($opt['fComplex'] == 1) {
2028
                            $arrayReturn['length'] += $opt['op'];
2029
                            $data['recLen'] -= $opt['op'];
2030
                        }
2031
                        break;
2032
                    case 0x03BF:
2033
                        // Group Shape Property Set : Group Shape Boolean Properties
2034
                        //@link : http://msdn.microsoft.com/en-us/library/dd949807(v=office.12).aspx
2035
                        break;
2036
                    default:
2037
                        throw new \Exception('Feature not implemented (l.'.__LINE__.' : 0x'.dechex($opt['opid']).')');
2038 4
                }
2039 4
            }
2040 4
            if ($data['recLen'] > 0) {
2041 2
                $arrayReturn['length'] += $data['recLen'];
2042 2
            }
2043 4
        }
2044
2045 4
        return $arrayReturn;
2046
    }
2047
2048
    /**
2049
     * The OfficeArtFPSPL record specifies the former hierarchical position of the containing object that is either a shape or a group of shapes.
2050
     * @param string $stream
2051
     * @param integer $pos
2052
     * @link https://msdn.microsoft.com/en-us/library/dd947479(v=office.12).aspx
2053
     */
2054
    private function readRecordOfficeArtFPSPL($stream, $pos)
2055
    {
2056
        $arrayReturn = array(
2057
            'length' => 0,
2058
        );
2059
2060
        $data = $this->loadRecordHeader($stream, $pos);
2061
        if ($data['recVer'] == 0x0 && $data['recInstance'] == 0x000 && $data['recType'] == 0xF11D && $data['recLen'] == 0x00000004) {
2062
            $arrayReturn['length'] += 8;
2063
            $arrayReturn['length'] += $data['recLen'];
2064
        }
2065
2066
        return $arrayReturn;
2067
    }
2068
2069
    /**
2070
     * The OfficeArtFSP record specifies an instance of a shape.
2071
     * @param string $stream
2072
     * @param integer $pos
2073
     * @link https://msdn.microsoft.com/en-us/library/dd925898(v=office.12).aspx
2074
     */
2075 4
    private function readRecordOfficeArtFSP($stream, $pos)
2076
    {
2077
        $arrayReturn = array(
2078 4
            'length' => 0,
2079 4
        );
2080
2081 4
        $data = $this->loadRecordHeader($stream, $pos);
2082 4
        if ($data['recVer'] == 0x2 && $data['recType'] == 0xF00A && $data['recLen'] == 0x00000008) {
2083 4
            $arrayReturn['length'] += 8;
2084
            // spid
2085 4
            $arrayReturn['length'] += 4;
2086
            // data
2087 4
            $data = self::getInt4d($this->streamPowerpointDocument, $pos + $arrayReturn['length']);
2088 4
            $arrayReturn['length'] += 4;
2089 4
            $arrayReturn['fGroup'] = ($data >> 0) & bindec('1');
2090 4
            $arrayReturn['fChild'] = ($data >> 1) & bindec('1');
2091 4
            $arrayReturn['fPatriarch'] = ($data >> 2) & bindec('1');
2092 4
            $arrayReturn['fDeleted'] = ($data >> 3) & bindec('1');
2093 4
        }
2094
2095 4
        return $arrayReturn;
2096
    }
2097
2098
    /**
2099
     * The OfficeArtFSPGR record specifies the coordinate system of the group shape that the anchors of the child shape are expressed in.
2100
     * @param string $stream
2101
     * @param integer $pos
2102
     * @link https://msdn.microsoft.com/en-us/library/dd925381(v=office.12).aspx
2103
     */
2104 4
    private function readRecordOfficeArtFSPGR($stream, $pos)
2105
    {
2106
        $arrayReturn = array(
2107 4
            'length' => 0,
2108 4
        );
2109
2110 4
        $data = $this->loadRecordHeader($stream, $pos);
2111 4
        if ($data['recVer'] == 0x1 && $data['recInstance'] == 0x000 && $data['recType'] == 0xF009 && $data['recLen'] == 0x00000010) {
2112 4
            $arrayReturn['length'] += 8;
2113
            //$arrShapeGroup['xLeft'] = self::getInt4d($this->streamPowerpointDocument, $pos);
2114 4
            $arrayReturn['length'] += 4;
2115
            //$arrShapeGroup['yTop'] = self::getInt4d($this->streamPowerpointDocument, $pos);
2116 4
            $arrayReturn['length'] += 4;
2117
            //$arrShapeGroup['xRight'] = self::getInt4d($this->streamPowerpointDocument, $pos);
2118 4
            $arrayReturn['length'] += 4;
2119
            //$arrShapeGroup['yBottom'] = self::getInt4d($this->streamPowerpointDocument, $pos);
2120 4
            $arrayReturn['length'] += 4;
2121 4
        }
2122
2123 4
        return $arrayReturn;
2124
    }
2125
2126
    /**
2127
     * The OfficeArtSecondaryFOPT record specifies a table of OfficeArtRGFOPTE records.
2128
     * @param string $stream
2129
     * @param integer $pos
2130
     * @link https://msdn.microsoft.com/en-us/library/dd950259(v=office.12).aspx
2131
     */
2132 4
    private function readRecordOfficeArtSecondaryFOPT($stream, $pos)
2133
    {
2134
        $arrayReturn = array(
2135 4
            'length' => 0,
2136 4
        );
2137
2138 4
        $data = $this->loadRecordHeader($stream, $pos);
2139 4
        if ($data['recVer'] == 0x3 && $data['recType'] == 0xF121) {
2140
            // Record Header
2141
            $arrayReturn['length'] += 8;
2142
            // Length
2143
            $arrayReturn['length'] += $data['recLen'];
2144
        }
2145 4
        return $arrayReturn;
2146
    }
2147
2148
    /**
2149
     * A container record that specifies information about a shape.
2150
     * @param string $stream
2151
     * @param integer $pos
2152
     * @link : https://msdn.microsoft.com/en-us/library/dd950927(v=office.12).aspx
2153
     */
2154 4
    private function readRecordOfficeArtClientData($stream, $pos)
2155
    {
2156
        $arrayReturn = array(
2157 4
            'length' => 0,
2158 4
        );
2159
2160 4
        $data = $this->loadRecordHeader($stream, $pos);
2161 4
        if ($data['recVer'] == 0xF && $data['recInstance'] == 0x000 && $data['recType'] == 0xF011) {
2162
            $arrayReturn['length'] += 8;
2163
            // shapeFlagsAtom (9 bytes)
2164
            $dataShapeFlagsAtom = $this->readRecordShapeFlagsAtom($stream, $pos + $arrayReturn['length']);
2165
            $arrayReturn['length'] += $dataShapeFlagsAtom['length'];
2166
2167
            // shapeFlags10Atom (9 bytes)
2168
            $dataShapeFlags10Atom = $this->readRecordShapeFlags10Atom($stream, $pos + $arrayReturn['length']);
2169
            $arrayReturn['length'] += $dataShapeFlags10Atom['length'];
2170
2171
            // exObjRefAtom (12 bytes)
2172
            $dataExObjRefAtom = $this->readRecordExObjRefAtom($stream, $pos + $arrayReturn['length']);
2173
            $arrayReturn['length'] += $dataExObjRefAtom['length'];
2174
2175
            // animationInfo (variable)
2176
            $dataAnimationInfo = $this->readRecordAnimationInfoContainer($stream, $pos + $arrayReturn['length']);
2177
            $arrayReturn['length'] += $dataAnimationInfo['length'];
2178
2179
            // mouseClickInteractiveInfo (variable)
2180
            $mouseClickInfo = $this->readRecordMouseClickInteractiveInfoContainer($stream, $pos + $arrayReturn['length']);
2181
            $arrayReturn['length'] += $mouseClickInfo['length'];
2182
2183
            // mouseOverInteractiveInfo (variable)
2184
            $mouseOverInfo = $this->readRecordMouseOverInteractiveInfoContainer($stream, $pos + $arrayReturn['length']);
2185
            $arrayReturn['length'] += $mouseOverInfo['length'];
2186
2187
            // placeholderAtom (16 bytes)
2188
            $dataPlaceholderAtom = $this->readRecordPlaceholderAtom($stream, $pos + $arrayReturn['length']);
2189
            $arrayReturn['length'] += $dataPlaceholderAtom['length'];
2190
2191
            // recolorInfoAtom (variable)
2192
            $dataRecolorInfo = $this->readRecordRecolorInfoAtom($stream, $pos + $arrayReturn['length']);
2193
            $arrayReturn['length'] += $dataRecolorInfo['length'];
2194
2195
            // rgShapeClientRoundtripData (variable)
2196
            $array = array(
2197
                self::RT_PROGTAGS,
2198
                self::RT_ROUNDTRIPNEWPLACEHOLDERID12ATOM,
2199
                self::RT_ROUNDTRIPSHAPEID12ATOM,
2200
                self::RT_ROUNDTRIPHFPLACEHOLDER12ATOM,
2201
                self::RT_ROUNDTRIPSHAPECHECKSUMFORCL12ATOM,
2202
            );
2203
            do {
2204
                $dataHeaderRG = $this->loadRecordHeader($stream, $pos + $arrayReturn['length']);
2205
                if (in_array($dataHeaderRG['recType'], $array)) {
2206
                    switch ($dataHeaderRG['recType']) {
2207
                        case self::RT_PROGTAGS:
2208
                            $dataRG = $this->readRecordShapeProgTagsContainer($stream, $pos + $arrayReturn['length']);
2209
                            $arrayReturn['length'] += $dataRG['length'];
2210
                            break;
2211
                        case self::RT_ROUNDTRIPHFPLACEHOLDER12ATOM:
2212
                            $dataRG = $this->readRecordRoundTripHFPlaceholder12Atom($stream, $pos + $arrayReturn['length']);
2213
                            $arrayReturn['length'] += $dataRG['length'];
2214
                            break;
2215
                        case self::RT_ROUNDTRIPSHAPEID12ATOM:
2216
                            $dataRG = $this->readRecordRoundTripShapeId12Atom($stream, $pos + $arrayReturn['length']);
2217
                            $arrayReturn['length'] += $dataRG['length'];
2218
                            break;
2219
                        default:
2220
                            throw new \Exception('Feature not implemented (l.'.__LINE__.' : 0x'.dechex($dataHeaderRG['recType']).')');
2221
                    }
2222
                }
2223
            } while (in_array($dataHeaderRG['recType'], $array));
2224
        }
2225
2226 4
        return $arrayReturn;
2227
    }
2228
2229
    /**
2230
     * An atom record that specifies a persist object directory. Each persist object identifier specified MUST be unique in that persist object directory.
2231
     * @link http://msdn.microsoft.com/en-us/library/dd952680(v=office.12).aspx
2232
     * @param string $stream
2233
     * @param integer $pos
2234
     * @throws \Exception
2235
     */
2236 4
    private function readRecordPersistDirectoryAtom($stream, $pos)
2237
    {
2238 4
        $rHeader = $this->loadRecordHeader($stream, $pos);
2239 4
        $pos += 8;
2240 4
        if ($rHeader['recVer'] != 0x0 || $rHeader['recInstance'] != 0x000 || $rHeader['recType'] != self::RT_PERSISTDIRECTORYATOM) {
2241
            throw new \Exception('File PowerPoint 97 in error (Location : PersistDirectoryAtom > RecordHeader).');
2242
        }
2243
        // rgPersistDirEntry
2244
        // @link : http://msdn.microsoft.com/en-us/library/dd947347(v=office.12).aspx
2245
        do {
2246 4
            $data = self::getInt4d($stream, $pos);
2247 4
            $pos += 4;
2248 4
            $rHeader['recLen'] -= 4;
2249
            //$persistId  = ($data >> 0) & bindec('11111111111111111111');
2250 4
            $cPersist  = ($data >> 20) & bindec('111111111111');
2251
2252 4
            $rgPersistOffset = array();
2253 4
            for ($inc = 0; $inc < $cPersist; $inc++) {
2254 4
                $rgPersistOffset[] = self::getInt4d($stream, $pos);
2255 4
                $pos += 4;
2256 4
                $rHeader['recLen'] -= 4;
2257 4
            }
2258 4
        } while ($rHeader['recLen'] > 0);
2259 4
        $this->rgPersistDirEntry = $rgPersistOffset;
2260 4
    }
2261
2262
    /**
2263
     * A container record that specifies information about the headers (1) and footers within a slide.
2264
     * @param string $stream
2265
     * @param integer $pos
2266
     * @link https://msdn.microsoft.com/en-us/library/dd904856(v=office.12).aspx
2267
     */
2268 4
    private function readRecordPerSlideHeadersFootersContainer($stream, $pos)
2269
    {
2270
        $arrayReturn = array(
2271 4
            'length' => 0,
2272 4
        );
2273
2274 4
        $data = $this->loadRecordHeader($stream, $pos);
2275 4
        if ($data['recVer'] == 0xF && $data['recInstance'] == 0x000 && $data['recType'] == self::RT_HEADERSFOOTERS) {
2276
            // Record Header
2277 4
            $arrayReturn['length'] += 8;
2278
            // Length
2279 4
            $arrayReturn['length'] += $data['recLen'];
2280 4
        }
2281
2282 4
        return $arrayReturn;
2283
    }
2284
2285
    /**
2286
     * An atom record that specifies whether a shape is a placeholder shape.
2287
     * @param string $stream
2288
     * @param integer $pos
2289
     * @link https://msdn.microsoft.com/en-us/library/dd923930(v=office.12).aspx
2290
     */
2291
    private function readRecordPlaceholderAtom($stream, $pos)
2292
    {
2293
        $arrayReturn = array(
2294
            'length' => 0,
2295
        );
2296
2297
        $data = $this->loadRecordHeader($stream, $pos);
2298
        if ($data['recVer'] == 0x0 && $data['recInstance'] == 0x000 && $data['recType'] == self::RT_PLACEHOLDERATOM && $data['recLen'] == 0x00000008) {
2299
            // Record Header
2300
            $arrayReturn['length'] += 8;
2301
            // Datas
2302
            $arrayReturn['length'] += $data['recLen'];
2303
        }
2304
2305
        return $arrayReturn;
2306
    }
2307
2308
    /**
2309
     * An atom record that specifies a collection of re-color mappings for a metafile ([MS-WMF]).
2310
     * @param string $stream
2311
     * @param integer $pos
2312
     * @link https://msdn.microsoft.com/en-us/library/dd904899(v=office.12).aspx
2313
     */
2314
    private function readRecordRecolorInfoAtom($stream, $pos)
2315
    {
2316
        $arrayReturn = array(
2317
            'length' => 0,
2318
        );
2319
2320
        $data = $this->loadRecordHeader($stream, $pos);
2321
        if ($data['recVer'] == 0x0 && $data['recInstance'] == 0x000 && $data['recType'] == self::RT_RECOLORINFOATOM) {
2322
            // Record Header
2323
            $arrayReturn['length'] += 8;
2324
            // Datas
2325
            $arrayReturn['length'] += $data['recLen'];
2326
        }
2327
2328
        return $arrayReturn;
2329
    }
2330
2331
    /**
2332
     * An atom record that specifies that a shape is a header or footerplaceholder shape.
2333
     * @param string $stream
2334
     * @param integer $pos
2335
     * @link https://msdn.microsoft.com/en-us/library/dd910800(v=office.12).aspx
2336
     */
2337
    private function readRecordRoundTripHFPlaceholder12Atom($stream, $pos)
2338
    {
2339
        $arrayReturn = array(
2340
            'length' => 0,
2341
        );
2342
2343
        $data = $this->loadRecordHeader($stream, $pos);
2344
        if ($data['recVer'] == 0x0 && $data['recInstance'] == 0x000 && $data['recType'] == self::RT_ROUNDTRIPHFPLACEHOLDER12ATOM && $data['recLen'] == 0x00000001) {
2345
            // Record Header
2346
            $arrayReturn['length'] += 8;
2347
            // Datas
2348
            $arrayReturn['length'] += $data['recLen'];
2349
        }
2350
2351
        return $arrayReturn;
2352
    }
2353
2354
    /**
2355
     * An atom record that specifies a shape identifier.
2356
     * @param string $stream
2357
     * @param integer $pos
2358
     * @link https://msdn.microsoft.com/en-us/library/dd772926(v=office.12).aspx
2359
     */
2360
    private function readRecordRoundTripShapeId12Atom($stream, $pos)
2361
    {
2362
        $arrayReturn = array(
2363
            'length' => 0,
2364
        );
2365
2366
        $data = $this->loadRecordHeader($stream, $pos);
2367
        if ($data['recVer'] == 0x0 && $data['recInstance'] == 0x000 && $data['recType'] == self::RT_ROUNDTRIPSHAPEID12ATOM && $data['recLen'] == 0x00000004) {
2368
            // Record Header
2369
            $arrayReturn['length'] += 8;
2370
            // Length
2371
            $arrayReturn['length'] += $data['recLen'];
2372
        }
2373
2374
        return $arrayReturn;
2375
    }
2376
2377
    /**
2378
     * A container record that specifies information about a slide that synchronizes to a slide in a slide library.
2379
     * @param string $stream
2380
     * @param integer $pos
2381
     * @link https://msdn.microsoft.com/en-us/library/dd923801(v=office.12).aspx
2382
     */
2383 4
    private function readRecordRoundTripSlideSyncInfo12Container($stream, $pos)
2384
    {
2385
        $arrayReturn = array(
2386 4
            'length' => 0,
2387 4
        );
2388
2389 4
        $data = $this->loadRecordHeader($stream, $pos);
2390 4
        if ($data['recVer'] == 0xF && $data['recInstance'] == 0x000 && $data['recType'] == self::RT_ROUNDTRIPSLIDESYNCINFO12) {
2391
            // Record Header
2392
            $arrayReturn['length'] += 8;
2393
            // Length
2394
            $arrayReturn['length'] += $data['recLen'];
2395
        }
2396
2397 4
        return $arrayReturn;
2398
    }
2399
2400
    /**
2401
     * An atom record that specifies shape-level Boolean flags.
2402
     * @param string $stream
2403
     * @param integer $pos
2404
     * @link https://msdn.microsoft.com/en-us/library/dd908949(v=office.12).aspx
2405
     */
2406
    private function readRecordShapeFlags10Atom($stream, $pos)
2407
    {
2408
        $arrayReturn = array(
2409
            'length' => 0,
2410
        );
2411
2412
        $data = $this->loadRecordHeader($stream, $pos);
2413
        if ($data['recVer'] == 0x0 && $data['recInstance'] == 0x000 && $data['recType'] == self::RT_SHAPEFLAGS10ATOM && $data['recLen'] == 0x00000001) {
2414
            // Record Header
2415
            $arrayReturn['length'] += 8;
2416
            // Datas
2417
            $arrayReturn['length'] += $data['recLen'];
2418
        }
2419
2420
        return $arrayReturn;
2421
    }
2422
2423
    /**
2424
     * An atom record that specifies shape-level Boolean flags.
2425
     * @param string $stream
2426
     * @param integer $pos
2427
     * @link https://msdn.microsoft.com/en-us/library/dd925824(v=office.12).aspx
2428
     */
2429
    private function readRecordShapeFlagsAtom($stream, $pos)
2430
    {
2431
        $arrayReturn = array(
2432
                'length' => 0,
2433
        );
2434
2435
        $data = $this->loadRecordHeader($stream, $pos);
2436
        if ($data['recVer'] == 0x0 && $data['recInstance'] == 0x000 && $data['recType'] == self::RT_SHAPEATOM && $data['recLen'] == 0x00000001) {
2437
            // Record Header
2438
            $arrayReturn['length'] += 8;
2439
            // Datas
2440
            $arrayReturn['length'] += $data['recLen'];
2441
        }
2442
2443
        return $arrayReturn;
2444
    }
2445
2446
    /**
2447
     * A container record that specifies programmable tags with additional binary shape data.
2448
     * @param string $stream
2449
     * @param integer $pos
2450
     * @link https://msdn.microsoft.com/en-us/library/dd911033(v=office.12).aspx
2451
     */
2452
    private function readRecordShapeProgBinaryTagContainer($stream, $pos)
2453
    {
2454
        $arrayReturn = array(
2455
            'length' => 0,
2456
        );
2457
2458
        $data = $this->loadRecordHeader($stream, $pos);
2459
        if ($data['recVer'] == 0xF && $data['recInstance'] == 0x000 && $data['recType'] == self::RT_PROGBINARYTAG) {
2460
            // Record Header
2461
            $arrayReturn['length'] += 8;
2462
            // Datas
2463
            $arrayReturn['length'] += $data['recLen'];
2464
        }
2465
2466
        return $arrayReturn;
2467
    }
2468
2469
    /**
2470
     * A container record that specifies programmable tags with additional shape data.
2471
     * @param string $stream
2472
     * @param integer $pos
2473
     * @link https://msdn.microsoft.com/en-us/library/dd911266(v=office.12).aspx
2474
     */
2475
    private function readRecordShapeProgTagsContainer($stream, $pos)
2476
    {
2477
        $arrayReturn = array(
2478
            'length' => 0,
2479
        );
2480
2481
        $data = $this->loadRecordHeader($stream, $pos);
2482
        if ($data['recVer'] == 0xF && $data['recInstance'] == 0x000 && $data['recType'] == self::RT_PROGTAGS) {
2483
            // Record Header
2484
            $arrayReturn['length'] += 8;
2485
2486
            $length = 0;
2487
            do {
2488
                $dataHeaderRG = $this->loadRecordHeader($stream, $pos + $arrayReturn['length'] + $length);
2489
                switch ($dataHeaderRG['recType']) {
2490
                    case self::RT_PROGBINARYTAG:
2491
                        $dataRG = $this->readRecordShapeProgBinaryTagContainer($stream, $pos + $arrayReturn['length'] + $length);
2492
                        $length += $dataRG['length'];
2493
                        break;
2494
                    //case self::RT_PROGSTRINGTAG:
2495
                    default:
2496
                        throw new \Exception('Feature not implemented (l.'.__LINE__.')');
2497
                }
2498
            } while ($length < $data['recLen']);
2499
            // Datas
2500
            $arrayReturn['length'] += $data['recLen'];
2501
        }
2502
2503
        return $arrayReturn;
2504
    }
2505
2506
    /**
2507
     * An atom record that specifies information about a slide.
2508
     * @param string $stream
2509
     * @param integer $pos
2510
     * @link https://msdn.microsoft.com/en-us/library/dd923801(v=office.12).aspx
2511
     */
2512 4
    private function readRecordSlideAtom($stream, $pos)
2513
    {
2514
        $arrayReturn = array(
2515 4
            'length' => 0,
2516 4
        );
2517
2518 4
        $data = $this->loadRecordHeader($stream, $pos);
2519 4
        if ($data['recVer'] == 0x2 && $data['recInstance'] == 0x000 && $data['recType'] == self::RT_SLIDEATOM) {
2520
            // Record Header
2521 4
            $arrayReturn['length'] += 8;
2522
            // slideAtom > geom
2523 4
            $arrayReturn['length'] += 4;
2524
            // slideAtom > rgPlaceholderTypes
2525 4
            $rgPlaceholderTypes = array();
2526 4
            for ($inc = 0; $inc < 8; $inc++) {
2527 4
                $rgPlaceholderTypes[] = self::getInt1d($this->streamPowerpointDocument, $pos);
2528 4
                $arrayReturn['length'] += 1;
2529 4
            }
2530
2531
            // slideAtom > masterIdRef
2532 4
            $arrayReturn['length'] += 4;
2533
            // slideAtom > notesIdRef
2534 4
            $arrayReturn['length'] += 4;
2535
            // slideAtom > slideFlags
2536 4
            $arrayReturn['length'] += 2;
2537
            // slideAtom > unused;
2538 4
            $arrayReturn['length'] += 2;
2539 4
        }
2540
2541 4
        return $arrayReturn;
2542
    }
2543
2544
    /**
2545
     * A container record that specifies a presentation slide or title master slide.
2546
     * @param string $stream
2547
     * @param int $pos
2548
     * @link http://msdn.microsoft.com/en-us/library/dd946323(v=office.12).aspx
2549
     */
2550 4
    private function readRecordSlideContainer($stream, $pos)
2551
    {
2552
        // Core
2553 4
        $this->oPhpPresentation->createSlide();
2554 4
        $this->oPhpPresentation->setActiveSlideIndex($this->oPhpPresentation->getSlideCount() - 1);
2555
2556
        // *** slideAtom (32 bytes)
2557 4
        $slideAtom = $this->readRecordSlideAtom($stream, $pos);
2558 4
        if ($slideAtom['length'] == 0) {
2559
            throw new \Exception('PowerPoint97 Reader : record SlideAtom');
2560
        }
2561 4
        $pos += $slideAtom['length'];
2562
2563
        // *** slideShowSlideInfoAtom (24 bytes)
2564 4
        $slideShowInfoAtom = $this->readRecordSlideShowSlideInfoAtom($stream, $pos);
2565 4
        $pos += $slideShowInfoAtom['length'];
2566
2567
        // *** perSlideHFContainer (variable) : optional
2568 4
        $perSlideHFContainer = $this->readRecordPerSlideHeadersFootersContainer($stream, $pos);
2569 4
        $pos += $perSlideHFContainer['length'];
2570
2571
        // *** rtSlideSyncInfo12 (variable) : optional
2572 4
        $rtSlideSyncInfo12 = $this->readRecordRoundTripSlideSyncInfo12Container($stream, $pos);
2573 4
        $pos += $rtSlideSyncInfo12['length'];
2574
2575
        // *** drawing (variable)
2576 4
        $drawing = $this->readRecordDrawingContainer($stream, $pos);
2577 4
        $pos += $drawing['length'];
2578
2579
        // *** slideSchemeColorSchemeAtom (40 bytes)
2580 4
        $slideSchemeColorAtom = $this->readRecordSlideSchemeColorSchemeAtom($stream, $pos);
2581 4
        if ($slideSchemeColorAtom['length'] == 0) {
2582
            throw new \Exception('PowerPoint97 Reader : record SlideSchemeColorSchemeAtom');
2583
        }
2584 4
        $pos += $slideSchemeColorAtom['length'];
2585
2586
        // *** slideNameAtom (variable)
2587 4
        $slideNameAtom = $this->readRecordSlideNameAtom($stream, $pos);
2588 4
        $pos += $slideNameAtom['length'];
2589
2590
        // *** slideProgTagsContainer (variable).
2591 4
        $slideProgTags = $this->readRecordSlideProgTagsContainer($stream, $pos);
2592 4
        $pos += $slideProgTags['length'];
2593
2594
        // *** rgRoundTripSlide (variable)
2595 4
    }
2596
2597
    /**
2598
     * An atom record that specifies the name of a slide.
2599
     * @param string $stream
2600
     * @param integer $pos
2601
     * @link https://msdn.microsoft.com/en-us/library/dd906297(v=office.12).aspx
2602
     */
2603 4
    private function readRecordSlideNameAtom($stream, $pos)
2604
    {
2605
        $arrayReturn = array(
2606 4
            'length' => 0,
2607 4
            'slideName' => '',
2608 4
        );
2609
2610 4
        $data = $this->loadRecordHeader($stream, $pos);
2611 4
        if ($data['recVer'] == 0x0 && $data['recInstance'] == 0x003 && $data['recType'] == self::RT_CSTRING && $data['recLen'] % 2 == 0) {
2612
            // Record Header
2613
            $arrayReturn['length'] += 8;
2614
            // Length
2615
            $strLen = ($data['recLen'] / 2);
2616
            for ($inc = 0; $inc < $strLen; $inc++) {
2617
                $char = self::getInt2d($stream, $pos + $arrayReturn['length']);
2618
                $arrayReturn['length'] += 2;
2619
                $arrayReturn['slideName'] .= Text::chr($char);
2620
            }
2621
        }
2622
2623 4
        return $arrayReturn;
2624
    }
2625
2626
    /**
2627
     * An atom record that specifies a slide number metacharacter.
2628
     * @param string $stream
2629
     * @param integer $pos
2630
     * @link https://msdn.microsoft.com/en-us/library/dd945703(v=office.12).aspx
2631
     */
2632
    private function readRecordSlideNumberMCAtom($stream, $pos)
2633
    {
2634
        $arrayReturn = array(
2635
            'length' => 0,
2636
        );
2637
2638
        $data = $this->loadRecordHeader($stream, $pos);
2639
        if ($data['recVer'] == 0x0 && $data['recInstance'] == 0x000 && $data['recType'] == self::RT_SLIDENUMBERMETACHARATOM && $data['recLen'] == 0x00000004) {
2640
            // Record Header
2641
            $arrayReturn['length'] += 8;
2642
            // Datas
2643
            $arrayReturn['length'] += $data['recLen'];
2644
        }
2645
2646
        return $arrayReturn;
2647
    }
2648
2649
2650
2651
    /**
2652
     * A container record that specifies programmable tags with additional slide data.
2653
     * @param string $stream
2654
     * @param integer $pos
2655
     * @link https://msdn.microsoft.com/en-us/library/dd951946(v=office.12).aspx
2656
     */
2657 4
    private function readRecordSlideProgTagsContainer($stream, $pos)
2658
    {
2659
        $arrayReturn = array(
2660 4
            'length' => 0,
2661 4
        );
2662
2663 4
        $data = $this->loadRecordHeader($stream, $pos);
2664 4
        if ($data['recVer'] == 0xF && $data['recInstance'] == 0x000 && $data['recType'] == self::RT_PROGTAGS) {
2665
            // Record Header
2666 4
            $arrayReturn['length'] += 8;
2667
            // Length
2668 4
            $arrayReturn['length'] += $data['recLen'];
2669 4
        }
2670
2671 4
        return $arrayReturn;
2672
    }
2673
2674
    /**
2675
     * A container record that specifies the color scheme used by a slide.
2676
     * @param string $stream
2677
     * @param integer $pos
2678
     * @link https://msdn.microsoft.com/en-us/library/dd949420(v=office.12).aspx
2679
     */
2680 4
    private function readRecordSlideSchemeColorSchemeAtom($stream, $pos)
2681
    {
2682
        $arrayReturn = array(
2683 4
            'length' => 0,
2684 4
        );
2685
2686 4
        $data = $this->loadRecordHeader($stream, $pos);
2687 4
        if ($data['recVer'] == 0x0 && $data['recInstance'] == 0x001 && $data['recType'] == self::RT_COLORSCHEMEATOM && $data['recLen'] == 0x00000020) {
2688
            // Record Header
2689 4
            $arrayReturn['length'] += 8;
2690
            // Length
2691 4
            $rgSchemeColor = array();
2692 4
            for ($inc = 0; $inc <= 7; $inc++) {
2693 4
                $rgSchemeColor[] = array(
2694 4
                    'red' => self::getInt1d($stream, $pos + $arrayReturn['length'] + $inc * 4),
2695 4
                    'green' => self::getInt1d($stream, $pos + $arrayReturn['length'] + $inc * 4 + 1),
2696 4
                    'blue' => self::getInt1d($stream, $pos + $arrayReturn['length'] + $inc * 4 + 2),
2697
                );
2698 4
            }
2699 4
            $arrayReturn['length'] += (8 * 4);
2700 4
        }
2701
2702 4
        return $arrayReturn;
2703
    }
2704
2705
    /**
2706
     * An atom record that specifies what transition effect to perform during a slide show, and how to advance to the next presentation slide.
2707
     * @param string $stream
2708
     * @param integer $pos
2709
     * @link https://msdn.microsoft.com/en-us/library/dd943408(v=office.12).aspx
2710
     */
2711 4
    private function readRecordSlideShowSlideInfoAtom($stream, $pos)
2712
    {
2713
        $arrayReturn = array(
2714 4
            'length' => 0,
2715 4
        );
2716
2717 4
        $data = $this->loadRecordHeader($stream, $pos);
2718 4
        if ($data['recVer'] == 0x0 && $data['recInstance'] == 0x000 && $data['recType'] == self::RT_SLIDESHOWSLIDEINFOATOM && $data['recLen'] == 0x00000010) {
2719
            // Record Header
2720 4
            $arrayReturn['length'] += 8;
2721
            // Length;
2722 4
            $arrayReturn['length'] += $data['recLen'];
2723 4
        }
2724
2725 4
        return $arrayReturn;
2726
    }
2727
2728
    /**
2729
     * UserEditAtom
2730
     * @link http://msdn.microsoft.com/en-us/library/dd945746(v=office.12).aspx
2731
     * @param string $stream
2732
     * @param integer $pos
2733
     * @throws \Exception
2734
     */
2735 4
    private function readRecordUserEditAtom($stream, $pos)
2736
    {
2737 4
        $rHeader = $this->loadRecordHeader($stream, $pos);
2738 4
        $pos += 8;
2739 4
        if ($rHeader['recVer'] != 0x0 || $rHeader['recInstance'] != 0x000 || $rHeader['recType'] != self::RT_USEREDITATOM || ($rHeader['recLen'] != 0x0000001C && $rHeader['recLen'] != 0x00000020)) {
2740
            throw new \Exception('File PowerPoint 97 in error (Location : UserEditAtom > RecordHeader).');
2741
        }
2742
2743
        // lastSlideIdRef
2744 4
        $pos += 4;
2745
        // version
2746 4
        $pos += 2;
2747
2748
        // minorVersion
2749 4
        $minorVersion = self::getInt1d($stream, $pos);
2750 4
        $pos += 1;
2751 4
        if ($minorVersion != 0x00) {
2752
            throw new \Exception('File PowerPoint 97 in error (Location : UserEditAtom > minorVersion).');
2753
        }
2754
2755
        // majorVersion
2756 4
        $majorVersion = self::getInt1d($stream, $pos);
2757 4
        $pos += 1;
2758 4
        if ($majorVersion != 0x03) {
2759
            throw new \Exception('File PowerPoint 97 in error (Location : UserEditAtom > majorVersion).');
2760
        }
2761
2762
        // offsetLastEdit
2763 4
        $pos += 4;
2764
        // offsetPersistDirectory
2765 4
        $this->offsetPersistDirectory = self::getInt4d($stream, $pos);
2766 4
        $pos += 4;
2767
2768
        // docPersistIdRef
2769 4
        $docPersistIdRef  = self::getInt4d($stream, $pos);
2770 4
        $pos += 4;
2771 4
        if ($docPersistIdRef != 0x00000001) {
2772
            throw new \Exception('File PowerPoint 97 in error (Location : UserEditAtom > docPersistIdRef).');
2773
        }
2774
2775
        // persistIdSeed
2776 4
        $pos += 4;
2777
        // lastView
2778 4
        $pos += 2;
2779
        // unused
2780 4
        $pos += 2;
2781 4
    }
2782
2783
    /**
2784
     * A structure that specifies the character-level formatting of a run of text.
2785
     * @param string $stream
2786
     * @param int $pos
2787
     * @param int $strLenRT
2788
     * @link https://msdn.microsoft.com/en-us/library/dd945870(v=office.12).aspx
2789
     */
2790 3
    private function readStructureTextCFRun($stream, $pos, $strLenRT)
2791
    {
2792
        $arrayReturn = array(
2793 3
            'length' => 0,
2794 3
            'strLenRT' => $strLenRT,
2795 3
        );
2796
2797
        // rgTextCFRun
2798 3
        $countRgTextCFRun = self::getInt4d($stream, $pos + $arrayReturn['length']);
2799 3
        $arrayReturn['strLenRT'] -= $countRgTextCFRun;
2800 3
        $arrayReturn['length'] += 4;
2801 3
        $arrayReturn['partLength'] = $countRgTextCFRun;
2802
2803 3
        $masks = self::getInt4d($stream, $pos + $arrayReturn['length']);
2804 3
        $arrayReturn['length'] += 4;
2805
2806 3
        $masksData = array();
2807 3
        $masksData['bold'] = ($masks >> 0) & bindec('1');
2808 3
        $masksData['italic'] = ($masks >> 1) & bindec('1');
2809 3
        $masksData['underline'] = ($masks >> 2) & bindec('1');
2810 3
        $masksData['unused1'] = ($masks >> 3) & bindec('1');
2811 3
        $masksData['shadow'] = ($masks >> 4) & bindec('1');
2812 3
        $masksData['fehint'] = ($masks >> 5) & bindec('1');
2813 3
        $masksData['unused2'] = ($masks >> 6) & bindec('1');
2814 3
        $masksData['kumi'] = ($masks >> 7) & bindec('1');
2815 3
        $masksData['unused3'] = ($masks >> 8) & bindec('1');
2816 3
        $masksData['emboss'] = ($masks >> 9) & bindec('1');
2817 3
        $masksData['fHasStyle'] = ($masks >> 10) & bindec('1111');
2818 3
        $masksData['unused4'] = ($masks >> 14) & bindec('11');
2819 3
        $masksData['typeface'] = ($masks >> 16) & bindec('1');
2820 3
        $masksData['size'] = ($masks >> 17) & bindec('1');
2821 3
        $masksData['color'] = ($masks >> 18) & bindec('1');
2822 3
        $masksData['position'] = ($masks >> 19) & bindec('1');
2823 3
        $masksData['pp10ext'] = ($masks >> 20) & bindec('1');
2824 3
        $masksData['oldEATypeface'] = ($masks >> 21) & bindec('1');
2825 3
        $masksData['ansiTypeface'] = ($masks >> 22) & bindec('1');
2826 3
        $masksData['symbolTypeface'] = ($masks >> 23) & bindec('1');
2827 3
        $masksData['newEATypeface'] = ($masks >> 24) & bindec('1');
2828 3
        $masksData['csTypeface'] = ($masks >> 25) & bindec('1');
2829 3
        $masksData['pp11ext'] = ($masks >> 26) & bindec('1');
2830 3
        if ($masksData['bold'] == 1 || $masksData['italic'] == 1 || $masksData['underline'] == 1 || $masksData['shadow'] == 1 || $masksData['fehint'] == 1 ||  $masksData['kumi'] == 1 ||  $masksData['emboss'] == 1 ||  $masksData['fHasStyle'] == 1) {
2831 3
            $data = self::getInt2d($stream, $pos + $arrayReturn['length']);
2832 3
            $arrayReturn['length'] += 2;
2833
2834 3
            $fontStyleFlags = array();
2835 3
            $fontStyleFlags['bold'] = ($data >> 0) & bindec('1');
2836 3
            $fontStyleFlags['italic'] = ($data >> 1) & bindec('1');
2837 3
            $fontStyleFlags['underline'] = ($data >> 2) & bindec('1');
2838 3
            $fontStyleFlags['unused1'] = ($data >> 3) & bindec('1');
2839 3
            $fontStyleFlags['shadow'] = ($data >> 4) & bindec('1');
2840 3
            $fontStyleFlags['fehint'] = ($data >> 5) & bindec('1');
2841 3
            $fontStyleFlags['unused2'] = ($data >> 6) & bindec('1');
2842 3
            $fontStyleFlags['kumi'] = ($data >> 7) & bindec('1');
2843 3
            $fontStyleFlags['unused3'] = ($data >> 8) & bindec('1');
2844 3
            $fontStyleFlags['emboss'] = ($data >> 9) & bindec('1');
2845 3
            $fontStyleFlags['pp9rt'] = ($data >> 10) & bindec('1111');
2846 3
            $fontStyleFlags['unused4'] = ($data >> 14) & bindec('11');
2847
2848 3
            $arrayReturn['bold'] = ($fontStyleFlags['bold'] == 1) ? true : false;
2849 3
            $arrayReturn['italic'] = ($fontStyleFlags['italic'] == 1) ? true : false;
2850 3
            $arrayReturn['underline'] = ($fontStyleFlags['underline'] == 1) ? true : false;
2851 3
        }
2852 3
        if ($masksData['typeface'] == 1) {
2853 3
            $data = self::getInt2d($stream, $pos + $arrayReturn['length']);
2854 3
            $arrayReturn['length'] += 2;
2855 3
            $arrayReturn['fontName'] = isset($this->arrayFonts[$data]) ? $this->arrayFonts[$data] : '';
2856 3
        }
2857 3
        if ($masksData['oldEATypeface'] == 1) {
2858
            // $data = self::getInt2d($stream, $pos + $arrayReturn['length']);
2859
            $arrayReturn['length'] += 2;
2860
        }
2861 3
        if ($masksData['ansiTypeface'] == 1) {
2862
            // $data = self::getInt2d($stream, $pos + $arrayReturn['length']);
2863
            $arrayReturn['length'] += 2;
2864
        }
2865 3
        if ($masksData['symbolTypeface'] == 1) {
2866
            // $data = self::getInt2d($stream, $pos + $arrayReturn['length']);
2867
            $arrayReturn['length'] += 2;
2868
        }
2869 3
        if ($masksData['size'] == 1) {
2870 3
            $arrayReturn['fontSize'] = self::getInt2d($stream, $pos + $arrayReturn['length']);
2871 3
            $arrayReturn['length'] += 2;
2872 3
        }
2873 3
        if ($masksData['color'] == 1) {
2874 3
            $red = self::getInt1d($stream, $pos + $arrayReturn['length']);
2875 3
            $arrayReturn['length'] += 1;
2876 3
            $green = self::getInt1d($stream, $pos + $arrayReturn['length']);
2877 3
            $arrayReturn['length'] += 1;
2878 3
            $blue = self::getInt1d($stream, $pos + $arrayReturn['length']);
2879 3
            $arrayReturn['length'] += 1;
2880 3
            $index = self::getInt1d($stream, $pos + $arrayReturn['length']);
2881 3
            $arrayReturn['length'] += 1;
2882
2883 3
            if ($index == 0xFE) {
2884 3
                $strColor = str_pad(dechex($red), 2, STR_PAD_LEFT, '0');
2885 3
                $strColor .= str_pad(dechex($green), 2, STR_PAD_LEFT, '0');
2886 3
                $strColor .= str_pad(dechex($blue), 2, STR_PAD_LEFT, '0');
2887
2888 3
                $arrayReturn['color'] = new Color('FF'.$strColor);
2889 3
            }
2890 3
        }
2891 3
        if ($masksData['position'] == 1) {
2892
            throw new \Exception('Feature not implemented (l.'.__LINE__.')');
2893
        }
2894
2895 3
        return $arrayReturn;
2896
    }
2897
2898
    /**
2899
     * A structure that specifies the paragraph-level formatting of a run of text.
2900
     * @param string $stream
2901
     * @param integer $pos
2902
     * @link https://msdn.microsoft.com/en-us/library/dd923535(v=office.12).aspx
2903
     */
2904 3
    private function readStructureTextPFRun($stream, $pos, $strLenRT)
2905
    {
2906
        $arrayReturn = array(
2907 3
            'length' => 0,
2908 3
            'strLenRT' => $strLenRT,
2909 3
        );
2910
2911
        // rgTextPFRun
2912 3
        $countRgTextPFRun = self::getInt4d($stream, $pos + $arrayReturn['length']);
2913 3
        $arrayReturn['strLenRT'] -= $countRgTextPFRun;
2914 3
        $arrayReturn['length'] += 4;
2915
2916
        // indent
2917 3
        $arrayReturn['length'] += 2;
2918
2919 3
        $masks = self::getInt4d($stream, $pos + $arrayReturn['length']);
2920 3
        $arrayReturn['length'] += 4;
2921
2922 3
        $masksData = array();
2923 3
        $masksData['hasBullet'] = ($masks >> 0) & bindec('1');
2924 3
        $masksData['bulletHasFont'] = ($masks >> 1) & bindec('1');
2925 3
        $masksData['bulletHasColor'] = ($masks >> 2) & bindec('1');
2926 3
        $masksData['bulletHasSize'] = ($masks >> 3) & bindec('1');
2927 3
        $masksData['bulletFont'] = ($masks >> 4) & bindec('1');
2928 3
        $masksData['bulletColor'] = ($masks >> 5) & bindec('1');
2929 3
        $masksData['bulletSize'] = ($masks >> 6) & bindec('1');
2930 3
        $masksData['bulletChar'] = ($masks >> 7) & bindec('1');
2931 3
        $masksData['leftMargin'] = ($masks >> 8) & bindec('1');
2932 3
        $masksData['unused'] = ($masks >> 9) & bindec('1');
2933 3
        $masksData['indent'] = ($masks >> 10) & bindec('1');
2934 3
        $masksData['align'] = ($masks >> 11) & bindec('1');
2935 3
        $masksData['lineSpacing'] = ($masks >> 12) & bindec('1');
2936 3
        $masksData['spaceBefore'] = ($masks >> 13) & bindec('1');
2937 3
        $masksData['spaceAfter'] = ($masks >> 14) & bindec('1');
2938 3
        $masksData['defaultTabSize'] = ($masks >> 15) & bindec('1');
2939 3
        $masksData['fontAlign'] = ($masks >> 16) & bindec('1');
2940 3
        $masksData['charWrap'] = ($masks >> 17) & bindec('1');
2941 3
        $masksData['wordWrap'] = ($masks >> 18) & bindec('1');
2942 3
        $masksData['overflow'] = ($masks >> 19) & bindec('1');
2943 3
        $masksData['tabStops'] = ($masks >> 20) & bindec('1');
2944 3
        $masksData['textDirection'] = ($masks >> 21) & bindec('1');
2945 3
        $masksData['reserved1'] = ($masks >> 22) & bindec('1');
2946 3
        $masksData['bulletBlip'] = ($masks >> 23) & bindec('1');
2947 3
        $masksData['bulletScheme'] = ($masks >> 24) & bindec('1');
2948 3
        $masksData['bulletHasScheme'] = ($masks >> 25) & bindec('1');
2949
2950 3
        $bulletFlags = array();
2951 3
        if ($masksData['hasBullet'] == 1 || $masksData['bulletHasFont'] == 1  || $masksData['bulletHasColor'] == 1  || $masksData['bulletHasSize'] == 1) {
2952 3
            $data = self::getInt2d($stream, $pos + $arrayReturn['length']);
2953 3
            $arrayReturn['length'] += 2;
2954
2955 3
            $bulletFlags['fHasBullet'] = ($data >> 0) & bindec('1');
2956 3
            $bulletFlags['fBulletHasFont'] = ($data >> 1) & bindec('1');
2957 3
            $bulletFlags['fBulletHasColor'] = ($data >> 2) & bindec('1');
2958 3
            $bulletFlags['fBulletHasSize'] = ($data >> 3) & bindec('1');
2959 3
        }
2960 3
        if ($masksData['bulletChar'] == 1) {
2961 1
            $data = self::getInt2d($stream, $pos + $arrayReturn['length']);
2962 1
            $arrayReturn['length'] += 2;
2963 1
            $arrayReturn['bulletChar'] = chr($data);
2964 1
        }
2965 3
        if ($masksData['bulletFont'] == 1) {
2966
            // $data = self::getInt2d($stream, $pos);
2967 1
            $arrayReturn['length'] += 2;
2968 1
        }
2969 3
        if ($masksData['bulletSize'] == 1) {
2970
            // $data = self::getInt2d($stream, $pos);
2971 2
            $arrayReturn['length'] += 2;
2972 2
        }
2973 3
        if ($masksData['bulletColor'] == 1) {
2974 1
            $red = self::getInt1d($stream, $pos + $arrayReturn['length']);
2975 1
            $arrayReturn['length'] += 1;
2976 1
            $green = self::getInt1d($stream, $pos + $arrayReturn['length']);
2977 1
            $arrayReturn['length'] += 1;
2978 1
            $blue = self::getInt1d($stream, $pos + $arrayReturn['length']);
2979 1
            $arrayReturn['length'] += 1;
2980 1
            $index = self::getInt1d($stream, $pos + $arrayReturn['length']);
2981 1
            $arrayReturn['length'] += 1;
2982
2983 1
            if ($index == 0xFE) {
2984 1
                $strColor = str_pad(dechex($red), 2, STR_PAD_LEFT, '0');
2985 1
                $strColor .= str_pad(dechex($green), 2, STR_PAD_LEFT, '0');
2986 1
                $strColor .= str_pad(dechex($blue), 2, STR_PAD_LEFT, '0');
2987 1
            }
2988 1
        }
2989 3
        if ($masksData['align'] == 1) {
2990 3
            $data = self::getInt2d($stream, $pos + $arrayReturn['length']);
2991 3
            $arrayReturn['length'] += 2;
2992
            switch ($data) {
2993 3
                case 0x0000:
2994 1
                    $arrayReturn['alignH'] = Alignment::HORIZONTAL_LEFT;
2995 1
                    break;
2996 2
                case 0x0001:
2997 2
                    $arrayReturn['alignH'] = Alignment::HORIZONTAL_CENTER;
2998 2
                    break;
2999
                case 0x0002:
3000
                    $arrayReturn['alignH'] = Alignment::HORIZONTAL_RIGHT;
3001
                    break;
3002
                case 0x0003:
3003
                    $arrayReturn['alignH'] = Alignment::HORIZONTAL_JUSTIFY;
3004
                    break;
3005
                case 0x0004:
3006
                    $arrayReturn['alignH'] = Alignment::HORIZONTAL_DISTRIBUTED;
3007
                    break;
3008
                case 0x0005:
3009
                    $arrayReturn['alignH'] = Alignment::HORIZONTAL_DISTRIBUTED;
3010
                    break;
3011
                case 0x0006:
3012
                    $arrayReturn['alignH'] = Alignment::HORIZONTAL_JUSTIFY;
3013
                    break;
3014
                default:
3015
                    break;
3016
            }
3017 3
        }
3018 3
        if ($masksData['lineSpacing'] == 1) {
3019
            // $data = self::getInt2d($stream, $pos + $arrayReturn['length']);
3020 3
            $arrayReturn['length'] += 2;
3021 3
        }
3022 3
        if ($masksData['spaceBefore'] == 1) {
3023
            // $data = self::getInt2d($stream, $pos + $arrayReturn['length']);
3024 2
            $arrayReturn['length'] += 2;
3025 2
        }
3026 3
        if ($masksData['spaceAfter'] == 1) {
3027
            // $data = self::getInt2d($stream, $pos + $arrayReturn['length']);
3028 2
            $arrayReturn['length'] += 2;
3029 2
        }
3030 3
        if ($masksData['leftMargin'] == 1) {
3031 1
            $data = self::getInt2d($stream, $pos + $arrayReturn['length']);
3032 1
            $arrayReturn['length'] += 2;
3033 1
            $arrayReturn['leftMargin'] = (int)round($data/6);
3034 1
        }
3035 3
        if ($masksData['indent'] == 1) {
3036 1
            $data = self::getInt2d($stream, $pos + $arrayReturn['length']);
3037 1
            $arrayReturn['length'] += 2;
3038 1
            $arrayReturn['indent'] = (int)round($data/6);
3039 1
        }
3040 3
        if ($masksData['defaultTabSize'] == 1) {
3041
            // $data = self::getInt2d($stream, $pos + $arrayReturn['length']);
3042
            $arrayReturn['length'] += 2;
3043
        }
3044 3
        if ($masksData['tabStops'] == 1) {
3045
            throw new \Exception('Feature not implemented (l.'.__LINE__.')');
3046
        }
3047 3
        if ($masksData['fontAlign'] == 1) {
3048
            // $data = self::getInt2d($stream, $pos + $arrayReturn['length']);
3049
            $arrayReturn['length'] += 2;
3050
        }
3051 3
        if ($masksData['charWrap'] == 1 || $masksData['wordWrap'] == 1 || $masksData['overflow'] == 1) {
3052
            // $data = self::getInt2d($stream, $pos + $arrayReturn['length']);
3053 3
            $arrayReturn['length'] += 2;
3054 3
        }
3055 3
        if ($masksData['textDirection'] == 1) {
3056
            throw new \Exception('Feature not implemented (l.'.__LINE__.')');
3057
        }
3058
3059 3
        return $arrayReturn;
3060
    }
3061
3062
3063
    /**
3064
     * A structure that specifies language and spelling information for a run of text.
3065
     * @param string $stream
3066
     * @param integer $pos
3067
     * @link https://msdn.microsoft.com/en-us/library/dd909603(v=office.12).aspx
3068
     */
3069 3
    private function readStructureTextSIRun($stream, $pos, $strLenRT)
3070
    {
3071
        $arrayReturn = array(
3072 3
            'length' => 0,
3073 3
            'strLenRT' => $strLenRT,
3074 3
        );
3075
3076 3
        $arrayReturn['strLenRT'] -= self::getInt4d($stream, $pos + $arrayReturn['length']);
3077 3
        $arrayReturn['length'] += 4;
3078
3079 3
        $data = self::getInt4d($stream, $pos + $arrayReturn['length']);
3080 3
        $arrayReturn['length'] += 4;
3081 3
        $masksData = array();
3082 3
        $masksData['spell'] = ($data >> 0) & bindec('1');
3083 3
        $masksData['lang'] = ($data >> 1) & bindec('1');
3084 3
        $masksData['altLang'] = ($data >> 2) & bindec('1');
3085 3
        $masksData['unused1'] = ($data >> 3) & bindec('1');
3086 3
        $masksData['unused2'] = ($data >> 4) & bindec('1');
3087 3
        $masksData['fPp10ext'] = ($data >> 5) & bindec('1');
3088 3
        $masksData['fBidi'] = ($data >> 6) & bindec('1');
3089 3
        $masksData['unused3'] = ($data >> 7) & bindec('1');
3090 3
        $masksData['reserved1'] = ($data >> 8) & bindec('1');
3091 3
        $masksData['smartTag'] = ($data >> 9) & bindec('1');
3092
3093 3
        if ($masksData['spell'] == 1) {
3094 3
            $data = self::getInt2d($stream, $pos + $arrayReturn['length']);
3095 3
            $arrayReturn['length'] += 2;
3096 3
            $masksSpell = array();
3097 3
            $masksSpell['error'] = ($data >> 0) & bindec('1');
3098 3
            $masksSpell['clean'] = ($data >> 1) & bindec('1');
3099 3
            $masksSpell['grammar'] = ($data >> 2) & bindec('1');
3100 3
        }
3101 3
        if ($masksData['lang'] == 1) {
3102
            // $data = self::getInt2d($stream, $pos);
3103 3
            $arrayReturn['length'] += 2;
3104 3
        }
3105 3
        if ($masksData['altLang'] == 1) {
3106
            // $data = self::getInt2d($stream, $pos);
3107 3
            $arrayReturn['length'] += 2;
3108 3
        }
3109 3
        if ($masksData['fBidi'] == 1) {
3110
            throw new \Exception('Feature not implemented (l.'.__LINE__.')');
3111
        }
3112 3
        if ($masksData['fPp10ext'] == 1) {
3113
            throw new \Exception('Feature not implemented (l.'.__LINE__.')');
3114
        }
3115 3
        if ($masksData['smartTag'] == 1) {
3116
            throw new \Exception('Feature not implemented (l.'.__LINE__.')');
3117
        }
3118
3119 3
        return $arrayReturn;
3120
    }
3121
3122
    /**
3123
     * A structure that specifies tabbing, margins, and indentation for text.
3124
     * @param string $stream
3125
     * @param integer $pos
3126
     * @link https://msdn.microsoft.com/en-us/library/dd922749(v=office.12).aspx
3127
     */
3128 3
    private function readStructureTextRuler($stream, $pos)
3129
    {
3130
        $arrayReturn = array(
3131 3
            'length' => 0,
3132 3
        );
3133
3134 3
        $data = self::getInt4d($stream, $pos + $arrayReturn['length']);
3135 3
        $arrayReturn['length'] += 4;
3136
3137 3
        $masksData = array();
3138 3
        $masksData['fDefaultTabSize'] = ($data >> 0) & bindec('1');
3139 3
        $masksData['fCLevels'] = ($data >> 1) & bindec('1');
3140 3
        $masksData['fTabStops'] = ($data >> 2) & bindec('1');
3141 3
        $masksData['fLeftMargin1'] = ($data >> 3) & bindec('1');
3142 3
        $masksData['fLeftMargin2'] = ($data >> 4) & bindec('1');
3143 3
        $masksData['fLeftMargin3'] = ($data >> 5) & bindec('1');
3144 3
        $masksData['fLeftMargin4'] = ($data >> 6) & bindec('1');
3145 3
        $masksData['fLeftMargin5'] = ($data >> 7) & bindec('1');
3146 3
        $masksData['fIndent1'] = ($data >> 8) & bindec('1');
3147 3
        $masksData['fIndent2'] = ($data >> 9) & bindec('1');
3148 3
        $masksData['fIndent3'] = ($data >> 10) & bindec('1');
3149 3
        $masksData['fIndent4'] = ($data >> 11) & bindec('1');
3150 3
        $masksData['fIndent5'] = ($data >> 12) & bindec('1');
3151
3152 3
        if ($masksData['fCLevels'] == 1) {
3153
            throw new \Exception('Feature not implemented (l.'.__LINE__.')');
3154
        }
3155 3
        if ($masksData['fDefaultTabSize'] == 1) {
3156
            throw new \Exception('Feature not implemented (l.'.__LINE__.')');
3157
        }
3158 3
        if ($masksData['fTabStops'] == 1) {
3159 3
            $count = self::getInt2d($stream, $pos + $arrayReturn['length']);
3160 3
            $arrayReturn['length'] += 2;
3161 3
            $arrayTabStops = array();
3162 3
            for ($inc = 0; $inc < $count; $inc++) {
3163 3
                $position = self::getInt2d($stream, $pos + $arrayReturn['length']);
3164 3
                $arrayReturn['length'] += 2;
3165 3
                $type = self::getInt2d($stream, $pos + $arrayReturn['length']);
3166 3
                $arrayReturn['length'] += 2;
3167 3
                $arrayTabStops[] = array(
3168 3
                    'position' => $position,
3169 3
                    'type' => $type,
3170
                );
3171 3
            }
3172 3
        }
3173 3
        if ($masksData['fLeftMargin1'] == 1) {
3174
            // $data = self::getInt2d($stream, $pos + $arrayReturn['length']);
3175 1
            $arrayReturn['length'] += 2;
3176 1
        }
3177 3
        if ($masksData['fIndent1'] == 1) {
3178
            // $data = self::getInt2d($stream, $pos + $arrayReturn['length']);
3179 1
            $arrayReturn['length'] += 2;
3180 1
        }
3181 3
        if ($masksData['fLeftMargin2'] == 1) {
3182
            // $data = self::getInt2d($stream, $pos + $arrayReturn['length']);
3183 1
            $arrayReturn['length'] += 2;
3184 1
        }
3185 3
        if ($masksData['fIndent2'] == 1) {
3186
            // $data = self::getInt2d($stream, $pos + $arrayReturn['length']);
3187 1
            $arrayReturn['length'] += 2;
3188 1
        }
3189 3
        if ($masksData['fLeftMargin3'] == 1) {
3190
            // $data = self::getInt2d($stream, $pos + $arrayReturn['length']);
3191
            $arrayReturn['length'] += 2;
3192
        }
3193 3
        if ($masksData['fIndent3'] == 1) {
3194
            // $data = self::getInt2d($stream, $pos + $arrayReturn['length']);
3195
            $arrayReturn['length'] += 2;
3196
        }
3197 3
        if ($masksData['fLeftMargin4'] == 1) {
3198
            // $data = self::getInt2d($stream, $pos + $arrayReturn['length']);
3199
            $arrayReturn['length'] += 2;
3200
        }
3201 3
        if ($masksData['fIndent4'] == 1) {
3202
            // $data = self::getInt2d($stream, $pos + $arrayReturn['length']);
3203
            $arrayReturn['length'] += 2;
3204
        }
3205 3
        if ($masksData['fLeftMargin5'] == 1) {
3206
            // $data = self::getInt2d($stream, $pos + $arrayReturn['length']);
3207
            $arrayReturn['length'] += 2;
3208
        }
3209 3
        if ($masksData['fIndent5'] == 1) {
3210
            // $data = self::getInt2d($stream, $pos + $arrayReturn['length']);
3211
            $arrayReturn['length'] += 2;
3212
        }
3213
3214 3
        return $arrayReturn;
3215
    }
3216
}
3217