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
This commit is contained in:
parent
a2aa35c9a8
commit
a4c7338078
@ -34,6 +34,7 @@
|
|||||||
|
|
||||||
<changes>
|
<changes>
|
||||||
<release version="3.8-beta6" date="2012-??-??">
|
<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">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="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>
|
<action dev="poi-developers" type="add"> allow runtime registration of functions in FormulaEvaluator</action>
|
||||||
|
@ -163,19 +163,12 @@ public final class Fill {
|
|||||||
*/
|
*/
|
||||||
public Color getForegroundColor(){
|
public Color getForegroundColor(){
|
||||||
EscherOptRecord opt = (EscherOptRecord)Shape.getEscherChild(shape.getSpContainer(), EscherOptRecord.RECORD_ID);
|
EscherOptRecord opt = (EscherOptRecord)Shape.getEscherChild(shape.getSpContainer(), EscherOptRecord.RECORD_ID);
|
||||||
EscherSimpleProperty p1 = (EscherSimpleProperty)Shape.getEscherProperty(opt, EscherProperties.FILL__FILLCOLOR);
|
EscherSimpleProperty p = (EscherSimpleProperty)Shape.getEscherProperty(opt, EscherProperties.FILL__NOFILLHITTEST);
|
||||||
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();
|
if(p != null && (p.getPropertyValue() & 0x10) == 0) return null;
|
||||||
int alpha = p3 == null ? 255 : ((p3.getPropertyValue() >> 8) & 0xFF);
|
|
||||||
|
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(){
|
public Color getBackgroundColor(){
|
||||||
EscherOptRecord opt = (EscherOptRecord)Shape.getEscherChild(shape.getSpContainer(), EscherOptRecord.RECORD_ID);
|
EscherOptRecord opt = (EscherOptRecord)Shape.getEscherChild(shape.getSpContainer(), EscherOptRecord.RECORD_ID);
|
||||||
EscherSimpleProperty p1 = (EscherSimpleProperty)Shape.getEscherProperty(opt, EscherProperties.FILL__FILLBACKCOLOR);
|
EscherSimpleProperty p = (EscherSimpleProperty)Shape.getEscherProperty(opt, EscherProperties.FILL__NOFILLHITTEST);
|
||||||
EscherSimpleProperty p2 = (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;
|
return shape.getColor(EscherProperties.FILL__FILLBACKCOLOR, EscherProperties.FILL__FILLOPACITY, -1);
|
||||||
if (p1 != null && (p2val & 0x10) != 0){
|
|
||||||
int rgb = p1.getPropertyValue();
|
|
||||||
clr = shape.getColor(rgb, 255);
|
|
||||||
}
|
|
||||||
return clr;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -363,14 +363,72 @@ public abstract class Shape {
|
|||||||
_sheet = sheet;
|
_sheet = sheet;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected Color getColor(int rgb, int alpha){
|
Color getColor(short colorProperty, short opacityProperty, int defaultColor){
|
||||||
if (rgb >= 0x8000000) {
|
EscherOptRecord opt = (EscherOptRecord)getEscherChild(_escherContainer, EscherOptRecord.RECORD_ID);
|
||||||
int idx = rgb - 0x8000000;
|
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();
|
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
|
||||||
}
|
}
|
||||||
Color tmp = new Color(rgb, true);
|
|
||||||
return new Color(tmp.getBlue(), tmp.getGreen(), tmp.getRed(), alpha);
|
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;
|
||||||
|
}
|
||||||
|
return new Color(r, g, b);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -138,23 +138,11 @@ public abstract class SimpleShape extends Shape {
|
|||||||
public Color getLineColor(){
|
public Color getLineColor(){
|
||||||
EscherOptRecord opt = (EscherOptRecord)getEscherChild(_escherContainer, EscherOptRecord.RECORD_ID);
|
EscherOptRecord opt = (EscherOptRecord)getEscherChild(_escherContainer, EscherOptRecord.RECORD_ID);
|
||||||
|
|
||||||
EscherSimpleProperty p1 = (EscherSimpleProperty)getEscherProperty(opt, EscherProperties.LINESTYLE__COLOR);
|
EscherSimpleProperty p = (EscherSimpleProperty)getEscherProperty(opt, EscherProperties.LINESTYLE__NOLINEDRAWDASH);
|
||||||
EscherSimpleProperty p2 = (EscherSimpleProperty)getEscherProperty(opt, EscherProperties.LINESTYLE__NOLINEDRAWDASH);
|
if(p != null && (p.getPropertyValue() & 0x8) == 0) return null;
|
||||||
int p2val = p2 == null ? 0 : p2.getPropertyValue();
|
|
||||||
Color clr = null;
|
Color clr = getColor(EscherProperties.LINESTYLE__COLOR, EscherProperties.LINESTYLE__OPACITY, -1);
|
||||||
if ((p2val & 0x8) != 0 || (p2val & 0x10) != 0){
|
return clr == null ? Color.black : clr;
|
||||||
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;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -366,4 +366,29 @@ public final class TestShapes extends TestCase {
|
|||||||
}
|
}
|
||||||
assertEquals(numClusters + 1, dgg.getNumIdClusters());
|
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…
Reference in New Issue
Block a user