Browse Source

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
tags/REL_3_8_FINAL
Yegor Kozlov 12 years ago
parent
commit
63bb61c820

+ 1
- 0
src/documentation/content/xdocs/status.xml View 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>

+ 7
- 20
src/scratchpad/src/org/apache/poi/hslf/model/Fill.java View 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);
}

/**

+ 64
- 6
src/scratchpad/src/org/apache/poi/hslf/model/Shape.java View 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);
}

/**

+ 5
- 17
src/scratchpad/src/org/apache/poi/hslf/model/SimpleShape.java View 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;
}

/**

+ 25
- 0
src/scratchpad/testcases/org/apache/poi/hslf/model/TestShapes.java View 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());
}
}

Loading…
Cancel
Save