]> source.dussan.org Git - xmlgraphics-fop.git/commitdiff
Bugzilla 46828: Activation of the possibility to use CachedRenderPagesModel to conser...
authorAndreas L. Delmelle <adelmelle@apache.org>
Fri, 13 Mar 2009 17:51:45 +0000 (17:51 +0000)
committerAndreas L. Delmelle <adelmelle@apache.org>
Fri, 13 Mar 2009 17:51:45 +0000 (17:51 +0000)
Thanks to Dario Laeria for submitting and testing.

git-svn-id: https://svn.apache.org/repos/asf/xmlgraphics/fop/trunk@753327 13f79535-47bb-0310-9956-ffa450edef68

src/java/org/apache/fop/apps/FOUserAgent.java
src/java/org/apache/fop/area/AreaTreeHandler.java
src/java/org/apache/fop/area/CachedRenderPagesModel.java
src/java/org/apache/fop/area/inline/InlineArea.java
src/java/org/apache/fop/cli/CommandLineOptions.java
src/java/org/apache/fop/layoutmgr/BlockStackingLayoutManager.java
src/java/org/apache/fop/layoutmgr/table/TableCellLayoutManager.java
status.xml

index ebd2e0594229e11e8e7157a64be2dc0ff0157f73..303967a75dc7f08a007cc3a8f27b835f194e831a 100644 (file)
@@ -97,6 +97,7 @@ public class FOUserAgent {
     private Renderer rendererOverride = null;
     private FOEventHandler foEventHandlerOverride = null;
     private boolean locatorEnabled = true; // true by default (for error messages).
+    private boolean conserveMemoryPolicy = false;
     private EventBroadcaster eventBroadcaster = new FOPEventBroadcaster();
 
     /** Producer:  Metadata element for the system/software that produces
@@ -615,5 +616,23 @@ public class FOUserAgent {
 
     }
 
+    /**
+     * Check whether memory-conservation is enabled.
+     *
+     * @return true if FOP is to conserve as much as possible
+     */
+    public boolean isConserveMemoryPolicyEnabled() {
+        return this.conserveMemoryPolicy;
+    }
+
+    /**
+     * Control whether memory-conservation should be enabled
+     *
+     * @param conserveMemoryPolicy the cachingEnabled to set
+     */
+    public void setConserveMemoryPolicy(boolean conserveMemoryPolicy) {
+        this.conserveMemoryPolicy = conserveMemoryPolicy;
+    }
+
 }
 
