PluginProbe
wpDataTables – WordPress Data Table, Dynamic Tables & Table Charts Plugin / 6.5.1.7
wpDataTables – WordPress Data Table, Dynamic Tables & Table Charts Plugin v6.5.1.7
6.5.1.7 6.5.1.6 6.5.1.5 6.5.1.4 6.5.1.3 6.5.1.2 6.5.1.1 6.5.0.9 6.5.0.8 6.5.0.7 6.5.0.6 trunk 3.4.2.40 3.4.2.41 3.4.2.42 3.4.2.43 3.4.2.44 3.4.2.45 3.4.2.46 3.4.2.47 3.4.2.48 3.4.2.49 3.4.2.50 6.3.2 6.3.3.1 All 47 releases
wpdatatables / lib / phpoffice / phpspreadsheet / src / PhpSpreadsheet / Writer / Xls / Escher.php

Escher.php in wpDataTables – WordPress Data Table, Dynamic Tables & Table Charts Plugin 6.5.1.7, at lib/phpoffice/phpspreadsheet/src/PhpSpreadsheet/Writer/Xls/Escher.php

525 lines 18.0 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 namespace PhpOffice\PhpSpreadsheet\Writer\Xls;
4
5 use PhpOffice\PhpSpreadsheet\Cell\Coordinate;
6 use PhpOffice\PhpSpreadsheet\Shared\Escher as SharedEscher;
7 use PhpOffice\PhpSpreadsheet\Shared\Escher\DgContainer;
8 use PhpOffice\PhpSpreadsheet\Shared\Escher\DgContainer\SpgrContainer;
9 use PhpOffice\PhpSpreadsheet\Shared\Escher\DgContainer\SpgrContainer\SpContainer;
10 use PhpOffice\PhpSpreadsheet\Shared\Escher\DggContainer;
11 use PhpOffice\PhpSpreadsheet\Shared\Escher\DggContainer\BstoreContainer;
12 use PhpOffice\PhpSpreadsheet\Shared\Escher\DggContainer\BstoreContainer\BSE;
13 use PhpOffice\PhpSpreadsheet\Shared\Escher\DggContainer\BstoreContainer\BSE\Blip;
14
15 class Escher
16 {
17 /**
18 * The object we are writing.
19 *
20 * @var Blip|BSE|BstoreContainer|DgContainer|DggContainer|Escher|SpContainer|SpgrContainer
21 */
22 private $object;
23
24 /**
25 * The written binary data.
26 *
27 * @var string
28 */
29 private $data;
30
31 /**
32 * Shape offsets. Positions in binary stream where a new shape record begins.
33 *
34 * @var array
35 */
36 private $spOffsets;
37
38 /**
39 * Shape types.
40 *
41 * @var array
42 */
43 private $spTypes;
44
45 /**
46 * Constructor.
47 *
48 * @param mixed $object
49 */
50 public function __construct($object)
51 {
52 $this->object = $object;
53 }
54
55 /**
56 * Process the object to be written.
57 *
58 * @return string
59 */
60 public function close()
61 {
62 // initialize
63 $this->data = '';
64
65 switch (get_class($this->object)) {
66 case SharedEscher::class:
67 if ($dggContainer = $this->object->/** @scrutinizer ignore-call */ getDggContainer()) {
68 $writer = new self($dggContainer);
69 $this->data = $writer->close();
70 } elseif ($dgContainer = $this->object->/** @scrutinizer ignore-call */ getDgContainer()) {
71 $writer = new self($dgContainer);
72 $this->data = $writer->close();
73 $this->spOffsets = $writer->getSpOffsets();
74 $this->spTypes = $writer->getSpTypes();
75 }
76
77 break;
78 case DggContainer::class:
79 // this is a container record
80
81 // initialize
82 $innerData = '';
83
84 // write the dgg
85 $recVer = 0x0;
86 $recInstance = 0x0000;
87 $recType = 0xF006;
88
89 $recVerInstance = $recVer;
90 $recVerInstance |= $recInstance << 4;
91
92 // dgg data
93 $dggData =
94 pack(
95 'VVVV',
96 $this->object->/** @scrutinizer ignore-call */ getSpIdMax(), // maximum shape identifier increased by one
97 $this->object->/** @scrutinizer ignore-call */ getCDgSaved() + 1, // number of file identifier clusters increased by one
98 $this->object->/** @scrutinizer ignore-call */ getCSpSaved(),
99 $this->object->/** @scrutinizer ignore-call */ getCDgSaved() // count total number of drawings saved
100 );
101
102 // add file identifier clusters (one per drawing)
103 /** @scrutinizer ignore-call */
104 $IDCLs = $this->object->getIDCLs();
105
106 foreach ($IDCLs as $dgId => $maxReducedSpId) {
107 $dggData .= pack('VV', $dgId, $maxReducedSpId + 1);
108 }
109
110 $header = pack('vvV', $recVerInstance, $recType, strlen($dggData));
111 $innerData .= $header . $dggData;
112
113 // write the bstoreContainer
114 if ($bstoreContainer = $this->object->/** @scrutinizer ignore-call */ getBstoreContainer()) {
115 $writer = new self($bstoreContainer);
116 $innerData .= $writer->close();
117 }
118
119 // write the record
120 $recVer = 0xF;
121 $recInstance = 0x0000;
122 $recType = 0xF000;
123 $length = strlen($innerData);
124
125 $recVerInstance = $recVer;
126 $recVerInstance |= $recInstance << 4;
127
128 $header = pack('vvV', $recVerInstance, $recType, $length);
129
130 $this->data = $header . $innerData;
131
132 break;
133 case BstoreContainer::class:
134 // this is a container record
135
136 // initialize
137 $innerData = '';
138
139 // treat the inner data
140 if ($BSECollection = $this->object->/** @scrutinizer ignore-call */ getBSECollection()) {
141 foreach ($BSECollection as $BSE) {
142 $writer = new self($BSE);
143 $innerData .= $writer->close();
144 }
145 }
146
147 // write the record
148 $recVer = 0xF;
149 $recInstance = count($this->object->/** @scrutinizer ignore-call */ getBSECollection());
150 $recType = 0xF001;
151 $length = strlen($innerData);
152
153 $recVerInstance = $recVer;
154 $recVerInstance |= $recInstance << 4;
155
156 $header = pack('vvV', $recVerInstance, $recType, $length);
157
158 $this->data = $header . $innerData;
159
160 break;
161 case BSE::class:
162 // this is a semi-container record
163
164 // initialize
165 $innerData = '';
166
167 // here we treat the inner data
168 if ($blip = $this->object->/** @scrutinizer ignore-call */ getBlip()) {
169 $writer = new self($blip);
170 $innerData .= $writer->close();
171 }
172
173 // initialize
174 $data = '';
175
176 /** @scrutinizer ignore-call */
177 $btWin32 = $this->object->getBlipType();
178 /** @scrutinizer ignore-call */
179 $btMacOS = $this->object->getBlipType();
180 $data .= pack('CC', $btWin32, $btMacOS);
181
182 $rgbUid = pack('VVVV', 0, 0, 0, 0); // todo
183 $data .= $rgbUid;
184
185 $tag = 0;
186 $size = strlen($innerData);
187 $cRef = 1;
188 $foDelay = 0; //todo
189 $unused1 = 0x0;
190 $cbName = 0x0;
191 $unused2 = 0x0;
192 $unused3 = 0x0;
193 $data .= pack('vVVVCCCC', $tag, $size, $cRef, $foDelay, $unused1, $cbName, $unused2, $unused3);
194
195 $data .= $innerData;
196
197 // write the record
198 $recVer = 0x2;
199 /** @scrutinizer ignore-call */
200 $recInstance = $this->object->getBlipType();
201 $recType = 0xF007;
202 $length = strlen($data);
203
204 $recVerInstance = $recVer;
205 $recVerInstance |= $recInstance << 4;
206
207 $header = pack('vvV', $recVerInstance, $recType, $length);
208
209 $this->data = $header;
210
211 $this->data .= $data;
212
213 break;
214 case Blip::class:
215 // this is an atom record
216
217 // write the record
218 switch ($this->object->/** @scrutinizer ignore-call */ getParent()->/** @scrutinizer ignore-call */ getBlipType()) {
219 case BSE::BLIPTYPE_JPEG:
220 // initialize
221 $innerData = '';
222
223 $rgbUid1 = pack('VVVV', 0, 0, 0, 0); // todo
224 $innerData .= $rgbUid1;
225
226 $tag = 0xFF; // todo
227 $innerData .= pack('C', $tag);
228
229 $innerData .= $this->object->/** @scrutinizer ignore-call */ getData();
230
231 $recVer = 0x0;
232 $recInstance = 0x46A;
233 $recType = 0xF01D;
234 $length = strlen($innerData);
235
236 $recVerInstance = $recVer;
237 $recVerInstance |= $recInstance << 4;
238
239 $header = pack('vvV', $recVerInstance, $recType, $length);
240
241 $this->data = $header;
242
243 $this->data .= $innerData;
244
245 break;
246 case BSE::BLIPTYPE_PNG:
247 // initialize
248 $innerData = '';
249
250 $rgbUid1 = pack('VVVV', 0, 0, 0, 0); // todo
251 $innerData .= $rgbUid1;
252
253 $tag = 0xFF; // todo
254 $innerData .= pack('C', $tag);
255
256 $innerData .= $this->object->/** @scrutinizer ignore-call */ getData();
257
258 $recVer = 0x0;
259 $recInstance = 0x6E0;
260 $recType = 0xF01E;
261 $length = strlen($innerData);
262
263 $recVerInstance = $recVer;
264 $recVerInstance |= $recInstance << 4;
265
266 $header = pack('vvV', $recVerInstance, $recType, $length);
267
268 $this->data = $header;
269
270 $this->data .= $innerData;
271
272 break;
273 }
274
275 break;
276 case DgContainer::class:
277 // this is a container record
278
279 // initialize
280 $innerData = '';
281
282 // write the dg
283 $recVer = 0x0;
284 /** @scrutinizer ignore-call */
285 $recInstance = $this->object->getDgId();
286 $recType = 0xF008;
287 $length = 8;
288
289 $recVerInstance = $recVer;
290 $recVerInstance |= $recInstance << 4;
291
292 $header = pack('vvV', $recVerInstance, $recType, $length);
293
294 // number of shapes in this drawing (including group shape)
295 $countShapes = count($this->object->/** @scrutinizer ignore-call */ getSpgrContainerOrThrow()->getChildren());
296 $innerData .= $header . pack('VV', $countShapes, $this->object->/** @scrutinizer ignore-call */ getLastSpId());
297
298 // write the spgrContainer
299 if ($spgrContainer = $this->object->/** @scrutinizer ignore-call */ getSpgrContainer()) {
300 $writer = new self($spgrContainer);
301 $innerData .= $writer->close();
302
303 // get the shape offsets relative to the spgrContainer record
304 $spOffsets = $writer->getSpOffsets();
305 $spTypes = $writer->getSpTypes();
306
307 // save the shape offsets relative to dgContainer
308 foreach ($spOffsets as &$spOffset) {
309 $spOffset += 24; // add length of dgContainer header data (8 bytes) plus dg data (16 bytes)
310 }
311
312 $this->spOffsets = $spOffsets;
313 $this->spTypes = $spTypes;
314 }
315
316 // write the record
317 $recVer = 0xF;
318 $recInstance = 0x0000;
319 $recType = 0xF002;
320 $length = strlen($innerData);
321
322 $recVerInstance = $recVer;
323 $recVerInstance |= $recInstance << 4;
324
325 $header = pack('vvV', $recVerInstance, $recType, $length);
326
327 $this->data = $header . $innerData;
328
329 break;
330 case SpgrContainer::class:
331 // this is a container record
332
333 // initialize
334 $innerData = '';
335
336 // initialize spape offsets
337 $totalSize = 8;
338 $spOffsets = [];
339 $spTypes = [];
340
341 // treat the inner data
342 foreach ($this->object->/** @scrutinizer ignore-call */ getChildren() as $spContainer) {
343 $writer = new self($spContainer);
344 $spData = $writer->close();
345 $innerData .= $spData;
346
347 // save the shape offsets (where new shape records begin)
348 $totalSize += strlen($spData);
349 $spOffsets[] = $totalSize;
350
351 $spTypes = array_merge($spTypes, $writer->getSpTypes());
352 }
353
354 // write the record
355 $recVer = 0xF;
356 $recInstance = 0x0000;
357 $recType = 0xF003;
358 $length = strlen($innerData);
359
360 $recVerInstance = $recVer;
361 $recVerInstance |= $recInstance << 4;
362
363 $header = pack('vvV', $recVerInstance, $recType, $length);
364
365 $this->data = $header . $innerData;
366 $this->spOffsets = $spOffsets;
367 $this->spTypes = $spTypes;
368
369 break;
370 case SpContainer::class:
371 // initialize
372 $data = '';
373
374 // build the data
375
376 // write group shape record, if necessary?
377 if ($this->object->/** @scrutinizer ignore-call */ getSpgr()) {
378 $recVer = 0x1;
379 $recInstance = 0x0000;
380 $recType = 0xF009;
381 $length = 0x00000010;
382
383 $recVerInstance = $recVer;
384 $recVerInstance |= $recInstance << 4;
385
386 $header = pack('vvV', $recVerInstance, $recType, $length);
387
388 $data .= $header . pack('VVVV', 0, 0, 0, 0);
389 }
390 /** @scrutinizer ignore-call */
391 $this->spTypes[] = ($this->object->getSpType());
392
393 // write the shape record
394 $recVer = 0x2;
395 /** @scrutinizer ignore-call */
396 $recInstance = $this->object->getSpType(); // shape type
397 $recType = 0xF00A;
398 $length = 0x00000008;
399
400 $recVerInstance = $recVer;
401 $recVerInstance |= $recInstance << 4;
402
403 $header = pack('vvV', $recVerInstance, $recType, $length);
404
405 $data .= $header . pack('VV', $this->object->/** @scrutinizer ignore-call */ getSpId(), $this->object->/** @scrutinizer ignore-call */ getSpgr() ? 0x0005 : 0x0A00);
406
407 // the options
408 if ($this->object->/** @scrutinizer ignore-call */ getOPTCollection()) {
409 $optData = '';
410
411 $recVer = 0x3;
412 $recInstance = count($this->object->/** @scrutinizer ignore-call */ getOPTCollection());
413 $recType = 0xF00B;
414 foreach ($this->object->/** @scrutinizer ignore-call */ getOPTCollection() as $property => $value) {
415 $optData .= pack('vV', $property, $value);
416 }
417 $length = strlen($optData);
418
419 $recVerInstance = $recVer;
420 $recVerInstance |= $recInstance << 4;
421
422 $header = pack('vvV', $recVerInstance, $recType, $length);
423 $data .= $header . $optData;
424 }
425
426 // the client anchor
427 if ($this->object->/** @scrutinizer ignore-call */ getStartCoordinates()) {
428 $recVer = 0x0;
429 $recInstance = 0x0;
430 $recType = 0xF010;
431
432 // start coordinates
433 [$column, $row] = Coordinate::indexesFromString($this->object->/** @scrutinizer ignore-call */ getStartCoordinates());
434 $c1 = $column - 1;
435 $r1 = $row - 1;
436
437 // start offsetX
438 /** @scrutinizer ignore-call */
439 $startOffsetX = $this->object->getStartOffsetX();
440
441 // start offsetY
442 /** @scrutinizer ignore-call */
443 $startOffsetY = $this->object->getStartOffsetY();
444
445 // end coordinates
446 [$column, $row] = Coordinate::indexesFromString($this->object->/** @scrutinizer ignore-call */ getEndCoordinates());
447 $c2 = $column - 1;
448 $r2 = $row - 1;
449
450 // end offsetX
451 /** @scrutinizer ignore-call */
452 $endOffsetX = $this->object->getEndOffsetX();
453
454 // end offsetY
455 /** @scrutinizer ignore-call */
456 $endOffsetY = $this->object->getEndOffsetY();
457
458 $clientAnchorData = pack('vvvvvvvvv', $this->object->/** @scrutinizer ignore-call */ getSpFlag(), $c1, $startOffsetX, $r1, $startOffsetY, $c2, $endOffsetX, $r2, $endOffsetY);
459
460 $length = strlen($clientAnchorData);
461
462 $recVerInstance = $recVer;
463 $recVerInstance |= $recInstance << 4;
464
465 $header = pack('vvV', $recVerInstance, $recType, $length);
466 $data .= $header . $clientAnchorData;
467 }
468
469 // the client data, just empty for now
470 if (!$this->object->/** @scrutinizer ignore-call */ getSpgr()) {
471 $clientDataData = '';
472
473 $recVer = 0x0;
474 $recInstance = 0x0;
475 $recType = 0xF011;
476
477 $length = strlen($clientDataData);
478
479 $recVerInstance = $recVer;
480 $recVerInstance |= $recInstance << 4;
481
482 $header = pack('vvV', $recVerInstance, $recType, $length);
483 $data .= $header . $clientDataData;
484 }
485
486 // write the record
487 $recVer = 0xF;
488 $recInstance = 0x0000;
489 $recType = 0xF004;
490 $length = strlen($data);
491
492 $recVerInstance = $recVer;
493 $recVerInstance |= $recInstance << 4;
494
495 $header = pack('vvV', $recVerInstance, $recType, $length);
496
497 $this->data = $header . $data;
498
499 break;
500 }
501
502 return $this->data;
503 }
504
505 /**
506 * Gets the shape offsets.
507 *
508 * @return array
509 */
510 public function getSpOffsets()
511 {
512 return $this->spOffsets;
513 }
514
515 /**
516 * Gets the shape types.
517 *
518 * @return array
519 */
520 public function getSpTypes()
521 {
522 return $this->spTypes;
523 }
524 }
525