3cde46ee6d3507ce61352cbee4d1690ca4f74d47.svn-base 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537
  1. <?php
  2. /**
  3. * PHPExcel
  4. *
  5. * Copyright (c) 2006 - 2014 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 - 2014 PHPExcel (http://www.codeplex.com/PHPExcel)
  24. * @license http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt LGPL
  25. * @version ##VERSION##, ##DATE##
  26. */
  27. /**
  28. * PHPExcel_Shared_Escher_DggContainer_BstoreContainer
  29. *
  30. * @category PHPExcel
  31. * @package PHPExcel_Writer_Excel5
  32. * @copyright Copyright (c) 2006 - 2014 PHPExcel (http://www.codeplex.com/PHPExcel)
  33. */
  34. class PHPExcel_Writer_Excel5_Escher
  35. {
  36. /**
  37. * The object we are writing
  38. */
  39. private $_object;
  40. /**
  41. * The written binary data
  42. */
  43. private $_data;
  44. /**
  45. * Shape offsets. Positions in binary stream where a new shape record begins
  46. *
  47. * @var array
  48. */
  49. private $_spOffsets;
  50. /**
  51. * Shape types.
  52. *
  53. * @var array
  54. */
  55. private $_spTypes;
  56. /**
  57. * Constructor
  58. *
  59. * @param mixed
  60. */
  61. public function __construct($object)
  62. {
  63. $this->_object = $object;
  64. }
  65. /**
  66. * Process the object to be written
  67. */
  68. public function close()
  69. {
  70. // initialize
  71. $this->_data = '';
  72. switch (get_class($this->_object)) {
  73. case 'PHPExcel_Shared_Escher':
  74. if ($dggContainer = $this->_object->getDggContainer()) {
  75. $writer = new PHPExcel_Writer_Excel5_Escher($dggContainer);
  76. $this->_data = $writer->close();
  77. } else if ($dgContainer = $this->_object->getDgContainer()) {
  78. $writer = new PHPExcel_Writer_Excel5_Escher($dgContainer);
  79. $this->_data = $writer->close();
  80. $this->_spOffsets = $writer->getSpOffsets();
  81. $this->_spTypes = $writer->getSpTypes();
  82. }
  83. break;
  84. case 'PHPExcel_Shared_Escher_DggContainer':
  85. // this is a container record
  86. // initialize
  87. $innerData = '';
  88. // write the dgg
  89. $recVer = 0x0;
  90. $recInstance = 0x0000;
  91. $recType = 0xF006;
  92. $recVerInstance = $recVer;
  93. $recVerInstance |= $recInstance << 4;
  94. // dgg data
  95. $dggData =
  96. pack('VVVV'
  97. , $this->_object->getSpIdMax() // maximum shape identifier increased by one
  98. , $this->_object->getCDgSaved() + 1 // number of file identifier clusters increased by one
  99. , $this->_object->getCSpSaved()
  100. , $this->_object->getCDgSaved() // count total number of drawings saved
  101. );
  102. // add file identifier clusters (one per drawing)
  103. $IDCLs = $this->_object->getIDCLs();
  104. foreach ($IDCLs as $dgId => $maxReducedSpId) {
  105. $dggData .= pack('VV', $dgId, $maxReducedSpId + 1);
  106. }
  107. $header = pack('vvV', $recVerInstance, $recType, strlen($dggData));
  108. $innerData .= $header . $dggData;
  109. // write the bstoreContainer
  110. if ($bstoreContainer = $this->_object->getBstoreContainer()) {
  111. $writer = new PHPExcel_Writer_Excel5_Escher($bstoreContainer);
  112. $innerData .= $writer->close();
  113. }
  114. // write the record
  115. $recVer = 0xF;
  116. $recInstance = 0x0000;
  117. $recType = 0xF000;
  118. $length = strlen($innerData);
  119. $recVerInstance = $recVer;
  120. $recVerInstance |= $recInstance << 4;
  121. $header = pack('vvV', $recVerInstance, $recType, $length);
  122. $this->_data = $header . $innerData;
  123. break;
  124. case 'PHPExcel_Shared_Escher_DggContainer_BstoreContainer':
  125. // this is a container record
  126. // initialize
  127. $innerData = '';
  128. // treat the inner data
  129. if ($BSECollection = $this->_object->getBSECollection()) {
  130. foreach ($BSECollection as $BSE) {
  131. $writer = new PHPExcel_Writer_Excel5_Escher($BSE);
  132. $innerData .= $writer->close();
  133. }
  134. }
  135. // write the record
  136. $recVer = 0xF;
  137. $recInstance = count($this->_object->getBSECollection());
  138. $recType = 0xF001;
  139. $length = strlen($innerData);
  140. $recVerInstance = $recVer;
  141. $recVerInstance |= $recInstance << 4;
  142. $header = pack('vvV', $recVerInstance, $recType, $length);
  143. $this->_data = $header . $innerData;
  144. break;
  145. case 'PHPExcel_Shared_Escher_DggContainer_BstoreContainer_BSE':
  146. // this is a semi-container record
  147. // initialize
  148. $innerData = '';
  149. // here we treat the inner data
  150. if ($blip = $this->_object->getBlip()) {
  151. $writer = new PHPExcel_Writer_Excel5_Escher($blip);
  152. $innerData .= $writer->close();
  153. }
  154. // initialize
  155. $data = '';
  156. $btWin32 = $this->_object->getBlipType();
  157. $btMacOS = $this->_object->getBlipType();
  158. $data .= pack('CC', $btWin32, $btMacOS);
  159. $rgbUid = pack('VVVV', 0,0,0,0); // todo
  160. $data .= $rgbUid;
  161. $tag = 0;
  162. $size = strlen($innerData);
  163. $cRef = 1;
  164. $foDelay = 0; //todo
  165. $unused1 = 0x0;
  166. $cbName = 0x0;
  167. $unused2 = 0x0;
  168. $unused3 = 0x0;
  169. $data .= pack('vVVVCCCC', $tag, $size, $cRef, $foDelay, $unused1, $cbName, $unused2, $unused3);
  170. $data .= $innerData;
  171. // write the record
  172. $recVer = 0x2;
  173. $recInstance = $this->_object->getBlipType();
  174. $recType = 0xF007;
  175. $length = strlen($data);
  176. $recVerInstance = $recVer;
  177. $recVerInstance |= $recInstance << 4;
  178. $header = pack('vvV', $recVerInstance, $recType, $length);
  179. $this->_data = $header;
  180. $this->_data .= $data;
  181. break;
  182. case 'PHPExcel_Shared_Escher_DggContainer_BstoreContainer_BSE_Blip':
  183. // this is an atom record
  184. // write the record
  185. switch ($this->_object->getParent()->getBlipType()) {
  186. case PHPExcel_Shared_Escher_DggContainer_BstoreContainer_BSE::BLIPTYPE_JPEG:
  187. // initialize
  188. $innerData = '';
  189. $rgbUid1 = pack('VVVV', 0,0,0,0); // todo
  190. $innerData .= $rgbUid1;
  191. $tag = 0xFF; // todo
  192. $innerData .= pack('C', $tag);
  193. $innerData .= $this->_object->getData();
  194. $recVer = 0x0;
  195. $recInstance = 0x46A;
  196. $recType = 0xF01D;
  197. $length = strlen($innerData);
  198. $recVerInstance = $recVer;
  199. $recVerInstance |= $recInstance << 4;
  200. $header = pack('vvV', $recVerInstance, $recType, $length);
  201. $this->_data = $header;
  202. $this->_data .= $innerData;
  203. break;
  204. case PHPExcel_Shared_Escher_DggContainer_BstoreContainer_BSE::BLIPTYPE_PNG:
  205. // initialize
  206. $innerData = '';
  207. $rgbUid1 = pack('VVVV', 0,0,0,0); // todo
  208. $innerData .= $rgbUid1;
  209. $tag = 0xFF; // todo
  210. $innerData .= pack('C', $tag);
  211. $innerData .= $this->_object->getData();
  212. $recVer = 0x0;
  213. $recInstance = 0x6E0;
  214. $recType = 0xF01E;
  215. $length = strlen($innerData);
  216. $recVerInstance = $recVer;
  217. $recVerInstance |= $recInstance << 4;
  218. $header = pack('vvV', $recVerInstance, $recType, $length);
  219. $this->_data = $header;
  220. $this->_data .= $innerData;
  221. break;
  222. }
  223. break;
  224. case 'PHPExcel_Shared_Escher_DgContainer':
  225. // this is a container record
  226. // initialize
  227. $innerData = '';
  228. // write the dg
  229. $recVer = 0x0;
  230. $recInstance = $this->_object->getDgId();
  231. $recType = 0xF008;
  232. $length = 8;
  233. $recVerInstance = $recVer;
  234. $recVerInstance |= $recInstance << 4;
  235. $header = pack('vvV', $recVerInstance, $recType, $length);
  236. // number of shapes in this drawing (including group shape)
  237. $countShapes = count($this->_object->getSpgrContainer()->getChildren());
  238. $innerData .= $header . pack('VV', $countShapes, $this->_object->getLastSpId());
  239. //$innerData .= $header . pack('VV', 0, 0);
  240. // write the spgrContainer
  241. if ($spgrContainer = $this->_object->getSpgrContainer()) {
  242. $writer = new PHPExcel_Writer_Excel5_Escher($spgrContainer);
  243. $innerData .= $writer->close();
  244. // get the shape offsets relative to the spgrContainer record
  245. $spOffsets = $writer->getSpOffsets();
  246. $spTypes = $writer->getSpTypes();
  247. // save the shape offsets relative to dgContainer
  248. foreach ($spOffsets as & $spOffset) {
  249. $spOffset += 24; // add length of dgContainer header data (8 bytes) plus dg data (16 bytes)
  250. }
  251. $this->_spOffsets = $spOffsets;
  252. $this->_spTypes = $spTypes;
  253. }
  254. // write the record
  255. $recVer = 0xF;
  256. $recInstance = 0x0000;
  257. $recType = 0xF002;
  258. $length = strlen($innerData);
  259. $recVerInstance = $recVer;
  260. $recVerInstance |= $recInstance << 4;
  261. $header = pack('vvV', $recVerInstance, $recType, $length);
  262. $this->_data = $header . $innerData;
  263. break;
  264. case 'PHPExcel_Shared_Escher_DgContainer_SpgrContainer':
  265. // this is a container record
  266. // initialize
  267. $innerData = '';
  268. // initialize spape offsets
  269. $totalSize = 8;
  270. $spOffsets = array();
  271. $spTypes = array();
  272. // treat the inner data
  273. foreach ($this->_object->getChildren() as $spContainer) {
  274. $writer = new PHPExcel_Writer_Excel5_Escher($spContainer);
  275. $spData = $writer->close();
  276. $innerData .= $spData;
  277. // save the shape offsets (where new shape records begin)
  278. $totalSize += strlen($spData);
  279. $spOffsets[] = $totalSize;
  280. $spTypes = array_merge($spTypes, $writer->getSpTypes());
  281. }
  282. // write the record
  283. $recVer = 0xF;
  284. $recInstance = 0x0000;
  285. $recType = 0xF003;
  286. $length = strlen($innerData);
  287. $recVerInstance = $recVer;
  288. $recVerInstance |= $recInstance << 4;
  289. $header = pack('vvV', $recVerInstance, $recType, $length);
  290. $this->_data = $header . $innerData;
  291. $this->_spOffsets = $spOffsets;
  292. $this->_spTypes = $spTypes;
  293. break;
  294. case 'PHPExcel_Shared_Escher_DgContainer_SpgrContainer_SpContainer':
  295. // initialize
  296. $data = '';
  297. // build the data
  298. // write group shape record, if necessary?
  299. if ($this->_object->getSpgr()) {
  300. $recVer = 0x1;
  301. $recInstance = 0x0000;
  302. $recType = 0xF009;
  303. $length = 0x00000010;
  304. $recVerInstance = $recVer;
  305. $recVerInstance |= $recInstance << 4;
  306. $header = pack('vvV', $recVerInstance, $recType, $length);
  307. $data .= $header . pack('VVVV', 0,0,0,0);
  308. }
  309. $this->_spTypes[] = ($this->_object->getSpType());
  310. // write the shape record
  311. $recVer = 0x2;
  312. $recInstance = $this->_object->getSpType(); // shape type
  313. $recType = 0xF00A;
  314. $length = 0x00000008;
  315. $recVerInstance = $recVer;
  316. $recVerInstance |= $recInstance << 4;
  317. $header = pack('vvV', $recVerInstance, $recType, $length);
  318. $data .= $header . pack('VV', $this->_object->getSpId(), $this->_object->getSpgr() ? 0x0005 : 0x0A00);
  319. // the options
  320. if ($this->_object->getOPTCollection()) {
  321. $optData = '';
  322. $recVer = 0x3;
  323. $recInstance = count($this->_object->getOPTCollection());
  324. $recType = 0xF00B;
  325. foreach ($this->_object->getOPTCollection() as $property => $value) {
  326. $optData .= pack('vV', $property, $value);
  327. }
  328. $length = strlen($optData);
  329. $recVerInstance = $recVer;
  330. $recVerInstance |= $recInstance << 4;
  331. $header = pack('vvV', $recVerInstance, $recType, $length);
  332. $data .= $header . $optData;
  333. }
  334. // the client anchor
  335. if ($this->_object->getStartCoordinates()) {
  336. $clientAnchorData = '';
  337. $recVer = 0x0;
  338. $recInstance = 0x0;
  339. $recType = 0xF010;
  340. // start coordinates
  341. list($column, $row) = PHPExcel_Cell::coordinateFromString($this->_object->getStartCoordinates());
  342. $c1 = PHPExcel_Cell::columnIndexFromString($column) - 1;
  343. $r1 = $row - 1;
  344. // start offsetX
  345. $startOffsetX = $this->_object->getStartOffsetX();
  346. // start offsetY
  347. $startOffsetY = $this->_object->getStartOffsetY();
  348. // end coordinates
  349. list($column, $row) = PHPExcel_Cell::coordinateFromString($this->_object->getEndCoordinates());
  350. $c2 = PHPExcel_Cell::columnIndexFromString($column) - 1;
  351. $r2 = $row - 1;
  352. // end offsetX
  353. $endOffsetX = $this->_object->getEndOffsetX();
  354. // end offsetY
  355. $endOffsetY = $this->_object->getEndOffsetY();
  356. $clientAnchorData = pack('vvvvvvvvv', $this->_object->getSpFlag(),
  357. $c1, $startOffsetX, $r1, $startOffsetY,
  358. $c2, $endOffsetX, $r2, $endOffsetY);
  359. $length = strlen($clientAnchorData);
  360. $recVerInstance = $recVer;
  361. $recVerInstance |= $recInstance << 4;
  362. $header = pack('vvV', $recVerInstance, $recType, $length);
  363. $data .= $header . $clientAnchorData;
  364. }
  365. // the client data, just empty for now
  366. if (!$this->_object->getSpgr()) {
  367. $clientDataData = '';
  368. $recVer = 0x0;
  369. $recInstance = 0x0;
  370. $recType = 0xF011;
  371. $length = strlen($clientDataData);
  372. $recVerInstance = $recVer;
  373. $recVerInstance |= $recInstance << 4;
  374. $header = pack('vvV', $recVerInstance, $recType, $length);
  375. $data .= $header . $clientDataData;
  376. }
  377. // write the record
  378. $recVer = 0xF;
  379. $recInstance = 0x0000;
  380. $recType = 0xF004;
  381. $length = strlen($data);
  382. $recVerInstance = $recVer;
  383. $recVerInstance |= $recInstance << 4;
  384. $header = pack('vvV', $recVerInstance, $recType, $length);
  385. $this->_data = $header . $data;
  386. break;
  387. }
  388. return $this->_data;
  389. }
  390. /**
  391. * Gets the shape offsets
  392. *
  393. * @return array
  394. */
  395. public function getSpOffsets()
  396. {
  397. return $this->_spOffsets;
  398. }
  399. /**
  400. * Gets the shape types
  401. *
  402. * @return array
  403. */
  404. public function getSpTypes()
  405. {
  406. return $this->_spTypes;
  407. }
  408. }