Browse Source

start of spacing and borders


git-svn-id: https://svn.apache.org/repos/asf/xmlgraphics/fop/trunk@195226 13f79535-47bb-0310-9956-ffa450edef68
tags/Alt-Design-integration-base
Keiron Liddle 22 years ago
parent
commit
e8a21088e2

+ 65
- 2
src/org/apache/fop/layoutmgr/BlockLayoutManager.java View File

@@ -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) {

+ 28
- 7
src/org/apache/fop/layoutmgr/BlockStackingLayoutManager.java View File

@@ -58,6 +58,27 @@ public abstract class BlockStackingLayoutManager extends AbstractLayoutManager {
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.
@@ -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;
}
//}
}



+ 2
- 2
src/org/apache/fop/layoutmgr/FlowLayoutManager.java View File

@@ -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);

+ 4
- 2
src/org/apache/fop/layoutmgr/InlineStackingLayoutManager.java View File

@@ -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 {
}
}


}


+ 1
- 1
src/org/apache/fop/layoutmgr/LeafNodeLayoutManager.java View File

@@ -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();

+ 2
- 1
src/org/apache/fop/layoutmgr/LineLayoutManager.java View File

@@ -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)

+ 4
- 4
src/org/apache/fop/layoutmgr/PageLayoutManager.java View File

@@ -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;
}


+ 3
- 1
src/org/apache/fop/layoutmgr/table/Body.java View File

@@ -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;


+ 5
- 0
src/org/apache/fop/layoutmgr/table/Cell.java View File

@@ -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;

+ 1
- 1
src/org/apache/fop/layoutmgr/table/TableLayoutManager.java View File

@@ -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());

Loading…
Cancel
Save