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 ga...@apache.org on 2016/03/03 10:40:51 UTC

svn commit: r1733431 [1/2] - in /xmlgraphics/fop/branches/maven: ./ lib/ lib/build/ src/java/org/apache/fop/apps/ src/java/org/apache/fop/area/ src/java/org/apache/fop/fo/ src/java/org/apache/fop/fo/flow/ src/java/org/apache/fop/fo/pagination/ src/java...

Author: gadams
Date: Thu Mar  3 09:40:50 2016
New Revision: 1733431

URL: http://svn.apache.org/viewvc?rev=1733431&view=rev
Log:
Merge from ^/xmlgraphics/fop/trunk.

Added:
    xmlgraphics/fop/branches/maven/src/java/org/apache/fop/render/ps/Gradient.java
      - copied unchanged from r1733430, xmlgraphics/fop/trunk/src/java/org/apache/fop/render/ps/Gradient.java
    xmlgraphics/fop/branches/maven/test/java/org/apache/fop/pdf/PDFAttachmentTestCase.java
      - copied unchanged from r1733430, xmlgraphics/fop/trunk/test/java/org/apache/fop/pdf/PDFAttachmentTestCase.java
    xmlgraphics/fop/branches/maven/test/java/org/apache/fop/render/pcl/PCLPainterTestCase.java
      - copied unchanged from r1733430, xmlgraphics/fop/trunk/test/java/org/apache/fop/render/pcl/PCLPainterTestCase.java
    xmlgraphics/fop/branches/maven/test/layoutengine/standard-testcases/flow_changing-ipd_columns.xml
      - copied unchanged from r1733430, xmlgraphics/fop/trunk/test/layoutengine/standard-testcases/flow_changing-ipd_columns.xml
    xmlgraphics/fop/branches/maven/test/layoutengine/standard-testcases/flow_changing-ipd_last-page_1.xml
      - copied unchanged from r1733430, xmlgraphics/fop/trunk/test/layoutengine/standard-testcases/flow_changing-ipd_last-page_1.xml
    xmlgraphics/fop/branches/maven/test/layoutengine/standard-testcases/flow_changing-ipd_last-page_2.xml
      - copied unchanged from r1733430, xmlgraphics/fop/trunk/test/layoutengine/standard-testcases/flow_changing-ipd_last-page_2.xml
    xmlgraphics/fop/branches/maven/test/layoutengine/standard-testcases/flow_changing-ipd_last-page_3.xml
      - copied unchanged from r1733430, xmlgraphics/fop/trunk/test/layoutengine/standard-testcases/flow_changing-ipd_last-page_3.xml
    xmlgraphics/fop/branches/maven/test/layoutengine/standard-testcases/flow_changing-ipd_last-page_4.xml
      - copied unchanged from r1733430, xmlgraphics/fop/trunk/test/layoutengine/standard-testcases/flow_changing-ipd_last-page_4.xml
    xmlgraphics/fop/branches/maven/test/layoutengine/standard-testcases/flow_changing-ipd_last-page_5.xml
      - copied unchanged from r1733430, xmlgraphics/fop/trunk/test/layoutengine/standard-testcases/flow_changing-ipd_last-page_5.xml
    xmlgraphics/fop/branches/maven/test/layoutengine/standard-testcases/flow_changing-ipd_last-page_6.xml
      - copied unchanged from r1733430, xmlgraphics/fop/trunk/test/layoutengine/standard-testcases/flow_changing-ipd_last-page_6.xml
    xmlgraphics/fop/branches/maven/test/layoutengine/standard-testcases/flow_changing-ipd_last-page_7.xml
      - copied unchanged from r1733430, xmlgraphics/fop/trunk/test/layoutengine/standard-testcases/flow_changing-ipd_last-page_7.xml
    xmlgraphics/fop/branches/maven/test/layoutengine/standard-testcases/flow_changing-ipd_last-page_8.xml
      - copied unchanged from r1733430, xmlgraphics/fop/trunk/test/layoutengine/standard-testcases/flow_changing-ipd_last-page_8.xml
    xmlgraphics/fop/branches/maven/test/layoutengine/standard-testcases/flow_changing-ipd_last-page_9.xml
      - copied unchanged from r1733430, xmlgraphics/fop/trunk/test/layoutengine/standard-testcases/flow_changing-ipd_last-page_9.xml
    xmlgraphics/fop/branches/maven/test/layoutengine/standard-testcases/flow_changing-ipd_no-last-page.xml
      - copied unchanged from r1733430, xmlgraphics/fop/trunk/test/layoutengine/standard-testcases/flow_changing-ipd_no-last-page.xml
Removed:
    xmlgraphics/fop/branches/maven/status.xml
Modified:
    xmlgraphics/fop/branches/maven/   (props changed)
    xmlgraphics/fop/branches/maven/NOTICE
    xmlgraphics/fop/branches/maven/README
    xmlgraphics/fop/branches/maven/build.xml
    xmlgraphics/fop/branches/maven/lib/   (props changed)
    xmlgraphics/fop/branches/maven/lib/build/   (props changed)
    xmlgraphics/fop/branches/maven/lib/xmlgraphics-commons-svn-trunk.jar
    xmlgraphics/fop/branches/maven/src/java/org/apache/fop/apps/FOUserAgent.java
    xmlgraphics/fop/branches/maven/src/java/org/apache/fop/apps/FopFactory.java
    xmlgraphics/fop/branches/maven/src/java/org/apache/fop/area/BodyRegion.java
    xmlgraphics/fop/branches/maven/src/java/org/apache/fop/area/MainReference.java
    xmlgraphics/fop/branches/maven/src/java/org/apache/fop/fo/FONode.java
    xmlgraphics/fop/branches/maven/src/java/org/apache/fop/fo/FObj.java
    xmlgraphics/fop/branches/maven/src/java/org/apache/fop/fo/FObjMixed.java
    xmlgraphics/fop/branches/maven/src/java/org/apache/fop/fo/flow/AbstractGraphics.java
    xmlgraphics/fop/branches/maven/src/java/org/apache/fop/fo/flow/RetrieveTableMarker.java
    xmlgraphics/fop/branches/maven/src/java/org/apache/fop/fo/pagination/Declarations.java
    xmlgraphics/fop/branches/maven/src/java/org/apache/fop/fo/pagination/PageSequence.java
    xmlgraphics/fop/branches/maven/src/java/org/apache/fop/fo/pagination/PageSequenceMaster.java
    xmlgraphics/fop/branches/maven/src/java/org/apache/fop/fo/pagination/RepeatablePageMasterAlternatives.java
    xmlgraphics/fop/branches/maven/src/java/org/apache/fop/fo/pagination/RepeatablePageMasterReference.java
    xmlgraphics/fop/branches/maven/src/java/org/apache/fop/fo/pagination/Root.java
    xmlgraphics/fop/branches/maven/src/java/org/apache/fop/fo/pagination/SinglePageMasterReference.java
    xmlgraphics/fop/branches/maven/src/java/org/apache/fop/fo/pagination/SubSequenceSpecifier.java
    xmlgraphics/fop/branches/maven/src/java/org/apache/fop/layoutmgr/AbstractBreaker.java
    xmlgraphics/fop/branches/maven/src/java/org/apache/fop/layoutmgr/AbstractPageSequenceLayoutManager.java
    xmlgraphics/fop/branches/maven/src/java/org/apache/fop/layoutmgr/BlockLevelEventProducer.java
    xmlgraphics/fop/branches/maven/src/java/org/apache/fop/layoutmgr/BlockLevelEventProducer.xml
    xmlgraphics/fop/branches/maven/src/java/org/apache/fop/layoutmgr/PageBreaker.java
    xmlgraphics/fop/branches/maven/src/java/org/apache/fop/layoutmgr/PageBreakingAlgorithm.java
    xmlgraphics/fop/branches/maven/src/java/org/apache/fop/layoutmgr/PageProvider.java
    xmlgraphics/fop/branches/maven/src/java/org/apache/fop/layoutmgr/PageSequenceLayoutManager.java
    xmlgraphics/fop/branches/maven/src/java/org/apache/fop/layoutmgr/table/TableContentPosition.java
    xmlgraphics/fop/branches/maven/src/java/org/apache/fop/layoutmgr/table/TableRowIterator.java
    xmlgraphics/fop/branches/maven/src/java/org/apache/fop/pdf/PDFPattern.java
    xmlgraphics/fop/branches/maven/src/java/org/apache/fop/render/intermediate/IFParser.java
    xmlgraphics/fop/branches/maven/src/java/org/apache/fop/render/pcl/Java2DRendererOption.java
    xmlgraphics/fop/branches/maven/src/java/org/apache/fop/render/pcl/PCLDocumentHandler.java
    xmlgraphics/fop/branches/maven/src/java/org/apache/fop/render/pcl/PCLGenerator.java
    xmlgraphics/fop/branches/maven/src/java/org/apache/fop/render/pcl/PCLImageHandlerGraphics2D.java
    xmlgraphics/fop/branches/maven/src/java/org/apache/fop/render/pcl/PCLImageHandlerRenderedImage.java
    xmlgraphics/fop/branches/maven/src/java/org/apache/fop/render/pcl/PCLPainter.java
    xmlgraphics/fop/branches/maven/src/java/org/apache/fop/render/pcl/PCLRendererConfig.java
    xmlgraphics/fop/branches/maven/src/java/org/apache/fop/render/pcl/PCLRendererConfigurator.java
    xmlgraphics/fop/branches/maven/src/java/org/apache/fop/render/pcl/PCLRenderingUtil.java
    xmlgraphics/fop/branches/maven/test/java/org/apache/fop/fo/flow/table/CollapsedConditionalBorderTestCase.java
    xmlgraphics/fop/branches/maven/test/layoutengine/standard-testcases/basic_link_to_last_page.xml
    xmlgraphics/fop/branches/maven/xmlgraphics-fop-pom-template.pom

Propchange: xmlgraphics/fop/branches/maven/
------------------------------------------------------------------------------
--- svn:mergeinfo (original)
+++ svn:mergeinfo Thu Mar  3 09:40:50 2016
@@ -15,3 +15,4 @@
 /xmlgraphics/fop/branches/fop-0_95:684572,688085,688696
 /xmlgraphics/fop/branches/fop-1_0:959975-964707
 /xmlgraphics/fop/branches/fop-1_1:1357766-1400689,1400697
+/xmlgraphics/fop/trunk:1721689-1733430

Modified: xmlgraphics/fop/branches/maven/NOTICE
URL: http://svn.apache.org/viewvc/xmlgraphics/fop/branches/maven/NOTICE?rev=1733431&r1=1733430&r2=1733431&view=diff
==============================================================================
--- xmlgraphics/fop/branches/maven/NOTICE (original)
+++ xmlgraphics/fop/branches/maven/NOTICE Thu Mar  3 09:40:50 2016
@@ -1,5 +1,5 @@
 Apache FOP
