]> source.dussan.org Git - poi.git/commitdiff
Add an Environment record, and make the code simpler
authorNick Burch <nick@apache.org>
Sun, 19 Mar 2006 16:09:51 +0000 (16:09 +0000)
committerNick Burch <nick@apache.org>
Sun, 19 Mar 2006 16:09:51 +0000 (16:09 +0000)
git-svn-id: https://svn.apache.org/repos/asf/jakarta/poi/trunk@386986 13f79535-47bb-0310-9956-ffa450edef68

src/scratchpad/src/org/apache/poi/hslf/record/Document.java
src/scratchpad/src/org/apache/poi/hslf/record/Environment.java [new file with mode: 0644]
src/scratchpad/src/org/apache/poi/hslf/record/RecordTypes.java
src/scratchpad/src/org/apache/poi/hslf/usermodel/SlideShow.java

index 15341162872e6dc3498cf3a7984dce10d8f8428d..c3c0012dd95f0af96293f41803bfe9708173b6f3 100644 (file)
@@ -35,7 +35,7 @@ public class Document extends PositionDependentRecordContainer
 
        // Links to our more interesting children
        private DocumentAtom documentAtom;
-       private Record environment;
+       private Environment environment;
        private SlideListWithText[] slwts;
 
        /**
@@ -46,7 +46,7 @@ public class Document extends PositionDependentRecordContainer
         * Returns the Environment of this Notes, which lots of
         *  settings for the document in it
         */
-       public Record getEnvironment() { return environment; }
+       public Environment getEnvironment() { return environment; }
        /**
         * Returns all the SlideListWithTexts that are defined for
         *  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) {
                                slwtcount++;
                        }
-                       if(_children[i].getRecordType() == RecordTypes.Environment.typeID) {
-                               environment = _children[i];
+                       if(_children[i] instanceof Environment) {
+                               environment = (Environment)_children[i];
                        }
                }
                // Now grab them all
diff --git a/src/scratchpad/src/org/apache/poi/hslf/record/Environment.java b/src/scratchpad/src/org/apache/poi/hslf/record/Environment.java
new file mode 100644 (file)
index 0000000..831e985
--- /dev/null
@@ -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);
+       }
+}
index d31bf84da3c2b7d1de6eaf29c47e80a8dabb2370..eaca249e962b0fb533a83ce886324265d6bf9b2d 100644 (file)
@@ -41,7 +41,7 @@ public class RecordTypes {
     public static final Type SlideAtom = new Type(1007,SlideAtom.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 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 SSlideLayoutAtom = new Type(1015,null);
     public static final Type MainMaster = new Type(1016,DummyPositionSensitiveRecordWithChildren.class);
index 1fc4c6fda7ad69d0671cedcbe0ac7dfb1cf53f61..ac16539c406e4afec6427307853cff77ba92ac92 100644 (file)
@@ -201,8 +201,10 @@ public class SlideShow
        
        // Now look for the interesting records in there
        for(int i=0; i<_mostRecentCoreRecords.length; i++) {
+               // Find the Document, and interesting things in it
                if(_mostRecentCoreRecords[i].getRecordType() == RecordTypes.Document.typeID) {
                        _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
        //  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
        //  record Document record's SLWTs should see to that
 
-       Record[] docChildren = _documentRecord.getChildRecords();
-       for(int i=0; i<docChildren.length; i++) {
-               // Look for SlideListWithText
-               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];
-                               }
-                       }
-               }
+       SlideListWithText[] slwts = _documentRecord.getSlideListWithTexts();
+       for(int i=0; i<slwts.length; i++) {
+               slwtV.add(slwts[i]);
        }
-
+       
        // For now, grab out all the sets of Atoms in the SlideListWithText's
        // Only store those which aren't empty
        // Also, get the list of IDs while we're at it