From 096a0bfab66076dfb587b666a33a79ea09b96e56 Mon Sep 17 00:00:00 2001 From: Jeremias Maerki Date: Fri, 28 Jan 2005 16:59:28 +0000 Subject: [PATCH] Added border, padding and spacing for list-blocks and list-items. git-svn-id: https://svn.apache.org/repos/asf/xmlgraphics/fop/trunk@198338 13f79535-47bb-0310-9956-ffa450edef68 --- .../list/ListBlockLayoutManager.java | 84 +++++++++++++++---- .../layoutmgr/list/ListItemLayoutManager.java | 74 +++++++++++++--- 2 files changed, 129 insertions(+), 29 deletions(-) diff --git a/src/java/org/apache/fop/layoutmgr/list/ListBlockLayoutManager.java b/src/java/org/apache/fop/layoutmgr/list/ListBlockLayoutManager.java index 7c69b9d9d..f9cfe5104 100644 --- a/src/java/org/apache/fop/layoutmgr/list/ListBlockLayoutManager.java +++ b/src/java/org/apache/fop/layoutmgr/list/ListBlockLayoutManager.java @@ -31,6 +31,7 @@ import org.apache.fop.layoutmgr.TraitSetter; 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; import java.util.List; @@ -45,25 +46,46 @@ public class ListBlockLayoutManager extends BlockStackingLayoutManager { private Block curBlockArea; + private int referenceIPD = 0; + private List bodyBreaks = new ArrayList(); + //TODO space-before|after: handle space-resolution rules + private MinOptMax spaceBefore; + private MinOptMax spaceAfter; + + /* private class SectionPosition extends LeafPosition { protected List list; protected SectionPosition(LayoutManager lm, int pos, List l) { super(lm, pos); list = l; } - } + }*/ /** * Create a new table layout manager. - * + * @param node list-block to create the layout manager for */ public ListBlockLayoutManager(ListBlock node) { super(node); fobj = node; } + /** @see org.apache.fop.layoutmgr.AbstractLayoutManager#initProperties() */ + protected void initProperties() { + super.initProperties(); + spaceBefore = new SpaceVal(fobj.getCommonMarginBlock().spaceBefore).getSpace(); + spaceAfter = new SpaceVal(fobj.getCommonMarginBlock().spaceAfter).getSpace(); + } + + private int getIPIndents() { + int iIndents = 0; + iIndents += fobj.getCommonMarginBlock().startIndent.getValue(); + iIndents += fobj.getCommonMarginBlock().endIndent.getValue(); + return iIndents; + } + /** * Get the next break possibility. * The break possibility depends on the height of the header and footer @@ -76,22 +98,31 @@ public class ListBlockLayoutManager extends BlockStackingLayoutManager { // currently active LM LayoutManager curLM; + referenceIPD = context.getRefIPD(); + MinOptMax stackSize = new MinOptMax(); - // if starting add space before - // stackSize.add(spaceBefore); + + //Add spacing + if (spaceAfter != null) { + stackSize.add(spaceAfter); + } + if (spaceBefore != null) { + stackSize.add(spaceBefore); + } + BreakPoss lastPos = null; while ((curLM = (LayoutManager)getChildLM()) != null) { // Make break positions // Set up a LayoutContext - int ipd = context.getRefIPD(); + //int ipd = context.getRefIPD(); BreakPoss bp; LayoutContext childLC = new LayoutContext(0); childLC.setStackLimit( MinOptMax.subtract(context.getStackLimit(), stackSize)); - childLC.setRefIPD(ipd); + childLC.setRefIPD(referenceIPD); boolean over = false; while (!curLM.isFinished()) { @@ -145,11 +176,17 @@ public class ListBlockLayoutManager extends BlockStackingLayoutManager { public void addAreas(PositionIterator parentIter, LayoutContext layoutContext) { getParentArea(null); + + // if adjusted space before + double adjust = layoutContext.getSpaceAdjust(); + addBlockSpacing(adjust, spaceBefore); + spaceBefore = null; + addID(fobj.getId()); // the list block contains areas stacked from each list item - int listHeight = 0; + //int listHeight = 0; LayoutManager childLM; int iStartPos = 0; @@ -157,20 +194,20 @@ public class ListBlockLayoutManager extends BlockStackingLayoutManager { while (parentIter.hasNext()) { LeafPosition lfp = (LeafPosition) parentIter.next(); // Add the block areas to Area - PositionIterator breakPosIter = - new BreakPossPosIter(bodyBreaks, iStartPos, - lfp.getLeafPos() + 1); + PositionIterator breakPosIter = new BreakPossPosIter( + bodyBreaks, iStartPos, lfp.getLeafPos() + 1); iStartPos = lfp.getLeafPos() + 1; while ((childLM = (LayoutManager)breakPosIter.getNextChildLM()) != null) { childLM.addAreas(breakPosIter, lc); } } - TraitSetter.addBorders(curBlockArea, fobj.getCommonBorderPaddingBackground()); - TraitSetter.addBackground(curBlockArea, fobj.getCommonBorderPaddingBackground()); flush(); + // if adjusted space after + addBlockSpacing(adjust, spaceAfter); + bodyBreaks.clear(); curBlockArea = null; } @@ -191,13 +228,24 @@ public class ListBlockLayoutManager extends BlockStackingLayoutManager { public Area getParentArea(Area childArea) { if (curBlockArea == null) { curBlockArea = new Block(); + // Set up dimensions // Must get dimensions from parent area - Area parentArea = parentLM.getParentArea(curBlockArea); - int referenceIPD = parentArea.getIPD(); - curBlockArea.setIPD(referenceIPD); - // Get reference IPD from parentArea - setCurrentArea(curBlockArea); // ??? for generic operations + /*Area parentArea =*/ parentLM.getParentArea(curBlockArea); + + // set traits + TraitSetter.addBorders(curBlockArea, fobj.getCommonBorderPaddingBackground()); + TraitSetter.addBackground(curBlockArea, fobj.getCommonBorderPaddingBackground()); + TraitSetter.addMargins(curBlockArea, + fobj.getCommonBorderPaddingBackground(), + fobj.getCommonMarginBlock()); + TraitSetter.addBreaks(curBlockArea, + fobj.getBreakBefore(), fobj.getBreakAfter()); + + int contentIPD = referenceIPD - getIPIndents(); + curBlockArea.setIPD(contentIPD); + + setCurrentArea(curBlockArea); } return curBlockArea; } @@ -223,7 +271,7 @@ public class ListBlockLayoutManager extends BlockStackingLayoutManager { bodyBreaks.clear(); reset(null); } else { - + //TODO Something to put here? } } } diff --git a/src/java/org/apache/fop/layoutmgr/list/ListItemLayoutManager.java b/src/java/org/apache/fop/layoutmgr/list/ListItemLayoutManager.java index ccd2ab21e..d81599e42 100644 --- a/src/java/org/apache/fop/layoutmgr/list/ListItemLayoutManager.java +++ b/src/java/org/apache/fop/layoutmgr/list/ListItemLayoutManager.java @@ -29,9 +29,11 @@ import org.apache.fop.layoutmgr.LayoutContext; 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.traits.MinOptMax; +import org.apache.fop.traits.SpaceVal; import java.util.Iterator; import java.util.ArrayList; @@ -47,11 +49,17 @@ public class ListItemLayoutManager extends BlockStackingLayoutManager { private Item label; private Item body; + private int referenceIPD = 0; + private Block curBlockArea = null; - private List cellList = null; + //private List cellList = null; private int listItemHeight; + //TODO space-before|after: handle space-resolution rules + private MinOptMax spaceBefore; + private MinOptMax spaceAfter; + private class ItemPosition extends LeafPosition { protected List cellBreaks; protected ItemPosition(LayoutManager lm, int pos, List l) { @@ -62,7 +70,7 @@ public class ListItemLayoutManager extends BlockStackingLayoutManager { /** * Create a new list item layout manager. - * + * @param node list-item to create the layout manager for */ public ListItemLayoutManager(ListItem node) { super(node); @@ -89,6 +97,20 @@ public class ListItemLayoutManager extends BlockStackingLayoutManager { body.setParent(this); } + /** @see org.apache.fop.layoutmgr.AbstractLayoutManager#initProperties() */ + protected void initProperties() { + super.initProperties(); + spaceBefore = new SpaceVal(fobj.getCommonMarginBlock().spaceBefore).getSpace(); + spaceAfter = new SpaceVal(fobj.getCommonMarginBlock().spaceAfter).getSpace(); + } + + private int getIPIndents() { + int iIndents = 0; + iIndents += fobj.getCommonMarginBlock().startIndent.getValue(); + iIndents += fobj.getCommonMarginBlock().endIndent.getValue(); + return iIndents; + } + /** * Get the next break possibility. * @@ -99,6 +121,9 @@ public class ListItemLayoutManager extends BlockStackingLayoutManager { // currently active LM Item curLM; + //int allocBPD = context. + referenceIPD = context.getRefIPD(); + BreakPoss lastPos = null; List breakList = new ArrayList(); @@ -121,14 +146,14 @@ public class ListItemLayoutManager extends BlockStackingLayoutManager { // Set up a LayoutContext // the ipd is from the current column - int ipd = context.getRefIPD(); + //int ipd = context.getRefIPD(); BreakPoss bp; LayoutContext childLC = new LayoutContext(0); childLC.setStackLimit( MinOptMax.subtract(context.getStackLimit(), stackSize)); - childLC.setRefIPD(context.getRefIPD()); + childLC.setRefIPD(referenceIPD); stage++; while (!curLM.isFinished()) { @@ -178,12 +203,20 @@ public class ListItemLayoutManager extends BlockStackingLayoutManager { } listItemHeight = opt; - MinOptMax itemSize = new MinOptMax(min, opt, max); - if (label.isFinished() && body.isFinished()) { setFinished(true); } + MinOptMax itemSize = new MinOptMax(min, opt, max); + + //Add spacing + if (spaceAfter != null) { + itemSize.add(spaceAfter); + } + if (spaceBefore != null) { + itemSize.add(spaceBefore); + } + ItemPosition rp = new ItemPosition(this, breakList.size() - 1, breakList); BreakPoss breakPoss = new BreakPoss(rp); if (over) { @@ -203,6 +236,12 @@ public class ListItemLayoutManager extends BlockStackingLayoutManager { public void addAreas(PositionIterator parentIter, LayoutContext layoutContext) { getParentArea(null); + + // if adjusted space before + double adjust = layoutContext.getSpaceAdjust(); + addBlockSpacing(adjust, spaceBefore); + spaceBefore = null; + addID(fobj.getId()); Item childLM; @@ -226,6 +265,9 @@ public class ListItemLayoutManager extends BlockStackingLayoutManager { flush(); + // if adjusted space after + addBlockSpacing(adjust, spaceAfter); + curBlockArea = null; } @@ -257,11 +299,21 @@ public class ListItemLayoutManager extends BlockStackingLayoutManager { curBlockArea = new Block(); // Set up dimensions - Area parentArea = parentLM.getParentArea(curBlockArea); - int referenceIPD = parentArea.getIPD(); - curBlockArea.setIPD(referenceIPD); - // Get reference IPD from parentArea - setCurrentArea(curBlockArea); // ??? for generic operations + /*Area parentArea =*/ parentLM.getParentArea(curBlockArea); + + // set traits + TraitSetter.addBorders(curBlockArea, fobj.getCommonBorderPaddingBackground()); + TraitSetter.addBackground(curBlockArea, fobj.getCommonBorderPaddingBackground()); + TraitSetter.addMargins(curBlockArea, + fobj.getCommonBorderPaddingBackground(), + fobj.getCommonMarginBlock()); + TraitSetter.addBreaks(curBlockArea, + fobj.getBreakBefore(), fobj.getBreakAfter()); + + int contentIPD = referenceIPD - getIPIndents(); + curBlockArea.setIPD(contentIPD); + + setCurrentArea(curBlockArea); } return curBlockArea; } -- 2.39.5