]> source.dussan.org Git - poi.git/commitdiff
applied patches from bug 42474: (1) Incorrect matching of notes to slides and (2...
authorYegor Kozlov <yegor@apache.org>
Thu, 24 May 2007 07:52:04 +0000 (07:52 +0000)
committerYegor Kozlov <yegor@apache.org>
Thu, 24 May 2007 07:52:04 +0000 (07:52 +0000)
git-svn-id: https://svn.apache.org/repos/asf/jakarta/poi/trunk@541219 13f79535-47bb-0310-9956-ffa450edef68

src/scratchpad/src/org/apache/poi/hslf/model/Notes.java
src/scratchpad/src/org/apache/poi/hslf/usermodel/RichTextRun.java
src/scratchpad/src/org/apache/poi/hslf/usermodel/SlideShow.java
src/scratchpad/testcases/org/apache/poi/hslf/data/42474-1.ppt [new file with mode: 0644]
src/scratchpad/testcases/org/apache/poi/hslf/data/42474-2.ppt [new file with mode: 0644]
src/scratchpad/testcases/org/apache/poi/hslf/usermodel/TestBugs.java

index dce95ec0b7d63e3b98e1ec17d548f02d00e1e155..20547571fc0348778f9dd4331f2f5c6c0ddfd548 100644 (file)
@@ -56,6 +56,10 @@ public class Notes extends Sheet
        //  one of TextBytesAtom or TextCharsAtom, found inside 
        //  EscherTextboxWrapper's in the PPDrawing
        _runs = findTextRuns(_notes.getPPDrawing());
+
+       // Set the sheet on each TextRun
+       for (int i = 0; i < _runs.length; i++)
+               _runs[i].setSheet(this);
   }
 
 
index 3fd9c95259f85d56d0834bb12f4069a5b78340a8..99515198ed1ddec499a6248aee2cf0ea844c3124 100644 (file)
@@ -170,7 +170,8 @@ public class RichTextRun
             Sheet sheet = parentRun.getSheet();
             int txtype = parentRun.getRunType();
             SlideMaster master = (SlideMaster)sheet.getMasterSheet();
-            cftp = (CharFlagsTextProp)master.getStyleAttribute(txtype, getIndentLevel(), "char_flags", true);
+            if (master != null)
+                cftp = (CharFlagsTextProp)master.getStyleAttribute(txtype, getIndentLevel(), "char_flags", true);
         }
 
                return cftp == null ? false : cftp.getSubValue(index);
@@ -223,7 +224,8 @@ public class RichTextRun
             Sheet sheet = parentRun.getSheet();
             int txtype = parentRun.getRunType();
             SlideMaster master = (SlideMaster)sheet.getMasterSheet();
-            prop = master.getStyleAttribute(txtype, getIndentLevel(), propName, true);
+            if (master != null)
+                prop = master.getStyleAttribute(txtype, getIndentLevel(), propName, true);
         }
                return prop == null ? -1 : prop.getValue();
        }
@@ -242,7 +244,8 @@ public class RichTextRun
             Sheet sheet = parentRun.getSheet();
             int txtype = parentRun.getRunType();
             SlideMaster master = (SlideMaster)sheet.getMasterSheet();
-            prop = master.getStyleAttribute(txtype, getIndentLevel(), propName, false);
+            if (master != null)
+                prop = master.getStyleAttribute(txtype, getIndentLevel(), propName, false);
         }
 
                return prop == null ? -1 : prop.getValue();
index fdecb2bb0484ada2716a6c3b8430c71572427bd4..7f201fb7b46d136d44ca2b152816a41a5c5a19e0 100644 (file)
@@ -30,21 +30,10 @@ import org.apache.poi.ddf.EscherOptRecord;
 import org.apache.poi.ddf.EscherRecord;
 import org.apache.poi.hslf.*;
 import org.apache.poi.hslf.model.*;
-import org.apache.poi.hslf.record.Document;
-import org.apache.poi.hslf.record.DocumentAtom;
-import org.apache.poi.hslf.record.FontCollection;
-import org.apache.poi.hslf.record.ParentAwareRecord;
-import org.apache.poi.hslf.record.PositionDependentRecordContainer;
-import org.apache.poi.hslf.record.Record;
-import org.apache.poi.hslf.record.RecordContainer;
-import org.apache.poi.hslf.record.RecordTypes;
-import org.apache.poi.hslf.record.SlideAtom;
-import org.apache.poi.hslf.record.SlideListWithText;
-import org.apache.poi.hslf.record.SlidePersistAtom;
-import org.apache.poi.hslf.record.UserEditAtom;
+import org.apache.poi.hslf.model.Notes;
+import org.apache.poi.hslf.model.Slide;
 import org.apache.poi.hslf.record.SlideListWithText.*;
