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 je...@apache.org on 2005/10/24 11:24:53 UTC

svn commit: r328010 [2/8] - in /xmlgraphics/fop/trunk: src/java/org/apache/fop/datatypes/ src/java/org/apache/fop/fo/ src/java/org/apache/fop/fo/flow/ src/java/org/apache/fop/layoutmgr/ src/java/org/apache/fop/layoutmgr/inline/ src/java/org/apache/fop/...

Modified: xmlgraphics/fop/trunk/src/java/org/apache/fop/layoutmgr/KnuthElement.java
URL: http://svn.apache.org/viewcvs/xmlgraphics/fop/trunk/src/java/org/apache/fop/layoutmgr/KnuthElement.java?rev=328010&r1=328009&r2=328010&view=diff
==============================================================================
--- xmlgraphics/fop/trunk/src/java/org/apache/fop/layoutmgr/KnuthElement.java (original)
+++ xmlgraphics/fop/trunk/src/java/org/apache/fop/layoutmgr/KnuthElement.java Mon Oct 24 02:21:26 2005
@@ -26,12 +26,12 @@
  * special feature (for example, the additional elements used to represent
  * a space when text alignment is right, left or center).
  */
-public abstract class KnuthElement {
+public abstract class KnuthElement extends ListElement {
 
+    /** The value used as an infinite indicator. */
     public static final int INFINITE = 1000;
 
     private int width;
-    private Position position;
     private boolean bIsAuxiliary;
 
     /**
@@ -43,84 +43,39 @@
      * @param bAux is this an auxiliary element?
      */
     protected KnuthElement(int w, Position pos, boolean bAux) {
+        super(pos);
         width = w;
-        position = pos;
         bIsAuxiliary = bAux;
     }
 
-    /**
-     * Return true if this element is a KnuthBox.
-     */
-    public boolean isBox() {
-        return false;
-    }
-
-    /**
-     * Return true if this element is a KnuthGlue.
-     */
-    public boolean isGlue() {
-        return false;
-    }
-
-    /**
-     * Return true if this element is a KnuthPenalty.
-     */
-    public boolean isPenalty() {
-        return false;
-    }
-
-    /**
-     * Return true if this element is an auxiliary one.
-     */
+    /** @return true if this element is an auxiliary one. */
     public boolean isAuxiliary() {
         return bIsAuxiliary;
     }
 
-    /**
-     * Return the width of this element.
-     */
+    /** @return the width of this element. */
     public int getW() {
         return width;
     }
 
+    /** @return the penalty value of this element, if applicable. */ 
     public int getP() {
         throw new RuntimeException("Element is not a penalty");
     }
 
+    /** @return the stretch value of this element, if applicable. */ 
     public int getY() {
         throw new RuntimeException("Element is not a glue");
     }
 
+    /** @return the shrink value of this element, if applicable. */ 
     public int getZ() {
         throw new RuntimeException("Element is not a glue");
     }
-
-    public boolean isForcedBreak() {
+    
+    /** @see org.apache.fop.layoutmgr.ListElement#isUnresolvedElement() */
+    public boolean isUnresolvedElement() {
         return false;
     }
 
-    /**
-     * Return the Position stored in this element.
-     */
-    public Position getPosition() {
-        return position;
-    }
-
-    /**
-     * Change the Position stored in this element.
-     */
-    public void setPosition(Position pos) {
-        position = pos;
-    }
-
-    /**
-     * Return the LayoutManager responsible for this element.
-     */
-    public LayoutManager getLayoutManager() {
-        if (position != null) {
-            return position.getLM();
-        } else {
-            return null;
-        }
-    }
 }

Modified: xmlgraphics/fop/trunk/src/java/org/apache/fop/layoutmgr/KnuthPossPosIter.java
URL: http://svn.apache.org/viewcvs/xmlgraphics/fop/trunk/src/java/org/apache/fop/layoutmgr/KnuthPossPosIter.java?rev=328010&r1=328009&r2=328010&view=diff
==============================================================================
--- xmlgraphics/fop/trunk/src/java/org/apache/fop/layoutmgr/KnuthPossPosIter.java (original)
+++ xmlgraphics/fop/trunk/src/java/org/apache/fop/layoutmgr/KnuthPossPosIter.java Mon Oct 24 02:21:26 2005
@@ -65,15 +65,15 @@
         return super.next();
     }
 
-    public KnuthElement getKE() {
-        return (KnuthElement) peekNext();
+    public ListElement getKE() {
+        return (ListElement) peekNext();
     }
 
     protected LayoutManager getLM(Object nextObj) {
-        return ((KnuthElement) nextObj).getLayoutManager();
+        return ((ListElement) nextObj).getLayoutManager();
     }
 
     protected Position getPos(Object nextObj) {
-        return ((KnuthElement) nextObj).getPosition();
+        return ((ListElement) nextObj).getPosition();
     }
 }

Modified: xmlgraphics/fop/trunk/src/java/org/apache/fop/layoutmgr/KnuthSequence.java
URL: http://svn.apache.org/viewcvs/xmlgraphics/fop/trunk/src/java/org/apache/fop/layoutmgr/KnuthSequence.java?rev=328010&r1=328009&r2=328010&view=diff
==============================================================================
--- xmlgraphics/fop/trunk/src/java/org/apache/fop/layoutmgr/KnuthSequence.java (original)
+++ xmlgraphics/fop/trunk/src/java/org/apache/fop/layoutmgr/KnuthSequence.java Mon Oct 24 02:21:26 2005
@@ -53,9 +53,19 @@
     }
 
     /**
+     * Finalizes a Knuth sequence.
      * @return a finalized sequence.
      */
     public KnuthSequence endSequence() {
+        return endSequence(null);
+    }
+    
+    /**
+     * Finalizes a Knuth sequence.
+     * @param breakPosition a Position instance for the last penalty (may be null)
+     * @return a finalized sequence.
+     */
+    public KnuthSequence endSequence(Position breakPosition) {
         // remove glue and penalty item at the end of the paragraph
         while (this.size() > ignoreAtStart
                && !((KnuthElement)this.get(this.size() - 1)).isBox()) {
@@ -66,7 +76,7 @@
             // and the forced break
             this.add(new KnuthPenalty(0, KnuthElement.INFINITE, false, null, false));
             this.add(new KnuthGlue(0, 10000000, 0, null, false));
-            this.add(new KnuthPenalty(0, -KnuthElement.INFINITE, false, null, false));
+            this.add(new KnuthPenalty(0, -KnuthElement.INFINITE, false, breakPosition, false));
             ignoreAtEnd = 3;
             return this;
         } else {

Modified: xmlgraphics/fop/trunk/src/java/org/apache/fop/layoutmgr/LayoutContext.java
URL: http://svn.apache.org/viewcvs/xmlgraphics/fop/trunk/src/java/org/apache/fop/layoutmgr/LayoutContext.java?rev=328010&r1=328009&r2=328010&view=diff
==============================================================================
--- xmlgraphics/fop/trunk/src/java/org/apache/fop/layoutmgr/LayoutContext.java (original)
+++ xmlgraphics/fop/trunk/src/java/org/apache/fop/layoutmgr/LayoutContext.java Mon Oct 24 02:21:26 2005
@@ -1,5 +1,5 @@
 /*
- * Copyright 1999-2004 The Apache Software Foundation.
+ * Copyright 1999-2005 The Apache Software Foundation.
  * 
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
@@ -18,6 +18,9 @@
 
 package org.apache.fop.layoutmgr;
 
+import java.util.Collections;
+import java.util.List;
+
 import org.apache.fop.fo.Constants;
 import org.apache.fop.layoutmgr.inline.HyphContext;
 import org.apache.fop.traits.MinOptMax;
@@ -25,7 +28,7 @@
 
 
 /**
- * This class is used to pass information to the getNextBreakPoss()
+ * This class is used to pass information to the getNextKnuthElements()
  * method. It is set up by higher level LM and used by lower level LM.
  */
 public class LayoutContext {
@@ -91,6 +94,18 @@
 
     /** Current pending space-before or space-start from ancestor areas */
     SpaceSpecifier leadingSpace;
+    
+    /**
+     * A list of pending marks (border and padding) on the after edge when a page break occurs. 
+     * May be null.
+     */
+    private List pendingAfterMarks;
+    
+    /**
+     * A list of pending marks (border and padding) on the before edge when a page break occurs. 
+     * May be null.
+     */
+    private List pendingBeforeMarks;
 
     /** Current hyphenation context. May be null. */
     private HyphContext hyphContext = null;
@@ -117,6 +132,10 @@
     /** Amount of space to reserve at the end of each line */
     private int lineEndBorderAndPaddingWidth = 0;
 
+    /**
+     * Copy constructor for creating child layout contexts.
+     * @param parentLC the parent layout context to copy from
+     */
     public LayoutContext(LayoutContext parentLC) {
         this.flags = parentLC.flags;
         this.refIPD = parentLC.refIPD;
@@ -131,9 +150,14 @@
         this.alignmentContext = parentLC.alignmentContext;
         this.lineStartBorderAndPaddingWidth = parentLC.lineStartBorderAndPaddingWidth;
         this.lineEndBorderAndPaddingWidth = parentLC.lineEndBorderAndPaddingWidth;
-        // Copy other fields as necessary. Use clone???
+        copyPendingMarksFrom(parentLC);
+        // Copy other fields as necessary.
     }
 
+    /**
+     * Main constructor.
+     * @param flags the initial flags
+     */
     public LayoutContext(int flags) {
         this.flags = flags;
         this.refIPD = 0;
@@ -142,6 +166,15 @@
         trailingSpace = null;
     }
 
+    public void copyPendingMarksFrom(LayoutContext source) {
+        if (source.pendingAfterMarks != null) {
+            this.pendingAfterMarks = new java.util.ArrayList(source.pendingAfterMarks); 
+        }
+        if (source.pendingBeforeMarks != null) {
+            this.pendingBeforeMarks = new java.util.ArrayList(source.pendingBeforeMarks); 
+        }
+    }
+    
     public void setFlags(int flags) {
         setFlags(flags, true);
     }
@@ -206,6 +239,56 @@
         return trailingSpace;
     }
 
+    /**
+     * Adds a border or padding element to the pending list which will be used to generate
+     * the right element list for break possibilities. Conditionality resolution will be done
+     * elsewhere.
+     * @param element the border, padding or space element
+     */
+    public void addPendingAfterMark(UnresolvedListElementWithLength element) {
+        if (this.pendingAfterMarks == null) {
+            this.pendingAfterMarks = new java.util.ArrayList();
+        }
+        this.pendingAfterMarks.add(element);
+    }
+    
+    /**
+     * @return the pending border and padding elements at the after edge
+     * @see addPendingAfterMark(BorderOrPaddingElement)
+     */
+    public List getPendingAfterMarks() {
+        if (this.pendingAfterMarks != null) {
+            return Collections.unmodifiableList(this.pendingAfterMarks);
+        } else {
+            return null;
+        }
+    }
+    
+    /**
+     * Adds a border or padding element to the pending list which will be used to generate
+     * the right element list for break possibilities. Conditionality resolution will be done
+     * elsewhere.
+     * @param element the border, padding or space element
+     */
+    public void addPendingBeforeMark(UnresolvedListElementWithLength element) {
+        if (this.pendingBeforeMarks == null) {
+            this.pendingBeforeMarks = new java.util.ArrayList();
+        }
+        this.pendingBeforeMarks.add(element);
+    }
+    
+    /**
+     * @return the pending border and padding elements at the before edge
+     * @see addPendingBeforeMark(BorderOrPaddingElement)
+     */
+    public List getPendingBeforeMarks() {
+        if (this.pendingBeforeMarks != null) {
+            return Collections.unmodifiableList(this.pendingBeforeMarks);
+        } else {
+            return null;
+        }
+    }
+    
     public void setStackLimit(MinOptMax limit) {
         stackLimit = limit;
     }

Propchange: xmlgraphics/fop/trunk/src/java/org/apache/fop/layoutmgr/LayoutContext.java
------------------------------------------------------------------------------
    svn:keywords = Id

Modified: xmlgraphics/fop/trunk/src/java/org/apache/fop/layoutmgr/PageBreakingAlgorithm.java
URL: http://svn.apache.org/viewcvs/xmlgraphics/fop/trunk/src/java/org/apache/fop/layoutmgr/PageBreakingAlgorithm.java?rev=328010&r1=328009&r2=328010&view=diff
==============================================================================
--- xmlgraphics/fop/trunk/src/java/org/apache/fop/layoutmgr/PageBreakingAlgorithm.java (original)
+++ xmlgraphics/fop/trunk/src/java/org/apache/fop/layoutmgr/PageBreakingAlgorithm.java Mon Oct 24 02:21:26 2005
@@ -201,6 +201,11 @@
         ListIterator elementListsIterator = elementLists.listIterator();
         while (elementListsIterator.hasNext()) {
             LinkedList noteList = (LinkedList) elementListsIterator.next();
+            
+            //Space resolution (Note: this does not respect possible stacking constraints 
+            //between footnotes!)
+            SpaceResolver.resolveElementList(noteList);
+            
             int noteLength = 0;
             footnotesList.add(noteList);
             ListIterator noteListIterator = noteList.listIterator();

Modified: xmlgraphics/fop/trunk/src/java/org/apache/fop/layoutmgr/PageSequenceLayoutManager.java
URL: http://svn.apache.org/viewcvs/xmlgraphics/fop/trunk/src/java/org/apache/fop/layoutmgr/PageSequenceLayoutManager.java?rev=328010&r1=328009&r2=328010&view=diff
==============================================================================
--- xmlgraphics/fop/trunk/src/java/org/apache/fop/layoutmgr/PageSequenceLayoutManager.java (original)
+++ xmlgraphics/fop/trunk/src/java/org/apache/fop/layoutmgr/PageSequenceLayoutManager.java Mon Oct 24 02:21:26 2005
@@ -227,7 +227,7 @@
             if (contentList != null) {
                 ListIterator contentListIterator = contentList.listIterator();
                 while (contentListIterator.hasNext()) {
-                    KnuthElement element = (KnuthElement) contentListIterator.next();
+                    ListElement element = (ListElement) contentListIterator.next();
                     if (element instanceof KnuthBlockBox
                         && ((KnuthBlockBox) element).hasAnchors()) {
                         // element represents a line with footnote citations
@@ -402,10 +402,11 @@
                     int lastIndex = (i == pbp.footnoteLastListIndex 
                             ? pbp.footnoteLastElementIndex : elementList.size() - 1);
 
-                    FootnoteBodyLayoutManager fblm = (FootnoteBodyLayoutManager)
-                            ((KnuthElement) elementList.getFirst()).getLayoutManager();
+                    SpaceResolver.performConditionalsNotification(elementList, 
+                            firstIndex, lastIndex, -1);
                     LayoutContext childLC = new LayoutContext(0);
-                    fblm.addAreas(new KnuthPossPosIter(elementList, firstIndex, lastIndex + 1), 
+                    AreaAdditionUtil.addAreas(null, 
+                            new KnuthPossPosIter(elementList, firstIndex, lastIndex + 1), 
                             childLC);
                 }
                 // set the offset from the top margin
@@ -422,6 +423,12 @@
         
         protected LayoutManager getCurrentChildLM() {
             return childFLM;
+        }
+        
+        /** @see org.apache.fop.layoutmgr.AbstractBreaker#observeElementList(java.util.List) */
+        protected void observeElementList(List elementList) {
+            ElementListObserver.observe(elementList, "breaker", 
+                    ((PageSequence)pslm.getFObj()).getId());
         }
         
     }

Modified: xmlgraphics/fop/trunk/src/java/org/apache/fop/layoutmgr/PositionIterator.java
URL: http://svn.apache.org/viewcvs/xmlgraphics/fop/trunk/src/java/org/apache/fop/layoutmgr/PositionIterator.java?rev=328010&r1=328009&r2=328010&view=diff
==============================================================================
--- xmlgraphics/fop/trunk/src/java/org/apache/fop/layoutmgr/PositionIterator.java (original)
+++ xmlgraphics/fop/trunk/src/java/org/apache/fop/layoutmgr/PositionIterator.java Mon Oct 24 02:21:26 2005
@@ -60,7 +60,7 @@
         LayoutManager lm = getLM(nextObj);
         if (childLM == null) {
             childLM = lm;
-        } else if (childLM != lm) {
+        } else if (childLM != lm && lm != null) {
             // End of this sub-sequence with same child LM
             bHasNext = false;
             childLM = null;

Modified: xmlgraphics/fop/trunk/src/java/org/apache/fop/layoutmgr/StaticContentLayoutManager.java
URL: http://svn.apache.org/viewcvs/xmlgraphics/fop/trunk/src/java/org/apache/fop/layoutmgr/StaticContentLayoutManager.java?rev=328010&r1=328009&r2=328010&view=diff
==============================================================================
--- xmlgraphics/fop/trunk/src/java/org/apache/fop/layoutmgr/StaticContentLayoutManager.java (original)
+++ xmlgraphics/fop/trunk/src/java/org/apache/fop/layoutmgr/StaticContentLayoutManager.java Mon Oct 24 02:21:26 2005
@@ -19,11 +19,13 @@
 package org.apache.fop.layoutmgr;
 
 import java.util.LinkedList;
+import java.util.List;
 import java.util.ListIterator;
 
 import org.apache.fop.area.RegionReference;
 import org.apache.fop.area.Area;
 import org.apache.fop.area.Block;
+import org.apache.fop.fo.pagination.PageSequence;
 import org.apache.fop.fo.pagination.SideRegion;
 import org.apache.fop.fo.pagination.StaticContent;
 import org.apache.fop.layoutmgr.inline.InlineLevelLayoutManager;
@@ -251,6 +253,16 @@
             this.displayAlign = displayAlign;
         }
 
+        /** @see org.apache.fop.layoutmgr.AbstractBreaker#observeElementList(java.util.List) */
+        protected void observeElementList(List elementList) {
+            String elementListID = getStaticContentFO().getFlowName();
+            String pageSequenceID = ((PageSequence)lm.getParent().getFObj()).getId();
+            if (pageSequenceID != null && pageSequenceID.length() > 0) {
+                elementListID += "-" + pageSequenceID;
+            }
+            ElementListObserver.observe(elementList, "static-content", elementListID);
+        }
+        
         /** @see org.apache.fop.layoutmgr.AbstractBreaker#isPartOverflowRecoveryActivated() */
         protected boolean isPartOverflowRecoveryActivated() {
             //For side regions, this must be disabled because of wanted overflow.
@@ -287,9 +299,9 @@
                 }
                 if (returnedList != null) {
                     lm.wrapPositionElements(returnedList, returnList);
-                    //returnList.addAll(returnedList);
                 }
             }
+            SpaceResolver.resolveElementList(returnList);
             setFinished(true);
             return returnList;
         }

Modified: xmlgraphics/fop/trunk/src/java/org/apache/fop/layoutmgr/TraitSetter.java
URL: http://svn.apache.org/viewcvs/xmlgraphics/fop/trunk/src/java/org/apache/fop/layoutmgr/TraitSetter.java?rev=328010&r1=328009&r2=328010&view=diff
==============================================================================
--- xmlgraphics/fop/trunk/src/java/org/apache/fop/layoutmgr/TraitSetter.java (original)
+++ xmlgraphics/fop/trunk/src/java/org/apache/fop/layoutmgr/TraitSetter.java Mon Oct 24 02:21:26 2005
@@ -21,6 +21,7 @@
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
 import org.apache.fop.traits.BorderProps;
+import org.apache.fop.traits.MinOptMax;
 import org.apache.fop.area.Area;
 import org.apache.fop.area.Trait;
 import org.apache.fop.datatypes.LengthBase;
@@ -105,12 +106,13 @@
     }
 
     /**
-     * Add borders to an area.
+     * Add borders to an area. Note: this method also adds unconditional padding. Don't use!
      * Layout managers that create areas with borders can use this to
      * add the borders to the area.
      * @param area the area to set the traits on.
      * @param bordProps border properties
      * @param context Property evaluation context
+     * @deprecated Call the other addBorders() method and addPadding separately.
      */
     public static void addBorders(Area area, CommonBorderPaddingBackground bordProps,
                                 PercentBaseContext context) {
@@ -135,6 +137,40 @@
     }
 
     /**
+     * Add borders to an area.
+     * Layout managers that create areas with borders can use this to
+     * add the borders to the area.
+     * @param area the area to set the traits on.
+     * @param bordProps border properties
+     * @param discardBefore true if the before border should be discarded
+     * @param discardAfter true if the after border should be discarded
+     * @param discardStart true if the start border should be discarded
+     * @param discardEnd true if the end border should be discarded
+     * @param context Property evaluation context
+     */
+    public static void addBorders(Area area, CommonBorderPaddingBackground bordProps,
+                boolean discardBefore, boolean discardAfter,
+                boolean discardStart, boolean discardEnd,
+                PercentBaseContext context) {
+        BorderProps bps = getBorderProps(bordProps, CommonBorderPaddingBackground.BEFORE);
+        if (bps != null && !discardBefore) {
+            area.addTrait(Trait.BORDER_BEFORE, bps);
+        }
+        bps = getBorderProps(bordProps, CommonBorderPaddingBackground.AFTER);
+        if (bps != null && !discardAfter) {
+            area.addTrait(Trait.BORDER_AFTER, bps);
+        }
+        bps = getBorderProps(bordProps, CommonBorderPaddingBackground.START);
+        if (bps != null && !discardStart) {
+            area.addTrait(Trait.BORDER_START, bps);
+        }
+        bps = getBorderProps(bordProps, CommonBorderPaddingBackground.END);
+        if (bps != null && !discardEnd) {
+            area.addTrait(Trait.BORDER_END, bps);
+        }
+    }
+
+    /**
      * Add borders to an area for the collapsing border model in tables.
      * Layout managers that create areas with borders can use this to
      * add the borders to the area.
@@ -174,25 +210,49 @@
 
     private static void addPadding(Area area, CommonBorderPaddingBackground bordProps, 
                                 PercentBaseContext context) {
-        int padding = bordProps.getPadding(CommonBorderPaddingBackground.START, false, context);
+        addPadding(area, bordProps, false, false, false, false, context);
+    }
+
+    /**
+     * Add padding to an area.
+     * Layout managers that create areas with padding can use this to
+     * add the borders to the area.
+     * @param area the area to set the traits on.
+     * @param bordProps border and padding properties
+     * @param discardBefore true if the before padding should be discarded
+     * @param discardAfter true if the after padding should be discarded
+     * @param discardStart true if the start padding should be discarded
+     * @param discardEnd true if the end padding should be discarded
+     * @param context Property evaluation context
+     */
+    public static void addPadding(Area area, CommonBorderPaddingBackground bordProps,
+                boolean discardBefore, boolean discardAfter,
+                boolean discardStart, boolean discardEnd,
+                PercentBaseContext context) {
+        int padding = bordProps.getPadding(CommonBorderPaddingBackground.BEFORE, 
+                discardBefore, context);
         if (padding != 0) {
-            area.addTrait(Trait.PADDING_START, new java.lang.Integer(padding));
+            area.addTrait(Trait.PADDING_BEFORE, new java.lang.Integer(padding));
         }
 
-        padding = bordProps.getPadding(CommonBorderPaddingBackground.END, false, context);
+        padding = bordProps.getPadding(CommonBorderPaddingBackground.AFTER, 
+                discardAfter, context);
         if (padding != 0) {
-            area.addTrait(Trait.PADDING_END, new java.lang.Integer(padding));
+            area.addTrait(Trait.PADDING_AFTER, new java.lang.Integer(padding));
         }
 
-        padding = bordProps.getPadding(CommonBorderPaddingBackground.BEFORE, false, context);
+        padding = bordProps.getPadding(CommonBorderPaddingBackground.START, 
+                discardStart, context);
         if (padding != 0) {
-            area.addTrait(Trait.PADDING_BEFORE, new java.lang.Integer(padding));
+            area.addTrait(Trait.PADDING_START, new java.lang.Integer(padding));
         }
 
-        padding = bordProps.getPadding(CommonBorderPaddingBackground.AFTER, false, context);
+        padding = bordProps.getPadding(CommonBorderPaddingBackground.END, 
+                discardEnd, context);
         if (padding != 0) {
-            area.addTrait(Trait.PADDING_AFTER, new java.lang.Integer(padding));
+            area.addTrait(Trait.PADDING_END, new java.lang.Integer(padding));
         }
+
     }
     
     private static BorderProps getBorderProps(CommonBorderPaddingBackground bordProps, int side) {
@@ -254,9 +314,9 @@
                         width += backProps.getPaddingEnd(false, context);
                         back.setHoriz(backProps.backgroundPositionHorizontal.getValue(
                                 new SimplePercentBaseContext(context, 
-                                                             LengthBase.IMAGE_BACKGROUND_POSITION_HORIZONTAL,
-                                                             (width - back.getFopImage().getIntrinsicWidth())
-                                                            )
+                                    LengthBase.IMAGE_BACKGROUND_POSITION_HORIZONTAL,
+                                    (width - back.getFopImage().getIntrinsicWidth())
+                                )
                             ));
                     } else {
                         //TODO Area IPD has to be set for this to work
@@ -275,9 +335,9 @@
                         height += backProps.getPaddingAfter(false, context);
                         back.setVertical(backProps.backgroundPositionVertical.getValue(
                                 new SimplePercentBaseContext(context, 
-                                                             LengthBase.IMAGE_BACKGROUND_POSITION_VERTICAL,
-                                                             (height - back.getFopImage().getIntrinsicHeight())
-                                                            )
+                                     LengthBase.IMAGE_BACKGROUND_POSITION_VERTICAL,
+                                     (height - back.getFopImage().getIntrinsicHeight())
+                                )
                             ));
                     } else {
                         //TODO Area BPD has to be set for this to work
@@ -329,6 +389,32 @@
         }
     }
 
