For God so loved the world, that He gave His only begotten Son, that all who believe in Him should not perish but have everlasting life
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

361 lines
7.8 KiB

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