PageRenderTime 42ms CodeModel.GetById 18ms RepoModel.GetById 0ms app.codeStats 0ms

/common/libraries/plugin/phpexcel/PHPExcel/Worksheet/HeaderFooterDrawing.php

https://bitbucket.org/renaatdemuynck/chamilo
PHP | 377 lines | 159 code | 32 blank | 186 comment | 19 complexity | 24d92669e379721dfcb554c46fc5fac0 MD5 | raw file
Possible License(s): BSD-3-Clause, LGPL-2.1, LGPL-3.0, GPL-3.0, MIT, GPL-2.0
  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_Worksheet
  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. */
  27. /**
  28. * PHPExcel_Worksheet_HeaderFooterDrawing
  29. *
  30. * @category PHPExcel
  31. * @package PHPExcel_Worksheet
  32. * @copyright Copyright (c) 2006 - 2011 PHPExcel (http://www.codeplex.com/PHPExcel)
  33. */
  34. class PHPExcel_Worksheet_HeaderFooterDrawing extends PHPExcel_Worksheet_Drawing implements PHPExcel_IComparable
  35. {
  36. /**
  37. * Path
  38. *
  39. * @var string
  40. */
  41. private $_path;
  42. /**
  43. * Name
  44. *
  45. * @var string
  46. */
  47. protected $_name;
  48. /**
  49. * Offset X
  50. *
  51. * @var int
  52. */
  53. protected $_offsetX;
  54. /**
  55. * Offset Y
  56. *
  57. * @var int
  58. */
  59. protected $_offsetY;
  60. /**
  61. * Width
  62. *
  63. * @var int
  64. */
  65. protected $_width;
  66. /**
  67. * Height
  68. *
  69. * @var int
  70. */
  71. protected $_height;
  72. /**
  73. * Proportional resize
  74. *
  75. * @var boolean
  76. */
  77. protected $_resizeProportional;
  78. /**
  79. * Create a new PHPExcel_Worksheet_HeaderFooterDrawing
  80. */
  81. public function __construct()
  82. {
  83. // Initialise values
  84. $this->_path = '';
  85. $this->_name = '';
  86. $this->_offsetX = 0;
  87. $this->_offsetY = 0;
  88. $this->_width = 0;
  89. $this->_height = 0;
  90. $this->_resizeProportional = true;
  91. }
  92. /**
  93. * Get Name
  94. *
  95. * @return string
  96. */
  97. public function getName()
  98. {
  99. return $this->_name;
  100. }
  101. /**
  102. * Set Name
  103. *
  104. * @param string $pValue
  105. * @return PHPExcel_Worksheet_HeaderFooterDrawing
  106. */
  107. public function setName($pValue = '')
  108. {
  109. $this->_name = $pValue;
  110. return $this;
  111. }
  112. /**
  113. * Get OffsetX
  114. *
  115. * @return int
  116. */
  117. public function getOffsetX()
  118. {
  119. return $this->_offsetX;
  120. }
  121. /**
  122. * Set OffsetX
  123. *
  124. * @param int $pValue
  125. * @return PHPExcel_Worksheet_HeaderFooterDrawing
  126. */
  127. public function setOffsetX($pValue = 0)
  128. {
  129. $this->_offsetX = $pValue;
  130. return $this;
  131. }
  132. /**
  133. * Get OffsetY
  134. *
  135. * @return int
  136. */
  137. public function getOffsetY()
  138. {
  139. return $this->_offsetY;
  140. }
  141. /**
  142. * Set OffsetY
  143. *
  144. * @param int $pValue
  145. * @return PHPExcel_Worksheet_HeaderFooterDrawing
  146. */
  147. public function setOffsetY($pValue = 0)
  148. {
  149. $this->_offsetY = $pValue;
  150. return $this;
  151. }
  152. /**
  153. * Get Width
  154. *
  155. * @return int
  156. */
  157. public function getWidth()
  158. {
  159. return $this->_width;
  160. }
  161. /**
  162. * Set Width
  163. *
  164. * @param int $pValue
  165. * @return PHPExcel_Worksheet_HeaderFooterDrawing
  166. */
  167. public function setWidth($pValue = 0)
  168. {
  169. // Resize proportional?
  170. if ($this->_resizeProportional && $pValue != 0)
  171. {
  172. $ratio = $this->_width / $this->_height;
  173. $this->_height = round($ratio * $pValue);
  174. }
  175. // Set width
  176. $this->_width = $pValue;
  177. return $this;
  178. }
  179. /**
  180. * Get Height
  181. *
  182. * @return int
  183. */
  184. public function getHeight()
  185. {
  186. return $this->_height;
  187. }
  188. /**
  189. * Set Height
  190. *
  191. * @param int $pValue
  192. * @return PHPExcel_Worksheet_HeaderFooterDrawing
  193. */
  194. public function setHeight($pValue = 0)
  195. {
  196. // Resize proportional?
  197. if ($this->_resizeProportional && $pValue != 0)
  198. {
  199. $ratio = $this->_width / $this->_height;
  200. $this->_width = round($ratio * $pValue);
  201. }
  202. // Set height
  203. $this->_height = $pValue;
  204. return $this;
  205. }
  206. /**
  207. * Set width and height with proportional resize
  208. * Example:
  209. * <code>
  210. * $objDrawing->setResizeProportional(true);
  211. * $objDrawing->setWidthAndHeight(160,120);
  212. * </code>
  213. *
  214. * @author Vincent@luo MSN:kele_100@hotmail.com
  215. * @param int $width
  216. * @param int $height
  217. * @return PHPExcel_Worksheet_HeaderFooterDrawing
  218. */
  219. public function setWidthAndHeight($width = 0, $height = 0)
  220. {
  221. $xratio = $width / $this->_width;
  222. $yratio = $height / $this->_height;
  223. if ($this->_resizeProportional && ! ($width == 0 || $height == 0))
  224. {
  225. if (($xratio * $this->_height) < $height)
  226. {
  227. $this->_height = ceil($xratio * $this->_height);
  228. $this->_width = $width;
  229. }
  230. else
  231. {
  232. $this->_width = ceil($yratio * $this->_width);
  233. $this->_height = $height;
  234. }
  235. }
  236. return $this;
  237. }
  238. /**
  239. * Get ResizeProportional
  240. *
  241. * @return boolean
  242. */
  243. public function getResizeProportional()
  244. {
  245. return $this->_resizeProportional;
  246. }
  247. /**
  248. * Set ResizeProportional
  249. *
  250. * @param boolean $pValue
  251. * @return PHPExcel_Worksheet_HeaderFooterDrawing
  252. */
  253. public function setResizeProportional($pValue = true)
  254. {
  255. $this->_resizeProportional = $pValue;
  256. return $this;
  257. }
  258. /**
  259. * Get Filename
  260. *
  261. * @return string
  262. */
  263. public function getFilename()
  264. {
  265. return basename($this->_path);
  266. }
  267. /**
  268. * Get Extension
  269. *
  270. * @return string
  271. */
  272. public function getExtension()
  273. {
  274. $parts = explode(".", basename($this->_path));
  275. return end($parts);
  276. }
  277. /**
  278. * Get Path
  279. *
  280. * @return string
  281. */
  282. public function getPath()
  283. {
  284. return $this->_path;
  285. }
  286. /**
  287. * Set Path
  288. *
  289. * @param string $pValue File path
  290. * @param boolean $pVerifyFile Verify file
  291. * @throws Exception
  292. * @return PHPExcel_Worksheet_HeaderFooterDrawing
  293. */
  294. public function setPath($pValue = '', $pVerifyFile = true)
  295. {
  296. if ($pVerifyFile)
  297. {
  298. if (file_exists($pValue))
  299. {
  300. $this->_path = $pValue;
  301. if ($this->_width == 0 && $this->_height == 0)
  302. {
  303. // Get width/height
  304. list($this->_width, $this->_height) = getimagesize($pValue);
  305. }
  306. }
  307. else
  308. {
  309. throw new Exception("File $pValue not found!");
  310. }
  311. }
  312. else
  313. {
  314. $this->_path = $pValue;
  315. }
  316. return $this;
  317. }
  318. /**
  319. * Get hash code
  320. *
  321. * @return string Hash code
  322. */
  323. public function getHashCode()
  324. {
  325. return md5($this->_path . $this->_name . $this->_offsetX . $this->_offsetY . $this->_width . $this->_height . __CLASS__);
  326. }
  327. /**
  328. * Implement PHP __clone to create a deep clone, not just a shallow copy.
  329. */
  330. public function __clone()
  331. {
  332. $vars = get_object_vars($this);
  333. foreach ($vars as $key => $value)
  334. {
  335. if (is_object($value))
  336. {
  337. $this->$key = clone $value;
  338. }
  339. else
  340. {
  341. $this->$key = $value;
  342. }
  343. }
  344. }
  345. }