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 c3a789ffe..33e353c0f 100644 --- a/src/scratchpad/src/org/apache/poi/hslf/usermodel/SlideShow.java +++ b/src/scratchpad/src/org/apache/poi/hslf/usermodel/SlideShow.java @@ -30,6 +30,8 @@ import org.apache.poi.hslf.record.Record; import org.apache.poi.hslf.record.SlideAtom; import org.apache.poi.hslf.record.SlideListWithText; import org.apache.poi.hslf.record.SlideListWithText.*; +import org.apache.poi.hslf.record.PersistPtrHolder; +import org.apache.poi.hslf.record.PositionDependentRecord; /** * This class is a friendly wrapper on top of the more scary HSLFSlideShow. @@ -50,6 +52,10 @@ public class SlideShow // Low level contents, as taken from HSLFSlideShow private Record[] _records; + // Pointers to the most recent versions of the core records + // (Document, Notes, Slide etc) + private Record[] _mostRecentCoreRecords; + // Friendly objects for people to deal with private Slide[] _slides; private Notes[] _notes; @@ -90,7 +96,93 @@ public class SlideShow _records = _hslfSlideShow.getRecords(); byte[] _docstream = _hslfSlideShow.getUnderlyingBytes(); + // Find the versions of the core records we'll want to use + findMostRecentCoreRecords(); + // Build up the model level Slides and Notes + buildSlidesAndNotes(); + } + + /** + * Use the PersistPtrHolder entries to figure out what is + * the "most recent" version of all the core records + * (Document, Notes, Slide etc), and save a record of them. + * Do this by walking from the oldest PersistPtr to the newest, + * overwriting any references found along the way with newer ones + */ + private void findMostRecentCoreRecords() { + // To start with, find the most recent in the byte offset domain + Hashtable mostRecentByBytes = new Hashtable(); + for(int i=0; i<_records.length; i++) { + if(_records[i] instanceof PersistPtrHolder) { + PersistPtrHolder pph = (PersistPtrHolder)_records[i]; + + // If we've already seen any of the "slide" IDs for this + // PersistPtr, remove their old positions + int[] ids = pph.getKnownSlideIDs(); + for(int j=0; j