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

/branches/v1.6.1/Classes/PHPExcel/Worksheet/HeaderFooterDrawing.php

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