From 993972171b5374777854fd6971a071146e39544e Mon Sep 17 00:00:00 2001 From: Nick Burch Date: Tue, 27 Jun 2006 11:42:29 +0000 Subject: [PATCH] Update Document to offer the SlideListWithTexts by name, and change addSlide to add to the right SlideListWithText. (Based on a bug, the number I don't have to hand, doh\!) git-svn-id: https://svn.apache.org/repos/asf/jakarta/poi/trunk@417434 13f79535-47bb-0310-9956-ffa450edef68 --- .../org/apache/poi/hslf/record/Document.java | 46 +++++++++++++++++-- .../apache/poi/hslf/usermodel/SlideShow.java | 36 +++++++-------- .../org/apache/poi/hslf/TestReWrite.java | 12 ++--- .../poi/hslf/usermodel/TestAddingSlides.java | 12 +++++ 4 files changed, 76 insertions(+), 30 deletions(-) diff --git a/src/scratchpad/src/org/apache/poi/hslf/record/Document.java b/src/scratchpad/src/org/apache/poi/hslf/record/Document.java index 74ec7ee593..31ed8901db 100644 --- a/src/scratchpad/src/org/apache/poi/hslf/record/Document.java +++ b/src/scratchpad/src/org/apache/poi/hslf/record/Document.java @@ -53,12 +53,35 @@ public class Document extends PositionDependentRecordContainer * that contains information on pictures in the slides. */ public PPDrawingGroup getPPDrawingGroup() { return ppDrawing; } + /** * Returns all the SlideListWithTexts that are defined for * this Document. They hold the text, and some of the text * properties, which are referred to by the slides. + * This will normally return an array of size 2 or 3 */ public SlideListWithText[] getSlideListWithTexts() { return slwts; } + /** + * Returns the SlideListWithText that deals with the + * Master Slides + */ + public SlideListWithText getMasterSlideListWithText() { + if(slwts.length > 0) { return slwts[0]; } + return null; } + /** + * Returns the SlideListWithText that deals with the + * Slides, or null if there isn't one + */ + public SlideListWithText getSlideSlideListWithText() { + if(slwts.length > 1) { return slwts[1]; } + return null; } + /** + * Returns the SlideListWithText that deals with the + * notes, or null if there isn't one + */ + public SlideListWithText getNotesSlideListWithText() { + if(slwts.length > 2) { return slwts[2]; } + return null; } /** @@ -77,9 +100,10 @@ public class Document extends PositionDependentRecordContainer throw new IllegalStateException("The first child of a Document must be a DocumentAtom"); } documentAtom = (DocumentAtom)_children[0]; - + // Find how many SlideListWithTexts we have - // Also, grab the Environment record on our way past + // Also, grab the Environment and PPDrawing records + // on our way past int slwtcount = 0; for(int i=1; i<_children.length; i++) { if(_children[i] instanceof SlideListWithText) { @@ -92,7 +116,18 @@ public class Document extends PositionDependentRecordContainer ppDrawing = (PPDrawingGroup)_children[i]; } } - // Now grab them all + + // You should only every have 1, 2 or 3 SLWTs + // (normally it's 2, or 3 if you have notes) + // Complain if it's not + if(slwtcount == 0) { + System.err.println("No SlideListWithText's found - there should normally be at least one!"); + } + if(slwtcount > 3) { + System.err.println("Found " + slwtcount + " SlideListWithTexts - normally there should only be three!"); + } + + // Now grab all the SLWTs slwts = new SlideListWithText[slwtcount]; slwtcount = 0; for(int i=1; i<_children.length; i++) { @@ -105,7 +140,7 @@ public class Document extends PositionDependentRecordContainer /** * Adds a new SlideListWithText record, at the appropriate - * point + * point in the child records. */ public void addSlideListWithText(SlideListWithText slwt) { // The new SlideListWithText should go in @@ -119,7 +154,8 @@ public class Document extends PositionDependentRecordContainer addChildBefore(slwt, endDoc); // Updated our cached list of SlideListWithText records - SlideListWithText[] nl = new SlideListWithText[slwts.length + 1]; + int newSize = slwts.length + 1; + SlideListWithText[] nl = new SlideListWithText[newSize]; System.arraycopy(slwts, 0, nl, 0, slwts.length); nl[nl.length-1] = slwt; slwts = nl; 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 cef58ffe0f..76fc447a3b 100644 --- a/src/scratchpad/src/org/apache/poi/hslf/usermodel/SlideShow.java +++ b/src/scratchpad/src/org/apache/poi/hslf/usermodel/SlideShow.java @@ -524,35 +524,33 @@ public class SlideShow * @throws IOException */ public Slide createSlide() throws IOException { - SlideListWithText[] slwts = _documentRecord.getSlideListWithTexts(); SlideListWithText slist = null; - - if(slwts.length > 1) { - // Just use the last one - slist = slwts[slwts.length - 1]; - } else { + + // We need to add the records to the SLWT that deals + // with Slides. + // Add it, if it doesn't exist + slist = _documentRecord.getSlideSlideListWithText(); + if(slist == null) { // Need to add a new one slist = new SlideListWithText(); _documentRecord.addSlideListWithText(slist); - slwts = _documentRecord.getSlideListWithTexts(); } // 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(int i=0; i