bug 59224: change hasTint, add hasAlpha and unit tests. Patch from gubespam@gmail.com
git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1736469 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
4fe9f0bcab
commit
f0e824587b
@ -90,15 +90,25 @@ public class XSSFColor extends ExtendedColor {
|
||||
}
|
||||
|
||||
/**
|
||||
* A boolean value indicating if the ctColor has a tint or not
|
||||
* A boolean value indicating if the ctColor has a alpha or not
|
||||
*/
|
||||
public boolean hasTint() {
|
||||
public boolean hasAlpha() {
|
||||
if (! ctColor.isSetRgb()) {
|
||||
return false;
|
||||
}
|
||||
return ctColor.getRgb().length == 4;
|
||||
}
|
||||
|
||||
/**
|
||||
* A boolean value indicating if the ctColor has a tint or not
|
||||
*/
|
||||
public boolean hasTint() {
|
||||
if (!ctColor.isSetTint()) {
|
||||
return false;
|
||||
}
|
||||
return ctColor.getTint() != 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* Indexed ctColor value. Only used for backwards compatibility. References a ctColor in indexedColors.
|
||||
*/
|
||||
|
@ -43,6 +43,8 @@ public final class TestXSSFColor {
|
||||
assertEquals(null, indexed.getRGB());
|
||||
assertEquals(null, indexed.getRGBWithTint());
|
||||
assertEquals(null, indexed.getARGBHex());
|
||||
assertFalse(indexed.hasAlpha());
|
||||
assertFalse(indexed.hasTint());
|
||||
|
||||
// Now move to one with indexed rgb values
|
||||
indexed.setIndexed(59);
|
||||
@ -87,6 +89,8 @@ public final class TestXSSFColor {
|
||||
// Now check the XSSFColor
|
||||
assertEquals(0, rgb3.getIndexed());
|
||||
assertEquals(-0.34999, rgb3.getTint(), 0.00001);
|
||||
assertFalse(rgb3.hasAlpha());
|
||||
assertTrue(rgb3.hasTint());
|
||||
|
||||
assertEquals("FFFFFFFF", rgb3.getARGBHex());
|
||||
assertEquals(3, rgb3.getRGB().length);
|
||||
@ -118,6 +122,7 @@ public final class TestXSSFColor {
|
||||
|
||||
// Set another, is fine
|
||||
rgb3.setRGB(new byte[] {16,17,18});
|
||||
assertFalse(rgb3.hasAlpha());
|
||||
assertEquals("FF101112", rgb3.getARGBHex());
|
||||
assertEquals(0x10, rgb3.getCTColor().getRgb()[0]);
|
||||
assertEquals(0x11, rgb3.getCTColor().getRgb()[1]);
|
||||
@ -140,6 +145,8 @@ public final class TestXSSFColor {
|
||||
// Now check the XSSFColor
|
||||
assertEquals(0, rgb4.getIndexed());
|
||||
assertEquals(0.0, rgb4.getTint(), 0);
|
||||
assertFalse(rgb4.hasTint());
|
||||
assertTrue(rgb4.hasAlpha());
|
||||
|
||||
assertEquals("FFFF0000", rgb4.getARGBHex());
|
||||
assertEquals(3, rgb4.getRGB().length);
|
||||
@ -163,6 +170,7 @@ public final class TestXSSFColor {
|
||||
// Turn on tinting, and check it behaves
|
||||
// TODO These values are suspected to be wrong...
|
||||
rgb4.setTint(0.4);
|
||||
assertTrue(rgb4.hasTint());
|
||||
assertEquals(0.4, rgb4.getTint(), 0);
|
||||
|
||||
assertEquals(3, rgb4.getRGBWithTint().length);
|
||||
|
Loading…
Reference in New Issue
Block a user