You are viewing a plain text version of this content. The canonical link for it is here.
Posted to fop-commits@xmlgraphics.apache.org by je...@apache.org on 2011/02/10 15:09:46 UTC
svn commit: r1069397 [3/6] - in /xmlgraphics/fop/branches/Temp_Color: ./
lib/ lib/build/ src/codegen/java/org/apache/fop/tools/
src/documentation/content/xdocs/ src/documentation/content/xdocs/trunk/
src/documentation/resources/images/ src/java/org/apa...
Modified: xmlgraphics/fop/branches/Temp_Color/src/java/org/apache/fop/fonts/SingleByteFont.java
URL: http://svn.apache.org/viewvc/xmlgraphics/fop/branches/Temp_Color/src/java/org/apache/fop/fonts/SingleByteFont.java?rev=1069397&r1=1069396&r2=1069397&view=diff
==============================================================================
--- xmlgraphics/fop/branches/Temp_Color/src/java/org/apache/fop/fonts/SingleByteFont.java (original)
+++ xmlgraphics/fop/branches/Temp_Color/src/java/org/apache/fop/fonts/SingleByteFont.java Thu Feb 10 14:09:42 2011
@@ -29,6 +29,8 @@ import java.util.TreeSet;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
+import org.apache.xmlgraphics.fonts.Glyphs;
+
/**
* Generic SingleByte font
*/
@@ -44,6 +46,7 @@ public class SingleByteFont extends Cust
private Map<Character, UnencodedCharacter> unencodedCharacters;
private List<SimpleSingleByteEncoding> additionalEncodings;
+ private Map<Character, Character> alternativeCodes;
/**
@@ -99,19 +102,69 @@ public class SingleByteFont extends Cust
return arr;
}
- /** {@inheritDoc} */
- @Override
- public char mapChar(char c) {
- notifyMapOperation();
+ /**
+ * Lookup a character using its alternative names. If found, cache it so we
+ * can speed up lookups.
+ * @param c the character
+ * @return the suggested alternative character present in the font
+ */
+ private char findAlternative(char c) {
+ char d;
+ if (alternativeCodes == null) {
+ alternativeCodes = new java.util.HashMap<Character, Character>();
+ } else {
+ Character alternative = alternativeCodes.get(c);
+ if (alternative != null) {
+ return alternative;
+ }
+ }
+ String charName = Glyphs.charToGlyphName(c);
+ String[] charNameAlternatives = Glyphs.getCharNameAlternativesFor(charName);
+ if (charNameAlternatives != null && charNameAlternatives.length > 0) {
+ for (int i = 0; i < charNameAlternatives.length; i++) {
+ if (log.isDebugEnabled()) {
+ log.debug("Checking alternative for char " + c + " (charname="
+ + charName + "): " + charNameAlternatives[i]);
+ }
+ String s = Glyphs.getUnicodeSequenceForGlyphName(charNameAlternatives[i]);
+ if (s != null) {
+ d = lookupChar(s.charAt(0));
+ if (d != SingleByteEncoding.NOT_FOUND_CODE_POINT) {
+ alternativeCodes.put(c, d);
+ return d;
+ }
+ }
+ }
+ }
+
+ return SingleByteEncoding.NOT_FOUND_CODE_POINT;
+ }
+
+ private char lookupChar(char c) {
char d = mapping.mapChar(c);
if (d != SingleByteEncoding.NOT_FOUND_CODE_POINT) {
return d;
}
- //Check unencoded characters which are available in the font by character name
+ // Check unencoded characters which are available in the font by
+ // character name
d = mapUnencodedChar(c);
+ return d;
+ }
+
+ /** {@inheritDoc} */
+ @Override
+ public char mapChar(char c) {
+ notifyMapOperation();
+ char d = lookupChar(c);
if (d != SingleByteEncoding.NOT_FOUND_CODE_POINT) {
return d;
+ } else {
+ // Check for alternative
+ d = findAlternative(c);
+ if (d != SingleByteEncoding.NOT_FOUND_CODE_POINT) {
+ return d;
+ }
}
this.warnMissingGlyph(c);
return Typeface.NOT_FOUND;
@@ -162,6 +215,11 @@ public class SingleByteFont extends Cust
if (d != SingleByteEncoding.NOT_FOUND_CODE_POINT) {
return true;
}
+ // Check if an alternative exists
+ d = findAlternative(c);
+ if (d != SingleByteEncoding.NOT_FOUND_CODE_POINT) {
+ return true;
+ }
return false;
}
Modified: xmlgraphics/fop/branches/Temp_Color/src/java/org/apache/fop/layoutmgr/AbstractLayoutManager.java
URL: http://svn.apache.org/viewvc/xmlgraphics/fop/branches/Temp_Color/src/java/org/apache/fop/layoutmgr/AbstractLayoutManager.java?rev=1069397&r1=1069396&r2=1069397&view=diff
==============================================================================
--- xmlgraphics/fop/branches/Temp_Color/src/java/org/apache/fop/layoutmgr/AbstractLayoutManager.java (original)
+++ xmlgraphics/fop/branches/Temp_Color/src/java/org/apache/fop/layoutmgr/AbstractLayoutManager.java Thu Feb 10 14:09:42 2011
@@ -20,7 +20,6 @@
package org.apache.fop.layoutmgr;
import java.util.ArrayList;
-import java.util.Iterator;
import java.util.List;
import java.util.ListIterator;
import java.util.Map;
@@ -34,27 +33,27 @@ import org.apache.fop.area.PageViewport;
import org.apache.fop.fo.Constants;
import org.apache.fop.fo.FONode;
import org.apache.fop.fo.FObj;
+import org.apache.fop.fo.flow.Marker;
import org.apache.fop.fo.flow.RetrieveMarker;
+import org.apache.xmlgraphics.util.QName;
/**
* The base class for most LayoutManagers.
*/
public abstract class AbstractLayoutManager extends AbstractBaseLayoutManager
- implements Constants {
+ implements Constants {
- /**
- * logging instance
- */
+ /** logging instance */
private static Log log = LogFactory.getLog(AbstractLayoutManager.class);
/** Parent LayoutManager for this LayoutManager */
protected LayoutManager parentLayoutManager;
/** List of child LayoutManagers */
- protected List childLMs;
+ protected List<LayoutManager> childLMs;
/** Iterator for child LayoutManagers */
protected ListIterator fobjIter;
/** Marker map for markers related to this LayoutManager */
- private Map markers;
+ private Map<String, Marker> markers;
/** True if this LayoutManager has handled all of its content. */
private boolean isFinished;
@@ -63,7 +62,7 @@ public abstract class AbstractLayoutMana
protected LayoutManager curChildLM;
/** child LM iterator during getNextKnuthElement phase */
- protected ListIterator childLMiter;
+ protected ListIterator<LayoutManager> childLMiter;
private int lastGeneratedPosition = -1;
private int smallestPosNumberChecked = Integer.MAX_VALUE;
@@ -116,7 +115,7 @@ public abstract class AbstractLayoutMana
return curChildLM;
}
if (childLMiter.hasNext()) {
- curChildLM = (LayoutManager) childLMiter.next();
+ curChildLM = childLMiter.next();
curChildLM.initialize();
return curChildLM;
}
@@ -131,7 +130,7 @@ public abstract class AbstractLayoutMana
curChildLM = childLM;
childLMiter = new LMiter(this);
do {
- curChildLM = (LayoutManager) childLMiter.next();
+ curChildLM = childLMiter.next();
} while (curChildLM != childLM);
}
@@ -165,16 +164,14 @@ public abstract class AbstractLayoutMana
}
/** {@inheritDoc} */
- public List getNextKnuthElements(LayoutContext context,
- int alignment) {
+ public List getNextKnuthElements(LayoutContext context, int alignment) {
log.warn("null implementation of getNextKnuthElements() called!");
setFinished(true);
return null;
}
/** {@inheritDoc} */
- public List getChangedKnuthElements(List oldList,
- int alignment) {
+ public List getChangedKnuthElements(List oldList, int alignment) {
log.warn("null implementation of getChangeKnuthElement() called!");
return null;
}
@@ -210,11 +207,11 @@ public abstract class AbstractLayoutMana
* @param size the requested number of child LMs
* @return the list with the preloaded child LMs
*/
- protected List createChildLMs(int size) {
+ protected List<LayoutManager> createChildLMs(int size) {
if (fobjIter == null) {
return null;
}
- List newLMs = new ArrayList(size);
+ List<LayoutManager> newLMs = new ArrayList<LayoutManager>(size);
while (fobjIter.hasNext() && newLMs.size() < size ) {
Object theobj = fobjIter.next();
if (theobj instanceof FONode) {
@@ -250,35 +247,29 @@ public abstract class AbstractLayoutMana
return getPSLM().getCurrentPage().getPageViewport();
}
- /**
- * {@inheritDoc}
- */
+ /** {@inheritDoc} */
public boolean createNextChildLMs(int pos) {
- List newLMs = createChildLMs(pos + 1 - childLMs.size());
+ List<LayoutManager> newLMs = createChildLMs(pos + 1 - childLMs.size());
addChildLMs(newLMs);
return pos < childLMs.size();
}
- /**
- * {@inheritDoc}
- */
- public List getChildLMs() {
+ /** {@inheritDoc} */
+ public List<LayoutManager> getChildLMs() {
if (childLMs == null) {
- childLMs = new java.util.ArrayList(10);
+ childLMs = new java.util.ArrayList<LayoutManager>(10);
}
return childLMs;
}
- /**
- * {@inheritDoc}
- */
+ /** {@inheritDoc} */
public void addChildLM(LayoutManager lm) {
if (lm == null) {
return;
}
lm.setParent(this);
if (childLMs == null) {
- childLMs = new java.util.ArrayList(10);
+ childLMs = new java.util.ArrayList<LayoutManager>(10);
}
childLMs.add(lm);
if (log.isTraceEnabled()) {
@@ -287,17 +278,14 @@ public abstract class AbstractLayoutMana
}
}
- /**
- * {@inheritDoc}
- */
+ /** {@inheritDoc} */
public void addChildLMs(List newLMs) {
if (newLMs == null || newLMs.size() == 0) {
return;
}
- ListIterator iter = newLMs.listIterator();
+ ListIterator<LayoutManager> iter = newLMs.listIterator();
while (iter.hasNext()) {
- LayoutManager lm = (LayoutManager) iter.next();
- addChildLM(lm);
+ addChildLM(iter.next());
}
}
@@ -312,8 +300,7 @@ public abstract class AbstractLayoutMana
throw new IllegalStateException("Position already got its index");
}
- lastGeneratedPosition++;
- pos.setIndex(lastGeneratedPosition);
+ pos.setIndex(++lastGeneratedPosition);
return pos;
}
@@ -358,7 +345,7 @@ public abstract class AbstractLayoutMana
* @param targetArea the area to set the attributes on
*/
protected void transferForeignAttributes(AreaTreeObject targetArea) {
- Map atts = fobj.getForeignAttributes();
+ Map<QName, String> atts = fobj.getForeignAttributes();
targetArea.setForeignAttributes(atts);
}
@@ -459,18 +446,20 @@ public abstract class AbstractLayoutMana
}
/** {@inheritDoc} */
+ @Override
public String toString() {
return (super.toString() + (fobj != null ? "[fobj=" + fobj.toString() + "]" : ""));
}
/** {@inheritDoc} */
+ @Override
public void reset() {
isFinished = false;
curChildLM = null;
childLMiter = new LMiter(this);
/* Reset all the children LM that have been created so far. */
- for (Iterator iter = getChildLMs().iterator(); iter.hasNext();) {
- ((LayoutManager) iter.next()).reset();
+ for (LayoutManager childLM : getChildLMs()) {
+ childLM.reset();
}
if (fobj != null) {
markers = fobj.getMarkers();
Modified: xmlgraphics/fop/branches/Temp_Color/src/java/org/apache/fop/layoutmgr/AreaAdditionUtil.java
URL: http://svn.apache.org/viewvc/xmlgraphics/fop/branches/Temp_Color/src/java/org/apache/fop/layoutmgr/AreaAdditionUtil.java?rev=1069397&r1=1069396&r2=1069397&view=diff
==============================================================================
--- xmlgraphics/fop/branches/Temp_Color/src/java/org/apache/fop/layoutmgr/AreaAdditionUtil.java (original)
+++ xmlgraphics/fop/branches/Temp_Color/src/java/org/apache/fop/layoutmgr/AreaAdditionUtil.java Thu Feb 10 14:09:42 2011
@@ -19,7 +19,6 @@
package org.apache.fop.layoutmgr;
-import java.util.Iterator;
import java.util.LinkedList;
import org.apache.fop.layoutmgr.SpaceResolver.SpaceHandlingBreakPosition;
@@ -32,20 +31,6 @@ public final class AreaAdditionUtil {
private AreaAdditionUtil() {
}
- private static class StackingIter extends PositionIterator {
- StackingIter(Iterator parentIter) {
- super(parentIter);
- }
-
- protected LayoutManager getLM(Object nextObj) {
- return ((Position) nextObj).getLM();
- }
-
- protected Position getPos(Object nextObj) {
- return ((Position) nextObj);
- }
- }
-
/**
* Creates the child areas for the given layout manager.
* @param bslm the BlockStackingLayoutManager instance for which "addAreas" is performed.
@@ -54,19 +39,23 @@ public final class AreaAdditionUtil {
*/
public static void addAreas(BlockStackingLayoutManager bslm,
PositionIterator parentIter, LayoutContext layoutContext) {
- LayoutManager childLM = null;
+ LayoutManager childLM;
LayoutContext lc = new LayoutContext(0);
LayoutManager firstLM = null;
LayoutManager lastLM = null;
Position firstPos = null;
Position lastPos = null;
+ if (bslm != null) {
+ bslm.addId();
+ }
+
// "unwrap" the NonLeafPositions stored in parentIter
// and put them in a new list;
- LinkedList positionList = new LinkedList();
+ LinkedList<Position> positionList = new LinkedList<Position>();
Position pos;
while (parentIter.hasNext()) {
- pos = (Position)parentIter.next();
+ pos = parentIter.next();
if (pos == null) {
continue;
}
@@ -78,8 +67,8 @@ public final class AreaAdditionUtil {
}
if (pos instanceof NonLeafPosition) {
// pos was created by a child of this FlowLM
- positionList.add(((NonLeafPosition) pos).getPosition());
- lastLM = ((NonLeafPosition) pos).getPosition().getLM();
+ positionList.add(pos.getPosition());
+ lastLM = (pos.getPosition().getLM());
if (firstLM == null) {
firstLM = lastLM;
}
@@ -104,7 +93,7 @@ public final class AreaAdditionUtil {
bslm.isLast(lastPos));
}
- StackingIter childPosIter = new StackingIter(positionList.listIterator());
+ PositionIterator childPosIter = new PositionIterator(positionList.listIterator());
while ((childLM = childPosIter.getNextChildLM()) != null) {
// TODO vh: the test above might be problematic in some cases. See comment in
@@ -129,6 +118,7 @@ public final class AreaAdditionUtil {
false,
bslm.isFirst(firstPos),
bslm.isLast(lastPos));
+ bslm.checkEndOfLayout(lastPos);
}
Modified: xmlgraphics/fop/branches/Temp_Color/src/java/org/apache/fop/layoutmgr/BlockContainerLayoutManager.java
URL: http://svn.apache.org/viewvc/xmlgraphics/fop/branches/Temp_Color/src/java/org/apache/fop/layoutmgr/BlockContainerLayoutManager.java?rev=1069397&r1=1069396&r2=1069397&view=diff
==============================================================================
--- xmlgraphics/fop/branches/Temp_Color/src/java/org/apache/fop/layoutmgr/BlockContainerLayoutManager.java (original)
+++ xmlgraphics/fop/branches/Temp_Color/src/java/org/apache/fop/layoutmgr/BlockContainerLayoutManager.java Thu Feb 10 14:09:42 2011
@@ -23,7 +23,6 @@ import java.awt.Point;
import java.awt.geom.Rectangle2D;
import java.util.LinkedList;
import java.util.List;
-import java.util.ListIterator;
import java.util.Stack;
import org.apache.commons.logging.Log;
@@ -41,7 +40,6 @@ import org.apache.fop.fo.properties.Comm
import org.apache.fop.fo.properties.KeepProperty;
import org.apache.fop.traits.MinOptMax;
import org.apache.fop.traits.SpaceVal;
-import org.apache.fop.util.ListUtil;
/**
* LayoutManager for a block-container FO.
@@ -88,6 +86,8 @@ public class BlockContainerLayoutManager
private MinOptMax effSpaceBefore;
private MinOptMax effSpaceAfter;
+ private double contentRectOffsetX = 0;
+ private double contentRectOffsetY = 0;
/**
* Create a new block container layout manager.
@@ -98,6 +98,7 @@ public class BlockContainerLayoutManager
}
/** {@inheritDoc} */
+ @Override
public void initialize() {
abProps = getBlockContainerFO().getCommonAbsolutePosition();
foBlockSpaceBefore = new SpaceVal(getBlockContainerFO().getCommonMarginBlock()
@@ -119,20 +120,11 @@ public class BlockContainerLayoutManager
.getOptimum(this).getLength();
}
- bpUnit = 0; //layoutProps.blockProgressionUnit;
- if (bpUnit == 0) {
- // use optimum space values
- adjustedSpaceBefore = getBlockContainerFO().getCommonMarginBlock()
- .spaceBefore.getSpace().getOptimum(this).getLength().getValue(this);
- adjustedSpaceAfter = getBlockContainerFO().getCommonMarginBlock()
- .spaceAfter.getSpace().getOptimum(this).getLength().getValue(this);
- } else {
- // use minimum space values
- adjustedSpaceBefore = getBlockContainerFO().getCommonMarginBlock()
- .spaceBefore.getSpace().getMinimum(this).getLength().getValue(this);
- adjustedSpaceAfter = getBlockContainerFO().getCommonMarginBlock()
- .spaceAfter.getSpace().getMinimum(this).getLength().getValue(this);
- }
+ // use optimum space values
+ adjustedSpaceBefore = getBlockContainerFO().getCommonMarginBlock()
+ .spaceBefore.getSpace().getOptimum(this).getLength().getValue(this);
+ adjustedSpaceAfter = getBlockContainerFO().getCommonMarginBlock()
+ .spaceAfter.getSpace().getOptimum(this).getLength().getValue(this);
}
private void resetSpaces() {
@@ -169,8 +161,8 @@ public class BlockContainerLayoutManager
}
private boolean isAbsoluteOrFixed() {
- return (abProps.absolutePosition == EN_ABSOLUTE)
- || (abProps.absolutePosition == EN_FIXED);
+ return (abProps.absolutePosition == EN_ABSOLUTE
+ || abProps.absolutePosition == EN_FIXED);
}
private boolean isFixed() {
@@ -178,6 +170,7 @@ public class BlockContainerLayoutManager
}
/** {@inheritDoc} */
+ @Override
public int getContentAreaBPD() {
if (autoHeight) {
return -1;
@@ -187,126 +180,104 @@ public class BlockContainerLayoutManager
}
/** {@inheritDoc} */
- public List getNextKnuthElements // CSOK: MethodLength
- (LayoutContext context, int alignment) {
- resetSpaces();
- if (isAbsoluteOrFixed()) {
- return getNextKnuthElementsAbsolute(context, alignment);
- }
-
- autoHeight = false;
- //boolean rotated = (getBlockContainerFO().getReferenceOrientation() % 180 != 0);
- int maxbpd = context.getStackLimitBP().getOpt();
- int allocBPD;
- if (height.getEnum() == EN_AUTO
- || (!height.isAbsolute() && getAncestorBlockAreaBPD() <= 0)) {
- //auto height when height="auto" or "if that dimension is not specified explicitly
- //(i.e., it depends on content's block-progression-dimension)" (XSL 1.0, 7.14.1)
- allocBPD = maxbpd;
- autoHeight = true;
- if (getBlockContainerFO().getReferenceOrientation() == 0) {
- //Cannot easily inline element list when ref-or="180"
- inlineElementList = true;
- }
- } else {
- allocBPD = height.getValue(this); //this is the content-height
- allocBPD += getBPIndents();
- }
- vpContentBPD = allocBPD - getBPIndents();
-
- referenceIPD = context.getRefIPD();
- if (width.getEnum() == EN_AUTO) {
- updateContentAreaIPDwithOverconstrainedAdjust();
- } else {
- int contentWidth = width.getValue(this);
- updateContentAreaIPDwithOverconstrainedAdjust(contentWidth);
- }
+ @Override
+ public List getNextKnuthElements(LayoutContext context, int alignment) {
+ return getNextKnuthElements(context, alignment, null, null, null);
+ }
- double contentRectOffsetX = 0;
- contentRectOffsetX += getBlockContainerFO()
- .getCommonMarginBlock().startIndent.getValue(this);
- double contentRectOffsetY = 0;
- contentRectOffsetY += getBlockContainerFO()
- .getCommonBorderPaddingBackground().getBorderBeforeWidth(false);
- contentRectOffsetY += getBlockContainerFO()
- .getCommonBorderPaddingBackground().getPaddingBefore(false, this);
+ /**
+ * Overridden to handle writing-mode, and different stack limit
+ * setup.
+ * {@inheritDoc}
+ */
+ @Override
+ protected LayoutContext makeChildLayoutContext(LayoutContext context) {
+ LayoutContext childLC = new LayoutContext(0);
+ childLC.setStackLimitBP(
+ context.getStackLimitBP().minus(MinOptMax.getInstance(relDims.bpd)));
+ childLC.setRefIPD(relDims.ipd);
+ childLC.setWritingMode(getBlockContainerFO().getWritingMode());
+ return childLC;
+ }
- updateRelDims(contentRectOffsetX, contentRectOffsetY, autoHeight);
+ /** {@inheritDoc} */
+ @Override
+ public List getNextKnuthElements(LayoutContext context, int alignment, Stack lmStack,
+ Position restartPosition, LayoutManager restartAtLM) {
- int availableIPD = referenceIPD - getIPIndents();
- if (getContentAreaIPD() > availableIPD) {
- BlockLevelEventProducer eventProducer = BlockLevelEventProducer.Provider.get(
- getBlockContainerFO().getUserAgent().getEventBroadcaster());
- eventProducer.objectTooWide(this, getBlockContainerFO().getName(),
- getContentAreaIPD(), context.getRefIPD(),
- getBlockContainerFO().getLocator());
+ resetSpaces();
+ // special treatment for position="absolute|fixed"
+ if (isAbsoluteOrFixed()) {
+ return getNextKnuthElementsAbsolute(context);
}
- MinOptMax stackLimit = MinOptMax.getInstance(relDims.bpd);
+ boolean isRestart = (lmStack != null);
+ boolean emptyStack = (!isRestart || lmStack.isEmpty());
- List returnedList;
- List contentList = new LinkedList();
- List returnList = new LinkedList();
-
- if (!breakBeforeServed) {
- breakBeforeServed = true;
- if (!context.suppressBreakBefore()) {
- if (addKnuthElementsForBreakBefore(returnList, context)) {
- return returnList;
- }
- }
- }
+ setupAreaDimensions(context);
- if (!firstVisibleMarkServed) {
- addKnuthElementsForSpaceBefore(returnList, alignment);
- context.updateKeepWithPreviousPending(getKeepWithPrevious());
+ List<ListElement> returnedList;
+ List<ListElement> contentList = new LinkedList<ListElement>();
+ List<ListElement> returnList = new LinkedList<ListElement>();
+
+ if (!breakBeforeServed(context, returnList)) {
+ return returnList;
}
- addKnuthElementsForBorderPaddingBefore(returnList, !firstVisibleMarkServed);
- firstVisibleMarkServed = true;
+ addFirstVisibleMarks(returnList, context, alignment);
if (autoHeight && inlineElementList) {
- //Spaces, border and padding to be repeated at each break
- addPendingMarks(context);
LayoutManager curLM; // currently active LM
LayoutManager prevLM = null; // previously active LM
- while ((curLM = getChildLM()) != null) {
- LayoutContext childLC = new LayoutContext(0);
- childLC.copyPendingMarksFrom(context);
- // curLM is a ?
- childLC.setStackLimitBP(context.getStackLimitBP().minus(stackLimit));
- childLC.setRefIPD(relDims.ipd);
- childLC.setWritingMode(getBlockContainerFO().getWritingMode());
- if (curLM == this.childLMs.get(0)) {
- childLC.setFlags(LayoutContext.SUPPRESS_BREAK_BEFORE);
- //Handled already by the parent (break collapsing, see above)
+
+ LayoutContext childLC;
+ boolean doReset = isRestart;
+ if (isRestart) {
+ if (emptyStack) {
+ assert restartAtLM != null && restartAtLM.getParent() == this;
+ curLM = restartAtLM;
+ } else {
+ curLM = (LayoutManager) lmStack.pop();
+ // make sure the initial LM is not reset
+ doReset = false;
}
+ setCurrentChildLM(curLM);
+ } else {
+ curLM = getChildLM();
+ }
+
+ while (curLM != null) {
+ if (doReset) {
+ curLM.reset();
+ }
+
+ childLC = makeChildLayoutContext(context);
// get elements from curLM
- returnedList = curLM.getNextKnuthElements(childLC, alignment);
+ if (!isRestart || emptyStack) {
+ returnedList = getNextChildElements(curLM, context, childLC, alignment,
+ null, null, null);
+ } else {
+ returnedList = getNextChildElements(curLM, context, childLC, alignment,
+ lmStack, restartPosition, restartAtLM);
+ // once encountered, irrelevant for following child LMs
+ emptyStack = true;
+ // force reset as of the next child
+ doReset = true;
+ }
if (contentList.isEmpty() && childLC.isKeepWithPreviousPending()) {
//Propagate keep-with-previous up from the first child
context.updateKeepWithPreviousPending(childLC.getKeepWithPreviousPending());
childLC.clearKeepWithPreviousPending();
}
if (returnedList.size() == 1
- && ((ListElement)returnedList.get(0)).isForcedBreak()) {
+ && ElementListUtils.startsWithForcedBreak(returnedList)) {
// a descendant of this block has break-before
- /*
- if (returnList.size() == 0) {
- // the first child (or its first child ...) has
- // break-before;
- // all this block, including space before, will be put in
- // the
- // following page
- bSpaceBeforeServed = false;
- }*/
contentList.addAll(returnedList);
// "wrap" the Position inside each element
// moving the elements from contentList to returnList
- returnedList = new LinkedList();
wrapPositionElements(contentList, returnList);
return returnList;
@@ -329,9 +300,7 @@ public class BlockContainerLayoutManager
setFinished(true);
}
- returnedList = new LinkedList();
wrapPositionElements(contentList, returnList);
-
return returnList;
}
}
@@ -339,20 +308,15 @@ public class BlockContainerLayoutManager
context.updateKeepWithNextPending(childLC.getKeepWithNextPending());
childLC.clearKeepsPending();
prevLM = curLM;
+ curLM = getChildLM();
}
-
- returnedList = new LinkedList();
wrapPositionElements(contentList, returnList);
-
} else {
- returnList.add(refactoredBecauseOfDuplicateCode(contentRectOffsetX,
- contentRectOffsetY));
+ returnList.add(generateNonInlinedBox());
}
- addKnuthElementsForBorderPaddingAfter(returnList, true);
- addKnuthElementsForSpaceAfter(returnList, alignment);
- //All child content is processed. Only break-after can occur now, so...
- context.clearPendingMarks();
+ addLastVisibleMarks(returnList, context, alignment);
+
addKnuthElementsForBreakAfter(returnList, context);
context.updateKeepWithNextPending(getKeepWithNext());
@@ -361,72 +325,19 @@ public class BlockContainerLayoutManager
return returnList;
}
- private KnuthBox refactoredBecauseOfDuplicateCode(double contentRectOffsetX,
- double contentRectOffsetY) {
-
- MinOptMax range = MinOptMax.getInstance(relDims.ipd);
- BlockContainerBreaker breaker = new BlockContainerBreaker(this, range);
- breaker.doLayout(relDims.bpd, autoHeight);
- boolean contentOverflows = breaker.isOverflow();
- if (autoHeight) {
- //Update content BPD now that it is known
- int newHeight = breaker.deferredAlg.totalWidth;
- if (blockProgressionDirectionChanges()) {
- setContentAreaIPD(newHeight);
- } else {
- vpContentBPD = newHeight;
- }
- updateRelDims(contentRectOffsetX, contentRectOffsetY, false);
- }
-
- Position bcPosition = new BlockContainerPosition(this, breaker);
- KnuthBox knuthBox = new KnuthBox(vpContentBPD, notifyPos(bcPosition), false);
- //TODO Handle min/opt/max for block-progression-dimension
- /* These two elements will be used to add stretchability to the above box
- returnList.add(new KnuthPenalty(0, KnuthElement.INFINITE,
- false, returnPosition, false));
- returnList.add(new KnuthGlue(0, 1 * constantLineHeight, 0,
- LINE_NUMBER_ADJUSTMENT, returnPosition, false));
- */
-
- if (contentOverflows) {
- BlockLevelEventProducer eventProducer = BlockLevelEventProducer.Provider.get(
- getBlockContainerFO().getUserAgent().getEventBroadcaster());
- boolean canRecover = (getBlockContainerFO().getOverflow() != EN_ERROR_IF_OVERFLOW);
- eventProducer.viewportOverflow(this, getBlockContainerFO().getName(),
- breaker.getOverflowAmount(), needClip(), canRecover,
- getBlockContainerFO().getLocator());
- }
- return knuthBox;
- }
-
- private boolean blockProgressionDirectionChanges() {
- return getBlockContainerFO().getReferenceOrientation() % 180 != 0;
- }
-
- /** {@inheritDoc} */
- public List getNextKnuthElements // CSOK: MethodLength
- (LayoutContext context, int alignment, Stack lmStack,
- Position restartPosition, LayoutManager restartAtLM) {
- resetSpaces();
- if (isAbsoluteOrFixed()) {
- return getNextKnuthElementsAbsolute(context, alignment);
- }
-
+ private void setupAreaDimensions(LayoutContext context) {
autoHeight = false;
- //boolean rotated = (getBlockContainerFO().getReferenceOrientation() % 180 != 0);
int maxbpd = context.getStackLimitBP().getOpt();
int allocBPD;
+ BlockContainer fo = getBlockContainerFO();
if (height.getEnum() == EN_AUTO
|| (!height.isAbsolute() && getAncestorBlockAreaBPD() <= 0)) {
//auto height when height="auto" or "if that dimension is not specified explicitly
//(i.e., it depends on content's block-progression-dimension)" (XSL 1.0, 7.14.1)
allocBPD = maxbpd;
autoHeight = true;
- if (getBlockContainerFO().getReferenceOrientation() == 0) {
- //Cannot easily inline element list when ref-or="180"
- inlineElementList = true;
- }
+ //Cannot easily inline element list when ref-or<>"0"
+ inlineElementList = (fo.getReferenceOrientation() == 0);
} else {
allocBPD = height.getValue(this); //this is the content-height
allocBPD += getBPIndents();
@@ -441,243 +352,71 @@ public class BlockContainerLayoutManager
updateContentAreaIPDwithOverconstrainedAdjust(contentWidth);
}
- double contentRectOffsetX = 0;
- contentRectOffsetX += getBlockContainerFO()
- .getCommonMarginBlock().startIndent.getValue(this);
- double contentRectOffsetY = 0;
- contentRectOffsetY += getBlockContainerFO()
- .getCommonBorderPaddingBackground().getBorderBeforeWidth(false);
- contentRectOffsetY += getBlockContainerFO()
- .getCommonBorderPaddingBackground().getPaddingBefore(false, this);
+ contentRectOffsetX += fo.getCommonMarginBlock().startIndent.getValue(this);
+ contentRectOffsetY += fo.getCommonBorderPaddingBackground().getBorderBeforeWidth(false);
+ contentRectOffsetY += fo.getCommonBorderPaddingBackground().getPaddingBefore(false, this);
- updateRelDims(contentRectOffsetX, contentRectOffsetY, autoHeight);
+ updateRelDims();
int availableIPD = referenceIPD - getIPIndents();
if (getContentAreaIPD() > availableIPD) {
BlockLevelEventProducer eventProducer = BlockLevelEventProducer.Provider.get(
- getBlockContainerFO().getUserAgent().getEventBroadcaster());
- eventProducer.objectTooWide(this, getBlockContainerFO().getName(),
+ fo.getUserAgent().getEventBroadcaster());
+ eventProducer.objectTooWide(this, fo.getName(),
getContentAreaIPD(), context.getRefIPD(),
- getBlockContainerFO().getLocator());
- }
-
- MinOptMax stackLimit = MinOptMax.getInstance(relDims.bpd);
-
- List returnedList;
- List contentList = new LinkedList();
- List returnList = new LinkedList();
-
- if (!breakBeforeServed) {
- breakBeforeServed = true;
- if (!context.suppressBreakBefore()) {
- if (addKnuthElementsForBreakBefore(returnList, context)) {
- return returnList;
- }
- }
+ fo.getLocator());
}
+ }
- if (!firstVisibleMarkServed) {
- addKnuthElementsForSpaceBefore(returnList, alignment);
- context.updateKeepWithPreviousPending(getKeepWithPrevious());
- }
-
- addKnuthElementsForBorderPaddingBefore(returnList, !firstVisibleMarkServed);
- firstVisibleMarkServed = true;
-
- if (autoHeight && inlineElementList) {
- //Spaces, border and padding to be repeated at each break
- addPendingMarks(context);
-
- BlockLevelLayoutManager curLM; // currently active LM
- BlockLevelLayoutManager prevLM = null; // previously active LM
-
- LayoutContext childLC = new LayoutContext(0);
- if (lmStack.isEmpty()) {
- assert restartAtLM != null && restartAtLM.getParent() == this;
- curLM = (BlockLevelLayoutManager) restartAtLM;
- curLM.reset();
- setCurrentChildLM(curLM);
-
- childLC.copyPendingMarksFrom(context);
- childLC.setStackLimitBP(context.getStackLimitBP().minus(stackLimit));
- childLC.setRefIPD(relDims.ipd);
- childLC.setWritingMode(getBlockContainerFO().getWritingMode());
- if (curLM == this.childLMs.get(0)) {
- childLC.setFlags(LayoutContext.SUPPRESS_BREAK_BEFORE);
- //Handled already by the parent (break collapsing, see above)
- }
-
- // get elements from curLM
- returnedList = curLM.getNextKnuthElements(childLC, alignment);
- } else {
- curLM = (BlockLevelLayoutManager) lmStack.pop();
- setCurrentChildLM(curLM);
-
- childLC.copyPendingMarksFrom(context);
- childLC.setStackLimitBP(context.getStackLimitBP().minus(stackLimit));
- childLC.setRefIPD(relDims.ipd);
- childLC.setWritingMode(getBlockContainerFO().getWritingMode());
- if (curLM == this.childLMs.get(0)) {
- childLC.setFlags(LayoutContext.SUPPRESS_BREAK_BEFORE);
- //Handled already by the parent (break collapsing, see above)
- }
-
- // get elements from curLM
- returnedList = curLM.getNextKnuthElements(childLC, alignment, lmStack,
- restartPosition, restartAtLM);
- }
- if (contentList.isEmpty() && childLC.isKeepWithPreviousPending()) {
- //Propagate keep-with-previous up from the first child
- context.updateKeepWithPreviousPending(childLC.getKeepWithPreviousPending());
- childLC.clearKeepWithPreviousPending();
- }
- if (returnedList.size() == 1
- && ((ListElement)returnedList.get(0)).isForcedBreak()) {
- // a descendant of this block has break-before
- /*
- if (returnList.size() == 0) {
- // the first child (or its first child ...) has
- // break-before;
- // all this block, including space before, will be put in
- // the
- // following page
- bSpaceBeforeServed = false;
- }*/
- contentList.addAll(returnedList);
-
- // "wrap" the Position inside each element
- // moving the elements from contentList to returnList
- returnedList = new LinkedList();
- wrapPositionElements(contentList, returnList);
+ private KnuthBox generateNonInlinedBox() {
- return returnList;
+ MinOptMax range = MinOptMax.getInstance(relDims.ipd);
+ BlockContainerBreaker breaker = new BlockContainerBreaker(this, range);
+ breaker.doLayout(relDims.bpd, autoHeight);
+ boolean contentOverflows = breaker.isOverflow();
+ if (autoHeight) {
+ //Update content BPD now that it is known
+ int newHeight = breaker.deferredAlg.totalWidth;
+ if (blockProgressionDirectionChanges()) {
+ setContentAreaIPD(newHeight);
} else {
- if (prevLM != null) {
- // there is a block handled by prevLM
- // before the one handled by curLM
- addInBetweenBreak(contentList, context, childLC);
- }
- contentList.addAll(returnedList);
- if (!returnedList.isEmpty()) {
- if (((ListElement) ListUtil.getLast(returnedList))
- .isForcedBreak()) {
- // a descendant of this block has break-after
- if (curLM.isFinished()) {
- // there is no other content in this block;
- // it's useless to add space after before a page break
- setFinished(true);
- }
-
- returnedList = new LinkedList();
- wrapPositionElements(contentList, returnList);
-
- return returnList;
- }
- }
- }
- // propagate and clear
- context.updateKeepWithNextPending(childLC.getKeepWithNextPending());
- childLC.clearKeepsPending();
- prevLM = curLM;
-
- while ((curLM = (BlockLevelLayoutManager) getChildLM()) != null) {
- curLM.reset();
- childLC = new LayoutContext(0);
- childLC.copyPendingMarksFrom(context);
- // curLM is a ?
- childLC.setStackLimitBP(context.getStackLimitBP().minus(stackLimit));
- childLC.setRefIPD(relDims.ipd);
- childLC.setWritingMode(getBlockContainerFO().getWritingMode());
- if (curLM == this.childLMs.get(0)) {
- childLC.setFlags(LayoutContext.SUPPRESS_BREAK_BEFORE);
- //Handled already by the parent (break collapsing, see above)
- }
-
- // get elements from curLM
- returnedList = curLM.getNextKnuthElements(childLC, alignment);
- if (contentList.isEmpty() && childLC.isKeepWithPreviousPending()) {
- //Propagate keep-with-previous up from the first child
- context.updateKeepWithPreviousPending(childLC.getKeepWithPreviousPending());
- childLC.clearKeepWithPreviousPending();
- }
- if (returnedList.size() == 1
- && ((ListElement)returnedList.get(0)).isForcedBreak()) {
- // a descendant of this block has break-before
- /*
- if (returnList.size() == 0) {
- // the first child (or its first child ...) has
- // break-before;
- // all this block, including space before, will be put in
- // the
- // following page
- bSpaceBeforeServed = false;
- }*/
- contentList.addAll(returnedList);
-
- // "wrap" the Position inside each element
- // moving the elements from contentList to returnList
- returnedList = new LinkedList();
- wrapPositionElements(contentList, returnList);
-
- return returnList;
- } else {
- if (prevLM != null) {
- // there is a block handled by prevLM
- // before the one handled by curLM
- addInBetweenBreak(contentList, context, childLC);
- }
- contentList.addAll(returnedList);
- if (returnedList.isEmpty()) {
- //Avoid NoSuchElementException below (happens with empty blocks)
- continue;
- }
- if (((ListElement) ListUtil.getLast(returnedList))
- .isForcedBreak()) {
- // a descendant of this block has break-after
- if (curLM.isFinished()) {
- // there is no other content in this block;
- // it's useless to add space after before a page break
- setFinished(true);
- }
-
- returnedList = new LinkedList();
- wrapPositionElements(contentList, returnList);
-
- return returnList;
- }
- }
- // propagate and clear
- context.updateKeepWithNextPending(childLC.getKeepWithNextPending());
- childLC.clearKeepsPending();
- prevLM = curLM;
+ vpContentBPD = newHeight;
}
-
- returnedList = new LinkedList();
- wrapPositionElements(contentList, returnList);
-
- } else {
- returnList.add(refactoredBecauseOfDuplicateCode(contentRectOffsetX,
- contentRectOffsetY));
+ updateRelDims();
}
- addKnuthElementsForBorderPaddingAfter(returnList, true);
- addKnuthElementsForSpaceAfter(returnList, alignment);
- //All child content is processed. Only break-after can occur now, so...
- context.clearPendingMarks();
- addKnuthElementsForBreakAfter(returnList, context);
+ Position bcPosition = new BlockContainerPosition(this, breaker);
+ KnuthBox knuthBox = new KnuthBox(vpContentBPD, notifyPos(bcPosition), false);
+ //TODO Handle min/opt/max for block-progression-dimension
+ /* These two elements will be used to add stretchability to the above box
+ returnList.add(new KnuthPenalty(0, KnuthElement.INFINITE,
+ false, returnPosition, false));
+ returnList.add(new KnuthGlue(0, 1 * constantLineHeight, 0,
+ LINE_NUMBER_ADJUSTMENT, returnPosition, false));
+ */
- context.updateKeepWithNextPending(getKeepWithNext());
+ if (contentOverflows) {
+ BlockLevelEventProducer eventProducer = BlockLevelEventProducer.Provider.get(
+ getBlockContainerFO().getUserAgent().getEventBroadcaster());
+ boolean canRecover = (getBlockContainerFO().getOverflow() != EN_ERROR_IF_OVERFLOW);
+ eventProducer.viewportOverflow(this, getBlockContainerFO().getName(),
+ breaker.getOverflowAmount(), needClip(), canRecover,
+ getBlockContainerFO().getLocator());
+ }
+ return knuthBox;
+ }
- setFinished(true);
- return returnList;
+ private boolean blockProgressionDirectionChanges() {
+ return getBlockContainerFO().getReferenceOrientation() % 180 != 0;
}
/** {@inheritDoc} */
+ @Override
public boolean isRestartable() {
return true;
}
- private List getNextKnuthElementsAbsolute(LayoutContext context, int alignment) {
+ private List<ListElement> getNextKnuthElementsAbsolute(LayoutContext context) {
autoHeight = false;
boolean bpDirectionChanges = blockProgressionDirectionChanges();
@@ -783,7 +522,9 @@ public class BlockContainerLayoutManager
vpContentBPD = allocBPD - getBPIndents();
setContentAreaIPD(allocIPD - getIPIndents());
- updateRelDims(0, 0, autoHeight);
+ contentRectOffsetX = 0;
+ contentRectOffsetY = 0;
+ updateRelDims();
MinOptMax range = MinOptMax.getInstance(relDims.ipd);
BlockContainerBreaker breaker = new BlockContainerBreaker(this, range);
@@ -797,9 +538,9 @@ public class BlockContainerLayoutManager
} else {
vpContentBPD = newHeight;
}
- updateRelDims(0, 0, false);
+ updateRelDims();
}
- List returnList = new LinkedList();
+ List<ListElement> returnList = new LinkedList<ListElement>();
if (!breaker.isEmpty()) {
Position bcPosition = new BlockContainerPosition(this, breaker);
returnList.add(new KnuthBox(0, notifyPos(bcPosition), false));
@@ -819,9 +560,9 @@ public class BlockContainerLayoutManager
return returnList;
}
- private void updateRelDims(double xOffset, double yOffset, boolean skipAutoHeight) {
+ private void updateRelDims() {
Rectangle2D rect = new Rectangle2D.Double(
- xOffset, yOffset,
+ contentRectOffsetX, contentRectOffsetY,
getContentAreaIPD(),
this.vpContentBPD);
relDims = new FODimension(0, 0);
@@ -879,7 +620,7 @@ public class BlockContainerLayoutManager
}
public int getDifferenceOfFirstPart() {
- PageBreakPosition pbp = (PageBreakPosition)this.deferredAlg.getPageBreaks().getFirst();
+ PageBreakPosition pbp = this.deferredAlg.getPageBreaks().getFirst();
return pbp.difference;
}
@@ -908,13 +649,10 @@ public class BlockContainerLayoutManager
protected List getNextKnuthElements(LayoutContext context, int alignment) {
LayoutManager curLM; // currently active LM
- List returnList = new LinkedList();
+ List<ListElement> returnList = new LinkedList<ListElement>();
while ((curLM = getChildLM()) != null) {
- LayoutContext childLC = new LayoutContext(0);
- childLC.setStackLimitBP(context.getStackLimitBP());
- childLC.setRefIPD(context.getRefIPD());
- childLC.setWritingMode(getBlockContainerFO().getWritingMode());
+ LayoutContext childLC = makeChildLayoutContext(context);
List returnedList = null;
if (!curLM.isFinished()) {
@@ -992,8 +730,8 @@ public class BlockContainerLayoutManager
}
/** {@inheritDoc} */
- public void addAreas // CSOK: MethodLength
- (PositionIterator parentIter, LayoutContext layoutContext) {
+ @Override
+ public void addAreas(PositionIterator parentIter, LayoutContext layoutContext) {
getParentArea(null);
// if this will create the first block area in a page
@@ -1015,14 +753,12 @@ public class BlockContainerLayoutManager
// "unwrap" the NonLeafPositions stored in parentIter
// and put them in a new list;
- List positionList = new LinkedList();
+ List<Position> positionList = new LinkedList<Position>();
Position pos;
- boolean bSpaceBefore = false;
- boolean bSpaceAfter = false;
Position firstPos = null;
Position lastPos = null;
while (parentIter.hasNext()) {
- pos = (Position) parentIter.next();
+ pos = parentIter.next();
if (pos.getIndex() >= 0) {
if (firstPos == null) {
firstPos = pos;
@@ -1041,20 +777,7 @@ public class BlockContainerLayoutManager
//Add child areas inside the reference area
//bcpos.getBreaker().addContainedAreas();
} else if (innerPosition == null) {
- if (pos instanceof NonLeafPosition) {
- // pos was created by this BCLM and was inside an element
- // representing space before or after
- // this means the space was not discarded
- if (positionList.isEmpty() && bcpos == null) {
- // pos was in the element representing space-before
- bSpaceBefore = true;
- } else {
- // pos was in the element representing space-after
- bSpaceAfter = true;
- }
- } else {
- //ignore (probably a Position for a simple penalty between blocks)
- }
+ //ignore (probably a Position for a simple penalty between blocks)
} else if (innerPosition.getLM() == this
&& !(innerPosition instanceof MappingPosition)) {
// pos was created by this BlockLM and was inside a penalty
@@ -1072,86 +795,15 @@ public class BlockContainerLayoutManager
addMarkersToPage(true, isFirst(firstPos), isLast(lastPos));
if (bcpos == null) {
- if (bpUnit == 0) {
- // the Positions in positionList were inside the elements
- // created by the LineLM
- childPosIter = new StackingIter(positionList.listIterator());
- } else {
- // the Positions in positionList were inside the elements
- // created by the BCLM in the createUnitElements() method
- //if (((Position) positionList.getLast()) instanceof
- // LeafPosition) {
- // // the last item inside positionList is a LeafPosition
- // // (a LineBreakPosition, more precisely); this means that
- // // the whole paragraph is on the same page
- // childPosIter = new KnuthPossPosIter(storedList, 0,
- // storedList.size());
- //} else {
- // // the last item inside positionList is a Position;
- // // this means that the paragraph has been split
- // // between consecutive pages
- List splitList = new LinkedList();
- int splitLength = 0;
- int iFirst = ((MappingPosition) positionList.get(0))
- .getFirstIndex();
- int iLast = ((MappingPosition) ListUtil.getLast(positionList))
- .getLastIndex();
- // copy from storedList to splitList all the elements from
- // iFirst to iLast
- ListIterator storedListIterator = storedList.listIterator(iFirst);
- while (storedListIterator.nextIndex() <= iLast) {
- KnuthElement element = (KnuthElement) storedListIterator
- .next();
- // some elements in storedList (i.e. penalty items) were created
- // by this BlockLM, and must be ignored
- if (element.getLayoutManager() != this) {
- splitList.add(element);
- splitLength += element.getWidth();
- lastLM = element.getLayoutManager();
- }
- }
- //log.debug("Adding areas from " + iFirst + " to " + iLast);
- //log.debug("splitLength= " + splitLength
- // + " (" + neededUnits(splitLength) + " units') "
- // + (neededUnits(splitLength) * bpUnit - splitLength)
- // + " spacing");
- // add space before and / or after the paragraph
- // to reach a multiple of bpUnit
- if (bSpaceBefore && bSpaceAfter) {
- foBlockSpaceBefore = new SpaceVal(getBlockContainerFO()
- .getCommonMarginBlock().spaceBefore, this).getSpace();
- foBlockSpaceAfter = new SpaceVal(getBlockContainerFO()
- .getCommonMarginBlock().spaceAfter, this).getSpace();
- adjustedSpaceBefore = (neededUnits(splitLength
- + foBlockSpaceBefore.getMin()
- + foBlockSpaceAfter.getMin())
- * bpUnit - splitLength) / 2;
- adjustedSpaceAfter = neededUnits(splitLength
- + foBlockSpaceBefore.getMin()
- + foBlockSpaceAfter.getMin())
- * bpUnit - splitLength - adjustedSpaceBefore;
- } else if (bSpaceBefore) {
- adjustedSpaceBefore = neededUnits(splitLength
- + foBlockSpaceBefore.getMin())
- * bpUnit - splitLength;
- } else {
- adjustedSpaceAfter = neededUnits(splitLength
- + foBlockSpaceAfter.getMin())
- * bpUnit - splitLength;
- }
- //log.debug("space before = " + adjustedSpaceBefore
- // + " space after = " + adjustedSpaceAfter + " total = " +
- // (adjustedSpaceBefore + adjustedSpaceAfter + splitLength));
- childPosIter = new KnuthPossPosIter(splitList, 0, splitList
- .size());
- //}
- }
+ // the Positions in positionList were inside the elements
+ // created by the LineLM
+ childPosIter = new PositionIterator(positionList.listIterator());
while ((childLM = childPosIter.getNextChildLM()) != null) {
// set last area flag
lc.setFlags(LayoutContext.LAST_AREA,
(layoutContext.isLastArea() && childLM == lastLM));
- /*LF*/lc.setStackLimitBP(layoutContext.getStackLimitBP());
+ lc.setStackLimitBP(layoutContext.getStackLimitBP());
// Add the line areas to Area
childLM.addAreas(childPosIter, lc);
}
@@ -1180,6 +832,7 @@ public class BlockContainerLayoutManager
*
* {@inheritDoc}
*/
+ @Override
public Area getParentArea(Area childArea) {
if (referenceArea == null) {
boolean switchedProgressionDirection = blockProgressionDirectionChanges();
@@ -1203,9 +856,6 @@ public class BlockContainerLayoutManager
TraitSetter.addPadding(viewportBlockArea,
getBlockContainerFO().getCommonBorderPaddingBackground(),
discardPaddingBefore, discardPaddingAfter, false, false, this);
- // TraitSetter.addBackground(viewportBlockArea,
- // getBlockContainerFO().getCommonBorderPaddingBackground(),
- // this);
TraitSetter.addMargins(viewportBlockArea,
getBlockContainerFO().getCommonBorderPaddingBackground(),
startIndent, endIndent,
@@ -1213,13 +863,6 @@ public class BlockContainerLayoutManager
viewportBlockArea.setCTM(absoluteCTM);
viewportBlockArea.setClip(needClip());
- /*
- if (getSpaceBefore() != 0) {
- viewportBlockArea.addTrait(Trait.SPACE_BEFORE, new Integer(getSpaceBefore()));
- }
- if (foBlockSpaceAfter.opt != 0) {
- viewportBlockArea.addTrait(Trait.SPACE_AFTER, new Integer(foBlockSpaceAfter.opt));
- }*/
if (abProps.absolutePosition == EN_ABSOLUTE
|| abProps.absolutePosition == EN_FIXED) {
@@ -1256,6 +899,7 @@ public class BlockContainerLayoutManager
*
* {@inheritDoc}
*/
+ @Override
public void addChildArea(Area childArea) {
if (referenceArea != null) {
referenceArea.addBlock((Block) childArea);
@@ -1266,6 +910,7 @@ public class BlockContainerLayoutManager
* Force current area to be added to parent area.
* {@inheritDoc}
*/
+ @Override
protected void flush() {
viewportBlockArea.addBlock(referenceArea, autoHeight);
@@ -1277,28 +922,32 @@ public class BlockContainerLayoutManager
}
/** {@inheritDoc} */
+ @Override
public int negotiateBPDAdjustment(int adj, KnuthElement lastElement) {
// TODO Auto-generated method stub
return 0;
}
/** {@inheritDoc} */
+ @Override
public void discardSpace(KnuthGlue spaceGlue) {
// TODO Auto-generated method stub
-
}
/** {@inheritDoc} */
+ @Override
public KeepProperty getKeepTogetherProperty() {
return getBlockContainerFO().getKeepTogether();
}
/** {@inheritDoc} */
+ @Override
public KeepProperty getKeepWithPreviousProperty() {
return getBlockContainerFO().getKeepWithPrevious();
}
/** {@inheritDoc} */
+ @Override
public KeepProperty getKeepWithNextProperty() {
return getBlockContainerFO().getKeepWithNext();
}
@@ -1313,11 +962,13 @@ public class BlockContainerLayoutManager
// --------- Property Resolution related functions --------- //
/** {@inheritDoc} */
+ @Override
public boolean getGeneratesReferenceArea() {
return true;
}
/** {@inheritDoc} */
+ @Override
public boolean getGeneratesBlockArea() {
return true;
}
Modified: xmlgraphics/fop/branches/Temp_Color/src/java/org/apache/fop/layoutmgr/BlockLayoutManager.java
URL: http://svn.apache.org/viewvc/xmlgraphics/fop/branches/Temp_Color/src/java/org/apache/fop/layoutmgr/BlockLayoutManager.java?rev=1069397&r1=1069396&r2=1069397&view=diff
==============================================================================
--- xmlgraphics/fop/branches/Temp_Color/src/java/org/apache/fop/layoutmgr/BlockLayoutManager.java (original)
+++ xmlgraphics/fop/branches/Temp_Color/src/java/org/apache/fop/layoutmgr/BlockLayoutManager.java Thu Feb 10 14:09:42 2011
@@ -46,15 +46,13 @@ import org.apache.fop.traits.SpaceVal;
public class BlockLayoutManager extends BlockStackingLayoutManager
implements ConditionalElementListener {
- /**
- * logging instance
- */
+ /** logging instance */
private static Log log = LogFactory.getLog(BlockLayoutManager.class);
private Block curBlockArea;
/** Iterator over the child layout managers. */
- protected ListIterator proxyLMiter;
+ protected ListIterator<LayoutManager> proxyLMiter;
private int lead = 12000;
private Length lineHeight;
@@ -78,52 +76,77 @@ public class BlockLayoutManager extends
}
/** {@inheritDoc} */
+ @Override
public void initialize() {
super.initialize();
- FontInfo fi = getBlockFO().getFOEventHandler().getFontInfo();
- FontTriplet[] fontkeys = getBlockFO().getCommonFont().getFontState(fi);
+ org.apache.fop.fo.flow.Block fo = getBlockFO();
+ FontInfo fi = fo.getFOEventHandler().getFontInfo();
+ FontTriplet[] fontkeys = fo.getCommonFont().getFontState(fi);
Font initFont = fi.getFontInstance(fontkeys[0],
getBlockFO().getCommonFont().fontSize.getValue(this));
lead = initFont.getAscender();
follow = -initFont.getDescender();
//middleShift = -fs.getXHeight() / 2;
- lineHeight = getBlockFO().getLineHeight().getOptimum(this).getLength();
- startIndent = getBlockFO().getCommonMarginBlock().startIndent.getValue(this);
- endIndent = getBlockFO().getCommonMarginBlock().endIndent.getValue(this);
- foSpaceBefore = new SpaceVal(getBlockFO().getCommonMarginBlock().spaceBefore, this)
- .getSpace();
- foSpaceAfter = new SpaceVal(getBlockFO().getCommonMarginBlock().spaceAfter, this)
- .getSpace();
- bpUnit = 0; // non-standard extension
- if (bpUnit == 0) {
- // use optimum space values
- adjustedSpaceBefore = getBlockFO().getCommonMarginBlock().spaceBefore.getSpace()
- .getOptimum(this).getLength().getValue(this);
- adjustedSpaceAfter = getBlockFO().getCommonMarginBlock().spaceAfter.getSpace()
- .getOptimum(this).getLength().getValue(this);
- } else {
- // use minimum space values
- adjustedSpaceBefore = getBlockFO().getCommonMarginBlock().spaceBefore.getSpace()
- .getMinimum(this).getLength().getValue(this);
- adjustedSpaceAfter = getBlockFO().getCommonMarginBlock().spaceAfter.getSpace()
- .getMinimum(this).getLength().getValue(this);
- }
+ lineHeight = fo.getLineHeight().getOptimum(this).getLength();
+ startIndent = fo.getCommonMarginBlock().startIndent.getValue(this);
+ endIndent = fo.getCommonMarginBlock().endIndent.getValue(this);
+ foSpaceBefore = new SpaceVal(fo.getCommonMarginBlock().spaceBefore, this).getSpace();
+ foSpaceAfter = new SpaceVal(fo.getCommonMarginBlock().spaceAfter, this).getSpace();
+ // use optimum space values
+ adjustedSpaceBefore = fo.getCommonMarginBlock().spaceBefore.getSpace()
+ .getOptimum(this).getLength().getValue(this);
+ adjustedSpaceAfter = fo.getCommonMarginBlock().spaceAfter.getSpace()
+ .getOptimum(this).getLength().getValue(this);
}
/** {@inheritDoc} */
+ @Override
public List getNextKnuthElements(LayoutContext context, int alignment) {
return getNextKnuthElements(context, alignment, null, null, null);
}
/** {@inheritDoc} */
+ @Override
public List getNextKnuthElements(LayoutContext context, int alignment, Stack lmStack,
Position restartPosition, LayoutManager restartAtLM) {
resetSpaces();
+ return super.getNextKnuthElements(
+ context, alignment, lmStack, restartPosition, restartAtLM);
+ }
+
+ /**
+ * Overridden to take into account that the childLM may be the block's
+ * {@link LineLayoutManager}.
+ * {@inheritDoc}
+ */
+ @Override
+ protected List<ListElement> getNextChildElements(LayoutManager childLM, LayoutContext context,
+ LayoutContext childLC, int alignment, Stack lmStack, Position restartPosition,
+ LayoutManager restartAtLM) {
+
+ childLC.copyPendingMarksFrom(context);
+
+ if (childLM instanceof LineLayoutManager) {
+ childLC.setRefIPD(getContentAreaIPD());
+ } else {
+ // nop; will have been properly set by makeChildLayoutContext()
+ }
+
+ if (childLM == this.childLMs.get(0)) {
+ childLC.setFlags(LayoutContext.SUPPRESS_BREAK_BEFORE);
+ //Handled already by the parent (break collapsing, see above)
+ }
+
if (lmStack == null) {
- return super.getNextKnuthElements(context, alignment);
+ return childLM.getNextKnuthElements(childLC, alignment);
} else {
- return super.getNextKnuthElements(context, alignment, lmStack, restartPosition,
- restartAtLM);
+ if (childLM instanceof LineLayoutManager) {
+ return ((LineLayoutManager) childLM).getNextKnuthElements(childLC, alignment,
+ (LeafPosition) restartPosition);
+ } else {
+ return childLM.getNextKnuthElements(childLC, alignment,
+ lmStack, restartPosition, restartAtLM);
+ }
}
}
@@ -151,7 +174,7 @@ public class BlockLayoutManager extends
*/
public ProxyLMiter() {
super(BlockLayoutManager.this);
- listLMs = new java.util.ArrayList(10);
+ listLMs = new java.util.ArrayList<LayoutManager>(10);
}
/**
@@ -166,7 +189,7 @@ public class BlockLayoutManager extends
* @return true if new child lms were added
*/
protected boolean createNextChildLMs(int pos) {
- List newLMs = createChildLMs(pos + 1 - listLMs.size());
+ List<LayoutManager> newLMs = createChildLMs(pos + 1 - listLMs.size());
if (newLMs != null) {
listLMs.addAll(newLMs);
}
@@ -174,13 +197,12 @@ public class BlockLayoutManager extends
}
}
- /**
- * {@inheritDoc}
- */
+ /** {@inheritDoc} */
+ @Override
public boolean createNextChildLMs(int pos) {
while (proxyLMiter.hasNext()) {
- LayoutManager lm = (LayoutManager) proxyLMiter.next();
+ LayoutManager lm = proxyLMiter.next();
if (lm instanceof InlineLevelLayoutManager) {
LineLayoutManager lineLM = createLineManager(lm);
addChildLM(lineLM);
@@ -203,10 +225,10 @@ public class BlockLayoutManager extends
private LineLayoutManager createLineManager(LayoutManager firstlm) {
LineLayoutManager llm;
llm = new LineLayoutManager(getBlockFO(), lineHeight, lead, follow);
- List inlines = new java.util.ArrayList();
+ List<LayoutManager> inlines = new java.util.ArrayList<LayoutManager>();
inlines.add(firstlm);
while (proxyLMiter.hasNext()) {
- LayoutManager lm = (LayoutManager) proxyLMiter.next();
+ LayoutManager lm = proxyLMiter.next();
if (lm instanceof InlineLevelLayoutManager) {
inlines.add(lm);
} else {
@@ -219,23 +241,26 @@ public class BlockLayoutManager extends
}
/** {@inheritDoc} */
+ @Override
public KeepProperty getKeepTogetherProperty() {
return getBlockFO().getKeepTogether();
}
/** {@inheritDoc} */
+ @Override
public KeepProperty getKeepWithPreviousProperty() {
return getBlockFO().getKeepWithPrevious();
}
/** {@inheritDoc} */
+ @Override
public KeepProperty getKeepWithNextProperty() {
return getBlockFO().getKeepWithNext();
}
/** {@inheritDoc} */
- public void addAreas // CSOK: MethodLength
- (PositionIterator parentIter, LayoutContext layoutContext) {
+ @Override
+ public void addAreas(PositionIterator parentIter, LayoutContext layoutContext) {
getParentArea(null);
// if this will create the first block area in a page
@@ -256,14 +281,12 @@ public class BlockLayoutManager extends
// "unwrap" the NonLeafPositions stored in parentIter
// and put them in a new list;
- LinkedList positionList = new LinkedList();
+ LinkedList<Position> positionList = new LinkedList<Position>();
Position pos;
- boolean spaceBefore = false;
- boolean spaceAfter = false;
Position firstPos = null;
Position lastPos = null;
while (parentIter.hasNext()) {
- pos = (Position) parentIter.next();
+ pos = parentIter.next();
//log.trace("pos = " + pos.getClass().getName() + "; " + pos);
if (pos.getIndex() >= 0) {
if (firstPos == null) {
@@ -276,30 +299,13 @@ public class BlockLayoutManager extends
//Not all elements are wrapped
innerPosition = pos.getPosition();
}
- if (innerPosition == null) {
- // pos was created by this BlockLM and was inside an element
- // representing space before or after
- // this means the space was not discarded
- if (positionList.size() == 0) {
- // pos was in the element representing space-before
- spaceBefore = true;
- //log.trace(" space before");
- } else {
- // pos was in the element representing space-after
- spaceAfter = true;
- //log.trace(" space-after");
- }
- } else if (innerPosition.getLM() == this
- && !(innerPosition instanceof MappingPosition)) {
- // pos was created by this BlockLM and was inside a penalty
- // allowing or forbidding a page break
- // nothing to do
- //log.trace(" penalty");
- } else {
+
+ if (innerPosition != null
+ && (innerPosition.getLM() != this
+ || innerPosition instanceof MappingPosition)) {
// innerPosition was created by another LM
positionList.add(innerPosition);
lastLM = innerPosition.getLM();
- //log.trace(" " + innerPosition.getClass().getName());
}
}
@@ -307,78 +313,9 @@ public class BlockLayoutManager extends
addMarkersToPage(true, isFirst(firstPos), isLast(lastPos));
- if (bpUnit == 0) {
- // the Positions in positionList were inside the elements
- // created by the LineLM
- childPosIter = new StackingIter(positionList.listIterator());
- } else {
- // the Positions in positionList were inside the elements
- // created by the BlockLM in the createUnitElements() method
- //if (((Position) positionList.getLast()) instanceof
- // LeafPosition) {
- // // the last item inside positionList is a LeafPosition
- // // (a LineBreakPosition, more precisely); this means that
- // // the whole paragraph is on the same page
- // childPosIter = new KnuthPossPosIter(storedList, 0,
- // storedList.size());
- //} else {
- // // the last item inside positionList is a Position;
- // // this means that the paragraph has been split
- // // between consecutive pages
- LinkedList splitList = new LinkedList();
- int splitLength = 0;
- int iFirst = ((MappingPosition) positionList.getFirst()).getFirstIndex();
- int iLast = ((MappingPosition) positionList.getLast()).getLastIndex();
- // copy from storedList to splitList all the elements from
- // iFirst to iLast
- ListIterator storedListIterator = storedList.listIterator(iFirst);
- while (storedListIterator.nextIndex() <= iLast) {
- KnuthElement element = (KnuthElement) storedListIterator
- .next();
- // some elements in storedList (i.e. penalty items) were created
- // by this BlockLM, and must be ignored
- if (element.getLayoutManager() != this) {
- splitList.add(element);
- splitLength += element.getWidth();
- lastLM = element.getLayoutManager();
- }
- }
- //log.debug("Adding areas from " + iFirst + " to " + iLast);
- //log.debug("splitLength= " + splitLength
- // + " (" + neededUnits(splitLength) + " units') "
- // + (neededUnits(splitLength) * bpUnit - splitLength)
- // + " spacing");
- // add space before and / or after the paragraph
- // to reach a multiple of bpUnit
- if (spaceBefore && spaceAfter) {
- foSpaceBefore = new SpaceVal(getBlockFO()
- .getCommonMarginBlock().spaceBefore, this).getSpace();
- foSpaceAfter = new SpaceVal(getBlockFO()
- .getCommonMarginBlock().spaceAfter, this).getSpace();
- adjustedSpaceBefore = (neededUnits(splitLength
- + foSpaceBefore.getMin()
- + foSpaceAfter.getMin())
- * bpUnit - splitLength) / 2;
- adjustedSpaceAfter = neededUnits(splitLength
- + foSpaceBefore.getMin()
- + foSpaceAfter.getMin())
- * bpUnit - splitLength - adjustedSpaceBefore;
- } else if (spaceBefore) {
- adjustedSpaceBefore = neededUnits(splitLength
- + foSpaceBefore.getMin())
- * bpUnit - splitLength;
- } else {
- adjustedSpaceAfter = neededUnits(splitLength
- + foSpaceAfter.getMin())
- * bpUnit - splitLength;
- }
- //log.debug("spazio prima = " + adjustedSpaceBefore
- // + " spazio dopo = " + adjustedSpaceAfter + " totale = " +
- // (adjustedSpaceBefore + adjustedSpaceAfter + splitLength));
- childPosIter = new KnuthPossPosIter(splitList, 0, splitList
- .size());
- //}
- }
+ // the Positions in positionList were inside the elements
+ // created by the LineLM
+ childPosIter = new PositionIterator(positionList.listIterator());
while ((childLM = childPosIter.getNextChildLM()) != null) {
// set last area flag
@@ -415,6 +352,7 @@ public class BlockLayoutManager extends
* @param childArea area to get the parent area for
* @return the parent area
*/
+ @Override
public Area getParentArea(Area childArea) {
if (curBlockArea == null) {
curBlockArea = new Block();
@@ -446,9 +384,8 @@ public class BlockLayoutManager extends
return curBlockArea;
}
- /**
- * {@inheritDoc}
- */
+ /** {@inheritDoc} */
+ @Override
public void addChildArea(Area childArea) {
if (curBlockArea != null) {
if (childArea instanceof LineArea) {
@@ -463,6 +400,7 @@ public class BlockLayoutManager extends
* Force current area to be added to parent area.
* {@inheritDoc}
*/
+ @Override
protected void flush() {
if (curBlockArea != null) {
TraitSetter.addBackground(curBlockArea,
@@ -486,6 +424,7 @@ public class BlockLayoutManager extends
* Returns the IPD of the content area
* @return the IPD of the content area
*/
+ @Override
public int getContentAreaIPD() {
if (curBlockArea != null) {
return curBlockArea.getIPD();
@@ -498,6 +437,7 @@ public class BlockLayoutManager extends
* Returns the BPD of the content area
* @return the BPD of the content area
*/
+ @Override
public int getContentAreaBPD() {
if (curBlockArea != null) {
return curBlockArea.getBPD();
@@ -505,9 +445,8 @@ public class BlockLayoutManager extends
return -1;
}
- /**
- * {@inheritDoc}
- */
+ /** {@inheritDoc} */
+ @Override
public boolean getGeneratesBlockArea() {
return true;
}
@@ -558,6 +497,7 @@ public class BlockLayoutManager extends
}
/** {@inheritDoc} */
+ @Override
public boolean isRestartable() {
return true;
}
---------------------------------------------------------------------
To unsubscribe, e-mail: fop-commits-unsubscribe@xmlgraphics.apache.org
For additional commands, e-mail: fop-commits-help@xmlgraphics.apache.org