From e69dd93c642678c082700bfe5842b573a5301dfc Mon Sep 17 00:00:00 2001 From: Dominik Stadler Date: Thu, 3 Sep 2015 20:46:23 +0000 Subject: [PATCH] Fix bug 53275: reset indexed color flag when setting a non-indexed color git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1701134 13f79535-47bb-0310-9956-ffa450edef68 --- .../apache/poi/xssf/usermodel/XSSFFont.java | 3 +++ .../poi/xssf/usermodel/TestXSSFFont.java | 20 +++++++++++++------ 2 files changed, 17 insertions(+), 6 deletions(-) diff --git a/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFFont.java b/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFFont.java index 28ef261ae9..2e9c842ed4 100644 --- a/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFFont.java +++ b/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFFont.java @@ -388,6 +388,9 @@ public class XSSFFont implements Font { if(color == null) _ctFont.setColorArray(null); else { CTColor ctColor = _ctFont.sizeOfColorArray() == 0 ? _ctFont.addNewColor() : _ctFont.getColorArray(0); + if (ctColor.isSetIndexed()) { + ctColor.unsetIndexed(); + } ctColor.setRgb(color.getRGB()); } } diff --git a/src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestXSSFFont.java b/src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestXSSFFont.java index e0dbcaa9b4..cbb66daf37 100644 --- a/src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestXSSFFont.java +++ b/src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestXSSFFont.java @@ -17,6 +17,8 @@ package org.apache.poi.xssf.usermodel; +import static org.junit.Assert.assertArrayEquals; + import java.io.IOException; import org.apache.poi.POIXMLException; @@ -226,15 +228,21 @@ public final class TestXSSFFont extends BaseTestFont{ ctFont.setColorArray(0,color); XSSFFont xssfFont=new XSSFFont(ctFont); - assertEquals(ctFont.getColorArray(0).getRgb()[0],xssfFont.getXSSFColor().getRgb()[0]); - assertEquals(ctFont.getColorArray(0).getRgb()[1],xssfFont.getXSSFColor().getRgb()[1]); - assertEquals(ctFont.getColorArray(0).getRgb()[2],xssfFont.getXSSFColor().getRgb()[2]); - assertEquals(ctFont.getColorArray(0).getRgb()[3],xssfFont.getXSSFColor().getRgb()[3]); + assertEquals(ctFont.getColorArray(0).getRgb()[0],xssfFont.getXSSFColor().getRGB()[0]); + assertEquals(ctFont.getColorArray(0).getRgb()[1],xssfFont.getXSSFColor().getRGB()[1]); + assertEquals(ctFont.getColorArray(0).getRgb()[2],xssfFont.getXSSFColor().getRGB()[2]); + assertEquals(ctFont.getColorArray(0).getRgb()[3],xssfFont.getXSSFColor().getRGB()[3]); - color.setRgb(Integer.toHexString(0xF1F1F1).getBytes()); + xssfFont.setColor((short)23); + + byte[] bytes = Integer.toHexString(0xF1F1F1).getBytes(); + color.setRgb(bytes); XSSFColor newColor=new XSSFColor(color); xssfFont.setColor(newColor); - assertEquals(ctFont.getColorArray(0).getRgb()[2],newColor.getRgb()[2]); + assertEquals(ctFont.getColorArray(0).getRgb()[2],newColor.getRGB()[2]); + + assertArrayEquals(bytes, xssfFont.getXSSFColor().getRGB()); + assertEquals(0, xssfFont.getColor()); } public void testThemeColor() { -- 2.39.5