diff options
author | Keiron Liddle <keiron@apache.org> | 2002-09-18 14:15:05 +0000 |
---|---|---|
committer | Keiron Liddle <keiron@apache.org> | 2002-09-18 14:15:05 +0000 |
commit | e8a21088e28e8d2caffcafe032f1745f2a22a591 (patch) | |
tree | c5882d0fdb7f8c2cb69e45e6e41763ad0904af06 /src/org | |
parent | 31e520e3a8bc5dd68427b17f1307c46a971406df (diff) | |
download | xmlgraphics-fop-e8a21088e28e8d2caffcafe032f1745f2a22a591.tar.gz xmlgraphics-fop-e8a21088e28e8d2caffcafe032f1745f2a22a591.zip |
start of spacing and borders
git-svn-id: https://svn.apache.org/repos/asf/xmlgraphics/fop/trunk@195226 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'src/org')
10 files changed, 115 insertions, 21 deletions
diff --git a/src/org/apache/fop/layoutmgr/BlockLayoutManager.java b/src/org/apache/fop/layoutmgr/BlockLayoutManager.java index ec6e58c18..280963eb4 100644 --- a/src/org/apache/fop/layoutmgr/BlockLayoutManager.java +++ b/src/org/apache/fop/layoutmgr/BlockLayoutManager.java @@ -9,11 +9,18 @@ package org.apache.fop.layoutmgr; import org.apache.fop.fo.FObj; import org.apache.fop.fo.TextInfo; +import org.apache.fop.fo.PropertyManager; import org.apache.fop.area.Area; import org.apache.fop.area.BlockParent; import org.apache.fop.area.Block; import org.apache.fop.area.LineArea; import org.apache.fop.area.MinOptMax; +import org.apache.fop.area.Trait; +import org.apache.fop.traits.LayoutProps; +import org.apache.fop.layout.BorderAndPadding; +import org.apache.fop.layout.BackgroundProps; +import org.apache.fop.traits.SpaceVal; +import org.apache.fop.traits.BorderProps; import java.util.ListIterator; import java.util.ArrayList; @@ -26,6 +33,10 @@ public class BlockLayoutManager extends BlockStackingLayoutManager { private Block curBlockArea; + LayoutProps layoutProps; + BorderAndPadding borderProps; + BackgroundProps backgroundsPops; + int lead = 12000; int lineHeight = 14000; int follow = 2000; @@ -96,12 +107,23 @@ public class BlockLayoutManager extends BlockStackingLayoutManager { lineHeight = ti.lineHeight; } + /** + * This method provides a hook for a LayoutManager to intialize traits + * for the areas it will create, based on Properties set on its FO. + */ + protected void initProperties(PropertyManager pm) { + layoutProps = pm.getLayoutProps(); + borderProps = pm.getBorderAndPadding(); + backgroundsPops = pm.getBackgroundProps(); + } + public BreakPoss getNextBreakPoss(LayoutContext context) { LayoutManager curLM ; // currently active LM MinOptMax stackSize = new MinOptMax(); // if starting add space before - // stackSize.add(spaceBefore); + stackSize.add(layoutProps.spaceBefore.space); + BreakPoss lastPos = null; while ((curLM = getChildLM()) != null) { @@ -127,7 +149,7 @@ public class BlockLayoutManager extends BlockStackingLayoutManager { while (!curLM.isFinished()) { if ((bp = curLM.getNextBreakPoss(childLC)) != null) { stackSize.add(bp.getStackingSize()); - if (stackSize.min > context.getStackLimit().max) { + if (stackSize.opt > context.getStackLimit().max) { // reset to last break if (lastPos != null) { reset(lastPos.getPosition()); @@ -148,6 +170,9 @@ public class BlockLayoutManager extends BlockStackingLayoutManager { } } } + if(getChildLM() == null) { + stackSize.add(layoutProps.spaceAfter.space); + } BreakPoss breakPoss = new BreakPoss( new LeafPosition(this, childBreaks.size() - 1)); breakPoss.setStackingSize(stackSize); @@ -160,6 +185,11 @@ public class BlockLayoutManager extends BlockStackingLayoutManager { public void addAreas(PositionIterator parentIter, LayoutContext layoutContext) { getParentArea(null); + + // if adjusted space before + double adjust = layoutContext.getSpaceAdjust(); + addBlockSpacing(adjust, layoutProps.spaceBefore.space); + addID(); LayoutManager childLM ; @@ -179,6 +209,9 @@ public class BlockLayoutManager extends BlockStackingLayoutManager { flush(); + // if adjusted space after + addBlockSpacing(adjust, layoutProps.spaceAfter.space); + childBreaks.clear(); curBlockArea = null; } @@ -196,6 +229,10 @@ public class BlockLayoutManager extends BlockStackingLayoutManager { public Area getParentArea(Area childArea) { if (curBlockArea == null) { curBlockArea = new Block(); + + // set traits + addBorders(curBlockArea); + // Set up dimensions // Must get dimensions from parent area Area parentArea = parentLM.getParentArea(curBlockArea); @@ -207,6 +244,32 @@ public class BlockLayoutManager extends BlockStackingLayoutManager { return curBlockArea; } + public void addBorders(Block curBlockArea) { + BorderProps bps = getBorderProps(BorderAndPadding.TOP); + if(bps.width != 0) { + curBlockArea.addTrait(Trait.BORDER_START, bps); + } + bps = getBorderProps(BorderAndPadding.BOTTOM); + if(bps.width != 0) { + curBlockArea.addTrait(Trait.BORDER_END, bps); + } + bps = getBorderProps(BorderAndPadding.LEFT); + if(bps.width != 0) { + curBlockArea.addTrait(Trait.BORDER_BEFORE, bps); + } + bps = getBorderProps(BorderAndPadding.RIGHT); + if(bps.width != 0) { + curBlockArea.addTrait(Trait.BORDER_AFTER, bps); + } + } + + private BorderProps getBorderProps(int side) { + BorderProps bps; + bps = new BorderProps(borderProps.getBorderStyle(side), + borderProps.getBorderWidth(side, false), + borderProps.getBorderColor(side)); + return bps; + } public boolean addChild(Area childArea) { if (curBlockArea != null) { diff --git a/src/org/apache/fop/layoutmgr/BlockStackingLayoutManager.java b/src/org/apache/fop/layoutmgr/BlockStackingLayoutManager.java index 249500931..7c8fba848 100644 --- a/src/org/apache/fop/layoutmgr/BlockStackingLayoutManager.java +++ b/src/org/apache/fop/layoutmgr/BlockStackingLayoutManager.java @@ -59,6 +59,27 @@ public abstract class BlockStackingLayoutManager extends AbstractLayoutManager { } /** + * Add a block spacer for space before and space after a block. + * This adds an empty Block area that acts as a block space. + * + * @param adjust the adjustment value + * @param minoptmax the min/opt/max value of the spacing + */ + public void addBlockSpacing(double adjust, MinOptMax minoptmax) { + int sp = minoptmax.opt; + if(adjust > 0) { + sp = sp + (int)(adjust * (minoptmax.max - minoptmax.opt)); + } else { + sp = sp + (int)(adjust * (minoptmax.opt - minoptmax.min)); + } + if(sp != 0) { + Block spacer = new Block(); + spacer.setHeight(sp); + parentLM.addChild(spacer); + } + } + + /** * Add the childArea to the passed area. * Called by child LayoutManager when it has filled one of its areas. * The LM should already have an Area in which to put the child. @@ -77,14 +98,14 @@ public abstract class BlockStackingLayoutManager extends AbstractLayoutManager { // See if the whole thing fits, including space before // Calculate space between last child in curFlow and childArea - MinOptMax targetDim = parentArea.getAvailBPD(); + //MinOptMax targetDim = parentArea.getAvailBPD(); MinOptMax spaceBefore = resolveSpaceSpecifier(childArea); - targetDim.subtract(spaceBefore); - if (targetDim.max >= childArea.getAllocationBPD().min) { + //targetDim.subtract(spaceBefore); + //if (targetDim.max >= childArea.getAllocationBPD().min) { //parentArea.addBlock(new InterBlockSpace(spaceBefore)); - parentArea.addBlock((Block) childArea); - return false; - } else { + // parentArea.addBlock((Block) childArea); + // return false; + //} else { parentArea.addBlock((Block) childArea); flush(); // hand off current area to parent // Probably need something like max BPD so we don't get into @@ -104,7 +125,7 @@ public abstract class BlockStackingLayoutManager extends AbstractLayoutManager { //addChild(splitContext.nextArea); //addChild(childArea); return true; - } + //} } diff --git a/src/org/apache/fop/layoutmgr/FlowLayoutManager.java b/src/org/apache/fop/layoutmgr/FlowLayoutManager.java index 4d4dc0e02..7ef504481 100644 --- a/src/org/apache/fop/layoutmgr/FlowLayoutManager.java +++ b/src/org/apache/fop/layoutmgr/FlowLayoutManager.java @@ -75,12 +75,12 @@ public class FlowLayoutManager extends BlockStackingLayoutManager { // check the stack bpd and if greater than available // height then go to the last best break and return // break position - if(stackSize.min > context.getStackLimit().opt) { + if(stackSize.opt > context.getStackLimit().opt) { breakPage = true; } if(breakPage) { return new BreakPoss( - new LeafPosition(this, blockBreaks.size() - 1)); + new LeafPosition(this, blockBreaks.size() - 1)); } } setFinished(true); diff --git a/src/org/apache/fop/layoutmgr/InlineStackingLayoutManager.java b/src/org/apache/fop/layoutmgr/InlineStackingLayoutManager.java index 8616353e5..4788edf9c 100644 --- a/src/org/apache/fop/layoutmgr/InlineStackingLayoutManager.java +++ b/src/org/apache/fop/layoutmgr/InlineStackingLayoutManager.java @@ -447,7 +447,9 @@ public class InlineStackingLayoutManager extends AbstractLayoutManager { context.setTrailingSpace(getContext().getTrailingSpace()); } // Add own trailing space to parent context (or set on area?) - context.getTrailingSpace().addSpace(m_inlineProps.spaceEnd); + if(context.getTrailingSpace() != null) { + context.getTrailingSpace().addSpace(m_inlineProps.spaceEnd); + } // Add border and padding to current area and set flags (FIRST, LAST ...) TraitSetter.setBorderPaddingTraits(getCurrentArea(), @@ -511,5 +513,5 @@ public class InlineStackingLayoutManager extends AbstractLayoutManager { } } - } + diff --git a/src/org/apache/fop/layoutmgr/LeafNodeLayoutManager.java b/src/org/apache/fop/layoutmgr/LeafNodeLayoutManager.java index c24b99a78..17df76309 100644 --- a/src/org/apache/fop/layoutmgr/LeafNodeLayoutManager.java +++ b/src/org/apache/fop/layoutmgr/LeafNodeLayoutManager.java @@ -128,7 +128,7 @@ public class LeafNodeLayoutManager extends AbstractLayoutManager { | BreakPoss.ISLAST); ipd = getAllocationIPD(context.getRefIPD()); bp.setStackingSize(ipd); - bp.setNonStackingSize(curArea.getAllocationBPD()); + bp.setNonStackingSize(new MinOptMax(curArea.getHeight())); bp.setTrailingSpace(new SpaceSpecifier(false)); int bpd = curArea.getHeight(); diff --git a/src/org/apache/fop/layoutmgr/LineLayoutManager.java b/src/org/apache/fop/layoutmgr/LineLayoutManager.java index 81e983900..36b798d59 100644 --- a/src/org/apache/fop/layoutmgr/LineLayoutManager.java +++ b/src/org/apache/fop/layoutmgr/LineLayoutManager.java @@ -166,7 +166,8 @@ public class LineLayoutManager extends InlineStackingLayoutManager { if (bBreakOK) { /* Add any non-conditional trailing space, assuming we * end the line here. If we can't break here, we just - * check if the content fits. */ + * check if the content fits. + */ bpDim.add(bp.resolveTrailingSpace(true)); } // TODO: stop if linebreak is forced (NEWLINE) diff --git a/src/org/apache/fop/layoutmgr/PageLayoutManager.java b/src/org/apache/fop/layoutmgr/PageLayoutManager.java index c22bc589e..b1d3e3cba 100644 --- a/src/org/apache/fop/layoutmgr/PageLayoutManager.java +++ b/src/org/apache/fop/layoutmgr/PageLayoutManager.java @@ -60,7 +60,7 @@ public class PageLayoutManager extends AbstractLayoutManager implements Runnable private AreaTree areaTree; private PageSequence pageSequence; - private int pageCount = 0; + private int pageCount = 1; /** * This is the top level layout manager. @@ -98,7 +98,6 @@ public class PageLayoutManager extends AbstractLayoutManager implements Runnable BreakPoss bp; LayoutContext childLC = new LayoutContext(0); while (!isFinished()) { - pageCount++; if ((bp = getNextBreakPoss(childLC)) != null) { addAreas((BlockBreakPosition)bp.getPosition()); // add static areas and resolve any new id areas @@ -106,6 +105,7 @@ public class PageLayoutManager extends AbstractLayoutManager implements Runnable // finish page and add to area tree finishPage(); } + pageCount++; } } @@ -214,14 +214,14 @@ public class PageLayoutManager extends AbstractLayoutManager implements Runnable // Alternatively the child LM indicates to parent that it's full? //System.out.println("size: " + area.getAllocationBPD().max + // ":" + curSpan.getMaxBPD().min); - if (area.getAllocationBPD().max >= curSpan.getMaxBPD().min) { + /*if (area.getAllocationBPD().max >= curSpan.getMaxBPD().min) { // Consider it filled if (curSpan.getColumnCount() == curSpanColumns) { finishPage(); return true; } else curFlow = null; // Create new flow on next getParentArea() - } + }*/ return false; } diff --git a/src/org/apache/fop/layoutmgr/table/Body.java b/src/org/apache/fop/layoutmgr/table/Body.java index 902c14bea..ff69e1d05 100644 --- a/src/org/apache/fop/layoutmgr/table/Body.java +++ b/src/org/apache/fop/layoutmgr/table/Body.java @@ -146,11 +146,13 @@ public class Body extends BlockStackingLayoutManager { new BreakPossPosIter(childBreaks, iStartPos, lfp.getLeafPos() + 1); iStartPos = lfp.getLeafPos() + 1; + int lastheight = 0; while ((childLM = (Row)breakPosIter.getNextChildLM()) != null) { childLM.setYOffset(yoffset + rowoffset); childLM.addAreas(breakPosIter, lc); - rowoffset += childLM.getRowHeight(); + lastheight = childLM.getRowHeight(); } + rowoffset += lastheight; } bodyHeight = rowoffset; diff --git a/src/org/apache/fop/layoutmgr/table/Cell.java b/src/org/apache/fop/layoutmgr/table/Cell.java index 57dd6b2cf..4f0ed25ba 100644 --- a/src/org/apache/fop/layoutmgr/table/Cell.java +++ b/src/org/apache/fop/layoutmgr/table/Cell.java @@ -63,6 +63,11 @@ public class Cell extends BlockStackingLayoutManager { cellIPD = context.getRefIPD(); while ((curLM = getChildLM()) != null) { + if(curLM.generatesInlineAreas()) { + // error + curLM.setFinished(true); + continue; + } // Set up a LayoutContext int ipd = context.getRefIPD(); BreakPoss bp; diff --git a/src/org/apache/fop/layoutmgr/table/TableLayoutManager.java b/src/org/apache/fop/layoutmgr/table/TableLayoutManager.java index 9dda28697..70840a629 100644 --- a/src/org/apache/fop/layoutmgr/table/TableLayoutManager.java +++ b/src/org/apache/fop/layoutmgr/table/TableLayoutManager.java @@ -131,7 +131,7 @@ public class TableLayoutManager extends BlockStackingLayoutManager { while (!curLM.isFinished()) { if ((bp = curLM.getNextBreakPoss(childLC)) != null) { stackSize.add(bp.getStackingSize()); - if (stackSize.min > context.getStackLimit().max) { + if (stackSize.opt > context.getStackLimit().max) { // reset to last break if (lastPos != null) { reset(lastPos.getPosition()); |