You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@poi.apache.org by ni...@apache.org on 2011/05/23 21:55:00 UTC

svn commit: r1126696 - in /poi/trunk/src: documentation/content/xdocs/status.xml ooxml/java/org/apache/poi/xssf/model/ThemesTable.java ooxml/java/org/apache/poi/xssf/usermodel/XSSFColor.java ooxml/testcases/org/apache/poi/xssf/usermodel/TestXSSFColor.java

Author: nick
Date: Mon May 23 19:55:00 2011
New Revision: 1126696

URL: http://svn.apache.org/viewvc?rev=1126696&view=rev
Log:
Hopefully fix bug #51236 - make the xssf colour black/white 3 rgb fix apply for set as well as get

Modified:
    poi/trunk/src/documentation/content/xdocs/status.xml
    poi/trunk/src/ooxml/java/org/apache/poi/xssf/model/ThemesTable.java
    poi/trunk/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFColor.java
    poi/trunk/src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestXSSFColor.java

Modified: poi/trunk/src/documentation/content/xdocs/status.xml
URL: http://svn.apache.org/viewvc/poi/trunk/src/documentation/content/xdocs/status.xml?rev=1126696&r1=1126695&r2=1126696&view=diff
==============================================================================
--- poi/trunk/src/documentation/content/xdocs/status.xml (original)
+++ poi/trunk/src/documentation/content/xdocs/status.xml Mon May 23 19:55:00 2011
@@ -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>

Modified: poi/trunk/src/ooxml/java/org/apache/poi/xssf/model/ThemesTable.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/ooxml/java/org/apache/poi/xssf/model/ThemesTable.java?rev=1126696&r1=1126695&r2=1126696&view=diff
==============================================================================
--- poi/trunk/src/ooxml/java/org/apache/poi/xssf/model/ThemesTable.java (original)
+++ poi/trunk/src/ooxml/java/org/apache/poi/xssf/model/ThemesTable.java Mon May 23 19:55:00 2011
@@ -87,7 +87,8 @@ public class ThemesTable extends POIXMLD
        // 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
     }

Modified: poi/trunk/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFColor.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFColor.java?rev=1126696&r1=1126695&r2=1126696&view=diff
==============================================================================
--- poi/trunk/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFColor.java (original)
+++ poi/trunk/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFColor.java Mon May 23 19:55:00 2011
@@ -79,6 +79,27 @@ public class XSSFColor implements Color 
 	public void setIndexed(int indexed) {
 		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).
@@ -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,9 +220,10 @@ 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));
 	}
-
+	
     /**
      * Index into the <clrScheme> collection, referencing a particular <sysClr> or
      *  <srgbClr> value expressed in the Theme part.

Modified: poi/trunk/src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestXSSFColor.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestXSSFColor.java?rev=1126696&r1=1126695&r2=1126696&view=diff
==============================================================================
--- poi/trunk/src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestXSSFColor.java (original)
+++ poi/trunk/src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestXSSFColor.java Mon May 23 19:55:00 2011
@@ -97,6 +97,21 @@ public final class TestXSSFColor extends
       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 {



---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@poi.apache.org
For additional commands, e-mail: commits-help@poi.apache.org