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;
private Block curBlockArea;
+ LayoutProps layoutProps;
+ BorderAndPadding borderProps;
+ BackgroundProps backgroundsPops;
+
int lead = 12000;
int lineHeight = 14000;
int follow = 2000;
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) {
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());
}
}
}
+ if(getChildLM() == null) {
+ stackSize.add(layoutProps.spaceAfter.space);
+ }
BreakPoss breakPoss = new BreakPoss(
new LeafPosition(this, childBreaks.size() - 1));
breakPoss.setStackingSize(stackSize);
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 ;
flush();
+ // if adjusted space after
+ addBlockSpacing(adjust, layoutProps.spaceAfter.space);
+
childBreaks.clear();
curBlockArea = null;
}
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);
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) {
return spaceSpec.resolve(false);
}
+ /**
+ * 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.
// 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
//addChild(splitContext.nextArea);
//addChild(childArea);
return true;
- }
+ //}
}
// 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);
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(),
}
}
-
}
+
| 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();
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)
private AreaTree areaTree;
private PageSequence pageSequence;
- private int pageCount = 0;
+ private int pageCount = 1;
/**
* This is the top level layout manager.
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
// finish page and add to area tree
finishPage();
}
+ pageCount++;
}
}
// 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;
}
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;
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;
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());