1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace PhpOffice\PhpSpreadsheet\Reader\Xls; |
4
|
|
|
|
5
|
|
|
/** |
6
|
|
|
* Copyright (c) 2006 - 2016 PhpSpreadsheet |
7
|
|
|
* |
8
|
|
|
* This library is free software; you can redistribute it and/or |
9
|
|
|
* modify it under the terms of the GNU Lesser General Public |
10
|
|
|
* License as published by the Free Software Foundation; either |
11
|
|
|
* version 2.1 of the License, or (at your option) any later version. |
12
|
|
|
* |
13
|
|
|
* This library is distributed in the hope that it will be useful, |
14
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
15
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
16
|
|
|
* Lesser General Public License for more details. |
17
|
|
|
* |
18
|
|
|
* You should have received a copy of the GNU Lesser General Public |
19
|
|
|
* License along with this library; if not, write to the Free Software |
20
|
|
|
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA |
21
|
|
|
* |
22
|
|
|
* @category PhpSpreadsheet |
23
|
|
|
* @copyright Copyright (c) 2006 - 2016 PhpSpreadsheet (https://github.com/PHPOffice/PhpSpreadsheet) |
24
|
|
|
* @license http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt LGPL |
25
|
|
|
* @version ##VERSION##, ##DATE## |
26
|
|
|
*/ |
27
|
|
|
class Escher |
28
|
|
|
{ |
29
|
|
|
const DGGCONTAINER = 0xF000; |
30
|
|
|
const BSTORECONTAINER = 0xF001; |
31
|
|
|
const DGCONTAINER = 0xF002; |
32
|
|
|
const SPGRCONTAINER = 0xF003; |
33
|
|
|
const SPCONTAINER = 0xF004; |
34
|
|
|
const DGG = 0xF006; |
35
|
|
|
const BSE = 0xF007; |
36
|
|
|
const DG = 0xF008; |
37
|
|
|
const SPGR = 0xF009; |
38
|
|
|
const SP = 0xF00A; |
39
|
|
|
const OPT = 0xF00B; |
40
|
|
|
const CLIENTTEXTBOX = 0xF00D; |
41
|
|
|
const CLIENTANCHOR = 0xF010; |
42
|
|
|
const CLIENTDATA = 0xF011; |
43
|
|
|
const BLIPJPEG = 0xF01D; |
44
|
|
|
const BLIPPNG = 0xF01E; |
45
|
|
|
const SPLITMENUCOLORS = 0xF11E; |
46
|
|
|
const TERTIARYOPT = 0xF122; |
47
|
|
|
|
48
|
|
|
/** |
49
|
|
|
* Escher stream data (binary) |
50
|
|
|
* |
51
|
|
|
* @var string |
52
|
|
|
*/ |
53
|
|
|
private $data; |
54
|
|
|
|
55
|
|
|
/** |
56
|
|
|
* Size in bytes of the Escher stream data |
57
|
|
|
* |
58
|
|
|
* @var int |
59
|
|
|
*/ |
60
|
|
|
private $dataSize; |
61
|
|
|
|
62
|
|
|
/** |
63
|
|
|
* Current position of stream pointer in Escher stream data |
64
|
|
|
* |
65
|
|
|
* @var int |
66
|
|
|
*/ |
67
|
|
|
private $pos; |
68
|
|
|
|
69
|
|
|
/** |
70
|
|
|
* The object to be returned by the reader. Modified during load. |
71
|
|
|
* |
72
|
|
|
* @var mixed |
73
|
|
|
*/ |
74
|
|
|
private $object; |
75
|
|
|
|
76
|
|
|
/** |
77
|
|
|
* Create a new Escher instance |
78
|
|
|
* |
79
|
|
|
* @param mixed $object |
80
|
|
|
*/ |
81
|
2 |
|
public function __construct($object) |
82
|
|
|
{ |
83
|
2 |
|
$this->object = $object; |
84
|
2 |
|
} |
85
|
|
|
|
86
|
|
|
/** |
87
|
|
|
* Load Escher stream data. May be a partial Escher stream. |
88
|
|
|
* |
89
|
|
|
* @param string $data |
90
|
|
|
*/ |
91
|
2 |
|
public function load($data) |
92
|
|
|
{ |
93
|
2 |
|
$this->data = $data; |
94
|
|
|
|
95
|
|
|
// total byte size of Excel data (workbook global substream + sheet substreams) |
96
|
2 |
|
$this->dataSize = strlen($this->data); |
97
|
|
|
|
98
|
2 |
|
$this->pos = 0; |
99
|
|
|
|
100
|
|
|
// Parse Escher stream |
101
|
2 |
|
while ($this->pos < $this->dataSize) { |
102
|
|
|
// offset: 2; size: 2: Record Type |
103
|
2 |
|
$fbt = \PhpOffice\PhpSpreadsheet\Reader\Xls::getInt2d($this->data, $this->pos + 2); |
104
|
|
|
|
105
|
|
|
switch ($fbt) { |
106
|
2 |
|
case self::DGGCONTAINER: |
107
|
2 |
|
$this->readDggContainer(); |
108
|
2 |
|
break; |
109
|
2 |
|
case self::DGG: |
110
|
2 |
|
$this->readDgg(); |
111
|
2 |
|
break; |
112
|
2 |
|
case self::BSTORECONTAINER: |
113
|
2 |
|
$this->readBstoreContainer(); |
114
|
2 |
|
break; |
115
|
2 |
|
case self::BSE: |
116
|
2 |
|
$this->readBSE(); |
117
|
2 |
|
break; |
118
|
2 |
|
case self::BLIPJPEG: |
119
|
2 |
|
$this->readBlipJPEG(); |
120
|
2 |
|
break; |
121
|
2 |
|
case self::BLIPPNG: |
122
|
2 |
|
$this->readBlipPNG(); |
123
|
2 |
|
break; |
124
|
2 |
|
case self::OPT: |
125
|
2 |
|
$this->readOPT(); |
126
|
2 |
|
break; |
127
|
2 |
|
case self::TERTIARYOPT: |
128
|
|
|
$this->readTertiaryOPT(); |
129
|
|
|
break; |
130
|
2 |
|
case self::SPLITMENUCOLORS: |
131
|
2 |
|
$this->readSplitMenuColors(); |
132
|
2 |
|
break; |
133
|
2 |
|
case self::DGCONTAINER: |
134
|
2 |
|
$this->readDgContainer(); |
135
|
2 |
|
break; |
136
|
2 |
|
case self::DG: |
137
|
2 |
|
$this->readDg(); |
138
|
2 |
|
break; |
139
|
2 |
|
case self::SPGRCONTAINER: |
140
|
2 |
|
$this->readSpgrContainer(); |
141
|
2 |
|
break; |
142
|
2 |
|
case self::SPCONTAINER: |
143
|
2 |
|
$this->readSpContainer(); |
144
|
2 |
|
break; |
145
|
2 |
|
case self::SPGR: |
146
|
2 |
|
$this->readSpgr(); |
147
|
2 |
|
break; |
148
|
2 |
|
case self::SP: |
149
|
2 |
|
$this->readSp(); |
150
|
2 |
|
break; |
151
|
2 |
|
case self::CLIENTTEXTBOX: |
152
|
1 |
|
$this->readClientTextbox(); |
153
|
1 |
|
break; |
154
|
2 |
|
case self::CLIENTANCHOR: |
155
|
2 |
|
$this->readClientAnchor(); |
156
|
2 |
|
break; |
157
|
2 |
|
case self::CLIENTDATA: |
158
|
2 |
|
$this->readClientData(); |
159
|
2 |
|
break; |
160
|
|
|
default: |
161
|
|
|
$this->readDefault(); |
162
|
|
|
break; |
163
|
|
|
} |
164
|
|
|
} |
165
|
|
|
|
166
|
2 |
|
return $this->object; |
167
|
|
|
} |
168
|
|
|
|
169
|
|
|
/** |
170
|
|
|
* Read a generic record |
171
|
|
|
*/ |
172
|
|
|
private function readDefault() |
173
|
|
|
{ |
174
|
|
|
// offset 0; size: 2; recVer and recInstance |
175
|
|
|
$verInstance = \PhpOffice\PhpSpreadsheet\Reader\Xls::getInt2d($this->data, $this->pos); |
176
|
|
|
|
177
|
|
|
// offset: 2; size: 2: Record Type |
178
|
|
|
$fbt = \PhpOffice\PhpSpreadsheet\Reader\Xls::getInt2d($this->data, $this->pos + 2); |
|
|
|
|
179
|
|
|
|
180
|
|
|
// bit: 0-3; mask: 0x000F; recVer |
|
|
|
|
181
|
|
|
$recVer = (0x000F & $verInstance) >> 0; |
|
|
|
|
182
|
|
|
|
183
|
|
|
$length = \PhpOffice\PhpSpreadsheet\Reader\Xls::getInt4d($this->data, $this->pos + 4); |
184
|
|
|
$recordData = substr($this->data, $this->pos + 8, $length); |
|
|
|
|
185
|
|
|
|
186
|
|
|
// move stream pointer to next record |
187
|
|
|
$this->pos += 8 + $length; |
188
|
|
|
} |
189
|
|
|
|
190
|
|
|
/** |
191
|
|
|
* Read DggContainer record (Drawing Group Container) |
192
|
|
|
*/ |
193
|
2 |
View Code Duplication |
private function readDggContainer() |
|
|
|
|
194
|
|
|
{ |
195
|
2 |
|
$length = \PhpOffice\PhpSpreadsheet\Reader\Xls::getInt4d($this->data, $this->pos + 4); |
196
|
2 |
|
$recordData = substr($this->data, $this->pos + 8, $length); |
197
|
|
|
|
198
|
|
|
// move stream pointer to next record |
199
|
2 |
|
$this->pos += 8 + $length; |
200
|
|
|
|
201
|
|
|
// record is a container, read contents |
202
|
2 |
|
$dggContainer = new \PhpOffice\PhpSpreadsheet\Shared\Escher\DggContainer(); |
203
|
2 |
|
$this->object->setDggContainer($dggContainer); |
204
|
2 |
|
$reader = new self($dggContainer); |
205
|
2 |
|
$reader->load($recordData); |
206
|
2 |
|
} |
207
|
|
|
|
208
|
|
|
/** |
209
|
|
|
* Read Dgg record (Drawing Group) |
210
|
|
|
*/ |
211
|
2 |
View Code Duplication |
private function readDgg() |
|
|
|
|
212
|
|
|
{ |
213
|
2 |
|
$length = \PhpOffice\PhpSpreadsheet\Reader\Xls::getInt4d($this->data, $this->pos + 4); |
214
|
2 |
|
$recordData = substr($this->data, $this->pos + 8, $length); |
|
|
|
|
215
|
|
|
|
216
|
|
|
// move stream pointer to next record |
217
|
2 |
|
$this->pos += 8 + $length; |
218
|
2 |
|
} |
219
|
|
|
|
220
|
|
|
/** |
221
|
|
|
* Read BstoreContainer record (Blip Store Container) |
222
|
|
|
*/ |
223
|
2 |
View Code Duplication |
private function readBstoreContainer() |
|
|
|
|
224
|
|
|
{ |
225
|
2 |
|
$length = \PhpOffice\PhpSpreadsheet\Reader\Xls::getInt4d($this->data, $this->pos + 4); |
226
|
2 |
|
$recordData = substr($this->data, $this->pos + 8, $length); |
227
|
|
|
|
228
|
|
|
// move stream pointer to next record |
229
|
2 |
|
$this->pos += 8 + $length; |
230
|
|
|
|
231
|
|
|
// record is a container, read contents |
232
|
2 |
|
$bstoreContainer = new \PhpOffice\PhpSpreadsheet\Shared\Escher\DggContainer\BstoreContainer(); |
233
|
2 |
|
$this->object->setBstoreContainer($bstoreContainer); |
234
|
2 |
|
$reader = new self($bstoreContainer); |
235
|
2 |
|
$reader->load($recordData); |
236
|
2 |
|
} |
237
|
|
|
|
238
|
|
|
/** |
239
|
|
|
* Read BSE record |
240
|
|
|
*/ |
241
|
2 |
|
private function readBSE() |
242
|
|
|
{ |
243
|
|
|
// offset: 0; size: 2; recVer and recInstance |
244
|
|
|
|
245
|
|
|
// bit: 4-15; mask: 0xFFF0; recInstance |
|
|
|
|
246
|
2 |
|
$recInstance = (0xFFF0 & \PhpOffice\PhpSpreadsheet\Reader\Xls::getInt2d($this->data, $this->pos)) >> 4; |
247
|
|
|
|
248
|
2 |
|
$length = \PhpOffice\PhpSpreadsheet\Reader\Xls::getInt4d($this->data, $this->pos + 4); |
249
|
2 |
|
$recordData = substr($this->data, $this->pos + 8, $length); |
250
|
|
|
|
251
|
|
|
// move stream pointer to next record |
252
|
2 |
|
$this->pos += 8 + $length; |
253
|
|
|
|
254
|
|
|
// add BSE to BstoreContainer |
255
|
2 |
|
$BSE = new \PhpOffice\PhpSpreadsheet\Shared\Escher\DggContainer\BstoreContainer\BSE(); |
256
|
2 |
|
$this->object->addBSE($BSE); |
257
|
|
|
|
258
|
2 |
|
$BSE->setBLIPType($recInstance); |
259
|
|
|
|
260
|
|
|
// offset: 0; size: 1; btWin32 (MSOBLIPTYPE) |
|
|
|
|
261
|
2 |
|
$btWin32 = ord($recordData[0]); |
|
|
|
|
262
|
|
|
|
263
|
|
|
// offset: 1; size: 1; btWin32 (MSOBLIPTYPE) |
|
|
|
|
264
|
2 |
|
$btMacOS = ord($recordData[1]); |
|
|
|
|
265
|
|
|
|
266
|
|
|
// offset: 2; size: 16; MD4 digest |
267
|
2 |
|
$rgbUid = substr($recordData, 2, 16); |
|
|
|
|
268
|
|
|
|
269
|
|
|
// offset: 18; size: 2; tag |
270
|
2 |
|
$tag = \PhpOffice\PhpSpreadsheet\Reader\Xls::getInt2d($recordData, 18); |
|
|
|
|
271
|
|
|
|
272
|
|
|
// offset: 20; size: 4; size of BLIP in bytes |
273
|
2 |
|
$size = \PhpOffice\PhpSpreadsheet\Reader\Xls::getInt4d($recordData, 20); |
|
|
|
|
274
|
|
|
|
275
|
|
|
// offset: 24; size: 4; number of references to this BLIP |
276
|
2 |
|
$cRef = \PhpOffice\PhpSpreadsheet\Reader\Xls::getInt4d($recordData, 24); |
|
|
|
|
277
|
|
|
|
278
|
|
|
// offset: 28; size: 4; MSOFO file offset |
279
|
2 |
|
$foDelay = \PhpOffice\PhpSpreadsheet\Reader\Xls::getInt4d($recordData, 28); |
|
|
|
|
280
|
|
|
|
281
|
|
|
// offset: 32; size: 1; unused1 |
282
|
2 |
|
$unused1 = ord($recordData{32}); |
|
|
|
|
283
|
|
|
|
284
|
|
|
// offset: 33; size: 1; size of nameData in bytes (including null terminator) |
285
|
2 |
|
$cbName = ord($recordData{33}); |
286
|
|
|
|
287
|
|
|
// offset: 34; size: 1; unused2 |
288
|
2 |
|
$unused2 = ord($recordData{34}); |
|
|
|
|
289
|
|
|
|
290
|
|
|
// offset: 35; size: 1; unused3 |
291
|
2 |
|
$unused3 = ord($recordData{35}); |
|
|
|
|
292
|
|
|
|
293
|
|
|
// offset: 36; size: $cbName; nameData |
294
|
2 |
|
$nameData = substr($recordData, 36, $cbName); |
|
|
|
|
295
|
|
|
|
296
|
|
|
// offset: 36 + $cbName, size: var; the BLIP data |
297
|
2 |
|
$blipData = substr($recordData, 36 + $cbName); |
298
|
|
|
|
299
|
|
|
// record is a container, read contents |
300
|
2 |
|
$reader = new \PhpOffice\PhpSpreadsheet\Reader\Xls\Escher($BSE); |
301
|
2 |
|
$reader->load($blipData); |
302
|
2 |
|
} |
303
|
|
|
|
304
|
|
|
/** |
305
|
|
|
* Read BlipJPEG record. Holds raw JPEG image data |
306
|
|
|
*/ |
307
|
2 |
View Code Duplication |
private function readBlipJPEG() |
|
|
|
|
308
|
|
|
{ |
309
|
|
|
// offset: 0; size: 2; recVer and recInstance |
310
|
|
|
|
311
|
|
|
// bit: 4-15; mask: 0xFFF0; recInstance |
|
|
|
|
312
|
2 |
|
$recInstance = (0xFFF0 & \PhpOffice\PhpSpreadsheet\Reader\Xls::getInt2d($this->data, $this->pos)) >> 4; |
313
|
|
|
|
314
|
2 |
|
$length = \PhpOffice\PhpSpreadsheet\Reader\Xls::getInt4d($this->data, $this->pos + 4); |
315
|
2 |
|
$recordData = substr($this->data, $this->pos + 8, $length); |
316
|
|
|
|
317
|
|
|
// move stream pointer to next record |
318
|
2 |
|
$this->pos += 8 + $length; |
319
|
|
|
|
320
|
2 |
|
$pos = 0; |
321
|
|
|
|
322
|
|
|
// offset: 0; size: 16; rgbUid1 (MD4 digest of) |
323
|
2 |
|
$rgbUid1 = substr($recordData, 0, 16); |
|
|
|
|
324
|
2 |
|
$pos += 16; |
325
|
|
|
|
326
|
|
|
// offset: 16; size: 16; rgbUid2 (MD4 digest), only if $recInstance = 0x46B or 0x6E3 |
|
|
|
|
327
|
2 |
|
if (in_array($recInstance, [0x046B, 0x06E3])) { |
328
|
|
|
$rgbUid2 = substr($recordData, 16, 16); |
|
|
|
|
329
|
|
|
$pos += 16; |
330
|
|
|
} |
331
|
|
|
|
332
|
|
|
// offset: var; size: 1; tag |
333
|
2 |
|
$tag = ord($recordData{$pos}); |
|
|
|
|
334
|
2 |
|
$pos += 1; |
335
|
|
|
|
336
|
|
|
// offset: var; size: var; the raw image data |
337
|
2 |
|
$data = substr($recordData, $pos); |
338
|
|
|
|
339
|
2 |
|
$blip = new \PhpOffice\PhpSpreadsheet\Shared\Escher\DggContainer\BstoreContainer\BSE\Blip(); |
340
|
2 |
|
$blip->setData($data); |
341
|
|
|
|
342
|
2 |
|
$this->object->setBlip($blip); |
343
|
2 |
|
} |
344
|
|
|
|
345
|
|
|
/** |
346
|
|
|
* Read BlipPNG record. Holds raw PNG image data |
347
|
|
|
*/ |
348
|
2 |
View Code Duplication |
private function readBlipPNG() |
|
|
|
|
349
|
|
|
{ |
350
|
|
|
// offset: 0; size: 2; recVer and recInstance |
351
|
|
|
|
352
|
|
|
// bit: 4-15; mask: 0xFFF0; recInstance |
|
|
|
|
353
|
2 |
|
$recInstance = (0xFFF0 & \PhpOffice\PhpSpreadsheet\Reader\Xls::getInt2d($this->data, $this->pos)) >> 4; |
354
|
|
|
|
355
|
2 |
|
$length = \PhpOffice\PhpSpreadsheet\Reader\Xls::getInt4d($this->data, $this->pos + 4); |
356
|
2 |
|
$recordData = substr($this->data, $this->pos + 8, $length); |
357
|
|
|
|
358
|
|
|
// move stream pointer to next record |
359
|
2 |
|
$this->pos += 8 + $length; |
360
|
|
|
|
361
|
2 |
|
$pos = 0; |
362
|
|
|
|
363
|
|
|
// offset: 0; size: 16; rgbUid1 (MD4 digest of) |
364
|
2 |
|
$rgbUid1 = substr($recordData, 0, 16); |
|
|
|
|
365
|
2 |
|
$pos += 16; |
366
|
|
|
|
367
|
|
|
// offset: 16; size: 16; rgbUid2 (MD4 digest), only if $recInstance = 0x46B or 0x6E3 |
|
|
|
|
368
|
2 |
|
if ($recInstance == 0x06E1) { |
369
|
|
|
$rgbUid2 = substr($recordData, 16, 16); |
|
|
|
|
370
|
|
|
$pos += 16; |
371
|
|
|
} |
372
|
|
|
|
373
|
|
|
// offset: var; size: 1; tag |
374
|
2 |
|
$tag = ord($recordData{$pos}); |
|
|
|
|
375
|
2 |
|
$pos += 1; |
376
|
|
|
|
377
|
|
|
// offset: var; size: var; the raw image data |
378
|
2 |
|
$data = substr($recordData, $pos); |
379
|
|
|
|
380
|
2 |
|
$blip = new \PhpOffice\PhpSpreadsheet\Shared\Escher\DggContainer\BstoreContainer\BSE\Blip(); |
381
|
2 |
|
$blip->setData($data); |
382
|
|
|
|
383
|
2 |
|
$this->object->setBlip($blip); |
384
|
2 |
|
} |
385
|
|
|
|
386
|
|
|
/** |
387
|
|
|
* Read OPT record. This record may occur within DggContainer record or SpContainer |
388
|
|
|
*/ |
389
|
2 |
View Code Duplication |
private function readOPT() |
|
|
|
|
390
|
|
|
{ |
391
|
|
|
// offset: 0; size: 2; recVer and recInstance |
392
|
|
|
|
393
|
|
|
// bit: 4-15; mask: 0xFFF0; recInstance |
|
|
|
|
394
|
2 |
|
$recInstance = (0xFFF0 & \PhpOffice\PhpSpreadsheet\Reader\Xls::getInt2d($this->data, $this->pos)) >> 4; |
395
|
|
|
|
396
|
2 |
|
$length = \PhpOffice\PhpSpreadsheet\Reader\Xls::getInt4d($this->data, $this->pos + 4); |
397
|
2 |
|
$recordData = substr($this->data, $this->pos + 8, $length); |
398
|
|
|
|
399
|
|
|
// move stream pointer to next record |
400
|
2 |
|
$this->pos += 8 + $length; |
401
|
|
|
|
402
|
2 |
|
$this->readOfficeArtRGFOPTE($recordData, $recInstance); |
403
|
2 |
|
} |
404
|
|
|
|
405
|
|
|
/** |
406
|
|
|
* Read TertiaryOPT record |
407
|
|
|
*/ |
408
|
|
View Code Duplication |
private function readTertiaryOPT() |
|
|
|
|
409
|
|
|
{ |
410
|
|
|
// offset: 0; size: 2; recVer and recInstance |
411
|
|
|
|
412
|
|
|
// bit: 4-15; mask: 0xFFF0; recInstance |
|
|
|
|
413
|
|
|
$recInstance = (0xFFF0 & \PhpOffice\PhpSpreadsheet\Reader\Xls::getInt2d($this->data, $this->pos)) >> 4; |
|
|
|
|
414
|
|
|
|
415
|
|
|
$length = \PhpOffice\PhpSpreadsheet\Reader\Xls::getInt4d($this->data, $this->pos + 4); |
416
|
|
|
$recordData = substr($this->data, $this->pos + 8, $length); |
|
|
|
|
417
|
|
|
|
418
|
|
|
// move stream pointer to next record |
419
|
|
|
$this->pos += 8 + $length; |
420
|
|
|
} |
421
|
|
|
|
422
|
|
|
/** |
423
|
|
|
* Read SplitMenuColors record |
424
|
|
|
*/ |
425
|
2 |
View Code Duplication |
private function readSplitMenuColors() |
|
|
|
|
426
|
|
|
{ |
427
|
2 |
|
$length = \PhpOffice\PhpSpreadsheet\Reader\Xls::getInt4d($this->data, $this->pos + 4); |
428
|
2 |
|
$recordData = substr($this->data, $this->pos + 8, $length); |
|
|
|
|
429
|
|
|
|
430
|
|
|
// move stream pointer to next record |
431
|
2 |
|
$this->pos += 8 + $length; |
432
|
2 |
|
} |
433
|
|
|
|
434
|
|
|
/** |
435
|
|
|
* Read DgContainer record (Drawing Container) |
436
|
|
|
*/ |
437
|
2 |
View Code Duplication |
private function readDgContainer() |
|
|
|
|
438
|
|
|
{ |
439
|
2 |
|
$length = \PhpOffice\PhpSpreadsheet\Reader\Xls::getInt4d($this->data, $this->pos + 4); |
440
|
2 |
|
$recordData = substr($this->data, $this->pos + 8, $length); |
441
|
|
|
|
442
|
|
|
// move stream pointer to next record |
443
|
2 |
|
$this->pos += 8 + $length; |
444
|
|
|
|
445
|
|
|
// record is a container, read contents |
446
|
2 |
|
$dgContainer = new \PhpOffice\PhpSpreadsheet\Shared\Escher\DgContainer(); |
447
|
2 |
|
$this->object->setDgContainer($dgContainer); |
448
|
2 |
|
$reader = new \PhpOffice\PhpSpreadsheet\Reader\Xls\Escher($dgContainer); |
449
|
2 |
|
$escher = $reader->load($recordData); |
|
|
|
|
450
|
2 |
|
} |
451
|
|
|
|
452
|
|
|
/** |
453
|
|
|
* Read Dg record (Drawing) |
454
|
|
|
*/ |
455
|
2 |
View Code Duplication |
private function readDg() |
|
|
|
|
456
|
|
|
{ |
457
|
2 |
|
$length = \PhpOffice\PhpSpreadsheet\Reader\Xls::getInt4d($this->data, $this->pos + 4); |
458
|
2 |
|
$recordData = substr($this->data, $this->pos + 8, $length); |
|
|
|
|
459
|
|
|
|
460
|
|
|
// move stream pointer to next record |
461
|
2 |
|
$this->pos += 8 + $length; |
462
|
2 |
|
} |
463
|
|
|
|
464
|
|
|
/** |
465
|
|
|
* Read SpgrContainer record (Shape Group Container) |
466
|
|
|
*/ |
467
|
2 |
|
private function readSpgrContainer() |
468
|
|
|
{ |
469
|
|
|
// context is either context DgContainer or SpgrContainer |
470
|
|
|
|
471
|
2 |
|
$length = \PhpOffice\PhpSpreadsheet\Reader\Xls::getInt4d($this->data, $this->pos + 4); |
472
|
2 |
|
$recordData = substr($this->data, $this->pos + 8, $length); |
473
|
|
|
|
474
|
|
|
// move stream pointer to next record |
475
|
2 |
|
$this->pos += 8 + $length; |
476
|
|
|
|
477
|
|
|
// record is a container, read contents |
478
|
2 |
|
$spgrContainer = new \PhpOffice\PhpSpreadsheet\Shared\Escher\DgContainer\SpgrContainer(); |
479
|
|
|
|
480
|
2 |
|
if ($this->object instanceof \PhpOffice\PhpSpreadsheet\Shared\Escher\DgContainer) { |
481
|
|
|
// DgContainer |
482
|
2 |
|
$this->object->setSpgrContainer($spgrContainer); |
483
|
|
|
} else { |
484
|
|
|
// SpgrContainer |
485
|
|
|
$this->object->addChild($spgrContainer); |
486
|
|
|
} |
487
|
|
|
|
488
|
2 |
|
$reader = new self($spgrContainer); |
489
|
2 |
|
$escher = $reader->load($recordData); |
|
|
|
|
490
|
2 |
|
} |
491
|
|
|
|
492
|
|
|
/** |
493
|
|
|
* Read SpContainer record (Shape Container) |
494
|
|
|
*/ |
495
|
2 |
View Code Duplication |
private function readSpContainer() |
|
|
|
|
496
|
|
|
{ |
497
|
2 |
|
$length = \PhpOffice\PhpSpreadsheet\Reader\Xls::getInt4d($this->data, $this->pos + 4); |
498
|
2 |
|
$recordData = substr($this->data, $this->pos + 8, $length); |
499
|
|
|
|
500
|
|
|
// add spContainer to spgrContainer |
501
|
2 |
|
$spContainer = new \PhpOffice\PhpSpreadsheet\Shared\Escher\DgContainer\SpgrContainer\SpContainer(); |
502
|
2 |
|
$this->object->addChild($spContainer); |
503
|
|
|
|
504
|
|
|
// move stream pointer to next record |
505
|
2 |
|
$this->pos += 8 + $length; |
506
|
|
|
|
507
|
|
|
// record is a container, read contents |
508
|
2 |
|
$reader = new self($spContainer); |
509
|
2 |
|
$escher = $reader->load($recordData); |
|
|
|
|
510
|
2 |
|
} |
511
|
|
|
|
512
|
|
|
/** |
513
|
|
|
* Read Spgr record (Shape Group) |
514
|
|
|
*/ |
515
|
2 |
View Code Duplication |
private function readSpgr() |
|
|
|
|
516
|
|
|
{ |
517
|
2 |
|
$length = \PhpOffice\PhpSpreadsheet\Reader\Xls::getInt4d($this->data, $this->pos + 4); |
518
|
2 |
|
$recordData = substr($this->data, $this->pos + 8, $length); |
|
|
|
|
519
|
|
|
|
520
|
|
|
// move stream pointer to next record |
521
|
2 |
|
$this->pos += 8 + $length; |
522
|
2 |
|
} |
523
|
|
|
|
524
|
|
|
/** |
525
|
|
|
* Read Sp record (Shape) |
526
|
|
|
*/ |
527
|
2 |
View Code Duplication |
private function readSp() |
|
|
|
|
528
|
|
|
{ |
529
|
|
|
// offset: 0; size: 2; recVer and recInstance |
530
|
|
|
|
531
|
|
|
// bit: 4-15; mask: 0xFFF0; recInstance |
|
|
|
|
532
|
2 |
|
$recInstance = (0xFFF0 & \PhpOffice\PhpSpreadsheet\Reader\Xls::getInt2d($this->data, $this->pos)) >> 4; |
|
|
|
|
533
|
|
|
|
534
|
2 |
|
$length = \PhpOffice\PhpSpreadsheet\Reader\Xls::getInt4d($this->data, $this->pos + 4); |
535
|
2 |
|
$recordData = substr($this->data, $this->pos + 8, $length); |
|
|
|
|
536
|
|
|
|
537
|
|
|
// move stream pointer to next record |
538
|
2 |
|
$this->pos += 8 + $length; |
539
|
2 |
|
} |
540
|
|
|
|
541
|
|
|
/** |
542
|
|
|
* Read ClientTextbox record |
543
|
|
|
*/ |
544
|
1 |
View Code Duplication |
private function readClientTextbox() |
|
|
|
|
545
|
|
|
{ |
546
|
|
|
// offset: 0; size: 2; recVer and recInstance |
547
|
|
|
|
548
|
|
|
// bit: 4-15; mask: 0xFFF0; recInstance |
|
|
|
|
549
|
1 |
|
$recInstance = (0xFFF0 & \PhpOffice\PhpSpreadsheet\Reader\Xls::getInt2d($this->data, $this->pos)) >> 4; |
|
|
|
|
550
|
|
|
|
551
|
1 |
|
$length = \PhpOffice\PhpSpreadsheet\Reader\Xls::getInt4d($this->data, $this->pos + 4); |
552
|
1 |
|
$recordData = substr($this->data, $this->pos + 8, $length); |
|
|
|
|
553
|
|
|
|
554
|
|
|
// move stream pointer to next record |
555
|
1 |
|
$this->pos += 8 + $length; |
556
|
1 |
|
} |
557
|
|
|
|
558
|
|
|
/** |
559
|
|
|
* Read ClientAnchor record. This record holds information about where the shape is anchored in worksheet |
560
|
|
|
*/ |
561
|
2 |
|
private function readClientAnchor() |
562
|
|
|
{ |
563
|
2 |
|
$length = \PhpOffice\PhpSpreadsheet\Reader\Xls::getInt4d($this->data, $this->pos + 4); |
564
|
2 |
|
$recordData = substr($this->data, $this->pos + 8, $length); |
565
|
|
|
|
566
|
|
|
// move stream pointer to next record |
567
|
2 |
|
$this->pos += 8 + $length; |
568
|
|
|
|
569
|
|
|
// offset: 2; size: 2; upper-left corner column index (0-based) |
570
|
2 |
|
$c1 = \PhpOffice\PhpSpreadsheet\Reader\Xls::getInt2d($recordData, 2); |
571
|
|
|
|
572
|
|
|
// offset: 4; size: 2; upper-left corner horizontal offset in 1/1024 of column width |
573
|
2 |
|
$startOffsetX = \PhpOffice\PhpSpreadsheet\Reader\Xls::getInt2d($recordData, 4); |
574
|
|
|
|
575
|
|
|
// offset: 6; size: 2; upper-left corner row index (0-based) |
576
|
2 |
|
$r1 = \PhpOffice\PhpSpreadsheet\Reader\Xls::getInt2d($recordData, 6); |
577
|
|
|
|
578
|
|
|
// offset: 8; size: 2; upper-left corner vertical offset in 1/256 of row height |
579
|
2 |
|
$startOffsetY = \PhpOffice\PhpSpreadsheet\Reader\Xls::getInt2d($recordData, 8); |
580
|
|
|
|
581
|
|
|
// offset: 10; size: 2; bottom-right corner column index (0-based) |
582
|
2 |
|
$c2 = \PhpOffice\PhpSpreadsheet\Reader\Xls::getInt2d($recordData, 10); |
583
|
|
|
|
584
|
|
|
// offset: 12; size: 2; bottom-right corner horizontal offset in 1/1024 of column width |
585
|
2 |
|
$endOffsetX = \PhpOffice\PhpSpreadsheet\Reader\Xls::getInt2d($recordData, 12); |
586
|
|
|
|
587
|
|
|
// offset: 14; size: 2; bottom-right corner row index (0-based) |
588
|
2 |
|
$r2 = \PhpOffice\PhpSpreadsheet\Reader\Xls::getInt2d($recordData, 14); |
589
|
|
|
|
590
|
|
|
// offset: 16; size: 2; bottom-right corner vertical offset in 1/256 of row height |
591
|
2 |
|
$endOffsetY = \PhpOffice\PhpSpreadsheet\Reader\Xls::getInt2d($recordData, 16); |
592
|
|
|
|
593
|
|
|
// set the start coordinates |
594
|
2 |
|
$this->object->setStartCoordinates(\PhpOffice\PhpSpreadsheet\Cell::stringFromColumnIndex($c1) . ($r1 + 1)); |
595
|
|
|
|
596
|
|
|
// set the start offsetX |
597
|
2 |
|
$this->object->setStartOffsetX($startOffsetX); |
598
|
|
|
|
599
|
|
|
// set the start offsetY |
600
|
2 |
|
$this->object->setStartOffsetY($startOffsetY); |
601
|
|
|
|
602
|
|
|
// set the end coordinates |
603
|
2 |
|
$this->object->setEndCoordinates(\PhpOffice\PhpSpreadsheet\Cell::stringFromColumnIndex($c2) . ($r2 + 1)); |
604
|
|
|
|
605
|
|
|
// set the end offsetX |
606
|
2 |
|
$this->object->setEndOffsetX($endOffsetX); |
607
|
|
|
|
608
|
|
|
// set the end offsetY |
609
|
2 |
|
$this->object->setEndOffsetY($endOffsetY); |
610
|
2 |
|
} |
611
|
|
|
|
612
|
|
|
/** |
613
|
|
|
* Read ClientData record |
614
|
|
|
*/ |
615
|
2 |
View Code Duplication |
private function readClientData() |
|
|
|
|
616
|
|
|
{ |
617
|
2 |
|
$length = \PhpOffice\PhpSpreadsheet\Reader\Xls::getInt4d($this->data, $this->pos + 4); |
618
|
2 |
|
$recordData = substr($this->data, $this->pos + 8, $length); |
|
|
|
|
619
|
|
|
|
620
|
|
|
// move stream pointer to next record |
621
|
2 |
|
$this->pos += 8 + $length; |
622
|
2 |
|
} |
623
|
|
|
|
624
|
|
|
/** |
625
|
|
|
* Read OfficeArtRGFOPTE table of property-value pairs |
626
|
|
|
* |
627
|
|
|
* @param string $data Binary data |
628
|
|
|
* @param int $n Number of properties |
629
|
|
|
*/ |
630
|
2 |
|
private function readOfficeArtRGFOPTE($data, $n) |
631
|
|
|
{ |
632
|
2 |
|
$splicedComplexData = substr($data, 6 * $n); |
633
|
|
|
|
634
|
|
|
// loop through property-value pairs |
635
|
2 |
|
for ($i = 0; $i < $n; ++$i) { |
636
|
|
|
// read 6 bytes at a time |
637
|
2 |
|
$fopte = substr($data, 6 * $i, 6); |
638
|
|
|
|
639
|
|
|
// offset: 0; size: 2; opid |
640
|
2 |
|
$opid = \PhpOffice\PhpSpreadsheet\Reader\Xls::getInt2d($fopte, 0); |
641
|
|
|
|
642
|
|
|
// bit: 0-13; mask: 0x3FFF; opid.opid |
643
|
2 |
|
$opidOpid = (0x3FFF & $opid) >> 0; |
644
|
|
|
|
645
|
|
|
// bit: 14; mask 0x4000; 1 = value in op field is BLIP identifier |
646
|
2 |
|
$opidFBid = (0x4000 & $opid) >> 14; |
|
|
|
|
647
|
|
|
|
648
|
|
|
// bit: 15; mask 0x8000; 1 = this is a complex property, op field specifies size of complex data |
649
|
2 |
|
$opidFComplex = (0x8000 & $opid) >> 15; |
650
|
|
|
|
651
|
|
|
// offset: 2; size: 4; the value for this property |
652
|
2 |
|
$op = \PhpOffice\PhpSpreadsheet\Reader\Xls::getInt4d($fopte, 2); |
653
|
|
|
|
654
|
2 |
|
if ($opidFComplex) { |
655
|
2 |
|
$complexData = substr($splicedComplexData, 0, $op); |
656
|
2 |
|
$splicedComplexData = substr($splicedComplexData, $op); |
657
|
|
|
|
658
|
|
|
// we store string value with complex data |
659
|
2 |
|
$value = $complexData; |
660
|
|
|
} else { |
661
|
|
|
// we store integer value |
662
|
2 |
|
$value = $op; |
663
|
|
|
} |
664
|
|
|
|
665
|
2 |
|
$this->object->setOPT($opidOpid, $value); |
666
|
|
|
} |
667
|
2 |
|
} |
668
|
|
|
} |
669
|
|
|
|
This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.
Both the
$myVar
assignment in line 1 and the$higher
assignment in line 2 are dead. The first because$myVar
is never used and the second because$higher
is always overwritten for every possible time line.