]> source.dussan.org Git - poi.git/commitdiff
Bugzilla 51731 - fixed painting shape outlines in HSLF
authorYegor Kozlov <yegor@apache.org>
Wed, 22 Feb 2012 11:44:21 +0000 (11:44 +0000)
committerYegor Kozlov <yegor@apache.org>
Wed, 22 Feb 2012 11:44:21 +0000 (11:44 +0000)
git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1292247 13f79535-47bb-0310-9956-ffa450edef68

src/documentation/content/xdocs/status.xml
src/scratchpad/src/org/apache/poi/hslf/model/Fill.java
src/scratchpad/src/org/apache/poi/hslf/model/Shape.java
src/scratchpad/src/org/apache/poi/hslf/model/SimpleShape.java
src/scratchpad/testcases/org/apache/poi/hslf/model/TestShapes.java

index 9e88c81f2fa68f11e6f51766832e68c7275754ae..a2bd2f3d0b9fdecfefc837638a2c87696ab247ff 100644 (file)
@@ -34,6 +34,7 @@
 
     <changes>
         <release version="3.8-beta6" date="2012-??-??">
+           <action dev="poi-developers" type="fix">51731 - fixed painting shape outlines in HSLF</action>
            <action dev="poi-developers" type="fix">52701 - fixed seting vertical alignment for XSLFTableCell</action>
            <action dev="poi-developers" type="fix">52687 - fixed merging slides with pictures with associated custom tags</action>
            <action dev="poi-developers" type="add"> allow runtime registration of functions in FormulaEvaluator</action>
