PageRenderTime 43ms CodeModel.GetById 14ms RepoModel.GetById 0ms app.codeStats 0ms

/branches/v1.6.5/Classes/PHPExcel/Worksheet/Drawing.php

#
PHP | 188 lines | 65 code | 20 blank | 103 comment | 10 complexity | 352e79ddc3dee9f5cd2753d794b0af9b 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 - 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_Drawing
  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 ##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_Shadow */
  34. require_once 'PHPExcel/Worksheet/Drawing/Shadow.php';
  35. /**
  36. * PHPExcel_Worksheet_Drawing
  37. *
  38. * @category PHPExcel
  39. * @package PHPExcel_Worksheet_Drawing
  40. * @copyright Copyright (c) 2006 - 2009 PHPExcel (http://www.codeplex.com/PHPExcel)
  41. */
  42. class PHPExcel_Worksheet_Drawing extends PHPExcel_Worksheet_BaseDrawing implements PHPExcel_IComparable
  43. {
  44. /**
  45. * Path
  46. *
  47. * @var string
  48. */
  49. private $_path;
  50. /**
  51. * Create a new PHPExcel_Worksheet_Drawing
  52. */
  53. public function __construct()
  54. {
  55. // Initialise values
  56. $this->_path = '';
  57. // Initialize parent
  58. parent::__construct();
  59. }
  60. /**
  61. * Get Filename
  62. *
  63. * @return string
  64. */
  65. public function getFilename() {
  66. return basename($this->_path);
  67. }
  68. /**
  69. * Get indexed filename (using image index)
  70. *
  71. * @return string
  72. */
  73. public function getIndexedFilename() {
  74. return str_replace('.' . $this->getExtension(), '', $this->getFilename()) . $this->getImageIndex() . '.' . $this->getExtension();
  75. }
  76. /**
  77. * Get Extension
  78. *
  79. * @return string
  80. */
  81. public function getExtension() {
  82. $exploded = explode(".", basename($this->_path));
  83. return $exploded[count($exploded) - 1];
  84. }
  85. /**
  86. * Get Path
  87. *
  88. * @return string
  89. */
  90. public function getPath() {
  91. return $this->_path;
  92. }
  93. /**
  94. * Set Path
  95. *
  96. * @param string $pValue File path
  97. * @param boolean $pVerifyFile Verify file
  98. * @throws Exception
  99. */
  100. public function setPath($pValue = '', $pVerifyFile = true) {
  101. if ($pVerifyFile) {
  102. if (file_exists($pValue)) {
  103. $this->_path = $pValue;
  104. if ($this->_width == 0 && $this->_height == 0) {
  105. // Get width/height
  106. list($this->_width, $this->_height) = getimagesize($pValue);
  107. }
  108. } else {
  109. throw new Exception("File $pValue not found!");
  110. }
  111. } else {
  112. $this->_path = $pValue;
  113. }
  114. }
  115. /**
  116. * Get hash code
  117. *
  118. * @return string Hash code
  119. */
  120. public function getHashCode() {
  121. return md5(
  122. $this->_path
  123. . parent::getHashCode()
  124. . __CLASS__
  125. );
  126. }
  127. /**
  128. * Hash index
  129. *
  130. * @var string
  131. */
  132. private $_hashIndex;
  133. /**
  134. * Get hash index
  135. *
  136. * Note that this index may vary during script execution! Only reliable moment is
  137. * while doing a write of a workbook and when changes are not allowed.
  138. *
  139. * @return string Hash index
  140. */
  141. public function getHashIndex() {
  142. return $this->_hashIndex;
  143. }
  144. /**
  145. * Set hash index
  146. *
  147. * Note that this index may vary during script execution! Only reliable moment is
  148. * while doing a write of a workbook and when changes are not allowed.
  149. *
  150. * @param string $value Hash index
  151. */
  152. public function setHashIndex($value) {
  153. $this->_hashIndex = $value;
  154. }
  155. /**
  156. * Implement PHP __clone to create a deep clone, not just a shallow copy.
  157. */
  158. public function __clone() {
  159. $vars = get_object_vars($this);
  160. foreach ($vars as $key => $value) {
  161. if (is_object($value)) {
  162. $this->$key = clone $value;
  163. } else {
  164. $this->$key = $value;
  165. }
  166. }
  167. }
  168. }