// 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);
}
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);
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();
}
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();
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;
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);
}
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);
}
}
}
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);
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
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