+    public static int getEffectiveSpace(double adjust, MinOptMax space) {
+        if (space == null) {
+            return 0;
+        }
+        int sp = space.opt;
+        if (adjust > 0) {
+            sp = sp + (int)(adjust * (space.max - space.opt));
+        } else {
+            sp = sp + (int)(adjust * (space.opt - space.min));
+        }
+        return sp;
+    }
+    
+    public static void addSpaceBeforeAfter(Area area, double adjust, 
+            MinOptMax spaceBefore, MinOptMax spaceAfter) {
+        int space;
+        space = getEffectiveSpace(adjust, spaceBefore);
+        if (space != 0) {
+            area.addTrait(Trait.SPACE_BEFORE, new Integer(space));
+        }
+        space = getEffectiveSpace(adjust, spaceAfter);
+        if (space != 0) {
+            area.addTrait(Trait.SPACE_AFTER, new Integer(space));
+        }
+    }
+    
     /**
      * Sets the traits for breaks on an area.
      * @param area the area to set the traits on.

Modified: xmlgraphics/fop/trunk/src/java/org/apache/fop/layoutmgr/inline/LineLayoutManager.java
URL: http://svn.apache.org/viewcvs/xmlgraphics/fop/trunk/src/java/org/apache/fop/layoutmgr/inline/LineLayoutManager.java?rev=328010&r1=328009&r2=328010&view=diff
==============================================================================
--- xmlgraphics/fop/trunk/src/java/org/apache/fop/layoutmgr/inline/LineLayoutManager.java (original)
+++ xmlgraphics/fop/trunk/src/java/org/apache/fop/layoutmgr/inline/LineLayoutManager.java Mon Oct 24 02:21:26 2005
@@ -25,6 +25,7 @@
 import org.apache.fop.hyphenation.Hyphenation;
 import org.apache.fop.hyphenation.Hyphenator;
 import org.apache.fop.layoutmgr.BlockLevelLayoutManager;
+import org.apache.fop.layoutmgr.BreakElement;
 import org.apache.fop.layoutmgr.BreakingAlgorithm;
 import org.apache.fop.layoutmgr.ElementListObserver;
 import org.apache.fop.layoutmgr.KnuthBlockBox;
@@ -642,7 +643,7 @@
         }
 
         //PHASE 2: Create line breaks
-        return createLineBreaks(context.getBPAlignment());
+        return createLineBreaks(context.getBPAlignment(), context);
         /*
         LineBreakPosition lbp = null;
         if (breakpoints == null) {
@@ -979,9 +980,10 @@
     /**
      * Phase 2 of Knuth algorithm: find optimal break points.
      * @param alignment alignment in BP direction of the paragraph
+     * @param context the layout context
      * @return a list of Knuth elements representing broken lines
      */
