/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
- <?php
- /**
- * PHPExcel
- *
- * Copyright (c) 2006 - 2007 PHPExcel
- *
- * This library is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 2.1 of the License, or (at your option) any later version.
- *
- * This library is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this library; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
- *
- * @category PHPExcel
- * @package PHPExcel_Style
- * @copyright Copyright (c) 2006 - 2007 PHPExcel (http://www.codeplex.com/PHPExcel)
- * @license http://www.gnu.org/licenses/lgpl.txt LGPL
- * @version ##VERSION##, ##DATE##
- */
-
-
- /** PHPExcel_IComparable */
- require_once 'PHPExcel/IComparable.php';
-
-
- /**
- * PHPExcel_Style_Color
- *
- * @category PHPExcel
- * @package PHPExcel_Style
- * @copyright Copyright (c) 2006 - 2007 PHPExcel (http://www.codeplex.com/PHPExcel)
- */
- class PHPExcel_Style_Color implements PHPExcel_IComparable
- {
- /* Colors */
- const COLOR_BLACK = 'FF000000';
- const COLOR_WHITE = 'FFFFFFFF';
- const COLOR_RED = 'FFFF0000';
- const COLOR_DARKRED = 'FF800000';
- const COLOR_BLUE = 'FF0000FF';
- const COLOR_DARKBLUE = 'FF000080';
- const COLOR_GREEN = 'FF00FF00';
- const COLOR_DARKGREEN = 'FF008000';
- const COLOR_YELLOW = 'FFFFFF00';
- const COLOR_DARKYELLOW = 'FF808000';
-
- /**
- * ARGB - Alpha RGB
- *
- * @var string
- */
- private $_argb;
-
- /**
- * Create a new PHPExcel_Style_Color
- *
- * @param string $pARGB
- */
- public function __construct($pARGB = PHPExcel_Style_Color::COLOR_BLACK)
- {
- // Initialise values
- $this->_argb = $pARGB;
- }
-
- /**
- * Apply styles from array
- *
- * <code>
- * $objPHPExcel->getActiveSheet()->getStyle('B2')->getFont()->getColor()->applyFromArray( array('rgb' => '808080') );
- * </code>
- *
- * @param array $pStyles Array containing style information
- * @throws Exception
- */
- public function applyFromArray($pStyles = null) {
- if (is_array($pStyles)) {
- if (array_key_exists('rgb', $pStyles)) {
- $this->setRGB($pStyles['rgb']);
- }
- if (array_key_exists('argb', $pStyles)) {
- $this->setARGB($pStyles['argb']);
- }
- } else {
- throw new Exception("Invalid style array passed.");
- }
- }
-
- /**
- * Get ARGB
- *
- * @return string
- */
- public function getARGB() {
- return $this->_argb;
- }
-
- /**
- * Set ARGB
- *
- * @param string $pValue
- */
- public function setARGB($pValue = PHPExcel_Style_Color::COLOR_BLACK) {
- if ($pValue == '') {
- $pValue = PHPExcel_Style_Color::COLOR_BLACK;
- }
- $this->_argb = $pValue;
- }
-
- /**
- * Get RGB
- *
- * @return string
- */
- public function getRGB() {
- return substr($this->_argb, 2);
- }
-
- /**
- * Set RGB
- *
- * @param string $pValue
- */
- public function setRGB($pValue = '000000') {
- if ($pValue == '') {
- $pValue = '000000';
- }
- $this->_argb = 'FF' . $pValue;
- }
-
- /**
- * Get hash code
- *
- * @return string Hash code
- */
- public function getHashCode() {
- return md5(
- $this->_argb
- . __CLASS__
- );
- }
-
- /**
- * Implement PHP __clone to create a deep clone, not just a shallow copy.
- */
- public function __clone() {
- $vars = get_object_vars($this);
- foreach ($vars as $key => $value) {
- if (is_object($value)) {
- $this->$key = clone $value;
- } else {
- $this->$key = $value;
- }
- }
- }
- }