PageRenderTime 30ms CodeModel.GetById 0ms RepoModel.GetById 0ms app.codeStats 0ms

/branches/v1.4.0/Classes/PHPExcel/Style/Color.php

#
PHP | 162 lines | 66 code | 13 blank | 83 comment | 10 complexity | 7b144c34cbcef4715a214addb22e2939 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 - 2007 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_Style
  23. * @copyright Copyright (c) 2006 - 2007 PHPExcel (http://www.codeplex.com/PHPExcel)
  24. * @license http://www.gnu.org/licenses/lgpl.txt LGPL
  25. * @version ##VERSION##, ##DATE##
  26. */
  27. /** PHPExcel_IComparable */
  28. require_once 'PHPExcel/IComparable.php';
  29. /**
  30. * PHPExcel_Style_Color
  31. *
  32. * @category PHPExcel
  33. * @package PHPExcel_Style
  34. * @copyright Copyright (c) 2006 - 2007 PHPExcel (http://www.codeplex.com/PHPExcel)
  35. */
  36. class PHPExcel_Style_Color implements PHPExcel_IComparable
  37. {
  38. /* Colors */
  39. const COLOR_BLACK = 'FF000000';
  40. const COLOR_WHITE = 'FFFFFFFF';
  41. const COLOR_RED = 'FFFF0000';
  42. const COLOR_DARKRED = 'FF800000';
  43. const COLOR_BLUE = 'FF0000FF';
  44. const COLOR_DARKBLUE = 'FF000080';
  45. const COLOR_GREEN = 'FF00FF00';
  46. const COLOR_DARKGREEN = 'FF008000';
  47. const COLOR_YELLOW = 'FFFFFF00';
  48. const COLOR_DARKYELLOW = 'FF808000';
  49. /**
  50. * ARGB - Alpha RGB
  51. *
  52. * @var string
  53. */
  54. private $_argb;
  55. /**
  56. * Create a new PHPExcel_Style_Color
  57. *
  58. * @param string $pARGB
  59. */
  60. public function __construct($pARGB = PHPExcel_Style_Color::COLOR_BLACK)
  61. {
  62. // Initialise values
  63. $this->_argb = $pARGB;
  64. }
  65. /**
  66. * Apply styles from array
  67. *
  68. * <code>
  69. * $objPHPExcel->getActiveSheet()->getStyle('B2')->getFont()->getColor()->applyFromArray( array('rgb' => '808080') );
  70. * </code>
  71. *
  72. * @param array $pStyles Array containing style information
  73. * @throws Exception
  74. */
  75. public function applyFromArray($pStyles = null) {
  76. if (is_array($pStyles)) {
  77. if (array_key_exists('rgb', $pStyles)) {
  78. $this->setRGB($pStyles['rgb']);
  79. }
  80. if (array_key_exists('argb', $pStyles)) {
  81. $this->setARGB($pStyles['argb']);
  82. }
  83. } else {
  84. throw new Exception("Invalid style array passed.");
  85. }
  86. }
  87. /**
  88. * Get ARGB
  89. *
  90. * @return string
  91. */
  92. public function getARGB() {
  93. return $this->_argb;
  94. }
  95. /**
  96. * Set ARGB
  97. *
  98. * @param string $pValue
  99. */
  100. public function setARGB($pValue = PHPExcel_Style_Color::COLOR_BLACK) {
  101. if ($pValue == '') {
  102. $pValue = PHPExcel_Style_Color::COLOR_BLACK;
  103. }
  104. $this->_argb = $pValue;
  105. }
  106. /**
  107. * Get RGB
  108. *
  109. * @return string
  110. */
  111. public function getRGB() {
  112. return substr($this->_argb, 2);
  113. }
  114. /**
  115. * Set RGB
  116. *
  117. * @param string $pValue
  118. */
  119. public function setRGB($pValue = '000000') {
  120. if ($pValue == '') {
  121. $pValue = '000000';
  122. }
  123. $this->_argb = 'FF' . $pValue;
  124. }
  125. /**
  126. * Get hash code
  127. *
  128. * @return string Hash code
  129. */
  130. public function getHashCode() {
  131. return md5(
  132. $this->_argb
  133. . __CLASS__
  134. );
  135. }
  136. /**
  137. * Implement PHP __clone to create a deep clone, not just a shallow copy.
  138. */
  139. public function __clone() {
  140. $vars = get_object_vars($this);
  141. foreach ($vars as $key => $value) {
  142. if (is_object($value)) {
  143. $this->$key = clone $value;
  144. } else {
  145. $this->$key = $value;
  146. }
  147. }
  148. }
  149. }