From 3911eb8fe4211a982e05928856caf0e46531d854 Mon Sep 17 00:00:00 2001 From: Keiron Liddle Date: Sun, 18 Aug 2002 13:47:13 +0000 Subject: [PATCH] improved block layout, adds areas to correct parent properly resets git-svn-id: https://svn.apache.org/repos/asf/xmlgraphics/fop/trunk@195092 13f79535-47bb-0310-9956-ffa450edef68 --- src/org/apache/fop/fo/flow/Block.java | 2 +- .../fop/layoutmgr/BlockLayoutManager.java | 35 +++++++--------- src/org/apache/fop/layoutmgr/BreakPoss.java | 5 --- .../fop/layoutmgr/FlowLayoutManager.java | 1 + src/org/apache/fop/layoutmgr/LMiter.java | 11 +++-- .../apache/fop/layoutmgr/LayoutContext.java | 8 ++++ .../fop/layoutmgr/LineBPLayoutManager.java | 29 ++++++++----- .../fop/layoutmgr/PageLayoutManager.java | 42 +++++++++---------- .../fop/layoutmgr/TextBPLayoutManager.java | 22 ++++++---- 9 files changed, 84 insertions(+), 71 deletions(-) diff --git a/src/org/apache/fop/fo/flow/Block.java b/src/org/apache/fop/fo/flow/Block.java index 75667c8e6..4360ce8e2 100644 --- a/src/org/apache/fop/fo/flow/Block.java +++ b/src/org/apache/fop/fo/flow/Block.java @@ -293,7 +293,7 @@ public class Block extends FObjMixed { break; case CharUtilities.EOT: - // A "boundary" objects such as non-character inline + // A "boundary" objects such as non-character inline // or nested block object was encountered. // If any whitespace run in progress, finish it. // FALL THROUGH diff --git a/src/org/apache/fop/layoutmgr/BlockLayoutManager.java b/src/org/apache/fop/layoutmgr/BlockLayoutManager.java index 3b15f5f85..88af158db 100644 --- a/src/org/apache/fop/layoutmgr/BlockLayoutManager.java +++ b/src/org/apache/fop/layoutmgr/BlockLayoutManager.java @@ -103,45 +103,37 @@ public class BlockLayoutManager extends BlockStackingLayoutManager { MinOptMax stackSize = new MinOptMax(); // if starting add space before // stackSize.add(spaceBefore); + BreakPoss lastPos = null; while ((curLM = getChildLM()) != null) { // Make break positions and return blocks! // Set up a LayoutContext - int ipd = 0; + int ipd = context.getRefIPD(); BreakPoss bp; - // Force area creation on first call - // NOTE: normally not necessary when fully integrated! LayoutContext childLC = - new LayoutContext(LayoutContext.CHECK_REF_AREA); + new LayoutContext(0); if(curLM.generatesInlineAreas()) { - // Reset stackLimit for non-first lines - childLC.setStackLimit(new MinOptMax(ipd/* - m_iIndents*/)); + // set stackLimit for lines + childLC.setStackLimit(new MinOptMax(ipd/* - m_iIndents - m_iTextIndent*/)); } else { childLC.setStackLimit(MinOptMax.subtract(context.getStackLimit(), stackSize)); + childLC.setRefIPD(ipd); } while (!curLM.isFinished()) { if ((bp = curLM.getNextBreakPoss(childLC, null)) != null) { - if (bp.checkIPD()) { - // Need IPD in order to layout lines! - // This is supposed to bubble up to PageLM to - // make the necessary flow reference area, depending - // on span and break-before flags set as the BreakPoss - // makes its way back up the call stack. - // Fake it for now! - getParentArea(null); - ipd = getContentIPD(); - childLC.flags &= ~LayoutContext.CHECK_REF_AREA; - childLC.setStackLimit(new MinOptMax(ipd/* - m_iIndents - - m_iTextIndent*/)); - } else { stackSize.add(bp.getStackingSize()); if(stackSize.min > context.getStackLimit().max) { // reset to last break - // curLM.reset(); + if(lastPos != null) { + reset(lastPos.getPosition()); + } else { + curLM.resetPosition(null); + } break; } + lastPos = bp; childBreaks.add(bp); if(curLM.generatesInlineAreas()) { @@ -150,7 +142,6 @@ public class BlockLayoutManager extends BlockStackingLayoutManager { } else { childLC.setStackLimit(MinOptMax.subtract(context.getStackLimit(), stackSize)); } - } } } BreakPoss breakPoss = new BreakPoss( @@ -163,6 +154,7 @@ public class BlockLayoutManager extends BlockStackingLayoutManager { } public void addAreas(PositionIterator parentIter, LayoutContext layoutContext) { + getParentArea(null); BPLayoutManager childLM ; int iStartPos = 0; @@ -182,6 +174,7 @@ public class BlockLayoutManager extends BlockStackingLayoutManager { flush(); childBreaks.clear(); + curBlockArea = null; } /** diff --git a/src/org/apache/fop/layoutmgr/BreakPoss.java b/src/org/apache/fop/layoutmgr/BreakPoss.java index e8a745a67..7a8aa3099 100644 --- a/src/org/apache/fop/layoutmgr/BreakPoss.java +++ b/src/org/apache/fop/layoutmgr/BreakPoss.java @@ -28,7 +28,6 @@ public class BreakPoss { public static final int ISFIRST = 0x04; // First area generated by FO public static final int FORCE = 0x08; // Forced break (ie LF) public static final int CAN_BREAK_BEFORE = 0x10; - public static final int NEED_IPD = 0x20; public static final int HAS_ANCHORS = 0x40; // Set this flag if all fo:character generated Areas would // suppressed at the end or beginning of a line @@ -198,10 +197,6 @@ public class BreakPoss { return m_layoutProps; } - public boolean checkIPD() { - return ((m_flags & NEED_IPD) != 0); - } - public int getLead() { return m_iLead; } diff --git a/src/org/apache/fop/layoutmgr/FlowLayoutManager.java b/src/org/apache/fop/layoutmgr/FlowLayoutManager.java index b3906aaf6..97d031e27 100644 --- a/src/org/apache/fop/layoutmgr/FlowLayoutManager.java +++ b/src/org/apache/fop/layoutmgr/FlowLayoutManager.java @@ -51,6 +51,7 @@ public class FlowLayoutManager extends BlockStackingLayoutManager { LayoutContext childLC = new LayoutContext(0); boolean breakPage = false; childLC.setStackLimit(MinOptMax.subtract(bpd, stackSize)); + childLC.setRefIPD(context.getRefIPD()); if (!curLM.isFinished()) { if ((bp = curLM.getNextBreakPoss(childLC, null)) != null) { diff --git a/src/org/apache/fop/layoutmgr/LMiter.java b/src/org/apache/fop/layoutmgr/LMiter.java index 1f79174fa..eea620c95 100644 --- a/src/org/apache/fop/layoutmgr/LMiter.java +++ b/src/org/apache/fop/layoutmgr/LMiter.java @@ -31,13 +31,16 @@ public class LMiter implements ListIterator { } private boolean preLoadNext() { - if (m_baseIter.hasNext()) { + // skip over child FObj's that don't add lms + while (m_baseIter.hasNext()) { FObj fobj = (FObj) m_baseIter.next(); //m_listLMs.add(fobj.getLayoutManager()); fobj.addLayoutManager(m_listLMs); - return m_curPos < m_listLMs.size(); - } else - return false; + if(m_curPos < m_listLMs.size()) { + return true; + } + } + return false; } public boolean hasPrevious() { diff --git a/src/org/apache/fop/layoutmgr/LayoutContext.java b/src/org/apache/fop/layoutmgr/LayoutContext.java index e359720ac..d53cd4b23 100644 --- a/src/org/apache/fop/layoutmgr/LayoutContext.java +++ b/src/org/apache/fop/layoutmgr/LayoutContext.java @@ -157,6 +157,14 @@ public class LayoutContext { return m_stackLimit; } + public void setRefIPD(int ipd) { + refIPD = ipd; + } + + public int getRefIPD() { + return refIPD; + } + public void setHyphContext(HyphContext hyphContext) { m_hyphContext = hyphContext; } diff --git a/src/org/apache/fop/layoutmgr/LineBPLayoutManager.java b/src/org/apache/fop/layoutmgr/LineBPLayoutManager.java index 337980d2c..b0e4a60dc 100644 --- a/src/org/apache/fop/layoutmgr/LineBPLayoutManager.java +++ b/src/org/apache/fop/layoutmgr/LineBPLayoutManager.java @@ -74,6 +74,9 @@ public class LineBPLayoutManager extends InlineStackingBPLayoutManager { private int lead; private int follow; + // inline start pos when adding areas + int iStartPos = 0; + public LineBPLayoutManager(FObj fobj, List lms, int lh, int l, int f) { //super(fobj, lms.listIterator(), lh, l, f); super(fobj, lms.listIterator()); @@ -103,15 +106,6 @@ public class LineBPLayoutManager extends InlineStackingBPLayoutManager { // Get a break from currently active child LM // Set up constraints for inline level managers - if ((context.flags & LayoutContext.CHECK_REF_AREA) != 0) { - /* Return a BreakPoss indicating that higher level LM - * (page) should check reference area and possibly - * create a new one. - */ - return new BreakPoss(new LineBreakPosition(this, -1, 0.0, lineHeight, lead), - BreakPoss.NEED_IPD); - } - BPLayoutManager curLM ; // currently active LM BreakPoss prevBP = null; BreakPoss bp = null; // proposed BreakPoss @@ -461,6 +455,21 @@ public class LineBPLayoutManager extends InlineStackingBPLayoutManager { return curLineBP; } + public void resetPosition(Position resetPos) { + if (resetPos == null) { + reset(null); + m_vecInlineBreaks.clear(); + m_prevBP = null; + } else { + m_prevBP = (BreakPoss)m_vecInlineBreaks.get(((LineBreakPosition)resetPos).getLeafPos()); + while (m_vecInlineBreaks.get(m_vecInlineBreaks.size() - 1) != m_prevBP) +{ + m_vecInlineBreaks.remove(m_vecInlineBreaks.size() - 1); + } + reset(m_prevBP.getPosition()); + } + } + public void addAreas(PositionIterator parentIter, LayoutContext context) { addAreas(parentIter, 0.0); @@ -474,7 +483,7 @@ public class LineBPLayoutManager extends InlineStackingBPLayoutManager { // dSpaceAdjust should reference extra space in the BPD public void addAreas(PositionIterator parentIter, double dSpaceAdjust) { BPLayoutManager childLM ; - int iStartPos = 0; + //int iStartPos = 0; LayoutContext lc = new LayoutContext(0); while (parentIter.hasNext()) { LineBreakPosition lbp = (LineBreakPosition) parentIter.next(); diff --git a/src/org/apache/fop/layoutmgr/PageLayoutManager.java b/src/org/apache/fop/layoutmgr/PageLayoutManager.java index 822a40ada..4bb7c1f60 100644 --- a/src/org/apache/fop/layoutmgr/PageLayoutManager.java +++ b/src/org/apache/fop/layoutmgr/PageLayoutManager.java @@ -25,11 +25,11 @@ import java.util.List; public class PageLayoutManager extends AbstractBPLayoutManager implements Runnable { private static class BlockBreakPosition extends LeafPosition { - List blockps; + BreakPoss breakps; - BlockBreakPosition(BPLayoutManager lm, int iBreakIndex, List bps) { - super(lm, iBreakIndex); - blockps = bps; + BlockBreakPosition(BPLayoutManager lm, BreakPoss bp) { + super(lm, 0); + breakps = bp; } } @@ -51,6 +51,7 @@ public class PageLayoutManager extends AbstractBPLayoutManager implements Runnab private Flow curFlow; private int flowBPD = 0; + private int flowIPD = 0; /** Manager which handles a queue of all pages which are completely * laid out and ready for rendering, except for resolution of ID @@ -86,16 +87,17 @@ public class PageLayoutManager extends AbstractBPLayoutManager implements Runnab public void doLayout() { + // this should be done another way makeNewPage(false, false); + createBodyMainReferenceArea(); + createSpan(1); + flowIPD = curFlow.getIPD(); BreakPoss bp; LayoutContext childLC = new LayoutContext(0); while (!isFinished()) { - ArrayList vecBreakPoss = new ArrayList(); if ((bp = getNextBreakPoss(childLC, null)) != null) { - vecBreakPoss.add(bp); - addAreas( new BreakPossPosIter(vecBreakPoss, 0, - vecBreakPoss.size()), null); + addAreas((BlockBreakPosition)bp.getPosition()); // add static areas and resolve any new id areas // finish page and add to area tree @@ -112,33 +114,29 @@ public class PageLayoutManager extends AbstractBPLayoutManager implements Runnab BPLayoutManager curLM ; // currently active LM while ((curLM = getChildLM()) != null) { - ArrayList vecBreakPoss = new ArrayList(); + BreakPoss bp = null; LayoutContext childLC = new LayoutContext(0); childLC.setStackLimit(new MinOptMax(flowBPD)); + childLC.setRefIPD(flowIPD); if (!curLM.isFinished()) { - BreakPoss bp; - if ((bp = curLM.getNextBreakPoss(childLC, null)) != null) { - vecBreakPoss.add(bp); - } + bp = curLM.getNextBreakPoss(childLC, null); } - if(vecBreakPoss.size() > 0) { + if(bp != null) { return new BreakPoss( - new BlockBreakPosition(curLM, 0, vecBreakPoss)); + new BlockBreakPosition(curLM, bp)); } } setFinished(true); return null; } - public void addAreas(PositionIterator parentIter, LayoutContext lc) { - - while (parentIter.hasNext()) { - BlockBreakPosition bbp = (BlockBreakPosition) parentIter.next(); - bbp.getLM().addAreas( new BreakPossPosIter(bbp.blockps, 0, - bbp.blockps.size()), null); - } + public void addAreas(BlockBreakPosition bbp) { + List list = new ArrayList(); + list.add(bbp.breakps); + bbp.getLM().addAreas( new BreakPossPosIter(list, 0, + 1), null); } /** diff --git a/src/org/apache/fop/layoutmgr/TextBPLayoutManager.java b/src/org/apache/fop/layoutmgr/TextBPLayoutManager.java index 2abba0a17..7baf9a857 100644 --- a/src/org/apache/fop/layoutmgr/TextBPLayoutManager.java +++ b/src/org/apache/fop/layoutmgr/TextBPLayoutManager.java @@ -466,14 +466,18 @@ public class TextBPLayoutManager extends AbstractBPLayoutManager { // " total=" + iAdjust); // Make an area containing all characters between start and end. - Word word = createWord( - new String(chars, iStart, ai.m_iBreakIndex - iStart), + Word word = null; + String str = new String(chars, iStart, ai.m_iBreakIndex - iStart); + //if(!"".equals(str.trim())) { + word = createWord( + str, ai.m_ipdArea.opt + iAdjust, context.getBaseline()); - if (iWScount > 0) { - //log.error("Adjustment per word-space= " + - // iAdjust / iWScount); - word.setWSadjust(iAdjust / iWScount); - } + if (iWScount > 0) { + //log.error("Adjustment per word-space= " + + // iAdjust / iWScount); + word.setWSadjust(iAdjust / iWScount); + } + //} if ((chars[iStart] == SPACE || chars[iStart] == NBSPACE) && context.getLeadingSpace().hasSpaces()) { context.getLeadingSpace().addSpace(m_halfWS); @@ -493,7 +497,9 @@ public class TextBPLayoutManager extends AbstractBPLayoutManager { chars[ai.m_iBreakIndex - 1] == NBSPACE) { context.getTrailingSpace().addSpace(m_halfWS); } - parentLM.addChild(word); + if(word != null) { + parentLM.addChild(word); + } } -- 2.39.5