File Source for Escher.php

PHPExcel_Writer_Excel5

# Source for file Escher.php

Documentation is available at Escher.php

1. <?php
2. /**
3. * PHPExcel
4. *
5. * Copyright (c) 2006 - 2011 PHPExcel
6. *
7. * This library is free software; you can redistribute it and/or
8. * modify it under the terms of the GNU Lesser General Public
9. * License as published by the Free Software Foundation; either
10. * version 2.1 of the License, or (at your option) any later version.
11. *
12. * This library is distributed in the hope that it will be useful,
13. * but WITHOUT ANY WARRANTY; without even the implied warranty of
14. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15. * Lesser General Public License for more details.
16. *
17. * You should have received a copy of the GNU Lesser General Public
18. * License along with this library; if not, write to the Free Software
19. * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
20. *
21. * @category PHPExcel
22. * @package PHPExcel_Writer_Excel5
23. * @copyright Copyright (c) 2006 - 2011 PHPExcel (http://www.codeplex.com/PHPExcel)
24. * @license http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt LGPL
25. * @version 1.7.6, 2011-02-27
26. */
29. /**
30. * PHPExcel_Shared_Escher_DggContainer_BstoreContainer
31. *
32. * @category PHPExcel
33. * @package PHPExcel_Writer_Excel5
34. * @copyright Copyright (c) 2006 - 2011 PHPExcel (http://www.codeplex.com/PHPExcel)
35. */
36. class PHPExcel_Writer_Excel5_Escher
37. {
38. /**
39. * The object we are writing
40. */
41. private $_object;
43. /**
44. * The written binary data
45. */
46. private $_data;
48. /**
49. * Shape offsets. Positions in binary stream where a new shape record begins
50. *
51. * @var array
52. */
53. private $_spOffsets;
56. /**
57. * Constructor
58. *
59. * @param mixed
60. */
61. public function __construct($object)
62. {
63. $this->_object = $object;
64. }
66. /**
67. * Process the object to be written
68. */
69. public function close()
70. {
71. // initialize
72. $this->_data = '';
74. switch ( get_class($this->_object)) {
76. case 'PHPExcel_Shared_Escher':
77. if ($dggContainer = $this->_object->getDggContainer()) {
78. $writer = new PHPExcel_Writer_Excel5_Escher($dggContainer);
79. $this->_data = $writer->close();
80. } else if ($dgContainer = $this->_object->getDgContainer()) {
81. $writer = new PHPExcel_Writer_Excel5_Escher($dgContainer);
82. $this->_data = $writer->close();
83. $this->_spOffsets = $writer->getSpOffsets();
84. }
85. break;
87. case 'PHPExcel_Shared_Escher_DggContainer':
88. // this is a container record
90. // initialize
91. $innerData = '';
93. // write the dgg
94. $recVer = 0x0;
95. $recInstance = 0x0000;
96. $recType = 0xF006;
98. $recVerInstance = $recVer;
99. $recVerInstance |= $recInstance << 4;
101. // dgg data
102. $dggData =
103. pack('VVVV'
104. , $this->_object->getSpIdMax() // maximum shape identifier increased by one
105. , $this->_object->getCDgSaved() + 1 // number of file identifier clusters increased by one
106. , $this->_object->getCSpSaved()
107. , $this->_object->getCDgSaved() // count total number of drawings saved
108. );
110. // add file identifier clusters (one per drawing)
111. $IDCLs = $this->_object->getIDCLs();
113. foreach ($IDCLs as $dgId => $maxReducedSpId) {
114. $dggData .= pack('VV', $dgId, $maxReducedSpId + 1);
115. }
117. $header = pack('vvV', $recVerInstance, $recType, strlen($dggData));
118. $innerData .= $header . $dggData;
120. // write the bstoreContainer
121. if ($bstoreContainer = $this->_object->getBstoreContainer()) {
122. $writer = new PHPExcel_Writer_Excel5_Escher($bstoreContainer);
123. $innerData .= $writer->close();
124. }
126. // write the record
127. $recVer = 0xF;
128. $recInstance = 0x0000;
129. $recType = 0xF000;
130. $length = strlen($innerData);
132. $recVerInstance = $recVer;
133. $recVerInstance |= $recInstance << 4;
135. $header = pack('vvV', $recVerInstance, $recType, $length);
137. $this->_data = $header . $innerData;
138. break;
140. case 'PHPExcel_Shared_Escher_DggContainer_BstoreContainer':
141. // this is a container record
143. // initialize
144. $innerData = '';
146. // treat the inner data
147. if ($BSECollection = $this->_object->getBSECollection()) {
148. foreach ($BSECollection as $BSE) {
149. $writer = new PHPExcel_Writer_Excel5_Escher($BSE);
150. $innerData .= $writer->close();
151. }
152. }
154. // write the record
155. $recVer = 0xF;
156. $recInstance = count($this->_object->getBSECollection());
157. $recType = 0xF001;
158. $length = strlen($innerData);
160. $recVerInstance = $recVer;
161. $recVerInstance |= $recInstance << 4;
163. $header = pack('vvV', $recVerInstance, $recType, $length);
165. $this->_data = $header . $innerData;
166. break;
168. case 'PHPExcel_Shared_Escher_DggContainer_BstoreContainer_BSE':
169. // this is a semi-container record
171. // initialize
172. $innerData = '';
174. // here we treat the inner data
175. if ($blip = $this->_object->getBlip()) {
176. $writer = new PHPExcel_Writer_Excel5_Escher($blip);
177. $innerData .= $writer->close();
178. }
180. // initialize
181. $data = '';
183. $btWin32 = $this->_object->getBlipType();
184. $btMacOS = $this->_object->getBlipType();
185. $data .= pack('CC', $btWin32, $btMacOS);
187. $rgbUid = pack('VVVV', 0,0,0,0); // todo
188. $data .= $rgbUid;
190. $tag = 0;
191. $size = strlen($innerData);
192. $cRef = 1;
193. $foDelay = 0; //todo
194. $unused1 = 0x0;
195. $cbName = 0x0;
196. $unused2 = 0x0;
197. $unused3 = 0x0;
198. $data .= pack('vVVVCCCC', $tag, $size, $cRef, $foDelay, $unused1, $cbName, $unused2, $unused3);
200. $data .= $innerData;
202. // write the record
203. $recVer = 0x2;
204. $recInstance = $this->_object->getBlipType();
205. $recType = 0xF007;
206. $length = strlen($data);
208. $recVerInstance = $recVer;
209. $recVerInstance |= $recInstance << 4;
211. $header = pack('vvV', $recVerInstance, $recType, $length);
213. $this->_data = $header;
215. $this->_data .= $data;
216. break;
218. case 'PHPExcel_Shared_Escher_DggContainer_BstoreContainer_BSE_Blip':
219. // this is an atom record
221. // write the record
222. switch ($this->_object->getParent()->getBlipType()) {
224. case PHPExcel_Shared_Escher_DggContainer_BstoreContainer_BSE:: BLIPTYPE_JPEG:
225. // initialize
226. $innerData = '';
228. $rgbUid1 = pack('VVVV', 0,0,0,0); // todo
229. $innerData .= $rgbUid1;
231. $tag = 0xFF; // todo
232. $innerData .= pack('C', $tag);
234. $innerData .= $this->_object->getData();
236. $recVer = 0x0;
237. $recInstance = 0x46A;
238. $recType = 0xF01D;
239. $length = strlen($innerData);
241. $recVerInstance = $recVer;
242. $recVerInstance |= $recInstance << 4;
244. $header = pack('vvV', $recVerInstance, $recType, $length);
246. $this->_data = $header;
248. $this->_data .= $innerData;
249. break;
251. case PHPExcel_Shared_Escher_DggContainer_BstoreContainer_BSE:: BLIPTYPE_PNG:
252. // initialize
253. $innerData = '';
255. $rgbUid1 = pack('VVVV', 0,0,0,0); // todo
256. $innerData .= $rgbUid1;
258. $tag = 0xFF; // todo
259. $innerData .= pack('C', $tag);
261. $innerData .= $this->_object->getData();
263. $recVer = 0x0;
264. $recInstance = 0x6E0;
265. $recType = 0xF01E;
266. $length = strlen($innerData);
268. $recVerInstance = $recVer;
269. $recVerInstance |= $recInstance << 4;
271. $header = pack('vvV', $recVerInstance, $recType, $length);
273. $this->_data = $header;
275. $this->_data .= $innerData;
276. break;
278. }
279. break;
281. case 'PHPExcel_Shared_Escher_DgContainer':
282. // this is a container record
284. // initialize
285. $innerData = '';
287. // write the dg
288. $recVer = 0x0;
289. $recInstance = $this->_object->getDgId();
290. $recType = 0xF008;
291. $length = 8;
293. $recVerInstance = $recVer;
294. $recVerInstance |= $recInstance << 4;
296. $header = pack('vvV', $recVerInstance, $recType, $length);
298. // number of shapes in this drawing (including group shape)
299. $countShapes = count($this->_object->getSpgrContainer()->getChildren());
300. $innerData .= $header . pack('VV', $countShapes, $this->_object->getLastSpId());
301. //$innerData .= $header . pack('VV', 0, 0);
303. // write the spgrContainer
304. if ($spgrContainer = $this->_object->getSpgrContainer()) {
305. $writer = new PHPExcel_Writer_Excel5_Escher($spgrContainer);
306. $innerData .= $writer->close();
308. // get the shape offsets relative to the spgrContainer record
309. $spOffsets = $writer->getSpOffsets();
311. // save the shape offsets relative to dgContainer
312. foreach ($spOffsets as & $spOffset) {
313. $spOffset += 24; // add length of dgContainer header data (8 bytes) plus dg data (16 bytes)
314. }
316. $this->_spOffsets = $spOffsets;
317. }
319. // write the record
320. $recVer = 0xF;
321. $recInstance = 0x0000;
322. $recType = 0xF002;
323. $length = strlen($innerData);
325. $recVerInstance = $recVer;
326. $recVerInstance |= $recInstance << 4;
328. $header = pack('vvV', $recVerInstance, $recType, $length);
330. $this->_data = $header . $innerData;
331. break;
333. case 'PHPExcel_Shared_Escher_DgContainer_SpgrContainer':
334. // this is a container record
336. // initialize
337. $innerData = '';
339. // initialize spape offsets
340. $totalSize = 8;
341. $spOffsets = array();
343. // treat the inner data
344. foreach ($this->_object->getChildren() as $spContainer) {
345. $writer = new PHPExcel_Writer_Excel5_Escher($spContainer);
346. $spData = $writer->close();
347. $innerData .= $spData;
349. // save the shape offsets (where new shape records begin)
350. $totalSize += strlen($spData);
351. $spOffsets[] = $totalSize;
352. }
354. // write the record
355. $recVer = 0xF;
356. $recInstance = 0x0000;
357. $recType = 0xF003;
358. $length = strlen($innerData);
360. $recVerInstance = $recVer;
361. $recVerInstance |= $recInstance << 4;
363. $header = pack('vvV', $recVerInstance, $recType, $length);
365. $this->_data = $header . $innerData;
366. $this->_spOffsets = $spOffsets;
367. break;
369. case 'PHPExcel_Shared_Escher_DgContainer_SpgrContainer_SpContainer':
370. // initialize
371. $data = '';
373. // build the data
375. // write group shape record, if necessary?
376. if ($this->_object->getSpgr()) {
377. $recVer = 0x1;
378. $recInstance = 0x0000;
379. $recType = 0xF009;
380. $length = 0x00000010;
382. $recVerInstance = $recVer;
383. $recVerInstance |= $recInstance << 4;
385. $header = pack('vvV', $recVerInstance, $recType, $length);
387. $data .= $header . pack('VVVV', 0,0,0,0);
388. }
390. // write the shape record
391. $recVer = 0x2;
392. $recInstance = $this->_object->getSpType(); // shape type
393. $recType = 0xF00A;
394. $length = 0x00000008;
396. $recVerInstance = $recVer;
397. $recVerInstance |= $recInstance << 4;
399. $header = pack('vvV', $recVerInstance, $recType, $length);
401. $data .= $header . pack('VV', $this->_object->getSpId(), $this->_object->getSpgr() ? 0x0005 : 0x0A00);
404. // the options
405. if ($this->_object->getOPTCollection()) {
406. $optData = '';
408. $recVer = 0x3;
409. $recInstance = count($this->_object->getOPTCollection());
410. $recType = 0xF00B;
411. foreach ($this->_object->getOPTCollection() as $property => $value) {
412. $optData .= pack('vV', $property, $value);
413. }
414. $length = strlen($optData);
416. $recVerInstance = $recVer;
417. $recVerInstance |= $recInstance << 4;
419. $header = pack('vvV', $recVerInstance, $recType, $length);
420. $data .= $header . $optData;
421. }
423. // the client anchor
424. if ($this->_object->getStartCoordinates()) {
425. $clientAnchorData = '';
427. $recVer = 0x0;
428. $recInstance = 0x0;
429. $recType = 0xF010;
431. // start coordinates
432. list($column, $row) = PHPExcel_Cell:: coordinateFromString($this->_object->getStartCoordinates());
433. $c1 = PHPExcel_Cell:: columnIndexFromString($column) - 1;
434. $r1 = $row - 1;
436. // start offsetX
437. $startOffsetX = $this->_object->getStartOffsetX();
439. // start offsetY
440. $startOffsetY = $this->_object->getStartOffsetY();
442. // end coordinates
443. list($column, $row) = PHPExcel_Cell:: coordinateFromString($this->_object->getEndCoordinates());
444. $c2 = PHPExcel_Cell:: columnIndexFromString($column) - 1;
445. $r2 = $row - 1;
447. // end offsetX
448. $endOffsetX = $this->_object->getEndOffsetX();
450. // end offsetY
451. $endOffsetY = $this->_object->getEndOffsetY();
453. $clientAnchorData = pack('vvvvvvvvv', 0x02,
454. $c1, $startOffsetX, $r1, $startOffsetY,
455. $c2, $endOffsetX, $r2, $endOffsetY);
457. $length = strlen($clientAnchorData);
459. $recVerInstance = $recVer;
460. $recVerInstance |= $recInstance << 4;
462. $header = pack('vvV', $recVerInstance, $recType, $length);
463. $data .= $header . $clientAnchorData;
464. }
466. // the client data, just empty for now
467. if (!$this->_object->getSpgr()) {
468. $clientDataData = '';
470. $recVer = 0x0;
471. $recInstance = 0x0;
472. $recType = 0xF011;
474. $length = strlen($clientDataData);
476. $recVerInstance = $recVer;
477. $recVerInstance |= $recInstance << 4;
479. $header = pack('vvV', $recVerInstance, $recType, $length);
480. $data .= $header . $clientDataData;
481. }
483. // write the record
484. $recVer = 0xF;
485. $recInstance = 0x0000;
486. $recType = 0xF004;
487. $length = strlen($data);
489. $recVerInstance = $recVer;
490. $recVerInstance |= $recInstance << 4;
492. $header = pack('vvV', $recVerInstance, $recType, $length);
494. $this->_data = $header . $data;
495. break;
497. }
499. return $this->_data;
500. }
502. /**
503. * Gets the shape offsets
504. *
505. * @return array
506. */
507. public function getSpOffsets()
508. {
509. return $this->_spOffsets;
510. }
512. }

Documentation generated on Sun, 27 Feb 2011 16:30:39 -0800 by phpDocumentor 1.4.3