-import org.apache.poi.hslf.record.PersistPtrHolder;
-import org.apache.poi.hslf.record.PositionDependentRecord;
+import org.apache.poi.hslf.record.*;
 import org.apache.poi.hslf.exceptions.CorruptPowerPointFileException;
 import org.apache.poi.util.ArrayUtil;
 import org.apache.poi.util.POILogFactory;
@@ -363,13 +352,14 @@ public class SlideShow
                        Record r = getCoreRecordForSAS(notesSets[i]);
                        
                        // Ensure it really is a notes record
-                       if(r != null && r instanceof org.apache.poi.hslf.record.Notes) {
-                               notesRecordsL.add( (org.apache.poi.hslf.record.Notes)r );
+                       if(r instanceof org.apache.poi.hslf.record.Notes) {
+                org.apache.poi.hslf.record.Notes notesRecord = (org.apache.poi.hslf.record.Notes)r;
+                               notesRecordsL.add( notesRecord );
                                
                                // Record the match between slide id and these notes
-                               SlidePersistAtom spa = notesSets[i].getSlidePersistAtom();
-                               Integer slideId = new Integer(spa.getSlideIdentifier());
-                               slideIdToNotes.put(slideId, new Integer(i));
+                SlidePersistAtom spa = notesSets[i].getSlidePersistAtom();
+                Integer slideId = new Integer(spa.getSlideIdentifier());
+                slideIdToNotes.put(slideId, new Integer(i));
                        } else {
                                logger.log(POILogger.ERROR, "A Notes SlideAtomSet at " + i + " said its record was at refID " + notesSets[i].getSlidePersistAtom().getRefID() + ", but that was actually a " + r);
                        }
@@ -397,7 +387,7 @@ public class SlideShow
                        if(r instanceof org.apache.poi.hslf.record.Slide) {
                                slidesRecords[i] = (org.apache.poi.hslf.record.Slide)r;
                        } else {
-                               System.err.println("A Slide SlideAtomSet at " + i + " said its record was at refID " + slidesSets[i].getSlidePersistAtom().getRefID() + ", but that was actually a " + r);
+                               logger.log(POILogger.ERROR, "A Slide SlideAtomSet at " + i + " said its record was at refID " + slidesSets[i].getSlidePersistAtom().getRefID() + ", but that was actually a " + r);
                        }
                }
        }
