You are viewing a plain text version of this content. The canonical link for it is here.
Posted to fop-commits@xmlgraphics.apache.org by ph...@apache.org on 2005/08/25 23:36:46 UTC

svn commit: r240144 - /xmlgraphics/fop/trunk/src/java/org/apache/fop/render/rtf/RTFHandler.java

Author: pherweg
Date: Thu Aug 25 14:36:42 2005
New Revision: 240144

URL: http://svn.apache.org/viewcvs?rev=240144&view=rev
Log:
fixed support for tables and lists

Modified:
    xmlgraphics/fop/trunk/src/java/org/apache/fop/render/rtf/RTFHandler.java

Modified: xmlgraphics/fop/trunk/src/java/org/apache/fop/render/rtf/RTFHandler.java
URL: http://svn.apache.org/viewcvs/xmlgraphics/fop/trunk/src/java/org/apache/fop/render/rtf/RTFHandler.java?rev=240144&r1=240143&r2=240144&view=diff
==============================================================================
--- xmlgraphics/fop/trunk/src/java/org/apache/fop/render/rtf/RTFHandler.java (original)
+++ xmlgraphics/fop/trunk/src/java/org/apache/fop/render/rtf/RTFHandler.java Thu Aug 25 14:36:42 2005
@@ -57,6 +57,7 @@
 import org.apache.fop.fo.pagination.Flow;
 import org.apache.fop.fo.pagination.PageSequence;
 import org.apache.fop.fo.pagination.SimplePageMaster;
+import org.apache.fop.fo.pagination.StaticContent;
 import org.apache.fop.fo.Constants;
 import org.apache.fop.fo.FOText;
 import org.apache.fop.render.rtf.rtflib.rtfdoc.ITableAttributes;
@@ -103,12 +104,8 @@
     private static Log log = LogFactory.getLog(RTFHandler.class);
     private RtfSection sect;
     private RtfDocumentArea docArea;
-    private int iNestCount;
     private boolean bDefer;              //true, if each called handler shall be
                                          //processed at later time.
-    private boolean bDeferredExecution;  //true, if currently called handler was not
-                                         //called while SAX parsing, but was called
-                                         //by invokeDeferredEvent.
     private boolean bPrevHeaderSpecified = false; //true, if there has been a
                                                   //header in any page-sequence
     private boolean bPrevFooterSpecified = false; //true, if there has been a
@@ -128,9 +125,8 @@
     public RTFHandler(FOUserAgent userAgent, OutputStream os) {
         super(userAgent);
         this.os = os;
-        bDefer = false;
-        bDeferredExecution = false;
-        iNestCount = 0;
+        bDefer = true;
+
         FontSetup.setup(fontInfo, null);
     }
 
