diff options
author | Jeremias Maerki <jeremias@apache.org> | 2005-02-07 11:01:37 +0000 |
---|---|---|
committer | Jeremias Maerki <jeremias@apache.org> | 2005-02-07 11:01:37 +0000 |
commit | 36a04093061ccc030a667fac652b490409970b40 (patch) | |
tree | 67fa2886c1ce425dc0462c6311e9ac7c5502503d /src/java/org | |
parent | 7cd913f036c369e67e95661467449cd872cb266c (diff) | |
download | xmlgraphics-fop-36a04093061ccc030a667fac652b490409970b40.tar.gz xmlgraphics-fop-36a04093061ccc030a667fac652b490409970b40.zip |
Temporary fix for markers (using isBogus() check)
ipd/height and display-align support for table rows and cells.
git-svn-id: https://svn.apache.org/repos/asf/xmlgraphics/fop/trunk@198387 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'src/java/org')
10 files changed, 230 insertions, 24 deletions
diff --git a/src/java/org/apache/fop/layoutmgr/AbstractLayoutManager.java b/src/java/org/apache/fop/layoutmgr/AbstractLayoutManager.java index 84f5a90d1..0f6770cd4 100644 --- a/src/java/org/apache/fop/layoutmgr/AbstractLayoutManager.java +++ b/src/java/org/apache/fop/layoutmgr/AbstractLayoutManager.java @@ -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. @@ -48,6 +48,13 @@ public abstract class AbstractLayoutManager implements LayoutManager, Constants /** True if this LayoutManager has handled all of its content. */ private boolean bFinished = false; protected boolean bInited = false; + + /** + * Used during addAreas(): signals that a BreakPoss is not generating areas + * and therefore doesn't add IDs and markers to the current page. + * @see org.apache.fop.layoutmgr.AbstractLayoutManager#isBogus + */ + protected boolean bBogus = false; /** child LM and child LM iterator during getNextBreakPoss phase */ protected LayoutManager curChildLM = null; @@ -145,10 +152,20 @@ public abstract class AbstractLayoutManager implements LayoutManager, Constants */ + /** @see org.apache.fop.layoutmgr.LayoutManager#generatesInlineAreas() */ public boolean generatesInlineAreas() { return false; } + /** @see org.apache.fop.layoutmgr.LayoutManager#isBogus() */ + public boolean isBogus() { + if (getParent().isBogus()) { + return true; + } else { + return bBogus; + } + } + /** * Add a child area to the current area. If this causes the maximum * dimension of the current area to be exceeded, the parent LM is called @@ -263,6 +280,9 @@ public abstract class AbstractLayoutManager implements LayoutManager, Constants } + /** + * @see org.apache.fop.layoutmgr.LayoutManager#addAreas(org.apache.fop.layoutmgr.PositionIterator, org.apache.fop.layoutmgr.LayoutContext) + */ public void addAreas(PositionIterator posIter, LayoutContext context) { } @@ -276,6 +296,9 @@ public abstract class AbstractLayoutManager implements LayoutManager, Constants * interface which are declared abstract in AbstractLayoutManager. * ---------------------------------------------------------*/ + /** + * @see org.apache.fop.layoutmgr.LayoutManager#getParentArea(org.apache.fop.area.Area) + */ public Area getParentArea(Area childArea) { return null; } @@ -309,7 +332,7 @@ public abstract class AbstractLayoutManager implements LayoutManager, Constants * If the id string is not null then add the id to the current page. */ protected void addID(String foID) { - if (foID != null) { + if (foID != null && foID.length() > 0) { addIDToPage(foID); } } diff --git a/src/java/org/apache/fop/layoutmgr/BlockLayoutManager.java b/src/java/org/apache/fop/layoutmgr/BlockLayoutManager.java index 0cc6a557a..454afa2bd 100644 --- a/src/java/org/apache/fop/layoutmgr/BlockLayoutManager.java +++ b/src/java/org/apache/fop/layoutmgr/BlockLayoutManager.java @@ -285,13 +285,18 @@ public class BlockLayoutManager extends BlockStackingLayoutManager { LayoutContext layoutContext) { getParentArea(null); + BreakPoss bp1 = (BreakPoss)parentIter.peekNext(); + bBogus = !bp1.generatesAreas(); + // if adjusted space before double adjust = layoutContext.getSpaceAdjust(); addBlockSpacing(adjust, foBlockSpaceBefore); foBlockSpaceBefore = null; - addID(fobj.getId()); - addMarkers(true, true); + if (!isBogus()) { + addID(fobj.getId()); + addMarkers(true, true); + } try { LayoutManager childLM; @@ -311,7 +316,9 @@ public class BlockLayoutManager extends BlockStackingLayoutManager { } } } finally { - addMarkers(false, true); + if (!isBogus()) { + addMarkers(false, true); + } flush(); // if adjusted space after diff --git a/src/java/org/apache/fop/layoutmgr/BreakPoss.java b/src/java/org/apache/fop/layoutmgr/BreakPoss.java index 03a613f89..6dca0522b 100644 --- a/src/java/org/apache/fop/layoutmgr/BreakPoss.java +++ b/src/java/org/apache/fop/layoutmgr/BreakPoss.java @@ -187,6 +187,13 @@ public class BreakPoss { return ((flags & ALL_ARE_SUPPRESS_AT_LB) != 0); } + /** + * @return true if the BreakPoss results in an area being created. + */ + public boolean generatesAreas() { + return !(nextBreakOverflows() && getStackingSize().opt <= 0); + } + public SpaceSpecifier getLeadingSpace() { return spaceSpecLeading; } diff --git a/src/java/org/apache/fop/layoutmgr/ContentLayoutManager.java b/src/java/org/apache/fop/layoutmgr/ContentLayoutManager.java index 79c1ab6d7..52d351a2e 100644 --- a/src/java/org/apache/fop/layoutmgr/ContentLayoutManager.java +++ b/src/java/org/apache/fop/layoutmgr/ContentLayoutManager.java @@ -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. @@ -159,6 +159,11 @@ public class ContentLayoutManager implements InlineLevelLayoutManager { return true; } + /** @see org.apache.fop.layoutmgr.LayoutManager#isBogus() */ + public boolean isBogus() { + return false; + } + /** @see org.apache.fop.layoutmgr.LayoutManager */ public Area getParentArea(Area childArea) { return holder; @@ -370,5 +375,6 @@ public class ContentLayoutManager implements InlineLevelLayoutManager { int alignment) { return null; } + } diff --git a/src/java/org/apache/fop/layoutmgr/LayoutManager.java b/src/java/org/apache/fop/layoutmgr/LayoutManager.java index 6291a058b..edd283dbc 100644 --- a/src/java/org/apache/fop/layoutmgr/LayoutManager.java +++ b/src/java/org/apache/fop/layoutmgr/LayoutManager.java @@ -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. @@ -72,6 +72,17 @@ public interface LayoutManager { boolean generatesInlineAreas(); /** + * This method is used during the stage where addAreas() converts BreakPoss + * instances to areas. It is used to skip adding IDs and markers to a page + * when the current BreakPoss/area was only generated to signal a break + * situation. This avoids adding IDs and markers to the wrong pages. + * @todo This is a hack. This should be handled differently in the long term. + * @return true if the current BreakPoss/area was only generated to signal + * break situations. + */ + boolean isBogus(); + + /** * Return true if the next area which would be generated by this * LayoutManager could start a new line (or flow for block-level FO). * diff --git a/src/java/org/apache/fop/layoutmgr/MinOptMaxUtil.java b/src/java/org/apache/fop/layoutmgr/MinOptMaxUtil.java new file mode 100644 index 000000000..63cec1a7e --- /dev/null +++ b/src/java/org/apache/fop/layoutmgr/MinOptMaxUtil.java @@ -0,0 +1,80 @@ +/* + * Copyright 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. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/* $Id$ */ + +package org.apache.fop.layoutmgr; + +import org.apache.fop.fo.Constants; +import org.apache.fop.fo.properties.LengthRangeProperty; +import org.apache.fop.traits.MinOptMax; + +/** + * Utilities for MinOptMax and LengthRangeProperty. + */ +public class MinOptMaxUtil { + + /** + * Restricts a MinOptMax using the values from a LengthRangeProperty. + * @param mom MinOptMax to restrict + * @param lr restricting source + */ + public static void restrict(MinOptMax mom, LengthRangeProperty lr) { + if (lr.getEnum() != Constants.EN_AUTO) { + if (lr.getMinimum().getEnum() != Constants.EN_AUTO) { + int min = lr.getMinimum().getLength().getValue(); + if (min > mom.min) { + mom.min = min; + fixAfterMinChanged(mom); + } + } + if (lr.getMaximum().getEnum() != Constants.EN_AUTO) { + int max = lr.getMaximum().getLength().getValue(); + if (max < mom.max) { + mom.max = max; + if (mom.max < mom.opt) { + mom.opt = mom.max; + mom.min = mom.opt; + } + } + } + if (lr.getOptimum().getEnum() != Constants.EN_AUTO) { + int opt = lr.getOptimum().getLength().getValue(); + if (opt > mom.min) { + mom.opt = opt; + if (mom.opt > mom.max) { + mom.max = mom.opt; + } + } + } + } + } + + /** + * After a calculation on a MinOptMax, this can be called to set opt to + * a new effective value. + * @param mom MinOptMax to adjust + */ + public static void fixAfterMinChanged(MinOptMax mom) { + if (mom.min > mom.opt) { + mom.opt = mom.min; + if (mom.opt > mom.max) { + mom.max = mom.opt; + } + } + } + +} diff --git a/src/java/org/apache/fop/layoutmgr/PageSequenceLayoutManager.java b/src/java/org/apache/fop/layoutmgr/PageSequenceLayoutManager.java index e05ee1da7..3e99fe44e 100644 --- a/src/java/org/apache/fop/layoutmgr/PageSequenceLayoutManager.java +++ b/src/java/org/apache/fop/layoutmgr/PageSequenceLayoutManager.java @@ -227,6 +227,11 @@ public class PageSequenceLayoutManager extends AbstractLayoutManager { pageSeq.setCurrentPageNumber(getPageCount()); } + /** @see org.apache.fop.layoutmgr.LayoutManager#isBogus() */ + public boolean isBogus() { + return false; + } + /** * Get the next break possibility. * This finds the next break for a page which is always at the end @@ -484,8 +489,9 @@ public class PageSequenceLayoutManager extends AbstractLayoutManager { RegionViewport rv = curPage.getPage().getRegionViewport( FO_REGION_BODY); curBody = (BodyRegion) rv.getRegion(); - flowBPD = (int) curBody.getBPD() - - rv.getBorderAndPaddingWidthBefore() - rv.getBorderAndPaddingWidthAfter(); + flowBPD = (int) curBody.getBPD() + - rv.getBorderAndPaddingWidthBefore() + - rv.getBorderAndPaddingWidthAfter(); return curPage; } diff --git a/src/java/org/apache/fop/layoutmgr/PositionIterator.java b/src/java/org/apache/fop/layoutmgr/PositionIterator.java index 9a35fd695..3ecf56486 100644 --- a/src/java/org/apache/fop/layoutmgr/PositionIterator.java +++ b/src/java/org/apache/fop/layoutmgr/PositionIterator.java @@ -84,13 +84,14 @@ public abstract class PositionIterator implements Iterator { if (bHasNext) { Object retObj = getPos(nextObj); lookAhead(); + //System.out.println(retObj); return retObj; } else { throw new NoSuchElementException("PosIter"); } } - protected Object peekNext() { + public Object peekNext() { return nextObj; } diff --git a/src/java/org/apache/fop/layoutmgr/table/Cell.java b/src/java/org/apache/fop/layoutmgr/table/Cell.java index e3c5bad18..dce9da005 100644 --- a/src/java/org/apache/fop/layoutmgr/table/Cell.java +++ b/src/java/org/apache/fop/layoutmgr/table/Cell.java @@ -19,17 +19,20 @@ package org.apache.fop.layoutmgr.table; import org.apache.fop.fo.flow.TableCell; +import org.apache.fop.fo.properties.LengthRangeProperty; import org.apache.fop.layoutmgr.BlockStackingLayoutManager; import org.apache.fop.layoutmgr.LayoutManager; import org.apache.fop.layoutmgr.LeafPosition; import org.apache.fop.layoutmgr.BreakPoss; import org.apache.fop.layoutmgr.LayoutContext; +import org.apache.fop.layoutmgr.MinOptMaxUtil; import org.apache.fop.layoutmgr.PositionIterator; import org.apache.fop.layoutmgr.BreakPossPosIter; import org.apache.fop.layoutmgr.Position; import org.apache.fop.layoutmgr.TraitSetter; import org.apache.fop.area.Area; import org.apache.fop.area.Block; +import org.apache.fop.area.CTM; import org.apache.fop.area.Trait; import org.apache.fop.traits.MinOptMax; @@ -50,7 +53,8 @@ public class Cell extends BlockStackingLayoutManager { private int xoffset; private int yoffset; private int cellIPD; - private int height; + private int allocBPD; + private int usedBPD; /** * Create a new Cell layout manager. @@ -123,6 +127,19 @@ public class Cell extends BlockStackingLayoutManager { context.getStackLimit(), stackSize)); } } + + usedBPD = stackSize.opt; + + LengthRangeProperty specifiedBPD = fobj.getBlockProgressionDimension(); + if (specifiedBPD.getEnum() != EN_AUTO) { + if ((specifiedBPD.getMaximum().getEnum() != EN_AUTO) + && (specifiedBPD.getMaximum().getLength().getValue() < stackSize.min)) { + log.warn("maximum height of cell is smaller than the minimum " + + "height of its contents"); + } + MinOptMaxUtil.restrict(stackSize, specifiedBPD); + } + BreakPoss breakPoss = new BreakPoss( new LeafPosition(this, childBreaks.size() - 1)); if (over) { @@ -161,7 +178,7 @@ public class Cell extends BlockStackingLayoutManager { * @param h the height of the row */ public void setRowHeight(int h) { - height = h; + allocBPD = h; } /** @@ -175,7 +192,25 @@ public class Cell extends BlockStackingLayoutManager { public void addAreas(PositionIterator parentIter, LayoutContext layoutContext) { getParentArea(null); - addID(fobj.getId()); + BreakPoss bp1 = (BreakPoss)parentIter.peekNext(); + bBogus = !bp1.generatesAreas(); + + if (!isBogus()) { + addID(fobj.getId()); + } + + //Handle display-align + if (usedBPD < allocBPD) { + if (fobj.getDisplayAlign() == EN_CENTER) { + Block space = new Block(); + space.setBPD((allocBPD - usedBPD) / 2); + curBlockArea.addBlock(space); + } else if (fobj.getDisplayAlign() == EN_AFTER) { + Block space = new Block(); + space.setBPD((allocBPD - usedBPD)); + curBlockArea.addBlock(space); + } + } LayoutManager childLM; int iStartPos = 0; @@ -195,7 +230,7 @@ public class Cell extends BlockStackingLayoutManager { TraitSetter.addBorders(curBlockArea, fobj.getCommonBorderPaddingBackground()); TraitSetter.addBackground(curBlockArea, fobj.getCommonBorderPaddingBackground()); - curBlockArea.setBPD(height); + curBlockArea.setBPD(allocBPD); flush(); diff --git a/src/java/org/apache/fop/layoutmgr/table/Row.java b/src/java/org/apache/fop/layoutmgr/table/Row.java index 49562329f..7233adf27 100644 --- a/src/java/org/apache/fop/layoutmgr/table/Row.java +++ b/src/java/org/apache/fop/layoutmgr/table/Row.java @@ -19,17 +19,20 @@ package org.apache.fop.layoutmgr.table; import org.apache.fop.fo.flow.TableRow; +import org.apache.fop.fo.properties.LengthRangeProperty; import org.apache.fop.layoutmgr.BlockStackingLayoutManager; import org.apache.fop.layoutmgr.LayoutManager; import org.apache.fop.layoutmgr.LeafPosition; import org.apache.fop.layoutmgr.BreakPoss; import org.apache.fop.layoutmgr.LayoutContext; +import org.apache.fop.layoutmgr.MinOptMaxUtil; import org.apache.fop.layoutmgr.PositionIterator; import org.apache.fop.layoutmgr.BreakPossPosIter; import org.apache.fop.layoutmgr.Position; import org.apache.fop.layoutmgr.TraitSetter; import org.apache.fop.area.Area; import org.apache.fop.area.Block; +import org.apache.fop.area.Trait; import org.apache.fop.traits.MinOptMax; import java.util.Iterator; @@ -48,6 +51,7 @@ public class Row extends BlockStackingLayoutManager { private List cellList = null; private List columns = null; + private int referenceIPD; private int rowHeight; private int xoffset; private int yoffset; @@ -133,7 +137,7 @@ public class Row extends BlockStackingLayoutManager { // Set up a LayoutContext // the ipd is from the current column - int ipd = context.getRefIPD(); + referenceIPD = context.getRefIPD(); BreakPoss bp; LayoutContext childLC = new LayoutContext(0); @@ -194,9 +198,17 @@ public class Row extends BlockStackingLayoutManager { breakList.add(childBreaks); } - rowHeight = opt; - MinOptMax rowSize = new MinOptMax(min, opt, max); + LengthRangeProperty specifiedBPD = fobj.getBlockProgressionDimension(); + if (specifiedBPD.getEnum() != EN_AUTO) { + if ((specifiedBPD.getMaximum().getEnum() != EN_AUTO) + && (specifiedBPD.getMaximum().getLength().getValue() < rowSize.min)) { + log.warn("maximum height of row is smaller than the minimum " + + "height of its contents"); + } + MinOptMaxUtil.restrict(rowSize, specifiedBPD); + } + rowHeight = rowSize.opt; boolean fin = true; cellcount = 0; @@ -278,14 +290,27 @@ public class Row extends BlockStackingLayoutManager { public void addAreas(PositionIterator parentIter, LayoutContext layoutContext) { getParentArea(null); - addID(fobj.getId()); + BreakPoss bp1 = (BreakPoss)parentIter.peekNext(); + bBogus = !bp1.generatesAreas(); + if (!isBogus()) { + addID(fobj.getId()); + } Cell childLM; int iStartPos = 0; LayoutContext lc = new LayoutContext(0); while (parentIter.hasNext()) { RowPosition lfp = (RowPosition) parentIter.next(); - // Add the block areas to Area + + //area exclusively for painting the row background + Block rowArea = getRowArea(); + if (rowArea != null) { + rowArea.setBPD(rowHeight); + rowArea.setIPD(referenceIPD); + rowArea.setXOffset(xoffset); + rowArea.setYOffset(yoffset); + parentLM.addChild(rowArea); + } int cellcount = 0; int x = this.xoffset; @@ -316,7 +341,6 @@ public class Row extends BlockStackingLayoutManager { } flush(); - } /** @@ -374,10 +398,16 @@ public class Row extends BlockStackingLayoutManager { * * @return the row area */ - public Area getRowArea() { - Area block = new Block(); - TraitSetter.addBackground(block, fobj.getCommonBorderPaddingBackground()); - return block; + public Block getRowArea() { + if (fobj.getCommonBorderPaddingBackground().hasBackground()) { + Block block = new Block(); + block.addTrait(Trait.IS_REFERENCE_AREA, Boolean.TRUE); + block.setPositioning(Block.ABSOLUTE); + TraitSetter.addBackground(block, fobj.getCommonBorderPaddingBackground()); + return block; + } else { + return null; + } } } |