From 42c265b1fa3fa8eb9c3e19bf4f0d573c4f880e56 Mon Sep 17 00:00:00 2001 From: Javen O'Neal Date: Thu, 24 Mar 2016 17:29:00 +0000 Subject: [PATCH] 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 --- .../org/apache/poi/xssf/usermodel/XSSFColor.java | 14 ++++++++++++-- .../apache/poi/xssf/usermodel/TestXSSFColor.java | 8 ++++++++ 2 files changed, 20 insertions(+), 2 deletions(-) diff --git a/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFColor.java b/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFColor.java index b2cb8747a1..ce142b78c8 100644 --- a/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFColor.java +++ b/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFColor.java @@ -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. */ diff --git a/src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestXSSFColor.java b/src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestXSSFColor.java index ef8b81dce6..38406c30a4 100644 --- a/src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestXSSFColor.java +++ b/src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestXSSFColor.java @@ -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); -- 2.39.5