-    private LinkedList createLineBreaks(int alignment) {
+    private LinkedList createLineBreaks(int alignment, LayoutContext context) {
 
         // find the optimal line breaking points for each paragraph
         ListIterator paragraphsIterator
@@ -1000,7 +1002,7 @@
         setFinished(true);
     
         //Post-process the line breaks found
-        return postProcessLineBreaks(alignment);
+        return postProcessLineBreaks(alignment, context);
     }
 
     /**
@@ -1143,17 +1145,19 @@
     /**
      * Creates the element list in BP direction for the broken lines.
      * @param alignment the currently applicable vertical alignment
+     * @param context the layout context
      * @return the newly built element list
      */
-    private LinkedList postProcessLineBreaks(int alignment) {
+    private LinkedList postProcessLineBreaks(int alignment, LayoutContext context) {
     
         LinkedList returnList = new LinkedList();
         
         for (int p = 0; p < knuthParagraphs.size(); p++) {
             // null penalty between paragraphs
-            if (p > 0
-                && !((BlockLevelLayoutManager) parentLM).mustKeepTogether()) {
-                returnList.add(new KnuthPenalty(0, 0, false, new Position(this), false));
+            if (p > 0 && !((BlockLevelLayoutManager) parentLM).mustKeepTogether()) {
+                returnList.add(new BreakElement(
+                        new Position(this), 0, context));
+                //returnList.add(new KnuthPenalty(0, 0, false, new Position(this), false));
             }
         
             lineLayouts = (LineLayoutPossibilities)lineLayoutsList.get(p);
@@ -1187,11 +1191,13 @@
                         i < lineLayouts.getChosenLineCount();
                         i++) {
                     if (!((BlockLevelLayoutManager) parentLM).mustKeepTogether()
-                        && i >= fobj.getOrphans()
-                        && i <= lineLayouts.getChosenLineCount() - fobj.getWidows()
-                        && returnList.size() > 0) {
+                            && i >= fobj.getOrphans()
+                            && i <= lineLayouts.getChosenLineCount() - fobj.getWidows()
+                            && returnList.size() > 0) {
                         // null penalty allowing a page break between lines
-                        returnList.add(new KnuthPenalty(0, 0, false, returnPosition, false));
+                        returnList.add(new BreakElement(
+                                returnPosition, 0, context));
+                        //returnList.add(new KnuthPenalty(0, 0, false, returnPosition, false));
                     }
                     int endIndex = ((LineBreakPosition) lineLayouts.getChosenPosition(i)).getLeafPos();
                     // create a list of the FootnoteBodyLM handling footnotes 

Modified: xmlgraphics/fop/trunk/src/java/org/apache/fop/layoutmgr/list/ListBlockLayoutManager.java
URL: http://svn.apache.org/viewcvs/xmlgraphics/fop/trunk/src/java/org/apache/fop/layoutmgr/list/ListBlockLayoutManager.java?rev=328010&r1=328009&r2=328010&view=diff
==============================================================================
--- xmlgraphics/fop/trunk/src/java/org/apache/fop/layoutmgr/list/ListBlockLayoutManager.java (original)
+++ xmlgraphics/fop/trunk/src/java/org/apache/fop/layoutmgr/list/ListBlockLayoutManager.java Mon Oct 24 02:21:26 2005
@@ -21,11 +21,13 @@
 import org.apache.fop.fo.flow.ListBlock;
 import org.apache.fop.layoutmgr.BlockLevelLayoutManager;
 import org.apache.fop.layoutmgr.BlockStackingLayoutManager;
+import org.apache.fop.layoutmgr.ConditionalElementListener;
 import org.apache.fop.layoutmgr.LayoutManager;
 import org.apache.fop.layoutmgr.LayoutContext;
 import org.apache.fop.layoutmgr.PositionIterator;
 import org.apache.fop.layoutmgr.Position;
 import org.apache.fop.layoutmgr.NonLeafPosition;
+import org.apache.fop.layoutmgr.RelSide;
 import org.apache.fop.layoutmgr.TraitSetter;
 import org.apache.fop.area.Area;
 import org.apache.fop.area.Block;
@@ -41,11 +43,17 @@
  * A list block contains list items which are stacked within
  * the list block area..
  */
-public class ListBlockLayoutManager extends BlockStackingLayoutManager {
+public class ListBlockLayoutManager extends BlockStackingLayoutManager 
+                implements ConditionalElementListener {
 
     private Block curBlockArea;
 
-    //TODO space-before|after: handle space-resolution rules
+    private boolean discardBorderBefore;
+    private boolean discardBorderAfter;
+    private boolean discardPaddingBefore;
+    private boolean discardPaddingAfter;
+    private MinOptMax effSpaceBefore;
+    private MinOptMax effSpaceAfter;
 
     private static class StackingIter extends PositionIterator {
         StackingIter(Iterator parentIter) {
@@ -86,11 +94,23 @@
         return (ListBlock)fobj;
     }
 
+    /** @see org.apache.fop.layoutmgr.LayoutManager#initialize() */
     public void initialize() {
-        foSpaceBefore = new SpaceVal(getListBlockFO().getCommonMarginBlock().spaceBefore, this).getSpace();
-        foSpaceAfter = new SpaceVal(getListBlockFO().getCommonMarginBlock().spaceAfter, this).getSpace();
+        foSpaceBefore = new SpaceVal(
+                getListBlockFO().getCommonMarginBlock().spaceBefore, this).getSpace();
+        foSpaceAfter = new SpaceVal(
+                getListBlockFO().getCommonMarginBlock().spaceAfter, this).getSpace();
     }
 
+    private void resetSpaces() {
+        this.discardBorderBefore = false;        
+        this.discardBorderAfter = false;        
+        this.discardPaddingBefore = false;        
+        this.discardPaddingAfter = false;
+        this.effSpaceBefore = foSpaceBefore;
+        this.effSpaceAfter = foSpaceAfter;
+    }
+    
     private int getIPIndents() {
         int iIndents = 0;
         iIndents += getListBlockFO().getCommonMarginBlock().startIndent.getValue(this);
@@ -98,6 +118,12 @@
         return iIndents;
     }
     
+    /** @see org.apache.fop.layoutmgr.BlockStackingLayoutManager */
+    public LinkedList getNextKnuthElements(LayoutContext context, int alignment) {
+        resetSpaces(); 
+        return super.getNextKnuthElements(context, alignment);
+    }
+   
     /** @see org.apache.fop.layoutmgr.LayoutManager#getChangedKnuthElements(java.util.List, int) */
     public LinkedList getChangedKnuthElements(List oldList, int alignment) {
         //log.debug("LBLM.getChangedKnuthElements>");
@@ -121,11 +147,6 @@
             addBlockSpacing(0.0, new MinOptMax(layoutContext.getSpaceBefore()));
         }
 
-        // if adjusted space before
-        double adjust = layoutContext.getSpaceAdjust();
-        addBlockSpacing(adjust, foSpaceBefore);
-        foSpaceBefore = null;
-        
         getPSLM().addIDToPage(getListBlockFO().getId());
 
         // the list block contains areas stacked from each list item
@@ -184,13 +205,13 @@
         TraitSetter.addBackground(curBlockArea, 
                 getListBlockFO().getCommonBorderPaddingBackground(),
                 this);
+        TraitSetter.addSpaceBeforeAfter(curBlockArea, layoutContext.getSpaceAdjust(), 
+                effSpaceBefore, effSpaceAfter);
 
         flush();
 
-        // if adjusted space after
-        addBlockSpacing(adjust, foSpaceAfter);
-        
         curBlockArea = null;
+        resetSpaces();
     }
 
     /**
@@ -217,7 +238,11 @@
             // set traits
             TraitSetter.setProducerID(curBlockArea, getListBlockFO().getId());
             TraitSetter.addBorders(curBlockArea, 
-            getListBlockFO().getCommonBorderPaddingBackground(), this);
+                    getListBlockFO().getCommonBorderPaddingBackground(), 
+                    discardBorderBefore, discardBorderAfter, false, false, this);
+            TraitSetter.addPadding(curBlockArea, 
+                    getListBlockFO().getCommonBorderPaddingBackground(), 
+                    discardPaddingBefore, discardPaddingAfter, false, false, this);
             TraitSetter.addMargins(curBlockArea,
                     getListBlockFO().getCommonBorderPaddingBackground(), 
                     getListBlockFO().getCommonMarginBlock(),
@@ -276,6 +301,51 @@
     public boolean mustKeepWithNext() {
         return !getListBlockFO().getKeepWithNext().getWithinPage().isAuto()
                 || !getListBlockFO().getKeepWithNext().getWithinColumn().isAuto();
+    }
+
+    /** @see org.apache.fop.layoutmgr.ConditionalElementListener */
+    public void notifySpace(RelSide side, MinOptMax effectiveLength) {
+        if (RelSide.BEFORE == side) {
+            if (log.isDebugEnabled()) {
+                log.debug(this + ": Space " + side + ", " 
+                        + this.effSpaceBefore + "-> " + effectiveLength);
+            }
+            this.effSpaceBefore = effectiveLength;
+        } else {
+            if (log.isDebugEnabled()) {
+                log.debug(this + ": Space " + side + ", " 
+                        + this.effSpaceAfter + "-> " + effectiveLength);
+            }
+            this.effSpaceAfter = effectiveLength;
+        }
+    }
+
+    /** @see org.apache.fop.layoutmgr.ConditionalElementListener */
+    public void notifyBorder(RelSide side, MinOptMax effectiveLength) {
+        if (effectiveLength == null) {
+            if (RelSide.BEFORE == side) {
+                this.discardBorderBefore = true;
+            } else {
+                this.discardBorderAfter = true;
+            }
+        }
+        if (log.isDebugEnabled()) {
+            log.debug(this + ": Border " + side + " -> " + effectiveLength);
+        }
+    }
+
+    /** @see org.apache.fop.layoutmgr.ConditionalElementListener */
+    public void notifyPadding(RelSide side, MinOptMax effectiveLength) {
+        if (effectiveLength == null) {
+            if (RelSide.BEFORE == side) {
+                this.discardPaddingBefore = true;
+            } else {
+                this.discardPaddingAfter = true;
+            }
+        }
+        if (log.isDebugEnabled()) {
+            log.debug(this + ": Padding " + side + " -> " + effectiveLength);
+        }
     }
 
 }

Modified: xmlgraphics/fop/trunk/src/java/org/apache/fop/layoutmgr/list/ListItemLayoutManager.java
URL: http://svn.apache.org/viewcvs/xmlgraphics/fop/trunk/src/java/org/apache/fop/layoutmgr/list/ListItemLayoutManager.java?rev=328010&r1=328009&r2=328010&view=diff
==============================================================================
--- xmlgraphics/fop/trunk/src/java/org/apache/fop/layoutmgr/list/ListItemLayoutManager.java (original)
+++ xmlgraphics/fop/trunk/src/java/org/apache/fop/layoutmgr/list/ListItemLayoutManager.java Mon Oct 24 02:21:26 2005
@@ -23,11 +23,17 @@
 import org.apache.fop.fo.flow.ListItemLabel;
 import org.apache.fop.layoutmgr.BlockLevelLayoutManager;
 import org.apache.fop.layoutmgr.BlockStackingLayoutManager;
+import org.apache.fop.layoutmgr.BreakElement;
+import org.apache.fop.layoutmgr.ConditionalElementListener;
+import org.apache.fop.layoutmgr.ElementListObserver;
+import org.apache.fop.layoutmgr.ElementListUtils;
 import org.apache.fop.layoutmgr.LayoutManager;
 import org.apache.fop.layoutmgr.LayoutContext;
 import org.apache.fop.layoutmgr.PositionIterator;
 import org.apache.fop.layoutmgr.Position;
 import org.apache.fop.layoutmgr.NonLeafPosition;
+import org.apache.fop.layoutmgr.RelSide;
+import org.apache.fop.layoutmgr.SpaceResolver;
 import org.apache.fop.layoutmgr.TraitSetter;
 import org.apache.fop.layoutmgr.KnuthElement;
 import org.apache.fop.layoutmgr.KnuthBox;
@@ -35,6 +41,7 @@
 import org.apache.fop.layoutmgr.KnuthPossPosIter;
 import org.apache.fop.area.Area;
 import org.apache.fop.area.Block;
+import org.apache.fop.traits.MinOptMax;
 import org.apache.fop.traits.SpaceVal;
 
 import java.util.ArrayList;
@@ -46,7 +53,8 @@
  * LayoutManager for a list-item FO.
  * The list item contains a list item label and a list item body.
  */
-public class ListItemLayoutManager extends BlockStackingLayoutManager {
+public class ListItemLayoutManager extends BlockStackingLayoutManager 
+                    implements ConditionalElementListener {
     private ListItemContentLayoutManager label;
     private ListItemContentLayoutManager body;
 
@@ -57,20 +65,16 @@
 
     private int listItemHeight;
     
-    //TODO space-before|after: handle space-resolution rules
+    private boolean discardBorderBefore;
+    private boolean discardBorderAfter;
+    private boolean discardPaddingBefore;
+    private boolean discardPaddingAfter;
+    private MinOptMax effSpaceBefore;
+    private MinOptMax effSpaceAfter;
     
     private boolean keepWithNextPendingOnLabel;
     private boolean keepWithNextPendingOnBody;
-    
-    /*
-    private class ItemPosition extends LeafPosition {
-        protected List cellBreaks;
-        protected ItemPosition(LayoutManager lm, int pos, List l) {
-            super(lm, pos);
-            cellBreaks = l;
-        }
-    }*/
-
+  
     private class ListItemPosition extends Position {
         private int iLabelFirstIndex;
         private int iLabelLastIndex;
@@ -149,11 +153,23 @@
         body.setParent(this);
     }
 
+    /** @see org.apache.fop.layoutmgr.LayoutManager#initialize() */
     public void initialize() {
-        foSpaceBefore = new SpaceVal(getListItemFO().getCommonMarginBlock().spaceBefore, this).getSpace();
-        foSpaceAfter = new SpaceVal(getListItemFO().getCommonMarginBlock().spaceAfter, this).getSpace();
+        foSpaceBefore = new SpaceVal(
+                getListItemFO().getCommonMarginBlock().spaceBefore, this).getSpace();
+        foSpaceAfter = new SpaceVal(
+                getListItemFO().getCommonMarginBlock().spaceAfter, this).getSpace();
     }
 
+    private void resetSpaces() {
+        this.discardBorderBefore = false;        
+        this.discardBorderAfter = false;        
+        this.discardPaddingBefore = false;        
+        this.discardPaddingAfter = false;
+        this.effSpaceBefore = foSpaceBefore;
+        this.effSpaceAfter = foSpaceAfter;
+    }
+    
     private int getIPIndents() {
         int iIndents = 0;
         iIndents += getListItemFO().getCommonMarginBlock().startIndent.getValue(this);
@@ -168,16 +184,22 @@
         
         LinkedList returnList = new LinkedList();
         
-        if (!bSpaceBeforeServed) {
-            addKnuthElementsForSpaceBefore(returnList, alignment);
-            bSpaceBeforeServed = true;
-        }
+        addKnuthElementsForSpaceBefore(returnList, alignment);
         
+        //Spaces, border and padding to be repeated at each break
+        addPendingMarks(context);
+
         // label
         childLC = new LayoutContext(0);
         childLC.setRefIPD(context.getRefIPD());
         label.initialize();
         labelList = label.getNextKnuthElements(childLC, alignment);
+        
+        //Space resolution as if the contents were placed in a new reference area
+        //(see 6.8.3, XSL 1.0, section on Constraints, last paragraph)
+        SpaceResolver.resolveElementList(labelList);
+        ElementListObserver.observe(labelList, "list-item-label", label.getPartFO().getId());
+        
         if (childLC.isKeepWithPreviousPending()) {
             context.setFlags(LayoutContext.KEEP_WITH_PREVIOUS_PENDING);
         }
@@ -188,13 +210,19 @@
         childLC.setRefIPD(context.getRefIPD());
         body.initialize();
         bodyList = body.getNextKnuthElements(childLC, alignment);
+
+        //Space resolution as if the contents were placed in a new reference area
+        //(see 6.8.3, XSL 1.0, section on Constraints, last paragraph)
+        SpaceResolver.resolveElementList(bodyList);
+        ElementListObserver.observe(bodyList, "list-item-body", body.getPartFO().getId());
+        
         if (childLC.isKeepWithPreviousPending()) {
             context.setFlags(LayoutContext.KEEP_WITH_PREVIOUS_PENDING);
         }
         this.keepWithNextPendingOnBody = childLC.isKeepWithNextPending();
 
         // create a combined list
-        LinkedList returnedList = getCombinedKnuthElementsForListItem(labelList, bodyList);
+        LinkedList returnedList = getCombinedKnuthElementsForListItem(labelList, bodyList, context);
 
         // "wrap" the Position inside each element
         wrapPositionElements(returnedList, returnList, true);
@@ -209,16 +237,18 @@
         }
 
         setFinished(true);
+        resetSpaces();
         return returnList;
     }
 
     private LinkedList getCombinedKnuthElementsForListItem(LinkedList labelElements,
-                                                           LinkedList bodyElements) {
+                                                           LinkedList bodyElements,
+                                                           LayoutContext context) {
         //Copy elements to array lists to improve element access performance
         List[] elementLists = {new ArrayList(labelElements),
                                new ArrayList(bodyElements)};
-        int[] fullHeights = {calcItemHeightFromContents(elementLists[0]),
-                            calcItemHeightFromContents(elementLists[1])};
+        int[] fullHeights = {ElementListUtils.calcContentLength(elementLists[0]),
+                ElementListUtils.calcContentLength(elementLists[1])};
         int[] partialHeights = {0, 0};
         int[] start = {-1, -1};
         int[] end = {-1, -1};
@@ -259,39 +289,14 @@
                 if (keepWithNextActive || mustKeepTogether()) {
                     p = KnuthPenalty.INFINITE;
                 }
-                returnList.add(new KnuthPenalty(penaltyHeight, p, false, stepPosition, false));
+                //returnList.add(new KnuthPenalty(penaltyHeight, p, false, stepPosition, false));
+                returnList.add(new BreakElement(stepPosition, penaltyHeight, p, 0, context));
             }
         }
 
         return returnList;
     }
 
-    private int calcItemHeightFromContents(List elements, int start, int end) {
-        ListIterator iter = elements.listIterator(start);
-        int count = end - start + 1;
-        int len = 0;
-        while (iter.hasNext()) {
-            KnuthElement el = (KnuthElement)iter.next();
-            if (el.isBox()) {
-                len += el.getW();
-            } else if (el.isGlue()) {
-                len += el.getW();
-            } else {
-                log.debug("Ignoring penalty: " + el);
-                //ignore penalties
-            }
-            count--;
-            if (count == 0) {
-                break;
-            }
-        }
-        return len;
-    }
-    
-    private int calcItemHeightFromContents(List elements) {
-        return calcItemHeightFromContents(elements, 0, elements.size() - 1);
-    }
-
     private int getNextStep(List[] elementLists, int[] start, int[] end, int[] partialHeights) {
         // backup of partial heights
         int[] backupHeights = {partialHeights[0], partialHeights[1]};
@@ -422,11 +427,6 @@
                          LayoutContext layoutContext) {
         getParentArea(null);
 
-        // if adjusted space before
-        double adjust = layoutContext.getSpaceAdjust();
-        addBlockSpacing(adjust, foSpaceBefore);
-        foSpaceBefore = null;
-
         getPSLM().addIDToPage(getListItemFO().getId());
 
         LayoutContext lc = new LayoutContext(0);
@@ -461,6 +461,31 @@
         int bodyFirstIndex = ((ListItemPosition) positionList.getFirst()).getBodyFirstIndex();
         int bodyLastIndex = ((ListItemPosition) positionList.getLast()).getBodyLastIndex();
 
+        int lastBreak;
+        //Determine last break if any
+        lastBreak = labelFirstIndex - 1;
+        while (lastBreak >= 0) {
+            KnuthElement el = (KnuthElement)labelList.get(lastBreak);
+            if (el.isPenalty() && el.getP() < KnuthElement.INFINITE) {
+                break;
+            }
+            lastBreak--;
+        }
+        SpaceResolver.performConditionalsNotification(labelList, 
+                labelFirstIndex, labelLastIndex, lastBreak);
+
+        //Determine last break if any
+        lastBreak = bodyFirstIndex - 1;
+        while (lastBreak >= 0) {
+            KnuthElement el = (KnuthElement)bodyList.get(lastBreak);
+            if (el.isPenalty() && el.getP() < KnuthElement.INFINITE) {
+                break;
+            }
+            lastBreak--;
+        }
+        SpaceResolver.performConditionalsNotification(bodyList, 
+                bodyFirstIndex, bodyLastIndex, lastBreak);
+        
         // add label areas
         if (labelFirstIndex <= labelLastIndex) {
             KnuthPossPosIter labelIter = new KnuthPossPosIter(labelList, 
@@ -508,13 +533,13 @@
         TraitSetter.addBackground(curBlockArea, 
                 getListItemFO().getCommonBorderPaddingBackground(),
                 this);
+        TraitSetter.addSpaceBeforeAfter(curBlockArea, layoutContext.getSpaceAdjust(), 
+                effSpaceBefore, effSpaceAfter);
 
         flush();
 
-        // if adjusted space after
-        addBlockSpacing(adjust, foSpaceAfter);
-        
         curBlockArea = null;
+        resetSpaces();
     }
 
     /**
@@ -550,7 +575,11 @@
             // set traits
             TraitSetter.setProducerID(curBlockArea, getListItemFO().getId());
             TraitSetter.addBorders(curBlockArea, 
-                    getListItemFO().getCommonBorderPaddingBackground(), this);
+                    getListItemFO().getCommonBorderPaddingBackground(), 
+                    discardBorderBefore, discardBorderAfter, false, false, this);
+            TraitSetter.addPadding(curBlockArea, 
+                    getListItemFO().getCommonBorderPaddingBackground(), 
+                    discardPaddingBefore, discardPaddingAfter, false, false, this);
             TraitSetter.addMargins(curBlockArea,
                     getListItemFO().getCommonBorderPaddingBackground(), 
                     getListItemFO().getCommonMarginBlock(), this);
@@ -610,5 +639,51 @@
                 || !getListItemFO().getKeepWithNext().getWithinColumn().isAuto();
     }
 
+    /** @see org.apache.fop.layoutmgr.ConditionalElementListener */
+    public void notifySpace(RelSide side, MinOptMax effectiveLength) {
+        if (RelSide.BEFORE == side) {
+            if (log.isDebugEnabled()) {
+                log.debug(this + ": Space " + side + ", " 
+                        + this.effSpaceBefore + "-> " + effectiveLength);
+            }
+            this.effSpaceBefore = effectiveLength;
+        } else {
+            if (log.isDebugEnabled()) {
+                log.debug(this + ": Space " + side + ", " 
+                        + this.effSpaceAfter + "-> " + effectiveLength);
+            }
+            this.effSpaceAfter = effectiveLength;
+        }
+    }
+
+    /** @see org.apache.fop.layoutmgr.ConditionalElementListener */
+    public void notifyBorder(RelSide side, MinOptMax effectiveLength) {
+        if (effectiveLength == null) {
+            if (RelSide.BEFORE == side) {
+                this.discardBorderBefore = true;
+            } else {
+                this.discardBorderAfter = true;
+            }
+        }
+        if (log.isDebugEnabled()) {
+            log.debug(this + ": Border " + side + " -> " + effectiveLength);
+        }
+    }
+
+    /** @see org.apache.fop.layoutmgr.ConditionalElementListener */
+    public void notifyPadding(RelSide side, MinOptMax effectiveLength) {
+        if (effectiveLength == null) {
+            if (RelSide.BEFORE == side) {
+                this.discardPaddingBefore = true;
+            } else {
+                this.discardPaddingAfter = true;
+            }
+        }
+        if (log.isDebugEnabled()) {
+            log.debug(this + ": Padding " + side + " -> " + effectiveLength);
+        }
+    }
+
+    
 }
 

Modified: xmlgraphics/fop/trunk/src/java/org/apache/fop/layoutmgr/table/TableCellLayoutManager.java
URL: http://svn.apache.org/viewcvs/xmlgraphics/fop/trunk/src/java/org/apache/fop/layoutmgr/table/TableCellLayoutManager.java?rev=328010&r1=328009&r2=328010&view=diff
==============================================================================
--- xmlgraphics/fop/trunk/src/java/org/apache/fop/layoutmgr/table/TableCellLayoutManager.java (original)
+++ xmlgraphics/fop/trunk/src/java/org/apache/fop/layoutmgr/table/TableCellLayoutManager.java Mon Oct 24 02:21:26 2005
@@ -27,12 +27,14 @@
 import org.apache.fop.layoutmgr.AreaAdditionUtil;
 import org.apache.fop.layoutmgr.BlockLevelLayoutManager;
 import org.apache.fop.layoutmgr.BlockStackingLayoutManager;
+import org.apache.fop.layoutmgr.BreakElement;
 import org.apache.fop.layoutmgr.KnuthElement;
 import org.apache.fop.layoutmgr.KnuthGlue;
-import org.apache.fop.layoutmgr.KnuthPenalty;
 import org.apache.fop.layoutmgr.LayoutContext;
+import org.apache.fop.layoutmgr.ListElement;
 import org.apache.fop.layoutmgr.PositionIterator;
 import org.apache.fop.layoutmgr.Position;
+import org.apache.fop.layoutmgr.SpaceResolver;
 import org.apache.fop.layoutmgr.TraitSetter;
 import org.apache.fop.area.Area;
 import org.apache.fop.area.Block;
@@ -43,9 +45,9 @@
  * LayoutManager for a table-cell FO.
  * A cell contains blocks. These blocks fill the cell.
  */
-public class TableCellLayoutManager extends BlockStackingLayoutManager implements BlockLevelLayoutManager {
+public class TableCellLayoutManager extends BlockStackingLayoutManager 
+            implements BlockLevelLayoutManager {
     
-    private TableCell fobj;
     private PrimaryGridUnit gridUnit;
     
     private Block curBlockArea;
@@ -75,22 +77,27 @@
 
     /** @return the table-cell FO */
     public TableCell getTableCell() {
-        return this.fobj;
+        return (TableCell)this.fobj;
     }
     
     private boolean isSeparateBorderModel() {
-        return fobj.isSeparateBorderModel();
+        return getTableCell().isSeparateBorderModel();
     }
     
+    /** @see org.apache.fop.layoutmgr.LayoutManager#initialize() */
     public void initialize() {
         borderAndPaddingBPD = 0;
-        borderAndPaddingBPD += fobj.getCommonBorderPaddingBackground().getBorderBeforeWidth(false);
-        borderAndPaddingBPD += fobj.getCommonBorderPaddingBackground().getBorderAfterWidth(false);
+        borderAndPaddingBPD += getTableCell()
+            .getCommonBorderPaddingBackground().getBorderBeforeWidth(false);
+        borderAndPaddingBPD += getTableCell()
+            .getCommonBorderPaddingBackground().getBorderAfterWidth(false);
         if (!isSeparateBorderModel()) {
             borderAndPaddingBPD /= 2;
         }
-        borderAndPaddingBPD += fobj.getCommonBorderPaddingBackground().getPaddingBefore(false, this);
-        borderAndPaddingBPD += fobj.getCommonBorderPaddingBackground().getPaddingAfter(false, this);
+        borderAndPaddingBPD += getTableCell().getCommonBorderPaddingBackground()
+                .getPaddingBefore(false, this);
+        borderAndPaddingBPD += getTableCell().getCommonBorderPaddingBackground()
+                .getPaddingAfter(false, this);
     }
     
     /**
@@ -115,8 +122,8 @@
         if (!isSeparateBorderModel()) {
             iIndents /= 2;
         }
-        iIndents += fobj.getCommonBorderPaddingBackground().getPaddingStart(false, this);
-        iIndents += fobj.getCommonBorderPaddingBackground().getPaddingEnd(false, this);
+        iIndents += getTableCell().getCommonBorderPaddingBackground().getPaddingStart(false, this);
+        iIndents += getTableCell().getCommonBorderPaddingBackground().getPaddingEnd(false, this);
         return iIndents;
     }
     
@@ -130,7 +137,7 @@
         cellIPD = referenceIPD;
         cellIPD -= getIPIndents();
         if (isSeparateBorderModel()) {
-            int borderSep = fobj.getBorderSeparation().getLengthPair()
+            int borderSep = getTableCell().getBorderSeparation().getLengthPair()
                     .getIPD().getLength().getValue(this);
             cellIPD -= borderSep;
         }
@@ -159,8 +166,7 @@
             }
             
             if (returnedList.size() == 1
-                    && ((KnuthElement) returnedList.getFirst()).isPenalty()
-                    && ((KnuthPenalty) returnedList.getFirst()).getP() == -KnuthElement.INFINITE) {
+                    && ((ListElement)returnedList.getFirst()).isForcedBreak()) {
                 // a descendant of this block has break-before
                 if (returnList.size() == 0) {
                     // the first child (or its first child ...) has
@@ -176,6 +182,9 @@
                 returnedList = new LinkedList();
                 wrapPositionElements(contentList, returnList);
 
+                //Space resolution
+                SpaceResolver.resolveElementList(returnList);
+                
                 return returnList;
             } else {
                 if (prevLM != null) {
@@ -189,13 +198,17 @@
                         childLC.setFlags(LayoutContext.KEEP_WITH_PREVIOUS_PENDING, false);
                         // add an infinite penalty to forbid a break between
                         // blocks
-                        contentList.add(new KnuthPenalty(0,
-                                KnuthElement.INFINITE, false,
-                                new Position(this), false));
+                        contentList.add(new BreakElement(
+                                new Position(this), KnuthElement.INFINITE, context));
+                        //contentList.add(new KnuthPenalty(0,
+                        //        KnuthElement.INFINITE, false,
+                        //        new Position(this), false));
                     } else if (!((KnuthElement) contentList.getLast()).isGlue()) {
                         // add a null penalty to allow a break between blocks
-                        contentList.add(new KnuthPenalty(0, 0, false,
-                                new Position(this), false));
+                        contentList.add(new BreakElement(
+                                new Position(this), 0, context));
+                        //contentList.add(new KnuthPenalty(0, 0, false,
+                        //        new Position(this), false));
                     } else {
                         // the last element in contentList is a glue;
                         // it is a feasible breakpoint, there is no need to add
@@ -207,9 +220,7 @@
                     //Avoid NoSuchElementException below (happens with empty blocks)
                     continue;
                 }
-                if (((KnuthElement) returnedList.getLast()).isPenalty()
-                        && ((KnuthPenalty) returnedList.getLast()).getP() 
-                                == -KnuthElement.INFINITE) {
+                if (((ListElement)returnedList.getLast()).isForcedBreak()) {
                     // a descendant of this block has break-after
                     if (curLM.isFinished()) {
                         // there is no other content in this block;
@@ -220,6 +231,9 @@
                     returnedList = new LinkedList();
                     wrapPositionElements(contentList, returnList);
 
+                    //Space resolution
+                    SpaceResolver.resolveElementList(returnList);
+                    
                     return returnList;
                 }
             }
@@ -234,6 +248,9 @@
         returnedList = new LinkedList();
         wrapPositionElements(contentList, returnList);
         
+        //Space resolution
+        SpaceResolver.resolveElementList(returnList);
+        
         setFinished(true);
         return returnList;
     }
@@ -314,11 +331,12 @@
                          LayoutContext layoutContext) {
         getParentArea(null);
 
-        getPSLM().addIDToPage(fobj.getId());
+        getPSLM().addIDToPage(getTableCell().getId());
 
         if (isSeparateBorderModel()) {
-            if (!emptyCell || fobj.showEmptyCells()) {
-                TraitSetter.addBorders(curBlockArea, fobj.getCommonBorderPaddingBackground(), this);
+            if (!emptyCell || getTableCell().showEmptyCells()) {
+                TraitSetter.addBorders(curBlockArea, 
+                        getTableCell().getCommonBorderPaddingBackground(), this);
             }
         } else {
             boolean[] outer = new boolean[] {
@@ -384,11 +402,11 @@
         //Handle display-align
         int contentBPD = getContentHeight(rowHeight, gridUnit);
         if (usedBPD < contentBPD) {
-            if (fobj.getDisplayAlign() == EN_CENTER) {
+            if (getTableCell().getDisplayAlign() == EN_CENTER) {
                 Block space = new Block();
                 space.setBPD((contentBPD - usedBPD) / 2);
                 curBlockArea.addBlock(space);
-            } else if (fobj.getDisplayAlign() == EN_AFTER) {
+            } else if (getTableCell().getDisplayAlign() == EN_AFTER) {
                 Block space = new Block();
                 space.setBPD((contentBPD - usedBPD));
                 curBlockArea.addBlock(space);
@@ -401,15 +419,15 @@
 
         // Add background after we know the BPD
         if (isSeparateBorderModel()) {
-            if (!emptyCell || fobj.showEmptyCells()) {
+            if (!emptyCell || getTableCell().showEmptyCells()) {
                 TraitSetter.addBackground(curBlockArea,
-                                          fobj.getCommonBorderPaddingBackground(),
-                                          this);
+                        getTableCell().getCommonBorderPaddingBackground(),
+                        this);
             }
         } else {
             TraitSetter.addBackground(curBlockArea,
-                                      fobj.getCommonBorderPaddingBackground(),
-                                      this);
+                    getTableCell().getCommonBorderPaddingBackground(),
+                    this);
         }
         
         flush();
@@ -434,18 +452,19 @@
         if (curBlockArea == null) {
             curBlockArea = new Block();
             curBlockArea.addTrait(Trait.IS_REFERENCE_AREA, Boolean.TRUE);
-            TraitSetter.setProducerID(curBlockArea, fobj.getId());
+            TraitSetter.setProducerID(curBlockArea, getTableCell().getId());
             curBlockArea.setPositioning(Block.ABSOLUTE);
             int indent = 0;
             indent += startBorderWidth;
             if (!isSeparateBorderModel()) {
                 indent /= 2;
             }
-            indent += fobj.getCommonBorderPaddingBackground().getPaddingStart(false, this);
+            indent += getTableCell()
+                    .getCommonBorderPaddingBackground().getPaddingStart(false, this);
             // set position
             int halfBorderSep = 0;
             if (isSeparateBorderModel()) {
-                halfBorderSep = fobj.getBorderSeparation().getLengthPair()
+                halfBorderSep = getTableCell().getBorderSeparation().getLengthPair()
                         .getIPD().getLength().getValue(this) / 2;
             }
             int borderAdjust = 0;

Modified: xmlgraphics/fop/trunk/src/java/org/apache/fop/layoutmgr/table/TableContentLayoutManager.java
URL: http://svn.apache.org/viewcvs/xmlgraphics/fop/trunk/src/java/org/apache/fop/layoutmgr/table/TableContentLayoutManager.java?rev=328010&r1=328009&r2=328010&view=diff
==============================================================================
--- xmlgraphics/fop/trunk/src/java/org/apache/fop/layoutmgr/table/TableContentLayoutManager.java (original)
+++ xmlgraphics/fop/trunk/src/java/org/apache/fop/layoutmgr/table/TableContentLayoutManager.java Mon Oct 24 02:21:26 2005
@@ -36,6 +36,7 @@
 import org.apache.fop.fo.flow.TableRow;
 import org.apache.fop.fo.properties.CommonBorderPaddingBackground;
 import org.apache.fop.fo.properties.LengthRangeProperty;
+import org.apache.fop.layoutmgr.BreakElement;
 import org.apache.fop.layoutmgr.ElementListObserver;
 import org.apache.fop.layoutmgr.ElementListUtils;
 import org.apache.fop.layoutmgr.KnuthBox;
@@ -44,10 +45,12 @@
 import org.apache.fop.layoutmgr.KnuthPossPosIter;
 import org.apache.fop.layoutmgr.LayoutContext;
 import org.apache.fop.layoutmgr.LayoutManager;
+import org.apache.fop.layoutmgr.ListElement;
 import org.apache.fop.layoutmgr.MinOptMaxUtil;
 import org.apache.fop.layoutmgr.Position;
 import org.apache.fop.layoutmgr.PositionIterator;
 import org.apache.fop.layoutmgr.TraitSetter;
+import org.apache.fop.layoutmgr.SpaceResolver.SpaceHandlingBreakPosition;
 import org.apache.fop.traits.MinOptMax;
 
 /**
@@ -199,16 +202,22 @@
             if (rowFO != null && rowFO.getBreakBefore() != Constants.EN_AUTO) {
                 log.info("break-before found");
                 if (returnList.size() > 0) {
-                    KnuthElement last = (KnuthElement)returnList.getLast();
+                    ListElement last = (ListElement)returnList.getLast();
                     if (last.isPenalty()) {
                         KnuthPenalty pen = (KnuthPenalty)last;
                         pen.setP(-KnuthPenalty.INFINITE);
                         pen.setBreakClass(rowFO.getBreakBefore());
+                    } else if (last instanceof BreakElement) {
+                        BreakElement breakPoss = (BreakElement)last;
+                        breakPoss.setPenaltyValue(-KnuthPenalty.INFINITE);
+                        breakPoss.setBreakClass(rowFO.getBreakBefore());
                     }
                 } else {
                     if (!firstBreakBeforeServed) {
-                        returnList.add(new KnuthPenalty(0, -KnuthPenalty.INFINITE, 
-                                false, rowFO.getBreakBefore(), new Position(getTableLM()), true));
+                        //returnList.add(new KnuthPenalty(0, -KnuthPenalty.INFINITE, 
+                        //        false, rowFO.getBreakBefore(), new Position(getTableLM()), true));
+                        returnList.add(new BreakElement(new Position(getTableLM()),
+                                0, -KnuthPenalty.INFINITE, rowFO.getBreakBefore(), context));
                         iter.backToPreviousRow();
                         firstBreakBeforeServed = true;
                         break;
@@ -234,12 +243,12 @@
                 log.debug("child LM (row group) signals pending keep-with-previous");
                 if (returnList.size() > 0) {
                     //Modify last penalty
-                    KnuthElement last = (KnuthElement)returnList.getLast();
+                    ListElement last = (ListElement)returnList.getLast();
                     if (last.isPenalty()) {
-                        KnuthPenalty pen = (KnuthPenalty)last;
+                        BreakElement breakPoss = (BreakElement)last;
                         //Only honor keep if there's no forced break
-                        if (!pen.isForcedBreak()) {
-                            pen.setP(KnuthPenalty.INFINITE);
+                        if (!breakPoss.isForcedBreak()) {
+                            breakPoss.setPenaltyValue(KnuthPenalty.INFINITE);
                         }
                     }
                 }
@@ -250,11 +259,15 @@
             if (rowFO != null && rowFO.getBreakAfter() != Constants.EN_AUTO) {
                 log.info("break-after found");
                 if (returnList.size() > 0) {
-                    KnuthElement last = (KnuthElement)returnList.getLast();
-                    if (last.isPenalty()) {
+                    ListElement last = (ListElement)returnList.getLast();
+                    if (last instanceof KnuthPenalty) {
                         KnuthPenalty pen = (KnuthPenalty)last;
                         pen.setP(-KnuthPenalty.INFINITE);
                         pen.setBreakClass(rowFO.getBreakAfter());
+                    } else if (last instanceof BreakElement) {
+                        BreakElement breakPoss = (BreakElement)last;
+                        breakPoss.setPenaltyValue(-KnuthPenalty.INFINITE);
+                        breakPoss.setBreakClass(rowFO.getBreakAfter());
                     }
                 }
             }
@@ -262,10 +275,9 @@
         
         if (returnList.size() > 0) {
             //Remove last penalty
-            KnuthElement last = (KnuthElement)returnList.getLast();
-            if (last.isPenalty()) {
-                KnuthPenalty pen = (KnuthPenalty)last;
-                if (!pen.isForcedBreak()) {
+            ListElement last = (ListElement)returnList.getLast();
+            if (last.isPenalty() || last instanceof BreakElement) {
+                if (!last.isForcedBreak()) {
                     //Only remove if we don't signal a forced break
                     returnList.removeLast();
                 }
@@ -461,9 +473,7 @@
                         ElementListObserver.observe(elems, "table-cell", primary.getCell().getId());
 
                         if ((elems.size() > 0) 
-                                && ((KnuthElement)elems.getLast()).isPenalty()
-                                && ((KnuthPenalty)elems.getLast()).getP() 
-                                        == -KnuthElement.INFINITE) {
+                                && ((KnuthElement)elems.getLast()).isForcedBreak()) {
                             // a descendant of this block has break-after
                             log.warn("Descendant of table-cell signals break: " 
                                     + primary.getCellLM().isFinished());
@@ -587,12 +597,24 @@
         List footerElements = null;
         Position firstPos = null;
         Position lastPos = null;
+        Position lastCheckPos = null;
         while (parentIter.hasNext()) {
             Position pos = (Position)parentIter.next();
+            if (pos instanceof SpaceHandlingBreakPosition) {
+                //This position has only been needed before addAreas was called, now we need the
+                //original one created by the layout manager.
+                pos = ((SpaceHandlingBreakPosition)pos).getOriginalBreakPosition();
+            }
+            if (pos == null) {
+                continue;
+            }
             if (firstPos == null) {
                 firstPos = pos;
             }
             lastPos = pos;
+            if (pos.getIndex() >= 0) {
+                lastCheckPos = pos;
+            }
             if (pos instanceof TableHeaderFooterPosition) {
                 TableHeaderFooterPosition thfpos = (TableHeaderFooterPosition)pos;
                 //these positions need to be unpacked
@@ -627,7 +649,7 @@
         Map markers = getTableLM().getTable().getMarkers();
         if (markers != null) {
             getTableLM().getCurrentPV().addMarkers(markers, 
-                    true, getTableLM().isFirst(firstPos), getTableLM().isLast(lastPos));
+                    true, getTableLM().isFirst(firstPos), getTableLM().isLast(lastCheckPos));
         }
         
         if (headerElements != null) {
@@ -655,7 +677,7 @@
 
         if (markers != null) {
             getTableLM().getCurrentPV().addMarkers(markers, 
-                    false, getTableLM().isFirst(firstPos), getTableLM().isLast(lastPos));
+                    false, getTableLM().isFirst(firstPos), getTableLM().isLast(lastCheckPos));
         }
     }
     

Modified: xmlgraphics/fop/trunk/src/java/org/apache/fop/layoutmgr/table/TableLayoutManager.java
URL: http://svn.apache.org/viewcvs/xmlgraphics/fop/trunk/src/java/org/apache/fop/layoutmgr/table/TableLayoutManager.java?rev=328010&r1=328009&r2=328010&view=diff
==============================================================================
--- xmlgraphics/fop/trunk/src/java/org/apache/fop/layoutmgr/table/TableLayoutManager.java (original)
+++ xmlgraphics/fop/trunk/src/java/org/apache/fop/layoutmgr/table/TableLayoutManager.java Mon Oct 24 02:21:26 2005
@@ -24,12 +24,14 @@
 import org.apache.fop.fo.properties.TableColLength;
 import org.apache.fop.layoutmgr.BlockLevelLayoutManager;
 import org.apache.fop.layoutmgr.BlockStackingLayoutManager;
+import org.apache.fop.layoutmgr.ConditionalElementListener;
 import org.apache.fop.layoutmgr.KnuthElement;
 import org.apache.fop.layoutmgr.KnuthGlue;
-import org.apache.fop.layoutmgr.KnuthPenalty;
 import org.apache.fop.layoutmgr.LayoutContext;
+import org.apache.fop.layoutmgr.ListElement;
 import org.apache.fop.layoutmgr.PositionIterator;
 import org.apache.fop.layoutmgr.Position;
+import org.apache.fop.layoutmgr.RelSide;
 import org.apache.fop.layoutmgr.TraitSetter;
 import org.apache.fop.area.Area;
 import org.apache.fop.area.Block;
@@ -50,8 +52,7 @@
  * the render background.
  */
 public class TableLayoutManager extends BlockStackingLayoutManager 
-                implements BlockLevelLayoutManager {
-    private Table fobj;
+                implements ConditionalElementListener {
     
     private TableContentLayoutManager contentLM; 
     private ColumnSetup columns = null;
@@ -63,9 +64,12 @@
     private double tableUnits;
     private boolean autoLayout = true;
 
-    //TODO space-before|after: handle space-resolution rules
-    private MinOptMax spaceBefore;
-    private MinOptMax spaceAfter;
+    private boolean discardBorderBefore;
+    private boolean discardBorderAfter;
+    private boolean discardPaddingBefore;
+    private boolean discardPaddingAfter;
+    private MinOptMax effSpaceBefore;
+    private MinOptMax effSpaceAfter;
     
     /**
      * Create a new table layout manager.
@@ -73,13 +77,12 @@
      */
     public TableLayoutManager(Table node) {
         super(node);
-        fobj = node;
         this.columns = new ColumnSetup(node);
     }
 
     /** @return the table FO */
     public Table getTable() {
-        return this.fobj;
+        return (Table)this.fobj;
     }
     
     /**
@@ -91,19 +94,31 @@
     
     /** @see org.apache.fop.layoutmgr.LayoutManager#initialize() */
     public void initialize() {
-        spaceBefore = new SpaceVal(fobj.getCommonMarginBlock().spaceBefore, this).getSpace();
-        spaceAfter = new SpaceVal(fobj.getCommonMarginBlock().spaceAfter, this).getSpace();
+        foSpaceBefore = new SpaceVal(
+                getTable().getCommonMarginBlock().spaceBefore, this).getSpace();
+        foSpaceAfter = new SpaceVal(
+                getTable().getCommonMarginBlock().spaceAfter, this).getSpace();
         
-        if (!fobj.isAutoLayout() 
-                && fobj.getInlineProgressionDimension().getOptimum(this).getEnum() != EN_AUTO) {
+        if (!getTable().isAutoLayout() 
+                && getTable().getInlineProgressionDimension().getOptimum(this).getEnum() 
+                    != EN_AUTO) {
             autoLayout = false;
         }
     }
 
+    private void resetSpaces() {
+        this.discardBorderBefore = false;        
+        this.discardBorderAfter = false;        
+        this.discardPaddingBefore = false;        
+        this.discardPaddingAfter = false;
+        this.effSpaceBefore = foSpaceBefore;
+        this.effSpaceAfter = foSpaceAfter;
+    }
+    
     private int getIPIndents() {
         int iIndents = 0;
-        iIndents += fobj.getCommonMarginBlock().startIndent.getValue(this);
-        iIndents += fobj.getCommonMarginBlock().endIndent.getValue(this);
+        iIndents += getTable().getCommonMarginBlock().startIndent.getValue(this);
+        iIndents += getTable().getCommonMarginBlock().endIndent.getValue(this);
         return iIndents;
     }
     
@@ -114,7 +129,7 @@
         
         if (!bBreakBeforeServed) {
             try {
-                if (addKnuthElementsForBreakBefore(returnList)) {
+                if (addKnuthElementsForBreakBefore(returnList, context)) {
                     return returnList;
                 }
             } finally {
@@ -125,12 +140,12 @@
         referenceBPD = context.getStackLimit().opt;
         referenceIPD = context.getRefIPD();
 
-        if (fobj.getInlineProgressionDimension().getOptimum(this).getEnum() != EN_AUTO) {
-            referenceIPD = fobj.getInlineProgressionDimension().getOptimum(this)
+        if (getTable().getInlineProgressionDimension().getOptimum(this).getEnum() != EN_AUTO) {
+            referenceIPD = getTable().getInlineProgressionDimension().getOptimum(this)
                     .getLength().getValue(this);
             contentIPD = referenceIPD;
         } else {
-            if (!fobj.isAutoLayout()) {
+            if (!getTable().isAutoLayout()) {
                 log.info("table-layout=\"fixed\" and width=\"auto\", "
                         + "but auto-layout not supported " 
                         + "=> assuming width=\"100%\"");
@@ -141,15 +156,6 @@
             log.warn("Allocated IPD exceeds available reference IPD");
         }
 
-        MinOptMax stackSize = new MinOptMax();
-        //Add spacing
-        if (spaceAfter != null) {
-            stackSize.add(spaceAfter);
-        }
-        if (spaceBefore != null) {
-            stackSize.add(spaceBefore);
-        }
-
         // either works out table of column widths or if proportional-column-width function
         // is used works out total factor, so that value of single unit can be computed.
         int sumCols = 0;
@@ -172,16 +178,28 @@
             }
         }
 
+        addKnuthElementsForSpaceBefore(returnList, alignment);
+        
+        if (getTable().isSeparateBorderModel()) {
+            addKnuthElementsForBorderPaddingBefore(returnList, !firstVisibleMarkServed);
+            firstVisibleMarkServed = true;
+        }
+
+        //Spaces, border and padding to be repeated at each break
+        addPendingMarks(context);
+
         LinkedList returnedList = null;
         LinkedList contentList = new LinkedList();
         //Position returnPosition = new NonLeafPosition(this, null);
         //Body prevLM = null;
 
         LayoutContext childLC = new LayoutContext(0);
+        /*
         childLC.setStackLimit(
               MinOptMax.subtract(context.getStackLimit(),
-                                 stackSize));
+                                 stackSize));*/
         childLC.setRefIPD(context.getRefIPD());
+        childLC.copyPendingMarksFrom(context);
 
         if (contentLM == null) {
             contentLM = new TableContentLayoutManager(this);
@@ -199,14 +217,13 @@
         //Set index values on elements coming from the content LM
         Iterator iter = returnedList.iterator();
         while (iter.hasNext()) {
-            KnuthElement el = (KnuthElement)iter.next();
+            ListElement el = (ListElement)iter.next();
             notifyPos(el.getPosition());
         }
         log.debug(returnedList);
         
         if (returnedList.size() == 1
-                && ((KnuthElement) returnedList.getFirst()).isPenalty()
-                && ((KnuthPenalty) returnedList.getFirst()).getP() == -KnuthElement.INFINITE) {
+                && ((ListElement)returnedList.getFirst()).isForcedBreak()) {
             // a descendant of this block has break-before
             if (returnList.size() == 0) {
                 // the first child (or its first child ...) has
@@ -250,8 +267,7 @@
             }*/
             contentList.addAll(returnedList);
             if (returnedList.size() > 0) {
-                if (((KnuthElement) returnedList.getLast()).isPenalty()
-                        && ((KnuthPenalty) returnedList.getLast()).getP() == -KnuthElement.INFINITE) {
+                if (((ListElement)returnedList.getLast()).isForcedBreak()) {
                     // a descendant of this block has break-after
                     if (false /*curLM.isFinished()*/) {
                         // there is no other content in this block;
@@ -267,8 +283,13 @@
             }
         }
         wrapPositionElements(contentList, returnList);
-        addKnuthElementsForBreakAfter(returnList);
+        if (getTable().isSeparateBorderModel()) {
+            addKnuthElementsForBorderPaddingAfter(returnList, true);
+        }
+        addKnuthElementsForSpaceAfter(returnList, alignment);
+        addKnuthElementsForBreakAfter(returnList, context);
         setFinished(true);
+        resetSpaces();
         return returnList;
     }
     
@@ -282,14 +303,9 @@
     public void addAreas(PositionIterator parentIter,
                          LayoutContext layoutContext) {
         getParentArea(null);
-        getPSLM().addIDToPage(fobj.getId());
+        getPSLM().addIDToPage(getTable().getId());
 
-        // if adjusted space before
-        double adjust = layoutContext.getSpaceAdjust();
-        addBlockSpacing(adjust, spaceBefore);
-        spaceBefore = null;
-
-        int startXOffset = fobj.getCommonMarginBlock().startIndent.getValue(this);
+        int startXOffset = getTable().getCommonMarginBlock().startIndent.getValue(this);
         
         // add column, body then row areas
 
@@ -305,25 +321,29 @@
 
         curBlockArea.setBPD(tableHeight);
 
-        if (fobj.isSeparateBorderModel()) {
-            TraitSetter.addBorders(curBlockArea, fobj.getCommonBorderPaddingBackground(), this);
+        if (getTable().isSeparateBorderModel()) {
+            TraitSetter.addBorders(curBlockArea, 
+                    getTable().getCommonBorderPaddingBackground(), 
+                    discardBorderBefore, discardBorderAfter, false, false, this);
+            TraitSetter.addPadding(curBlockArea, 
+                    getTable().getCommonBorderPaddingBackground(), 
+                    discardPaddingBefore, discardPaddingAfter, false, false, this);
         }
         TraitSetter.addBackground(curBlockArea, 
-                fobj.getCommonBorderPaddingBackground(),
+                getTable().getCommonBorderPaddingBackground(),
                 this);
         TraitSetter.addMargins(curBlockArea,
-                fobj.getCommonBorderPaddingBackground(), 
-                fobj.getCommonMarginBlock(),
+                getTable().getCommonBorderPaddingBackground(), 
+                getTable().getCommonMarginBlock(),
                 this);
         TraitSetter.addBreaks(curBlockArea, 
-                fobj.getBreakBefore(), fobj.getBreakAfter());
+                getTable().getBreakBefore(), getTable().getBreakAfter());
+        TraitSetter.addSpaceBeforeAfter(curBlockArea, layoutContext.getSpaceAdjust(), 
+                effSpaceBefore, effSpaceAfter);
 
         flush();
 
-        // if adjusted space after
-        addBlockSpacing(adjust, spaceAfter);
-
-        //bodyBreaks.clear();
+        resetSpaces();
         curBlockArea = null;
     }
 
@@ -378,17 +398,13 @@
         }
     }
 
-    /**
-     * @see org.apache.fop.layoutmgr.BlockLevelLayoutManager#negotiateBPDAdjustment(int, org.apache.fop.layoutmgr.KnuthElement)
-     */
+    /** @see org.apache.fop.layoutmgr.BlockLevelLayoutManager */
     public int negotiateBPDAdjustment(int adj, KnuthElement lastElement) {
         // TODO Auto-generated method stub
         return 0;
     }
 
-    /**
-     * @see org.apache.fop.layoutmgr.BlockLevelLayoutManager#discardSpace(org.apache.fop.layoutmgr.KnuthGlue)
-     */
+    /** @see org.apache.fop.layoutmgr.BlockLevelLayoutManager */
     public void discardSpace(KnuthGlue spaceGlue) {
         // TODO Auto-generated method stub
         
@@ -400,24 +416,24 @@
     public boolean mustKeepTogether() {
         //TODO Keeps will have to be more sophisticated sooner or later
         return ((BlockLevelLayoutManager)getParent()).mustKeepTogether() 
-                || !fobj.getKeepTogether().getWithinPage().isAuto()
-                || !fobj.getKeepTogether().getWithinColumn().isAuto();
+                || !getTable().getKeepTogether().getWithinPage().isAuto()
+                || !getTable().getKeepTogether().getWithinColumn().isAuto();
     }
 
     /**
      * @see org.apache.fop.layoutmgr.BlockLevelLayoutManager#mustKeepWithPrevious()
      */
     public boolean mustKeepWithPrevious() {
-        return !fobj.getKeepWithPrevious().getWithinPage().isAuto()
-                || !fobj.getKeepWithPrevious().getWithinColumn().isAuto();
+        return !getTable().getKeepWithPrevious().getWithinPage().isAuto()
+                || !getTable().getKeepWithPrevious().getWithinColumn().isAuto();
     }
 
     /**
      * @see org.apache.fop.layoutmgr.BlockLevelLayoutManager#mustKeepWithNext()
      */
     public boolean mustKeepWithNext() {
-        return !fobj.getKeepWithNext().getWithinPage().isAuto()
-                || !fobj.getKeepWithNext().getWithinColumn().isAuto();
+        return !getTable().getKeepWithNext().getWithinPage().isAuto()
+                || !getTable().getKeepWithNext().getWithinColumn().isAuto();
     }
 
     // --------- Property Resolution related functions --------- //
@@ -459,6 +475,51 @@
      */
     public int getContentAreaBPD() {
         return referenceBPD;
+    }
+    
+    /** @see org.apache.fop.layoutmgr.ConditionalElementListener */
+    public void notifySpace(RelSide side, MinOptMax effectiveLength) {
+        if (RelSide.BEFORE == side) {
+            if (log.isDebugEnabled()) {
+                log.debug(this + ": Space " + side + ", " 
+                        + this.effSpaceBefore + "-> " + effectiveLength);
+            }
+            this.effSpaceBefore = effectiveLength;
+        } else {
+            if (log.isDebugEnabled()) {
+                log.debug(this + ": Space " + side + ", " 
+                        + this.effSpaceAfter + "-> " + effectiveLength);
+            }
+            this.effSpaceAfter = effectiveLength;
+        }
+    }
+
+    /** @see org.apache.fop.layoutmgr.ConditionalElementListener */
+    public void notifyBorder(RelSide side, MinOptMax effectiveLength) {
+        if (effectiveLength == null) {
+            if (RelSide.BEFORE == side) {
+                this.discardBorderBefore = true;
+            } else {
+                this.discardBorderAfter = true;
+            }
+        }
+        if (log.isDebugEnabled()) {
+            log.debug(this + ": Border " + side + " -> " + effectiveLength);
+        }
+    }
+
+    /** @see org.apache.fop.layoutmgr.ConditionalElementListener */
+    public void notifyPadding(RelSide side, MinOptMax effectiveLength) {
+        if (effectiveLength == null) {
+            if (RelSide.BEFORE == side) {
+                this.discardPaddingBefore = true;
+            } else {
+                this.discardPaddingAfter = true;
+            }
+        }
+        if (log.isDebugEnabled()) {
+            log.debug(this + ": Padding " + side + " -> " + effectiveLength);
+        }
     }
     
 }



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