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 vh...@apache.org on 2009/08/26 20:50:11 UTC
svn commit: r808157 [2/2] - in /xmlgraphics/fop/trunk:
src/java/org/apache/fop/layoutmgr/ src/java/org/apache/fop/layoutmgr/inline/
src/java/org/apache/fop/layoutmgr/list/ src/java/org/apache/fop/render/pdf/
test/layoutengine/standard-testcases/
Modified: xmlgraphics/fop/trunk/src/java/org/apache/fop/layoutmgr/PageBreakingAlgorithm.java
URL: http://svn.apache.org/viewvc/xmlgraphics/fop/trunk/src/java/org/apache/fop/layoutmgr/PageBreakingAlgorithm.java?rev=808157&r1=808156&r2=808157&view=diff
==============================================================================
--- xmlgraphics/fop/trunk/src/java/org/apache/fop/layoutmgr/PageBreakingAlgorithm.java (original)
+++ xmlgraphics/fop/trunk/src/java/org/apache/fop/layoutmgr/PageBreakingAlgorithm.java Wed Aug 26 18:50:10 2009
@@ -96,6 +96,9 @@
//Controls whether a single part should be forced if possible (ex. block-container)
private boolean favorSinglePart = false;
+ private boolean ipdChange;
+ private KnuthNode bestNodeForIPDChange;
+
//Used to keep track of switches in keep-context
private int currentKeepContext = Constants.EN_AUTO;
private KnuthNode lastBeforeKeepContextSwitch;
@@ -1073,4 +1076,63 @@
}
+ /** {@inheritDoc} */
+ protected boolean ipdChanged() {
+ return ipdChange;
+ }
+
+ /** {@inheritDoc} */
+ protected int handleIpdChange() {
+ log.trace("Best node for ipd change:" + bestNodeForIPDChange);
+ // TODO finish()
+ /*
+ * The third parameter is used to determine if this is the last page, so
+ * if the content must be vertically justified or not. If we are here
+ * this means that there is further content and the next page has a
+ * different ipd. So tweak the parameter to fall into the non-last-page
+ * case.
+ */
+ calculateBreakPoints(bestNodeForIPDChange, par, bestNodeForIPDChange.line + 1);
+ activeLines = null;
+ return bestNodeForIPDChange.line;
+ }
+
+ /**
+ * Add a node at the end of the given line's existing active nodes.
+ * If this is the first node in the line, adjust endLine accordingly.
+ * @param line number of the line ending at the node's corresponding breakpoint
+ * @param node the active node to add
+ */
+ protected void addNode(int line, KnuthNode node) {
+ if (node.position < par.size() - 1 && line > 0 && ipdChange(line - 1)) {
+ log.trace("IPD changes at page " + line);
+ ipdChange = true;
+ if (bestNodeForIPDChange == null
+ || node.totalDemerits < bestNodeForIPDChange.totalDemerits) {
+ bestNodeForIPDChange = node;
+ }
+ } else {
+ if (node.position == par.size() - 1) {
+ /*
+ * The whole sequence could actually fit on the last page before
+ * the IPD change. No need to do any special handling.
+ */
+ ipdChange = false;
+ }
+ super.addNode(line, node);
+ }
+ }
+
+ KnuthNode getBestNodeBeforeIPDChange() {
+ return bestNodeForIPDChange;
+ }
+
+ /** {@inheritDoc} */
+ protected boolean ipdChange(int line) {
+ if (pageProvider == null) {
+ return false;
+ }
+ return pageProvider.ipdChange(line);
+ }
+
}
Modified: xmlgraphics/fop/trunk/src/java/org/apache/fop/layoutmgr/PageProvider.java
URL: http://svn.apache.org/viewvc/xmlgraphics/fop/trunk/src/java/org/apache/fop/layoutmgr/PageProvider.java?rev=808157&r1=808156&r2=808157&view=diff
==============================================================================
--- xmlgraphics/fop/trunk/src/java/org/apache/fop/layoutmgr/PageProvider.java (original)
+++ xmlgraphics/fop/trunk/src/java/org/apache/fop/layoutmgr/PageProvider.java Wed Aug 26 18:50:10 2009
@@ -161,6 +161,33 @@
}
/**
+ * Returns true if the part following the given one has a different IPD.
+ *
+ * @param index index of the current part
+ * @return true if the following part has a different IPD, false otherwise
+ */
+ public boolean ipdChange(int index) {
+ int columnCount = 0;
+ int colIndex = startColumnOfCurrentElementList + index;
+ int pageIndex = -1;
+ Page page;
+ do {
+ colIndex -= columnCount;
+ pageIndex++;
+ page = getPage(false, pageIndex, RELTO_CURRENT_ELEMENT_LIST);
+ columnCount = page.getPageViewport().getCurrentSpan().getColumnCount();
+ } while (colIndex >= columnCount);
+ if (colIndex + 1 < columnCount) {
+ // Next part is a column on same page => same IPD
+ return false;
+ } else {
+ Page nextPage = getPage(false, pageIndex + 1, RELTO_CURRENT_ELEMENT_LIST);
+ return page.getPageViewport().getBodyRegion().getIPD()
+ != nextPage.getPageViewport().getBodyRegion().getIPD();
+ }
+ }
+
+ /**
* Checks if a break at the passed index would start a new page
* @param index the index of the element before the break
* @return {@code true} if the break starts a new page
Modified: xmlgraphics/fop/trunk/src/java/org/apache/fop/layoutmgr/Position.java
URL: http://svn.apache.org/viewvc/xmlgraphics/fop/trunk/src/java/org/apache/fop/layoutmgr/Position.java?rev=808157&r1=808156&r2=808157&view=diff
==============================================================================
--- xmlgraphics/fop/trunk/src/java/org/apache/fop/layoutmgr/Position.java (original)
+++ xmlgraphics/fop/trunk/src/java/org/apache/fop/layoutmgr/Position.java Wed Aug 26 18:50:10 2009
@@ -28,6 +28,11 @@
layoutManager = lm;
}
+ public Position(LayoutManager lm, int index) {
+ this(lm);
+ setIndex(index);
+ }
+
public LayoutManager getLM() {
return layoutManager;
}
Modified: xmlgraphics/fop/trunk/src/java/org/apache/fop/layoutmgr/SpaceResolver.java
URL: http://svn.apache.org/viewvc/xmlgraphics/fop/trunk/src/java/org/apache/fop/layoutmgr/SpaceResolver.java?rev=808157&r1=808156&r2=808157&view=diff
==============================================================================
--- xmlgraphics/fop/trunk/src/java/org/apache/fop/layoutmgr/SpaceResolver.java (original)
+++ xmlgraphics/fop/trunk/src/java/org/apache/fop/layoutmgr/SpaceResolver.java Wed Aug 26 18:50:10 2009
@@ -19,7 +19,6 @@
package org.apache.fop.layoutmgr;
-import java.util.LinkedList;
import java.util.List;
import java.util.ListIterator;
@@ -565,6 +564,11 @@
public Position getOriginalBreakPosition() {
return this.originalPosition;
}
+
+ public Position getPosition() {
+ return originalPosition;
+ }
+
}
/**
Modified: xmlgraphics/fop/trunk/src/java/org/apache/fop/layoutmgr/StaticContentLayoutManager.java
URL: http://svn.apache.org/viewvc/xmlgraphics/fop/trunk/src/java/org/apache/fop/layoutmgr/StaticContentLayoutManager.java?rev=808157&r1=808156&r2=808157&view=diff
==============================================================================
--- xmlgraphics/fop/trunk/src/java/org/apache/fop/layoutmgr/StaticContentLayoutManager.java (original)
+++ xmlgraphics/fop/trunk/src/java/org/apache/fop/layoutmgr/StaticContentLayoutManager.java Wed Aug 26 18:50:10 2009
@@ -21,10 +21,6 @@
import java.util.LinkedList;
import java.util.List;
-import java.util.ListIterator;
-
-import org.apache.commons.logging.Log;
-import org.apache.commons.logging.LogFactory;
import org.apache.fop.area.Area;
import org.apache.fop.area.Block;
@@ -35,10 +31,7 @@
import org.apache.fop.fo.pagination.SideRegion;
import org.apache.fop.fo.pagination.StaticContent;
import org.apache.fop.layoutmgr.PageBreakingAlgorithm.PageBreakingLayoutListener;
-import org.apache.fop.layoutmgr.inline.InlineLevelLayoutManager;
import org.apache.fop.layoutmgr.inline.TextLayoutManager;
-import org.apache.fop.traits.MinOptMax;
-import org.apache.fop.util.ListUtil;
/**
* LayoutManager for an fo:flow object.
@@ -48,11 +41,6 @@
*/
public class StaticContentLayoutManager extends BlockStackingLayoutManager {
- /**
- * logging instance
- */
- private static Log log = LogFactory.getLog(StaticContentLayoutManager.class);
-
private RegionReference targetRegion;
private Block targetBlock;
private SideRegion regionFO;
@@ -89,96 +77,7 @@
/** {@inheritDoc} */
public List getNextKnuthElements(LayoutContext context, int alignment) {
- if (true) {
- throw new UnsupportedOperationException(
- "Shouldn't this method be emptied because it's never called at all?");
- }
- //TODO Empty this method?!?
- // set layout dimensions
- setContentAreaIPD(context.getRefIPD());
- setContentAreaBPD(context.getStackLimitBP().opt);
-
- //TODO Copied from elsewhere. May be worthwhile to factor out the common parts.
- // currently active LM
- BlockLevelLayoutManager curLM;
- BlockLevelLayoutManager prevLM = null;
- MinOptMax stackSize = new MinOptMax();
- List returnedList;
- List returnList = new LinkedList();
-
- while ((curLM = ((BlockLevelLayoutManager) getChildLM())) != null) {
- if (curLM instanceof InlineLevelLayoutManager) {
- log.error("inline area not allowed under flow - ignoring");
- curLM.setFinished(true);
- continue;
- }
-
- // Set up a LayoutContext
- MinOptMax bpd = context.getStackLimitBP();
-
- LayoutContext childLC = new LayoutContext(0);
- childLC.setStackLimitBP(MinOptMax.subtract(bpd, stackSize));
- childLC.setRefIPD(context.getRefIPD());
-
- // get elements from curLM
- returnedList = curLM.getNextKnuthElements(childLC, alignment);
- //log.debug("FLM.getNextKnuthElements> returnedList.size() = "
- // + returnedList.size());
-
- // "wrap" the Position inside each element
- List tempList = returnedList;
- KnuthElement tempElement;
- returnedList = new LinkedList();
- ListIterator listIter = tempList.listIterator();
- while (listIter.hasNext()) {
- tempElement = (KnuthElement)listIter.next();
- tempElement.setPosition(new NonLeafPosition(this, tempElement.getPosition()));
- returnedList.add(tempElement);
- }
-
- if (returnedList.size() == 1
- && ((KnuthElement)returnedList.get(0)).isPenalty()
- && ((KnuthPenalty)returnedList.get(0)).getP() == -KnuthElement.INFINITE) {
- // a descendant of this flow has break-before
- returnList.addAll(returnedList);
- return returnList;
- } else {
- if (!returnList.isEmpty()) {
- // there is a block before this one
- if (prevLM.mustKeepWithNext()
- || curLM.mustKeepWithPrevious()) {
- // add an infinite penalty to forbid a break between blocks
- returnList.add(new KnuthPenalty(0,
- KnuthElement.INFINITE, false,
- new Position(this), false));
- } else if (!((KnuthElement) ListUtil.getLast(returnList))
- .isGlue()) {
- // add a null penalty to allow a break between blocks
- returnList.add(new KnuthPenalty(0, 0, false, new Position(this), false));
- }
- }
-/*LF*/ if (!returnedList.isEmpty()) { // controllare!
- returnList.addAll(returnedList);
- final KnuthElement last = (KnuthElement) ListUtil
- .getLast(returnedList);
- if (last.isPenalty()
- && ((KnuthPenalty) last).getP() == -KnuthElement.INFINITE) {
- // a descendant of this flow has break-after
-/*LF*/ //log.debug("FLM - break after!!");
- return returnList;
- }
-/*LF*/ }
- }
- prevLM = curLM;
- }
-
- setFinished(true);
-
- if (returnList.isEmpty()) {
- return null;
- } else {
- return returnList;
- }
+ throw new IllegalStateException();
}
/**
Modified: xmlgraphics/fop/trunk/src/java/org/apache/fop/layoutmgr/inline/ContentLayoutManager.java
URL: http://svn.apache.org/viewvc/xmlgraphics/fop/trunk/src/java/org/apache/fop/layoutmgr/inline/ContentLayoutManager.java?rev=808157&r1=808156&r2=808157&view=diff
==============================================================================
--- xmlgraphics/fop/trunk/src/java/org/apache/fop/layoutmgr/inline/ContentLayoutManager.java (original)
+++ xmlgraphics/fop/trunk/src/java/org/apache/fop/layoutmgr/inline/ContentLayoutManager.java Wed Aug 26 18:50:10 2009
@@ -27,6 +27,7 @@
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
+
import org.apache.fop.area.Area;
import org.apache.fop.area.Block;
import org.apache.fop.area.LineArea;
@@ -43,7 +44,6 @@
import org.apache.fop.layoutmgr.Position;
import org.apache.fop.layoutmgr.PositionIterator;
import org.apache.fop.layoutmgr.SpaceSpecifier;
-import org.apache.fop.traits.MinOptMax;
/**
* Content Layout Manager.
@@ -111,8 +111,6 @@
LayoutContext childLC = new LayoutContext(LayoutContext.NEW_AREA);
childLC.setLeadingSpace(new SpaceSpecifier(false));
childLC.setTrailingSpace(new SpaceSpecifier(false));
- // set stackLimit for lines
- childLC.setStackLimitIP(new MinOptMax(ipd));
childLC.setRefIPD(ipd);
int lineHeight = 14000;
@@ -129,8 +127,7 @@
stackSize = 0;
- List contentList =
- getNextKnuthElements(childLC, Constants.EN_START);
+ List contentList = getNextKnuthElements(childLC, Constants.EN_START);
ListIterator contentIter = contentList.listIterator();
while (contentIter.hasNext()) {
KnuthElement element = (KnuthElement) contentIter.next();
@@ -149,8 +146,7 @@
lc.setFlags(LayoutContext.RESOLVE_LEADING_SPACE, true);
lc.setLeadingSpace(new SpaceSpecifier(false));
lc.setTrailingSpace(new SpaceSpecifier(false));
- KnuthPossPosIter contentPosIter =
- new KnuthPossPosIter(contentList, 0, contentList.size());
+ KnuthPossPosIter contentPosIter = new KnuthPossPosIter(contentList, 0, contentList.size());
curLM.addAreas(contentPosIter, lc);
}
Modified: xmlgraphics/fop/trunk/src/java/org/apache/fop/layoutmgr/inline/InlineLayoutManager.java
URL: http://svn.apache.org/viewvc/xmlgraphics/fop/trunk/src/java/org/apache/fop/layoutmgr/inline/InlineLayoutManager.java?rev=808157&r1=808156&r2=808157&view=diff
==============================================================================
--- xmlgraphics/fop/trunk/src/java/org/apache/fop/layoutmgr/inline/InlineLayoutManager.java (original)
+++ xmlgraphics/fop/trunk/src/java/org/apache/fop/layoutmgr/inline/InlineLayoutManager.java Wed Aug 26 18:50:10 2009
@@ -248,8 +248,6 @@
List returnList = new LinkedList();
KnuthSequence lastSequence = null;
- SpaceSpecifier leadingSpace = context.getLeadingSpace();
-
if (fobj instanceof Title) {
alignmentContext = new AlignmentContext(font,
lineHeight.getOptimum(this).getLength().getValue(this),
@@ -274,14 +272,6 @@
if (getSpaceStart() != null) {
context.getLeadingSpace().addSpace(new SpaceVal(getSpaceStart(), this));
}
-
- // Check for "fence"
- if (hasLeadingFence(!context.isFirstArea())) {
- // Reset leading space sequence for child areas
- leadingSpace = new SpaceSpecifier(false);
- }
- // Reset state variables
- clearPrevIPD(); // Clear stored prev content dimensions
}
StringBuffer trace = new StringBuffer("InlineLM:");
Modified: xmlgraphics/fop/trunk/src/java/org/apache/fop/layoutmgr/inline/InlineStackingLayoutManager.java
URL: http://svn.apache.org/viewvc/xmlgraphics/fop/trunk/src/java/org/apache/fop/layoutmgr/inline/InlineStackingLayoutManager.java?rev=808157&r1=808156&r2=808157&view=diff
==============================================================================
--- xmlgraphics/fop/trunk/src/java/org/apache/fop/layoutmgr/inline/InlineStackingLayoutManager.java (original)
+++ xmlgraphics/fop/trunk/src/java/org/apache/fop/layoutmgr/inline/InlineStackingLayoutManager.java Wed Aug 26 18:50:10 2009
@@ -19,12 +19,13 @@
package org.apache.fop.layoutmgr.inline;
-import java.util.LinkedList;
import java.util.Iterator;
+import java.util.LinkedList;
import java.util.List;
import java.util.ListIterator;
-import java.util.HashMap;
+import org.apache.fop.area.Area;
+import org.apache.fop.area.inline.Space;
import org.apache.fop.fo.FObj;
import org.apache.fop.fo.properties.SpaceProperty;
import org.apache.fop.layoutmgr.AbstractLayoutManager;
@@ -34,8 +35,6 @@
import org.apache.fop.layoutmgr.NonLeafPosition;
import org.apache.fop.layoutmgr.Position;
import org.apache.fop.layoutmgr.PositionIterator;
-import org.apache.fop.area.Area;
-import org.apache.fop.area.inline.Space;
import org.apache.fop.traits.MinOptMax;
/**
@@ -62,12 +61,6 @@
}
}
-
- /**
- * Size of any start or end borders and padding.
- */
- private MinOptMax allocIPD = new MinOptMax(0);
-
/**
* Size of border and padding in BPD (ie, before and after).
*/
@@ -78,9 +71,6 @@
/** The child layout context */
protected LayoutContext childLC;
- /** Used to store previous content IPD for each child LM. */
- private HashMap hmPrevIPD = new HashMap();
-
/**
* Create an inline stacking layout manager.
* This is used for fo's that create areas that
@@ -149,22 +139,6 @@
}
/**
- * TODO: Explain this method
- * @param lm ???
- * @return ???
- */
- protected MinOptMax getPrevIPD(LayoutManager lm) {
- return (MinOptMax) hmPrevIPD.get(lm);
- }
-
- /**
- * Clear the previous IPD calculation.
- */
- protected void clearPrevIPD() {
- hmPrevIPD.clear();
- }
-
- /**
* Returns the current area.
* @return the current area
*/
Modified: xmlgraphics/fop/trunk/src/java/org/apache/fop/layoutmgr/inline/LineLayoutManager.java
URL: http://svn.apache.org/viewvc/xmlgraphics/fop/trunk/src/java/org/apache/fop/layoutmgr/inline/LineLayoutManager.java?rev=808157&r1=808156&r2=808157&view=diff
==============================================================================
--- xmlgraphics/fop/trunk/src/java/org/apache/fop/layoutmgr/inline/LineLayoutManager.java (original)
+++ xmlgraphics/fop/trunk/src/java/org/apache/fop/layoutmgr/inline/LineLayoutManager.java Wed Aug 26 18:50:10 2009
@@ -20,6 +20,7 @@
package org.apache.fop.layoutmgr.inline;
import java.util.ArrayList;
+import java.util.Iterator;
import java.util.LinkedList;
import java.util.List;
import java.util.ListIterator;
@@ -116,8 +117,8 @@
* inline break positions.
*/
private static class LineBreakPosition extends LeafPosition {
- private int iParIndex; // index of the Paragraph this Position refers to
- private int iStartIndex; //index of the first element this Position refers to
+ private int parIndex; // index of the Paragraph this Position refers to
+ private int startIndex; //index of the first element this Position refers to
private int availableShrink;
private int availableStretch;
private int difference;
@@ -130,16 +131,16 @@
private int spaceAfter;
private int baseline;
- LineBreakPosition(LayoutManager lm, int index, int iStartIndex, int iBreakIndex,
+ LineBreakPosition(LayoutManager lm, int index, int startIndex, int breakIndex,
int shrink, int stretch, int diff,
double ipdA, double adjust, int ind,
int lh, int lw, int sb, int sa, int bl) {
- super(lm, iBreakIndex);
+ super(lm, breakIndex);
availableShrink = shrink;
availableStretch = stretch;
difference = diff;
- iParIndex = index;
- this.iStartIndex = iStartIndex;
+ parIndex = index;
+ this.startIndex = startIndex;
ipdAdjust = ipdA;
dAdjust = adjust;
startIndent = ind;
@@ -167,18 +168,18 @@
private Length lineHeight;
private int lead;
private int follow;
- private AlignmentContext alignmentContext = null;
+ private AlignmentContext alignmentContext;
- private List knuthParagraphs = null;
- private int iReturnedLBP = 0;
-
- // parameters of Knuth's algorithm:
- // penalty value for flagged penalties
- private int flaggedPenalty = 50;
+ private List knuthParagraphs;
private LineLayoutPossibilities lineLayouts;
private List lineLayoutsList;
- private int iLineWidth = 0;
+ private int ipd = 0;
+ /**
+ * When layout must be re-started due to a change of IPD, there is no need
+ * to perform hyphenation on the remaining Knuth sequence once again.
+ */
+ private boolean hyphenationPerformed;
/**
* this constant is used to create elements when text-align is center:
@@ -238,7 +239,7 @@
} else {
lineFiller = new MinOptMax(lastLineEndIndent,
lastLineEndIndent,
- layoutManager.iLineWidth);
+ layoutManager.ipd);
}
// add auxiliary elements at the beginning of the paragraph
@@ -319,11 +320,9 @@
private int activePossibility;
private int addedPositions;
private int textIndent;
- private int fillerMinWidth;
private int lineHeight;
private int lead;
private int follow;
- private int maxDiff;
private static final double MAX_DEMERITS = 10e6;
public LineBreakingAlgorithm (int pageAlign,
@@ -334,22 +333,17 @@
super(textAlign, textAlignLast, first, false, maxFlagCount);
pageAlignment = pageAlign;
textIndent = indent;
- fillerMinWidth = fillerWidth;
lineHeight = lh;
lead = ld;
follow = fl;
thisLLM = llm;
activePossibility = -1;
- maxDiff = fobj.getWidows() >= fobj.getOrphans()
- ? fobj.getWidows()
- : fobj.getOrphans();
}
public void updateData1(int lineCount, double demerits) {
lineLayouts.addPossibility(lineCount, demerits);
- if (super.log.isTraceEnabled()) {
- super.log.trace(
- "Layout possibility in " + lineCount + " lines; break at position:");
+ if (log.isTraceEnabled()) {
+ log.trace("Layout possibility in " + lineCount + " lines; break at position:");
}
}
@@ -430,7 +424,7 @@
// true if this line contains only zero-height, auxiliary boxes
// and the actual line width is 0; in this case, the line "collapses"
// i.e. the line area will have bpd = 0
- boolean bZeroHeightLine = (difference == iLineWidth);
+ boolean bZeroHeightLine = (difference == ipd);
// if line-stacking-strategy is "font-height", the line height
// is not affected by its content
@@ -486,7 +480,7 @@
firstElementIndex, lastElementIndex,
availableShrink, availableStretch,
difference, ratio, 0, indent,
- 0, iLineWidth, 0, 0, 0);
+ 0, ipd, 0, 0, 0);
} else {
return new LineBreakPosition(thisLLM,
knuthParagraphs.indexOf(par),
@@ -494,18 +488,11 @@
availableShrink, availableStretch,
difference, ratio, 0, indent,
lineLead + lineFollow,
- iLineWidth, spaceBefore, spaceAfter,
+ ipd, spaceBefore, spaceAfter,
lineLead);
}
}
- public int findBreakingPoints(Paragraph par, /*int lineWidth,*/
- double threshold, boolean force,
- int allowedBreaks) {
- return super.findBreakingPoints(par, /*lineWidth,*/
- threshold, force, allowedBreaks);
- }
-
protected int filterActiveNodes() {
KnuthNode bestActiveNode = null;
@@ -578,13 +565,10 @@
FontInfo fi = fobj.getFOEventHandler().getFontInfo();
FontTriplet[] fontkeys = fobj.getCommonFont().getFontState(fi);
Font fs = fi.getFontInstance(fontkeys[0], fobj.getCommonFont().fontSize.getValue(this));
- alignmentContext
- = new AlignmentContext(fs, lineHeight.getValue(this), context.getWritingMode());
+ alignmentContext = new AlignmentContext(fs, lineHeight.getValue(this),
+ context.getWritingMode());
context.setAlignmentContext(alignmentContext);
- // Get a break from currently active child LM
- // Set up constraints for inline level managers
-
- clearPrevIPD();
+ ipd = context.getRefIPD();
//PHASE 1: Create Knuth elements
if (knuthParagraphs == null) {
@@ -606,34 +590,33 @@
//PHASE 2: Create line breaks
return createLineBreaks(context.getBPAlignment(), context);
- /*
- LineBreakPosition lbp = null;
- if (breakpoints == null) {
- // find the optimal line breaking points for each paragraph
- breakpoints = new ArrayList();
- ListIterator paragraphsIterator
- = knuthParagraphs.listIterator(knuthParagraphs.size());
- Paragraph currPar = null;
- while (paragraphsIterator.hasPrevious()) {
- currPar = (Paragraph) paragraphsIterator.previous();
- findBreakingPoints(currPar, context.getStackLimit().opt);
- }
- }*/
+ }
- //PHASE 3: Return lines
+ public List getNextKnuthElements(LayoutContext context, int alignment,
+ LeafPosition restartPosition) {
+ log.trace("Restarting line breaking from index " + restartPosition.getIndex());
+ int parIndex = restartPosition.getLeafPos();
+ Paragraph paragraph = (Paragraph) knuthParagraphs.get(parIndex);
+ for (int i = 0; i <= restartPosition.getIndex(); i++) {
+ paragraph.remove(0);
+ }
+ Iterator iter = paragraph.iterator();
+ while (iter.hasNext() && !((KnuthElement) iter.next()).isBox()) {
+ iter.remove();
+ }
+ if (!iter.hasNext()) {
+ knuthParagraphs.remove(parIndex);
+ }
- /*
- // get a break point from the list
- lbp = (LineBreakPosition) breakpoints.get(iReturnedLBP ++);
- if (iReturnedLBP == breakpoints.size()) {
+ // return finished when there's no content
+ if (knuthParagraphs.size() == 0) {
setFinished(true);
+ return null;
}
- BreakPoss curLineBP = new BreakPoss(lbp);
- curLineBP.setFlag(BreakPoss.ISLAST, isFinished());
- curLineBP.setStackingSize(new MinOptMax(lbp.lineHeight));
- return curLineBP;
- */
+ ipd = context.getRefIPD();
+ //PHASE 2: Create line breaks
+ return createLineBreaks(context.getBPAlignment(), context);
}
/**
@@ -643,22 +626,18 @@
private void collectInlineKnuthElements(LayoutContext context) {
LayoutContext inlineLC = new LayoutContext(context);
- InlineLevelLayoutManager curLM;
- List returnedList = null;
- iLineWidth = context.getStackLimitIP().opt;
-
// convert all the text in a sequence of paragraphs made
// of KnuthBox, KnuthGlue and KnuthPenalty objects
- boolean bPrevWasKnuthBox = false;
+ boolean previousIsBox = false;
StringBuffer trace = new StringBuffer("LineLM:");
Paragraph lastPar = null;
+ InlineLevelLayoutManager curLM;
while ((curLM = (InlineLevelLayoutManager) getChildLM()) != null) {
- returnedList = curLM.getNextKnuthElements(inlineLC, effectiveAlignment);
- if (returnedList == null
- || returnedList.size() == 0) {
+ List inlineElements = curLM.getNextKnuthElements(inlineLC, effectiveAlignment);
+ if (inlineElements == null || inlineElements.size() == 0) {
/* curLM.getNextKnuthElements() returned null or an empty list;
* this can happen if there is nothing more to layout,
* so just iterate once more to see if there are other children */
@@ -666,7 +645,7 @@
}
if (lastPar != null) {
- KnuthSequence firstSeq = (KnuthSequence) returnedList.get(0);
+ KnuthSequence firstSeq = (KnuthSequence) inlineElements.get(0);
// finish last paragraph before a new block sequence
if (!firstSeq.isInlineSequence()) {
@@ -676,7 +655,7 @@
if (log.isTraceEnabled()) {
trace.append(" ]");
}
- bPrevWasKnuthBox = false;
+ previousIsBox = false;
}
// does the first element of the first paragraph add to an existing word?
@@ -684,27 +663,24 @@
KnuthElement thisElement;
thisElement = (KnuthElement) firstSeq.get(0);
if (thisElement.isBox() && !thisElement.isAuxiliary()
- && bPrevWasKnuthBox) {
+ && previousIsBox) {
lastPar.addALetterSpace();
}
}
}
// loop over the KnuthSequences (and single KnuthElements) in returnedList
- ListIterator iter = returnedList.listIterator();
+ ListIterator iter = inlineElements.listIterator();
while (iter.hasNext()) {
KnuthSequence sequence = (KnuthSequence) iter.next();
// the sequence contains inline Knuth elements
if (sequence.isInlineSequence()) {
// look at the last element
ListElement lastElement = sequence.getLast();
- if (lastElement == null) {
- throw new NullPointerException(
- "Sequence was empty! lastElement is null");
- }
- bPrevWasKnuthBox = lastElement.isBox()
- && !((KnuthElement) lastElement).isAuxiliary()
- && ((KnuthElement) lastElement).getW() != 0;
+ assert lastElement != null;
+ previousIsBox = lastElement.isBox()
+ && !((KnuthElement) lastElement).isAuxiliary()
+ && ((KnuthElement) lastElement).getW() != 0;
// if last paragraph is open, add the new elements to the paragraph
// else this is the last paragraph
@@ -729,8 +705,7 @@
// finish last paragraph if it was closed with a linefeed
if (lastElement.isPenalty()
- && ((KnuthPenalty) lastElement).getP()
- == -KnuthPenalty.INFINITE) {
+ && ((KnuthPenalty) lastElement).getP() == -KnuthPenalty.INFINITE) {
// a penalty item whose value is -inf
// represents a preserved linefeed,
// which forces a line break
@@ -738,7 +713,7 @@
if (!lastPar.containsBox()) {
//only a forced linefeed on this line
//-> compensate with an auxiliary glue
- lastPar.add(new KnuthGlue(iLineWidth, 0, iLineWidth, null, true));
+ lastPar.add(new KnuthGlue(ipd, 0, ipd, null, true));
}
lastPar.endParagraph();
ElementListObserver.observe(lastPar, "line", null);
@@ -746,7 +721,7 @@
if (log.isTraceEnabled()) {
trace.append(" ]");
}
- bPrevWasKnuthBox = false;
+ previousIsBox = false;
}
} else { // the sequence is a block sequence
// the positions will be wrapped with this LM in postProcessLineBreaks
@@ -768,144 +743,14 @@
}
/**
- * Find a set of breaking points.
- * This method is called only once by getNextBreakPoss, and it
- * subsequently calls the other findBreakingPoints() method with
- * different parameters, until a set of breaking points is found.
- *
- * @param par the list of elements that must be parted
- * into lines
- * @param lineWidth the desired length ot the lines
- */
- /*
- private void findBreakingPoints(Paragraph par, int lineWidth) {
- // maximum adjustment ratio permitted
- float maxAdjustment = 1;
-
- // first try
- if (!findBreakingPoints(par, lineWidth, maxAdjustment, false)) {
- // the first try failed, now try something different
- log.debug("No set of breaking points found with maxAdjustment = " + maxAdjustment);
- if (hyphenationProperties.hyphenate == Constants.EN_TRUE) {
- // consider every hyphenation point as a legal break
- findHyphenationPoints(par);
- } else {
- // try with a higher threshold
- maxAdjustment = 5;
- }
-
- if (!findBreakingPoints(par, lineWidth, maxAdjustment, false)) {
- // the second try failed too, try with a huge threshold;
- // if this fails too, use a different algorithm
- log.debug("No set of breaking points found with maxAdjustment = " + maxAdjustment
- + (hyphenationProperties.hyphenate == Constants.EN_TRUE ? " and hyphenation" : ""));
- maxAdjustment = 20;
- if (!findBreakingPoints(par, lineWidth, maxAdjustment, true)) {
- log.debug("No set of breaking points found, using first-fit algorithm");
- }
- }
- }
- }
-
- private boolean findBreakingPoints(Paragraph par, int lineWidth,
- double threshold, boolean force) {
- KnuthParagraph knuthPara = new KnuthParagraph(par);
- int lines = knuthPara.findBreakPoints(lineWidth, threshold, force);
- if (lines == 0) {
- return false;
- }
-
- for (int i = lines-1; i >= 0; i--) {
- int line = i+1;
- if (log.isTraceEnabled()) {
- log.trace("Making line from " + knuthPara.getStart(i) + " to " +
- knuthPara.getEnd(i));
- }
- // compute indent and adjustment ratio, according to
- // the value of text-align and text-align-last
-
- int difference = knuthPara.getDifference(i);
- if (line == lines) {
- difference += par.lineFillerWidth;
- }
- int textAlign = (line < lines)
- ? textAlignment : textAlignmentLast;
- int indent = (textAlign == EN_CENTER)
- ? difference / 2
- : (textAlign == EN_END) ? difference : 0;
- indent += (line == 1 && knuthParagraphs.indexOf(par) == 0)
- ? textIndent.getValue(this) : 0;
- double ratio = (textAlign == EN_JUSTIFY)
- ? knuthPara.getAdjustRatio(i) : 0;
-
- int start = knuthPara.getStart(i);
- int end = knuthPara.getEnd(i);
- makeLineBreakPosition(par, start, end, 0, ratio, indent);
- }
- return true;
- }
-
- private void makeLineBreakPosition(Paragraph par,
- int firstElementIndex, int lastElementIndex,
- int insertIndex, double ratio, int indent) {
- // line height calculation
-
- int halfLeading = (lineHeight - lead - follow) / 2;
- // height above the main baseline
- int lineLead = lead + halfLeading;
- // maximum size of top and bottom alignment
- int lineFollow = follow + halfLeading;
-
- ListIterator inlineIterator
- = par.listIterator(firstElementIndex);
- for (int j = firstElementIndex;
- j <= lastElementIndex;
- j++) {
- KnuthElement element = (KnuthElement) inlineIterator.next();
- if (element.isBox()) {
- KnuthInlineBox box = (KnuthInlineBox)element;
- if (box.getLead() > lineLead) {
- lineLead = box.getLead();
- }
- if (box.getTotal() > lineFollow) {
- lineFollow = box.getTotal();
- }
- if (box.getMiddle() > lineLead + middleShift) {
- lineLead += box.getMiddle()
- - lineLead - middleShift;
- }
- if (box.getMiddle() > middlefollow - middleShift) {
- middlefollow += box.getMiddle()
- - middlefollow + middleShift;
- }
- }
- }
-
- if (lineFollow - lineLead > middlefollow) {
- middlefollow = lineFollow - lineLead;
- }
-
- breakpoints.add(insertIndex,
- new LineBreakPosition(this,
- knuthParagraphs.indexOf(par),
- lastElementIndex ,
- ratio, 0, indent,
- lineLead + middlefollow,
- lineLead));
- }*/
-
-
- /**
* Phase 2 of Knuth algorithm: find optimal break points.
* @param alignment alignment in BP direction of the paragraph
* @param context the layout context
* @return a list of Knuth elements representing broken lines
*/
private List createLineBreaks(int alignment, LayoutContext context) {
-
// find the optimal line breaking points for each paragraph
- ListIterator paragraphsIterator
- = knuthParagraphs.listIterator(knuthParagraphs.size());
+ ListIterator paragraphsIterator = knuthParagraphs.listIterator(knuthParagraphs.size());
lineLayoutsList = new ArrayList(knuthParagraphs.size());
LineLayoutPossibilities llPoss;
while (paragraphsIterator.hasPrevious()) {
@@ -947,7 +792,8 @@
this);
if (hyphenationProperties.hyphenate.getEnum() == EN_TRUE
- && fobj.getWrapOption() != EN_NO_WRAP) {
+ && fobj.getWrapOption() != EN_NO_WRAP && !hyphenationPerformed) {
+ hyphenationPerformed = true;
findHyphenationPoints(currPar);
}
@@ -958,7 +804,7 @@
} else {
allowedBreaks = BreakingAlgorithm.NO_FLAGGED_PENALTIES;
}
- alg.setConstantLineWidth(iLineWidth);
+ alg.setConstantLineWidth(ipd);
iBPcount = alg.findBreakingPoints(currPar,
maxAdjustment, false, allowedBreaks);
if (iBPcount == 0 || alignment == EN_JUSTIFY) {
@@ -1014,26 +860,26 @@
alg.resetAlgorithm();
lineLayouts.savePossibilities(true);
// try with shorter lines
- int savedLineWidth = iLineWidth;
- iLineWidth = (int) (iLineWidth * 0.95);
+ int savedLineWidth = ipd;
+ ipd = (int) (ipd * 0.95);
iBPcount = alg.findBreakingPoints(currPar,
- maxAdjustment, true, allowedBreaks);
+ maxAdjustment, true, allowedBreaks);
// use normal lines, when possible
lineLayouts.restorePossibilities();
- iLineWidth = savedLineWidth;
+ ipd = savedLineWidth;
}
if (!lineLayouts.canUseLessLines()) {
alg.resetAlgorithm();
lineLayouts.savePossibilities(true);
// try with longer lines
- int savedLineWidth = iLineWidth;
- iLineWidth = (int) (iLineWidth * 1.05);
- alg.setConstantLineWidth(iLineWidth);
+ int savedLineWidth = ipd;
+ ipd = (int) (ipd * 1.05);
+ alg.setConstantLineWidth(ipd);
iBPcount = alg.findBreakingPoints(currPar,
maxAdjustment, true, allowedBreaks);
// use normal lines, when possible
lineLayouts.restorePossibilities();
- iLineWidth = savedLineWidth;
+ ipd = savedLineWidth;
}
//log.debug("LLM.getNextKnuthElements> now, layouts with more lines? " + lineLayouts.canUseMoreLines());
//log.debug(" now, layouts with fewer lines? " + lineLayouts.canUseLessLines());
@@ -1052,6 +898,7 @@
List returnList = new LinkedList();
+ int endIndex = -1;
for (int p = 0; p < knuthParagraphs.size(); p++) {
// penalty between paragraphs
if (p > 0) {
@@ -1089,7 +936,6 @@
} else {
/* "normal" vertical alignment: create a sequence whose boxes
represent effective lines, and contain LineBreakPositions */
- Position returnPosition = new LeafPosition(this, p);
int startIndex = 0;
for (int i = 0;
i < llPoss.getChosenLineCount();
@@ -1101,13 +947,12 @@
// penalty allowing a page break between lines
Keep keep = getKeepTogether();
returnList.add(new BreakElement(
- new Position(this),
+ new LeafPosition(this, p, endIndex),
keep.getPenalty(),
keep.getContext(),
context));
}
- int endIndex
- = ((LineBreakPosition) llPoss.getChosenPosition(i)).getLeafPos();
+ endIndex = ((LineBreakPosition) llPoss.getChosenPosition(i)).getLeafPos();
// create a list of the FootnoteBodyLM handling footnotes
// whose citations are in this line
List footnoteList = new LinkedList();
@@ -1115,15 +960,14 @@
while (elementIterator.nextIndex() <= endIndex) {
KnuthElement element = (KnuthElement) elementIterator.next();
if (element instanceof KnuthInlineBox
- && ((KnuthInlineBox) element).isAnchor()) {
+ && ((KnuthInlineBox) element).isAnchor()) {
footnoteList.add(((KnuthInlineBox) element).getFootnoteBodyLM());
} else if (element instanceof KnuthBlockBox) {
footnoteList.addAll(((KnuthBlockBox) element).getFootnoteBodyLMs());
}
}
startIndex = endIndex + 1;
- LineBreakPosition lbp
- = (LineBreakPosition) llPoss.getChosenPosition(i);
+ LineBreakPosition lbp = (LineBreakPosition) llPoss.getChosenPosition(i);
returnList.add(new KnuthBlockBox
(lbp.lineHeight + lbp.spaceBefore + lbp.spaceAfter,
footnoteList, lbp, false));
@@ -1597,7 +1441,7 @@
Position pos = (Position) parentIter.next();
boolean isLastPosition = !parentIter.hasNext();
if (pos instanceof LineBreakPosition) {
- addInlineArea(context, pos, isLastPosition);
+ addInlineArea(context, (LineBreakPosition) pos, isLastPosition);
} else if ((pos instanceof NonLeafPosition) && pos.generatesAreas()) {
addBlockArea(context, pos, isLastPosition);
} else {
@@ -1617,147 +1461,129 @@
* @param pos the position for which the line is generated
* @param isLastPosition true if this is the last position of this LM
*/
- private void addInlineArea(LayoutContext context, Position pos, boolean isLastPosition) {
- ListIterator seqIterator = null;
- KnuthElement tempElement = null;
- // the TLM which created the last KnuthElement in this line
- LayoutManager lastLM = null;
-
- LineBreakPosition lbp = (LineBreakPosition) pos;
- int iCurrParIndex;
- iCurrParIndex = lbp.iParIndex;
- KnuthSequence seq = (KnuthSequence) knuthParagraphs.get(iCurrParIndex);
- int iStartElement = lbp.iStartIndex;
- int iEndElement = lbp.getLeafPos();
-
- LineArea lineArea
- = new LineArea((lbp.getLeafPos() < seq.size() - 1
- ? textAlignment : textAlignmentLast),
- lbp.difference, lbp.availableStretch, lbp.availableShrink);
- if (lbp.startIndent != 0) {
- lineArea.addTrait(Trait.START_INDENT, new Integer(lbp.startIndent));
- }
- lineArea.setBPD(lbp.lineHeight);
- lineArea.setIPD(lbp.lineWidth);
- lineArea.addTrait(Trait.SPACE_BEFORE, new Integer(lbp.spaceBefore));
- lineArea.addTrait(Trait.SPACE_AFTER, new Integer(lbp.spaceAfter));
- alignmentContext.resizeLine(lbp.lineHeight, lbp.baseline);
-
- if (seq instanceof Paragraph) {
- Paragraph currPar = (Paragraph) seq;
- // ignore the first elements added by the LineLayoutManager
- iStartElement += (iStartElement == 0) ? currPar.ignoreAtStart : 0;
-
- // if this is the last line area that for this paragraph,
- // ignore the last elements added by the LineLayoutManager and
- // subtract the last-line-end-indent from the area ipd
- if (iEndElement == (currPar.size() - 1)) {
- iEndElement -= currPar.ignoreAtEnd;
- lineArea.setIPD(lineArea.getIPD() - lastLineEndIndent.getValue(this));
- }
+ private void addInlineArea(LayoutContext context, LineBreakPosition lbp,
+ boolean isLastPosition) {
+ // the TLM which created the last KnuthElement in this line
+ LayoutManager lastLM = null;
+
+ KnuthSequence seq = (KnuthSequence) knuthParagraphs.get(lbp.parIndex);
+ int startElementIndex = lbp.startIndex;
+ int endElementIndex = lbp.getLeafPos();
+
+ LineArea lineArea = new LineArea(
+ (lbp.getLeafPos() < seq.size() - 1 ? textAlignment : textAlignmentLast),
+ lbp.difference, lbp.availableStretch, lbp.availableShrink);
+ if (lbp.startIndent != 0) {
+ lineArea.addTrait(Trait.START_INDENT, new Integer(lbp.startIndent));
+ }
+ lineArea.setBPD(lbp.lineHeight);
+ lineArea.setIPD(lbp.lineWidth);
+ lineArea.addTrait(Trait.SPACE_BEFORE, new Integer(lbp.spaceBefore));
+ lineArea.addTrait(Trait.SPACE_AFTER, new Integer(lbp.spaceAfter));
+ alignmentContext.resizeLine(lbp.lineHeight, lbp.baseline);
+
+ if (seq instanceof Paragraph) {
+ Paragraph currPar = (Paragraph) seq;
+ // ignore the first elements added by the LineLayoutManager
+ startElementIndex += (startElementIndex == 0) ? currPar.ignoreAtStart : 0;
+
+ // if this is the last line area that for this paragraph,
+ // ignore the last elements added by the LineLayoutManager and
+ // subtract the last-line-end-indent from the area ipd
+ if (endElementIndex == (currPar.size() - 1)) {
+ endElementIndex -= currPar.ignoreAtEnd;
+ lineArea.setIPD(lineArea.getIPD() - lastLineEndIndent.getValue(this));
}
+ }
- // Remove trailing spaces if allowed so
- if (whiteSpaceTreament == EN_IGNORE_IF_SURROUNDING_LINEFEED
+ // Remove trailing spaces if allowed so
+ if (whiteSpaceTreament == EN_IGNORE_IF_SURROUNDING_LINEFEED
|| whiteSpaceTreament == EN_IGNORE
|| whiteSpaceTreament == EN_IGNORE_IF_BEFORE_LINEFEED) {
- // ignore the last element in the line if it is a KnuthGlue object
- seqIterator = seq.listIterator(iEndElement);
- tempElement = (KnuthElement) seqIterator.next();
- if (tempElement.isGlue()) {
- iEndElement--;
- // this returns the same KnuthElement
- seqIterator.previous();
- if (seqIterator.hasPrevious()) {
- tempElement = (KnuthElement) seqIterator.previous();
- } else {
- tempElement = null;
- }
- }
- if (tempElement != null) {
- lastLM = tempElement.getLayoutManager();
+ // ignore the last element in the line if it is a KnuthGlue object
+ ListIterator seqIterator = seq.listIterator(endElementIndex);
+ KnuthElement lastElement = (KnuthElement) seqIterator.next();
+ lastLM = lastElement.getLayoutManager();
+ if (lastElement.isGlue()) {
+ endElementIndex--;
+ // this returns the same KnuthElement
+ seqIterator.previous();
+ if (seqIterator.hasPrevious()) {
+ lastLM = ((KnuthElement) seqIterator.previous()).getLayoutManager();
}
}
+ }
- // Remove leading spaces if allowed so
- if (whiteSpaceTreament == EN_IGNORE_IF_SURROUNDING_LINEFEED
+ // Remove leading spaces if allowed so
+ if (whiteSpaceTreament == EN_IGNORE_IF_SURROUNDING_LINEFEED
|| whiteSpaceTreament == EN_IGNORE
|| whiteSpaceTreament == EN_IGNORE_IF_AFTER_LINEFEED) {
- // ignore KnuthGlue and KnuthPenalty objects
- // at the beginning of the line
- seqIterator = seq.listIterator(iStartElement);
- tempElement = (KnuthElement) seqIterator.next();
- while (!tempElement.isBox() && seqIterator.hasNext()) {
- tempElement = (KnuthElement) seqIterator.next();
- iStartElement++;
- }
- }
- // Add the inline areas to lineArea
- PositionIterator inlinePosIter
- = new KnuthPossPosIter(seq, iStartElement, iEndElement + 1);
-
- iStartElement = lbp.getLeafPos() + 1;
- if (iStartElement == seq.size()) {
- // advance to next paragraph
- iStartElement = 0;
- }
-
- LayoutContext lc = new LayoutContext(0);
- lc.setAlignmentContext(alignmentContext);
- lc.setSpaceAdjust(lbp.dAdjust);
- lc.setIPDAdjust(lbp.ipdAdjust);
- lc.setLeadingSpace(new SpaceSpecifier(true));
+ // ignore KnuthGlue and KnuthPenalty objects
+ // at the beginning of the line
+ ListIterator seqIterator = seq.listIterator(startElementIndex);
+ while (seqIterator.hasNext() && !((KnuthElement) seqIterator.next()).isBox()) {
+ startElementIndex++;
+ }
+ }
+ // Add the inline areas to lineArea
+ PositionIterator inlinePosIter = new KnuthPossPosIter(seq, startElementIndex,
+ endElementIndex + 1);
+
+ LayoutContext lc = new LayoutContext(0);
+ lc.setAlignmentContext(alignmentContext);
+ lc.setSpaceAdjust(lbp.dAdjust);
+ lc.setIPDAdjust(lbp.ipdAdjust);
+ lc.setLeadingSpace(new SpaceSpecifier(true));
+ lc.setTrailingSpace(new SpaceSpecifier(false));
+ lc.setFlags(LayoutContext.RESOLVE_LEADING_SPACE, true);
+
+ /*
+ * extension (not in the XSL FO recommendation): if the left and right margins
+ * have been optimized, recompute indents and / or adjust ratio, according
+ * to the paragraph horizontal alignment
+ */
+ if (false && textAlignment == EN_JUSTIFY) {
+ // re-compute space adjust ratio
+ int updatedDifference = context.getRefIPD()
+ - lbp.lineWidth + lbp.difference;
+ double updatedRatio = 0.0;
+ if (updatedDifference > 0) {
+ updatedRatio = (float) updatedDifference / lbp.availableStretch;
+ } else if (updatedDifference < 0) {
+ updatedRatio = (float) updatedDifference / lbp.availableShrink;
+ }
+ lc.setIPDAdjust(updatedRatio);
+ //log.debug("LLM.addAreas> old difference = " + lbp.difference + " new difference = " + updatedDifference);
+ //log.debug(" old ratio = " + lbp.ipdAdjust + " new ratio = " + updatedRatio);
+ } else if (false && textAlignment == EN_CENTER) {
+ // re-compute indent
+ int updatedIndent = lbp.startIndent
+ + (context.getRefIPD() - lbp.lineWidth) / 2;
+ lineArea.addTrait(Trait.START_INDENT, new Integer(updatedIndent));
+ } else if (false && textAlignment == EN_END) {
+ // re-compute indent
+ int updatedIndent = lbp.startIndent
+ + (context.getRefIPD() - lbp.lineWidth);
+ lineArea.addTrait(Trait.START_INDENT, new Integer(updatedIndent));
+ }
+
+ setCurrentArea(lineArea);
+ setChildContext(lc);
+ LayoutManager childLM;
+ while ((childLM = inlinePosIter.getNextChildLM()) != null) {
+ lc.setFlags(LayoutContext.LAST_AREA, (childLM == lastLM));
+ childLM.addAreas(inlinePosIter, lc);
+ lc.setLeadingSpace(lc.getTrailingSpace());
lc.setTrailingSpace(new SpaceSpecifier(false));
- lc.setFlags(LayoutContext.RESOLVE_LEADING_SPACE, true);
+ }
- /*
- * extension (not in the XSL FO recommendation): if the left and right margins
- * have been optimized, recompute indents and / or adjust ratio, according
- * to the paragraph horizontal alignment
- */
- if (false && textAlignment == EN_JUSTIFY) {
- // re-compute space adjust ratio
- int updatedDifference = context.getStackLimitIP().opt
- - lbp.lineWidth + lbp.difference;
- double updatedRatio = 0.0;
- if (updatedDifference > 0) {
- updatedRatio = (float) updatedDifference / lbp.availableStretch;
- } else if (updatedDifference < 0) {
- updatedRatio = (float) updatedDifference / lbp.availableShrink;
- }
- lc.setIPDAdjust(updatedRatio);
- //log.debug("LLM.addAreas> old difference = " + lbp.difference + " new difference = " + updatedDifference);
- //log.debug(" old ratio = " + lbp.ipdAdjust + " new ratio = " + updatedRatio);
- } else if (false && textAlignment == EN_CENTER) {
- // re-compute indent
- int updatedIndent = lbp.startIndent
- + (context.getStackLimitIP().opt - lbp.lineWidth) / 2;
- lineArea.addTrait(Trait.START_INDENT, new Integer(updatedIndent));
- } else if (false && textAlignment == EN_END) {
- // re-compute indent
- int updatedIndent = lbp.startIndent
- + (context.getStackLimitIP().opt - lbp.lineWidth);
- lineArea.addTrait(Trait.START_INDENT, new Integer(updatedIndent));
- }
-
- setCurrentArea(lineArea);
- setChildContext(lc);
- LayoutManager childLM;
- while ((childLM = inlinePosIter.getNextChildLM()) != null) {
- lc.setFlags(LayoutContext.LAST_AREA, (childLM == lastLM));
- childLM.addAreas(inlinePosIter, lc);
- lc.setLeadingSpace(lc.getTrailingSpace());
- lc.setTrailingSpace(new SpaceSpecifier(false));
- }
-
- // when can this be null?
- // if display-align is distribute, add space after
- if (context.getSpaceAfter() > 0
- && (!context.isLastArea() || !isLastPosition)) {
- lineArea.setBPD(lineArea.getBPD() + context.getSpaceAfter());
- }
- lineArea.finalise();
- parentLM.addChildArea(lineArea);
+ // if display-align is distribute, add space after
+ if (context.getSpaceAfter() > 0
+ && (!context.isLastArea() || !isLastPosition)) {
+ lineArea.setBPD(lineArea.getBPD() + context.getSpaceAfter());
+ }
+ lineArea.finalise();
+ parentLM.addChildArea(lineArea);
}
/**
@@ -1800,7 +1626,7 @@
// set last area flag
blocklc.setFlags(LayoutContext.LAST_AREA,
(context.isLastArea() && childLM == lastLM));
- blocklc.setStackLimitsFrom(context);
+ blocklc.setStackLimitBP(context.getStackLimitBP());
// Add the line areas to Area
childLM.addAreas(childPosIter, blocklc);
blocklc.setLeadingSpace(blocklc.getTrailingSpace());
@@ -1841,5 +1667,11 @@
public boolean getGeneratesLineArea() {
return true;
}
+
+ /** {@inheritDoc} */
+ public boolean isRestartable() {
+ return true;
+ }
+
}
Modified: xmlgraphics/fop/trunk/src/java/org/apache/fop/layoutmgr/list/ListItemLayoutManager.java
URL: http://svn.apache.org/viewvc/xmlgraphics/fop/trunk/src/java/org/apache/fop/layoutmgr/list/ListItemLayoutManager.java?rev=808157&r1=808156&r2=808157&view=diff
==============================================================================
--- xmlgraphics/fop/trunk/src/java/org/apache/fop/layoutmgr/list/ListItemLayoutManager.java (original)
+++ xmlgraphics/fop/trunk/src/java/org/apache/fop/layoutmgr/list/ListItemLayoutManager.java Wed Aug 26 18:50:10 2009
@@ -702,6 +702,13 @@
}
}
+ /** {@inheritDoc} */
+ public void reset() {
+ super.reset();
+ label.reset();
+ body.reset();
+ }
+
}
Modified: xmlgraphics/fop/trunk/src/java/org/apache/fop/render/pdf/PDFEventProducer.xml
URL: http://svn.apache.org/viewvc/xmlgraphics/fop/trunk/src/java/org/apache/fop/render/pdf/PDFEventProducer.xml?rev=808157&r1=808156&r2=808157&view=diff
==============================================================================
--- xmlgraphics/fop/trunk/src/java/org/apache/fop/render/pdf/PDFEventProducer.xml (original)
+++ xmlgraphics/fop/trunk/src/java/org/apache/fop/render/pdf/PDFEventProducer.xml Wed Aug 26 18:50:10 2009
@@ -1,3 +1,4 @@
-<?xml version="1.0" encoding="UTF-8"?><catalogue xml:lang="en">
+<?xml version="1.0" encoding="UTF-8"?>
+<catalogue xml:lang="en">
<message key="org.apache.fop.render.pdf.PDFEventProducer.nonFullyResolvedLinkTargets">{count} link target{count,equals,1,,s} could not be fully resolved and now point{count,equals,1,,s} to the top of the page or {count,equals,1,is,are} dysfunctional.</message>
</catalogue>
---------------------------------------------------------------------
To unsubscribe, e-mail: fop-commits-unsubscribe@xmlgraphics.apache.org
For additional commands, e-mail: fop-commits-help@xmlgraphics.apache.org