4e056aa40e3cb1f704ec266cbbdf793118f8a8bf.svn-base 6.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327
  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
  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_Comment
  29. *
  30. * @category PHPExcel
  31. * @package PHPExcel
  32. * @copyright Copyright (c) 2006 - 2014 PHPExcel (http://www.codeplex.com/PHPExcel)
  33. */
  34. class PHPExcel_Comment implements PHPExcel_IComparable
  35. {
  36. /**
  37. * Author
  38. *
  39. * @var string
  40. */
  41. private $_author;
  42. /**
  43. * Rich text comment
  44. *
  45. * @var PHPExcel_RichText
  46. */
  47. private $_text;
  48. /**
  49. * Comment width (CSS style, i.e. XXpx or YYpt)
  50. *
  51. * @var string
  52. */
  53. private $_width = '96pt';
  54. /**
  55. * Left margin (CSS style, i.e. XXpx or YYpt)
  56. *
  57. * @var string
  58. */
  59. private $_marginLeft = '59.25pt';
  60. /**
  61. * Top margin (CSS style, i.e. XXpx or YYpt)
  62. *
  63. * @var string
  64. */
  65. private $_marginTop = '1.5pt';
  66. /**
  67. * Visible
  68. *
  69. * @var boolean
  70. */
  71. private $_visible = false;
  72. /**
  73. * Comment height (CSS style, i.e. XXpx or YYpt)
  74. *
  75. * @var string
  76. */
  77. private $_height = '55.5pt';
  78. /**
  79. * Comment fill color
  80. *
  81. * @var PHPExcel_Style_Color
  82. */
  83. private $_fillColor;
  84. /**
  85. * Alignment
  86. *
  87. * @var string
  88. */
  89. private $_alignment;
  90. /**
  91. * Create a new PHPExcel_Comment
  92. *
  93. * @throws PHPExcel_Exception
  94. */
  95. public function __construct()
  96. {
  97. // Initialise variables
  98. $this->_author = 'Author';
  99. $this->_text = new PHPExcel_RichText();
  100. $this->_fillColor = new PHPExcel_Style_Color('FFFFFFE1');
  101. $this->_alignment = PHPExcel_Style_Alignment::HORIZONTAL_GENERAL;
  102. }
  103. /**
  104. * Get Author
  105. *
  106. * @return string
  107. */
  108. public function getAuthor() {
  109. return $this->_author;
  110. }
  111. /**
  112. * Set Author
  113. *
  114. * @param string $pValue
  115. * @return PHPExcel_Comment
  116. */
  117. public function setAuthor($pValue = '') {
  118. $this->_author = $pValue;
  119. return $this;
  120. }
  121. /**
  122. * Get Rich text comment
  123. *
  124. * @return PHPExcel_RichText
  125. */
  126. public function getText() {
  127. return $this->_text;
  128. }
  129. /**
  130. * Set Rich text comment
  131. *
  132. * @param PHPExcel_RichText $pValue
  133. * @return PHPExcel_Comment
  134. */
  135. public function setText(PHPExcel_RichText $pValue) {
  136. $this->_text = $pValue;
  137. return $this;
  138. }
  139. /**
  140. * Get comment width (CSS style, i.e. XXpx or YYpt)
  141. *
  142. * @return string
  143. */
  144. public function getWidth() {
  145. return $this->_width;
  146. }
  147. /**
  148. * Set comment width (CSS style, i.e. XXpx or YYpt)
  149. *
  150. * @param string $value
  151. * @return PHPExcel_Comment
  152. */
  153. public function setWidth($value = '96pt') {
  154. $this->_width = $value;
  155. return $this;
  156. }
  157. /**
  158. * Get comment height (CSS style, i.e. XXpx or YYpt)
  159. *
  160. * @return string
  161. */
  162. public function getHeight() {
  163. return $this->_height;
  164. }
  165. /**
  166. * Set comment height (CSS style, i.e. XXpx or YYpt)
  167. *
  168. * @param string $value
  169. * @return PHPExcel_Comment
  170. */
  171. public function setHeight($value = '55.5pt') {
  172. $this->_height = $value;
  173. return $this;
  174. }
  175. /**
  176. * Get left margin (CSS style, i.e. XXpx or YYpt)
  177. *
  178. * @return string
  179. */
  180. public function getMarginLeft() {
  181. return $this->_marginLeft;
  182. }
  183. /**
  184. * Set left margin (CSS style, i.e. XXpx or YYpt)
  185. *
  186. * @param string $value
  187. * @return PHPExcel_Comment
  188. */
  189. public function setMarginLeft($value = '59.25pt') {
  190. $this->_marginLeft = $value;
  191. return $this;
  192. }
  193. /**
  194. * Get top margin (CSS style, i.e. XXpx or YYpt)
  195. *
  196. * @return string
  197. */
  198. public function getMarginTop() {
  199. return $this->_marginTop;
  200. }
  201. /**
  202. * Set top margin (CSS style, i.e. XXpx or YYpt)
  203. *
  204. * @param string $value
  205. * @return PHPExcel_Comment
  206. */
  207. public function setMarginTop($value = '1.5pt') {
  208. $this->_marginTop = $value;
  209. return $this;
  210. }
  211. /**
  212. * Is the comment visible by default?
  213. *
  214. * @return boolean
  215. */
  216. public function getVisible() {
  217. return $this->_visible;
  218. }
  219. /**
  220. * Set comment default visibility
  221. *
  222. * @param boolean $value
  223. * @return PHPExcel_Comment
  224. */
  225. public function setVisible($value = false) {
  226. $this->_visible = $value;
  227. return $this;
  228. }
  229. /**
  230. * Get fill color
  231. *
  232. * @return PHPExcel_Style_Color
  233. */
  234. public function getFillColor() {
  235. return $this->_fillColor;
  236. }
  237. /**
  238. * Set Alignment
  239. *
  240. * @param string $pValue
  241. * @return PHPExcel_Comment
  242. */
  243. public function setAlignment($pValue = PHPExcel_Style_Alignment::HORIZONTAL_GENERAL) {
  244. $this->_alignment = $pValue;
  245. return $this;
  246. }
  247. /**
  248. * Get Alignment
  249. *
  250. * @return string
  251. */
  252. public function getAlignment() {
  253. return $this->_alignment;
  254. }
  255. /**
  256. * Get hash code
  257. *
  258. * @return string Hash code
  259. */
  260. public function getHashCode() {
  261. return md5(
  262. $this->_author
  263. . $this->_text->getHashCode()
  264. . $this->_width
  265. . $this->_height
  266. . $this->_marginLeft
  267. . $this->_marginTop
  268. . ($this->_visible ? 1 : 0)
  269. . $this->_fillColor->getHashCode()
  270. . $this->_alignment
  271. . __CLASS__
  272. );
  273. }
  274. /**
  275. * Implement PHP __clone to create a deep clone, not just a shallow copy.
  276. */
  277. public function __clone() {
  278. $vars = get_object_vars($this);
  279. foreach ($vars as $key => $value) {
  280. if (is_object($value)) {
  281. $this->$key = clone $value;
  282. } else {
  283. $this->$key = $value;
  284. }
  285. }
  286. }
  287. /**
  288. * Convert to string
  289. *
  290. * @return string
  291. */
  292. public function __toString() {
  293. return $this->_text->getPlainText();
  294. }
  295. }