From a5a563208c5afef691fd76082e726f1defff261d Mon Sep 17 00:00:00 2001 From: Keiron Liddle Date: Mon, 18 Nov 2002 15:54:16 +0000 Subject: [PATCH] set user agent on layout managers for values and logging improved break handling so that it breaks before overflow git-svn-id: https://svn.apache.org/repos/asf/xmlgraphics/fop/trunk@195556 13f79535-47bb-0310-9956-ffa450edef68 --- src/org/apache/fop/fo/FONode.java | 4 ++ src/org/apache/fop/fo/Title.java | 2 + src/org/apache/fop/fo/flow/Block.java | 1 + src/org/apache/fop/fo/flow/Flow.java | 4 +- src/org/apache/fop/fo/flow/Leader.java | 2 + src/org/apache/fop/fo/flow/ListItem.java | 2 + .../fop/fo/pagination/PageSequence.java | 1 + .../fop/layoutmgr/AbstractLayoutManager.java | 22 ++++++++ .../BlockContainerLayoutManager.java | 2 +- .../fop/layoutmgr/BlockLayoutManager.java | 25 ++++++--- src/org/apache/fop/layoutmgr/BreakPoss.java | 4 ++ .../fop/layoutmgr/ContentLayoutManager.java | 22 +++++++- .../fop/layoutmgr/FlowLayoutManager.java | 16 +++--- .../InlineStackingLayoutManager.java | 6 +-- .../apache/fop/layoutmgr/LayoutManager.java | 52 ++++++++++++++---- .../fop/layoutmgr/LineLayoutManager.java | 5 +- .../fop/layoutmgr/PageLayoutManager.java | 7 +-- .../layoutmgr/StaticContentLayoutManager.java | 8 +-- src/org/apache/fop/layoutmgr/list/Item.java | 21 ++++++-- .../list/ListBlockLayoutManager.java | 24 +++++++-- .../layoutmgr/list/ListItemLayoutManager.java | 25 +++++++-- src/org/apache/fop/layoutmgr/table/Body.java | 22 ++++++-- .../apache/fop/layoutmgr/table/Caption.java | 21 ++++++-- src/org/apache/fop/layoutmgr/table/Cell.java | 23 ++++++-- src/org/apache/fop/layoutmgr/table/Row.java | 53 +++++++++++++++++-- .../table/TableAndCaptionLayoutManager.java | 20 +++++-- .../layoutmgr/table/TableLayoutManager.java | 20 +++++-- 27 files changed, 344 insertions(+), 70 deletions(-) diff --git a/src/org/apache/fop/fo/FONode.java b/src/org/apache/fop/fo/FONode.java index c212b85b9..dabd6ff80 100644 --- a/src/org/apache/fop/fo/FONode.java +++ b/src/org/apache/fop/fo/FONode.java @@ -45,6 +45,10 @@ public abstract class FONode { userAgent = ua; } + public FOUserAgent getUserAgent() { + return userAgent; + } + public void setStructHandler(StructureHandler st) { } diff --git a/src/org/apache/fop/fo/Title.java b/src/org/apache/fop/fo/Title.java index 6ac1df5ca..9ee5d5c38 100644 --- a/src/org/apache/fop/fo/Title.java +++ b/src/org/apache/fop/fo/Title.java @@ -35,11 +35,13 @@ public class Title extends FObjMixed { InlineStackingLayoutManager lm; lm = new InlineStackingLayoutManager(this, new LMiter(children.listIterator())); + lm.setUserAgent(getUserAgent()); lm.init(); // get breaks then add areas to title ContentLayoutManager clm = new ContentLayoutManager(title); + clm.setUserAgent(getUserAgent()); lm.setParentLM(clm); clm.fillArea(lm); diff --git a/src/org/apache/fop/fo/flow/Block.java b/src/org/apache/fop/fo/flow/Block.java index 296e45dbf..a3c7f7444 100644 --- a/src/org/apache/fop/fo/flow/Block.java +++ b/src/org/apache/fop/fo/flow/Block.java @@ -176,6 +176,7 @@ public class Block extends FObjMixed { public void addLayoutManager(List list) { BlockLayoutManager blm = new BlockLayoutManager(this); + blm.setUserAgent(getUserAgent()); TextInfo ti = propMgr.getTextLayoutProps(fontInfo); blm.setBlockTextInfo(ti); list.add(blm); diff --git a/src/org/apache/fop/fo/flow/Flow.java b/src/org/apache/fop/fo/flow/Flow.java index 50ea4c2da..4f786d0c0 100644 --- a/src/org/apache/fop/fo/flow/Flow.java +++ b/src/org/apache/fop/fo/flow/Flow.java @@ -111,7 +111,9 @@ public class Flow extends FObj { } public void addLayoutManager(List list) { - list.add(new FlowLayoutManager(this)); + FlowLayoutManager lm = new FlowLayoutManager(this); + lm.setUserAgent(getUserAgent()); + list.add(lm); } } diff --git a/src/org/apache/fop/fo/flow/Leader.java b/src/org/apache/fop/fo/flow/Leader.java index c2fb0e372..930cf59af 100644 --- a/src/org/apache/fop/fo/flow/Leader.java +++ b/src/org/apache/fop/fo/flow/Leader.java @@ -123,12 +123,14 @@ public class Leader extends FObjMixed { InlineStackingLayoutManager lm; lm = new InlineStackingLayoutManager(this, new LMiter(children.listIterator())); + lm.setUserAgent(getUserAgent()); lm.init(); // get breaks then add areas to FilledArea FilledArea fa = new FilledArea(); ContentLayoutManager clm = new ContentLayoutManager(fa); + clm.setUserAgent(getUserAgent()); lm.setParentLM(clm); clm.fillArea(lm); diff --git a/src/org/apache/fop/fo/flow/ListItem.java b/src/org/apache/fop/fo/flow/ListItem.java index 1dc296d3e..af5db5880 100644 --- a/src/org/apache/fop/fo/flow/ListItem.java +++ b/src/org/apache/fop/fo/flow/ListItem.java @@ -43,6 +43,8 @@ public class ListItem extends FObj { blm.setLabel(label.getItemLayoutManager()); blm.setBody(body.getItemLayoutManager()); list.add(blm); + } else { + getLogger().error("list-item requires list-item-label and list-item-body"); } } diff --git a/src/org/apache/fop/fo/pagination/PageSequence.java b/src/org/apache/fop/fo/pagination/PageSequence.java index 9af862bfe..9e377eee0 100644 --- a/src/org/apache/fop/fo/pagination/PageSequence.java +++ b/src/org/apache/fop/fo/pagination/PageSequence.java @@ -339,6 +339,7 @@ public class PageSequence extends FObj { // This will layout pages and add them to the area tree PageLayoutManager pageLM = new PageLayoutManager(areaTree, this); + pageLM.setUserAgent(getUserAgent()); pageLM.setPageCounting(currentPageNumber, pageNumberGenerator); // For now, skip the threading and just call run directly. diff --git a/src/org/apache/fop/layoutmgr/AbstractLayoutManager.java b/src/org/apache/fop/layoutmgr/AbstractLayoutManager.java index 0a57777bd..9d649b266 100644 --- a/src/org/apache/fop/layoutmgr/AbstractLayoutManager.java +++ b/src/org/apache/fop/layoutmgr/AbstractLayoutManager.java @@ -8,6 +8,7 @@ package org.apache.fop.layoutmgr; import org.apache.fop.fo.FObj; +import org.apache.fop.fo.FOUserAgent; import org.apache.fop.area.Area; import org.apache.fop.area.Resolveable; import org.apache.fop.area.PageViewport; @@ -17,12 +18,15 @@ import org.apache.fop.layout.BorderAndPadding; import org.apache.fop.layout.BackgroundProps; import org.apache.fop.traits.BorderProps; +import org.apache.avalon.framework.logger.Logger; + import java.util.ListIterator; /** * The base class for all LayoutManagers. */ public abstract class AbstractLayoutManager implements LayoutManager { + protected FOUserAgent userAgent; protected LayoutManager parentLM; protected FObj fobj; protected String foID = null; @@ -51,6 +55,23 @@ public abstract class AbstractLayoutManager implements LayoutManager { childLMiter = lmIter; } + /** + * Set the user agent. + * + * @param ua the user agent + */ + public void setUserAgent(FOUserAgent ua) { + userAgent = ua; + } + + public FOUserAgent getUserAgent() { + return userAgent; + } + + protected Logger getLogger() { + return userAgent.getLogger(); + } + public void setParentLM(LayoutManager lm) { this.parentLM = lm; } @@ -109,6 +130,7 @@ public abstract class AbstractLayoutManager implements LayoutManager { } while (childLMiter.hasNext()) { curChildLM = (LayoutManager) childLMiter.next(); + curChildLM.setUserAgent(getUserAgent()); curChildLM.setParentLM(this); curChildLM.init(); return curChildLM; diff --git a/src/org/apache/fop/layoutmgr/BlockContainerLayoutManager.java b/src/org/apache/fop/layoutmgr/BlockContainerLayoutManager.java index f30ad2970..4ccfea572 100644 --- a/src/org/apache/fop/layoutmgr/BlockContainerLayoutManager.java +++ b/src/org/apache/fop/layoutmgr/BlockContainerLayoutManager.java @@ -193,7 +193,7 @@ public class BlockContainerLayoutManager extends BlockStackingLayoutManager { if (overflow == Overflow.HIDDEN) { clip = true; } else if (overflow == Overflow.ERROR_IF_OVERFLOW) { - //log.error("contents overflows block-container viewport: clipping"); + getLogger().error("contents overflows block-container viewport: clipping"); clip = true; } } diff --git a/src/org/apache/fop/layoutmgr/BlockLayoutManager.java b/src/org/apache/fop/layoutmgr/BlockLayoutManager.java index 0ad730170..63e56c613 100644 --- a/src/org/apache/fop/layoutmgr/BlockLayoutManager.java +++ b/src/org/apache/fop/layoutmgr/BlockLayoutManager.java @@ -91,6 +91,7 @@ public class BlockLayoutManager extends BlockStackingLayoutManager { LineLayoutManager child; child = new LineLayoutManager(fobj, inlines, lineHeight, lead, follow); + child.setUserAgent(getUserAgent()); return child; } @@ -149,20 +150,29 @@ public class BlockLayoutManager extends BlockStackingLayoutManager { boolean over = false; while (!curLM.isFinished()) { if ((bp = curLM.getNextBreakPoss(childLC)) != null) { - stackSize.add(bp.getStackingSize()); - if (stackSize.opt > context.getStackLimit().max) { + if (stackSize.opt + bp.getStackingSize().opt > context.getStackLimit().max) { // reset to last break if (lastPos != null) { - reset(lastPos.getPosition()); + LayoutManager lm = lastPos.getLayoutManager(); + lm.resetPosition(lastPos.getPosition()); + if (lm != curLM) { + curLM.resetPosition(null); + } } else { curLM.resetPosition(null); } over = true; break; } + stackSize.add(bp.getStackingSize()); lastPos = bp; childBreaks.add(bp); + if (bp.nextBreakOverflows()) { + over = true; + break; + } + if (curLM.generatesInlineAreas()) { // Reset stackLimit for non-first lines childLC.setStackLimit(new MinOptMax(ipd/* - iIndents*/)); @@ -179,6 +189,9 @@ public class BlockLayoutManager extends BlockStackingLayoutManager { } BreakPoss breakPoss = new BreakPoss( new LeafPosition(this, childBreaks.size() - 1)); + if (over) { + breakPoss.setFlag(BreakPoss.NEXT_OVERFLOWS, true); + } breakPoss.setStackingSize(stackSize); return breakPoss; } @@ -189,6 +202,8 @@ public class BlockLayoutManager extends BlockStackingLayoutManager { return breakPoss; } + int iStartPos = 0; + public void addAreas(PositionIterator parentIter, LayoutContext layoutContext) { getParentArea(null); @@ -200,12 +215,10 @@ public class BlockLayoutManager extends BlockStackingLayoutManager { addID(); LayoutManager childLM ; - int iStartPos = 0; LayoutContext lc = new LayoutContext(0); while (parentIter.hasNext()) { LeafPosition lfp = (LeafPosition) parentIter.next(); if (lfp.getLeafPos() == -2) { - childBreaks.clear(); curBlockArea = null; flush(); return; @@ -225,7 +238,6 @@ public class BlockLayoutManager extends BlockStackingLayoutManager { // if adjusted space after addBlockSpacing(adjust, layoutProps.spaceAfter.space); - childBreaks.clear(); curBlockArea = null; } @@ -273,6 +285,7 @@ public class BlockLayoutManager extends BlockStackingLayoutManager { if (resetPos == null) { reset(null); childBreaks.clear(); + iStartPos = 0; } else { //reset(resetPos); LayoutManager lm = resetPos.getLM(); diff --git a/src/org/apache/fop/layoutmgr/BreakPoss.java b/src/org/apache/fop/layoutmgr/BreakPoss.java index 2f9a01d11..237db85ae 100644 --- a/src/org/apache/fop/layoutmgr/BreakPoss.java +++ b/src/org/apache/fop/layoutmgr/BreakPoss.java @@ -162,6 +162,10 @@ public class BreakPoss { return ((m_flags & FORCE) != 0); } + public boolean nextBreakOverflows() { + return ((m_flags & NEXT_OVERFLOWS) != 0); + } + public boolean isSuppressible() { return ((m_flags & ALL_ARE_SUPPRESS_AT_LB) != 0); } diff --git a/src/org/apache/fop/layoutmgr/ContentLayoutManager.java b/src/org/apache/fop/layoutmgr/ContentLayoutManager.java index 3432c953f..49b55d128 100644 --- a/src/org/apache/fop/layoutmgr/ContentLayoutManager.java +++ b/src/org/apache/fop/layoutmgr/ContentLayoutManager.java @@ -6,11 +6,14 @@ */ package org.apache.fop.layoutmgr; +import org.apache.fop.fo.FOUserAgent; import org.apache.fop.area.Area; import org.apache.fop.area.MinOptMax; import org.apache.fop.area.Resolveable; import org.apache.fop.area.PageViewport; +import org.apache.avalon.framework.logger.Logger; + import java.util.List; import java.util.ArrayList; @@ -21,7 +24,7 @@ import java.util.ArrayList; * leader use-content and title. */ public class ContentLayoutManager implements LayoutManager { - + private FOUserAgent userAgent; private Area holder; private int stackSize; private LayoutManager parentLM; @@ -122,6 +125,23 @@ public class ContentLayoutManager implements LayoutManager { holder.addChild(childArea); } + /** + * Set the user agent. + * + * @param ua the user agent + */ + public void setUserAgent(FOUserAgent ua) { + userAgent = ua; + } + + public FOUserAgent getUserAgent() { + return userAgent; + } + + protected Logger getLogger() { + return userAgent.getLogger(); + } + /** @see org.apache.fop.layoutmgr.LayoutManager */ public void setParentLM(LayoutManager lm) { parentLM = lm; diff --git a/src/org/apache/fop/layoutmgr/FlowLayoutManager.java b/src/org/apache/fop/layoutmgr/FlowLayoutManager.java index f8011f033..58e57834d 100644 --- a/src/org/apache/fop/layoutmgr/FlowLayoutManager.java +++ b/src/org/apache/fop/layoutmgr/FlowLayoutManager.java @@ -38,12 +38,13 @@ public class FlowLayoutManager extends BlockStackingLayoutManager { public BreakPoss getNextBreakPoss(LayoutContext context) { - LayoutManager curLM ; // currently active LM + // currently active LM + LayoutManager curLM; MinOptMax stackSize = new MinOptMax(); while ((curLM = getChildLM()) != null) { if (curLM.generatesInlineAreas()) { - // problem + getLogger().error("inline area not allowed under flow - ignoring"); curLM.setFinished(true); continue; } @@ -65,9 +66,8 @@ public class FlowLayoutManager extends BlockStackingLayoutManager { // set stackLimit for remaining space childLC.setStackLimit(MinOptMax.subtract(bpd, stackSize)); - if (bp.isForcedBreak()) { + if (bp.isForcedBreak() || bp.nextBreakOverflows()) { breakPage = true; - break; } } } @@ -91,10 +91,11 @@ public class FlowLayoutManager extends BlockStackingLayoutManager { return null; } + int iStartPos = 0; + public void addAreas(PositionIterator parentIter, LayoutContext layoutContext) { - LayoutManager childLM ; - int iStartPos = 0; + LayoutManager childLM; LayoutContext lc = new LayoutContext(0); while (parentIter.hasNext()) { LeafPosition lfp = (LeafPosition) parentIter.next(); @@ -109,8 +110,6 @@ public class FlowLayoutManager extends BlockStackingLayoutManager { } flush(); - // clear the breaks for the page to start for the next page - blockBreaks.clear(); } @@ -147,6 +146,7 @@ public class FlowLayoutManager extends BlockStackingLayoutManager { */ public LayoutManager retrieveMarker(String name, int pos, int boundary) { // error cannot retrieve markers in flow + getLogger().error("Cannot retrieve a marker from the flow"); return null; } } diff --git a/src/org/apache/fop/layoutmgr/InlineStackingLayoutManager.java b/src/org/apache/fop/layoutmgr/InlineStackingLayoutManager.java index 1554a3d1e..8931289a5 100644 --- a/src/org/apache/fop/layoutmgr/InlineStackingLayoutManager.java +++ b/src/org/apache/fop/layoutmgr/InlineStackingLayoutManager.java @@ -149,7 +149,7 @@ public class InlineStackingLayoutManager extends AbstractLayoutManager { if (prevPos != null) { // ASSERT (prevPos.getLM() == this) if (prevPos.getLM() != this) { - //log.error( + //getLogger().error( // "InlineStackingLayoutManager.resetPosition: " + // "LM mismatch!!!"); } @@ -239,7 +239,7 @@ public class InlineStackingLayoutManager extends AbstractLayoutManager { // ignore nested blocks for now if (!curLM.generatesInlineAreas()) { - System.err.println("WARNING: ignoring block inside inline fo"); + getLogger().warn("ignoring block inside inline fo"); curLM.setFinished(true); continue; } @@ -547,7 +547,7 @@ public class InlineStackingLayoutManager extends AbstractLayoutManager { spaceRange.min) * dSpaceAdjust); } if (iAdjust != 0) { - //log.error("Add leading space: " + iAdjust); + //getLogger().debug("Add leading space: " + iAdjust); Space ls = new Space(); ls.setWidth(iAdjust); parentArea.addChild(ls); diff --git a/src/org/apache/fop/layoutmgr/LayoutManager.java b/src/org/apache/fop/layoutmgr/LayoutManager.java index ab3b3fc62..821263804 100644 --- a/src/org/apache/fop/layoutmgr/LayoutManager.java +++ b/src/org/apache/fop/layoutmgr/LayoutManager.java @@ -7,6 +7,7 @@ package org.apache.fop.layoutmgr; +import org.apache.fop.fo.FOUserAgent; import org.apache.fop.area.Area; import org.apache.fop.area.Resolveable; @@ -16,11 +17,40 @@ import org.apache.fop.area.PageViewport; * The interface for all LayoutManagers. */ public interface LayoutManager { - public boolean generatesInlineAreas(); - public Area getParentArea (Area childArea); - public void addChild (Area childArea); + + /** + * Set the user agent. + * + * @param ua the user agent + */ + public void setUserAgent(FOUserAgent ua); + + /** + * Get the user agent. + * + * @return the user agent + */ + public FOUserAgent getUserAgent(); + + /** + * Set the parent layout manager. + * The parent layout manager is required for adding areas. + * + * @param lm the parent layout manager + */ public void setParentLM(LayoutManager lm); + public void init(); + + /** + * Generates inline areas. + * This is used to check if the layout manager generates inline + * areas. + * + * @return true if the layout manager generates inline areas + */ + public boolean generatesInlineAreas(); + /** * Return true if the next area which would be generated by this * LayoutManager could start a new line (or flow for block-level FO). @@ -37,6 +67,11 @@ public interface LayoutManager { public BreakPoss getNextBreakPoss(LayoutContext context); + public void resetPosition(Position position); + + public void getWordChars(StringBuffer sbChars, Position bp1, + Position bp2); + /** * Return a value indicating whether this LayoutManager has laid out * all its content (or generated BreakPossibilities for all content.) @@ -50,6 +85,9 @@ public interface LayoutManager { */ public void setFinished(boolean isFinished); + public Area getParentArea(Area childArea); + public void addChild(Area childArea); + /** * Tell the layout manager to add all the child areas implied * by Position objects which will be returned by the @@ -57,13 +95,6 @@ public interface LayoutManager { */ public void addAreas(PositionIterator posIter, LayoutContext context); - public void init(); - - public void resetPosition(Position position); - - public void getWordChars(StringBuffer sbChars, Position bp1, - Position bp2); - /** * Get the string of the current page number. * @@ -121,3 +152,4 @@ public interface LayoutManager { public LayoutManager retrieveMarker(String name, int pos, int boundary); } + diff --git a/src/org/apache/fop/layoutmgr/LineLayoutManager.java b/src/org/apache/fop/layoutmgr/LineLayoutManager.java index 0a057d7e3..882644764 100644 --- a/src/org/apache/fop/layoutmgr/LineLayoutManager.java +++ b/src/org/apache/fop/layoutmgr/LineLayoutManager.java @@ -366,7 +366,7 @@ public class LineLayoutManager extends InlineStackingLayoutManager { while (bpIter.hasPrevious() && bpIter.previous() != prev) { } if (bpIter.next() != prev) { - //log.error("findHyphenPoss: problem!"); + getLogger().error("findHyphenPoss: problem!"); return null; } StringBuffer sbChars = new StringBuffer(30); @@ -382,7 +382,7 @@ public class LineLayoutManager extends InlineStackingLayoutManager { prev = bp; } vecInlineBreaks.remove(vecInlineBreaks.size() - 1); // remove last - //log.debug("Word to hyphenate: " + sbChars.toString()); + getLogger().debug("Word to hyphenate: " + sbChars.toString()); // Now find all hyphenation points in this word (get in an array of offsets) // hyphProps are from the block level?. Note that according to the spec, @@ -586,7 +586,6 @@ public class LineLayoutManager extends InlineStackingLayoutManager { */ public void addAreas(PositionIterator parentIter, double dSpaceAdjust) { LayoutManager childLM; - //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 6f1c1a8b8..9c494fa61 100644 --- a/src/org/apache/fop/layoutmgr/PageLayoutManager.java +++ b/src/org/apache/fop/layoutmgr/PageLayoutManager.java @@ -328,7 +328,7 @@ public class PageLayoutManager extends AbstractLayoutManager implements Runnable // end the page. getParentArea(area); // Alternatively the child LM indicates to parent that it's full? - //System.out.println("size: " + area.getAllocationBPD().max + + //getLogger().debug("size: " + area.getAllocationBPD().max + // ":" + curSpan.getMaxBPD().min); /*if (area.getAllocationBPD().max >= curSpan.getMaxBPD().min) { // Consider it filled @@ -385,9 +385,10 @@ public class PageLayoutManager extends AbstractLayoutManager implements Runnable .getRegion(regionClass); reg.getRegion().setIPD((int)reg.getViewArea().getWidth()); if (reg == null) { - System.out.println("no region viewport: shouldn't happen"); + getLogger().error("no region viewport: shouldn't happen"); } StaticContentLayoutManager lm = flow.getLayoutManager(); + lm.setUserAgent(getUserAgent()); lm.init(); lm.setRegionReference(reg.getRegion()); lm.setParentLM(this); @@ -403,7 +404,7 @@ public class PageLayoutManager extends AbstractLayoutManager implements Runnable lm.addAreas(new BreakPossPosIter(vecBreakPoss, 0, vecBreakPoss.size()), null); } else { - System.out.println("bp==null cls=" + regionClass); + getLogger().error("bp==null cls=" + regionClass); } } //lm.flush(); diff --git a/src/org/apache/fop/layoutmgr/StaticContentLayoutManager.java b/src/org/apache/fop/layoutmgr/StaticContentLayoutManager.java index 280d2ef8a..7d5c3a75e 100644 --- a/src/org/apache/fop/layoutmgr/StaticContentLayoutManager.java +++ b/src/org/apache/fop/layoutmgr/StaticContentLayoutManager.java @@ -36,7 +36,8 @@ public class StaticContentLayoutManager extends BlockStackingLayoutManager { public BreakPoss getNextBreakPoss(LayoutContext context) { - LayoutManager curLM; // currently active LM + // currently active LM + LayoutManager curLM; while ((curLM = getChildLM()) != null) { // Make break positions and return page break @@ -47,7 +48,7 @@ public class StaticContentLayoutManager extends BlockStackingLayoutManager { if ((bp = curLM.getNextBreakPoss(childLC)) != null) { blockBreaks.add(bp); if (bp.isForcedBreak()) { - System.out.println("Forced breaks are not allowed in static content"); + getLogger().error("Forced breaks are not allowed in static content - ignoring"); return null; } } @@ -79,8 +80,6 @@ public class StaticContentLayoutManager extends BlockStackingLayoutManager { } flush(); - // clear the breaks for the page to start for the next page - blockBreaks.clear(); } @@ -105,6 +104,7 @@ public class StaticContentLayoutManager extends BlockStackingLayoutManager { */ public void addMarker(String name, LayoutManager lm, boolean start) { // error markers not allowed in static + getLogger().error("Cannot add marker to static areas"); } } diff --git a/src/org/apache/fop/layoutmgr/list/Item.java b/src/org/apache/fop/layoutmgr/list/Item.java index 579c08491..029c864e9 100644 --- a/src/org/apache/fop/layoutmgr/list/Item.java +++ b/src/org/apache/fop/layoutmgr/list/Item.java @@ -88,27 +88,40 @@ public class Item extends BlockStackingLayoutManager { stackSize)); childLC.setRefIPD(ipd); + boolean over = false; while (!curLM.isFinished()) { if ((bp = curLM.getNextBreakPoss(childLC)) != null) { - stackSize.add(bp.getStackingSize()); - if (stackSize.opt > context.getStackLimit().max) { + if (stackSize.opt + bp.getStackingSize().opt > context.getStackLimit().max) { // reset to last break if (lastPos != null) { - reset(lastPos.getPosition()); + LayoutManager lm = lastPos.getLayoutManager(); + lm.resetPosition(lastPos.getPosition()); + if (lm != curLM) { + curLM.resetPosition(null); + } } else { curLM.resetPosition(null); } break; } + stackSize.add(bp.getStackingSize()); lastPos = bp; childBreaks.add(bp); + if (bp.nextBreakOverflows()) { + over = true; + break; + } + childLC.setStackLimit(MinOptMax.subtract( context.getStackLimit(), stackSize)); } } BreakPoss breakPoss = new BreakPoss( new LeafPosition(this, childBreaks.size() - 1)); + if (over) { + breakPoss.setFlag(BreakPoss.NEXT_OVERFLOWS, true); + } breakPoss.setStackingSize(stackSize); return breakPoss; } @@ -220,6 +233,8 @@ public class Item extends BlockStackingLayoutManager { public void resetPosition(Position resetPos) { if (resetPos == null) { reset(null); + } else { + //reset(resetPos); } } } diff --git a/src/org/apache/fop/layoutmgr/list/ListBlockLayoutManager.java b/src/org/apache/fop/layoutmgr/list/ListBlockLayoutManager.java index 36bb832f0..73db239dd 100644 --- a/src/org/apache/fop/layoutmgr/list/ListBlockLayoutManager.java +++ b/src/org/apache/fop/layoutmgr/list/ListBlockLayoutManager.java @@ -70,7 +70,8 @@ public class ListBlockLayoutManager extends BlockStackingLayoutManager { * @return the next break possibility */ public BreakPoss getNextBreakPoss(LayoutContext context) { - LayoutManager curLM; // currently active LM + // currently active LM + LayoutManager curLM; MinOptMax stackSize = new MinOptMax(); // if starting add space before @@ -89,27 +90,40 @@ public class ListBlockLayoutManager extends BlockStackingLayoutManager { stackSize)); childLC.setRefIPD(ipd); + boolean over = false; while (!curLM.isFinished()) { if ((bp = curLM.getNextBreakPoss(childLC)) != null) { - stackSize.add(bp.getStackingSize()); - if (stackSize.opt > context.getStackLimit().max) { + if (stackSize.opt + bp.getStackingSize().opt > context.getStackLimit().max) { // reset to last break if (lastPos != null) { - reset(lastPos.getPosition()); + LayoutManager lm = lastPos.getLayoutManager(); + lm.resetPosition(lastPos.getPosition()); + if (lm != curLM) { + curLM.resetPosition(null); + } } else { curLM.resetPosition(null); } break; } + stackSize.add(bp.getStackingSize()); lastPos = bp; bodyBreaks.add(bp); + if (bp.nextBreakOverflows()) { + over = true; + break; + } + childLC.setStackLimit(MinOptMax.subtract( context.getStackLimit(), stackSize)); } } BreakPoss breakPoss = new BreakPoss( new LeafPosition(this, bodyBreaks.size() - 1)); + if (over) { + breakPoss.setFlag(BreakPoss.NEXT_OVERFLOWS, true); + } breakPoss.setStackingSize(stackSize); return breakPoss; } @@ -209,6 +223,8 @@ public class ListBlockLayoutManager extends BlockStackingLayoutManager { if (resetPos == null) { bodyBreaks.clear(); reset(null); + } else { + } } } diff --git a/src/org/apache/fop/layoutmgr/list/ListItemLayoutManager.java b/src/org/apache/fop/layoutmgr/list/ListItemLayoutManager.java index dbff104dc..e495f0c44 100644 --- a/src/org/apache/fop/layoutmgr/list/ListItemLayoutManager.java +++ b/src/org/apache/fop/layoutmgr/list/ListItemLayoutManager.java @@ -82,7 +82,11 @@ public class ListItemLayoutManager extends BlockStackingLayoutManager { * @return the next break possibility */ public BreakPoss getNextBreakPoss(LayoutContext context) { - Item curLM; // currently active LM + // currently active LM + Item curLM; + + label.setUserAgent(getUserAgent()); + body.setUserAgent(getUserAgent()); BreakPoss lastPos = null; List breakList = new ArrayList(); @@ -92,6 +96,7 @@ public class ListItemLayoutManager extends BlockStackingLayoutManager { int max = 0; int stage = 0; + boolean over = false; while (true) { if(stage == 0) { curLM = label; @@ -120,11 +125,14 @@ public class ListItemLayoutManager extends BlockStackingLayoutManager { stage++; while (!curLM.isFinished()) { if ((bp = curLM.getNextBreakPoss(childLC)) != null) { - stackSize.add(bp.getStackingSize()); - if (stackSize.opt > context.getStackLimit().max) { + if (stackSize.opt + bp.getStackingSize().opt > context.getStackLimit().max) { // reset to last break if (lastPos != null) { - curLM.resetPosition(lastPos.getPosition()); + LayoutManager lm = lastPos.getLayoutManager(); + lm.resetPosition(lastPos.getPosition()); + if (lm != curLM) { + curLM.resetPosition(null); + } } else { curLM.resetPosition(null); } @@ -132,8 +140,14 @@ public class ListItemLayoutManager extends BlockStackingLayoutManager { } else { lastPos = bp; } + stackSize.add(bp.getStackingSize()); childBreaks.add(bp); + if (bp.nextBreakOverflows()) { + over = true; + break; + } + childLC.setStackLimit(MinOptMax.subtract( context.getStackLimit(), stackSize)); } @@ -160,6 +174,9 @@ public class ListItemLayoutManager extends BlockStackingLayoutManager { setFinished(true); ItemPosition rp = new ItemPosition(this, breakList.size() - 1, breakList); BreakPoss breakPoss = new BreakPoss(rp); + if (over) { + breakPoss.setFlag(BreakPoss.NEXT_OVERFLOWS, true); + } breakPoss.setStackingSize(itemSize); return breakPoss; } diff --git a/src/org/apache/fop/layoutmgr/table/Body.java b/src/org/apache/fop/layoutmgr/table/Body.java index 7ca0079d3..7fc135b7d 100644 --- a/src/org/apache/fop/layoutmgr/table/Body.java +++ b/src/org/apache/fop/layoutmgr/table/Body.java @@ -8,6 +8,7 @@ package org.apache.fop.layoutmgr.table; import org.apache.fop.fo.PropertyManager; +import org.apache.fop.layoutmgr.LayoutManager; import org.apache.fop.layoutmgr.BlockStackingLayoutManager; import org.apache.fop.layoutmgr.LeafPosition; import org.apache.fop.layoutmgr.BreakPoss; @@ -99,27 +100,42 @@ public class Body extends BlockStackingLayoutManager { curLM.setColumns(columns); + boolean over = false; + while (!curLM.isFinished()) { if ((bp = curLM.getNextBreakPoss(childLC)) != null) { - stackSize.add(bp.getStackingSize()); - if (stackSize.opt > context.getStackLimit().max) { + if (stackSize.opt + bp.getStackingSize().opt > context.getStackLimit().max) { // reset to last break if (lastPos != null) { - reset(lastPos.getPosition()); + LayoutManager lm = lastPos.getLayoutManager(); + lm.resetPosition(lastPos.getPosition()); + if (lm != curLM) { + curLM.resetPosition(null); + } } else { curLM.resetPosition(null); } + over = true; break; } + stackSize.add(bp.getStackingSize()); lastPos = bp; childBreaks.add(bp); + if (bp.nextBreakOverflows()) { + over = true; + break; + } + childLC.setStackLimit(MinOptMax.subtract( context.getStackLimit(), stackSize)); } } BreakPoss breakPoss = new BreakPoss( new LeafPosition(this, childBreaks.size() - 1)); + if (over) { + breakPoss.setFlag(BreakPoss.NEXT_OVERFLOWS, true); + } breakPoss.setStackingSize(stackSize); return breakPoss; } diff --git a/src/org/apache/fop/layoutmgr/table/Caption.java b/src/org/apache/fop/layoutmgr/table/Caption.java index 6c111cd56..c69ab7b0f 100644 --- a/src/org/apache/fop/layoutmgr/table/Caption.java +++ b/src/org/apache/fop/layoutmgr/table/Caption.java @@ -74,27 +74,42 @@ public class Caption extends BlockStackingLayoutManager { stackSize)); childLC.setRefIPD(ipd); + boolean over = false; + while (!curLM.isFinished()) { if ((bp = curLM.getNextBreakPoss(childLC)) != null) { - stackSize.add(bp.getStackingSize()); - if (stackSize.opt > context.getStackLimit().max) { + if (stackSize.opt + bp.getStackingSize().opt > context.getStackLimit().max) { // reset to last break if (lastPos != null) { - reset(lastPos.getPosition()); + LayoutManager lm = lastPos.getLayoutManager(); + lm.resetPosition(lastPos.getPosition()); + if (lm != curLM) { + curLM.resetPosition(null); + } } else { curLM.resetPosition(null); } + over = true; break; } + stackSize.add(bp.getStackingSize()); lastPos = bp; childBreaks.add(bp); + if (bp.nextBreakOverflows()) { + over = true; + break; + } + childLC.setStackLimit(MinOptMax.subtract( context.getStackLimit(), stackSize)); } } BreakPoss breakPoss = new BreakPoss( new LeafPosition(this, childBreaks.size() - 1)); + if (over) { + breakPoss.setFlag(BreakPoss.NEXT_OVERFLOWS, true); + } breakPoss.setStackingSize(stackSize); return breakPoss; } diff --git a/src/org/apache/fop/layoutmgr/table/Cell.java b/src/org/apache/fop/layoutmgr/table/Cell.java index 0c0dd1f5a..c0e00da2d 100644 --- a/src/org/apache/fop/layoutmgr/table/Cell.java +++ b/src/org/apache/fop/layoutmgr/table/Cell.java @@ -77,7 +77,7 @@ public class Cell extends BlockStackingLayoutManager { while ((curLM = getChildLM()) != null) { if(curLM.generatesInlineAreas()) { - // error + getLogger().error("table-cell must contain block areas - ignoring"); curLM.setFinished(true); continue; } @@ -90,27 +90,42 @@ public class Cell extends BlockStackingLayoutManager { stackSize)); childLC.setRefIPD(ipd); + boolean over = false; + while (!curLM.isFinished()) { if ((bp = curLM.getNextBreakPoss(childLC)) != null) { - stackSize.add(bp.getStackingSize()); - if (stackSize.opt > context.getStackLimit().max) { + if (stackSize.opt + bp.getStackingSize().opt > context.getStackLimit().max) { // reset to last break if (lastPos != null) { - reset(lastPos.getPosition()); + LayoutManager lm = lastPos.getLayoutManager(); + lm.resetPosition(lastPos.getPosition()); + if (lm != curLM) { + curLM.resetPosition(null); + } } else { curLM.resetPosition(null); } + over = true; break; } + stackSize.add(bp.getStackingSize()); lastPos = bp; childBreaks.add(bp); + if (bp.nextBreakOverflows()) { + over = true; + break; + } + childLC.setStackLimit(MinOptMax.subtract( context.getStackLimit(), stackSize)); } } BreakPoss breakPoss = new BreakPoss( new LeafPosition(this, childBreaks.size() - 1)); + if (over) { + breakPoss.setFlag(BreakPoss.NEXT_OVERFLOWS, true); + } breakPoss.setStackingSize(stackSize); return breakPoss; } diff --git a/src/org/apache/fop/layoutmgr/table/Row.java b/src/org/apache/fop/layoutmgr/table/Row.java index 8c8d0a790..a7beb6695 100644 --- a/src/org/apache/fop/layoutmgr/table/Row.java +++ b/src/org/apache/fop/layoutmgr/table/Row.java @@ -84,6 +84,7 @@ public class Row extends BlockStackingLayoutManager { // add cells to list while (childLMiter.hasNext()) { curChildLM = (LayoutManager) childLMiter.next(); + curChildLM.setUserAgent(getUserAgent()); curChildLM.setParentLM(this); curChildLM.init(); cellList.add(curChildLM); @@ -125,6 +126,8 @@ public class Row extends BlockStackingLayoutManager { int max = 0; int cellcount = 0; + boolean over = false; + while ((curLM = getCellLM(cellcount++)) != null) { List childBreaks = new ArrayList(); @@ -151,19 +154,29 @@ public class Row extends BlockStackingLayoutManager { while (!curLM.isFinished()) { if ((bp = curLM.getNextBreakPoss(childLC)) != null) { - stackSize.add(bp.getStackingSize()); - if (stackSize.opt > context.getStackLimit().max) { + if (stackSize.opt + bp.getStackingSize().opt > context.getStackLimit().max) { // reset to last break if (lastPos != null) { - reset(lastPos.getPosition()); + LayoutManager lm = lastPos.getLayoutManager(); + lm.resetPosition(lastPos.getPosition()); + if (lm != curLM) { + curLM.resetPosition(null); + } } else { curLM.resetPosition(null); } + over = true; break; } + stackSize.add(bp.getStackingSize()); lastPos = bp; childBreaks.add(bp); + if (bp.nextBreakOverflows()) { + over = true; + break; + } + childLC.setStackLimit(MinOptMax.subtract( context.getStackLimit(), stackSize)); } @@ -190,10 +203,44 @@ public class Row extends BlockStackingLayoutManager { setFinished(true); RowPosition rp = new RowPosition(this, breakList.size() - 1, breakList); BreakPoss breakPoss = new BreakPoss(rp); + if (over) { + breakPoss.setFlag(BreakPoss.NEXT_OVERFLOWS, true); + } breakPoss.setStackingSize(rowSize); return breakPoss; } + /** + * Reset the layoutmanager "iterator" so that it will start + * with the passed Position's generating LM + * on the next call to getChildLM. + * @param pos a Position returned by a child layout manager + * representing a potential break decision. + * If pos is null, then back up to the first child LM. + */ + protected void reset(Position pos) { + LayoutManager curLM; // currently active LM + int cellcount = 0; + + if (pos == null) { + while ((curLM = getCellLM(cellcount++)) != null) { + curLM.resetPosition(null); + cellcount++; + } + } else { + RowPosition rpos = (RowPosition)pos; + List breaks = rpos.cellBreaks; + + while ((curLM = getCellLM(cellcount++)) != null) { + List childbreaks = (List)breaks.get(cellcount); + curLM.resetPosition((Position)childbreaks.get(childbreaks.size() - 1)); + cellcount++; + } + } + + setFinished(false); + } + /** * Set the y position offset of this row. * This is used to set the position of the areas returned by this row. diff --git a/src/org/apache/fop/layoutmgr/table/TableAndCaptionLayoutManager.java b/src/org/apache/fop/layoutmgr/table/TableAndCaptionLayoutManager.java index 920a72785..0b7c2ccf4 100644 --- a/src/org/apache/fop/layoutmgr/table/TableAndCaptionLayoutManager.java +++ b/src/org/apache/fop/layoutmgr/table/TableAndCaptionLayoutManager.java @@ -76,27 +76,41 @@ public class TableAndCaptionLayoutManager extends BlockStackingLayoutManager { stackSize)); childLC.setRefIPD(ipd); + boolean over = false; while (!curLM.isFinished()) { if ((bp = curLM.getNextBreakPoss(childLC)) != null) { - stackSize.add(bp.getStackingSize()); - if (stackSize.opt > context.getStackLimit().max) { + if (stackSize.opt + bp.getStackingSize().opt > context.getStackLimit().max) { // reset to last break if (lastPos != null) { - reset(lastPos.getPosition()); + LayoutManager lm = lastPos.getLayoutManager(); + lm.resetPosition(lastPos.getPosition()); + if (lm != curLM) { + curLM.resetPosition(null); + } } else { curLM.resetPosition(null); } + over = true; break; } + stackSize.add(bp.getStackingSize()); lastPos = bp; childBreaks.add(bp); + if (bp.nextBreakOverflows()) { + over = true; + break; + } + childLC.setStackLimit(MinOptMax.subtract( context.getStackLimit(), stackSize)); } } BreakPoss breakPoss = new BreakPoss( new LeafPosition(this, childBreaks.size() - 1)); + if (over) { + breakPoss.setFlag(BreakPoss.NEXT_OVERFLOWS, true); + } breakPoss.setStackingSize(stackSize); return breakPoss; } diff --git a/src/org/apache/fop/layoutmgr/table/TableLayoutManager.java b/src/org/apache/fop/layoutmgr/table/TableLayoutManager.java index c51c6061c..45672fffe 100644 --- a/src/org/apache/fop/layoutmgr/table/TableLayoutManager.java +++ b/src/org/apache/fop/layoutmgr/table/TableLayoutManager.java @@ -139,27 +139,41 @@ public class TableLayoutManager extends BlockStackingLayoutManager { curLM.setColumns(columns); + boolean over = false; while (!curLM.isFinished()) { if ((bp = curLM.getNextBreakPoss(childLC)) != null) { - stackSize.add(bp.getStackingSize()); - if (stackSize.opt > context.getStackLimit().max) { + if (stackSize.opt + bp.getStackingSize().opt > context.getStackLimit().max) { // reset to last break if (lastPos != null) { - reset(lastPos.getPosition()); + LayoutManager lm = lastPos.getLayoutManager(); + lm.resetPosition(lastPos.getPosition()); + if (lm != curLM) { + curLM.resetPosition(null); + } } else { curLM.resetPosition(null); } + over = true; break; } + stackSize.add(bp.getStackingSize()); lastPos = bp; bodyBreaks.add(bp); + if (bp.nextBreakOverflows()) { + over = true; + break; + } + childLC.setStackLimit(MinOptMax.subtract( context.getStackLimit(), stackSize)); } } BreakPoss breakPoss = new BreakPoss( new LeafPosition(this, bodyBreaks.size() - 1)); + if (over) { + breakPoss.setFlag(BreakPoss.NEXT_OVERFLOWS, true); + } breakPoss.setStackingSize(stackSize); return breakPoss; } -- 2.39.5