PageRenderTime 25ms CodeModel.GetById 26ms RepoModel.GetById 1ms app.codeStats 0ms

/app/vendors/PHPExcel_deprecated/PHPExcel/Worksheet/BaseDrawing.php

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