]> source.dussan.org Git - poi.git/commitdiff
fix bug #44296: HSLF Not Extracting Slide Background Image
authorYegor Kozlov <yegor@apache.org>
Fri, 25 Jan 2008 19:37:22 +0000 (19:37 +0000)
committerYegor Kozlov <yegor@apache.org>
Fri, 25 Jan 2008 19:37:22 +0000 (19:37 +0000)
git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@615315 13f79535-47bb-0310-9956-ffa450edef68

src/documentation/content/xdocs/changes.xml
src/documentation/content/xdocs/status.xml
src/scratchpad/src/org/apache/poi/hslf/model/Fill.java
src/scratchpad/src/org/apache/poi/hslf/model/Picture.java
src/scratchpad/src/org/apache/poi/hslf/model/Shape.java
src/scratchpad/src/org/apache/poi/hslf/model/Slide.java
src/scratchpad/testcases/org/apache/poi/hslf/data/44296.ppt [new file with mode: 0755]
src/scratchpad/testcases/org/apache/poi/hslf/usermodel/TestBugs.java

index b1d8184e75c6812453767edb5af7f8c35d9be6f1..d5f6e9c53166af94458948eea1016282b995f65d 100644 (file)
@@ -36,6 +36,7 @@
 
                <!-- Don't forget to update status.xml too! -->
         <release version="3.0.2-FINAL" date="2008-??-??">
+            <action dev="POI-DEVELOPERS" type="fix">44296 - Fix for reading slide background images</action>
             <action dev="POI-DEVELOPERS" type="fix">44293 - Avoid swapping AreaPtgs from relative to absolute</action>
             <action dev="POI-DEVELOPERS" type="fix">44292 - Correctly process the last paragraph in a word file</action>
             <action dev="POI-DEVELOPERS" type="fix">44254 - Avoid some unread byte warnings, and properly understand DVALRecord</action>
index 8221954c09c9b6a49cbe3efceacada2c884e9f35..69190f915f16873b3e9e31a9078e079bb4196f26 100644 (file)
@@ -33,6 +33,7 @@
        <!-- Don't forget to update changes.xml too! -->
     <changes>
         <release version="3.0.2-FINAL" date="2008-??-??">
+            <action dev="POI-DEVELOPERS" type="fix">44296 - Fix for reading slide background images</action>
             <action dev="POI-DEVELOPERS" type="fix">44293 - Avoid swapping AreaPtgs from relative to absolute</action>
             <action dev="POI-DEVELOPERS" type="fix">44292 - Correctly process the last paragraph in a word file</action>
             <action dev="POI-DEVELOPERS" type="fix">44254 - Avoid some unread byte warnings, and properly understand DVALRecord</action>
index 7eae4edc4c3c56fab39af76d0a575bcfc8730f48..f9cc43a7eac6f98f779ce0edbb909b0261b3e6be 100644 (file)
@@ -23,6 +23,8 @@ import org.apache.poi.hslf.record.*;
 import org.apache.poi.hslf.usermodel.PictureData;
 import org.apache.poi.hslf.usermodel.SlideShow;
 import org.apache.poi.hslf.exceptions.HSLFException;
+import org.apache.poi.util.POILogger;
+import org.apache.poi.util.POILogFactory;
 
 import java.awt.*;
 import java.util.*;
