From 9329c11565e3770ae8ca9f18c554bd6a8f839152 Mon Sep 17 00:00:00 2001 From: Nick Burch Date: Mon, 27 Mar 2006 21:35:37 +0000 Subject: [PATCH] Big change in how we tie slides, notes, and their text together. Now make use of the RefID and SlideIndentifier values to pull everything together git-svn-id: https://svn.apache.org/repos/asf/jakarta/poi/trunk@389286 13f79535-47bb-0310-9956-ffa450edef68 --- .../hslf/extractor/PowerPointExtractor.java | 2 +- .../src/org/apache/poi/hslf/model/Notes.java | 15 +- .../src/org/apache/poi/hslf/model/Sheet.java | 8 +- .../src/org/apache/poi/hslf/model/Slide.java | 21 +- .../org/apache/poi/hslf/model/TextRun.java | 3 +- .../poi/hslf/record/SlideListWithText.java | 7 +- .../apache/poi/hslf/usermodel/SlideShow.java | 278 ++++++++++-------- 7 files changed, 195 insertions(+), 139 deletions(-) diff --git a/src/scratchpad/src/org/apache/poi/hslf/extractor/PowerPointExtractor.java b/src/scratchpad/src/org/apache/poi/hslf/extractor/PowerPointExtractor.java index c6f8094599..8db7382e97 100644 --- a/src/scratchpad/src/org/apache/poi/hslf/extractor/PowerPointExtractor.java +++ b/src/scratchpad/src/org/apache/poi/hslf/extractor/PowerPointExtractor.java @@ -163,7 +163,7 @@ public class PowerPointExtractor for(int i=0; i<_slides.length; i++) { Notes notes = _slides[i].getNotesSheet(); if(notes == null) { continue; } - Integer id = new Integer(notes.getSheetNumber()); + Integer id = new Integer(notes._getSheetNumber()); if(seenNotes.contains(id)) { continue; } seenNotes.add(id); diff --git a/src/scratchpad/src/org/apache/poi/hslf/model/Notes.java b/src/scratchpad/src/org/apache/poi/hslf/model/Notes.java index 87a2e105cc..7bf2154a4e 100644 --- a/src/scratchpad/src/org/apache/poi/hslf/model/Notes.java +++ b/src/scratchpad/src/org/apache/poi/hslf/model/Notes.java @@ -31,7 +31,7 @@ import org.apache.poi.hslf.record.PPDrawing; public class Notes extends Sheet { - private int _sheetNo; + private int _refSheetNo; private int _slideNo; private org.apache.poi.hslf.record.Notes _notes; private TextRun[] _runs; @@ -46,7 +46,7 @@ public class Notes extends Sheet _notes = notes; // Grab our internal sheet ID - _sheetNo = notes.getSheetId(); + _refSheetNo = notes.getSheetId(); // Grab the number of the slide we're for, via the NotesAtom _slideNo = _notes.getNotesAtom().getSlideID(); @@ -66,13 +66,14 @@ public class Notes extends Sheet public TextRun[] getTextRuns() { return _runs; } /** - * Returns the (internal, RefId based) sheet number (RefId) + * Returns the (internal, RefID based) sheet number, as used + * to in PersistPtr stuff. */ - public int getSheetNumber() { return _sheetNo; } - + public int _getSheetRefId() { return _refSheetNo; } /** - * Returns the (internal, identifer based) number of the slide we're attached to + * Returns the (internal, SlideIdentifer based) number of the + * slide we're attached to */ - public int getSlideInternalNumber() { return _slideNo; } + public int _getSheetNumber() { return _slideNo; } protected PPDrawing getPPDrawing() { return _notes.getPPDrawing(); }} diff --git a/src/scratchpad/src/org/apache/poi/hslf/model/Sheet.java b/src/scratchpad/src/org/apache/poi/hslf/model/Sheet.java index a904a18d6d..e1c95d747c 100644 --- a/src/scratchpad/src/org/apache/poi/hslf/model/Sheet.java +++ b/src/scratchpad/src/org/apache/poi/hslf/model/Sheet.java @@ -45,9 +45,15 @@ public abstract class Sheet /** * Returns the (internal, RefID based) sheet number, as used + * to in PersistPtr stuff. + */ + public abstract int _getSheetRefId(); + + /** + * Returns the (internal, SlideIdentifier based) sheet number, as used * to reference this sheet from other records. */ - public abstract int getSheetNumber(); + public abstract int _getSheetNumber(); /** * Fetch the PPDrawing from the underlying record diff --git a/src/scratchpad/src/org/apache/poi/hslf/model/Slide.java b/src/scratchpad/src/org/apache/poi/hslf/model/Slide.java index e725e3ffd3..69ee02a439 100644 --- a/src/scratchpad/src/org/apache/poi/hslf/model/Slide.java +++ b/src/scratchpad/src/org/apache/poi/hslf/model/Slide.java @@ -35,7 +35,7 @@ import org.apache.poi.hslf.record.SlideListWithText.SlideAtomsSet; public class Slide extends Sheet { - + private int _refSheetNo; private int _sheetNo; private int _slideNo; private org.apache.poi.hslf.record.Slide _slide; @@ -53,11 +53,12 @@ public class Slide extends Sheet * @param notes the Notes sheet attached to us * @param atomSet the SlideAtomsSet to get the text from */ - public Slide(org.apache.poi.hslf.record.Slide slide, Notes notes, SlideAtomsSet atomSet, int slideNumber) { + public Slide(org.apache.poi.hslf.record.Slide slide, Notes notes, SlideAtomsSet atomSet, int slideIdentifier, int slideNumber) { _slide = slide; _notes = notes; _atomSet = atomSet; - _sheetNo = slide.getSheetId(); + _refSheetNo = slide.getSheetId(); + _sheetNo = slideIdentifier; _slideNo = slideNumber; // Grab the TextRuns from the PPDrawing @@ -91,8 +92,9 @@ public class Slide extends Sheet * @param sheetNumber The internal number of the sheet, as used by PersistPtrHolder * @param slideNumber The user facing number of the sheet */ - public Slide(int sheetNumber, int slideNumber){ + public Slide(int sheetNumber, int sheetRefId, int slideNumber){ _slide = new org.apache.poi.hslf.record.Slide(); + _refSheetNo = sheetRefId; _sheetNo = sheetNumber; _slideNo = slideNumber; } @@ -112,7 +114,7 @@ public class Slide extends Sheet sa.setNotesID(0); } else { // Set to the value from the notes' sheet id - sa.setNotesID(notes.getSheetNumber()); + sa.setNotesID(notes._getSheetNumber()); } } @@ -125,10 +127,15 @@ public class Slide extends Sheet public TextRun[] getTextRuns() { return _runs; } /** - * Returns the (internal, RefId based) sheet number + * Returns the (internal, RefID based) sheet number, as used + * to in PersistPtr stuff. + */ + public int _getSheetRefId() { return _refSheetNo; } + /** + * Returns the (internal, SlideIdentifier based) sheet number * @see getSlideNumber() */ - public int getSheetNumber() { return _sheetNo; } + public int _getSheetNumber() { return _sheetNo; } /** * Returns the (public facing) page number of this slide diff --git a/src/scratchpad/src/org/apache/poi/hslf/model/TextRun.java b/src/scratchpad/src/org/apache/poi/hslf/model/TextRun.java index 7ebb280347..1360d8816f 100644 --- a/src/scratchpad/src/org/apache/poi/hslf/model/TextRun.java +++ b/src/scratchpad/src/org/apache/poi/hslf/model/TextRun.java @@ -130,7 +130,8 @@ public class TextRun } } if(pLenRemain < 0) { - throw new IllegalStateException("Paragraph style ran out before character style did!"); + System.err.println("Paragraph style ran out before character style did! Short by " + (0-pLenRemain) + " characters."); + System.err.println("Calling RichTextRun functions is likely to break things - see Bug #38544"); } } } diff --git a/src/scratchpad/src/org/apache/poi/hslf/record/SlideListWithText.java b/src/scratchpad/src/org/apache/poi/hslf/record/SlideListWithText.java index 7d8e382ba1..df3e607b9c 100644 --- a/src/scratchpad/src/org/apache/poi/hslf/record/SlideListWithText.java +++ b/src/scratchpad/src/org/apache/poi/hslf/record/SlideListWithText.java @@ -76,9 +76,12 @@ public class SlideListWithText extends RecordContainer endPos += 1; } - // Now, if not empty, create a SlideAtomsSets int clen = endPos - i - 1; - if(clen == 0) { continue; } + boolean emptySet = false; + if(clen == 0) { emptySet = true; } + + // Create a SlideAtomsSets, not caring if they're empty + //if(emptySet) { continue; } Record[] spaChildren = new Record[clen]; System.arraycopy(_children,i+1,spaChildren,0,clen); SlideAtomsSet set = new SlideAtomsSet((SlidePersistAtom)_children[i],spaChildren); diff --git a/src/scratchpad/src/org/apache/poi/hslf/usermodel/SlideShow.java b/src/scratchpad/src/org/apache/poi/hslf/usermodel/SlideShow.java index 19b80722da..5485c8043a 100644 --- a/src/scratchpad/src/org/apache/poi/hslf/usermodel/SlideShow.java +++ b/src/scratchpad/src/org/apache/poi/hslf/usermodel/SlideShow.java @@ -69,6 +69,11 @@ public class SlideShow // Pointers to the most recent versions of the core records // (Document, Notes, Slide etc) private Record[] _mostRecentCoreRecords; + // Lookup between the PersitPtr "sheet" IDs, and the position + // in the mostRecentCoreRecords array + private Hashtable _sheetIdToCoreRecordsLookup; + // Used when adding new core records + private int _highestSheetId; // Records that are interesting private Document _documentRecord; @@ -180,9 +185,10 @@ public class SlideShow // We now know how many unique special records we have, so init // the array _mostRecentCoreRecords = new Record[mostRecentByBytes.size()]; - - // Also, work out where we're going to put them in the array - Hashtable slideIDtoRecordLookup = new Hashtable(); + + // We'll also want to be able to turn the slide IDs into a position + // in this array + _sheetIdToCoreRecordsLookup = new Hashtable(); int[] allIDs = new int[_mostRecentCoreRecords.length]; Enumeration ids = mostRecentByBytes.keys(); for(int i=0; i 0) { + // Get the SlideIdentifier of the Notes + // (Note - might not be the same as the SlideIdentifier of the Slide) + int notesSlideIdentifier = s.getSlideAtom().getNotesID(); + Integer notesSlideIdentifierI = new Integer(notesSlideIdentifier); + + // Grab the notes record + Integer notesRefI = (Integer)notesSlideIdToRefid.get(notesSlideIdentifierI); + Integer notesCoreRecNum = (Integer)_sheetIdToCoreRecordsLookup.get(notesRefI); + n = (org.apache.poi.hslf.record.Notes) + _mostRecentCoreRecords[notesCoreRecNum.intValue()]; + } + + // Grab the matching SlideAtomSet + SlideAtomsSet sas = (SlideAtomsSet) + slideSlideIdToSlideAtomsSet.get(slideIdentifierI); + + // Build the notes model, if there's notes + Notes notes = null; + if(n != null) { + // TODO: Use this + SlideAtomsSet nsas = (SlideAtomsSet) + notesSlideIdToSlideAtomsSet.get(slideIdentifierI); + + // Create the model view of the notes + notes = new Notes(n); + notesV.add(notes); } - slideAtomSets[arrayPos] = thisSet; + + // Build the slide model + Slide slide = new Slide(s, notes, sas, slideIdentifier, slideNumber); + slidesV.add(slide); } + + // ******************* Finish up **************** - - - // ******************* Do the real model layer creation **************** - - - // Create our Notes - // (Need to create first, as passed to the Slides) + // Finish setting up the notes _notes = new Notes[notesV.size()]; for(int i=0; i<_notes.length; i++) { - _notes[i] = new Notes((org.apache.poi.hslf.record.Notes)notesV.get(i)); + _notes[i] = (Notes)notesV.get(i); // Now supply ourselves to all the rich text runs // of this note's TextRuns @@ -361,32 +417,8 @@ public class SlideShow // Create our Slides _slides = new Slide[slidesV.size()]; for(int i=0; i<_slides.length; i++) { - // Grab the slide Record - org.apache.poi.hslf.record.Slide slideRecord = (org.apache.poi.hslf.record.Slide)slidesV.get(i); - - // Decide if we've got a SlideAtomSet to use - // TODO: Use the internal IDs to match instead - SlideAtomsSet atomSet = null; - if(i < slideAtomSets.length) { - atomSet = slideAtomSets[i]; - } - - // Do they have a Notes? - Notes thisNotes = null; - // Find their SlideAtom, and use this to check for a Notes - SlideAtom sa = slideRecord.getSlideAtom(); - int notesID = sa.getNotesID(); - if(notesID != 0) { - for(int k=0; k<_notes.length; k++) { - if(_notes[k].getSlideInternalNumber() == notesID) { - thisNotes = _notes[k]; - } - } - } + _slides[i] = (Slide)slidesV.get(i); - // Create the Slide model layer - _slides[i] = new Slide(slideRecord,thisNotes,atomSet, (i+1)); - // Now supply ourselves to all the rich text runs // of this slide's TextRuns TextRun[] trs = _slides[i].getTextRuns(); @@ -492,15 +524,20 @@ public class SlideShow // Grab the SlidePersistAtom with the highest Slide Number. // (Will stay as null if no SlidePersistAtom exists yet in - // the slide) + // the slide, or only master slide's ones do) SlidePersistAtom prev = null; for(int i=0; i