Add an Environment record, and make the code simpler

git-svn-id: https://svn.apache.org/repos/asf/jakarta/poi/trunk@386986 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Nick Burch 2006-03-19 16:09:51 +00:00
parent b7827f2687
commit eb53534020
4 changed files with 92 additions and 22 deletions

View File

@ -35,7 +35,7 @@ public class Document extends PositionDependentRecordContainer
// Links to our more interesting children // Links to our more interesting children
private DocumentAtom documentAtom; private DocumentAtom documentAtom;
private Record environment; private Environment environment;
private SlideListWithText[] slwts; private SlideListWithText[] slwts;
/** /**
@ -46,7 +46,7 @@ public class Document extends PositionDependentRecordContainer
* Returns the Environment of this Notes, which lots of * Returns the Environment of this Notes, which lots of
* settings for the document in it * settings for the document in it
*/ */
public Record getEnvironment() { return environment; } public Environment getEnvironment() { return environment; }
/** /**
* 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
@ -79,8 +79,8 @@ public class Document extends PositionDependentRecordContainer
if(_children[i] instanceof SlideListWithText) { if(_children[i] instanceof SlideListWithText) {
slwtcount++; slwtcount++;
} }
if(_children[i].getRecordType() == RecordTypes.Environment.typeID) { if(_children[i] instanceof Environment) {
environment = _children[i]; environment = (Environment)_children[i];
} }
} }
// Now grab them all // Now grab them all

View File

@ -0,0 +1,80 @@
/* ====================================================================
Copyright 2002-2004 Apache Software Foundation
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
==================================================================== */
package org.apache.poi.hslf.record;
import java.io.IOException;
import java.io.OutputStream;
/**
* Environment, which contains lots of settings for the document.
*
* @author Nick Burch
*/
public class Environment extends PositionDependentRecordContainer
{
private byte[] _header;
private static long _type = 1010;
// Links to our more interesting children
private FontCollection fontCollection;
/**
* Returns the FontCollection of this Environment
*/
public FontCollection getFontCollection() { return fontCollection; }
/**
* Set things up, and find our more interesting children
*/
protected Environment(byte[] source, int start, int len) {
// Grab the header
_header = new byte[8];
System.arraycopy(source,start,_header,0,8);
// Find our children
_children = Record.findChildRecords(source,start+8,len-8);
// Find our FontCollection record
for(int i=0; i<_children.length; i++) {
if(_children[i] instanceof FontCollection) {
fontCollection = (FontCollection)_children[i];
}
}
if(fontCollection == null) {
throw new IllegalStateException("Environment didn't contain a FontCollection record!");
}
}
/**
* We are of type 1010
*/
public long getRecordType() { return _type; }
/**
* Write the contents of the record back, so it can be written
* to disk
*/
public void writeOut(OutputStream out) throws IOException {
writeOut(_header[0],_header[1],_type,_children,out);
}
}

View File

@ -41,7 +41,7 @@ public class RecordTypes {
public static final Type SlideAtom = new Type(1007,SlideAtom.class); public static final Type SlideAtom = new Type(1007,SlideAtom.class);
public static final Type Notes = new Type(1008,Notes.class); public static final Type Notes = new Type(1008,Notes.class);
public static final Type NotesAtom = new Type(1009,NotesAtom.class); public static final Type NotesAtom = new Type(1009,NotesAtom.class);
public static final Type Environment = new Type(1010,DummyRecordWithChildren.class); public static final Type Environment = new Type(1010,Environment.class);
public static final Type SlidePersistAtom = new Type(1011,SlidePersistAtom.class); public static final Type SlidePersistAtom = new Type(1011,SlidePersistAtom.class);
public static final Type SSlideLayoutAtom = new Type(1015,null); public static final Type SSlideLayoutAtom = new Type(1015,null);
public static final Type MainMaster = new Type(1016,DummyPositionSensitiveRecordWithChildren.class); public static final Type MainMaster = new Type(1016,DummyPositionSensitiveRecordWithChildren.class);

View File

@ -201,8 +201,10 @@ public class SlideShow
// Now look for the interesting records in there // Now look for the interesting records in there
for(int i=0; i<_mostRecentCoreRecords.length; i++) { for(int i=0; i<_mostRecentCoreRecords.length; i++) {
// Find the Document, and interesting things in it
if(_mostRecentCoreRecords[i].getRecordType() == RecordTypes.Document.typeID) { if(_mostRecentCoreRecords[i].getRecordType() == RecordTypes.Document.typeID) {
_documentRecord = (Document)_mostRecentCoreRecords[i]; _documentRecord = (Document)_mostRecentCoreRecords[i];
_fonts = _documentRecord.getEnvironment().getFontCollection();
} }
} }
} }
@ -238,7 +240,7 @@ public class SlideShow
} }
// Now look for SlideListWithTexts in the most up-to-date Document Record // Fetch the SlideListWithTexts in the most up-to-date Document Record
// //
// Need to get the SlideAtomsSets for all of these. Then, query the // Need to get the SlideAtomsSets for all of these. Then, query the
// SlidePersistAtom, and group stuff together between SLWT blocks // SlidePersistAtom, and group stuff together between SLWT blocks
@ -257,23 +259,11 @@ public class SlideShow
// There shouldn't be any text duplication - only using the most // There shouldn't be any text duplication - only using the most
// record Document record's SLWTs should see to that // record Document record's SLWTs should see to that
Record[] docChildren = _documentRecord.getChildRecords(); SlideListWithText[] slwts = _documentRecord.getSlideListWithTexts();
for(int i=0; i<docChildren.length; i++) { for(int i=0; i<slwts.length; i++) {
// Look for SlideListWithText slwtV.add(slwts[i]);
if(docChildren[i] instanceof SlideListWithText) {
slwtV.add(docChildren[i]);
}
// Look for FontCollection under Environment
if(docChildren[i].getRecordType() == RecordTypes.Environment.typeID) {
Record[] envChildren = docChildren[i].getChildRecords();
for(int j=0; j<envChildren.length; j++) {
if(envChildren[j] instanceof FontCollection) {
_fonts = (FontCollection)envChildren[j];
}
}
}
} }
// For now, grab out all the sets of Atoms in the SlideListWithText's // For now, grab out all the sets of Atoms in the SlideListWithText's
// Only store those which aren't empty // Only store those which aren't empty
// Also, get the list of IDs while we're at it // Also, get the list of IDs while we're at it