Bugfix: Work item 17166 - Indexed colors do not refer to Excel's indexed colors?

git-svn-id: https://phpexcel.svn.codeplex.com/svn/trunk@84644 2327b42d-5241-43d6-9e2a-de5ac946f064
This commit is contained in:
Mark Baker 2012-01-02 00:12:09 +00:00
parent cb6839b24a
commit 438bc9da60
2 changed files with 148 additions and 154 deletions

View File

@ -19,10 +19,10 @@
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
* *
* @category PHPExcel * @category PHPExcel
* @package PHPExcel_Style * @package PHPExcel_Style
* @copyright Copyright (c) 2006 - 2011 PHPExcel (http://www.codeplex.com/PHPExcel) * @copyright Copyright (c) 2006 - 2011 PHPExcel (http://www.codeplex.com/PHPExcel)
* @license http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt LGPL * @license http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt LGPL
* @version ##VERSION##, ##DATE## * @version ##VERSION##, ##DATE##
*/ */
@ -30,7 +30,7 @@
* PHPExcel_Style_Color * PHPExcel_Style_Color
* *
* @category PHPExcel * @category PHPExcel
* @package PHPExcel_Style * @package PHPExcel_Style
* @copyright Copyright (c) 2006 - 2011 PHPExcel (http://www.codeplex.com/PHPExcel) * @copyright Copyright (c) 2006 - 2011 PHPExcel (http://www.codeplex.com/PHPExcel)
*/ */
class PHPExcel_Style_Color implements PHPExcel_IComparable class PHPExcel_Style_Color implements PHPExcel_IComparable
@ -82,19 +82,19 @@ class PHPExcel_Style_Color implements PHPExcel_IComparable
*/ */
private $_parentPropertyName; private $_parentPropertyName;
/** /**
* Create a new PHPExcel_Style_Color * Create a new PHPExcel_Style_Color
* *
* @param string $pARGB * @param string $pARGB
*/ */
public function __construct($pARGB = PHPExcel_Style_Color::COLOR_BLACK, $isSupervisor = false) public function __construct($pARGB = PHPExcel_Style_Color::COLOR_BLACK, $isSupervisor = false)
{ {
// Supervisor? // Supervisor?
$this->_isSupervisor = $isSupervisor; $this->_isSupervisor = $isSupervisor;
// Initialise values // Initialise values
$this->_argb = $pARGB; $this->_argb = $pARGB;
} }
/** /**
* Bind parent. Only used for supervisor * Bind parent. Only used for supervisor
@ -200,17 +200,17 @@ class PHPExcel_Style_Color implements PHPExcel_IComparable
return $this->_parent->getStyleArray(array($key => $array)); return $this->_parent->getStyleArray(array($key => $array));
} }
/** /**
* Apply styles from array * Apply styles from array
* *
* <code> * <code>
* $objPHPExcel->getActiveSheet()->getStyle('B2')->getFont()->getColor()->applyFromArray( array('rgb' => '808080') ); * $objPHPExcel->getActiveSheet()->getStyle('B2')->getFont()->getColor()->applyFromArray( array('rgb' => '808080') );
* </code> * </code>
* *
* @param array $pStyles Array containing style information * @param array $pStyles Array containing style information
* @throws Exception * @throws Exception
* @return PHPExcel_Style_Color * @return PHPExcel_Style_Color
*/ */
public function applyFromArray($pStyles = null) { public function applyFromArray($pStyles = null) {
if (is_array($pStyles)) { if (is_array($pStyles)) {
if ($this->_isSupervisor) { if ($this->_isSupervisor) {
@ -229,28 +229,28 @@ class PHPExcel_Style_Color implements PHPExcel_IComparable
return $this; return $this;
} }
/** /**
* Get ARGB * Get ARGB
* *
* @return string * @return string
*/ */
public function getARGB() { public function getARGB() {
if ($this->_isSupervisor) { if ($this->_isSupervisor) {
return $this->getSharedComponent()->getARGB(); return $this->getSharedComponent()->getARGB();
} }
return $this->_argb; return $this->_argb;
} }
/** /**
* Set ARGB * Set ARGB
* *
* @param string $pValue * @param string $pValue
* @return PHPExcel_Style_Color * @return PHPExcel_Style_Color
*/ */
public function setARGB($pValue = PHPExcel_Style_Color::COLOR_BLACK) { public function setARGB($pValue = PHPExcel_Style_Color::COLOR_BLACK) {
if ($pValue == '') { if ($pValue == '') {
$pValue = PHPExcel_Style_Color::COLOR_BLACK; $pValue = PHPExcel_Style_Color::COLOR_BLACK;
} }
if ($this->_isSupervisor) { if ($this->_isSupervisor) {
$styleArray = $this->getStyleArray(array('argb' => $pValue)); $styleArray = $this->getStyleArray(array('argb' => $pValue));
$this->getActiveSheet()->getStyle($this->getSelectedCells())->applyFromArray($styleArray); $this->getActiveSheet()->getStyle($this->getSelectedCells())->applyFromArray($styleArray);
@ -258,30 +258,30 @@ class PHPExcel_Style_Color implements PHPExcel_IComparable
$this->_argb = $pValue; $this->_argb = $pValue;
} }
return $this; return $this;
} }
/** /**
* Get RGB * Get RGB
* *
* @return string * @return string
*/ */
public function getRGB() { public function getRGB() {
if ($this->_isSupervisor) { if ($this->_isSupervisor) {
return $this->getSharedComponent()->getRGB(); return $this->getSharedComponent()->getRGB();
} }
return substr($this->_argb, 2); return substr($this->_argb, 2);
} }
/** /**
* Set RGB * Set RGB
* *
* @param string $pValue * @param string $pValue
* @return PHPExcel_Style_Color * @return PHPExcel_Style_Color
*/ */
public function setRGB($pValue = '000000') { public function setRGB($pValue = '000000') {
if ($pValue == '') { if ($pValue == '') {
$pValue = '000000'; $pValue = '000000';
} }
if ($this->_isSupervisor) { if ($this->_isSupervisor) {
$styleArray = $this->getStyleArray(array('argb' => 'FF' . $pValue)); $styleArray = $this->getStyleArray(array('argb' => 'FF' . $pValue));
$this->getActiveSheet()->getStyle($this->getSelectedCells())->applyFromArray($styleArray); $this->getActiveSheet()->getStyle($this->getSelectedCells())->applyFromArray($styleArray);
@ -289,7 +289,7 @@ class PHPExcel_Style_Color implements PHPExcel_IComparable
$this->_argb = 'FF' . $pValue; $this->_argb = 'FF' . $pValue;
} }
return $this; return $this;
} }
private static function _getColourComponent($RGB,$offset,$hex=true) { private static function _getColourComponent($RGB,$offset,$hex=true) {
$colour = substr($RGB,$offset,2); $colour = substr($RGB,$offset,2);
@ -323,12 +323,12 @@ class PHPExcel_Style_Color implements PHPExcel_IComparable
} }
/** /**
* Adjust the brightness of a color * Adjust the brightness of a color
* *
* @param string $hex The colour as an RGB value (e.g. FF00CCCC or CCDDEE * @param string $hex The colour as an RGB value (e.g. FF00CCCC or CCDDEE
* @param float $adjustPercentage The percentage by which to adjust the colour as a float from -1 to 1 * @param float $adjustPercentage The percentage by which to adjust the colour as a float from -1 to 1
* @return string The adjusted colour as an RGB value (e.g. FF00CCCC or CCDDEE * @return string The adjusted colour as an RGB value (e.g. FF00CCCC or CCDDEE
*/ */
public static function changeBrightness($hex, $adjustPercentage) { public static function changeBrightness($hex, $adjustPercentage) {
$red = self::getRed($hex,false); $red = self::getRed($hex,false);
$green = self::getGreen($hex,false); $green = self::getGreen($hex,false);
@ -357,93 +357,86 @@ class PHPExcel_Style_Color implements PHPExcel_IComparable
} }
/** /**
* Get indexed color * Get indexed color
* *
* @param int $pIndex * @param int $pIndex
* @return PHPExcel_Style_Color * @return PHPExcel_Style_Color
*/ */
public static function indexedColor($pIndex, $background=false) { public static function indexedColor($pIndex, $background=false) {
// Clean parameter // Clean parameter
$pIndex = intval($pIndex); $pIndex = intval($pIndex);
// Indexed colors // Indexed colors
if (is_null(self::$_indexedColors)) { if (is_null(self::$_indexedColors)) {
self::$_indexedColors = array(); self::$_indexedColors = array(
self::$_indexedColors[] = '00000000'; '00000000', // System Colour #1 - Black
self::$_indexedColors[] = '00FFFFFF'; '00FFFFFF', // System Colour #2 - White
self::$_indexedColors[] = '00FF0000'; '00FF0000', // System Colour #3 - Red
self::$_indexedColors[] = '0000FF00'; '0000FF00', // System Colour #4 - Green
self::$_indexedColors[] = '000000FF'; '000000FF', // System Colour #5 - Blue
self::$_indexedColors[] = '00FFFF00'; '00FFFF00', // System Colour #6 - Yellow
self::$_indexedColors[] = '00FF00FF'; '00FF00FF', // System Colour #7- Magenta
self::$_indexedColors[] = '0000FFFF'; '0000FFFF', // System Colour #8- Cyan
self::$_indexedColors[] = '00000000'; '00800000', // Standard Colour #9
self::$_indexedColors[] = '00FFFFFF'; '00008000', // Standard Colour #10
self::$_indexedColors[] = '00FF0000'; '00000080', // Standard Colour #11
self::$_indexedColors[] = '0000FF00'; '00808000', // Standard Colour #12
self::$_indexedColors[] = '000000FF'; '00800080', // Standard Colour #13
self::$_indexedColors[] = '00FFFF00'; '00008080', // Standard Colour #14
self::$_indexedColors[] = '00FF00FF'; '00C0C0C0', // Standard Colour #15
self::$_indexedColors[] = '0000FFFF'; '00808080', // Standard Colour #16
self::$_indexedColors[] = '00800000'; '009999FF', // Chart Fill Colour #17
self::$_indexedColors[] = '00008000'; '00993366', // Chart Fill Colour #18
self::$_indexedColors[] = '00000080'; '00FFFFCC', // Chart Fill Colour #19
self::$_indexedColors[] = '00808000'; '00CCFFFF', // Chart Fill Colour #20
self::$_indexedColors[] = '00800080'; '00660066', // Chart Fill Colour #21
self::$_indexedColors[] = '00008080'; '00FF8080', // Chart Fill Colour #22
self::$_indexedColors[] = '00C0C0C0'; '000066CC', // Chart Fill Colour #23
self::$_indexedColors[] = '00808080'; '00CCCCFF', // Chart Fill Colour #24
self::$_indexedColors[] = '009999FF'; '00000080', // Chart Line Colour #25
self::$_indexedColors[] = '00993366'; '00FF00FF', // Chart Line Colour #26
self::$_indexedColors[] = '00FFFFCC'; '00FFFF00', // Chart Line Colour #27
self::$_indexedColors[] = '00CCFFFF'; '0000FFFF', // Chart Line Colour #28
self::$_indexedColors[] = '00660066'; '00800080', // Chart Line Colour #29
self::$_indexedColors[] = '00FF8080'; '00800000', // Chart Line Colour #30
self::$_indexedColors[] = '000066CC'; '00008080', // Chart Line Colour #31
self::$_indexedColors[] = '00CCCCFF'; '000000FF', // Chart Line Colour #32
self::$_indexedColors[] = '00000080'; '0000CCFF', // Standard Colour #33
self::$_indexedColors[] = '00FF00FF'; '00CCFFFF', // Standard Colour #34
self::$_indexedColors[] = '00FFFF00'; '00CCFFCC', // Standard Colour #35
self::$_indexedColors[] = '0000FFFF'; '00FFFF99', // Standard Colour #36
self::$_indexedColors[] = '00800080'; '0099CCFF', // Standard Colour #37
self::$_indexedColors[] = '00800000'; '00FF99CC', // Standard Colour #38
self::$_indexedColors[] = '00008080'; '00CC99FF', // Standard Colour #39
self::$_indexedColors[] = '000000FF'; '00FFCC99', // Standard Colour #40
self::$_indexedColors[] = '0000CCFF'; '003366FF', // Standard Colour #41
self::$_indexedColors[] = '00CCFFFF'; '0033CCCC', // Standard Colour #42
self::$_indexedColors[] = '00CCFFCC'; '0099CC00', // Standard Colour #43
self::$_indexedColors[] = '00FFFF99'; '00FFCC00', // Standard Colour #44
self::$_indexedColors[] = '0099CCFF'; '00FF9900', // Standard Colour #45
self::$_indexedColors[] = '00FF99CC'; '00FF6600', // Standard Colour #46
self::$_indexedColors[] = '00CC99FF'; '00666699', // Standard Colour #47
self::$_indexedColors[] = '00FFCC99'; '00969696', // Standard Colour #48
self::$_indexedColors[] = '003366FF'; '00003366', // Standard Colour #49
self::$_indexedColors[] = '0033CCCC'; '00339966', // Standard Colour #50
self::$_indexedColors[] = '0099CC00'; '00003300', // Standard Colour #51
self::$_indexedColors[] = '00FFCC00'; '00333300', // Standard Colour #52
self::$_indexedColors[] = '00FF9900'; '00993300', // Standard Colour #53
self::$_indexedColors[] = '00FF6600'; '00993366', // Standard Colour #54
self::$_indexedColors[] = '00666699'; '00333399', // Standard Colour #55
self::$_indexedColors[] = '00969696'; '00333333' // Standard Colour #56
self::$_indexedColors[] = '00003366'; );
self::$_indexedColors[] = '00339966'; }
self::$_indexedColors[] = '00003300';
self::$_indexedColors[] = '00333300';
self::$_indexedColors[] = '00993300';
self::$_indexedColors[] = '00993366';
self::$_indexedColors[] = '00333399';
self::$_indexedColors[] = '00333333';
}
if (array_key_exists($pIndex, self::$_indexedColors)) { if (array_key_exists($pIndex, self::$_indexedColors)) {
return new PHPExcel_Style_Color(self::$_indexedColors[$pIndex]); return new PHPExcel_Style_Color(self::$_indexedColors[$pIndex]);
} }
if ($background) { if ($background) {
return new PHPExcel_Style_Color('FFFFFFFF'); return new PHPExcel_Style_Color('FFFFFFFF');
} }
return new PHPExcel_Style_Color('FF000000'); return new PHPExcel_Style_Color('FF000000');
} }
/** /**
* Get hash code * Get hash code
@ -454,11 +447,11 @@ class PHPExcel_Style_Color implements PHPExcel_IComparable
if ($this->_isSupervisor) { if ($this->_isSupervisor) {
return $this->getSharedComponent()->getHashCode(); return $this->getSharedComponent()->getHashCode();
} }
return md5( return md5(
$this->_argb $this->_argb
. __CLASS__ . __CLASS__
); );
} }
/** /**
* Implement PHP __clone to create a deep clone, not just a shallow copy. * Implement PHP __clone to create a deep clone, not just a shallow copy.

View File

@ -50,6 +50,7 @@ Fixed in SVN:
- Bugfix: (MBaker) Work item 16960 - Previous calculation engine error conditions trigger cyclic reference errors - Bugfix: (MBaker) Work item 16960 - Previous calculation engine error conditions trigger cyclic reference errors
- Bugfix: (mkopinsky) Work item 16266 - PHPExcel_Style::applyFromArray() returns null rather than style object in advanced mode - Bugfix: (mkopinsky) Work item 16266 - PHPExcel_Style::applyFromArray() returns null rather than style object in advanced mode
- Bugfix: (fauvel) Work item 16958 - Cell::getFormattedValue returns RichText object instead of string - Bugfix: (fauvel) Work item 16958 - Cell::getFormattedValue returns RichText object instead of string
- Bugfix: (MBaker) Work item 17166 - Indexed colors do not refer to Excel's indexed colors?
- General: (MBaker) Work item 15405 - Two easy to fix Issues concerning PHPExcel_Token_Stack (l10n/UC) - General: (MBaker) Work item 15405 - Two easy to fix Issues concerning PHPExcel_Token_Stack (l10n/UC)
- General: (MBaker) Work item 15461 - Locale file paths not fit for windows - General: (MBaker) Work item 15461 - Locale file paths not fit for windows
- General: (MBaker) Work item 16643 - Add file directory as a cache option for cache_to_discISAM - General: (MBaker) Work item 16643 - Add file directory as a cache option for cache_to_discISAM