index 128fc8ce9994faa6f5a6fa4a98258a52ac597e26..298cf263b39859f48af26496ae8e7dd5ffe36374 100644 (file)
@@ -124,7 +124,11 @@ public class AreaTreeHandler extends FOEventHandler {
      */
     protected void setupModel(FOUserAgent userAgent, String outputFormat,
             OutputStream stream) throws FOPException {
-        this.model = new RenderPagesModel(userAgent, outputFormat, fontInfo, stream);
+        if (userAgent.isConserveMemoryPolicyEnabled()) {
+            this.model = new CachedRenderPagesModel(userAgent, outputFormat, fontInfo, stream);
+        } else {
+            this.model = new RenderPagesModel(userAgent, outputFormat, fontInfo, stream);
+        }
     }
 
     /**
@@ -442,7 +446,6 @@ public class AreaTreeHandler extends FOEventHandler {
 
         /**
          * Default constructor
-         * @param areaTreeHandler area tree handler
          */
         protected Statistics() {
             this.runtime = Runtime.getRuntime();
index f522b978bd2d46d2cb1a0f4e892d6061bec80599..73c50fa17de82a40f45834aeea2ec8289cde9568 100644 (file)
@@ -129,7 +129,7 @@ public class CachedRenderPagesModel extends RenderPagesModel {
         try {
             // save page to cache
             ObjectOutputStream tempstream;
-            String fname = "fop-page-" + page.toString() + ".ser";
+            String fname = "fop-page-" + page.getPageIndex() + ".ser";
             File tempFile = new File(baseDir, fname);
             tempFile.deleteOnExit();
             tempstream = new ObjectOutputStream(new BufferedOutputStream(
index 6d5d9ca98c7f883acf48f454538a247fd0d63c76..5106fd5bc3e7d9a4d482dbb23fed0b5315efea85 100644 (file)
@@ -19,6 +19,8 @@
 
 package org.apache.fop.area.inline;
 
+import java.io.Serializable;
+
 import org.apache.fop.area.Area;
 import org.apache.fop.area.LineArea;
 import org.apache.fop.area.Trait;
@@ -35,7 +37,7 @@ public class InlineArea extends Area {
      * that can be used in order to re-compute adjustments when a
      * page-number or a page-number-citation is resolved
      */
-    protected class InlineAdjustingInfo {
+    protected class InlineAdjustingInfo implements Serializable {
         /** stretch of the inline area */
         protected int availableStretch;
         /** shrink of the inline area */
index fef2a1f46671f728d4f09dfe8e5468be553ac980..cfab37c952b06fd3364c73a2f2349b27590c1412 100644 (file)
@@ -110,6 +110,8 @@ public class CommandLineOptions {
     private Map renderingOptions = new java.util.HashMap();
     /* target resolution (for the user agent) */
     private int targetResolution = 0;
+    /* control memory-conservation policy */
+    private boolean conserveMemoryPolicy = false;
 
     private FopFactory factory = FopFactory.newInstance();
     private FOUserAgent foUserAgent;
@@ -168,6 +170,7 @@ public class CommandLineOptions {
                 }
                 addXSLTParameter("fop-output-format", getOutputFormat());
                 addXSLTParameter("fop-version", Version.getVersion());
+                foUserAgent.setConserveMemoryPolicy(conserveMemoryPolicy);
             } else {
                 return false;
             }
@@ -268,6 +271,8 @@ public class CommandLineOptions {
                 setLogOption("debug", "debug");
             } else if (args[i].equals("-r")) {
                 factory.setStrictValidation(false);
+            } else if (args[i].equals("-conserve")) {
+                conserveMemoryPolicy = true;
             } else if (args[i].equals("-dpi")) {
                 i = i + parseResolution(args, i);
             } else if (args[i].equals("-q") || args[i].equals("--quiet")) {
@@ -1131,6 +1136,8 @@ public class CommandLineOptions {
             + "  -noannotations    PDF file will be encrypted without edit annotation permission\n"
             + "  -pdfprofile prof  PDF file will be generated with the specified profile\n"
             + "                    (Examples for prof: PDF/A-1b or PDF/X-3:2003)\n\n"
+            + "  -conserve         Enable memory-conservation policy (trades memory-consumption for disk I/O)"
+            + "                    (Note: currently only influences whether the area tree is serialized.)"
             + " [INPUT]  \n"
             + "  infile            xsl:fo input file (the same as the next) \n"
             + "                    (use '-' for infile to pipe input from stdin)\n"
index 64b8bbc0d33c9f850e83c3bd045b338710975380..1f18a67a062dced6dcf54eb38e20a2c74d57344f 100644 (file)
@@ -167,6 +167,13 @@ public abstract class BlockStackingLayoutManager extends AbstractLayoutManager
         addChildToArea(childArea, getCurrentArea());
     }
 
+    /** {@inheritDoc} */
+    protected void notifyEndOfLayout() {
+        super.notifyEndOfLayout();
+        // Free memory of the area tree
+        //this.parentArea = null;
+    }
+
     /**
      * Force current area to be added to parent area.
      */
@@ -486,7 +493,7 @@ public abstract class BlockStackingLayoutManager extends AbstractLayoutManager
         //      ? "penalty" : (lastElement.isGlue() ? "glue" : "box" )));
 /*LF*/  //log.debug("  position e' " + lastElement.getPosition().getClass().getName());
 /*LF*/  //log.debug("  " + (bpUnit > 0 ? "unit" : ""));
-        Position innerPosition = ((NonLeafPosition) lastElement.getPosition()).getPosition();
+        Position innerPosition = lastElement.getPosition().getPosition();
 
         if (innerPosition == null && lastElement.isGlue()) {
             // this adjustment applies to space-before or space-after of this block
@@ -536,7 +543,7 @@ public abstract class BlockStackingLayoutManager extends AbstractLayoutManager
 /*LF*/              //log.debug("  BLM.negotiateBPDAdjustment> chiamata passata");
                     return ((BlockLevelLayoutManager)storedPenalty.getLayoutManager())
                            .negotiateBPDAdjustment(storedPenalty.getW(),
-                                   (KnuthElement)storedPenalty);
+                                   storedPenalty);
                 } else {
                     // the original penalty has width = 0
                     // the adjustment involves only the spaces before and after
@@ -787,12 +794,12 @@ public abstract class BlockStackingLayoutManager extends AbstractLayoutManager
                 returnList.add(new KnuthGlue(0, 0, 0,
                         SPACE_AFTER_ADJUSTMENT,
                         new NonLeafPosition(this, null),
-                        (!spaceAfterIsConditional) ? false : true));
+                        spaceAfterIsConditional));
             } else {
                 returnList.add(new KnuthGlue(adjustedSpaceAfter, 0, 0,
                         SPACE_AFTER_ADJUSTMENT,
                         new NonLeafPosition(this, null),
-                        (!spaceAfterIsConditional) ? false : true));
+                        spaceAfterIsConditional));
             }
             if (!spaceAfterIsConditional) {
                 returnList.add(new KnuthBox(0,
@@ -1201,8 +1208,8 @@ public abstract class BlockStackingLayoutManager extends AbstractLayoutManager
                 totalLength.add(new MinOptMax(element.getW()));
                 //log.debug("box " + element.getW());
             } else if (element.isGlue()) {
-                totalLength.min -= ((KnuthGlue) element).getZ();
-                totalLength.max += ((KnuthGlue) element).getY();
+                totalLength.min -= element.getZ();
+                totalLength.max += element.getY();
                 //leafValue = ((LeafPosition) element.getPosition()).getLeafPos();
                 //log.debug("glue " + element.getW() + " + "
                 //    + ((KnuthGlue) element).getY() + " - " + ((KnuthGlue) element).getZ());
@@ -1239,10 +1246,10 @@ public abstract class BlockStackingLayoutManager extends AbstractLayoutManager
                 lengthAfterBreak.subtract(new MinOptMax(element.getW()));
                 bPrevIsBox = true;
             } else if (element.isGlue()) {
-                lengthBeforeBreak.min -= ((KnuthGlue) element).getZ();
-                lengthAfterBreak.min += ((KnuthGlue) element).getZ();
-                lengthBeforeBreak.max += ((KnuthGlue) element).getY();
-                lengthAfterBreak.max -= ((KnuthGlue) element).getY();
+                lengthBeforeBreak.min -= element.getZ();
+                lengthAfterBreak.min += element.getZ();
+                lengthBeforeBreak.max += element.getY();
+                lengthAfterBreak.max -= element.getY();
                 bPrevIsBox = false;
             } else {
                 lengthBeforeBreak.add(new MinOptMax(element.getW()));
@@ -1250,7 +1257,7 @@ public abstract class BlockStackingLayoutManager extends AbstractLayoutManager
             }
 
             // create the new elements
-            if (element.isPenalty() && ((KnuthPenalty) element).getP() < KnuthElement.INFINITE
+            if (element.isPenalty() && element.getP() < KnuthElement.INFINITE
                     || element.isGlue() && bPrevIsBox
                     || !oldListIterator.hasNext()) {
                 // suppress elements after the breaking point
@@ -1260,8 +1267,8 @@ public abstract class BlockStackingLayoutManager extends AbstractLayoutManager
                     iStepsForward++;
                     if (el.isGlue()) {
                         // suppressed glue
-                        lengthAfterBreak.min += ((KnuthGlue) el).getZ();
-                        lengthAfterBreak.max -= ((KnuthGlue) el).getY();
+                        lengthAfterBreak.min += el.getZ();
+                        lengthAfterBreak.max -= el.getY();
                     } else if (el.isPenalty()) {
                         // suppressed penalty, do nothing
                     } else {
@@ -1281,8 +1288,8 @@ public abstract class BlockStackingLayoutManager extends AbstractLayoutManager
                 for (int i = 0; i < iStepsForward; i++) {
                     KnuthElement el = (KnuthElement) oldListIterator.previous();
                     if (el.isGlue()) {
-                        lengthAfterBreak.min -= ((KnuthGlue) el).getZ();
-                        lengthAfterBreak.max += ((KnuthGlue) el).getY();
+                        lengthAfterBreak.min -= el.getZ();
+                        lengthAfterBreak.max += el.getY();
                     }
                 }
 
index ba5e232e90b4fb900ffef068fd2127627c4b1eca..239a1a88e0b427d31b2ad464c3930489c2be1f7d 100644 (file)
@@ -201,8 +201,6 @@ public class TableCellLayoutManager extends BlockStackingLayoutManager
             p.setP(0);
         }
 
-        notifyEndOfLayout();
-
         setFinished(true);
         return returnList;
     }
@@ -427,6 +425,8 @@ public class TableCellLayoutManager extends BlockStackingLayoutManager
         flush();
 
         curBlockArea = null;
+
+        notifyEndOfLayout();
     }
 
     /** Adds background areas for the column, body and row, if any. */
index 7e60a7342d214bc225189bddf4da32cd171708f0..825824410c2fdcdde447ad9e8080a96a9518405b 100644 (file)
       documents. Example: the fix of marks layering will be such a case when it's done.
     -->
     <release version="FOP Trunk" date="TBD">
+      <action context="Code" dev="AD" type="add" fixes-bug="46828" due-to="Dario Laera">
+        Added the possibility to use CachedRenderPagesModel, to conserve memory in case
+        of large documents with a lot of cross-references (area tree will be serialized to
+        disk to avoid keeping it entirely in memory).
+      </action>
       <action context="Fonts" dev="JM" type="add">
-        AFP Fonts: Added support for full URI resolution on configured AFP fonts. 
+        AFP Fonts: Added support for full URI resolution on configured AFP fonts.
       </action>
       <action context="Renderers" dev="JM" type="add">
         AFP Output: Tag Logical Element (TLE) is now also allowed on fo:page-sequence
-        (page group level). 
+        (page group level).
       </action>
       <action context="Layout" dev="JM" type="fix">
         Fixed BPD trait and border painting for leaders with leader-pattern="space"
-        (and similar cases).  
+        (and similar cases).
       </action>
       <action context="Renderers" dev="JM" type="add">
-        AFP Output: Added support for Invoke Medium Map (IMM). 
+        AFP Output: Added support for Invoke Medium Map (IMM).
       </action>
       <action context="Renderers" dev="JM" type="add">
         Introduced a new, additional intermediate format optimized for performance. Please see
         code.
       </action>
       <action context="Code" dev="VH" type="fix" fixes-bug="46638">
-        MinOptMaxUtil.toMinOptMax was converting LengthRangeProperty objects into illegal MinOptMax 
+        MinOptMaxUtil.toMinOptMax was converting LengthRangeProperty objects into illegal MinOptMax
         objects (in some cases opt could be inferior to min).
       </action>
       <action context="Layout" dev="VH" type="add" fixes-bug="46315" due-to="Georg Datterl">
-        Added extension to disable column balancing before blocks spanning the whole page, in 
+        Added extension to disable column balancing before blocks spanning the whole page, in
         multiple-column documents.
       </action>
       <action context="Renderers" dev="JM" type="add">