From e8208a736352f608a13e93a1aa24ff83fc5175ba Mon Sep 17 00:00:00 2001 From: Yegor Kozlov Date: Fri, 9 Dec 2011 12:50:20 +0000 Subject: [PATCH] Bugzilla 46288: fixed refcount of Fill pictures in HSLF git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1212381 13f79535-47bb-0310-9956-ffa450edef68 --- src/documentation/content/xdocs/status.xml | 1 + .../src/org/apache/poi/hslf/model/Fill.java | 37 +++++++++++++++++++ .../src/org/apache/poi/hslf/model/Shape.java | 4 +- .../apache/poi/hslf/model/TestBackground.java | 24 ++++++++++++ 4 files changed, 65 insertions(+), 1 deletion(-) diff --git a/src/documentation/content/xdocs/status.xml b/src/documentation/content/xdocs/status.xml index e05178fe9..2370acc90 100644 --- a/src/documentation/content/xdocs/status.xml +++ b/src/documentation/content/xdocs/status.xml @@ -34,6 +34,7 @@ + 46288 - fixed refcount of Fill pictures in HSLF 51961 - support compression of temp files in SXSSF 52268 - support cloning sheets with drawings in XSSF 52285 - Support XWPF smart tags text in Paragraphs 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 ec3ab7f22..0b8ddaad8 100644 --- a/src/scratchpad/src/org/apache/poi/hslf/model/Fill.java +++ b/src/scratchpad/src/org/apache/poi/hslf/model/Fill.java @@ -23,6 +23,7 @@ import org.apache.poi.hslf.usermodel.PictureData; import org.apache.poi.hslf.usermodel.SlideShow; import org.apache.poi.util.POILogger; import org.apache.poi.util.POILogFactory; +import java.util.List; import java.awt.*; @@ -116,6 +117,36 @@ public final class Fill { return prop == null ? FILL_SOLID : prop.getPropertyValue(); } + /** + */ + protected void afterInsert(Sheet sh){ + EscherOptRecord opt = (EscherOptRecord)Shape.getEscherChild(shape.getSpContainer(), EscherOptRecord.RECORD_ID); + EscherSimpleProperty p = (EscherSimpleProperty)Shape.getEscherProperty(opt, EscherProperties.FILL__PATTERNTEXTURE); + if(p != null) { + int idx = p.getPropertyValue(); + EscherBSERecord bse = getEscherBSERecord(idx); + bse.setRef(bse.getRef() + 1); + } + } + + protected EscherBSERecord getEscherBSERecord(int idx){ + Sheet sheet = shape.getSheet(); + if(sheet == null) { + logger.log(POILogger.DEBUG, "Fill has not yet been assigned to a sheet"); + return null; + } + SlideShow ppt = sheet.getSlideShow(); + Document doc = ppt.getDocumentRecord(); + EscherContainerRecord dggContainer = doc.getPPDrawingGroup().getDggContainer(); + EscherContainerRecord bstore = (EscherContainerRecord)Shape.getEscherChild(dggContainer, EscherContainerRecord.BSTORE_CONTAINER); + if(bstore == null) { + logger.log(POILogger.DEBUG, "EscherContainerRecord.BSTORE_CONTAINER was not found "); + return null; + } + List lst = bstore.getChildRecords(); + return (EscherBSERecord)lst.get(idx-1); + } + /** * Sets fill type. * Must be one of the FILL_* constants defined in this class. @@ -233,6 +264,12 @@ public final class Fill { public void setPictureData(int idx){ EscherOptRecord opt = (EscherOptRecord)Shape.getEscherChild(shape.getSpContainer(), EscherOptRecord.RECORD_ID); Shape.setEscherProperty(opt, (short)(EscherProperties.FILL__PATTERNTEXTURE + 0x4000), idx); + if( idx != 0 ) { + if( shape.getSheet() != null ) { + EscherBSERecord bse = getEscherBSERecord(idx); + bse.setRef(bse.getRef() + 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 3fca27c44..f2e934127 100644 --- a/src/scratchpad/src/org/apache/poi/hslf/model/Shape.java +++ b/src/scratchpad/src/org/apache/poi/hslf/model/Shape.java @@ -342,7 +342,9 @@ public abstract class Shape { * @param sh - owning shape */ protected void afterInsert(Sheet sh){ - + if(_fill != null) { + _fill.afterInsert(sh); + } } /** diff --git a/src/scratchpad/testcases/org/apache/poi/hslf/model/TestBackground.java b/src/scratchpad/testcases/org/apache/poi/hslf/model/TestBackground.java index 69e7a6b37..55082abe9 100644 --- a/src/scratchpad/testcases/org/apache/poi/hslf/model/TestBackground.java +++ b/src/scratchpad/testcases/org/apache/poi/hslf/model/TestBackground.java @@ -21,11 +21,15 @@ import junit.framework.TestCase; import java.io.*; import java.awt.*; +import java.util.List; +import org.apache.poi.ddf.*; +import org.apache.poi.hslf.record.Document; import org.apache.poi.hslf.usermodel.SlideShow; import org.apache.poi.hslf.HSLFSlideShow; import org.apache.poi.POIDataSamples; + /** * Test Fill object. * @@ -163,6 +167,7 @@ public final class TestBackground extends TestCase { fill = slides[0].getBackground().getFill(); assertEquals(Fill.FILL_PICTURE, fill.getFillType()); + assertEquals(3, getFillPictureRefCount(slides[0].getBackground(), fill)); shape = slides[0].getShapes()[0]; assertEquals(Fill.FILL_SOLID, shape.getFill().getFillType()); @@ -173,8 +178,10 @@ public final class TestBackground extends TestCase { fill = slides[2].getBackground().getFill(); assertEquals(Fill.FILL_TEXTURE, fill.getFillType()); + assertEquals(3, getFillPictureRefCount(slides[2].getBackground(), fill)); shape = slides[2].getShapes()[0]; assertEquals(Fill.FILL_PICTURE, shape.getFill().getFillType()); + assertEquals(1, getFillPictureRefCount(shape, fill)); fill = slides[3].getBackground().getFill(); assertEquals(Fill.FILL_SHADE_CENTER, fill.getFillType()); @@ -183,4 +190,21 @@ public final class TestBackground extends TestCase { } + private int getFillPictureRefCount(Shape shape, Fill fill) { + EscherOptRecord opt = (EscherOptRecord)Shape.getEscherChild(shape.getSpContainer(), EscherOptRecord.RECORD_ID); + EscherSimpleProperty p = (EscherSimpleProperty)Shape.getEscherProperty(opt, EscherProperties.FILL__PATTERNTEXTURE); + if(p != null) { + int idx = p.getPropertyValue(); + + Sheet sheet = shape.getSheet(); + SlideShow ppt = sheet.getSlideShow(); + Document doc = ppt.getDocumentRecord(); + EscherContainerRecord dggContainer = doc.getPPDrawingGroup().getDggContainer(); + EscherContainerRecord bstore = (EscherContainerRecord)Shape.getEscherChild(dggContainer, EscherContainerRecord.BSTORE_CONTAINER); + List lst = bstore.getChildRecords(); + return ((EscherBSERecord)lst.get(idx-1)).getRef(); + } + return 0; + } + }