@@ -33,6 +35,9 @@ import java.util.*;
  * @author Yegor Kozlov
  */
 public class Fill {
+    // For logging
+    protected POILogger logger = POILogFactory.getLogger(this.getClass());
+
     /**
      *  Fill with a solid color
      */
@@ -208,15 +213,18 @@ public class Fill {
 
         java.util.List lst = bstore.getChildRecords();
         int idx = p.getPropertyValue();
-        EscherBSERecord bse = (EscherBSERecord)lst.get(idx);
-        for ( int i = 0; i < pict.length; i++ ) {
-                       if (pict[i].getOffset() ==  bse.getOffset()){
-                return pict[i];
+        if (idx == 0){
+            logger.log(POILogger.ERROR, "no reference to picture data found ");
+        } else {
+            EscherBSERecord bse = (EscherBSERecord)lst.get(idx - 1);
+            for ( int i = 0; i < pict.length; i++ ) {
+                if (pict[i].getOffset() ==  bse.getOffset()){
+                    return pict[i];
+                }
             }
         }
-        throw new HSLFException("Picture data not found: \n" +
-                "  bse: " + bse + " at " + bse.getOffset() );
 
+        return null;
     }
 
     /**
index 0740e23bce0002f07319e90854495ac1f63eca95..90efd5f3ee5a1f41348ede304f5097b43861fc97 100644 (file)
@@ -109,7 +109,7 @@ public class Picture extends SimpleShape {
      */
     public int getPictureIndex(){
         EscherOptRecord opt = (EscherOptRecord)getEscherChild(_escherContainer, EscherOptRecord.RECORD_ID);
-        EscherSimpleProperty prop = (EscherSimpleProperty)getEscherProperty(opt, EscherProperties.BLIP__BLIPTODISPLAY + 0x4000);
+        EscherSimpleProperty prop = (EscherSimpleProperty)getEscherProperty(opt, EscherProperties.BLIP__BLIPTODISPLAY);
         return prop == null ? 0 : prop.getPropertyValue();
     }
 
index 56d77764e9256d21648bfc839f1b7884b3c0407b..5cff81a8d7234fc05c821b6a148730f3acb265eb 100644 (file)
@@ -227,7 +227,7 @@ public abstract class Shape {
         for ( Iterator iterator = opt.getEscherProperties().iterator(); iterator.hasNext(); )
         {
             EscherProperty prop = (EscherProperty) iterator.next();
-            if (prop.getId() == propId)
+            if (prop.getPropertyNumber() == propId)
                 return prop;
         }
         return null;
index 201a069fc4797210ed9e378276b5935cdc78ecbe..ea7201751d79310cb73d43925f549a8779c06e02 100644 (file)
@@ -262,4 +262,11 @@ public class Slide extends Sheet
         SlideAtom sa = getSlideRecord().getSlideAtom();
         return sa.getFollowMasterBackground();
     }
+
+    public Background getBackground() {
+        if(getFollowMasterBackground())
+            return getMasterSheet().getBackground();
+        else
+            return super.getBackground();
+    }
 }
diff --git a/src/scratchpad/testcases/org/apache/poi/hslf/data/44296.ppt b/src/scratchpad/testcases/org/apache/poi/hslf/data/44296.ppt
new file mode 100755 (executable)
index 0000000..1e0529d
Binary files /dev/null and b/src/scratchpad/testcases/org/apache/poi/hslf/data/44296.ppt differ
index 996a733ac981a5ea444cb099a0416bbad5ea9f98..f3f5f8e7ee8a653fca73bb309df4456c51668e72 100644 (file)
@@ -330,4 +330,24 @@ public class TestBugs extends TestCase {
             assertEquals(tr1[i].getText(), tr2[i].getText());\r
         }\r
     }\r
+\r
+    /**\r
+     * Bug 44296: HSLF Not Extracting Slide Background Image\r
+     */\r
+    public void test44296  () throws Exception {\r
+        FileInputStream is = new FileInputStream(new File(cwd, "44296.ppt"));\r
+        SlideShow ppt = new SlideShow(is);\r
+        is.close();\r
+\r
+        Slide slide = ppt.getSlides()[0];\r
+\r
+        Background b = slide.getBackground();\r
+        Fill f = b.getFill();\r
+        assertEquals(Fill.FILL_PICTURE, f.getFillType());\r
+\r
+        PictureData pict = f.getPictureData();\r
+        assertNotNull(pict);\r
+        assertEquals(Picture.JPEG, pict.getType());\r
+    }\r
+\r
 }\r