poi-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ye...@apache.org
Subject svn commit: r1292247 - in /poi/trunk/src: documentation/content/xdocs/ scratchpad/src/org/apache/poi/hslf/model/ scratchpad/testcases/org/apache/poi/hslf/model/
Date Wed, 22 Feb 2012 11:44:21 GMT
Author: yegor
Date: Wed Feb 22 11:44:21 2012
New Revision: 1292247

URL: http://svn.apache.org/viewvc?rev=1292247&view=rev
Log:
Bugzilla 51731 - fixed painting shape outlines in HSLF

Modified:
    poi/trunk/src/documentation/content/xdocs/status.xml
    poi/trunk/src/scratchpad/src/org/apache/poi/hslf/model/Fill.java
    poi/trunk/src/scratchpad/src/org/apache/poi/hslf/model/Shape.java
    poi/trunk/src/scratchpad/src/org/apache/poi/hslf/model/SimpleShape.java
    poi/trunk/src/scratchpad/testcases/org/apache/poi/hslf/model/TestShapes.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=1292247&r1=1292246&r2=1292247&view=diff
==============================================================================
--- poi/trunk/src/documentation/content/xdocs/status.xml (original)
+++ poi/trunk/src/documentation/content/xdocs/status.xml Wed Feb 22 11:44:21 2012
@@ -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>

Modified: poi/trunk/src/scratchpad/src/org/apache/poi/hslf/model/Fill.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/scratchpad/src/org/apache/poi/hslf/model/Fill.java?rev=1292247&r1=1292246&r2=1292247&view=diff
==============================================================================
--- poi/trunk/src/scratchpad/src/org/apache/poi/hslf/model/Fill.java (original)
+++ poi/trunk/src/scratchpad/src/org/apache/poi/hslf/model/Fill.java Wed Feb 22 11:44:21 2012
@@ -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);
-
-        int p2val = p2 == null ? 0 : p2.getPropertyValue();
-        int alpha =  p3 == null ? 255 : ((p3.getPropertyValue() >> 8) & 0xFF);
-
-        Color clr = null;
-        if (p1 != null && (p2val  & 0x10) != 0){
-            int rgb = p1.getPropertyValue();
-            clr = shape.getColor(rgb, alpha);
-        }
-        return clr;
+        EscherSimpleProperty p = (EscherSimpleProperty)Shape.getEscherProperty(opt, EscherProperties.FILL__NOFILLHITTEST);
+
+        if(p != null && (p.getPropertyValue() & 0x10) == 0) return null;
+
+        return shape.getColor(EscherProperties.FILL__FILLCOLOR, EscherProperties.FILL__FILLOPACITY,
-1);
+
     }
 
     /**
@@ -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);
     }
 
     /**

Modified: poi/trunk/src/scratchpad/src/org/apache/poi/hslf/model/Shape.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/scratchpad/src/org/apache/poi/hslf/model/Shape.java?rev=1292247&r1=1292246&r2=1292247&view=diff
==============================================================================
--- poi/trunk/src/scratchpad/src/org/apache/poi/hslf/model/Shape.java (original)
+++ poi/trunk/src/scratchpad/src/org/apache/poi/hslf/model/Shape.java Wed Feb 22 11:44:21
2012
@@ -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);
     }
 
     /**

Modified: poi/trunk/src/scratchpad/src/org/apache/poi/hslf/model/SimpleShape.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/scratchpad/src/org/apache/poi/hslf/model/SimpleShape.java?rev=1292247&r1=1292246&r2=1292247&view=diff
==============================================================================
--- poi/trunk/src/scratchpad/src/org/apache/poi/hslf/model/SimpleShape.java (original)
+++ poi/trunk/src/scratchpad/src/org/apache/poi/hslf/model/SimpleShape.java Wed Feb 22 11:44:21
2012
@@ -138,23 +138,11 @@ public abstract class SimpleShape extend
     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;
     }
 
     /**

Modified: poi/trunk/src/scratchpad/testcases/org/apache/poi/hslf/model/TestShapes.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/scratchpad/testcases/org/apache/poi/hslf/model/TestShapes.java?rev=1292247&r1=1292246&r2=1292247&view=diff
==============================================================================
--- poi/trunk/src/scratchpad/testcases/org/apache/poi/hslf/model/TestShapes.java (original)
+++ poi/trunk/src/scratchpad/testcases/org/apache/poi/hslf/model/TestShapes.java Wed Feb 22
11:44:21 2012
@@ -366,4 +366,29 @@ public final class TestShapes extends Te
         }
         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());
+    }
 }



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


Mime
View raw message