1d74f352153d8cbddcb3feb8f5e63548cb0c4806.svn-base 7.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350
  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_HeaderFooterDrawing
  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_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. return $this->_name;
  99. }
  100. /**
  101. * Set Name
  102. *
  103. * @param string $pValue
  104. * @return PHPExcel_Worksheet_HeaderFooterDrawing
  105. */
  106. public function setName($pValue = '') {
  107. $this->_name = $pValue;
  108. return $this;
  109. }
  110. /**
  111. * Get OffsetX
  112. *
  113. * @return int
  114. */
  115. public function getOffsetX() {
  116. return $this->_offsetX;
  117. }
  118. /**
  119. * Set OffsetX
  120. *
  121. * @param int $pValue
  122. * @return PHPExcel_Worksheet_HeaderFooterDrawing
  123. */
  124. public function setOffsetX($pValue = 0) {
  125. $this->_offsetX = $pValue;
  126. return $this;
  127. }
  128. /**
  129. * Get OffsetY
  130. *
  131. * @return int
  132. */
  133. public function getOffsetY() {
  134. return $this->_offsetY;
  135. }
  136. /**
  137. * Set OffsetY
  138. *
  139. * @param int $pValue
  140. * @return PHPExcel_Worksheet_HeaderFooterDrawing
  141. */
  142. public function setOffsetY($pValue = 0) {
  143. $this->_offsetY = $pValue;
  144. return $this;
  145. }
  146. /**
  147. * Get Width
  148. *
  149. * @return int
  150. */
  151. public function getWidth() {
  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. // Resize proportional?
  162. if ($this->_resizeProportional && $pValue != 0) {
  163. $ratio = $this->_width / $this->_height;
  164. $this->_height = round($ratio * $pValue);
  165. }
  166. // Set width
  167. $this->_width = $pValue;
  168. return $this;
  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. * @return PHPExcel_Worksheet_HeaderFooterDrawing
  183. */
  184. public function setHeight($pValue = 0) {
  185. // Resize proportional?
  186. if ($this->_resizeProportional && $pValue != 0) {
  187. $ratio = $this->_width / $this->_height;
  188. $this->_width = round($ratio * $pValue);
  189. }
  190. // Set height
  191. $this->_height = $pValue;
  192. return $this;
  193. }
  194. /**
  195. * Set width and height with proportional resize
  196. * Example:
  197. * <code>
  198. * $objDrawing->setResizeProportional(true);
  199. * $objDrawing->setWidthAndHeight(160,120);
  200. * </code>
  201. *
  202. * @author Vincent@luo MSN:kele_100@hotmail.com
  203. * @param int $width
  204. * @param int $height
  205. * @return PHPExcel_Worksheet_HeaderFooterDrawing
  206. */
  207. public function setWidthAndHeight($width = 0, $height = 0) {
  208. $xratio = $width / $this->_width;
  209. $yratio = $height / $this->_height;
  210. if ($this->_resizeProportional && !($width == 0 || $height == 0)) {
  211. if (($xratio * $this->_height) < $height) {
  212. $this->_height = ceil($xratio * $this->_height);
  213. $this->_width = $width;
  214. } else {
  215. $this->_width = ceil($yratio * $this->_width);
  216. $this->_height = $height;
  217. }
  218. }
  219. return $this;
  220. }
  221. /**
  222. * Get ResizeProportional
  223. *
  224. * @return boolean
  225. */
  226. public function getResizeProportional() {
  227. return $this->_resizeProportional;
  228. }
  229. /**
  230. * Set ResizeProportional
  231. *
  232. * @param boolean $pValue
  233. * @return PHPExcel_Worksheet_HeaderFooterDrawing
  234. */
  235. public function setResizeProportional($pValue = true) {
  236. $this->_resizeProportional = $pValue;
  237. return $this;
  238. }
  239. /**
  240. * Get Filename
  241. *
  242. * @return string
  243. */
  244. public function getFilename() {
  245. return basename($this->_path);
  246. }
  247. /**
  248. * Get Extension
  249. *
  250. * @return string
  251. */
  252. public function getExtension() {
  253. $parts = explode(".", basename($this->_path));
  254. return end($parts);
  255. }
  256. /**
  257. * Get Path
  258. *
  259. * @return string
  260. */
  261. public function getPath() {
  262. return $this->_path;
  263. }
  264. /**
  265. * Set Path
  266. *
  267. * @param string $pValue File path
  268. * @param boolean $pVerifyFile Verify file
  269. * @throws PHPExcel_Exception
  270. * @return PHPExcel_Worksheet_HeaderFooterDrawing
  271. */
  272. public function setPath($pValue = '', $pVerifyFile = true) {
  273. if ($pVerifyFile) {
  274. if (file_exists($pValue)) {
  275. $this->_path = $pValue;
  276. if ($this->_width == 0 && $this->_height == 0) {
  277. // Get width/height
  278. list($this->_width, $this->_height) = getimagesize($pValue);
  279. }
  280. } else {
  281. throw new PHPExcel_Exception("File $pValue not found!");
  282. }
  283. } else {
  284. $this->_path = $pValue;
  285. }
  286. return $this;
  287. }
  288. /**
  289. * Get hash code
  290. *
  291. * @return string Hash code
  292. */
  293. public function getHashCode() {
  294. return md5(
  295. $this->_path
  296. . $this->_name
  297. . $this->_offsetX
  298. . $this->_offsetY
  299. . $this->_width
  300. . $this->_height
  301. . __CLASS__
  302. );
  303. }
  304. /**
  305. * Implement PHP __clone to create a deep clone, not just a shallow copy.
  306. */
  307. public function __clone() {
  308. $vars = get_object_vars($this);
  309. foreach ($vars as $key => $value) {
  310. if (is_object($value)) {
  311. $this->$key = clone $value;
  312. } else {
  313. $this->$key = $value;
  314. }
  315. }
  316. }
  317. }