Completed
Pull Request — develop (#207)
by Franck
09:22
created

PowerPoint97::readRecordSlideNumberMCAtom()   B

Complexity

Conditions 5
Paths 2

Size

Total Lines 16
Code Lines 8

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 30

Importance

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