use of org.apache.poi.hslf.record.SlideListWithText.SlideAtomsSet in project poi by apache.
the class HSLFSlideShow method findNotesSlides.
private void findNotesSlides(Map<Integer, Integer> slideIdToNotes) {
SlideListWithText notesSLWT = _documentRecord.getNotesSlideListWithText();
if (notesSLWT == null) {
return;
}
// Match up the records and the SlideAtomSets
int idx = -1;
for (SlideAtomsSet notesSet : notesSLWT.getSlideAtomsSets()) {
idx++;
// Get the right core record
Record r = getCoreRecordForSAS(notesSet);
SlidePersistAtom spa = notesSet.getSlidePersistAtom();
String loggerLoc = "A Notes SlideAtomSet at " + idx + " said its record was at refID " + spa.getRefID();
// we need to add null-records, otherwise the index references to other existing don't work anymore
if (r == null) {
logger.log(POILogger.WARN, loggerLoc + ", but that record didn't exist - record ignored.");
continue;
}
// Ensure it really is a notes record
if (!(r instanceof Notes)) {
logger.log(POILogger.ERROR, loggerLoc + ", but that was actually a " + r);
continue;
}
Notes notesRecord = (Notes) r;
// Record the match between slide id and these notes
int slideId = spa.getSlideIdentifier();
slideIdToNotes.put(slideId, idx);
HSLFNotes hn = new HSLFNotes(notesRecord);
hn.setSlideShow(this);
_notes.add(hn);
}
}
use of org.apache.poi.hslf.record.SlideListWithText.SlideAtomsSet in project poi by apache.
the class TestBugs method bug56260.
@Test
public void bug56260() throws IOException {
HSLFSlideShow ppt = open("56260.ppt");
List<HSLFSlide> _slides = ppt.getSlides();
assertEquals(13, _slides.size());
// Check the number of TextHeaderAtoms on Slide 1
Document dr = ppt.getDocumentRecord();
SlideListWithText slidesSLWT = dr.getSlideSlideListWithText();
SlideAtomsSet s1 = slidesSLWT.getSlideAtomsSets()[0];
int tha = 0;
for (Record r : s1.getSlideRecords()) {
if (r instanceof TextHeaderAtom) {
tha++;
}
}
assertEquals(2, tha);
// Check to see that we have a pair next to each other
assertEquals(TextHeaderAtom.class, s1.getSlideRecords()[0].getClass());
assertEquals(TextHeaderAtom.class, s1.getSlideRecords()[1].getClass());
// Check the number of text runs based on the slide (not textbox)
// Will have skipped the empty one
int str = 0;
for (List<HSLFTextParagraph> tr : _slides.get(0).getTextParagraphs()) {
if (!tr.get(0).isDrawingBased()) {
str++;
}
}
assertEquals(2, str);
ppt.close();
}
use of org.apache.poi.hslf.record.SlideListWithText.SlideAtomsSet in project poi by apache.
the class HSLFSlideShow method findMasterSlides.
/**
* Find master slides
* These can be MainMaster records, but oddly they can also be
* Slides or Notes, and possibly even other odd stuff....
* About the only thing you can say is that the master details are in the first SLWT.
*/
private void findMasterSlides() {
SlideListWithText masterSLWT = _documentRecord.getMasterSlideListWithText();
if (masterSLWT == null) {
return;
}
for (SlideAtomsSet sas : masterSLWT.getSlideAtomsSets()) {
Record r = getCoreRecordForSAS(sas);
int sheetNo = sas.getSlidePersistAtom().getSlideIdentifier();
if (r instanceof Slide) {
HSLFTitleMaster master = new HSLFTitleMaster((Slide) r, sheetNo);
master.setSlideShow(this);
_titleMasters.add(master);
} else if (r instanceof MainMaster) {
HSLFSlideMaster master = new HSLFSlideMaster((MainMaster) r, sheetNo);
master.setSlideShow(this);
_masters.add(master);
}
}
}
use of org.apache.poi.hslf.record.SlideListWithText.SlideAtomsSet in project poi by apache.
the class HSLFSlideShow method createSlide.
/**
* Create a blank <code>Slide</code>.
*
* @return the created <code>Slide</code>
*/
@Override
public HSLFSlide createSlide() {
// We need to add the records to the SLWT that deals
// with Slides.
// Add it, if it doesn't exist
SlideListWithText slist = _documentRecord.getSlideSlideListWithText();
if (slist == null) {
// Need to add a new one
slist = new SlideListWithText();
slist.setInstance(SlideListWithText.SLIDES);
_documentRecord.addSlideListWithText(slist);
}
// Grab the SlidePersistAtom with the highest Slide Number.
// (Will stay as null if no SlidePersistAtom exists yet in
// the slide, or only master slide's ones do)
SlidePersistAtom prev = null;
for (SlideAtomsSet sas : slist.getSlideAtomsSets()) {
SlidePersistAtom spa = sas.getSlidePersistAtom();
if (spa.getSlideIdentifier() < 0) {
// This is for a master slide
// Odd, since we only deal with the Slide SLWT
} else {
// Must be for a real slide
if (prev == null) {
prev = spa;
}
if (prev.getSlideIdentifier() < spa.getSlideIdentifier()) {
prev = spa;
}
}
}
// Set up a new SlidePersistAtom for this slide
SlidePersistAtom sp = new SlidePersistAtom();
// First slideId is always 256
sp.setSlideIdentifier(prev == null ? 256 : (prev.getSlideIdentifier() + 1));
// Add this new SlidePersistAtom to the SlideListWithText
slist.addSlidePersistAtom(sp);
// Create a new Slide
HSLFSlide slide = new HSLFSlide(sp.getSlideIdentifier(), sp.getRefID(), _slides.size() + 1);
slide.setSlideShow(this);
slide.onCreate();
// Add in to the list of Slides
_slides.add(slide);
logger.log(POILogger.INFO, "Added slide " + _slides.size() + " with ref " + sp.getRefID() + " and identifier " + sp.getSlideIdentifier());
// Add the core records for this new Slide to the record tree
Slide slideRecord = slide.getSlideRecord();
int psrId = addPersistentObject(slideRecord);
sp.setRefID(psrId);
slideRecord.setSheetId(psrId);
slide.setMasterSheet(_masters.get(0));
// All done and added
return slide;
}
use of org.apache.poi.hslf.record.SlideListWithText.SlideAtomsSet in project poi by apache.
the class HSLFSlideShow method findSlides.
private void findSlides(Map<Integer, Integer> slideIdToNotes) {
SlideListWithText slidesSLWT = _documentRecord.getSlideSlideListWithText();
if (slidesSLWT == null) {
return;
}
// Match up the records and the SlideAtomSets
int idx = -1;
for (SlideAtomsSet sas : slidesSLWT.getSlideAtomsSets()) {
idx++;
// Get the right core record
SlidePersistAtom spa = sas.getSlidePersistAtom();
Record r = getCoreRecordForSAS(sas);
// Ensure it really is a slide record
if (!(r instanceof Slide)) {
logger.log(POILogger.ERROR, "A Slide SlideAtomSet at " + idx + " said its record was at refID " + spa.getRefID() + ", but that was actually a " + r);
continue;
}
Slide slide = (Slide) r;
// Do we have a notes for this?
HSLFNotes notes = null;
// Slide.SlideAtom.notesId references the corresponding notes slide.
// 0 if slide has no notes.
int noteId = slide.getSlideAtom().getNotesID();
if (noteId != 0) {
Integer notesPos = slideIdToNotes.get(noteId);
if (notesPos != null && 0 <= notesPos && notesPos < _notes.size()) {
notes = _notes.get(notesPos);
} else {
logger.log(POILogger.ERROR, "Notes not found for noteId=" + noteId);
}
}
// Now, build our slide
int slideIdentifier = spa.getSlideIdentifier();
HSLFSlide hs = new HSLFSlide(slide, notes, sas, slideIdentifier, (idx + 1));
hs.setSlideShow(this);
_slides.add(hs);
}
}
Aggregations