-Copyright 1999-2015 The Apache Software Foundation
+Copyright 1999-2016 The Apache Software Foundation
 
 This product includes software developed at
 The Apache Software Foundation (http://www.apache.org/).

Modified: xmlgraphics/fop/branches/maven/README
URL: http://svn.apache.org/viewvc/xmlgraphics/fop/branches/maven/README?rev=1733431&r1=1733430&r2=1733431&view=diff
==============================================================================
--- xmlgraphics/fop/branches/maven/README (original)
+++ xmlgraphics/fop/branches/maven/README Thu Mar  3 09:40:50 2016
@@ -93,6 +93,23 @@ http://xmlgraphics.apache.org/fop/stable
   RELEASE NOTES
 ==============================================================================
 
+Version 2.1
+===========
+
+Major Changes in Version 2.1
+----------------------------
+
+* Add PreloaderRawPNG to handle images ImageIO cant
+* Support Barcode4J page number
+* Support CMYK JPEG in AFP
+* Support IPD change on last page
+* Support PDF/UA
+* Support TrueType fonts in PCL
+* Support Truetype for AFP
+* Support for PDF/A-3
+
+This release also contains a number of bug fixes.
+
 Version 2.0
 ===========
 

Modified: xmlgraphics/fop/branches/maven/build.xml
URL: http://svn.apache.org/viewvc/xmlgraphics/fop/branches/maven/build.xml?rev=1733431&r1=1733430&r2=1733431&view=diff
==============================================================================
--- xmlgraphics/fop/branches/maven/build.xml (original)
+++ xmlgraphics/fop/branches/maven/build.xml Thu Mar  3 09:40:50 2016
@@ -151,7 +151,7 @@ list of possible build targets.
   <property name="name" value="fop"/>
   <property name="NAME" value="FOP"/>
   <property name="version" value="svn-trunk"/>
-  <property name="year" value="1999-2015"/>
+  <property name="year" value="1999-2016"/>
   <property name="javac.debug" value="on"/>
   <property name="javac.optimize" value="off"/>
   <property name="javac.deprecation" value="on"/>
@@ -160,7 +160,7 @@ list of possible build targets.
   <property name="javac.fork" value="no"/>
   <property name="junit.fork" value="yes"/>
   <property name="junit.haltonfailure" value="off"/>
-  <property name="junit.maxmemory" value="256m"/>
+  <property name="junit.maxmemory" value="1024m"/>
   <property name="junit.printsummary" value="off"/>
   <property name="junit.formatter.brief" value="on"/>
   <property name="javadoc.packages" value="org.apache.fop.*"/>

Propchange: xmlgraphics/fop/branches/maven/lib/
------------------------------------------------------------------------------
--- svn:ignore (original)
+++ svn:ignore Thu Mar  3 09:40:50 2016
@@ -1 +1,2 @@
 checkstyle*.jar
+fop-hyph.jar

Propchange: xmlgraphics/fop/branches/maven/lib/build/
------------------------------------------------------------------------------
--- svn:ignore (original)
+++ svn:ignore Thu Mar  3 09:40:50 2016
@@ -1 +1,2 @@
 checkstyle-*.jar
+junit*.jar

Modified: xmlgraphics/fop/branches/maven/lib/xmlgraphics-commons-svn-trunk.jar
URL: http://svn.apache.org/viewvc/xmlgraphics/fop/branches/maven/lib/xmlgraphics-commons-svn-trunk.jar?rev=1733431&r1=1733430&r2=1733431&view=diff
==============================================================================
Binary files - no diff available.

Modified: xmlgraphics/fop/branches/maven/src/java/org/apache/fop/apps/FOUserAgent.java
URL: http://svn.apache.org/viewvc/xmlgraphics/fop/branches/maven/src/java/org/apache/fop/apps/FOUserAgent.java?rev=1733431&r1=1733430&r2=1733431&view=diff
==============================================================================
--- xmlgraphics/fop/branches/maven/src/java/org/apache/fop/apps/FOUserAgent.java (original)
+++ xmlgraphics/fop/branches/maven/src/java/org/apache/fop/apps/FOUserAgent.java Thu Mar  3 09:40:50 2016
@@ -134,6 +134,7 @@ public class FOUserAgent {
     protected String keywords;
 
     private final ImageSessionContext imageSessionContext;
+    private final SoftMapCache pdfObjectCache = new SoftMapCache(true);
 
     /**
      * Main constructor. <b>This constructor should not be called directly. Please use the
@@ -807,6 +808,6 @@ public class FOUserAgent {
     }
 
     public SoftMapCache getPDFObjectCache() {
-        return factory.getPDFObjectCache();
+        return pdfObjectCache;
     }
 }

Modified: xmlgraphics/fop/branches/maven/src/java/org/apache/fop/apps/FopFactory.java
URL: http://svn.apache.org/viewvc/xmlgraphics/fop/branches/maven/src/java/org/apache/fop/apps/FopFactory.java?rev=1733431&r1=1733430&r2=1733431&view=diff
==============================================================================
--- xmlgraphics/fop/branches/maven/src/java/org/apache/fop/apps/FopFactory.java (original)
+++ xmlgraphics/fop/branches/maven/src/java/org/apache/fop/apps/FopFactory.java Thu Mar  3 09:40:50 2016
@@ -37,7 +37,6 @@ import org.apache.commons.logging.LogFac
 import org.apache.xmlgraphics.image.loader.ImageContext;
 import org.apache.xmlgraphics.image.loader.ImageManager;
 import org.apache.xmlgraphics.image.loader.impl.AbstractImageSessionContext.FallbackResolver;
-import org.apache.xmlgraphics.image.loader.util.SoftMapCache;
 import org.apache.xmlgraphics.util.UnitConv;
 
 import org.apache.fop.apps.io.InternalResourceResolver;
@@ -83,8 +82,6 @@ public final class FopFactory implements
 
     private final ColorSpaceCache colorSpaceCache;
 
-    private final SoftMapCache pdfObjectCache = new SoftMapCache(true);
-
     private final FopFactoryConfig config;
 
     private final InternalResourceResolver resolver;
@@ -436,8 +433,4 @@ public final class FopFactory implements
     public ColorSpaceCache getColorSpaceCache() {
         return this.colorSpaceCache;
     }
-
-    public SoftMapCache getPDFObjectCache() {
-        return pdfObjectCache;
-    }
 }

Modified: xmlgraphics/fop/branches/maven/src/java/org/apache/fop/area/BodyRegion.java
URL: http://svn.apache.org/viewvc/xmlgraphics/fop/branches/maven/src/java/org/apache/fop/area/BodyRegion.java?rev=1733431&r1=1733430&r2=1733431&view=diff
==============================================================================
--- xmlgraphics/fop/branches/maven/src/java/org/apache/fop/area/BodyRegion.java (original)
+++ xmlgraphics/fop/branches/maven/src/java/org/apache/fop/area/BodyRegion.java Thu Mar  3 09:40:50 2016
@@ -81,6 +81,15 @@ public class BodyRegion extends RegionRe
         return this.columnGap;
     }
 
+    int getContentIPD() {
+        RegionViewport rv = getRegionViewport();
+        return getIPD() - rv.getBorderAndPaddingWidthStart() - rv.getBorderAndPaddingWidthEnd();
+    }
+
+    public int getColumnIPD() {
+        return (getContentIPD() - (columnCount - 1) * columnGap) / columnCount;
+    }
+
     /**
      * Get the main reference area.
      *

Modified: xmlgraphics/fop/branches/maven/src/java/org/apache/fop/area/MainReference.java
URL: http://svn.apache.org/viewvc/xmlgraphics/fop/branches/maven/src/java/org/apache/fop/area/MainReference.java?rev=1733431&r1=1733430&r2=1733431&view=diff
==============================================================================
--- xmlgraphics/fop/branches/maven/src/java/org/apache/fop/area/MainReference.java (original)
+++ xmlgraphics/fop/branches/maven/src/java/org/apache/fop/area/MainReference.java Thu Mar  3 09:40:50 2016
@@ -59,12 +59,8 @@ public class MainReference extends Area
             //Remove the current one if it is empty
             spanAreas.remove(spanAreas.size() - 1);
         }
-        RegionViewport rv = parent.getRegionViewport();
-        int ipdWidth = parent.getIPD()
-            - rv.getBorderAndPaddingWidthStart() - rv.getBorderAndPaddingWidthEnd();
-
         Span newSpan = new Span(((spanAll) ? 1 : getColumnCount()),
-                getColumnGap(), ipdWidth);
+                getColumnGap(), parent.getContentIPD());
         spanAreas.add(newSpan);
         return getCurrentSpan();
     }

Modified: xmlgraphics/fop/branches/maven/src/java/org/apache/fop/fo/FONode.java
URL: http://svn.apache.org/viewvc/xmlgraphics/fop/branches/maven/src/java/org/apache/fop/fo/FONode.java?rev=1733431&r1=1733430&r2=1733431&view=diff
==============================================================================
--- xmlgraphics/fop/branches/maven/src/java/org/apache/fop/fo/FONode.java (original)
+++ xmlgraphics/fop/branches/maven/src/java/org/apache/fop/fo/FONode.java Thu Mar  3 09:40:50 2016
@@ -20,7 +20,6 @@
 package org.apache.fop.fo;
 
 // Java
-import java.util.Iterator;
 import java.util.ListIterator;
 import java.util.Map;
 import java.util.Stack;
@@ -321,9 +320,9 @@ public abstract class FONode implements
      * has been reached.
      * The default implementation simply calls {@link #finalizeNode()}, without
      * sending any event to the {@link FOEventHandler}.
-     * <br/><i>Note: the recommended way to override this method in subclasses is</i>
-     * <br/><br/><code>super.endOfNode(); // invoke finalizeNode()
-     * <br/>getFOEventHandler().endXXX(); // send endOfNode() notification</code>
+     * <p><i>Note: the recommended way to override this method in subclasses is</i></p>
+     * <p><code>super.endOfNode(); // invoke finalizeNode()</code></p>
+     * <p><code>getFOEventHandler().endXXX(); // send endOfNode() notification</code></p>
      *
      * @throws FOPException if there's a problem during processing
      */
@@ -622,7 +621,7 @@ public abstract class FONode implements
      *
      * @param propertyName the name of the property.
      * @param propertyValue the value of the property.
-     * * @param e optional property parsing exception.
+     * @param e optional property parsing exception.
      * @throws ValidationException the validation error provoked by the method call
      */
     protected void invalidPropertyValueError(String propertyName, String propertyValue, Exception e)
@@ -936,7 +935,7 @@ public abstract class FONode implements
      * @param ranges a stack of delimited text ranges
      * @return the (possibly) updated stack of delimited text ranges
      */
-    public Stack collectDelimitedTextRanges(Stack<DelimitedTextRange> ranges) {
+    public Stack<DelimitedTextRange> collectDelimitedTextRanges(Stack<DelimitedTextRange> ranges) {
         // if boundary before, then push new range
         if (isRangeBoundaryBefore()) {
             maybeNewRange(ranges);
@@ -965,9 +964,11 @@ public abstract class FONode implements
      * @param currentRange the current range or null (if none)
      * @return the (possibly) updated stack of delimited text ranges
      */
-    protected Stack collectDelimitedTextRanges(Stack<DelimitedTextRange> ranges, DelimitedTextRange currentRange) {
-        for (Iterator it = getChildNodes(); (it != null) && it.hasNext();) {
-            ranges = ((FONode) it.next()).collectDelimitedTextRanges(ranges);
+    protected Stack<DelimitedTextRange> collectDelimitedTextRanges(
+            Stack<DelimitedTextRange> ranges, DelimitedTextRange currentRange) {
+
+        for (FONodeIterator it = getChildNodes(); (it != null) && it.hasNext();) {
+            ranges = it.next().collectDelimitedTextRanges(ranges);
         }
         return ranges;
     }
@@ -1011,33 +1012,55 @@ public abstract class FONode implements
     }
 
     /**
-     * Base iterator interface over a FO's children
+     * Base iterator interface over a FO's children, offering three methods on top of the base interface
+     * methods {@see java.util.ListIterator}.
      */
-    public interface FONodeIterator extends ListIterator {
+    public interface FONodeIterator extends ListIterator<FONode> {
+
+        /** @return the next node */
+        FONode next();
+
+        /** @return the previous node */
+        FONode previous();
 
         /**
-         * Returns the parent node for this iterator's list
-         * of child nodes
+         * Replace the node at the current index with the given <code>newNode</code>.
          *
-         * @return  the parent node
+         * @param newNode the new node
          */
-        FObj parentNode();
+        void set(FONode newNode);
 
         /**
-         * Convenience method with return type of FONode
-         * (semantically equivalent to: <code>(FONode) next();</code>)
+         * Add the given <code>newNode</code> at the current position.
          *
-         * @return the next node (if any), as a type FONode
+         * @param newNode the new node
+         */
+        void add(FONode newNode);
+
+        /** @return <code>true</code> if there is a next node, <code>false</code> otherwise */
+        boolean hasNext();
+
+        /** @return <code>true</code> if there is a previous node, <code>false</code> otherwise */
+        boolean hasPrevious();
+
+        /** @return the current index */
+        int nextIndex();
+
+        /** @return the previous index */
+        int previousIndex();
+
+        /**
+         * Removes the node at the current position.
          */
-        FONode nextNode();
+        void remove();
 
         /**
-         * Convenience method with return type of FONode
-         * (semantically equivalent to: <code>(FONode) previous();</code>)
+         * Returns the parent node for this iterator's list
+         * of child nodes
          *
-         * @return the previous node (if any), as a type FONode
+         * @return  the parent node
          */
-        FONode previousNode();
+        FObj parent();
 
         /**
          * Returns the first node in the list, and decreases the index,
@@ -1046,7 +1069,7 @@ public abstract class FONode implements
          *
          * @return the first node in the list
          */
-        FONode firstNode();
+        FONode first();
 
         /**
          * Returns the last node in the list, and advances the
@@ -1055,7 +1078,7 @@ public abstract class FONode implements
          *
          * @return the last node in the list
          */
-        FONode lastNode();
+        FONode last();
 
     }
 

Modified: xmlgraphics/fop/branches/maven/src/java/org/apache/fop/fo/FObj.java
URL: http://svn.apache.org/viewvc/xmlgraphics/fop/branches/maven/src/java/org/apache/fop/fo/FObj.java?rev=1733431&r1=1733430&r2=1733431&view=diff
==============================================================================
--- xmlgraphics/fop/branches/maven/src/java/org/apache/fop/fo/FObj.java (original)
+++ xmlgraphics/fop/branches/maven/src/java/org/apache/fop/fo/FObj.java Thu Mar  3 09:40:50 2016
@@ -21,9 +21,7 @@ package org.apache.fop.fo;
 
 import java.util.Collections;
 import java.util.HashMap;
-import java.util.Iterator;
 import java.util.List;
-import java.util.ListIterator;
 import java.util.Map;
 import java.util.Map.Entry;
 import java.util.NoSuchElementException;
@@ -37,7 +35,6 @@ import org.apache.xmlgraphics.util.QName
 import org.apache.fop.apps.FOPException;
 import org.apache.fop.fo.extensions.ExtensionAttachment;
 import org.apache.fop.fo.flow.Marker;
-import org.apache.fop.fo.flow.table.TableCell;
 import org.apache.fop.fo.properties.Property;
 import org.apache.fop.fo.properties.PropertyMaker;
 
@@ -198,7 +195,7 @@ public abstract class FObj extends FONod
      */
     private void checkId(String id) throws ValidationException {
         if (!inMarker() && !id.equals("")) {
-            Set idrefs = getBuilderContext().getIDReferences();
+            Set<String> idrefs = getBuilderContext().getIDReferences();
             if (!idrefs.contains(id)) {
                 idrefs.add(id);
             } else {
@@ -270,7 +267,7 @@ public abstract class FObj extends FONod
             if (firstChild != null) {
                 firstChild.siblings[0] = null;
             }
-        } else {
+        } else if (child.siblings != null) {
             FONode prevChild = child.siblings[0];
             prevChild.siblings[1] = nextChild;
             if (nextChild != null) {
@@ -328,7 +325,7 @@ public abstract class FObj extends FONod
      * at the passed-in node (= first call to iterator.next() will
      * return childNode)
      * @param childNode First node in the iterator
-     * @return A ListIterator or null if childNode isn't a child of
+     * @return A FONodeIterator or null if childNode isn't a child of
      * this FObj.
      */
     public FONodeIterator getChildNodes(FONode childNode) {
@@ -338,7 +335,7 @@ public abstract class FObj extends FONod
                 return it;
             } else {
                 while (it.hasNext()
-                        && it.nextNode().siblings[1] != childNode) {
+                        && it.next().siblings[1] != childNode) {
                     //nop
                 }
                 if (it.hasNext()) {
@@ -373,8 +370,8 @@ public abstract class FObj extends FONod
         String mcname = marker.getMarkerClassName();
         if (firstChild != null) {
             // check for empty childNodes
-            for (Iterator iter = getChildNodes(); iter.hasNext();) {
-                FONode node = (FONode) iter.next();
+            for (FONodeIterator iter = getChildNodes(); iter.hasNext();) {
+                FONode node = iter.next();
                 if (node instanceof FObj
                         || (node instanceof FOText
                                 && ((FOText) node).willCreateArea())) {
@@ -414,7 +411,7 @@ public abstract class FObj extends FONod
 
     /** {@inheritDoc} */
     protected String getContextInfoAlt() {
-        StringBuffer sb = new StringBuffer();
+        StringBuilder sb = new StringBuilder();
         if (getLocalName() != null) {
             sb.append(getName());
             sb.append(", ");
@@ -444,13 +441,13 @@ public abstract class FObj extends FONod
         if (getLocator() != null) {
             return super.gatherContextInfo();
         } else {
-            ListIterator iter = getChildNodes();
+            FONodeIterator iter = getChildNodes();
             if (iter == null) {
                 return null;
             }
-            StringBuffer sb = new StringBuffer();
+            StringBuilder sb = new StringBuilder();
             while (iter.hasNext()) {
-                FONode node = (FONode) iter.next();
+                FONode node = iter.next();
                 String s = node.gatherContextInfo();
                 if (s != null) {
                     if (sb.length() > 0) {
@@ -466,7 +463,7 @@ public abstract class FObj extends FONod
     /**
      * Convenience method for validity checking.  Checks if the
      * incoming node is a member of the "%block;" parameter entity
-     * as defined in Sect. 6.2 of the XSL 1.0 & 1.1 Recommendations
+     * as defined in Sect. 6.2 of the XSL 1.0 &amp; 1.1 Recommendations
      *
      * @param nsURI namespace URI of incoming node
      * @param lName local name (i.e., no prefix) of incoming node
@@ -486,7 +483,7 @@ public abstract class FObj extends FONod
     /**
      * Convenience method for validity checking.  Checks if the
      * incoming node is a member of the "%inline;" parameter entity
-     * as defined in Sect. 6.2 of the XSL 1.0 & 1.1 Recommendations
+     * as defined in Sect. 6.2 of the XSL 1.0 &amp; 1.1 Recommendations
      *
      * @param nsURI namespace URI of incoming node
      * @param lName local name (i.e., no prefix) of incoming node
@@ -528,7 +525,7 @@ public abstract class FObj extends FONod
     /**
      * Convenience method for validity checking.  Checks if the
      * incoming node is a member of the neutral item list
-     * as defined in Sect. 6.2 of the XSL 1.0 & 1.1 Recommendations
+     * as defined in Sect. 6.2 of the XSL 1.0 &amp; 1.1 Recommendations
      * @param nsURI namespace URI of incoming node
      * @param lName local name (i.e., no prefix) of incoming node
      * @return true if a member, false if not
@@ -554,11 +551,6 @@ public abstract class FObj extends FONod
         int found = 1;
         FONode temp = getParent();
         while (temp != null) {
-            if (temp instanceof TableCell && (ancestorID == FO_TABLE_HEADER || ancestorID == FO_TABLE_FOOTER)) {
-                // note that if the retrieve-table-marker is not in a table-header/footer an exception is
-                // thrown, so no need to reset this flag in that case
-                ((TableCell) temp).flagAsHavingRetrieveTableMarker();
-            }
             if (temp.getNameId() == ancestorID) {
                 return found;
             }
@@ -619,16 +611,16 @@ public abstract class FObj extends FONod
      * @param bidiLevel a non-negative bidi embedding level
      */
     public void setBidiLevel(int bidiLevel) {
+
         assert bidiLevel >= 0;
-        if (bidiLevel >= 0) {
-            if ((this.bidiLevel < 0) || (bidiLevel < this.bidiLevel)) {
-                this.bidiLevel = bidiLevel;
-                if ((parent != null) && !isBidiPropagationBoundary()) {
-                    FObj foParent = (FObj) parent;
-                    int parentBidiLevel = foParent.getBidiLevel();
-                    if ((parentBidiLevel < 0) || (bidiLevel < parentBidiLevel)) {
-                        foParent.setBidiLevel(bidiLevel);
-                    }
+
+        if ((this.bidiLevel < 0) || (bidiLevel < this.bidiLevel)) {
+            this.bidiLevel = bidiLevel;
+            if ((parent != null) && !isBidiPropagationBoundary()) {
+                FObj foParent = (FObj) parent;
+                int parentBidiLevel = foParent.getBidiLevel();
+                if ((parentBidiLevel < 0) || (bidiLevel < parentBidiLevel)) {
+                    foParent.setBidiLevel(bidiLevel);
                 }
             }
         }
@@ -765,12 +757,12 @@ public abstract class FObj extends FONod
         }
 
         /** {@inheritDoc} */
-        public FObj parentNode() {
+        public FObj parent() {
             return parentNode;
         }
 
         /** {@inheritDoc} */
-        public Object next() {
+        public FONode next() {
             if (currentNode != null) {
                 if (currentIndex != 0) {
                     if (currentNode.siblings != null
@@ -789,7 +781,7 @@ public abstract class FObj extends FONod
         }
 
         /** {@inheritDoc} */
-        public Object previous() {
+        public FONode previous() {
             if (currentNode.siblings != null
                     && currentNode.siblings[0] != null) {
                 currentIndex--;
@@ -802,9 +794,8 @@ public abstract class FObj extends FONod
         }
 
         /** {@inheritDoc} */
-        public void set(Object o) {
+        public void set(FONode newNode) {
             if ((flags & F_SET_ALLOWED) == F_SET_ALLOWED) {
-                FONode newNode = (FONode) o;
                 if (currentNode == parentNode.firstChild) {
                     parentNode.firstChild = newNode;
                 } else {
@@ -823,8 +814,7 @@ public abstract class FObj extends FONod
         }
 
         /** {@inheritDoc} */
-        public void add(Object o) {
-            FONode newNode = (FONode) o;
+        public void add(FONode newNode) {
             if (currentIndex == -1) {
                 if (currentNode != null) {
                     FONode.attachSiblings(newNode, currentNode);
@@ -838,9 +828,9 @@ public abstract class FObj extends FONod
             } else {
                 if (currentNode.siblings != null
                         && currentNode.siblings[1] != null) {
-                    FONode.attachSiblings((FONode) o, currentNode.siblings[1]);
+                    FONode.attachSiblings(newNode, currentNode.siblings[1]);
                 }
-                FONode.attachSiblings(currentNode, (FONode) o);
+                FONode.attachSiblings(currentNode, newNode);
                 if (currentNode == parentNode.lastChild) {
                     parentNode.lastChild = newNode;
                 }
@@ -894,7 +884,7 @@ public abstract class FObj extends FONod
         }
 
         /** {@inheritDoc} */
-        public FONode lastNode() {
+        public FONode last() {
             while (currentNode != null
                     && currentNode.siblings != null
                     && currentNode.siblings[1] != null) {
@@ -905,20 +895,10 @@ public abstract class FObj extends FONod
         }
 
         /** {@inheritDoc} */
-        public FONode firstNode() {
+        public FONode first() {
             currentNode = parentNode.firstChild;
             currentIndex = 0;
             return currentNode;
         }
-
-        /** {@inheritDoc} */
-        public FONode nextNode() {
-            return (FONode) next();
-        }
-
-        /** {@inheritDoc} */
-        public FONode previousNode() {
-            return (FONode) previous();
-        }
     }
 }

Modified: xmlgraphics/fop/branches/maven/src/java/org/apache/fop/fo/FObjMixed.java
URL: http://svn.apache.org/viewvc/xmlgraphics/fop/branches/maven/src/java/org/apache/fop/fo/FObjMixed.java?rev=1733431&r1=1733430&r2=1733431&view=diff
==============================================================================
--- xmlgraphics/fop/branches/maven/src/java/org/apache/fop/fo/FObjMixed.java (original)
+++ xmlgraphics/fop/branches/maven/src/java/org/apache/fop/fo/FObjMixed.java Thu Mar  3 09:40:50 2016
@@ -149,7 +149,7 @@ public abstract class FObjMixed extends
                     = this.getChildNodes(this.currentTextNode);
             FONode node;
             while (nodeIter.hasNext()) {
-                node = nodeIter.nextNode();
+                node = nodeIter.next();
                 assert (node instanceof FOText
                         || node.getNameId() == FO_CHARACTER);
                 if (node.getNameId() == FO_CHARACTER) {

Modified: xmlgraphics/fop/branches/maven/src/java/org/apache/fop/fo/flow/AbstractGraphics.java
URL: http://svn.apache.org/viewvc/xmlgraphics/fop/branches/maven/src/java/org/apache/fop/fo/flow/AbstractGraphics.java?rev=1733431&r1=1733430&r2=1733431&view=diff
==============================================================================
--- xmlgraphics/fop/branches/maven/src/java/org/apache/fop/fo/flow/AbstractGraphics.java (original)
+++ xmlgraphics/fop/branches/maven/src/java/org/apache/fop/fo/flow/AbstractGraphics.java Thu Mar  3 09:40:50 2016
@@ -61,7 +61,6 @@ public abstract class AbstractGraphics e
     private int displayAlign;
     private int dominantBaseline;
     private Length height;
-    private String id;
     private LengthRangeProperty inlineProgressionDimension;
     private KeepProperty keepWithNext;
     private KeepProperty keepWithPrevious;
@@ -92,6 +91,7 @@ public abstract class AbstractGraphics e
 
     /** {@inheritDoc} */
     public void bind(PropertyList pList) throws FOPException {
+        super.bind(pList);
         commonAccessibility = CommonAccessibility.getInstance(pList);
         commonBorderPaddingBackground = pList.getBorderPaddingBackgroundProps();
         alignmentAdjust = pList.get(PR_ALIGNMENT_ADJUST).getLength();
@@ -104,7 +104,6 @@ public abstract class AbstractGraphics e
         displayAlign = pList.get(PR_DISPLAY_ALIGN).getEnum();
         dominantBaseline = pList.get(PR_DOMINANT_BASELINE).getEnum();
         height = pList.get(PR_HEIGHT).getLength();
-        id = pList.get(PR_ID).getString();
         inlineProgressionDimension = pList.get(PR_INLINE_PROGRESSION_DIMENSION).getLengthRange();
         keepWithNext = pList.get(PR_KEEP_WITH_NEXT).getKeep();
         keepWithPrevious = pList.get(PR_KEEP_WITH_PREVIOUS).getKeep();
@@ -126,13 +125,6 @@ public abstract class AbstractGraphics e
         return commonAccessibility;
     }
 
-    /**
-     * @return the "id" property.
-     */
-    public String getId() {
-        return id;
-    }
-
     /** @return the {@link CommonBorderPaddingBackground} */
     public CommonBorderPaddingBackground getCommonBorderPaddingBackground() {
         return commonBorderPaddingBackground;

Modified: xmlgraphics/fop/branches/maven/src/java/org/apache/fop/fo/flow/RetrieveTableMarker.java
URL: http://svn.apache.org/viewvc/xmlgraphics/fop/branches/maven/src/java/org/apache/fop/fo/flow/RetrieveTableMarker.java?rev=1733431&r1=1733430&r2=1733431&view=diff
==============================================================================
--- xmlgraphics/fop/branches/maven/src/java/org/apache/fop/fo/flow/RetrieveTableMarker.java (original)
+++ xmlgraphics/fop/branches/maven/src/java/org/apache/fop/fo/flow/RetrieveTableMarker.java Thu Mar  3 09:40:50 2016
@@ -25,6 +25,7 @@ import org.xml.sax.Locator;
 import org.apache.fop.apps.FOPException;
 import org.apache.fop.fo.FONode;
 import org.apache.fop.fo.PropertyList;
+import org.apache.fop.fo.flow.table.TableCell;
 
 /**
  * Class modelling the <a href="http://www.w3.org/TR/xsl/#fo_retrieve-table-marker">
@@ -81,6 +82,33 @@ public class RetrieveTableMarker extends
     }
 
     /**
+     * Overridden to flag the ancestor table-cell.
+     *
+     * @param ancestorID    ID of node name to check for (e.g., FO_ROOT)
+     * @return number of levels above FO where ancestor exists,
+     *         -1 if not found
+     */
+    @Override
+    protected int findAncestor(int ancestorID) {
+        int found = 1;
+        FONode temp = getParent();
+        while (temp != null) {
+            if (temp instanceof TableCell
+                    && (ancestorID == FO_TABLE_HEADER || ancestorID == FO_TABLE_FOOTER)) {
+                // note that if the retrieve-table-marker is not in a table-header/footer an exception is
+                // thrown, so no need to reset this flag in that case
+                ((TableCell) temp).flagAsHavingRetrieveTableMarker();
+            }
+            if (temp.getNameId() == ancestorID) {
+                return found;
+            }
+            found += 1;
+            temp = temp.getParent();
+        }
+        return -1;
+    }
+
+    /**
      * Return the value for the <code>retrieve-position-within-table</code>
      * property
      * @return  the value for retrieve-position-within-table; one of

Modified: xmlgraphics/fop/branches/maven/src/java/org/apache/fop/fo/pagination/Declarations.java
URL: http://svn.apache.org/viewvc/xmlgraphics/fop/branches/maven/src/java/org/apache/fop/fo/pagination/Declarations.java?rev=1733431&r1=1733430&r2=1733431&view=diff
==============================================================================
--- xmlgraphics/fop/branches/maven/src/java/org/apache/fop/fo/pagination/Declarations.java (original)
+++ xmlgraphics/fop/branches/maven/src/java/org/apache/fop/fo/pagination/Declarations.java Thu Mar  3 09:40:50 2016
@@ -78,7 +78,7 @@ public class Declarations extends FObj {
     public void endOfNode() throws FOPException {
         if (firstChild != null) {
             for (FONodeIterator iter = getChildNodes(); iter.hasNext();) {
-                FONode node = iter.nextNode();
+                FONode node = iter.next();
                 if (node.getName().equals("fo:color-profile")) {
                     ColorProfile cp = (ColorProfile)node;
                     if (!"".equals(cp.getColorProfileName())) {

Modified: xmlgraphics/fop/branches/maven/src/java/org/apache/fop/fo/pagination/PageSequence.java
URL: http://svn.apache.org/viewvc/xmlgraphics/fop/branches/maven/src/java/org/apache/fop/fo/pagination/PageSequence.java?rev=1733431&r1=1733430&r2=1733431&view=diff
==============================================================================
--- xmlgraphics/fop/branches/maven/src/java/org/apache/fop/fo/pagination/PageSequence.java (original)
+++ xmlgraphics/fop/branches/maven/src/java/org/apache/fop/fo/pagination/PageSequence.java Thu Mar  3 09:40:50 2016
@@ -454,4 +454,14 @@ public class PageSequence extends Abstra
         this.flowMap.clear();
     }
 
+    public SimplePageMaster getLastSimplePageMaster(int page, boolean isFirstPage, boolean isBlank) {
+        boolean isOddPage = ((page % 2) != 0); // please findbugs...
+        log.debug("getNextSimplePageMaster(page=" + page + " isOdd=" + isOddPage + " isFirst="
+                + isFirstPage + " isLast=true" + " isBlank=" + isBlank + ")");
+        if (pageSequenceMaster == null) {
+            return simplePageMaster;
+        }
+        return pageSequenceMaster.getLastSimplePageMaster(isOddPage, isFirstPage, isBlank, getMainFlow()
+                .getFlowName());
+    }
 }

Modified: xmlgraphics/fop/branches/maven/src/java/org/apache/fop/fo/pagination/PageSequenceMaster.java
URL: http://svn.apache.org/viewvc/xmlgraphics/fop/branches/maven/src/java/org/apache/fop/fo/pagination/PageSequenceMaster.java?rev=1733431&r1=1733430&r2=1733431&view=diff
==============================================================================
--- xmlgraphics/fop/branches/maven/src/java/org/apache/fop/fo/pagination/PageSequenceMaster.java (original)
+++ xmlgraphics/fop/branches/maven/src/java/org/apache/fop/fo/pagination/PageSequenceMaster.java Thu Mar  3 09:40:50 2016
@@ -254,6 +254,24 @@ public class PageSequenceMaster extends
         return FO_PAGE_SEQUENCE_MASTER;
     }
 
+    public SimplePageMaster getLastSimplePageMaster(boolean isOddPage, boolean isFirstPage, boolean isBlank,
+            String flowName) {
+        if (currentSubSequence == null) {
+            currentSubSequence = getNextSubSequence();
+            if (currentSubSequence == null) {
+                blockLevelEventProducer.missingSubsequencesInPageSequenceMaster(this, masterName,
+                        getLocator());
+            }
+            if (currentSubSequence.isInfinite() && !currentSubSequence.canProcess(flowName)) {
+                throw new PageProductionException(
+                        "The current sub-sequence will not terminate whilst processing the main flow");
+            }
+        }
+
+        SimplePageMaster pageMaster = currentSubSequence.getLastPageMaster(isOddPage, isFirstPage, isBlank,
+                blockLevelEventProducer);
+        return pageMaster;
+    }
 
 }
 

Modified: xmlgraphics/fop/branches/maven/src/java/org/apache/fop/fo/pagination/RepeatablePageMasterAlternatives.java
URL: http://svn.apache.org/viewvc/xmlgraphics/fop/branches/maven/src/java/org/apache/fop/fo/pagination/RepeatablePageMasterAlternatives.java?rev=1733431&r1=1733430&r2=1733431&view=diff
==============================================================================
--- xmlgraphics/fop/branches/maven/src/java/org/apache/fop/fo/pagination/RepeatablePageMasterAlternatives.java (original)
+++ xmlgraphics/fop/branches/maven/src/java/org/apache/fop/fo/pagination/RepeatablePageMasterAlternatives.java Thu Mar  3 09:40:50 2016
@@ -31,6 +31,7 @@ import org.apache.fop.fo.FObj;
 import org.apache.fop.fo.PropertyList;
 import org.apache.fop.fo.ValidationException;
 import org.apache.fop.fo.properties.Property;
+import org.apache.fop.layoutmgr.BlockLevelEventProducer;
 
 /**
  * Class modelling the <a href="http://www.w3.org/TR/xsl/#fo_repeatable-page-master-alternatives">
@@ -136,6 +137,22 @@ public class RepeatablePageMasterAlterna
         return null;
     }
 
+    public SimplePageMaster getLastPageMaster(boolean isOddPage, boolean isFirstPage, boolean isBlankPage,
+                                              BlockLevelEventProducer blockLevelEventProducer) {
+        for (ConditionalPageMasterReference cpmr : conditionalPageMasterRefs) {
+            if (cpmr.isValid(isOddPage, isFirstPage, true, isBlankPage)) {
+                return cpmr.getMaster();
+            }
+        }
+        blockLevelEventProducer.lastPageMasterReferenceMissing(this, getLocator());
+        for (ConditionalPageMasterReference cpmr : conditionalPageMasterRefs) {
+            if (cpmr.isValid(isOddPage, isFirstPage, false, isBlankPage)) {
+                return cpmr.getMaster();
+            }
+        }
+        throw new PageProductionException("Last page master not found: oddpage=" + isOddPage
+                + " firstpage=" + isFirstPage + " blankpage=" + isBlankPage);
+    }
 
     /**
      * Adds a new conditional page master reference.

Modified: xmlgraphics/fop/branches/maven/src/java/org/apache/fop/fo/pagination/RepeatablePageMasterReference.java
URL: http://svn.apache.org/viewvc/xmlgraphics/fop/branches/maven/src/java/org/apache/fop/fo/pagination/RepeatablePageMasterReference.java?rev=1733431&r1=1733430&r2=1733431&view=diff
==============================================================================
--- xmlgraphics/fop/branches/maven/src/java/org/apache/fop/fo/pagination/RepeatablePageMasterReference.java (original)
+++ xmlgraphics/fop/branches/maven/src/java/org/apache/fop/fo/pagination/RepeatablePageMasterReference.java Thu Mar  3 09:40:50 2016
@@ -101,6 +101,11 @@ public class RepeatablePageMasterReferen
         return master;
     }
 
+    public SimplePageMaster getLastPageMaster(boolean isOddPage, boolean isFirstPage, boolean isEmptyPage,
+                                              BlockLevelEventProducer blockLevelEventProducer) {
+        return getNextPageMaster(isOddPage, isFirstPage, true, isEmptyPage);
+    }
+
     /**
      * Get the value of the <code>maximum-repeats</code> property.
      * @return the "maximum-repeats" property

Modified: xmlgraphics/fop/branches/maven/src/java/org/apache/fop/fo/pagination/Root.java
URL: http://svn.apache.org/viewvc/xmlgraphics/fop/branches/maven/src/java/org/apache/fop/fo/pagination/Root.java?rev=1733431&r1=1733430&r2=1733431&view=diff
==============================================================================
--- xmlgraphics/fop/branches/maven/src/java/org/apache/fop/fo/pagination/Root.java (original)
+++ xmlgraphics/fop/branches/maven/src/java/org/apache/fop/fo/pagination/Root.java Thu Mar  3 09:40:50 2016
@@ -75,6 +75,16 @@ public class Root extends FObj implement
      */
     private FOEventHandler foEventHandler;
 
+    private PageSequence lastSeq;
+
+    public void setLastSeq(PageSequence seq) {
+        lastSeq = seq;
+    }
+
+    public PageSequence getLastSeq() {
+          return lastSeq;
+    }
+
     /**
      * Base constructor
      *

Modified: xmlgraphics/fop/branches/maven/src/java/org/apache/fop/fo/pagination/SinglePageMasterReference.java
URL: http://svn.apache.org/viewvc/xmlgraphics/fop/branches/maven/src/java/org/apache/fop/fo/pagination/SinglePageMasterReference.java?rev=1733431&r1=1733430&r2=1733431&view=diff
==============================================================================
--- xmlgraphics/fop/branches/maven/src/java/org/apache/fop/fo/pagination/SinglePageMasterReference.java (original)
+++ xmlgraphics/fop/branches/maven/src/java/org/apache/fop/fo/pagination/SinglePageMasterReference.java Thu Mar  3 09:40:50 2016
@@ -100,6 +100,11 @@ public class SinglePageMasterReference e
         }
     }
 
+    public SimplePageMaster getLastPageMaster(boolean isOddPage, boolean isFirstPage, boolean isBlankPage,
+                                              BlockLevelEventProducer blockLevelEventProducer) {
+        return getNextPageMaster(isOddPage, isFirstPage, true, isBlankPage);
+    }
+
     /** {@inheritDoc} */
     public void reset() {
         this.state = FIRST;

Modified: xmlgraphics/fop/branches/maven/src/java/org/apache/fop/fo/pagination/SubSequenceSpecifier.java
URL: http://svn.apache.org/viewvc/xmlgraphics/fop/branches/maven/src/java/org/apache/fop/fo/pagination/SubSequenceSpecifier.java?rev=1733431&r1=1733430&r2=1733431&view=diff
==============================================================================
--- xmlgraphics/fop/branches/maven/src/java/org/apache/fop/fo/pagination/SubSequenceSpecifier.java (original)
+++ xmlgraphics/fop/branches/maven/src/java/org/apache/fop/fo/pagination/SubSequenceSpecifier.java Thu Mar  3 09:40:50 2016
@@ -20,6 +20,7 @@
 package org.apache.fop.fo.pagination;
 
 import org.apache.fop.fo.ValidationException;
+import org.apache.fop.layoutmgr.BlockLevelEventProducer;
 
 /**
  * Classes that implement this interface can be added to a {@link PageSequenceMaster},
@@ -43,6 +44,10 @@ public interface SubSequenceSpecifier {
                                  boolean isBlankPage)
                                     throws PageProductionException;
 
+    SimplePageMaster getLastPageMaster(boolean isOddPage, boolean isFirstPage, boolean isBlankPage,
+                                       BlockLevelEventProducer blockLevelEventProducer)
+            throws PageProductionException;
+
     /**
      * Called before a new page sequence is rendered so subsequences can reset
      * any state they keep during the formatting process.

Modified: xmlgraphics/fop/branches/maven/src/java/org/apache/fop/layoutmgr/AbstractBreaker.java
URL: http://svn.apache.org/viewvc/xmlgraphics/fop/branches/maven/src/java/org/apache/fop/layoutmgr/AbstractBreaker.java?rev=1733431&r1=1733430&r2=1733431&view=diff
==============================================================================
--- xmlgraphics/fop/branches/maven/src/java/org/apache/fop/layoutmgr/AbstractBreaker.java (original)
+++ xmlgraphics/fop/branches/maven/src/java/org/apache/fop/layoutmgr/AbstractBreaker.java Thu Mar  3 09:40:50 2016
@@ -42,6 +42,10 @@ public abstract class AbstractBreaker {
     /** logging instance */
     protected static final Log log = LogFactory.getLog(AbstractBreaker.class);
 
+    private LayoutManager originalRestartAtLM;
+    private Position positionAtBreak;
+    private List firstElementsForRestart;
+
     /**
      * A page break position.
      */
@@ -408,17 +412,36 @@ public abstract class AbstractBreaker {
                 alg.setConstantLineWidth(flowBPD);
                 int optimalPageCount = alg.findBreakingPoints(blockList, 1, true,
                         BreakingAlgorithm.ALL_BREAKS);
-
+                boolean ipdChangesOnNextPage = (alg.getIPDdifference() != 0);
+                boolean onLastPageAndIPDChanges = false;
+                if (!ipdChangesOnNextPage) {
+                    onLastPageAndIPDChanges = (lastPageHasIPDChange() && !thereIsANonRestartableLM(alg)
+                            && (shouldRedoLayout() || (wasLayoutRedone() && optimalPageCount > 1)));
+                }
                 if (alg.handlingFloat()) {
                     nextSequenceStartsOn = handleFloatLayout(alg, optimalPageCount, blockList, childLC);
-                } else if (Math.abs(alg.getIPDdifference()) > 1) {
-                    addAreas(alg, optimalPageCount, blockList, blockList);
-                    // *** redo Phase 1 ***
-                    log.trace("IPD changes after page " + optimalPageCount);
+                } else if (ipdChangesOnNextPage || onLastPageAndIPDChanges) {
+                    boolean visitedBefore = false;
+                    if (onLastPageAndIPDChanges) {
+                        visitedBefore = wasLayoutRedone();
+                        prepareToRedoLayout(alg, optimalPageCount, blockList, blockList);
+                    }
+
+                    firstElementsForRestart = null;
+                    LayoutManager restartAtLM = getRestartAtLM(alg, ipdChangesOnNextPage, onLastPageAndIPDChanges,
+                            visitedBefore, blockList, 1);
+                    if (restartAtLM == null) {
+                        firstElementsForRestart = null;
+                        restartAtLM = getRestartAtLM(alg, ipdChangesOnNextPage, onLastPageAndIPDChanges,
+                                visitedBefore, blockList, 0);
+                    }
+                    if (ipdChangesOnNextPage) {
+                        addAreas(alg, optimalPageCount, blockList, blockList);
+                    }
                     blockLists.clear();
-                    nextSequenceStartsOn = getNextBlockListChangedIPD(childLC, alg,
-                                                                      blockList);
                     blockListIndex = -1;
+                    nextSequenceStartsOn = getNextBlockList(childLC, Constants.EN_COLUMN, positionAtBreak,
+                            restartAtLM, firstElementsForRestart);
                 } else {
                     log.debug("PLM> optimalPageCount= " + optimalPageCount
                             + " pageBreaks.size()= " + alg.getPageBreaks().size());
@@ -433,6 +456,92 @@ public abstract class AbstractBreaker {
         blockLists = null;
     }
 
+    private LayoutManager getRestartAtLM(PageBreakingAlgorithm alg, boolean ipdChangesOnNextPage,
+                                         boolean onLastPageAndIPDChanges, boolean visitedBefore,
+                                         BlockSequence blockList, int start) {
+        KnuthNode optimalBreak = ipdChangesOnNextPage ? alg.getBestNodeBeforeIPDChange() : alg
+                .getBestNodeForLastPage();
+        if (onLastPageAndIPDChanges && visitedBefore && this.originalRestartAtLM == null) {
+            optimalBreak = null;
+        }
+
+        int positionIndex = (optimalBreak != null) ? optimalBreak.position : start;
+        KnuthElement elementAtBreak = alg.getElement(positionIndex);
+        if (elementAtBreak.getPosition() == null) {
+            elementAtBreak = alg.getElement(0);
+        }
+        positionAtBreak = elementAtBreak.getPosition();
+        /* Retrieve the original position wrapped into this space position */
+        positionAtBreak = positionAtBreak.getPosition();
+        if (ipdChangesOnNextPage || (positionAtBreak != null && positionAtBreak.getIndex() > -1)) {
+            firstElementsForRestart = Collections.EMPTY_LIST;
+            if (ipdChangesOnNextPage) {
+                if (containsNonRestartableLM(positionAtBreak)) {
+                    if (alg.getIPDdifference() > 0) {
+                        EventBroadcaster eventBroadcaster = getCurrentChildLM().getFObj()
+                                .getUserAgent().getEventBroadcaster();
+                        BlockLevelEventProducer eventProducer = BlockLevelEventProducer.Provider
+                                .get(eventBroadcaster);
+                        eventProducer.nonRestartableContentFlowingToNarrowerPage(this);
+                    }
+                    firstElementsForRestart = new LinkedList();
+                    boolean boxFound = false;
+                    Iterator iter = blockList.listIterator(positionIndex + 1);
+                    Position position = null;
+                    while (iter.hasNext()
+                            && (position == null || containsNonRestartableLM(position))) {
+                        positionIndex++;
+                        KnuthElement element = (KnuthElement) iter.next();
+                        position = element.getPosition();
+                        if (element.isBox()) {
+                            boxFound = true;
+                            firstElementsForRestart.add(element);
+                        } else if (boxFound) {
+                            firstElementsForRestart.add(element);
+                        }
+                    }
+                    if (position instanceof SpaceResolver.SpaceHandlingBreakPosition) {
+                                    /* Retrieve the original position wrapped into this space position */
+                        positionAtBreak = position.getPosition();
+                    } else {
+                        positionAtBreak = null;
+                    }
+                }
+            }
+        }
+        LayoutManager restartAtLM = null;
+        if (ipdChangesOnNextPage || !(positionAtBreak != null && positionAtBreak.getIndex() > -1)) {
+            if (positionAtBreak != null && positionAtBreak.getIndex() == -1) {
+                Position position;
+                Iterator iter = blockList.listIterator(positionIndex + 1);
+                do {
+                    KnuthElement nextElement = (KnuthElement) iter.next();
+                    position = nextElement.getPosition();
+                } while (position == null
+                        || position instanceof SpaceResolver.SpaceHandlingPosition
+                        || position instanceof SpaceResolver.SpaceHandlingBreakPosition
+                        && position.getPosition().getIndex() == -1);
+                LayoutManager surroundingLM = positionAtBreak.getLM();
+                while (position.getLM() != surroundingLM) {
+                    position = position.getPosition();
+                }
+                restartAtLM = position.getPosition().getLM();
+            }
+            if (onLastPageAndIPDChanges && restartAtLM != null) {
+                if (originalRestartAtLM == null) {
+                    originalRestartAtLM = restartAtLM;
+                } else {
+                    restartAtLM = originalRestartAtLM;
+                }
+                firstElementsForRestart = Collections.EMPTY_LIST;
+            }
+        }
+        if (onLastPageAndIPDChanges && !visitedBefore && positionAtBreak.getPosition() != null) {
+            restartAtLM = positionAtBreak.getPosition().getLM();
+        }
+        return restartAtLM;
+    }
+
     /**
      * Returns {@code true} if the given position or one of its descendants
      * corresponds to a non-restartable LM.
@@ -709,84 +818,39 @@ public abstract class AbstractBreaker {
         return nextSequenceStartsOn;
     }
 
-    /**
-     * @param childLC LayoutContext to use
-     * @param alg the pagebreaking algorithm
-     * @param effectiveList the list of Knuth elements to be reused
-     * @return the page on which the next content should appear after a hard break
-     */
-    private int getNextBlockListChangedIPD(LayoutContext childLC, PageBreakingAlgorithm alg,
-                    BlockSequence effectiveList) {
-        int nextSequenceStartsOn;
-        KnuthNode optimalBreak = alg.getBestNodeBeforeIPDChange();
-        int positionIndex = optimalBreak.position;
-        log.trace("IPD changes at index " + positionIndex);
-        KnuthElement elementAtBreak = alg.getElement(positionIndex);
-        Position positionAtBreak = elementAtBreak.getPosition();
-        if (!(positionAtBreak instanceof SpaceResolver.SpaceHandlingBreakPosition)) {
-            throw new UnsupportedOperationException(
-                    "Don't know how to restart at position " + positionAtBreak);
-        }
-        /* Retrieve the original position wrapped into this space position */
-        positionAtBreak = positionAtBreak.getPosition();
-        LayoutManager restartAtLM = null;
-        List<KnuthElement> firstElements = Collections.emptyList();
-        if (containsNonRestartableLM(positionAtBreak)) {
-            if (alg.getIPDdifference() > 0) {
-                EventBroadcaster eventBroadcaster = getCurrentChildLM().getFObj()
-                        .getUserAgent().getEventBroadcaster();
-                BlockLevelEventProducer eventProducer
-                        = BlockLevelEventProducer.Provider.get(eventBroadcaster);
-                eventProducer.nonRestartableContentFlowingToNarrowerPage(this);
-            }
-            firstElements = new LinkedList<KnuthElement>();
-            boolean boxFound = false;
-            Iterator<KnuthElement> iter = effectiveList.listIterator(positionIndex + 1);
-            Position position = null;
-            while (iter.hasNext()
-                    && (position == null || containsNonRestartableLM(position))) {
-                positionIndex++;
-                KnuthElement element = iter.next();
-                position = element.getPosition();
-                if (element.isBox()) {
-                    boxFound = true;
-                    firstElements.add(element);
-                } else if (boxFound) {
-                    firstElements.add(element);
-                }
-            }
-            if (position instanceof SpaceResolver.SpaceHandlingBreakPosition) {
-                /* Retrieve the original position wrapped into this space position */
-                positionAtBreak = position.getPosition();
-            } else {
-                positionAtBreak = null;
-            }
-        }
-        if (positionAtBreak != null && positionAtBreak.getIndex() == -1) {
-            /*
-             * This is an indication that we are between two blocks
-             * (possibly surrounded by another block), not inside a
-             * paragraph.
-             */
-            Position position;
-            Iterator<KnuthElement> iter = effectiveList.listIterator(positionIndex + 1);
-            do {
-                KnuthElement nextElement = iter.next();
-                position = nextElement.getPosition();
-            } while (position == null
-                    || position instanceof SpaceResolver.SpaceHandlingPosition
-                    || position instanceof SpaceResolver.SpaceHandlingBreakPosition
-                        && position.getPosition().getIndex() == -1);
-            LayoutManager surroundingLM = positionAtBreak.getLM();
-            while (position.getLM() != surroundingLM) {
-                position = position.getPosition();
+    protected boolean shouldRedoLayout() {
+        return false;
+    }
+
+    protected void prepareToRedoLayout(PageBreakingAlgorithm alg, int partCount,
+            BlockSequence originalList, BlockSequence effectiveList) {
+        return;
+    }
+
+    protected boolean wasLayoutRedone() {
+        return false;
+    }
+
+    private boolean thereIsANonRestartableLM(PageBreakingAlgorithm alg) {
+        KnuthNode optimalBreak = alg.getBestNodeForLastPage();
+        if (optimalBreak != null) {
+            int positionIndex = optimalBreak.position;
+            KnuthElement elementAtBreak = alg.getElement(positionIndex);
+            Position positionAtBreak = elementAtBreak.getPosition();
+            if (!(positionAtBreak instanceof SpaceResolver.SpaceHandlingBreakPosition)) {
+                return false;
+            }
+            /* Retrieve the original position wrapped into this space position */
+            positionAtBreak = positionAtBreak.getPosition();
+            if (positionAtBreak != null && containsNonRestartableLM(positionAtBreak)) {
+                return true;
             }
-            restartAtLM = position.getPosition().getLM();
         }
+        return false;
+    }
 
-        nextSequenceStartsOn = getNextBlockList(childLC, Constants.EN_COLUMN,
-                positionAtBreak, restartAtLM, firstElements);
-        return nextSequenceStartsOn;
+    protected boolean lastPageHasIPDChange() {
+        return false;
     }
 
     protected int handleFloatLayout(PageBreakingAlgorithm alg, int optimalPageCount, BlockSequence blockList,

Modified: xmlgraphics/fop/branches/maven/src/java/org/apache/fop/layoutmgr/AbstractPageSequenceLayoutManager.java
URL: http://svn.apache.org/viewvc/xmlgraphics/fop/branches/maven/src/java/org/apache/fop/layoutmgr/AbstractPageSequenceLayoutManager.java?rev=1733431&r1=1733430&r2=1733431&view=diff
==============================================================================
--- xmlgraphics/fop/branches/maven/src/java/org/apache/fop/layoutmgr/AbstractPageSequenceLayoutManager.java (original)
+++ xmlgraphics/fop/branches/maven/src/java/org/apache/fop/layoutmgr/AbstractPageSequenceLayoutManager.java Thu Mar  3 09:40:50 2016
@@ -383,6 +383,11 @@ public abstract class AbstractPageSequen
         if (curPage != null) {
             finishPage();
         }
+
+        while (forcePageCount != Constants.EN_NO_FORCE && getCurrentPageNum() < getLastPageNumber()) {
+            curPage = makeNewPage(true);
+            finishPage();
+        }
     }
 
     /** {@inheritDoc} */
@@ -390,4 +395,7 @@ public abstract class AbstractPageSequen
         throw new IllegalStateException();
     }
 
+    protected int getLastPageNumber() {
+        return currentPageNum;
+    }
 }

Modified: xmlgraphics/fop/branches/maven/src/java/org/apache/fop/layoutmgr/BlockLevelEventProducer.java
URL: http://svn.apache.org/viewvc/xmlgraphics/fop/branches/maven/src/java/org/apache/fop/layoutmgr/BlockLevelEventProducer.java?rev=1733431&r1=1733430&r2=1733431&view=diff
==============================================================================
--- xmlgraphics/fop/branches/maven/src/java/org/apache/fop/layoutmgr/BlockLevelEventProducer.java (original)
+++ xmlgraphics/fop/branches/maven/src/java/org/apache/fop/layoutmgr/BlockLevelEventProducer.java Thu Mar  3 09:40:50 2016
@@ -202,4 +202,21 @@ public interface BlockLevelEventProducer
      * @event.severity WARN
      */
     void nonRestartableContentFlowingToNarrowerPage(Object source);
+
+    /**
+     * A feasible layout has reached the given number of parts (columns or pages).
+     *
+     * @param source the event source
+     * @param partCount the number of parts that the layout has reached
+     * @event.severity INFO
+     */
+    void layoutHasReachedParts(Object source, int partCount);
+
+    /**
+     * Last page master reference missing.
+     *
+     * @param source the event source
+     * @event.severity WARN
+     */
+    void lastPageMasterReferenceMissing(Object source, Locator loc);
 }

Modified: xmlgraphics/fop/branches/maven/src/java/org/apache/fop/layoutmgr/BlockLevelEventProducer.xml
URL: http://svn.apache.org/viewvc/xmlgraphics/fop/branches/maven/src/java/org/apache/fop/layoutmgr/BlockLevelEventProducer.xml?rev=1733431&r1=1733430&r2=1733431&view=diff
==============================================================================
--- xmlgraphics/fop/branches/maven/src/java/org/apache/fop/layoutmgr/BlockLevelEventProducer.xml (original)
+++ xmlgraphics/fop/branches/maven/src/java/org/apache/fop/layoutmgr/BlockLevelEventProducer.xml Thu Mar  3 09:40:50 2016
@@ -31,4 +31,6 @@
   <message key="missingSubsequencesInPageSequenceMaster">No subsequences in page-sequence-master "{pageSequenceMasterName}".{{locator}}</message>
   <message key="noMatchingPageMaster">No simple-page-master matching "{pageMasterName}" in page-sequence-master "{pageSequenceMasterName}".{{locator}}</message>
   <message key="nonRestartableContentFlowingToNarrowerPage">Content that cannot handle IPD changes is flowing to a narrower page. Part of it may be clipped by the page border.</message>
+  <message key="layoutHasReachedParts">A layout has reached {partCount} part(s).</message>
+  <message key="lastPageMasterReferenceMissing">page-position="last" master reference missing.{{locator}}</message>
 </catalogue>

Modified: xmlgraphics/fop/branches/maven/src/java/org/apache/fop/layoutmgr/PageBreaker.java
URL: http://svn.apache.org/viewvc/xmlgraphics/fop/branches/maven/src/java/org/apache/fop/layoutmgr/PageBreaker.java?rev=1733431&r1=1733430&r2=1733431&view=diff
==============================================================================
--- xmlgraphics/fop/branches/maven/src/java/org/apache/fop/layoutmgr/PageBreaker.java (original)
+++ xmlgraphics/fop/branches/maven/src/java/org/apache/fop/layoutmgr/PageBreaker.java Thu Mar  3 09:40:50 2016
@@ -51,6 +51,8 @@ public class PageBreaker extends Abstrac
     private PageProvider pageProvider;
     private Block separatorArea;
     private boolean spanAllActive;
+    private boolean layoutRedone;
+    private int previousIndex;
     private boolean handlingStartOfFloat;
     private boolean handlingEndOfFloat;
     private int floatHeight;
@@ -161,7 +163,7 @@ public class PageBreaker extends Abstrac
     /** {@inheritDoc} */
     protected int getNextBlockList(LayoutContext childLC, int nextSequenceStartsOn,
             Position positionAtIPDChange, LayoutManager restartLM, List firstElements) {
-        if (!handlingFloat()) {
+        if (!layoutRedone && !handlingFloat()) {
             if (!firstPart) {
                 // if this is the first page that will be created by
                 // the current BlockSequence, it could have a break
@@ -330,21 +332,55 @@ public class PageBreaker extends Abstrac
             return;
         }
 
-        boolean lastPageMasterDefined = pslm.getPageSequence().hasPagePositionLast()
-                || pslm.getPageSequence().hasPagePositionOnly() && pslm.isOnFirstPage(partCount - 1);
-        if (!hasMoreContent()) {
-            //last part is reached
-            if (lastPageMasterDefined) {
-                //last-page condition
-                redoLayout(alg, partCount, originalList, effectiveList);
-                return;
-            }
+        if (shouldRedoLayout(partCount)) {
+            redoLayout(alg, partCount, originalList, effectiveList);
+            return;
         }
 
         //nothing special: just add the areas now
         addAreas(alg, partCount, originalList, effectiveList);
     }
 
+    protected void prepareToRedoLayout(PageBreakingAlgorithm alg, int partCount,
+            BlockSequence originalList,
+            BlockSequence effectiveList) {
+        int newStartPos = 0;
+        int restartPoint = pageProvider.getStartingPartIndexForLastPage(partCount);
+        if (restartPoint > 0 && !layoutRedone) {
+            // Add definitive areas for the parts before the
+            // restarting point
+            addAreas(alg, restartPoint, originalList, effectiveList);
+            // Get page break from which we restart
+            PageBreakPosition pbp = alg.getPageBreaks().get(restartPoint - 1);
+            newStartPos = alg.par.getFirstBoxIndex(pbp.getLeafPos() + 1);
+            // Handle page break right here to avoid any side-effects
+            if (newStartPos > 0) {
+                handleBreakTrait(Constants.EN_PAGE);
+            }
+        }
+        pageBreakHandled = true;
+        // Update so the available BPD is reported correctly
+        int currentPageNum = pslm.getCurrentPageNum();
+        int currentColumn = pslm.getCurrentPV().getCurrentSpan().getCurrentFlowIndex();
+        pageProvider.setStartOfNextElementList(currentPageNum, currentColumn, spanAllActive);
+
+        // Make sure we only add the areas we haven't added already
+        effectiveList.ignoreAtStart = newStartPos;
+        if (!layoutRedone) {
+            // Handle special page-master for last page
+            setLastPageIndex(currentPageNum);
+//          BodyRegion lastBody = pageProvider.getPage(false, currentPageNum).getPageViewport().getBodyRegion();
+            pslm.setCurrentPage(pageProvider.getPage(false, currentPageNum));
+            previousIndex = pageProvider.getIndexOfCachedLastPage();
+        } else {
+            setLastPageIndex(currentPageNum + 1);
+//            pslm.setCurrentPage(previousPage);
+            pageProvider.discardCacheStartingWith(previousIndex);
+            pslm.setCurrentPage(pageProvider.getPage(false, currentPageNum));
+        }
+        layoutRedone = true;
+    }
+
     /**
      * Restart the algorithm at the break corresponding to the given partCount. Used to
      * re-do the part after the last break in case of either column-balancing or a last
@@ -565,6 +601,7 @@ public class PageBreaker extends Abstrac
             return;
         case Constants.EN_COLUMN:
         case Constants.EN_AUTO:
+        case Constants.EN_PAGE:
         case -1:
             PageViewport pv = curPage.getPageViewport();
 
@@ -580,26 +617,35 @@ public class PageBreaker extends Abstrac
                 log.trace("Forcing new page with span");
                 curPage = pslm.makeNewPage(false);
                 curPage.getPageViewport().createSpan(true);
-            } else if (pv.getCurrentSpan().hasMoreFlows()) {
-                log.trace("Moving to next flow");
-                pv.getCurrentSpan().moveToNextFlow();
             } else {
-                log.trace("Making new page");
-                /*curPage = */pslm.makeNewPage(false);
+                if (breakVal == Constants.EN_PAGE) {
+                    handleBreakBeforeFollowingPage(breakVal);
+                } else {
+                    if (pv.getCurrentSpan().hasMoreFlows()) {
+                        log.trace("Moving to next flow");
+                        pv.getCurrentSpan().moveToNextFlow();
+                    } else {
+                        log.trace("Making new page");
+                        pslm.makeNewPage(false);
+                    }
+                }
             }
             return;
-        case Constants.EN_PAGE:
         default:
-            log.debug("handling break-before after page " + pslm.getCurrentPageNum()
-                + " breakVal=" + getBreakClassName(breakVal));
-            if (needBlankPageBeforeNew(breakVal)) {
-                log.trace("Inserting blank page");
-                /*curPage = */pslm.makeNewPage(true);
-            }
-            if (needNewPage(breakVal)) {
-                log.trace("Making new page");
-                /*curPage = */pslm.makeNewPage(false);
-            }
+            handleBreakBeforeFollowingPage(breakVal);
+        }
+    }
+
+    private void handleBreakBeforeFollowingPage(int breakVal) {
+        log.debug("handling break-before after page " + pslm.getCurrentPageNum() + " breakVal="
+                + getBreakClassName(breakVal));
+        if (needBlankPageBeforeNew(breakVal)) {
+            log.trace("Inserting blank page");
+            /* curPage = */pslm.makeNewPage(true);
+        }
+        if (needNewPage(breakVal)) {
+            log.trace("Making new page");
+            /* curPage = */pslm.makeNewPage(false);
         }
     }
 
@@ -641,6 +687,36 @@ public class PageBreaker extends Abstrac
         }
     }
 
+    protected boolean shouldRedoLayout() {
+        return shouldRedoLayout(-1);
+    }
+
+    protected boolean shouldRedoLayout(int partCount) {
+        boolean lastPageMasterDefined = pslm.getPageSequence().hasPagePositionLast();
+        if (!lastPageMasterDefined && partCount != -1) {
+            lastPageMasterDefined = pslm.getPageSequence().hasPagePositionOnly() && pslm.isOnFirstPage(partCount - 1);
+        }
+        return (!hasMoreContent() && lastPageMasterDefined && !layoutRedone);
+    }
+
+    protected boolean wasLayoutRedone() {
+        return layoutRedone;
+    }
+
+    protected boolean lastPageHasIPDChange() {
+        boolean lastPageMasterDefined = pslm.getPageSequence().hasPagePositionLast();
+        boolean onlyPageMasterDefined = pslm.getPageSequence().hasPagePositionOnly();
+        if (lastPageMasterDefined && !onlyPageMasterDefined) {
+            // code not very robust and unable to handle situations were only and last are defined
+            int currentIPD = this.pageProvider.getCurrentIPD();
+            int lastPageIPD = this.pageProvider.getLastPageIPD();
+            if (lastPageIPD != -1 && currentIPD != lastPageIPD) {
+                return true;
+            }
+        }
+        return false;
+    }
+
     protected boolean handlingStartOfFloat() {
         return handlingStartOfFloat;
     }

Modified: xmlgraphics/fop/branches/maven/src/java/org/apache/fop/layoutmgr/PageBreakingAlgorithm.java
URL: http://svn.apache.org/viewvc/xmlgraphics/fop/branches/maven/src/java/org/apache/fop/layoutmgr/PageBreakingAlgorithm.java?rev=1733431&r1=1733430&r2=1733431&view=diff
==============================================================================
--- xmlgraphics/fop/branches/maven/src/java/org/apache/fop/layoutmgr/PageBreakingAlgorithm.java (original)
+++ xmlgraphics/fop/branches/maven/src/java/org/apache/fop/layoutmgr/PageBreakingAlgorithm.java Thu Mar  3 09:40:50 2016
@@ -95,6 +95,7 @@ class PageBreakingAlgorithm extends Brea
 
     private int ipdDifference;
     private KnuthNode bestNodeForIPDChange;
+    public KnuthNode bestNodeForLastPage;
 
     //Used to keep track of switches in keep-context
     private int currentKeepContext = Constants.EN_AUTO;
@@ -1258,6 +1259,9 @@ class PageBreakingAlgorithm extends Brea
                  * the IPD change. No need to do any special handling.
                  */
                 ipdDifference = 0;
+            } else if (line > 0 /*&& (bestNodeForLastPage == null
+                     || node.totalDemerits < bestNodeForLastPage.totalDemerits)*/) {
+                bestNodeForLastPage = node;
             }
             super.addNode(line, node);
         }
@@ -1274,6 +1278,10 @@ class PageBreakingAlgorithm extends Brea
         return pageProvider.compareIPDs(line);
     }
 
+    KnuthNode getBestNodeForLastPage() {
+        return bestNodeForLastPage;
+    }
+
     protected boolean handlingFloat() {
         return (handlingStartOfFloat || handlingEndOfFloat);
     }

Modified: xmlgraphics/fop/branches/maven/src/java/org/apache/fop/layoutmgr/PageProvider.java
URL: http://svn.apache.org/viewvc/xmlgraphics/fop/branches/maven/src/java/org/apache/fop/layoutmgr/PageProvider.java?rev=1733431&r1=1733430&r2=1733431&view=diff
==============================================================================
--- xmlgraphics/fop/branches/maven/src/java/org/apache/fop/layoutmgr/PageProvider.java (original)
+++ xmlgraphics/fop/branches/maven/src/java/org/apache/fop/layoutmgr/PageProvider.java Thu Mar  3 09:40:50 2016
@@ -201,8 +201,8 @@ public class PageProvider implements Con
             return 0;
         } else {
             Page nextPage = getPage(false, column.pageIndex + 1, RELTO_CURRENT_ELEMENT_LIST);
-            return column.page.getPageViewport().getBodyRegion().getIPD()
-                    - nextPage.getPageViewport().getBodyRegion().getIPD();
+            return column.page.getPageViewport().getBodyRegion().getColumnIPD()
+                    - nextPage.getPageViewport().getBodyRegion().getColumnIPD();
         }
     }
 
@@ -332,7 +332,7 @@ public class PageProvider implements Con
         return page;
     }
 
-    private void discardCacheStartingWith(int index) {
+    protected void discardCacheStartingWith(int index) {
         while (index < cachedPages.size()) {
             this.cachedPages.remove(cachedPages.size() - 1);
             if (!pageSeq.goToPreviousSimplePageMaster()) {
@@ -352,9 +352,38 @@ public class PageProvider implements Con
         page.getPageViewport().setForeignAttributes(spm.getForeignAttributes());
         page.getPageViewport().setWritingModeTraits(pageSeq);
         cachedPages.add(page);
+        if (isLastPage) {
+            pageSeq.getRoot().setLastSeq(pageSeq);
+        } else if (!isFirstPage) {
+            pageSeq.getRoot().setLastSeq(null);
+        }
         return page;
     }
 
+    public int getIndexOfCachedLastPage() {
+        return indexOfCachedLastPage;
+    }
+
+    public int getLastPageIndex() {
+        return lastPageIndex;
+    }
+
+    public int getLastPageIPD() {
+        int index = this.cachedPages.size();
+        boolean isFirstPage = (startPageOfPageSequence == index);
+        SimplePageMaster spm = pageSeq.getLastSimplePageMaster(index, isFirstPage, false);
+        Page page = new Page(spm, index, "", false, false);
+        if (pageSeq.getRoot().getLastSeq() != null && pageSeq.getRoot().getLastSeq() != pageSeq) {
+            return -1;
+        }
+        return page.getPageViewport().getBodyRegion().getColumnIPD();
+    }
+
+    public int getCurrentIPD() {
+        return getPageFromColumnIndex(startColumnOfCurrentElementList).getPageViewport().getBodyRegion()
+                .getColumnIPD();
+    }
+
     /**
      * Indicates whether the column/page at the given index is on the first page of the page sequence.
      *

Modified: xmlgraphics/fop/branches/maven/src/java/org/apache/fop/layoutmgr/PageSequenceLayoutManager.java
URL: http://svn.apache.org/viewvc/xmlgraphics/fop/branches/maven/src/java/org/apache/fop/layoutmgr/PageSequenceLayoutManager.java?rev=1733431&r1=1733430&r2=1733431&view=diff
==============================================================================
--- xmlgraphics/fop/branches/maven/src/java/org/apache/fop/layoutmgr/PageSequenceLayoutManager.java (original)
+++ xmlgraphics/fop/branches/maven/src/java/org/apache/fop/layoutmgr/PageSequenceLayoutManager.java Thu Mar  3 09:40:50 2016
@@ -254,6 +254,16 @@ public class PageSequenceLayoutManager e
         return pageProvider.isOnFirstPage(partIndex);
     }
 
+    protected int getLastPageNumber() {
+        return pageProvider.getLastPageIndex();
+    }
+
+    protected int getWidthOfCurrentPage() {
+        if (curPage != null) {
+            return (int) curPage.getPageViewport().getViewArea().getWidth();
+        }
+        return 0;
+    }
     /**
      * Registers the given footnotes so that they can be added to the current page, before any other footnote.
      *

Modified: xmlgraphics/fop/branches/maven/src/java/org/apache/fop/layoutmgr/table/TableContentPosition.java
URL: http://svn.apache.org/viewvc/xmlgraphics/fop/branches/maven/src/java/org/apache/fop/layoutmgr/table/TableContentPosition.java?rev=1733431&r1=1733430&r2=1733431&view=diff
==============================================================================
--- xmlgraphics/fop/branches/maven/src/java/org/apache/fop/layoutmgr/table/TableContentPosition.java (original)
+++ xmlgraphics/fop/branches/maven/src/java/org/apache/fop/layoutmgr/table/TableContentPosition.java Thu Mar  3 09:40:50 2016
@@ -124,4 +124,8 @@ class TableContentPosition extends Posit
         sb.append(")");
         return sb.toString();
     }
+
+    public Position getPosition() {
+        return this;
+    }
 }

Modified: xmlgraphics/fop/branches/maven/src/java/org/apache/fop/layoutmgr/table/TableRowIterator.java
URL: http://svn.apache.org/viewvc/xmlgraphics/fop/branches/maven/src/java/org/apache/fop/layoutmgr/table/TableRowIterator.java?rev=1733431&r1=1733430&r2=1733431&view=diff
==============================================================================
--- xmlgraphics/fop/branches/maven/src/java/org/apache/fop/layoutmgr/table/TableRowIterator.java (original)
+++ xmlgraphics/fop/branches/maven/src/java/org/apache/fop/layoutmgr/table/TableRowIterator.java Thu Mar  3 09:40:50 2016
@@ -68,7 +68,7 @@ public class TableRowIterator {
                 List rowGroupsList = new LinkedList();
                 // TODO this is ugly
                 for (FONodeIterator iter = table.getChildNodes(); iter.hasNext();) {
-                    FONode node = iter.nextNode();
+                    FONode node = iter.next();
                     if (node instanceof TableBody) {
                         rowGroupsList.addAll(((TableBody) node).getRowGroups());
                     }

Modified: xmlgraphics/fop/branches/maven/src/java/org/apache/fop/pdf/PDFPattern.java
URL: http://svn.apache.org/viewvc/xmlgraphics/fop/branches/maven/src/java/org/apache/fop/pdf/PDFPattern.java?rev=1733431&r1=1733430&r2=1733431&view=diff
==============================================================================
--- xmlgraphics/fop/branches/maven/src/java/org/apache/fop/pdf/PDFPattern.java (original)
+++ xmlgraphics/fop/branches/maven/src/java/org/apache/fop/pdf/PDFPattern.java Thu Mar  3 09:40:50 2016
@@ -321,7 +321,7 @@ public class PDFPattern extends PDFPathP
         if (pdfStream != null) {
             length += pdfStream.outputStreamData(encodedStream, stream);
         }
-
+        patternDataStream = null;
         return length;
     }
 

Modified: xmlgraphics/fop/branches/maven/src/java/org/apache/fop/render/intermediate/IFParser.java
URL: http://svn.apache.org/viewvc/xmlgraphics/fop/branches/maven/src/java/org/apache/fop/render/intermediate/IFParser.java?rev=1733431&r1=1733430&r2=1733431&view=diff
==============================================================================
--- xmlgraphics/fop/branches/maven/src/java/org/apache/fop/render/intermediate/IFParser.java (original)
+++ xmlgraphics/fop/branches/maven/src/java/org/apache/fop/render/intermediate/IFParser.java Thu Mar  3 09:40:50 2016
@@ -523,7 +523,7 @@ public class IFParser implements IFConst
                 establishForeignAttributes(foreignAttributes);
                 documentHandler.startPage(index, name, pageMasterName,
                         new Dimension(width, height));
-                documentHandler.getContext().setPageNumber(Integer.parseInt(name));
+                documentHandler.getContext().setPageNumber(index + 1);
                 resetForeignAttributes();
             }
 

Modified: xmlgraphics/fop/branches/maven/src/java/org/apache/fop/render/pcl/Java2DRendererOption.java
URL: http://svn.apache.org/viewvc/xmlgraphics/fop/branches/maven/src/java/org/apache/fop/render/pcl/Java2DRendererOption.java?rev=1733431&r1=1733430&r2=1733431&view=diff
==============================================================================
--- xmlgraphics/fop/branches/maven/src/java/org/apache/fop/render/pcl/Java2DRendererOption.java (original)
+++ xmlgraphics/fop/branches/maven/src/java/org/apache/fop/render/pcl/Java2DRendererOption.java Thu Mar  3 09:40:50 2016
@@ -27,7 +27,8 @@ public enum Java2DRendererOption impleme
 
     RENDERING_MODE("rendering", PCLRenderingMode.class),
     TEXT_RENDERING("text-rendering", Boolean.class),
-    DISABLE_PJL("disable-pjl", Boolean.class);
+    DISABLE_PJL("disable-pjl", Boolean.class),
+    MODE_COLOR("color", Boolean.class);
 
     private final String name;
 

Modified: xmlgraphics/fop/branches/maven/src/java/org/apache/fop/render/pcl/PCLDocumentHandler.java
URL: http://svn.apache.org/viewvc/xmlgraphics/fop/branches/maven/src/java/org/apache/fop/render/pcl/PCLDocumentHandler.java?rev=1733431&r1=1733430&r2=1733431&view=diff
==============================================================================
--- xmlgraphics/fop/branches/maven/src/java/org/apache/fop/render/pcl/PCLDocumentHandler.java (original)
+++ xmlgraphics/fop/branches/maven/src/java/org/apache/fop/render/pcl/PCLDocumentHandler.java Thu Mar  3 09:40:50 2016
@@ -274,7 +274,7 @@ public class PCLDocumentHandler extends
             try {
                 Rectangle printArea = this.currentPageDefinition.getLogicalPageRect();
                 gen.setCursorPos(0, 0);
-                gen.paintBitmap(this.currentImage, printArea.getSize(), true);
+                gen.paintBitmap(this.currentImage, printArea.getSize(), true, pclUtil);
             } catch (IOException ioe) {
                 throw new IFException("I/O error while encoding page image", ioe);
             } finally {



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