aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorYegor Kozlov <yegor@apache.org>2012-02-22 11:44:21 +0000
committerYegor Kozlov <yegor@apache.org>2012-02-22 11:44:21 +0000
commit63bb61c8202a7711ec611ccfff2dc1ae456afc89 (patch)
tree1ec3eaccae6d6a91defecfe89df5e5aca93d0ea6
parentbd09f7104319b1822100e3499cca0d353e5212fd (diff)
downloadpoi-63bb61c8202a7711ec611ccfff2dc1ae456afc89.tar.gz
poi-63bb61c8202a7711ec611ccfff2dc1ae456afc89.zip
Bugzilla 51731 - fixed painting shape outlines in HSLF
git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1292247 13f79535-47bb-0310-9956-ffa450edef68
-rw-r--r--src/documentation/content/xdocs/status.xml1
-rw-r--r--src/scratchpad/src/org/apache/poi/hslf/model/Fill.java27
-rw-r--r--src/scratchpad/src/org/apache/poi/hslf/model/Shape.java70
-rw-r--r--src/scratchpad/src/org/apache/poi/hslf/model/SimpleShape.java22
-rw-r--r--src/scratchpad/testcases/org/apache/poi/hslf/model/TestShapes.java25
5 files changed, 102 insertions, 43 deletions
diff --git a/src/documentation/content/xdocs/status.xml b/src/documentation/content/xdocs/status.xml
index 9e88c81f2f..a2bd2f3d0b 100644
--- a/src/documentation/content/xdocs/status.xml
+++ b/src/documentation/content/xdocs/status.xml
@@ -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>
diff --git a/src/scratchpad/src/org/apache/poi/hslf/model/Fill.java b/src/scratchpad/src/org/apache/poi/hslf/model/Fill.java
index 0b8ddaad88..036219a258 100644
--- a/src/scratchpad/src/org/apache/poi/hslf/model/Fill.java
+++ b/src/scratchpad/src/org/apache/poi/hslf/model/Fill.java
@@ -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);
}
/**
diff --git a/src/scratchpad/src/org/apache/poi/hslf/model/Shape.java b/src/scratchpad/src/org/apache/poi/hslf/model/Shape.java
index f2e934127d..88c0b19fdd 100644
--- a/src/scratchpad/src/org/apache/poi/hslf/model/Shape.java
+++ b/src/scratchpad/src/org/apache/poi/hslf/model/Shape.java
@@ -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);
}
/**
diff --git a/src/scratchpad/src/org/apache/poi/hslf/model/SimpleShape.java b/src/scratchpad/src/org/apache/poi/hslf/model/SimpleShape.java
index ee2d8f98e5..3f7ce7cb31 100644
--- a/src/scratchpad/src/org/apache/poi/hslf/model/SimpleShape.java
+++ b/src/scratchpad/src/org/apache/poi/hslf/model/SimpleShape.java
@@ -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;
}
/**
diff --git a/src/scratchpad/testcases/org/apache/poi/hslf/model/TestShapes.java b/src/scratchpad/testcases/org/apache/poi/hslf/model/TestShapes.java
index 0d016e39d3..6018cf5f52 100644
--- a/src/scratchpad/testcases/org/apache/poi/hslf/model/TestShapes.java
+++ b/src/scratchpad/testcases/org/apache/poi/hslf/model/TestShapes.java
@@ -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());
+ }
}