diff options
author | Jeremias Maerki <jeremias@apache.org> | 2005-05-18 15:25:11 +0000 |
---|---|---|
committer | Jeremias Maerki <jeremias@apache.org> | 2005-05-18 15:25:11 +0000 |
commit | ef1396bf39fd12582c23101ad31f5561862d3fe4 (patch) | |
tree | be8795e97bb05137bfd305104f7a6c0d63de95fa /src/java | |
parent | 407531b9a51d5175eeb1234613fcd0ba57e8cced (diff) | |
download | xmlgraphics-fop-ef1396bf39fd12582c23101ad31f5561862d3fe4.tar.gz xmlgraphics-fop-ef1396bf39fd12582c23101ad31f5561862d3fe4.zip |
Bugfix for space-after on fixed-height block-containers.
Code cleanup.
git-svn-id: https://svn.apache.org/repos/asf/xmlgraphics/fop/trunk@198652 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'src/java')
-rw-r--r-- | src/java/org/apache/fop/layoutmgr/BlockContainerLayoutManager.java | 209 |
1 files changed, 88 insertions, 121 deletions
diff --git a/src/java/org/apache/fop/layoutmgr/BlockContainerLayoutManager.java b/src/java/org/apache/fop/layoutmgr/BlockContainerLayoutManager.java index bf9095fcf..8a1c3c86d 100644 --- a/src/java/org/apache/fop/layoutmgr/BlockContainerLayoutManager.java +++ b/src/java/org/apache/fop/layoutmgr/BlockContainerLayoutManager.java @@ -19,7 +19,6 @@ package org.apache.fop.layoutmgr; import java.util.LinkedList; -import java.util.List; import java.util.ListIterator; import java.awt.Point; import java.awt.geom.Rectangle2D; @@ -33,7 +32,6 @@ import org.apache.fop.fo.properties.CommonAbsolutePosition; import org.apache.fop.area.CTM; import org.apache.fop.datatypes.FODimension; import org.apache.fop.datatypes.Length; -import org.apache.fop.datatypes.PercentBase; import org.apache.fop.traits.MinOptMax; import org.apache.fop.traits.SpaceVal; @@ -45,8 +43,6 @@ public class BlockContainerLayoutManager extends BlockStackingLayoutManager { private BlockViewport viewportBlockArea; private Block referenceArea; - private List childBreaks = new java.util.ArrayList(); - private CommonAbsolutePosition abProps; private FODimension relDims; private CTM absoluteCTM; @@ -55,12 +51,9 @@ public class BlockContainerLayoutManager extends BlockStackingLayoutManager { private Length height; private int vpContentIPD; private int vpContentBPD; - private int usedBPD; // When viewport should grow with the content. private boolean autoHeight = true; - - private int referenceIPD; /* holds the (one-time use) fo:block space-before and -after properties. Large fo:blocks are split @@ -73,15 +66,6 @@ public class BlockContainerLayoutManager extends BlockStackingLayoutManager { //TODO space-before|after: handle space-resolution rules private MinOptMax foBlockSpaceBefore; private MinOptMax foBlockSpaceAfter; - - private boolean bBreakBeforeServed = false; - private boolean bSpaceBeforeServed = false; - - /*LF*/ - /** Only used to store the original list when createUnitElements is called */ - //TODO Maybe pull up as protected member if also used in this class (JM) - private LinkedList storedList = null; - /** * Create a new block container layout manager. @@ -163,9 +147,7 @@ public class BlockContainerLayoutManager extends BlockStackingLayoutManager { return (abProps.absolutePosition == EN_FIXED); } - /** - * @see org.apache.fop.layoutmgr.LayoutManager#getNextKnuthElements(org.apache.fop.layoutmgr.LayoutContext, int) - */ + /** @see org.apache.fop.layoutmgr.LayoutManager */ public LinkedList getNextKnuthElements(LayoutContext context, int alignment) { if (isAbsoluteOrFixed()) { return getNextKnuthElementsAbsolute(context, alignment); @@ -419,8 +401,6 @@ public class BlockContainerLayoutManager extends BlockStackingLayoutManager { boolean contentOverflows = breaker.isOverflow(); LinkedList returnList = new LinkedList(); if (!breaker.isEmpty()) { - usedBPD = relDims.bpd - breaker.getDifferenceOfFirstPart(); - Position bcPosition = new BlockContainerPosition(this, breaker); returnList.add(new KnuthBox(0, bcPosition, false)); @@ -617,7 +597,7 @@ public class BlockContainerLayoutManager extends BlockStackingLayoutManager { // pos was created by this BCLM and was inside an element // representing space before or after // this means the space was not discarded - if (positionList.size() == 0) { + if (positionList.size() == 0 && bcpos == null) { // pos was in the element representing space-before bSpaceBefore = true; /* LF *///System.out.println(" space-before"); @@ -642,94 +622,93 @@ public class BlockContainerLayoutManager extends BlockStackingLayoutManager { } if (bcpos == null) { - - if (bpUnit == 0) { - // the Positions in positionList were inside the elements - // created by the LineLM - childPosIter = new StackingIter(positionList.listIterator()); - } else { - // the Positions in positionList were inside the elements - // created by the BCLM in the createUnitElements() method - //if (((Position) positionList.getLast()) instanceof - // LeafPosition) { - // // the last item inside positionList is a LeafPosition - // // (a LineBreakPosition, more precisely); this means that - // // the whole paragraph is on the same page - // System.out.println("paragrafo intero"); - // childPosIter = new KnuthPossPosIter(storedList, 0, - // storedList.size()); - //} else { - // // the last item inside positionList is a Position; - // // this means that the paragraph has been split - // // between consecutive pages - LinkedList splitList = new LinkedList(); - int splitLength = 0; - int iFirst = ((MappingPosition) positionList.getFirst()).getFirstIndex(); - int iLast = ((MappingPosition) positionList.getLast()).getLastIndex(); - // copy from storedList to splitList all the elements from - // iFirst to iLast - ListIterator storedListIterator = storedList.listIterator(iFirst); - while (storedListIterator.nextIndex() <= iLast) { - KnuthElement element = (KnuthElement) storedListIterator - .next(); - // some elements in storedList (i.e. penalty items) were created - // by this BlockLM, and must be ignored - if (element.getLayoutManager() != this) { - splitList.add(element); - splitLength += element.getW(); - lastLM = element.getLayoutManager(); + if (bpUnit == 0) { + // the Positions in positionList were inside the elements + // created by the LineLM + childPosIter = new StackingIter(positionList.listIterator()); + } else { + // the Positions in positionList were inside the elements + // created by the BCLM in the createUnitElements() method + //if (((Position) positionList.getLast()) instanceof + // LeafPosition) { + // // the last item inside positionList is a LeafPosition + // // (a LineBreakPosition, more precisely); this means that + // // the whole paragraph is on the same page + // System.out.println("paragrafo intero"); + // childPosIter = new KnuthPossPosIter(storedList, 0, + // storedList.size()); + //} else { + // // the last item inside positionList is a Position; + // // this means that the paragraph has been split + // // between consecutive pages + LinkedList splitList = new LinkedList(); + int splitLength = 0; + int iFirst = ((MappingPosition) positionList.getFirst()).getFirstIndex(); + int iLast = ((MappingPosition) positionList.getLast()).getLastIndex(); + // copy from storedList to splitList all the elements from + // iFirst to iLast + ListIterator storedListIterator = storedList.listIterator(iFirst); + while (storedListIterator.nextIndex() <= iLast) { + KnuthElement element = (KnuthElement) storedListIterator + .next(); + // some elements in storedList (i.e. penalty items) were created + // by this BlockLM, and must be ignored + if (element.getLayoutManager() != this) { + splitList.add(element); + splitLength += element.getW(); + lastLM = element.getLayoutManager(); + } + } + //System.out.println("addAreas riferito a storedList da " + + // iFirst + " a " + iLast); + //System.out.println("splitLength= " + splitLength + // + " (" + neededUnits(splitLength) + " unita') " + // + (neededUnits(splitLength) * bpUnit - splitLength) + " spazi"); + // add space before and / or after the paragraph + // to reach a multiple of bpUnit + if (bSpaceBefore && bSpaceAfter) { + foBlockSpaceBefore = new SpaceVal(getBlockContainerFO() + .getCommonMarginBlock().spaceBefore).getSpace(); + foBlockSpaceAfter = new SpaceVal(getBlockContainerFO() + .getCommonMarginBlock().spaceAfter).getSpace(); + adjustedSpaceBefore = (neededUnits(splitLength + + foBlockSpaceBefore.min + + foBlockSpaceAfter.min) + * bpUnit - splitLength) / 2; + adjustedSpaceAfter = neededUnits(splitLength + + foBlockSpaceBefore.min + + foBlockSpaceAfter.min) + * bpUnit - splitLength - adjustedSpaceBefore; + } else if (bSpaceBefore) { + adjustedSpaceBefore = neededUnits(splitLength + + foBlockSpaceBefore.min) + * bpUnit - splitLength; + } else { + adjustedSpaceAfter = neededUnits(splitLength + + foBlockSpaceAfter.min) + * bpUnit - splitLength; } + //System.out.println("spazio prima = " + adjustedSpaceBefore + // + " spazio dopo = " + adjustedSpaceAfter + " totale = " + + // (adjustedSpaceBefore + adjustedSpaceAfter + splitLength)); + childPosIter = new KnuthPossPosIter(splitList, 0, splitList + .size()); + //} } - //System.out.println("addAreas riferito a storedList da " + - // iFirst + " a " + iLast); - //System.out.println("splitLength= " + splitLength - // + " (" + neededUnits(splitLength) + " unita') " - // + (neededUnits(splitLength) * bpUnit - splitLength) + " spazi"); - // add space before and / or after the paragraph - // to reach a multiple of bpUnit - if (bSpaceBefore && bSpaceAfter) { - foBlockSpaceBefore = new SpaceVal(getBlockContainerFO() - .getCommonMarginBlock().spaceBefore).getSpace(); - foBlockSpaceAfter = new SpaceVal(getBlockContainerFO() - .getCommonMarginBlock().spaceAfter).getSpace(); - adjustedSpaceBefore = (neededUnits(splitLength - + foBlockSpaceBefore.min - + foBlockSpaceAfter.min) - * bpUnit - splitLength) / 2; - adjustedSpaceAfter = neededUnits(splitLength - + foBlockSpaceBefore.min - + foBlockSpaceAfter.min) - * bpUnit - splitLength - adjustedSpaceBefore; - } else if (bSpaceBefore) { - adjustedSpaceBefore = neededUnits(splitLength - + foBlockSpaceBefore.min) - * bpUnit - splitLength; - } else { - adjustedSpaceAfter = neededUnits(splitLength - + foBlockSpaceAfter.min) - * bpUnit - splitLength; + + // if adjusted space before + if (bSpaceBefore) { + addBlockSpacing(0, new MinOptMax(adjustedSpaceBefore)); + } + + while ((childLM = childPosIter.getNextChildLM()) != null) { + // set last area flag + lc.setFlags(LayoutContext.LAST_AREA, + (layoutContext.isLastArea() && childLM == lastLM)); + /*LF*/lc.setStackLimit(layoutContext.getStackLimit()); + // Add the line areas to Area + childLM.addAreas(childPosIter, lc); } - //System.out.println("spazio prima = " + adjustedSpaceBefore - // + " spazio dopo = " + adjustedSpaceAfter + " totale = " + - // (adjustedSpaceBefore + adjustedSpaceAfter + splitLength)); - childPosIter = new KnuthPossPosIter(splitList, 0, splitList - .size()); - //} - } - - // if adjusted space before - if (bSpaceBefore) { - addBlockSpacing(0, new MinOptMax(adjustedSpaceBefore)); - } - - while ((childLM = childPosIter.getNextChildLM()) != null) { - // set last area flag - lc.setFlags(LayoutContext.LAST_AREA, - (layoutContext.isLastArea() && childLM == lastLM)); - /*LF*/lc.setStackLimit(layoutContext.getStackLimit()); - // Add the line areas to Area - childLM.addAreas(childPosIter, lc); - } } else { // if adjusted space before if (bSpaceBefore) { @@ -783,12 +762,13 @@ public class BlockContainerLayoutManager extends BlockStackingLayoutManager { viewportBlockArea.setCTM(absoluteCTM); viewportBlockArea.setClip(clip); + /* if (getSpaceBefore() != 0) { viewportBlockArea.addTrait(Trait.SPACE_BEFORE, new Integer(getSpaceBefore())); } if (foBlockSpaceAfter.opt != 0) { viewportBlockArea.addTrait(Trait.SPACE_AFTER, new Integer(foBlockSpaceAfter.opt)); - } + }*/ if (abProps.absolutePosition == EN_ABSOLUTE || abProps.absolutePosition == EN_FIXED) { @@ -846,19 +826,6 @@ public class BlockContainerLayoutManager extends BlockStackingLayoutManager { protected void flush() { viewportBlockArea.addBlock(referenceArea, autoHeight); - //Handle display-align now that the used BPD can be determined - usedBPD = referenceArea.getAllocBPD(); - /* done by the breaker now by inserting additional boxes - if (!autoHeight & (usedBPD > 0)) { - if (getBlockContainerFO().getDisplayAlign() == EN_CENTER) { - viewportBlockArea.setCTM(viewportBlockArea.getCTM().multiply( - new CTM().translate(0, (relDims.bpd - usedBPD) / 2))); - } else if (getBlockContainerFO().getDisplayAlign() == EN_AFTER) { - viewportBlockArea.setCTM(viewportBlockArea.getCTM().multiply( - new CTM().translate(0, (relDims.bpd - usedBPD)))); - } - }*/ - // Fake a 0 height for absolute positioned blocks. int saveBPD = viewportBlockArea.getBPD(); if (viewportBlockArea.getPositioning() == Block.ABSOLUTE) { |