PageRenderTime 50ms CodeModel.GetById 21ms RepoModel.GetById 0ms app.codeStats 0ms

/add-ons/PHPExcel/PHPExcel/Worksheet/HeaderFooterDrawing.php

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