]> source.dussan.org Git - poi.git/commitdiff
Fix NPE of regression tests
authorAndreas Beeker <kiwiwings@apache.org>
Mon, 29 Feb 2016 23:36:58 +0000 (23:36 +0000)
committerAndreas Beeker <kiwiwings@apache.org>
Mon, 29 Feb 2016 23:36:58 +0000 (23:36 +0000)
git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1732972 13f79535-47bb-0310-9956-ffa450edef68

src/java/org/apache/poi/sl/draw/DrawPaint.java

index d4da4313666c2cb763514877ecba9aeaaa7c092a..7362a0e4a5f2f2164c669335441fab9ca7c9ce7f 100644 (file)
@@ -49,8 +49,10 @@ import org.apache.poi.util.POILogger;
 public class DrawPaint {\r
     // HSL code is public domain - see https://tips4java.wordpress.com/contact-us/\r
     \r
-    private final static POILogger LOG = POILogFactory.getLogger(DrawPaint.class);\r
+    private static final POILogger LOG = POILogFactory.getLogger(DrawPaint.class);\r
 \r
+    private static final Color TRANSPARENT = new Color(1f,1f,1f,0f);\r
+    \r
     protected PlaceableShape<?,?> shape;\r
     \r
     public DrawPaint(PlaceableShape<?,?> shape) {\r
@@ -65,8 +67,10 @@ public class DrawPaint {
                 throw new NullPointerException("Color needs to be specified");\r
             }\r
             this.solidColor = new ColorStyle(){\r
-                    public Color getColor() { return color; }\r
-                    public int getAlpha() { return -1; }\r
+                    public Color getColor() {\r
+                        return new Color(color.getRed(), color.getGreen(), color.getBlue());\r
+                    }\r
+                    public int getAlpha() { return (int)Math.round(color.getAlpha()*100000./255.); }\r
                     public int getHueOff() { return -1; }\r
                     public int getHueMod() { return -1; }\r
                     public int getSatOff() { return -1; }\r
@@ -170,9 +174,11 @@ public class DrawPaint {
     public static Color applyColorTransform(ColorStyle color){\r
         // TODO: The colors don't match 100% the results of Powerpoint, maybe because we still\r
         // operate in sRGB and not scRGB ... work in progress ...\r
-\r
+        if (color == null || color.getColor() == null) {\r
+            return TRANSPARENT;\r
+        }\r
+        \r
         Color result = color.getColor();\r
-        if (result == null) return null;\r
 \r
         double alpha = getAlpha(result, color);\r
         double hsl[] = RGB2HSL(result); // values are in the range [0..100] (usually ...)\r
@@ -291,22 +297,8 @@ public class DrawPaint {
         \r
         int i = 0;\r
         for (ColorStyle fc : fill.getGradientColors()) {\r
-            if (fc == null) {\r
-                // get color of background\r
-                fc = new ColorStyle() {\r
-                    public int getTint() { return -1; }\r
-                    public int getShade() { return -1; }\r
-                    public int getSatOff() { return -1; }\r
-                    public int getSatMod() { return -1; }\r
-                    public int getLumOff() { return -1; }\r
-                    public int getLumMod() { return -1; }\r
-                    public int getHueOff() { return -1; }\r
-                    public int getHueMod() { return -1; }\r
-                    public Color getColor() { return Color.white; }\r
-                    public int getAlpha() { return 0; }\r
-                };\r
-            }\r
-            colors[i++] = applyColorTransform(fc);\r
+            // if fc is null, use transparent color to get color of background\r
+            colors[i++] = (fc == null) ? TRANSPARENT : applyColorTransform(fc);\r
         }\r
 \r
         AffineTransform grAt  = new AffineTransform();\r