PageRenderTime 52ms CodeModel.GetById 24ms RepoModel.GetById 1ms app.codeStats 0ms

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

#
PHP | 238 lines | 82 code | 28 blank | 128 comment | 3 complexity | 82158d5b0499ae26a92404d7b1b886b2 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
  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_MemoryDrawing
  37. *
  38. * @category PHPExcel
  39. * @package PHPExcel_Worksheet
  40. * @copyright Copyright (c) 2006 - 2009 PHPExcel (http://www.codeplex.com/PHPExcel)
  41. */
  42. class PHPExcel_Worksheet_MemoryDrawing extends PHPExcel_Worksheet_BaseDrawing implements PHPExcel_IComparable
  43. {
  44. /* Rendering functions */
  45. const RENDERING_DEFAULT = 'imagepng';
  46. const RENDERING_PNG = 'imagepng';
  47. const RENDERING_GIF = 'imagegif';
  48. const RENDERING_JPEG = 'imagejpeg';
  49. /* MIME types */
  50. const MIMETYPE_DEFAULT = 'image/png';
  51. const MIMETYPE_PNG = 'image/png';
  52. const MIMETYPE_GIF = 'image/gif';
  53. const MIMETYPE_JPEG = 'image/jpeg';
  54. /**
  55. * Image resource
  56. *
  57. * @var resource
  58. */
  59. private $_imageResource;
  60. /**
  61. * Rendering function
  62. *
  63. * @var string
  64. */
  65. private $_renderingFunction;
  66. /**
  67. * Mime type
  68. *
  69. * @var string
  70. */
  71. private $_mimeType;
  72. /**
  73. * Unique name
  74. *
  75. * @var string
  76. */
  77. private $_uniqueName;
  78. /**
  79. * Create a new PHPExcel_Worksheet_MemoryDrawing
  80. */
  81. public function __construct()
  82. {
  83. // Initialise values
  84. $this->_imageResource = null;
  85. $this->_renderingFunction = self::RENDERING_DEFAULT;
  86. $this->_mimeType = self::MIMETYPE_DEFAULT;
  87. $this->_uniqueName = md5(rand(0, 9999). time() . rand(0, 9999));
  88. // Initialize parent
  89. parent::__construct();
  90. }
  91. /**
  92. * Get image resource
  93. *
  94. * @return resource
  95. */
  96. public function getImageResource() {
  97. return $this->_imageResource;
  98. }
  99. /**
  100. * Set image resource
  101. *
  102. * @param $value resource
  103. */
  104. public function setImageResource($value = null) {
  105. $this->_imageResource = $value;
  106. if (!is_null($this->_imageResource)) {
  107. // Get width/height
  108. $this->_width = imagesx($this->_imageResource);
  109. $this->_height = imagesy($this->_imageResource);
  110. }
  111. }
  112. /**
  113. * Get rendering function
  114. *
  115. * @return string
  116. */
  117. public function getRenderingFunction() {
  118. return $this->_renderingFunction;
  119. }
  120. /**
  121. * Set rendering function
  122. *
  123. * @param string $value
  124. */
  125. public function setRenderingFunction($value = PHPExcel_Worksheet_MemoryDrawing::RENDERING_DEFAULT) {
  126. $this->_renderingFunction = $value;
  127. }
  128. /**
  129. * Get mime type
  130. *
  131. * @return string
  132. */
  133. public function getMimeType() {
  134. return $this->_mimeType;
  135. }
  136. /**
  137. * Set mime type
  138. *
  139. * @param string $value
  140. */
  141. public function setMimeType($value = PHPExcel_Worksheet_MemoryDrawing::MIMETYPE_DEFAULT) {
  142. $this->_mimeType = $value;
  143. }
  144. /**
  145. * Get indexed filename (using image index)
  146. *
  147. * @return string
  148. */
  149. public function getIndexedFilename() {
  150. $extension = strtolower($this->getMimeType());
  151. $extension = explode('/', $extension);
  152. $extension = $extension[1];
  153. return $this->_uniqueName . $this->getImageIndex() . '.' . $extension;
  154. }
  155. /**
  156. * Get hash code
  157. *
  158. * @return string Hash code
  159. */
  160. public function getHashCode() {
  161. return md5(
  162. $this->_renderingFunction
  163. . $this->_mimeType
  164. . $this->_uniqueName
  165. . parent::getHashCode()
  166. . __CLASS__
  167. );
  168. }
  169. /**
  170. * Hash index
  171. *
  172. * @var string
  173. */
  174. private $_hashIndex;
  175. /**
  176. * Get hash index
  177. *
  178. * Note that this index may vary during script execution! Only reliable moment is
  179. * while doing a write of a workbook and when changes are not allowed.
  180. *
  181. * @return string Hash index
  182. */
  183. public function getHashIndex() {
  184. return $this->_hashIndex;
  185. }
  186. /**
  187. * Set hash index
  188. *
  189. * Note that this index may vary during script execution! Only reliable moment is
  190. * while doing a write of a workbook and when changes are not allowed.
  191. *
  192. * @param string $value Hash index
  193. */
  194. public function setHashIndex($value) {
  195. $this->_hashIndex = $value;
  196. }
  197. /**
  198. * Implement PHP __clone to create a deep clone, not just a shallow copy.
  199. */
  200. public function __clone() {
  201. $vars = get_object_vars($this);
  202. foreach ($vars as $key => $value) {
  203. if (is_object($value)) {
  204. $this->$key = clone $value;
  205. } else {
  206. $this->$key = $value;
  207. }
  208. }
  209. }
  210. }