index 0b8ddaad8805c8ad5ed9bbd6a7ff73cb0f5fef72..036219a2588cb3012d06737fed34252b0bbbcd79 100644 (file)
@@ -163,19 +163,12 @@ public final class Fill {
      */
     public Color getForegroundColor(){
         EscherOptRecord opt = (EscherOptRecord)Shape.getEscherChild(shape.getSpContainer(), EscherOptRecord.RECORD_ID);
-        EscherSimpleProperty p1 = (EscherSimpleProperty)Shape.getEscherProperty(opt, EscherProperties.FILL__FILLCOLOR);
-        EscherSimpleProperty p2 = (EscherSimpleProperty)Shape.getEscherProperty(opt, EscherProperties.FILL__NOFILLHITTEST);
-        EscherSimpleProperty p3 = (EscherSimpleProperty)Shape.getEscherProperty(opt, EscherProperties.FILL__FILLOPACITY);
+        EscherSimpleProperty p = (EscherSimpleProperty)Shape.getEscherProperty(opt, EscherProperties.FILL__NOFILLHITTEST);
 
-        int p2val = p2 == null ? 0 : p2.getPropertyValue();
-        int alpha =  p3 == null ? 255 : ((p3.getPropertyValue() >> 8) & 0xFF);
+        if(p != null && (p.getPropertyValue() & 0x10) == 0) return null;
+
+        return shape.getColor(EscherProperties.FILL__FILLCOLOR, EscherProperties.FILL__FILLOPACITY, -1);
 
-        Color clr = null;
-        if (p1 != null && (p2val  & 0x10) != 0){
-            int rgb = p1.getPropertyValue();
-            clr = shape.getColor(rgb, alpha);
-        }
-        return clr;
     }
 
     /**
@@ -198,17 +191,11 @@ public final class Fill {
      */
     public Color getBackgroundColor(){
         EscherOptRecord opt = (EscherOptRecord)Shape.getEscherChild(shape.getSpContainer(), EscherOptRecord.RECORD_ID);
-        EscherSimpleProperty p1 = (EscherSimpleProperty)Shape.getEscherProperty(opt, EscherProperties.FILL__FILLBACKCOLOR);
-        EscherSimpleProperty p2 = (EscherSimpleProperty)Shape.getEscherProperty(opt, EscherProperties.FILL__NOFILLHITTEST);
+        EscherSimpleProperty p = (EscherSimpleProperty)Shape.getEscherProperty(opt, EscherProperties.FILL__NOFILLHITTEST);
 
-        int p2val = p2 == null ? 0 : p2.getPropertyValue();
+        if(p != null && (p.getPropertyValue() & 0x10) == 0) return null;
 
-        Color clr = null;
-        if (p1 != null && (p2val  & 0x10) != 0){
-            int rgb = p1.getPropertyValue();
-            clr = shape.getColor(rgb, 255);
-        }
-        return clr;
+        return shape.getColor(EscherProperties.FILL__FILLBACKCOLOR, EscherProperties.FILL__FILLOPACITY, -1);
     }
 
     /**
index f2e934127d35d8a99c399e48594d4ca81b513ac9..88c0b19fddfeff5ca70583d0a08eb32cb1c78e0d 100644 (file)
@@ -363,14 +363,72 @@ public abstract class Shape {
         _sheet = sheet;
     }
 
-    protected Color getColor(int rgb, int alpha){
-        if (rgb >= 0x8000000) {
-            int idx = rgb - 0x8000000;
+    Color getColor(short colorProperty, short opacityProperty, int defaultColor){
+        EscherOptRecord opt = (EscherOptRecord)getEscherChild(_escherContainer, EscherOptRecord.RECORD_ID);
+        EscherSimpleProperty p = (EscherSimpleProperty)getEscherProperty(opt, colorProperty);
+        if(p == null && defaultColor == -1) return null;
+
+        int val = p == null ? defaultColor : p.getPropertyValue();
+
+        int a = (val >> 24) & 0xFF;
+        int b = (val >> 16) & 0xFF;
+        int g = (val >> 8) & 0xFF;
+        int r = (val >> 0) & 0xFF;
+
+        boolean fPaletteIndex = (a & 1) != 0;
+        boolean fPaletteRGB = (a & (1 << 1)) != 0;
+        boolean fSystemRGB = (a & (1 << 2)) != 0;
+        boolean fSchemeIndex = (a & (1 << 3)) != 0;
+        boolean fSysIndex = (a & (1 << 4)) != 0;
+
+        if (fSchemeIndex)
+        {
+            //red is the index to the color scheme
             ColorSchemeAtom ca = getSheet().getColorScheme();
-            if(idx >= 0 && idx <= 7) rgb = ca.getColor(idx);
+            int schemeColor = ca.getColor(r);
+
+            r = (schemeColor >> 0) & 0xFF;
+            g = (schemeColor >> 8) & 0xFF;
+            b = (schemeColor >> 16) & 0xFF;
+        } else if (fPaletteIndex){
+            //TODO
+        } else if (fPaletteRGB){
+            //TODO
+        } else if (fSystemRGB){
+            //TODO
+        } else if (fSysIndex){
+            //TODO
+        }
+
+        EscherSimpleProperty op = (EscherSimpleProperty)getEscherProperty(opt, opacityProperty);
+        int defaultOpacity = 0x00010000;
+        int opacity = op == null ? defaultOpacity : op.getPropertyValue();
+        int i = (opacity >> 16);
+        int f = (opacity >> 0) & 0xFFFF ;
+        double alpha = (i + f/65536.0)*255;
+        return new Color(r, g, b, (int)alpha);
+    }
+
+    Color toRGB(int val){
+        int a = (val >> 24) & 0xFF;
+        int b = (val >> 16) & 0xFF;
+        int g = (val >> 8) & 0xFF;
+        int r = (val >> 0) & 0xFF;
+
+        if(a == 0xFE){
+            // Color is an sRGB value specified by red, green, and blue fields.
+        } else if (a == 0xFF){
+            // Color is undefined.
+        } else {
+            // index in the color scheme
+            ColorSchemeAtom ca = getSheet().getColorScheme();
+            int schemeColor = ca.getColor(a);
+
+            r = (schemeColor >> 0) & 0xFF;
+            g = (schemeColor >> 8) & 0xFF;
+            b = (schemeColor >> 16) & 0xFF;
         }
-        Color tmp = new Color(rgb, true);
-        return new Color(tmp.getBlue(), tmp.getGreen(), tmp.getRed(), alpha);
+        return new Color(r, g, b);
     }
 
     /**
index ee2d8f98e582454a7e658a03ceb48f808982f572..3f7ce7cb3110cc2934a9422f1c63c6303c9c55e5 100644 (file)
@@ -138,23 +138,11 @@ public abstract class SimpleShape extends Shape {
     public Color getLineColor(){
         EscherOptRecord opt = (EscherOptRecord)getEscherChild(_escherContainer, EscherOptRecord.RECORD_ID);
 
-        EscherSimpleProperty p1 = (EscherSimpleProperty)getEscherProperty(opt, EscherProperties.LINESTYLE__COLOR);
-        EscherSimpleProperty p2 = (EscherSimpleProperty)getEscherProperty(opt, EscherProperties.LINESTYLE__NOLINEDRAWDASH);
-        int p2val = p2 == null ? 0 : p2.getPropertyValue();
-        Color clr = null;
-        if ((p2val  & 0x8) != 0 || (p2val  & 0x10) != 0){
-            int rgb = p1 == null ? 0 : p1.getPropertyValue();
-            if (rgb >= 0x8000000) {
-                int idx = rgb % 0x8000000;
-                if(getSheet() != null) {
-                    ColorSchemeAtom ca = getSheet().getColorScheme();
-                    if(idx >= 0 && idx <= 7) rgb = ca.getColor(idx);
-                }
-            }
-            Color tmp = new Color(rgb, true);
-            clr = new Color(tmp.getBlue(), tmp.getGreen(), tmp.getRed());
-        }
-        return clr;
+        EscherSimpleProperty p = (EscherSimpleProperty)getEscherProperty(opt, EscherProperties.LINESTYLE__NOLINEDRAWDASH);
+        if(p != null && (p.getPropertyValue() & 0x8) == 0) return null;
+
+        Color clr = getColor(EscherProperties.LINESTYLE__COLOR, EscherProperties.LINESTYLE__OPACITY, -1);
+        return clr == null ? Color.black : clr;
     }
 
     /**
index 0d016e39d3aa2e010ada961601d2ba96ce93fe7b..6018cf5f52692533c4e70cbaf4c2324e9da4d467 100644 (file)
@@ -366,4 +366,29 @@ public final class TestShapes extends TestCase {
         }
         assertEquals(numClusters + 1, dgg.getNumIdClusters());
     }
+
+    public void testLineColor() throws IOException {
+        SlideShow ppt = new SlideShow(_slTests.openResourceAsStream("51731.ppt"));
+        Shape[] shape = ppt.getSlides()[0].getShapes();
+
+        assertEquals(4, shape.length);
+
+        TextShape sh1 = (TextShape)shape[0];
+        assertEquals("Hello Apache POI", sh1.getText());
+        assertNull(sh1.getLineColor());
+
+        TextShape sh2 = (TextShape)shape[1];
+        assertEquals("Why are you showing this border?", sh2.getText());
+        assertNull(sh2.getLineColor());
+
+        TextShape sh3 = (TextShape)shape[2];
+        assertEquals("Text in a black border", sh3.getText());
+        assertEquals(Color.black, sh3.getLineColor());
+        assertEquals(0.75, sh3.getLineWidth());
+
+        TextShape sh4 = (TextShape)shape[3];
+        assertEquals("Border width is 5 pt", sh4.getText());
+        assertEquals(Color.black, sh4.getLineColor());
+        assertEquals(5.0, sh4.getLineWidth());
+    }
 }