PageRenderTime 51ms CodeModel.GetById 23ms RepoModel.GetById 0ms app.codeStats 0ms

/vendor/phpoffice/phpexcel/Classes/PHPExcel/Worksheet/BaseDrawing.php

https://gitlab.com/techniconline/kmc
PHP | 515 lines | 207 code | 49 blank | 259 comment | 27 complexity | 49124cbfa938ca88658e75992add41aa MD5 | raw file
  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_Worksheet
  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_Worksheet_BaseDrawing
  29. *
  30. * @category PHPExcel
  31. * @package PHPExcel_Worksheet
  32. * @copyright Copyright (c) 2006 - 2014 PHPExcel (http://www.codeplex.com/PHPExcel)
  33. */
  34. class PHPExcel_Worksheet_BaseDrawing implements PHPExcel_IComparable
  35. {
  36. /**
  37. * Image counter
  38. *
  39. * @var int
  40. */
  41. private static $_imageCounter = 0;
  42. /**
  43. * Image index
  44. *
  45. * @var int
  46. */
  47. private $_imageIndex = 0;
  48. /**
  49. * Name
  50. *
  51. * @var string
  52. */
  53. protected $_name;
  54. /**
  55. * Description
  56. *
  57. * @var string
  58. */
  59. protected $_description;
  60. /**
  61. * Worksheet
  62. *
  63. * @var PHPExcel_Worksheet
  64. */
  65. protected $_worksheet;
  66. /**
  67. * Coordinates
  68. *
  69. * @var string
  70. */
  71. protected $_coordinates;
  72. /**
  73. * Offset X
  74. *
  75. * @var int
  76. */
  77. protected $_offsetX;
  78. /**
  79. * Offset Y
  80. *
  81. * @var int
  82. */
  83. protected $_offsetY;
  84. /**
  85. * Width
  86. *
  87. * @var int
  88. */
  89. protected $_width;
  90. /**
  91. * Height
  92. *
  93. * @var int
  94. */
  95. protected $_height;
  96. /**
  97. * Proportional resize
  98. *
  99. * @var boolean
  100. */
  101. protected $_resizeProportional;
  102. /**
  103. * Rotation
  104. *
  105. * @var int
  106. */
  107. protected $_rotation;
  108. /**
  109. * Shadow
  110. *
  111. * @var PHPExcel_Worksheet_Drawing_Shadow
  112. */
  113. protected $_shadow;
  114. /**
  115. * Create a new PHPExcel_Worksheet_BaseDrawing
  116. */
  117. public function __construct()
  118. {
  119. // Initialise values
  120. $this->_name = '';
  121. $this->_description = '';
  122. $this->_worksheet = null;
  123. $this->_coordinates = 'A1';
  124. $this->_offsetX = 0;
  125. $this->_offsetY = 0;
  126. $this->_width = 0;
  127. $this->_height = 0;
  128. $this->_resizeProportional = true;
  129. $this->_rotation = 0;
  130. $this->_shadow = new PHPExcel_Worksheet_Drawing_Shadow();
  131. // Set image index
  132. self::$_imageCounter++;
  133. $this->_imageIndex = self::$_imageCounter;
  134. }
  135. /**
  136. * Get image index
  137. *
  138. * @return int
  139. */
  140. public function getImageIndex()
  141. {
  142. return $this->_imageIndex;
  143. }
  144. /**
  145. * Get Name
  146. *
  147. * @return string
  148. */
  149. public function getName()
  150. {
  151. return $this->_name;
  152. }
  153. /**
  154. * Set Name
  155. *
  156. * @param string $pValue
  157. * @return PHPExcel_Worksheet_BaseDrawing
  158. */
  159. public function setName($pValue = '')
  160. {
  161. $this->_name = $pValue;
  162. return $this;
  163. }
  164. /**
  165. * Get Description
  166. *
  167. * @return string
  168. */
  169. public function getDescription()
  170. {
  171. return $this->_description;
  172. }
  173. /**
  174. * Set Description
  175. *
  176. * @param string $pValue
  177. * @return PHPExcel_Worksheet_BaseDrawing
  178. */
  179. public function setDescription($pValue = '')
  180. {
  181. $this->_description = $pValue;
  182. return $this;
  183. }
  184. /**
  185. * Get Worksheet
  186. *
  187. * @return PHPExcel_Worksheet
  188. */
  189. public function getWorksheet()
  190. {
  191. return $this->_worksheet;
  192. }
  193. /**
  194. * Set Worksheet
  195. *
  196. * @param PHPExcel_Worksheet $pValue
  197. * @param bool $pOverrideOld If a Worksheet has already been assigned, overwrite it and remove image from old Worksheet?
  198. * @throws PHPExcel_Exception
  199. * @return PHPExcel_Worksheet_BaseDrawing
  200. */
  201. public function setWorksheet(PHPExcel_Worksheet $pValue = null, $pOverrideOld = false)
  202. {
  203. if (is_null($this->_worksheet)) {
  204. // Add drawing to PHPExcel_Worksheet
  205. $this->_worksheet = $pValue;
  206. $this->_worksheet->getCell($this->_coordinates);
  207. $this->_worksheet->getDrawingCollection()->append($this);
  208. } else {
  209. if ($pOverrideOld) {
  210. // Remove drawing from old PHPExcel_Worksheet
  211. $iterator = $this->_worksheet->getDrawingCollection()->getIterator();
  212. while ($iterator->valid()) {
  213. if ($iterator->current()->getHashCode() == $this->getHashCode()) {
  214. $this->_worksheet->getDrawingCollection()->offsetUnset($iterator->key());
  215. $this->_worksheet = null;
  216. break;
  217. }
  218. }
  219. // Set new PHPExcel_Worksheet
  220. $this->setWorksheet($pValue);
  221. } else {
  222. throw new PHPExcel_Exception("A PHPExcel_Worksheet has already been assigned. Drawings can only exist on one PHPExcel_Worksheet.");
  223. }
  224. }
  225. return $this;
  226. }
  227. /**
  228. * Get Coordinates
  229. *
  230. * @return string
  231. */
  232. public function getCoordinates()
  233. {
  234. return $this->_coordinates;
  235. }
  236. /**
  237. * Set Coordinates
  238. *
  239. * @param string $pValue
  240. * @return PHPExcel_Worksheet_BaseDrawing
  241. */
  242. public function setCoordinates($pValue = 'A1')
  243. {
  244. $this->_coordinates = $pValue;
  245. return $this;
  246. }
  247. /**
  248. * Get OffsetX
  249. *
  250. * @return int
  251. */
  252. public function getOffsetX()
  253. {
  254. return $this->_offsetX;
  255. }
  256. /**
  257. * Set OffsetX
  258. *
  259. * @param int $pValue
  260. * @return PHPExcel_Worksheet_BaseDrawing
  261. */
  262. public function setOffsetX($pValue = 0)
  263. {
  264. $this->_offsetX = $pValue;
  265. return $this;
  266. }
  267. /**
  268. * Get OffsetY
  269. *
  270. * @return int
  271. */
  272. public function getOffsetY()
  273. {
  274. return $this->_offsetY;
  275. }
  276. /**
  277. * Set OffsetY
  278. *
  279. * @param int $pValue
  280. * @return PHPExcel_Worksheet_BaseDrawing
  281. */
  282. public function setOffsetY($pValue = 0)
  283. {
  284. $this->_offsetY = $pValue;
  285. return $this;
  286. }
  287. /**
  288. * Get Width
  289. *
  290. * @return int
  291. */
  292. public function getWidth()
  293. {
  294. return $this->_width;
  295. }
  296. /**
  297. * Set Width
  298. *
  299. * @param int $pValue
  300. * @return PHPExcel_Worksheet_BaseDrawing
  301. */
  302. public function setWidth($pValue = 0)
  303. {
  304. // Resize proportional?
  305. if ($this->_resizeProportional && $pValue != 0) {
  306. $ratio = $this->_height / ($this->_width != 0 ? $this->_width : 1);
  307. $this->_height = round($ratio * $pValue);
  308. }
  309. // Set width
  310. $this->_width = $pValue;
  311. return $this;
  312. }
  313. /**
  314. * Get Height
  315. *
  316. * @return int
  317. */
  318. public function getHeight()
  319. {
  320. return $this->_height;
  321. }
  322. /**
  323. * Set Height
  324. *
  325. * @param int $pValue
  326. * @return PHPExcel_Worksheet_BaseDrawing
  327. */
  328. public function setHeight($pValue = 0)
  329. {
  330. // Resize proportional?
  331. if ($this->_resizeProportional && $pValue != 0) {
  332. $ratio = $this->_width / ($this->_height != 0 ? $this->_height : 1);
  333. $this->_width = round($ratio * $pValue);
  334. }
  335. // Set height
  336. $this->_height = $pValue;
  337. return $this;
  338. }
  339. /**
  340. * Set width and height with proportional resize
  341. * Example:
  342. * <code>
  343. * $objDrawing->setResizeProportional(true);
  344. * $objDrawing->setWidthAndHeight(160,120);
  345. * </code>
  346. *
  347. * @author Vincent@luo MSN:kele_100@hotmail.com
  348. * @param int $width
  349. * @param int $height
  350. * @return PHPExcel_Worksheet_BaseDrawing
  351. */
  352. public function setWidthAndHeight($width = 0, $height = 0)
  353. {
  354. $xratio = $width / ($this->_width != 0 ? $this->_width : 1);
  355. $yratio = $height / ($this->_height != 0 ? $this->_height : 1);
  356. if ($this->_resizeProportional && !($width == 0 || $height == 0)) {
  357. if (($xratio * $this->_height) < $height) {
  358. $this->_height = ceil($xratio * $this->_height);
  359. $this->_width = $width;
  360. } else {
  361. $this->_width = ceil($yratio * $this->_width);
  362. $this->_height = $height;
  363. }
  364. } else {
  365. $this->_width = $width;
  366. $this->_height = $height;
  367. }
  368. return $this;
  369. }
  370. /**
  371. * Get ResizeProportional
  372. *
  373. * @return boolean
  374. */
  375. public function getResizeProportional()
  376. {
  377. return $this->_resizeProportional;
  378. }
  379. /**
  380. * Set ResizeProportional
  381. *
  382. * @param boolean $pValue
  383. * @return PHPExcel_Worksheet_BaseDrawing
  384. */
  385. public function setResizeProportional($pValue = true)
  386. {
  387. $this->_resizeProportional = $pValue;
  388. return $this;
  389. }
  390. /**
  391. * Get Rotation
  392. *
  393. * @return int
  394. */
  395. public function getRotation()
  396. {
  397. return $this->_rotation;
  398. }
  399. /**
  400. * Set Rotation
  401. *
  402. * @param int $pValue
  403. * @return PHPExcel_Worksheet_BaseDrawing
  404. */
  405. public function setRotation($pValue = 0)
  406. {
  407. $this->_rotation = $pValue;
  408. return $this;
  409. }
  410. /**
  411. * Get Shadow
  412. *
  413. * @return PHPExcel_Worksheet_Drawing_Shadow
  414. */
  415. public function getShadow()
  416. {
  417. return $this->_shadow;
  418. }
  419. /**
  420. * Set Shadow
  421. *
  422. * @param PHPExcel_Worksheet_Drawing_Shadow $pValue
  423. * @throws PHPExcel_Exception
  424. * @return PHPExcel_Worksheet_BaseDrawing
  425. */
  426. public function setShadow(PHPExcel_Worksheet_Drawing_Shadow $pValue = null)
  427. {
  428. $this->_shadow = $pValue;
  429. return $this;
  430. }
  431. /**
  432. * Get hash code
  433. *
  434. * @return string Hash code
  435. */
  436. public function getHashCode()
  437. {
  438. return md5(
  439. $this->_name
  440. . $this->_description
  441. . $this->_worksheet->getHashCode()
  442. . $this->_coordinates
  443. . $this->_offsetX
  444. . $this->_offsetY
  445. . $this->_width
  446. . $this->_height
  447. . $this->_rotation
  448. . $this->_shadow->getHashCode()
  449. . __CLASS__
  450. );
  451. }
  452. /**
  453. * Implement PHP __clone to create a deep clone, not just a shallow copy.
  454. */
  455. public function __clone()
  456. {
  457. $vars = get_object_vars($this);
  458. foreach ($vars as $key => $value) {
  459. if (is_object($value)) {
  460. $this->$key = clone $value;
  461. } else {
  462. $this->$key = $value;
  463. }
  464. }
  465. }
  466. }