@@ -203,10 +199,17 @@
      */
     public void endPageSequence(PageSequence pageSeq) {
         if (bDefer) {
+            //If endBlock was called while SAX parsing, and the passed FO is Block
+            //nested within another Block, stop deferring.
+            //Now process all deferred FOs.
+            bDefer = false;
+            recurseFONode(pageSeq);
+            bDefer = true;
+            
             return;
+        } else {
+            builderContext.popContainer();
         }
-
-        builderContext.popContainer();
     }
 
     /**
@@ -315,15 +318,6 @@
      * @see org.apache.fop.fo.FOEventHandler#startBlock(Block)
      */
     public void startBlock(Block bl) {
-        ++iNestCount;
-        
-        if (!bDeferredExecution) {
-            //If startBlock was called while SAX parsing, defer processing of this
-            //FO and all its elements until endBlock. This has to be done, because
-            //attributes (for example while-space-treatment, linefeed-treatment)
-            //are not available until endBlock.
-            bDefer = true;
-        }
         if (bDefer) {
             return;
         }
@@ -356,23 +350,7 @@
      * @see org.apache.fop.fo.FOEventHandler#endBlock(Block)
      */
     public void endBlock(Block bl) {
-        --iNestCount;
-        
-        if (!bDeferredExecution && iNestCount == 0) {
-            //If endBlock was called while SAX parsing, and the passed FO is Block
-            //nested within another Block, stop deferring.
-            //Now process all deferred FOs.
-            bDefer = false;
-            
-            bDeferredExecution = true;
-            recurseFONode(bl);
-            bDeferredExecution = false;
-            
-            //exit function, because the code has already beed executed while 
-            //deferred execution.   
-            return;
-        }
-        
+
         if (bDefer) {
             return;
         }
@@ -1198,7 +1176,25 @@
      * @param bStart TRUE calls the start handler, FALSE the end handler 
      */
     private void invokeDeferredEvent(FONode foNode, boolean bStart) {
-        if (foNode instanceof Block) {
+        if (foNode instanceof PageSequence) {
+            if (bStart) {
+                startPageSequence( (PageSequence) foNode);
+            } else {
+                endPageSequence( (PageSequence) foNode);
+            }
+        } else if (foNode instanceof Flow) {
+            if (bStart) {
+                startFlow( (Flow) foNode);
+            } else {
+                endFlow( (Flow) foNode);
+            }
+        } else if (foNode instanceof StaticContent) {
+            if (bStart) {
+                startStatic();
+            } else {
+                endStatic();
+            }
+        } else if (foNode instanceof Block) {
             if (bStart) {
                 startBlock( (Block) foNode);
             } else {
@@ -1297,12 +1293,58 @@
     private void recurseFONode(FONode foNode) {
         invokeDeferredEvent(foNode, true);
         
-        if (foNode.getChildNodes() != null) {
-            for (Iterator it = foNode.getChildNodes(); it.hasNext();) {
+        if (foNode instanceof PageSequence) {
+            PageSequence pageSequence = (PageSequence) foNode;
+                        
+            FONode regionBefore = (FONode) pageSequence.flowMap.get("xsl-region-before");
+            FONode regionAfter  = (FONode) pageSequence.flowMap.get("xsl-region-after");
+            
+            if (regionBefore != null) {
+                recurseFONode(regionBefore);
+            }
+            
+            if (regionAfter != null) {
+                recurseFONode(regionAfter);
+            }            
+            
+            recurseFONode( pageSequence.getMainFlow() );
+        } else if (foNode instanceof Table) {
+            Table table = (Table) foNode;
+            
+            //recurse all table-columns
+            for(Iterator it = table.getColumns().iterator(); it.hasNext();) {
                 recurseFONode( (FONode) it.next() );
             }
+            
+            //recurse table-header
+            if (table.getTableHeader()!=null) {
+                recurseFONode( table.getTableHeader() );
+            }
+            
+            //recurse table-footer
+            if (table.getTableHeader()!=null) {
+                recurseFONode( table.getTableFooter() );
+            }
+            
+            if (foNode.getChildNodes() != null) {
+                for (Iterator it = foNode.getChildNodes(); it.hasNext();) {
+                    recurseFONode( (FONode) it.next() );                       
+                }
+            }
+        } else if (foNode instanceof ListItem) {
+            ListItem item = (ListItem) foNode;
+            
+            recurseFONode( item.getLabel());
+            recurseFONode( item.getBody());
+        } else {
+            //Any other FO-Object: Simply recurse through all childNodes.
+            if (foNode.getChildNodes() != null) {
+                for (Iterator it = foNode.getChildNodes(); it.hasNext();) {
+                    recurseFONode( (FONode) it.next() );                       
+                }
+            }
         }
-        
+                
         invokeDeferredEvent(foNode, false);
     }
 }



---------------------------------------------------------------------
To unsubscribe, e-mail: fop-commits-unsubscribe@xmlgraphics.apache.org
For additional commands, e-mail: fop-commits-help@xmlgraphics.apache.org