diff options
author | Greg Woolsey <gwoolsey@apache.org> | 2017-05-26 23:14:48 +0000 |
---|---|---|
committer | Greg Woolsey <gwoolsey@apache.org> | 2017-05-26 23:14:48 +0000 |
commit | c844803b660d90b835a1de0dacbd7e369ec30db8 (patch) | |
tree | 73f331759737b1e9b2d2a6420ab9ad4ca91810f0 /src/java/org/apache | |
parent | 585d77c9cf0001d61f20cd59317bab7e2c5b9369 (diff) | |
download | poi-c844803b660d90b835a1de0dacbd7e369ec30db8.tar.gz poi-c844803b660d90b835a1de0dacbd7e369ec30db8.zip |
Bug 60898 - XSSFColor's getARGB() method returns a wrong color value when a workbook has a custom indexed color
teach XSSFColor and most things that create instances about indexed colors.
Null is a valid value for IndexedColorMap instances - the existing built-in default colors are used.
Whenever a workbook style is accessible in the call hierarchy its color mappings are passed down now.
Thanks for the unit test in the issue, it now passes.
git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1796359 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'src/java/org/apache')
3 files changed, 55 insertions, 22 deletions
diff --git a/src/java/org/apache/poi/hssf/usermodel/HSSFExtendedColor.java b/src/java/org/apache/poi/hssf/usermodel/HSSFExtendedColor.java index e6c8c1bf5e..b178263185 100644 --- a/src/java/org/apache/poi/hssf/usermodel/HSSFExtendedColor.java +++ b/src/java/org/apache/poi/hssf/usermodel/HSSFExtendedColor.java @@ -22,6 +22,7 @@ import static org.apache.poi.hssf.record.common.ExtendedColor.TYPE_INDEXED; import static org.apache.poi.hssf.record.common.ExtendedColor.TYPE_RGB; import static org.apache.poi.hssf.record.common.ExtendedColor.TYPE_THEMED; +import org.apache.poi.hssf.util.HSSFColor; import org.apache.poi.ss.usermodel.ExtendedColor; /** @@ -106,4 +107,19 @@ public class HSSFExtendedColor extends ExtendedColor { public void setTint(double tint) { color.setTint(tint); } + + protected byte[] getIndexedRGB() { + if (isIndexed() && getIndex() > 0) { + int indexNum = getIndex(); + HSSFColor indexed = HSSFColor.getIndexHash().get(indexNum); + if (indexed != null) { + byte[] rgb = new byte[3]; + rgb[0] = (byte) indexed.getTriplet()[0]; + rgb[1] = (byte) indexed.getTriplet()[1]; + rgb[2] = (byte) indexed.getTriplet()[2]; + return rgb; + } + } // else + return null; + } } diff --git a/src/java/org/apache/poi/ss/usermodel/ExtendedColor.java b/src/java/org/apache/poi/ss/usermodel/ExtendedColor.java index 2259bbfc29..616a61709d 100644 --- a/src/java/org/apache/poi/ss/usermodel/ExtendedColor.java +++ b/src/java/org/apache/poi/ss/usermodel/ExtendedColor.java @@ -18,77 +18,80 @@ package org.apache.poi.ss.usermodel; import java.util.Locale; -import org.apache.poi.hssf.util.HSSFColor; - /** * Represents a XSSF-style color (based on either a * {@link org.apache.poi.xssf.usermodel.XSSFColor} or a * {@link org.apache.poi.hssf.record.common.ExtendedColor} */ public abstract class ExtendedColor implements Color { + + /** + * + * @param clr awt Color to set + */ protected void setColor(java.awt.Color clr) { setRGB(new byte[]{(byte)clr.getRed(), (byte)clr.getGreen(), (byte)clr.getBlue()}); } /** - * A boolean value indicating the color is automatic + * @return true if the color is automatic */ public abstract boolean isAuto(); /** - * A boolean value indicating the color is indexed + * @return true if the color is indexed */ public abstract boolean isIndexed(); /** - * A boolean value indicating the color is RGB / ARGB + * @return true if the color is RGB / ARGB */ public abstract boolean isRGB(); /** - * A boolean value indicating the color is from a Theme + * @return true if the color is from a Theme */ public abstract boolean isThemed(); /** - * Indexed Color value, if {@link #isIndexed()} is true + * @return Indexed Color index value, if {@link #isIndexed()} is true */ public abstract short getIndex(); /** - * Index of Theme color, if {@link #isThemed()} is true + * @return Index of Theme color, if {@link #isThemed()} is true */ public abstract int getTheme(); /** - * Standard Red Green Blue ctColor value (RGB). + * @return Standard Red Green Blue ctColor value (RGB) bytes. * If there was an A (Alpha) value, it will be stripped. */ public abstract byte[] getRGB(); + /** - * Standard Alpha Red Green Blue ctColor value (ARGB). + * @return Standard Alpha Red Green Blue ctColor value (ARGB) bytes. */ public abstract byte[] getARGB(); /** - * RGB or ARGB or null + * @return RGB or ARGB bytes or null */ protected abstract byte[] getStoredRBG(); /** * Sets the Red Green Blue or Alpha Red Green Blue + * @param rgb bytes */ public abstract void setRGB(byte[] rgb); + /** + * @return RGB or ARGB bytes, either stored or by index + */ protected byte[] getRGBOrARGB() { if (isIndexed() && getIndex() > 0) { - int indexNum = getIndex(); - HSSFColor indexed = HSSFColor.getIndexHash().get(indexNum); - if (indexed != null) { - byte[] rgb = new byte[3]; - rgb[0] = (byte) indexed.getTriplet()[0]; - rgb[1] = (byte) indexed.getTriplet()[1]; - rgb[2] = (byte) indexed.getTriplet()[2]; + byte[] rgb = getIndexedRGB(); + if (rgb != null) { return rgb; } } @@ -96,9 +99,14 @@ public abstract class ExtendedColor implements Color { // Grab the colour return getStoredRBG(); } + + /** + * @return index color RGB bytes, if {@link #isIndexed()} == true, null if not indexed or index is invalid + */ + protected abstract byte[] getIndexedRGB(); /** - * Standard Red Green Blue ctColor value (RGB) with applied tint. + * @return Standard Red Green Blue ctColor value (RGB) bytes with applied tint. * Alpha values are ignored. */ public byte[] getRGBWithTint() { @@ -118,7 +126,7 @@ public abstract class ExtendedColor implements Color { } /** - * Return the ARGB value in hex format, eg FF00FF00. + * @return the ARGB value in hex string format, eg FF00FF00. * Works for both regular and indexed colours. */ public String getARGBHex() { @@ -142,6 +150,7 @@ public abstract class ExtendedColor implements Color { /** * Sets the ARGB value from hex format, eg FF0077FF. * Only works for regular (non-indexed) colours + * @param argb color ARGB hex string */ public void setARGBHex(String argb) { if (argb.length() == 6 || argb.length() == 8) { diff --git a/src/java/org/apache/poi/ss/usermodel/IndexedColors.java b/src/java/org/apache/poi/ss/usermodel/IndexedColors.java index 92ebc08a1f..bb5b911695 100644 --- a/src/java/org/apache/poi/ss/usermodel/IndexedColors.java +++ b/src/java/org/apache/poi/ss/usermodel/IndexedColors.java @@ -31,7 +31,15 @@ package org.apache.poi.ss.usermodel; */ public enum IndexedColors { - // 0-7? + // 0-7 duplicates of 8-15 for compatibility (OOXML spec pt.1 sec. 18.8.27) + BLACK1(0), + WHITE1(1), + RED1(2), + BRIGHT_GREEN1(3), + BLUE1(4), + YELLOW1(5), + PINK1(6), + TURQUOISE1(7), BLACK(8), WHITE(9), RED(10), @@ -51,7 +59,7 @@ public enum IndexedColors { CORNFLOWER_BLUE(24), MAROON(25), LEMON_CHIFFON(26), - // 27? + LIGHT_TURQUOISE1(27), ORCHID(28), CORAL(29), ROYAL_BLUE(30), |