]> source.dussan.org Git - xmlgraphics-fop.git/commitdiff
Adjusting verticals spaces (coming from space-before and space-after properties)...
authorLuca Furini <lfurini@apache.org>
Tue, 2 Aug 2005 09:05:25 +0000 (09:05 +0000)
committerLuca Furini <lfurini@apache.org>
Tue, 2 Aug 2005 09:05:25 +0000 (09:05 +0000)
git-svn-id: https://svn.apache.org/repos/asf/xmlgraphics/fop/trunk@226973 13f79535-47bb-0310-9956-ffa450edef68

src/java/org/apache/fop/layoutmgr/AbstractBreaker.java
src/java/org/apache/fop/layoutmgr/AreaAdditionUtil.java
src/java/org/apache/fop/layoutmgr/BlockLayoutManager.java
src/java/org/apache/fop/layoutmgr/BlockStackingLayoutManager.java
src/java/org/apache/fop/layoutmgr/PageBreakingAlgorithm.java
src/java/org/apache/fop/layoutmgr/list/ListBlockLayoutManager.java
src/java/org/apache/fop/layoutmgr/list/ListItemContentLayoutManager.java
src/java/org/apache/fop/layoutmgr/list/ListItemLayoutManager.java

index df753a1a1f4e2d3a42b2f0c599ed65482580198c..d5ba5513fd384b42f80633f0fd8ff978b5ec9788 100644 (file)
@@ -314,9 +314,16 @@ public abstract class AbstractBreaker {
             // at the beginning of the line
             effectiveListIterator = effectiveList
                     .listIterator(startElementIndex);
+            KnuthElement firstElement;
             while (effectiveListIterator.hasNext()
-                    && !((KnuthElement) effectiveListIterator.next())
+                    && !(firstElement = (KnuthElement) effectiveListIterator.next())
                             .isBox()) {
+                if (firstElement.isGlue()) {
+                    // discard the space representd by the glue element
+                    ((BlockLevelLayoutManager) firstElement
+                            .getLayoutManager())
+                            .discardSpace((KnuthGlue) firstElement);
+                }
                 startElementIndex++;
             }
 
@@ -324,6 +331,8 @@ public abstract class AbstractBreaker {
                 log.debug("     addAreas from " + startElementIndex
                         + " to " + endElementIndex);
                 childLC = new LayoutContext(0);
+                // set the space adjustment ratio
+                childLC.setSpaceAdjust(pbp.bpdAdjust);
                 // add space before if display-align is center or bottom
                 // add space after if display-align is distribute and
                 // this is not the last page
index 13198cae84d8762a96656816c4fa384e92991718..44ad1496bf300c73e32f5d5835b6964821dfec7d 100644 (file)
@@ -80,6 +80,8 @@ public class AreaAdditionUtil {
             // Add the block areas to Area
             lc.setFlags(LayoutContext.FIRST_AREA, childLM == firstLM);
             lc.setFlags(LayoutContext.LAST_AREA, childLM == lastLM);
+            // set the space adjustment ratio
+            lc.setSpaceAdjust(layoutContext.getSpaceAdjust());
             // set space before for the first LM, in order to implement
             // display-align = center or after
             lc.setSpaceBefore((childLM == firstLM ? layoutContext.getSpaceBefore() : 0));
index 83be99b71528d4ad020ccf2aa3ab27c17899fb08..636055cb5780a43ccd4ee2404b250502dd4a6a14 100644 (file)
@@ -41,17 +41,6 @@ public class BlockLayoutManager extends BlockStackingLayoutManager {
     /** Iterator over the child layout managers. */
     protected ListIterator proxyLMiter;
 
-    /* holds the (one-time use) fo:block space-before
-       and -after properties.  Large fo:blocks are split
-       into multiple Area.Blocks to accomodate the subsequent
-       regions (pages) they are placed on.  space-before
-       is applied at the beginning of the first
-       Block and space-after at the end of the last Block
-       used in rendering the fo:block.
-    */
-    private MinOptMax foBlockSpaceBefore = null;
-    private MinOptMax foBlockSpaceAfter = null;
-
     private int lead = 12000;
     private int lineHeight = 14000;
     private int follow = 2000;
@@ -79,17 +68,18 @@ public class BlockLayoutManager extends BlockStackingLayoutManager {
     }
 
     private void initialize() {
-        foBlockSpaceBefore = new SpaceVal(getBlockFO().getCommonMarginBlock().spaceBefore).getSpace();
-/*LF*/  bpUnit = 0; //layoutProps.blockProgressionUnit;
-/*LF*/  if (bpUnit == 0) {
-/*LF*/      // use optimum space values
-/*LF*/      adjustedSpaceBefore = getBlockFO().getCommonMarginBlock().spaceBefore.getSpace().getOptimum().getLength().getValue();
-/*LF*/      adjustedSpaceAfter = getBlockFO().getCommonMarginBlock().spaceAfter.getSpace().getOptimum().getLength().getValue();
-/*LF*/  } else {
-/*LF*/      // use minimum space values
-/*LF*/      adjustedSpaceBefore = getBlockFO().getCommonMarginBlock().spaceBefore.getSpace().getMinimum().getLength().getValue();
-/*LF*/      adjustedSpaceAfter = getBlockFO().getCommonMarginBlock().spaceAfter.getSpace().getMinimum().getLength().getValue();
-/*LF*/  }
+        foSpaceBefore = new SpaceVal(getBlockFO().getCommonMarginBlock().spaceBefore).getSpace();
+        foSpaceAfter = new SpaceVal(getBlockFO().getCommonMarginBlock().spaceAfter).getSpace();
+        bpUnit = 0; // non-standard extension
+        if (bpUnit == 0) {
+            // use optimum space values
+            adjustedSpaceBefore = getBlockFO().getCommonMarginBlock().spaceBefore.getSpace().getOptimum().getLength().getValue();
+            adjustedSpaceAfter = getBlockFO().getCommonMarginBlock().spaceAfter.getSpace().getOptimum().getLength().getValue();
+        } else {
+            // use minimum space values
+            adjustedSpaceBefore = getBlockFO().getCommonMarginBlock().spaceBefore.getSpace().getMinimum().getLength().getValue();
+            adjustedSpaceAfter = getBlockFO().getCommonMarginBlock().spaceAfter.getSpace().getMinimum().getLength().getValue();
+        }
     }
 
     /**
@@ -203,7 +193,7 @@ public class BlockLayoutManager extends BlockStackingLayoutManager {
         getParentArea(null);
 
         // if this will create the first block area in a page
-        // and display-align is bottom or center, add space before
+        // and display-align is after or center, add space before
         if (layoutContext.getSpaceBefore() > 0) {
             addBlockSpacing(0.0, new MinOptMax(layoutContext.getSpaceBefore()));
         }
@@ -322,23 +312,23 @@ public class BlockLayoutManager extends BlockStackingLayoutManager {
             // add space before and / or after the paragraph
             // to reach a multiple of bpUnit
             if (bSpaceBefore && bSpaceAfter) {
-                foBlockSpaceBefore = new SpaceVal(getBlockFO().getCommonMarginBlock().spaceBefore).getSpace();
-                foBlockSpaceAfter = new SpaceVal(getBlockFO().getCommonMarginBlock().spaceAfter).getSpace();
+                foSpaceBefore = new SpaceVal(getBlockFO().getCommonMarginBlock().spaceBefore).getSpace();
+                foSpaceAfter = new SpaceVal(getBlockFO().getCommonMarginBlock().spaceAfter).getSpace();
                 adjustedSpaceBefore = (neededUnits(splitLength
-                        + foBlockSpaceBefore.min
-                        + foBlockSpaceAfter.min)
+                        + foSpaceBefore.min
+                        + foSpaceAfter.min)
                         * bpUnit - splitLength) / 2;
                 adjustedSpaceAfter = neededUnits(splitLength
-                        + foBlockSpaceBefore.min
-                        + foBlockSpaceAfter.min)
+                        + foSpaceBefore.min
+                        + foSpaceAfter.min)
                         * bpUnit - splitLength - adjustedSpaceBefore;
                 } else if (bSpaceBefore) {
                 adjustedSpaceBefore = neededUnits(splitLength
-                        + foBlockSpaceBefore.min)
+                        + foSpaceBefore.min)
                         * bpUnit - splitLength;
                 } else {
                 adjustedSpaceAfter = neededUnits(splitLength
-                        + foBlockSpaceAfter.min)
+                        + foSpaceAfter.min)
                         * bpUnit - splitLength;
                 }
             //System.out.println("spazio prima = " + adjustedSpaceBefore
@@ -347,12 +337,15 @@ public class BlockLayoutManager extends BlockStackingLayoutManager {
             childPosIter = new KnuthPossPosIter(splitList, 0, splitList
                     .size());
             //}
-            }
+        }
 
         // if adjusted space before
-        if (bSpaceBefore) {
-            addBlockSpacing(0, new MinOptMax(adjustedSpaceBefore));
-        }
+        double adjust = layoutContext.getSpaceAdjust();
+        addBlockSpacing(adjust, foSpaceBefore);
+        foSpaceBefore = null;
+        //if (bSpaceBefore) {
+        //    addBlockSpacing(0, new MinOptMax(adjustedSpaceBefore));
+        //}
 
         while ((childLM = childPosIter.getNextChildLM()) != null) {
             // set last area flag
@@ -372,9 +365,10 @@ public class BlockLayoutManager extends BlockStackingLayoutManager {
         flush();
 
         // if adjusted space after
-        if (bSpaceAfter) {
-            addBlockSpacing(0, new MinOptMax(adjustedSpaceAfter));
-        }
+        addBlockSpacing(adjust, foSpaceAfter);
+        //if (bSpaceAfter) {
+        //    addBlockSpacing(0, new MinOptMax(adjustedSpaceAfter));
+        //}
 
         curBlockArea = null;
     }
index 9179e71ceb9d45124cde56eb308d8242f0418b58..d1f656b58f3a231390cd1ff5867fd2da029a9608 100644 (file)
@@ -62,7 +62,18 @@ public abstract class BlockStackingLayoutManager extends AbstractLayoutManager
     protected boolean bSpaceBeforeServed = false;
     /** Reference IPD available */
     protected int referenceIPD = 0;
-    
+
+    /* holds the (one-time use) fo:block space-before
+       and -after properties.  Large fo:blocks are split
+       into multiple Area.Blocks to accomodate the subsequent
+       regions (pages) they are placed on.  space-before
+       is applied at the beginning of the first
+       Block and space-after at the end of the last Block
+       used in rendering the fo:block.
+    */
+    protected MinOptMax foSpaceBefore = null;
+    protected MinOptMax foSpaceAfter = null;
+
     private int lastGeneratedPosition = -1;
     private int smallestPosNumberChecked = Integer.MAX_VALUE;
 
@@ -506,22 +517,24 @@ public abstract class BlockStackingLayoutManager extends AbstractLayoutManager
     }
 
     public void discardSpace(KnuthGlue spaceGlue) {
-/*LF*/  //System.out.println("  BLM.discardSpace> " + spaceGlue.getPosition().getClass().getName());
+        //System.out.println("  BLM.discardSpace> " + spaceGlue.getPosition().getClass().getName());
         Position innerPosition = ((NonLeafPosition) spaceGlue.getPosition()).getPosition();
 
-/*LF*/  if (innerPosition == null || innerPosition.getLM() == this) {
+        if (innerPosition == null || innerPosition.getLM() == this) {
             // if this block has block-progression-unit > 0, innerPosition can be
             // a MappingPosition
             // spaceGlue represents space before or space after of this block
             if (spaceGlue.getAdjustmentClass() == SPACE_BEFORE_ADJUSTMENT) {
                 // space-before must be discarded
                 adjustedSpaceBefore = 0;
+                foSpaceBefore = new MinOptMax(0);
             } else {
                 // space-after must be discarded
                 adjustedSpaceAfter = 0;
+                foSpaceAfter = new MinOptMax(0);
                 //TODO Why are both cases handled in the same way?
             }
-/*LF*/  } else {
+        } else {
             // this element was not created by this BlockLM
             NonLeafPosition savedPos = (NonLeafPosition)spaceGlue.getPosition();
             spaceGlue.setPosition(innerPosition);
index a303630e7a9d325fa7d48f588ad6e0d3f6242bfb..f0cd2c357f93d22c7452ba19713b49efa377492d 100644 (file)
@@ -700,9 +700,27 @@ class PageBreakingAlgorithm extends BreakingAlgorithm {
         //int difference = (bestActiveNode.line < total) ? bestActiveNode.difference : bestActiveNode.difference + fillerMinWidth;
         int difference = bestActiveNode.difference;
         int blockAlignment = (bestActiveNode.line < total) ? alignment : alignmentLast;
-        double ratio = (blockAlignment == org.apache.fop.fo.Constants.EN_JUSTIFY
-                        || bestActiveNode.adjustRatio < 0) ? bestActiveNode.adjustRatio : 0;
-
+        // it is always allowed to adjust space, so the ratio must be set regardless of
+        // the value of the property display-align; the ratio must be <= 1
+        double ratio = bestActiveNode.adjustRatio;
+        if (ratio < 0) {
+            // page break with a negative difference:
+            // spaces always have enough shrink
+            difference = 0;
+        } else if (ratio <= 1 && bestActiveNode.line < total) {
+            // not-last page break with a positive difference smaller than the available stretch:
+            // spaces can stretch to fill the whole difference
+            difference = 0;
+        } else if (ratio > 1) {
+            // not-last page with a positive difference greater than the available stretch
+            // spaces can stretch to fill the difference only partially
+            ratio = 1;
+            difference -= bestActiveNode.availableStretch;
+        } else {
+            // last page with a positive difference:
+            // spaces do not need to stretch
+            ratio = 0;
+        }
         // compute the indexes of the first footnote list and the first element in that list
         int firstListIndex = ((KnuthPageNode) bestActiveNode.previous).footnoteListIndex;
         int firstElementIndex = ((KnuthPageNode) bestActiveNode.previous).footnoteElementIndex;
index 8536c062ed947713f3e6cce981897bf9441653dc..4d97a4a778a793df125c362ce9e1aa8f046cc3b7 100644 (file)
@@ -45,8 +45,6 @@ public class ListBlockLayoutManager extends BlockStackingLayoutManager {
     private Block curBlockArea;
 
     //TODO space-before|after: handle space-resolution rules
-    private MinOptMax spaceBefore;
-    private MinOptMax spaceAfter;
 
     private static class StackingIter extends PositionIterator {
         StackingIter(Iterator parentIter) {
@@ -89,8 +87,8 @@ public class ListBlockLayoutManager extends BlockStackingLayoutManager {
     }
 
     private void initialize() {
-        spaceBefore = new SpaceVal(getListBlockFO().getCommonMarginBlock().spaceBefore).getSpace();
-        spaceAfter = new SpaceVal(getListBlockFO().getCommonMarginBlock().spaceAfter).getSpace();
+        foSpaceBefore = new SpaceVal(getListBlockFO().getCommonMarginBlock().spaceBefore).getSpace();
+        foSpaceAfter = new SpaceVal(getListBlockFO().getCommonMarginBlock().spaceAfter).getSpace();
     }
 
     private int getIPIndents() {
@@ -116,11 +114,17 @@ public class ListBlockLayoutManager extends BlockStackingLayoutManager {
     public void addAreas(PositionIterator parentIter,
                          LayoutContext layoutContext) {
         getParentArea(null);
-        
+
+        // if this will create the first block area in a page
+        // and display-align is after or center, add space before
+        if (layoutContext.getSpaceBefore() > 0) {
+            addBlockSpacing(0.0, new MinOptMax(layoutContext.getSpaceBefore()));
+        }
+
         // if adjusted space before
         double adjust = layoutContext.getSpaceAdjust();
-        addBlockSpacing(adjust, spaceBefore);
-        spaceBefore = null;
+        addBlockSpacing(adjust, foSpaceBefore);
+        foSpaceBefore = null;
         
         getPSLM().addIDToPage(getListBlockFO().getId());
 
@@ -164,6 +168,8 @@ public class ListBlockLayoutManager extends BlockStackingLayoutManager {
         StackingIter childPosIter = new StackingIter(positionList.listIterator());
         while ((childLM = childPosIter.getNextChildLM()) != null) {
             // Add the block areas to Area
+            // set the space adjustment ratio
+            lc.setSpaceAdjust(layoutContext.getSpaceAdjust());
             lc.setFlags(LayoutContext.FIRST_AREA, childLM == firstLM);
             lc.setFlags(LayoutContext.LAST_AREA, childLM == lastLM);
             lc.setStackLimit(layoutContext.getStackLimit());
@@ -177,7 +183,7 @@ public class ListBlockLayoutManager extends BlockStackingLayoutManager {
         flush();
 
         // if adjusted space after
-        addBlockSpacing(adjust, spaceAfter);
+        addBlockSpacing(adjust, foSpaceAfter);
         
         curBlockArea = null;
     }
index d86d06b3112aa8b6581c38db452b2ce91c338cfb..a9bf81bbea41e6b29fc5ad9dfcb3e4fd3f9b24bb 100644 (file)
@@ -155,6 +155,8 @@ public class ListItemContentLayoutManager extends BlockStackingLayoutManager {
             // Add the block areas to Area
             lc.setFlags(LayoutContext.FIRST_AREA, childLM == firstLM);
             lc.setFlags(LayoutContext.LAST_AREA, childLM == lastLM);
+            // set the space adjustment ratio
+            lc.setSpaceAdjust(layoutContext.getSpaceAdjust());
             lc.setStackLimit(layoutContext.getStackLimit());
             childLM.addAreas(childPosIter, lc);
         }
index 7092078cc6d817c9b0fee369a50e4fbbabb81dfa..e0ea656dd7a52501fba52fcd83019a7229827aee 100644 (file)
@@ -59,8 +59,6 @@ public class ListItemLayoutManager extends BlockStackingLayoutManager {
     private int listItemHeight;
 
     //TODO space-before|after: handle space-resolution rules
-    private MinOptMax spaceBefore;
-    private MinOptMax spaceAfter;
     
     private boolean keepWithNextPendingOnLabel;
     private boolean keepWithNextPendingOnBody;
@@ -154,8 +152,8 @@ public class ListItemLayoutManager extends BlockStackingLayoutManager {
     }
 
     private void initialize() {
-        spaceBefore = new SpaceVal(getListItemFO().getCommonMarginBlock().spaceBefore).getSpace();
-        spaceAfter = new SpaceVal(getListItemFO().getCommonMarginBlock().spaceAfter).getSpace();
+        foSpaceBefore = new SpaceVal(getListItemFO().getCommonMarginBlock().spaceBefore).getSpace();
+        foSpaceAfter = new SpaceVal(getListItemFO().getCommonMarginBlock().spaceAfter).getSpace();
     }
 
     private int getIPIndents() {
@@ -426,8 +424,8 @@ public class ListItemLayoutManager extends BlockStackingLayoutManager {
 
         // if adjusted space before
         double adjust = layoutContext.getSpaceAdjust();
-        addBlockSpacing(adjust, spaceBefore);
-        spaceBefore = null;
+        addBlockSpacing(adjust, foSpaceBefore);
+        foSpaceBefore = null;
 
         getPSLM().addIDToPage(getListItemFO().getId());
 
@@ -469,6 +467,8 @@ public class ListItemLayoutManager extends BlockStackingLayoutManager {
                     labelFirstIndex, labelLastIndex + 1);
             lc.setFlags(LayoutContext.FIRST_AREA, layoutContext.isFirstArea());
             lc.setFlags(LayoutContext.LAST_AREA, layoutContext.isLastArea());
+            // set the space adjustment ratio
+            lc.setSpaceAdjust(layoutContext.getSpaceAdjust());
             // TO DO: use the right stack limit for the label
             lc.setStackLimit(layoutContext.getStackLimit());
             label.addAreas(labelIter, lc);
@@ -488,6 +488,8 @@ public class ListItemLayoutManager extends BlockStackingLayoutManager {
                     bodyFirstIndex, bodyLastIndex + 1);
             lc.setFlags(LayoutContext.FIRST_AREA, layoutContext.isFirstArea());
             lc.setFlags(LayoutContext.LAST_AREA, layoutContext.isLastArea());
+            // set the space adjustment ratio
+            lc.setSpaceAdjust(layoutContext.getSpaceAdjust());
             // TO DO: use the right stack limit for the body
             lc.setStackLimit(layoutContext.getStackLimit());
             body.addAreas(bodyIter, lc);
@@ -505,7 +507,7 @@ public class ListItemLayoutManager extends BlockStackingLayoutManager {
         flush();
 
         // if adjusted space after
-        addBlockSpacing(adjust, spaceAfter);
+        addBlockSpacing(adjust, foSpaceAfter);
         
         curBlockArea = null;
     }