aboutsummaryrefslogtreecommitdiffstats
path: root/src/org/apache
diff options
context:
space:
mode:
authorKeiron Liddle <keiron@apache.org>2002-08-11 07:31:30 +0000
committerKeiron Liddle <keiron@apache.org>2002-08-11 07:31:30 +0000
commit7f538e55202188c51844ff3b37220bc3ddf177b0 (patch)
tree40baebdf3b8e576dab2bc0b22994ee120b4eec73 /src/org/apache
parent5320f10153519d6d59f2a4a8d0ea5d436b5fb1ec (diff)
downloadxmlgraphics-fop-7f538e55202188c51844ff3b37220bc3ddf177b0.tar.gz
xmlgraphics-fop-7f538e55202188c51844ff3b37220bc3ddf177b0.zip
get some page breaking working
properly resets leaf node git-svn-id: https://svn.apache.org/repos/asf/xmlgraphics/fop/trunk@195077 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'src/org/apache')
-rw-r--r--src/org/apache/fop/layoutmgr/BlockLayoutManager.java116
-rw-r--r--src/org/apache/fop/layoutmgr/FlowLayoutManager.java70
-rw-r--r--src/org/apache/fop/layoutmgr/LayoutContext.java2
-rw-r--r--src/org/apache/fop/layoutmgr/LeafNodeLayoutManager.java8
-rw-r--r--src/org/apache/fop/layoutmgr/LineBPLayoutManager.java5
-rw-r--r--src/org/apache/fop/layoutmgr/PageLayoutManager.java24
6 files changed, 119 insertions, 106 deletions
diff --git a/src/org/apache/fop/layoutmgr/BlockLayoutManager.java b/src/org/apache/fop/layoutmgr/BlockLayoutManager.java
index 85a93b164..3b15f5f85 100644
--- a/src/org/apache/fop/layoutmgr/BlockLayoutManager.java
+++ b/src/org/apache/fop/layoutmgr/BlockLayoutManager.java
@@ -30,6 +30,8 @@ public class BlockLayoutManager extends BlockStackingLayoutManager {
int lineHeight = 14000;
int follow = 2000;
+ ArrayList childBreaks = new ArrayList();
+
public BlockLayoutManager(FObj fobj) {
super(fobj);
}
@@ -52,15 +54,6 @@ public class BlockLayoutManager extends BlockStackingLayoutManager {
return curBlockArea.getIPD();
}
- private static class BlockBreakPosition extends LeafPosition {
- List blockps;
-
- BlockBreakPosition(BPLayoutManager lm, int iBreakIndex, List bps) {
- super(lm, iBreakIndex);
- blockps = bps;
- }
- }
-
protected BPLayoutManager getChildLM() {
if (m_curChildLM != null && !m_curChildLM.isFinished()) {
return m_curChildLM;
@@ -77,7 +70,7 @@ public class BlockLayoutManager extends BlockStackingLayoutManager {
inlines.add(lm);
//lms.remove(count + 1);
} else {
- m_childLMiter.previousIndex();
+ m_childLMiter.previous();
break;
}
}
@@ -106,19 +99,27 @@ public class BlockLayoutManager extends BlockStackingLayoutManager {
Position prevLineBP) {
BPLayoutManager curLM ; // currently active LM
- ArrayList list = new ArrayList();
+
+ MinOptMax stackSize = new MinOptMax();
+ // if starting add space before
+ // stackSize.add(spaceBefore);
while ((curLM = getChildLM()) != null) {
- // Make break positions and return lines!
+ // Make break positions and return blocks!
// Set up a LayoutContext
int ipd = 0;
BreakPoss bp;
- ArrayList vecBreakPoss = new ArrayList();
// Force area creation on first call
// NOTE: normally not necessary when fully integrated!
LayoutContext childLC =
new LayoutContext(LayoutContext.CHECK_REF_AREA);
+ if(curLM.generatesInlineAreas()) {
+ // Reset stackLimit for non-first lines
+ childLC.setStackLimit(new MinOptMax(ipd/* - m_iIndents*/));
+ } else {
+ childLC.setStackLimit(MinOptMax.subtract(context.getStackLimit(), stackSize));
+ }
while (!curLM.isFinished()) {
if ((bp = curLM.getNextBreakPoss(childLC, null)) != null) {
@@ -133,30 +134,54 @@ public class BlockLayoutManager extends BlockStackingLayoutManager {
ipd = getContentIPD();
childLC.flags &= ~LayoutContext.CHECK_REF_AREA;
childLC.setStackLimit(new MinOptMax(ipd/* - m_iIndents -
- m_iTextIndent*/));
+ m_iTextIndent*/));
} else {
- vecBreakPoss.add(bp);
+ stackSize.add(bp.getStackingSize());
+ if(stackSize.min > context.getStackLimit().max) {
+ // reset to last break
+ // curLM.reset();
+ break;
+ }
+ childBreaks.add(bp);
+
+ if(curLM.generatesInlineAreas()) {
// Reset stackLimit for non-first lines
childLC.setStackLimit(new MinOptMax(ipd/* - m_iIndents*/));
+ } else {
+ childLC.setStackLimit(MinOptMax.subtract(context.getStackLimit(), stackSize));
+ }
}
}
}
- list.add(vecBreakPoss);
- return new BreakPoss(
- new BlockBreakPosition(curLM, 0, vecBreakPoss));
+ BreakPoss breakPoss = new BreakPoss(
+ new LeafPosition(this, childBreaks.size() - 1));
+ breakPoss.setStackingSize(stackSize);
+ return breakPoss;
}
setFinished(true);
- return new BreakPoss(new BlockBreakPosition(this, 0, list));
+ return null;
}
- public void addAreas(PositionIterator parentIter, LayoutContext lc) {
+ public void addAreas(PositionIterator parentIter, LayoutContext layoutContext) {
+ BPLayoutManager childLM ;
+ int iStartPos = 0;
+ LayoutContext lc = new LayoutContext(0);
while (parentIter.hasNext()) {
- BlockBreakPosition bbp = (BlockBreakPosition) parentIter.next();
- bbp.getLM().addAreas( new BreakPossPosIter(bbp.blockps, 0,
- bbp.blockps.size()), null);
+ LeafPosition lfp = (LeafPosition) parentIter.next();
+ // Add the block areas to Area
+ PositionIterator breakPosIter =
+ new BreakPossPosIter(childBreaks, iStartPos,
+ lfp.getLeafPos() + 1);
+ iStartPos = lfp.getLeafPos() + 1;
+ while ((childLM = breakPosIter.getNextChildLM()) != null) {
+ childLM.addAreas(breakPosIter, lc);
+ }
}
+
flush();
+
+ childBreaks.clear();
}
/**
@@ -208,48 +233,5 @@ public class BlockLayoutManager extends BlockStackingLayoutManager {
return false;
}
-
-
- // /**
- // * Called by child LayoutManager when it has filled one of its areas.
- // * If no current container, make one.
- // * See if the area will fit in the current container.
- // * If so, add it.
- // * @param childArea the area to add: will either be a LineArea or
- // * a BlockArea.
- // */
- // public void addChild(Area childArea) {
- // /* If the childArea fits entirely in the maximum available BPD
- // * add it and return an OK status.
- // * If it doesn't all fit, overrun or ask for split?
- // * Might as well just add it since the page layout process
- // * may need to make other adjustments, resulting in changing
- // * split point.
- // */
- // // Things like breaks on child area can cause premature
- // // termination of the current area.
- // /* We go past the theoretical maximum to be able to handle things
- // * like widows.
- // */
- // // WARNING: this doesn't take into account space-specifier
- // // adujstment between childArea and last content of blockArea!
- // if (blockArea.getContentBPD().min + childArea.getAllocationBPD().min
- // > blockArea.getAvailBPD().max) {
- // if (++extraLines <= iWidows) {
- // blockArea.add(childArea);
- // }
- // else {
- // blockArea.setIsLast(false);
- // parentLM.addChildArea(blockArea);
- // // Make a new one for this area
- // blockArea = makeAreaForChild(childArea);
- // extraLines = 0; // Count potential widows
- // blockArea.add(childArea);
- // }
- // }
- // else {
- // blockArea.add(childArea);
- // }
- // }
-
}
+
diff --git a/src/org/apache/fop/layoutmgr/FlowLayoutManager.java b/src/org/apache/fop/layoutmgr/FlowLayoutManager.java
index 6919a71d5..b3906aaf6 100644
--- a/src/org/apache/fop/layoutmgr/FlowLayoutManager.java
+++ b/src/org/apache/fop/layoutmgr/FlowLayoutManager.java
@@ -23,14 +23,7 @@ import java.util.List;
*/
public class FlowLayoutManager extends BlockStackingLayoutManager {
- private static class BlockBreakPosition extends LeafPosition {
- List blockps;
-
- BlockBreakPosition(BPLayoutManager lm, int iBreakIndex, List bps) {
- super(lm, iBreakIndex);
- blockps = bps;
- }
- }
+ ArrayList blockBreaks = new ArrayList();
/** Array of areas currently being filled stored by area class */
private BlockParent[] currentAreas = new BlockParent[Area.CLASS_MAX];
@@ -47,40 +40,71 @@ public class FlowLayoutManager extends BlockStackingLayoutManager {
Position prevLineBP) {
BPLayoutManager curLM ; // currently active LM
+ MinOptMax stackSize = new MinOptMax();
while ((curLM = getChildLM()) != null) {
- // Make break positions and return lines!
+ // Make break positions and return page break
// Set up a LayoutContext
- int bpd = 0;
+ MinOptMax bpd = context.getStackLimit();
BreakPoss bp;
- ArrayList vecBreakPoss = new ArrayList();
- // Force area creation on first call
- // NOTE: normally not necessary when fully integrated!
LayoutContext childLC = new LayoutContext(0);
+ boolean breakPage = false;
+ childLC.setStackLimit(MinOptMax.subtract(bpd, stackSize));
- while (!curLM.isFinished()) {
+ if (!curLM.isFinished()) {
if ((bp = curLM.getNextBreakPoss(childLC, null)) != null) {
- vecBreakPoss.add(bp);
- // Reset stackLimit for non-first lines
- childLC.setStackLimit(new MinOptMax(bpd));
+ stackSize.add(bp.getStackingSize());
+ blockBreaks.add(bp);
+ // set stackLimit for remaining space
+ childLC.setStackLimit(MinOptMax.subtract(bpd, stackSize));
+
+ if(bp.isForcedBreak()) {
+ breakPage = true;
+ break;
+ }
}
}
- return new BreakPoss(
- new BlockBreakPosition(curLM, 0, vecBreakPoss));
+ // 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) {
+ breakPage = true;
+ }
+ if(breakPage) {
+ return new BreakPoss(
+ new LeafPosition(this, blockBreaks.size() - 1));
+ }
}
setFinished(true);
+ if(blockBreaks.size() > 0) {
+ return new BreakPoss(
+ new LeafPosition(this, blockBreaks.size() - 1));
+ }
return null;
}
- public void addAreas(PositionIterator parentIter, LayoutContext lc) {
+ public void addAreas(PositionIterator parentIter, LayoutContext layoutContext) {
+
+ BPLayoutManager childLM ;
+ int iStartPos = 0;
+ LayoutContext lc = new LayoutContext(0);
while (parentIter.hasNext()) {
- BlockBreakPosition bbp = (BlockBreakPosition) parentIter.next();
- bbp.getLM().addAreas( new BreakPossPosIter(bbp.blockps, 0,
- bbp.blockps.size()), null);
+ LeafPosition lfp = (LeafPosition) parentIter.next();
+ // Add the block areas to Area
+ PositionIterator breakPosIter =
+ new BreakPossPosIter(blockBreaks, iStartPos,
+ lfp.getLeafPos() + 1);
+ iStartPos = lfp.getLeafPos() + 1;
+ while ((childLM = breakPosIter.getNextChildLM()) != null) {
+ childLM.addAreas(breakPosIter, lc);
+ }
}
+
flush();
+ // clear the breaks for the page to start for the next page
+ blockBreaks.clear();
}
diff --git a/src/org/apache/fop/layoutmgr/LayoutContext.java b/src/org/apache/fop/layoutmgr/LayoutContext.java
index d095b3fc8..2ec273ee4 100644
--- a/src/org/apache/fop/layoutmgr/LayoutContext.java
+++ b/src/org/apache/fop/layoutmgr/LayoutContext.java
@@ -149,7 +149,7 @@ public class LayoutContext {
}
public MinOptMax getStackLimit() {
- return m_stackLimit ;
+ return m_stackLimit;
}
public void setHyphContext(HyphContext hyphContext) {
diff --git a/src/org/apache/fop/layoutmgr/LeafNodeLayoutManager.java b/src/org/apache/fop/layoutmgr/LeafNodeLayoutManager.java
index 0f060d3fb..43cae55ae 100644
--- a/src/org/apache/fop/layoutmgr/LeafNodeLayoutManager.java
+++ b/src/org/apache/fop/layoutmgr/LeafNodeLayoutManager.java
@@ -59,7 +59,6 @@ public class LeafNodeLayoutManager extends AbstractBPLayoutManager {
return false;
}
-
/**
* This is a leaf-node, so this method is never called.
*/
@@ -77,12 +76,17 @@ public class LeafNodeLayoutManager extends AbstractBPLayoutManager {
BreakPoss bp = new BreakPoss(new LeafPosition(this, 0),
BreakPoss.CAN_BREAK_AFTER |
BreakPoss.CAN_BREAK_BEFORE | BreakPoss.ISFIRST |
- BreakPoss.ISLAST | BreakPoss.REST_ARE_SUPPRESS_AT_LB);
+ BreakPoss.ISLAST);
bp.setStackingSize(curArea.getAllocationIPD());
+ bp.setNonStackingSize(curArea.getAllocationBPD());
setFinished(true);
return bp;
}
+ public void resetPosition(Position resetPos) {
+ setFinished(false);
+ }
+
public void addAreas(PositionIterator posIter, LayoutContext context) {
parentLM.addChild(curArea);
while (posIter.hasNext()) {
diff --git a/src/org/apache/fop/layoutmgr/LineBPLayoutManager.java b/src/org/apache/fop/layoutmgr/LineBPLayoutManager.java
index 489af7459..dfeb56aa3 100644
--- a/src/org/apache/fop/layoutmgr/LineBPLayoutManager.java
+++ b/src/org/apache/fop/layoutmgr/LineBPLayoutManager.java
@@ -437,6 +437,9 @@ public class LineBPLayoutManager extends InlineStackingBPLayoutManager {
public void addAreas(PositionIterator parentIter,
LayoutContext context) {
addAreas(parentIter, 0.0);
+
+ //m_vecInlineBreaks.clear();
+ m_prevBP = null;
}
// Generate and add areas to parent area
@@ -464,8 +467,10 @@ public class LineBPLayoutManager extends InlineStackingBPLayoutManager {
lc.setLeadingSpace(lc.getTrailingSpace());
lc.setTrailingSpace(new SpaceSpecifier(false));
}
+if(lc.getTrailingSpace() != null) {
addSpace(lineArea, lc.getTrailingSpace().resolve(true),
lc.getSpaceAdjust());
+}
lineArea.verticalAlign(lineHeight, lead, follow);
parentLM.addChild(lineArea);
}
diff --git a/src/org/apache/fop/layoutmgr/PageLayoutManager.java b/src/org/apache/fop/layoutmgr/PageLayoutManager.java
index a30e3335b..2fde2b55d 100644
--- a/src/org/apache/fop/layoutmgr/PageLayoutManager.java
+++ b/src/org/apache/fop/layoutmgr/PageLayoutManager.java
@@ -44,10 +44,11 @@ public class PageLayoutManager extends AbstractBPLayoutManager implements Runnab
/** Number of columns in current span area. */
private int curSpanColumns;
-
/** Current flow-reference-area (column) being filled. */
private Flow curFlow;
+ private int flowBPD = 0;
+
/** Manager which handles a queue of all pages which are completely
* laid out and ready for rendering, except for resolution of ID
* references?
@@ -82,7 +83,7 @@ public class PageLayoutManager extends AbstractBPLayoutManager implements Runnab
public void doLayout() {
- //ArrayList vecBreakPoss = new ArrayList();
+ makeNewPage(false, false);
BreakPoss bp;
LayoutContext childLC = new LayoutContext(0);
@@ -92,13 +93,13 @@ public class PageLayoutManager extends AbstractBPLayoutManager implements Runnab
vecBreakPoss.add(bp);
addAreas( new BreakPossPosIter(vecBreakPoss, 0,
vecBreakPoss.size()), null);
+ // add static areas and resolve any new id areas
+
+ // finish page and add to area tree
finishPage();
}
}
- //addAreas( new BreakPossPosIter(vecBreakPoss, 0,
- // vecBreakPoss.size()), null);
-
}
@@ -108,16 +109,11 @@ public class PageLayoutManager extends AbstractBPLayoutManager implements Runnab
BPLayoutManager curLM ; // currently active LM
while ((curLM = getChildLM()) != null) {
- // Make break positions and return lines!
- // Set up a LayoutContext
- int bpd = 0;
BreakPoss bp;
ArrayList vecBreakPoss = new ArrayList();
- // Force area creation on first call
- // NOTE: normally not necessary when fully integrated!
LayoutContext childLC = new LayoutContext(0);
- childLC.setStackLimit(new MinOptMax(bpd));
+ childLC.setStackLimit(new MinOptMax(flowBPD));
if (!curLM.isFinished()) {
if ((bp = curLM.getNextBreakPoss(childLC, null)) != null) {
@@ -218,8 +214,10 @@ getParentArea(area);
} catch (FOPException fopex) { /* ???? */
fopex.printStackTrace();
}
- curBody = (BodyRegion) curPage.getPage(). getRegion(
- RegionReference.BODY).getRegion();
+ RegionViewport reg = curPage.getPage(). getRegion(
+ RegionReference.BODY);
+ curBody = (BodyRegion) reg.getRegion();
+ flowBPD = (int)reg.getViewArea().getHeight();
return curPage;
}