@@ -422,15 +412,17 @@ public class SlideShow
        for(int i=0; i<_slides.length; i++) {
                SlideAtomsSet sas = slidesSets[i];
                int slideIdentifier = sas.getSlidePersistAtom().getSlideIdentifier();
-               Integer slideIdentifierI = new Integer(slideIdentifier);
-               
+
                // Do we have a notes for this?
                Notes notes = null;
-               if(slideIdToNotes.containsKey(slideIdentifierI)) {
-                       Integer notesPos = (Integer)slideIdToNotes.get(slideIdentifierI);
-                       notes = _notes[notesPos.intValue()];
-               }
-               
+        //Slide.SlideAtom.notesId references the corresponding notes slide. 0 if slide has no notes.
+        int noteId = slidesRecords[i].getSlideAtom().getNotesID();
+        if (noteId != 0){
+            Integer notesPos = (Integer)slideIdToNotes.get(new Integer(noteId));
+            if (notesPos != null) notes = _notes[notesPos.intValue()];
+            else logger.log(POILogger.ERROR, "Notes not found for noteId=" + noteId);
+        }
+
                // Now, build our slide
                _slides[i] = new Slide(slidesRecords[i], notes, sas, slideIdentifier, (i+1));
                _slides[i].setSlideShow(this);
diff --git a/src/scratchpad/testcases/org/apache/poi/hslf/data/42474-1.ppt b/src/scratchpad/testcases/org/apache/poi/hslf/data/42474-1.ppt
new file mode 100644 (file)
index 0000000..15b654d
Binary files /dev/null and b/src/scratchpad/testcases/org/apache/poi/hslf/data/42474-1.ppt differ
diff --git a/src/scratchpad/testcases/org/apache/poi/hslf/data/42474-2.ppt b/src/scratchpad/testcases/org/apache/poi/hslf/data/42474-2.ppt
new file mode 100644 (file)
index 0000000..5c6f8ca
Binary files /dev/null and b/src/scratchpad/testcases/org/apache/poi/hslf/data/42474-2.ppt differ
index cfc3c95295b03aa14de130397eda12236f6ee279..e79d05bc545cc1ebf801114fbeb93a04a9e67833 100644 (file)
@@ -20,8 +20,13 @@ package org.apache.poi.hslf.usermodel;
 import junit.framework.TestCase;\r
 import org.apache.poi.hslf.HSLFSlideShow;\r
 import org.apache.poi.hslf.model.Picture;\r
+import org.apache.poi.hslf.model.Slide;\r
+import org.apache.poi.hslf.model.Notes;\r
+import org.apache.poi.hslf.model.TextRun;\r
 \r
 import java.io.*;\r
+import java.util.HashSet;\r
+import java.util.HashMap;\r
 \r
 /**\r
  * Testcases for bugs entered in bugzilla\r
@@ -50,4 +55,67 @@ public class TestBugs extends TestCase {
         assertEquals(Picture.JPEG, pict[0].getType());\r
         assertEquals(Picture.JPEG, pict[1].getType());\r
     }\r
+\r
+    /**\r
+     * First fix from Bug 42474: NPE in RichTextRun.isBold()\r
+     * when the RichTextRun comes from a Notes model object\r
+     */\r
+    public void test42474_1() throws Exception {\r
+        FileInputStream is = new FileInputStream(new File(cwd, "42474-1.ppt"));\r
+        HSLFSlideShow hslf = new HSLFSlideShow(is);\r
+        is.close();\r
+\r
+        SlideShow ppt = new SlideShow(hslf);\r
+        assertTrue("No Exceptions while reading file", true);\r
+        assertEquals(2, ppt.getSlides().length);\r
+\r
+        TextRun txrun;\r
+        Notes notes;\r
+\r
+        notes = ppt.getSlides()[0].getNotesSheet();\r
+        assertNotNull(notes);\r
+        txrun = notes.getTextRuns()[0];\r
+        assertEquals("Notes-1", txrun.getRawText());\r
+        assertEquals(false, txrun.getRichTextRuns()[0].isBold());\r
+\r
+        //notes for the second slide are in bold\r
+        notes = ppt.getSlides()[1].getNotesSheet();\r
+        assertNotNull(notes);\r
+        txrun = notes.getTextRuns()[0];\r
+        assertEquals("Notes-2", txrun.getRawText());\r
+        assertEquals(true, txrun.getRichTextRuns()[0].isBold());\r
+\r
+    }\r
+\r
+    /**\r
+     * Second fix from Bug 42474: Incorrect matching of notes to slides\r
+     */\r
+    public void test42474_2() throws Exception {\r
+        FileInputStream is = new FileInputStream(new File(cwd, "42474-2.ppt"));\r
+        HSLFSlideShow hslf = new HSLFSlideShow(is);\r
+        is.close();\r
+\r
+        SlideShow ppt = new SlideShow(hslf);\r
+\r
+        //map slide number and starting phrase of its notes\r
+        HashMap notesMap = new HashMap();\r
+        notesMap.put(new Integer(4), "For  decades before calculators");\r
+        notesMap.put(new Integer(5), "Several commercial applications");\r
+        notesMap.put(new Integer(6), "There are three variations of LNS that are discussed here");\r
+        notesMap.put(new Integer(7), "Although multiply and square root are easier");\r
+        notesMap.put(new Integer(8), "The bus Z is split into Z_H and Z_L");\r
+\r
+        Slide[] slide = ppt.getSlides();\r
+        for (int i = 0; i < slide.length; i++) {\r
+            Integer slideNumber = new Integer(slide[i].getSlideNumber());\r
+            Notes notes = slide[i].getNotesSheet();\r
+            if (notesMap.containsKey(slideNumber)){\r
+                assertNotNull(notes);\r
+                String text = notes.getTextRuns()[0].getRawText();\r
+                String startingPhrase = (String)notesMap.get(slideNumber);\r
+                assertTrue("Notes for slide " + slideNumber + " must start with " +\r
+                        startingPhrase , text.startsWith(startingPhrase));\r
+            }\r
+        }\r
+    }\r
 }\r