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
This commit is contained in:
parent
dc9721e77e
commit
8514bc913e
@ -53,12 +53,35 @@ public class Document extends PositionDependentRecordContainer
|
|||||||
* that contains information on pictures in the slides.
|
* that contains information on pictures in the slides.
|
||||||
*/
|
*/
|
||||||
public PPDrawingGroup getPPDrawingGroup() { return ppDrawing; }
|
public PPDrawingGroup getPPDrawingGroup() { return ppDrawing; }
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns all the SlideListWithTexts that are defined for
|
* Returns all the SlideListWithTexts that are defined for
|
||||||
* this Document. They hold the text, and some of the text
|
* this Document. They hold the text, and some of the text
|
||||||
* properties, which are referred to by the slides.
|
* properties, which are referred to by the slides.
|
||||||
|
* This will normally return an array of size 2 or 3
|
||||||
*/
|
*/
|
||||||
public SlideListWithText[] getSlideListWithTexts() { return slwts; }
|
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");
|
throw new IllegalStateException("The first child of a Document must be a DocumentAtom");
|
||||||
}
|
}
|
||||||
documentAtom = (DocumentAtom)_children[0];
|
documentAtom = (DocumentAtom)_children[0];
|
||||||
|
|
||||||
// Find how many SlideListWithTexts we have
|
// 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;
|
int slwtcount = 0;
|
||||||
for(int i=1; i<_children.length; i++) {
|
for(int i=1; i<_children.length; i++) {
|
||||||
if(_children[i] instanceof SlideListWithText) {
|
if(_children[i] instanceof SlideListWithText) {
|
||||||
@ -92,7 +116,18 @@ public class Document extends PositionDependentRecordContainer
|
|||||||
ppDrawing = (PPDrawingGroup)_children[i];
|
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];
|
slwts = new SlideListWithText[slwtcount];
|
||||||
slwtcount = 0;
|
slwtcount = 0;
|
||||||
for(int i=1; i<_children.length; i++) {
|
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
|
* Adds a new SlideListWithText record, at the appropriate
|
||||||
* point
|
* point in the child records.
|
||||||
*/
|
*/
|
||||||
public void addSlideListWithText(SlideListWithText slwt) {
|
public void addSlideListWithText(SlideListWithText slwt) {
|
||||||
// The new SlideListWithText should go in
|
// The new SlideListWithText should go in
|
||||||
@ -119,7 +154,8 @@ public class Document extends PositionDependentRecordContainer
|
|||||||
addChildBefore(slwt, endDoc);
|
addChildBefore(slwt, endDoc);
|
||||||
|
|
||||||
// Updated our cached list of SlideListWithText records
|
// 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);
|
System.arraycopy(slwts, 0, nl, 0, slwts.length);
|
||||||
nl[nl.length-1] = slwt;
|
nl[nl.length-1] = slwt;
|
||||||
slwts = nl;
|
slwts = nl;
|
||||||
|
@ -524,35 +524,33 @@ public class SlideShow
|
|||||||
* @throws IOException
|
* @throws IOException
|
||||||
*/
|
*/
|
||||||
public Slide createSlide() throws IOException {
|
public Slide createSlide() throws IOException {
|
||||||
SlideListWithText[] slwts = _documentRecord.getSlideListWithTexts();
|
|
||||||
SlideListWithText slist = null;
|
SlideListWithText slist = null;
|
||||||
|
|
||||||
if(slwts.length > 1) {
|
// We need to add the records to the SLWT that deals
|
||||||
// Just use the last one
|
// with Slides.
|
||||||
slist = slwts[slwts.length - 1];
|
// Add it, if it doesn't exist
|
||||||
} else {
|
slist = _documentRecord.getSlideSlideListWithText();
|
||||||
|
if(slist == null) {
|
||||||
// Need to add a new one
|
// Need to add a new one
|
||||||
slist = new SlideListWithText();
|
slist = new SlideListWithText();
|
||||||
_documentRecord.addSlideListWithText(slist);
|
_documentRecord.addSlideListWithText(slist);
|
||||||
slwts = _documentRecord.getSlideListWithTexts();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Grab the SlidePersistAtom with the highest Slide Number.
|
// Grab the SlidePersistAtom with the highest Slide Number.
|
||||||
// (Will stay as null if no SlidePersistAtom exists yet in
|
// (Will stay as null if no SlidePersistAtom exists yet in
|
||||||
// the slide, or only master slide's ones do)
|
// the slide, or only master slide's ones do)
|
||||||
SlidePersistAtom prev = null;
|
SlidePersistAtom prev = null;
|
||||||
for(int i=0; i<slwts.length; i++) {
|
SlideAtomsSet[] sas = slist.getSlideAtomsSets();
|
||||||
SlideAtomsSet[] sas = slwts[i].getSlideAtomsSets();
|
for(int j=0; j<sas.length; j++) {
|
||||||
for(int j=0; j<sas.length; j++) {
|
SlidePersistAtom spa = sas[j].getSlidePersistAtom();
|
||||||
SlidePersistAtom spa = sas[j].getSlidePersistAtom();
|
if(spa.getSlideIdentifier() < 0) {
|
||||||
if(spa.getSlideIdentifier() < 0) {
|
// This is for a master slide
|
||||||
// This is for a master slide
|
// Odd, since we only deal with the Slide SLWT
|
||||||
} else {
|
} else {
|
||||||
// Must be for a real slide
|
// Must be for a real slide
|
||||||
if(prev == null) { prev = spa; }
|
if(prev == null) { prev = spa; }
|
||||||
if(prev.getSlideIdentifier() < spa.getSlideIdentifier()) {
|
if(prev.getSlideIdentifier() < spa.getSlideIdentifier()) {
|
||||||
prev = spa;
|
prev = spa;
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -56,9 +56,7 @@ public class TestReWrite extends TestCase {
|
|||||||
|
|
||||||
public void testWritesOutTheSame() throws Exception {
|
public void testWritesOutTheSame() throws Exception {
|
||||||
assertWritesOutTheSame(hssA, pfsA);
|
assertWritesOutTheSame(hssA, pfsA);
|
||||||
|
assertWritesOutTheSame(hssB, pfsB);
|
||||||
// Disabled until bug #39800 is fixed
|
|
||||||
//assertWritesOutTheSame(hssB, pfsB);
|
|
||||||
}
|
}
|
||||||
public void assertWritesOutTheSame(HSLFSlideShow hss, POIFSFileSystem pfs) throws Exception {
|
public void assertWritesOutTheSame(HSLFSlideShow hss, POIFSFileSystem pfs) throws Exception {
|
||||||
// Write out to a byte array
|
// Write out to a byte array
|
||||||
@ -82,7 +80,7 @@ public class TestReWrite extends TestCase {
|
|||||||
pfs.createDocumentInputStream("PowerPoint Document").read(_oData);
|
pfs.createDocumentInputStream("PowerPoint Document").read(_oData);
|
||||||
npfs.createDocumentInputStream("PowerPoint Document").read(_nData);
|
npfs.createDocumentInputStream("PowerPoint Document").read(_nData);
|
||||||
for(int i=0; i<_oData.length; i++) {
|
for(int i=0; i<_oData.length; i++) {
|
||||||
System.out.println(i + "\t" + Integer.toHexString(i));
|
//System.out.println(i + "\t" + Integer.toHexString(i));
|
||||||
assertEquals(_oData[i], _nData[i]);
|
assertEquals(_oData[i], _nData[i]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -94,7 +92,8 @@ public class TestReWrite extends TestCase {
|
|||||||
public void testSlideShowWritesOutTheSame() throws Exception {
|
public void testSlideShowWritesOutTheSame() throws Exception {
|
||||||
assertSlideShowWritesOutTheSame(hssA, pfsA);
|
assertSlideShowWritesOutTheSame(hssA, pfsA);
|
||||||
|
|
||||||
// Disabled until bug #39800 is fixed
|
// Some bug in StyleTextPropAtom rewriting means this will fail
|
||||||
|
// We need to identify and fix that first
|
||||||
//assertSlideShowWritesOutTheSame(hssB, pfsB);
|
//assertSlideShowWritesOutTheSame(hssB, pfsB);
|
||||||
}
|
}
|
||||||
public void assertSlideShowWritesOutTheSame(HSLFSlideShow hss, POIFSFileSystem pfs) throws Exception {
|
public void assertSlideShowWritesOutTheSame(HSLFSlideShow hss, POIFSFileSystem pfs) throws Exception {
|
||||||
@ -124,7 +123,8 @@ public class TestReWrite extends TestCase {
|
|||||||
pfs.createDocumentInputStream("PowerPoint Document").read(_oData);
|
pfs.createDocumentInputStream("PowerPoint Document").read(_oData);
|
||||||
npfs.createDocumentInputStream("PowerPoint Document").read(_nData);
|
npfs.createDocumentInputStream("PowerPoint Document").read(_nData);
|
||||||
for(int i=0; i<_oData.length; i++) {
|
for(int i=0; i<_oData.length; i++) {
|
||||||
//System.out.println(i + "\t" + Integer.toHexString(i));
|
if(_oData[i] != _nData[i])
|
||||||
|
System.out.println(i + "\t" + Integer.toHexString(i));
|
||||||
assertEquals(_oData[i], _nData[i]);
|
assertEquals(_oData[i], _nData[i]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -70,6 +70,9 @@ public class TestAddingSlides extends TestCase {
|
|||||||
// Doesn't have any slides
|
// Doesn't have any slides
|
||||||
assertEquals(0, ss_empty.getSlides().length);
|
assertEquals(0, ss_empty.getSlides().length);
|
||||||
|
|
||||||
|
// Should only have a master SLWT
|
||||||
|
assertEquals(1, ss_empty.getDocumentRecord().getSlideListWithTexts().length);
|
||||||
|
|
||||||
// Add one
|
// Add one
|
||||||
Slide slide = ss_empty.createSlide();
|
Slide slide = ss_empty.createSlide();
|
||||||
assertEquals(1, ss_empty.getSlides().length);
|
assertEquals(1, ss_empty.getSlides().length);
|
||||||
@ -87,6 +90,9 @@ public class TestAddingSlides extends TestCase {
|
|||||||
|
|
||||||
// Check it now has a slide
|
// Check it now has a slide
|
||||||
assertEquals(1, ss_read.getSlides().length);
|
assertEquals(1, ss_read.getSlides().length);
|
||||||
|
|
||||||
|
// Check it now has two SLWTs
|
||||||
|
assertEquals(2, ss_empty.getDocumentRecord().getSlideListWithTexts().length);
|
||||||
|
|
||||||
// And check it's as expected
|
// And check it's as expected
|
||||||
slide = ss_read.getSlides()[0];
|
slide = ss_read.getSlides()[0];
|
||||||
@ -103,6 +109,9 @@ public class TestAddingSlides extends TestCase {
|
|||||||
assertEquals(1, ss_one.getSlides().length);
|
assertEquals(1, ss_one.getSlides().length);
|
||||||
Slide s1 = ss_one.getSlides()[0];
|
Slide s1 = ss_one.getSlides()[0];
|
||||||
|
|
||||||
|
// Should have two SLTWs
|
||||||
|
assertEquals(2, ss_one.getDocumentRecord().getSlideListWithTexts().length);
|
||||||
|
|
||||||
// Check slide 1 is as expected
|
// Check slide 1 is as expected
|
||||||
assertEquals(256, s1._getSheetNumber());
|
assertEquals(256, s1._getSheetNumber());
|
||||||
assertEquals(3, s1._getSheetRefId());
|
assertEquals(3, s1._getSheetRefId());
|
||||||
@ -126,6 +135,9 @@ public class TestAddingSlides extends TestCase {
|
|||||||
// Check it now has two slides
|
// Check it now has two slides
|
||||||
assertEquals(2, ss_read.getSlides().length);
|
assertEquals(2, ss_read.getSlides().length);
|
||||||
|
|
||||||
|
// Should still have two SLTWs
|
||||||
|
assertEquals(2, ss_read.getDocumentRecord().getSlideListWithTexts().length);
|
||||||
|
|
||||||
// And check it's as expected
|
// And check it's as expected
|
||||||
s1 = ss_read.getSlides()[0];
|
s1 = ss_read.getSlides()[0];
|
||||||
s2 = ss_read.getSlides()[1];
|
s2 = ss_read.getSlides()[1];
|
||||||
|
Loading…
Reference in New Issue
Block a user