HeaderFooterDrawing.php 7.1 KB

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