Hopefully fix bug #51236 - make the xssf colour black/white 3 rgb fix apply for set as well as get
git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1126696 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
8144d5e1ae
commit
ab6caf7f49
@ -34,6 +34,7 @@
|
||||
|
||||
<changes>
|
||||
<release version="3.8-beta3" date="2011-??-??">
|
||||
<action dev="poi-developers" type="fix">51236 - XSSF set colour support for black/white to match getter</action>
|
||||
<action dev="poi-developers" type="add">51196 - Initial support for Spreadsheet Chart API</action>
|
||||
<action dev="poi-developers" type="add">Add support for OOXML Agile Encryption</action>
|
||||
<action dev="poi-developers" type="add">51160 - Initial version of SXSSF, a low memory foortprint API to produce xlsx files</action>
|
||||
|
@ -87,7 +87,8 @@ public class ThemesTable extends POIXMLDocumentPart {
|
||||
// Get the theme colour
|
||||
XSSFColor themeColor = getThemeColor(color.getTheme());
|
||||
// Set the raw colour, not the adjusted one
|
||||
color.setRgb(themeColor.getCTColor().getRgb());
|
||||
// Do a raw set, no adjusting at the XSSFColor layer either
|
||||
color.getCTColor().setRgb(themeColor.getCTColor().getRgb());
|
||||
|
||||
// All done
|
||||
}
|
||||
|
@ -80,6 +80,27 @@ public class XSSFColor implements Color {
|
||||
ctColor.setIndexed(indexed);
|
||||
}
|
||||
|
||||
/**
|
||||
* For RGB colours, but not ARGB (we think...)
|
||||
* Excel gets black and white the wrong way around, so switch them
|
||||
*/
|
||||
private byte[] correctRGB(byte[] rgb) {
|
||||
if(rgb.length == 4) {
|
||||
// Excel doesn't appear to get these wrong
|
||||
// Nothing to change
|
||||
return rgb;
|
||||
} else {
|
||||
// Excel gets black and white the wrong way around, so switch them
|
||||
if (rgb[0] == 0 && rgb[1] == 0 && rgb[2] == 0) {
|
||||
rgb = new byte[] {-1, -1, -1};
|
||||
}
|
||||
else if (rgb[0] == -1 && rgb[1] == -1 && rgb[2] == -1) {
|
||||
rgb = new byte[] {0, 0, 0};
|
||||
}
|
||||
return rgb;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Standard Red Green Blue ctColor value (RGB).
|
||||
* If there was an A (Alpha) value, it will be stripped.
|
||||
@ -138,20 +159,8 @@ public class XSSFColor implements Color {
|
||||
// Grab the colour
|
||||
rgb = ctColor.getRgb();
|
||||
|
||||
if(rgb.length == 4) {
|
||||
// Good to go, return it as-is
|
||||
return rgb;
|
||||
}
|
||||
|
||||
// For RGB colours, but not ARGB (we think...)
|
||||
// Excel gets black and white the wrong way around, so switch them
|
||||
if (rgb[0] == 0 && rgb[1] == 0 && rgb[2] == 0) {
|
||||
rgb = new byte[] {-1, -1, -1};
|
||||
}
|
||||
else if (rgb[0] == -1 && rgb[1] == -1 && rgb[2] == -1) {
|
||||
rgb = new byte[] {0, 0, 0};
|
||||
}
|
||||
return rgb;
|
||||
// Correct it as needed, and return
|
||||
return correctRGB(rgb);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -211,7 +220,8 @@ public class XSSFColor implements Color {
|
||||
* Standard Alpha Red Green Blue ctColor value (ARGB).
|
||||
*/
|
||||
public void setRgb(byte[] rgb) {
|
||||
ctColor.setRgb(rgb);
|
||||
// Correct it and save
|
||||
ctColor.setRgb(correctRGB(rgb));
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -97,6 +97,21 @@ public final class TestXSSFColor extends TestCase {
|
||||
assertEquals(0, rgb3.getRgbWithTint()[0]);
|
||||
assertEquals(0, rgb3.getRgbWithTint()[1]);
|
||||
assertEquals(0, rgb3.getRgbWithTint()[2]);
|
||||
|
||||
// Set the colour to black, will get translated internally
|
||||
// (Excel stores 3 colour white and black wrong!)
|
||||
rgb3.setRgb(new byte[] {-1,-1,-1});
|
||||
assertEquals("FFFFFFFF", rgb3.getARGBHex());
|
||||
assertEquals(0, rgb3.getCTColor().getRgb()[0]);
|
||||
assertEquals(0, rgb3.getCTColor().getRgb()[1]);
|
||||
assertEquals(0, rgb3.getCTColor().getRgb()[2]);
|
||||
|
||||
// Set another, is fine
|
||||
rgb3.setRgb(new byte[] {16,17,18});
|
||||
assertEquals("FF101112", rgb3.getARGBHex());
|
||||
assertEquals(0x10, rgb3.getCTColor().getRgb()[0]);
|
||||
assertEquals(0x11, rgb3.getCTColor().getRgb()[1]);
|
||||
assertEquals(0x12, rgb3.getCTColor().getRgb()[2]);
|
||||
}
|
||||
|
||||
public void testARGBColour() throws Exception {
|
||||
|
Loading…
Reference in New Issue
Block a user