From: Nick Burch Date: Sun, 26 Mar 2006 19:07:52 +0000 (+0000) Subject: Start to do more useful/sensible things with Slide IDs X-Git-Tag: REL_3_0_ALPHA3~145 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=8fb8942da5cf2f3401c3ca677740a24ac2273ee9;p=poi.git Start to do more useful/sensible things with Slide IDs git-svn-id: https://svn.apache.org/repos/asf/jakarta/poi/trunk@388941 13f79535-47bb-0310-9956-ffa450edef68 --- 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 f7fd003859..87a2e105cc 100644 --- a/src/scratchpad/src/org/apache/poi/hslf/model/Notes.java +++ b/src/scratchpad/src/org/apache/poi/hslf/model/Notes.java @@ -19,11 +19,7 @@ package org.apache.poi.hslf.model; -import java.util.*; - -import org.apache.poi.hslf.record.*; -import org.apache.poi.hslf.record.SlideListWithText.*; -import org.apache.poi.util.LittleEndian; +import org.apache.poi.hslf.record.PPDrawing; /** * This class represents a slide's notes in a PowerPoint Document. It @@ -35,8 +31,8 @@ import org.apache.poi.util.LittleEndian; public class Notes extends Sheet { - private int _sheetNo; + private int _slideNo; private org.apache.poi.hslf.record.Notes _notes; private TextRun[] _runs; @@ -48,9 +44,12 @@ public class Notes extends Sheet */ public Notes (org.apache.poi.hslf.record.Notes notes) { _notes = notes; + + // Grab our internal sheet ID + _sheetNo = notes.getSheetId(); - // Grab the sheet number, via the NotesAtom - _sheetNo = _notes.getNotesAtom().getSlideID(); + // Grab the number of the slide we're for, via the NotesAtom + _slideNo = _notes.getNotesAtom().getSlideID(); // Now, build up TextRuns from pairs of TextHeaderAtom and // one of TextBytesAtom or TextCharsAtom, found inside @@ -67,8 +66,13 @@ public class Notes extends Sheet public TextRun[] getTextRuns() { return _runs; } /** - * Returns the sheet number + * Returns the (internal, RefId based) sheet number (RefId) */ public int getSheetNumber() { return _sheetNo; } + /** + * Returns the (internal, identifer based) number of the slide we're attached to + */ + public int getSlideInternalNumber() { 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 e4a688628e..a904a18d6d 100644 --- a/src/scratchpad/src/org/apache/poi/hslf/model/Sheet.java +++ b/src/scratchpad/src/org/apache/poi/hslf/model/Sheet.java @@ -44,7 +44,8 @@ public abstract class Sheet public abstract TextRun[] getTextRuns(); /** - * Returns the sheet number + * Returns the (internal, RefID based) sheet number, as used + * to reference this sheet from other records. */ public abstract int getSheetNumber(); 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 6f374ec050..e725e3ffd3 100644 --- a/src/scratchpad/src/org/apache/poi/hslf/model/Slide.java +++ b/src/scratchpad/src/org/apache/poi/hslf/model/Slide.java @@ -19,11 +19,11 @@ package org.apache.poi.hslf.model; -import java.util.*; +import java.util.Vector; -import org.apache.poi.hslf.record.*; -import org.apache.poi.hslf.record.SlideListWithText.*; -import org.apache.poi.util.LittleEndian; +import org.apache.poi.hslf.record.PPDrawing; +import org.apache.poi.hslf.record.SlideAtom; +import org.apache.poi.hslf.record.SlideListWithText.SlideAtomsSet; /** * This class represents a slide in a PowerPoint Document. It allows @@ -37,6 +37,7 @@ public class Slide extends Sheet { private int _sheetNo; + private int _slideNo; private org.apache.poi.hslf.record.Slide _slide; private SlideAtomsSet _atomSet; private TextRun[] _runs; @@ -52,14 +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) { + public Slide(org.apache.poi.hslf.record.Slide slide, Notes notes, SlideAtomsSet atomSet, int slideNumber) { _slide = slide; _notes = notes; _atomSet = atomSet; - - // Grab the sheet number - //_sheetNo = _slide.getSlideAtom().getSheetNumber(); - _sheetNo = -1; + _sheetNo = slide.getSheetId(); + _slideNo = slideNumber; // Grab the TextRuns from the PPDrawing _otherRuns = findTextRuns(_slide.getPPDrawing()); @@ -89,9 +88,13 @@ public class Slide extends Sheet /** * Create a new Slide instance + * @param sheetNumber The internal number of the sheet, as used by PersistPtrHolder + * @param slideNumber The user facing number of the sheet */ - public Slide(){ - _slide = new org.apache.poi.hslf.record.Slide(); + public Slide(int sheetNumber, int slideNumber){ + _slide = new org.apache.poi.hslf.record.Slide(); + _sheetNo = sheetNumber; + _slideNo = slideNumber; } /** @@ -122,10 +125,16 @@ public class Slide extends Sheet public TextRun[] getTextRuns() { return _runs; } /** - * Returns the sheet number + * Returns the (internal, RefId based) sheet number + * @see getSlideNumber() */ public int getSheetNumber() { return _sheetNo; } - + + /** + * Returns the (public facing) page number of this slide + */ + public int getSlideNumber() { return _slideNo; } + /** * Returns the underlying slide record */ diff --git a/src/scratchpad/src/org/apache/poi/hslf/record/PersistPtrHolder.java b/src/scratchpad/src/org/apache/poi/hslf/record/PersistPtrHolder.java index fee1c529cc..bdf6251c29 100644 --- a/src/scratchpad/src/org/apache/poi/hslf/record/PersistPtrHolder.java +++ b/src/scratchpad/src/org/apache/poi/hslf/record/PersistPtrHolder.java @@ -41,7 +41,7 @@ public class PersistPtrHolder extends PositionDependentRecordAtom private byte[] _header; private byte[] _ptrData; // Will need to update this once we allow updates to _slideLocations private long _type; - + /** * Holds the lookup for slides to their position on disk. * You always need to check the most recent PersistPtrHolder diff --git a/src/scratchpad/src/org/apache/poi/hslf/record/PositionDependentRecordContainer.java b/src/scratchpad/src/org/apache/poi/hslf/record/PositionDependentRecordContainer.java index b7f9a99761..76346ff49f 100644 --- a/src/scratchpad/src/org/apache/poi/hslf/record/PositionDependentRecordContainer.java +++ b/src/scratchpad/src/org/apache/poi/hslf/record/PositionDependentRecordContainer.java @@ -29,6 +29,20 @@ import java.util.Hashtable; public abstract class PositionDependentRecordContainer extends RecordContainer implements PositionDependentRecord { + private int sheetId; // Found from PersistPtrHolder + + /** + * Fetch our sheet ID, as found from a PersistPtrHolder. + * Should match the RefId of our matching SlidePersistAtom + */ + public int getSheetId() { return sheetId; } + + /** + * Set our sheet ID, as found from a PersistPtrHolder + */ + public void setSheetId(int id) { sheetId = id; } + + /** Our location on the disk, as of the last write out */ protected int myLastOnDiskOffset; diff --git a/src/scratchpad/src/org/apache/poi/hslf/record/Slide.java b/src/scratchpad/src/org/apache/poi/hslf/record/Slide.java index 06262909ad..27d8113054 100644 --- a/src/scratchpad/src/org/apache/poi/hslf/record/Slide.java +++ b/src/scratchpad/src/org/apache/poi/hslf/record/Slide.java @@ -99,7 +99,7 @@ public class Slide extends PositionDependentRecordContainer * We are of type 1006 */ public long getRecordType() { return _type; } - + /** * Write the contents of the record back, so it can be written * to disk 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 df4b8fa656..19b80722da 100644 --- a/src/scratchpad/src/org/apache/poi/hslf/usermodel/SlideShow.java +++ b/src/scratchpad/src/org/apache/poi/hslf/usermodel/SlideShow.java @@ -33,6 +33,7 @@ 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; @@ -210,6 +211,14 @@ public class SlideShow (Integer)slideIDtoRecordLookup.get(thisID); int storeAt = storeAtI.intValue(); + // Tell it its Sheet ID, if it cares + // TODO: Check that this is the right ID to feed in + if(pdr instanceof PositionDependentRecordContainer) { + PositionDependentRecordContainer pdrc = + (PositionDependentRecordContainer)_records[i]; + pdrc.setSheetId(thisID.intValue()); + } + // Finally, save the record _mostRecentCoreRecords[storeAt] = _records[i]; } @@ -356,6 +365,7 @@ public class SlideShow 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]; @@ -368,14 +378,14 @@ public class SlideShow int notesID = sa.getNotesID(); if(notesID != 0) { for(int k=0; k<_notes.length; k++) { - if(_notes[k].getSheetNumber() == notesID) { + if(_notes[k].getSlideInternalNumber() == notesID) { thisNotes = _notes[k]; } } } // Create the Slide model layer - _slides[i] = new Slide(slideRecord,thisNotes,atomSet); + _slides[i] = new Slide(slideRecord,thisNotes,atomSet, (i+1)); // Now supply ourselves to all the rich text runs // of this slide's TextRuns @@ -492,7 +502,6 @@ public class SlideShow if(prev.getSlideIdentifier() < spa.getSlideIdentifier()) { prev = spa; } - System.err.println("Prev is " + prev.getRefID()); } } @@ -512,7 +521,8 @@ public class SlideShow // Create a new Slide - Slide slide = new Slide(); + Slide slide = new Slide(sp.getRefID(), _slides.length+1); + // Add in to the list of Slides Slide[] s = new Slide[_slides.length+1]; System.arraycopy(_slides, 0, s, 0, _slides.length); s[_slides.length] = slide; @@ -520,7 +530,8 @@ public class SlideShow System.out.println("Added slide " + _slides.length + " with ref " + sp.getRefID() + " and identifier " + sp.getSlideIdentifier()); // Add the core records for this new Slide to the record tree - org.apache.poi.hslf.record.Slide slideRecord = slide.getSlideRecord(); + org.apache.poi.hslf.record.Slide slideRecord = slide.getSlideRecord(); + slideRecord.setSheetId(sp.getRefID()); int slideRecordPos = _hslfSlideShow.appendRootLevelRecord(slideRecord); _records = _hslfSlideShow.getRecords();