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 sp...@apache.org on 2007/09/25 08:53:46 UTC
svn commit: r579095 [1/2] - in
/xmlgraphics/fop/branches/Temp_Interleaved_Page_Line_Breaking: ./
src/java/org/apache/fop/layoutmgr/
src/java/org/apache/fop/layoutmgr/inline/ test/java/org/apache/fop/
Author: spepping
Date: Mon Sep 24 23:53:44 2007
New Revision: 579095
URL: http://svn.apache.org/viewvc?rev=579095&view=rev
Log:
First working version of the code. 222 out of 341 layout-standard unit
tests pass.
Added:
xmlgraphics/fop/branches/Temp_Interleaved_Page_Line_Breaking/BRANCH (with props)
xmlgraphics/fop/branches/Temp_Interleaved_Page_Line_Breaking/src/java/org/apache/fop/layoutmgr/LineBreakingAlgorithm.java (with props)
xmlgraphics/fop/branches/Temp_Interleaved_Page_Line_Breaking/src/java/org/apache/fop/layoutmgr/ParagraphListElement.java (with props)
xmlgraphics/fop/branches/Temp_Interleaved_Page_Line_Breaking/src/java/org/apache/fop/layoutmgr/inline/KnuthParagraph.java (with props)
Modified:
xmlgraphics/fop/branches/Temp_Interleaved_Page_Line_Breaking/src/java/org/apache/fop/layoutmgr/AbstractBaseLayoutManager.java
xmlgraphics/fop/branches/Temp_Interleaved_Page_Line_Breaking/src/java/org/apache/fop/layoutmgr/AbstractBreaker.java
xmlgraphics/fop/branches/Temp_Interleaved_Page_Line_Breaking/src/java/org/apache/fop/layoutmgr/AbstractLayoutManager.java
xmlgraphics/fop/branches/Temp_Interleaved_Page_Line_Breaking/src/java/org/apache/fop/layoutmgr/BreakingAlgorithm.java
xmlgraphics/fop/branches/Temp_Interleaved_Page_Line_Breaking/src/java/org/apache/fop/layoutmgr/FlowLayoutManager.java
xmlgraphics/fop/branches/Temp_Interleaved_Page_Line_Breaking/src/java/org/apache/fop/layoutmgr/KnuthSequence.java
xmlgraphics/fop/branches/Temp_Interleaved_Page_Line_Breaking/src/java/org/apache/fop/layoutmgr/LayoutManager.java
xmlgraphics/fop/branches/Temp_Interleaved_Page_Line_Breaking/src/java/org/apache/fop/layoutmgr/PageBreakingAlgorithm.java
xmlgraphics/fop/branches/Temp_Interleaved_Page_Line_Breaking/src/java/org/apache/fop/layoutmgr/PageSequenceLayoutManager.java
xmlgraphics/fop/branches/Temp_Interleaved_Page_Line_Breaking/src/java/org/apache/fop/layoutmgr/SpaceResolver.java
xmlgraphics/fop/branches/Temp_Interleaved_Page_Line_Breaking/src/java/org/apache/fop/layoutmgr/inline/ContentLayoutManager.java
xmlgraphics/fop/branches/Temp_Interleaved_Page_Line_Breaking/src/java/org/apache/fop/layoutmgr/inline/LineLayoutManager.java
xmlgraphics/fop/branches/Temp_Interleaved_Page_Line_Breaking/test/java/org/apache/fop/KnuthAlgorithmTestCase.java
Added: xmlgraphics/fop/branches/Temp_Interleaved_Page_Line_Breaking/BRANCH
URL: http://svn.apache.org/viewvc/xmlgraphics/fop/branches/Temp_Interleaved_Page_Line_Breaking/BRANCH?rev=579095&view=auto
==============================================================================
--- xmlgraphics/fop/branches/Temp_Interleaved_Page_Line_Breaking/BRANCH (added)
+++ xmlgraphics/fop/branches/Temp_Interleaved_Page_Line_Breaking/BRANCH Mon Sep 24 23:53:44 2007
@@ -0,0 +1,16 @@
+This is branch Temp_Interleaved_Page_Line_Breaking. It holds the
+development of interleaved page and line breaking. That is, line
+breaking is postponed until the page breaker requires the lines of the
+paragraph. This allows the following features:
+
+The page breaker can implement both the total fit strategy for a page
+sequence and the best fit strategy for one page (or a range of
+pages). The latter strategy allows one to have different widths for
+different pages.
+
+A single total fit strategy for page and line breaking. Such a
+strategy allows one to integrate the placement of side floats in the
+page breaking calculations. The setup of such a strategy has not yet
+been fully understood.
+
+$Id$
Propchange: xmlgraphics/fop/branches/Temp_Interleaved_Page_Line_Breaking/BRANCH
------------------------------------------------------------------------------
svn:eol = native
Propchange: xmlgraphics/fop/branches/Temp_Interleaved_Page_Line_Breaking/BRANCH
------------------------------------------------------------------------------
svn:keywords = Author Date Id Revision
Modified: xmlgraphics/fop/branches/Temp_Interleaved_Page_Line_Breaking/src/java/org/apache/fop/layoutmgr/AbstractBaseLayoutManager.java
URL: http://svn.apache.org/viewvc/xmlgraphics/fop/branches/Temp_Interleaved_Page_Line_Breaking/src/java/org/apache/fop/layoutmgr/AbstractBaseLayoutManager.java?rev=579095&r1=579094&r2=579095&view=diff
==============================================================================
--- xmlgraphics/fop/branches/Temp_Interleaved_Page_Line_Breaking/src/java/org/apache/fop/layoutmgr/AbstractBaseLayoutManager.java (original)
+++ xmlgraphics/fop/branches/Temp_Interleaved_Page_Line_Breaking/src/java/org/apache/fop/layoutmgr/AbstractBaseLayoutManager.java Mon Sep 24 23:53:44 2007
@@ -19,6 +19,8 @@
package org.apache.fop.layoutmgr;
+import java.util.List;
+
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.apache.fop.datatypes.LengthBase;
@@ -266,6 +268,14 @@
*/
public FObj getFObj() {
return fobj;
+ }
+
+ /* (non-Javadoc)
+ * @see org.apache.fop.layoutmgr.LayoutManager#rewrapPositionElements(java.util.List, org.apache.fop.layoutmgr.ParagraphListElement)
+ */
+ public void wrapPositionElements(List elementList) {
+ // TODO Auto-generated method stub
+
}
}
Modified: xmlgraphics/fop/branches/Temp_Interleaved_Page_Line_Breaking/src/java/org/apache/fop/layoutmgr/AbstractBreaker.java
URL: http://svn.apache.org/viewvc/xmlgraphics/fop/branches/Temp_Interleaved_Page_Line_Breaking/src/java/org/apache/fop/layoutmgr/AbstractBreaker.java?rev=579095&r1=579094&r2=579095&view=diff
==============================================================================
--- xmlgraphics/fop/branches/Temp_Interleaved_Page_Line_Breaking/src/java/org/apache/fop/layoutmgr/AbstractBreaker.java (original)
+++ xmlgraphics/fop/branches/Temp_Interleaved_Page_Line_Breaking/src/java/org/apache/fop/layoutmgr/AbstractBreaker.java Mon Sep 24 23:53:44 2007
@@ -75,6 +75,10 @@
private int displayAlign;
+ private int breakClass = Constants.NOT_SET;
+
+ private boolean finished = false;
+
/**
* Creates a new BlockSequence.
* @param iStartOn the kind of page the sequence should start on. One of EN_ANY, EN_COLUMN,
@@ -113,10 +117,17 @@
* @return a finalized sequence.
*/
public KnuthSequence endSequence(Position breakPosition) {
+ if (finished) {
+ return this;
+ }
// remove glue and penalty item at the end of the paragraph
- while (this.size() > ignoreAtStart
- && !((KnuthElement)this.get(this.size() - 1)).isBox()) {
- this.remove(this.size() - 1);
+ while (this.size() > ignoreAtStart) {
+ ListElement elt = (ListElement) this.get(this.size() - 1);
+ if (elt instanceof KnuthElement && !((KnuthElement) elt).isBox()) {
+ this.remove(this.size() - 1);
+ } else {
+ break;
+ }
}
if (this.size() > ignoreAtStart) {
// add the elements representing the space at the end of the last line
@@ -140,8 +151,19 @@
}
}
- public BlockSequence endBlockSequence(Position breakPosition) {
+ public KnuthSequence endBlockSequence() {
+ if (finished) {
+ return this;
+ }
+ KnuthPenalty breakPenalty = getBreakPenalty();
+ Position breakPosition = null;
+ if (breakPenalty != null) {
+ setBreakClass(readBreakClass(breakPenalty));
+ removeLast();
+ breakPosition = breakPenalty.getPosition();
+ }
KnuthSequence temp = endSequence(breakPosition);
+ finished = true;
if (temp != null) {
BlockSequence returnSequence = new BlockSequence(startOn, displayAlign);
returnSequence.addAll(temp);
@@ -151,7 +173,66 @@
return null;
}
}
+
+ private KnuthPenalty getBreakPenalty() {
+ KnuthPenalty breakPenalty = null;
+ ListElement elt = (ListElement) getLast();
+ if (elt instanceof KnuthElement && ((KnuthElement) elt).isPenalty()
+ && ((KnuthPenalty) elt).getP() == -KnuthElement.INFINITE) {
+ breakPenalty = (KnuthPenalty) elt;
+ }
+ return breakPenalty;
+ }
+
+ /**
+ * Read the breakclass of an explicitly set penalty.
+ * This method must only be called on an explicitly set penalty,
+ * because it flags Constants.NOT_SET as an illegal break class.
+ * That is, it must be called before the block sequence
+ * is completed with the finishing penalty/glue/penalty.
+ * @param breakPenalty the break penalty whose break class is read
+ * @return the break class
+ */
+ public int readBreakClass(KnuthPenalty breakPenalty) {
+ int breakClass = Constants.NOT_SET;
+ if (breakPenalty != null) {
+ switch (breakPenalty.getBreakClass()) {
+ case Constants.EN_PAGE:
+ log.debug("PLM> break - PAGE");
+ breakClass = Constants.EN_ANY;
+ break;
+ case Constants.EN_COLUMN:
+ log.debug("PLM> break - COLUMN");
+ //TODO Fix this when implementing multi-column layout
+ breakClass = Constants.EN_COLUMN;
+ break;
+ case Constants.EN_ODD_PAGE:
+ log.debug("PLM> break - ODD PAGE");
+ breakClass = Constants.EN_ODD_PAGE;
+ break;
+ case Constants.EN_EVEN_PAGE:
+ log.debug("PLM> break - EVEN PAGE");
+ breakClass = Constants.EN_EVEN_PAGE;
+ break;
+ default:
+ throw new IllegalStateException("Invalid break class: "
+ + breakPenalty.getBreakClass());
+ }
+ }
+ return breakClass;
+ }
+ /**
+ * @param breakClass the breakClass to set
+ */
+ public void setBreakClass(int breakClass) {
+ this.breakClass = breakClass;
+ }
+
+ public int getBreakClass() {
+ return breakClass;
+ }
+
}
/** blockListIndex of the current BlockSequence in blockLists */
@@ -337,6 +418,13 @@
alg.setConstantLineWidth(flowBPD);
iOptPageCount = alg.findBreakingPoints(effectiveList, /*flowBPD,*/
1, true, BreakingAlgorithm.ALL_BREAKS);
+ /* now determine the breakclass of the final penalty,
+ * and set nextSequenceStartsOn accordingly.
+ */
+ int temp = effectiveList.getBreakClass();
+ if (temp != Constants.NOT_SET) {
+ nextSequenceStartsOn = temp;
+ }
log.debug("PLM> iOptPageCount= " + iOptPageCount
+ " pageBreaks.size()= " + alg.getPageBreaks().size());
@@ -561,38 +649,22 @@
//Only implemented by the PSLM
nextSequenceStartsOn = handleSpanChange(childLC, nextSequenceStartsOn);
+/* postpone determination of the breakpenalty and the breakclass
Position breakPosition = null;
- if (((KnuthElement) returnedList.getLast()).isPenalty()
- && ((KnuthPenalty) returnedList.getLast()).getP() == -KnuthElement.INFINITE) {
- KnuthPenalty breakPenalty = (KnuthPenalty) returnedList
- .removeLast();
+ KnuthPenalty breakPenalty = getBreakPenalty(returnedList);
+ if (breakPenalty != null) {
breakPosition = breakPenalty.getPosition();
- switch (breakPenalty.getBreakClass()) {
- case Constants.EN_PAGE:
- log.debug("PLM> break - PAGE");
- nextSequenceStartsOn = Constants.EN_ANY;
- break;
- case Constants.EN_COLUMN:
- log.debug("PLM> break - COLUMN");
- //TODO Fix this when implementing multi-column layout
- nextSequenceStartsOn = Constants.EN_COLUMN;
- break;
- case Constants.EN_ODD_PAGE:
- log.debug("PLM> break - ODD PAGE");
- nextSequenceStartsOn = Constants.EN_ODD_PAGE;
- break;
- case Constants.EN_EVEN_PAGE:
- log.debug("PLM> break - EVEN PAGE");
- nextSequenceStartsOn = Constants.EN_EVEN_PAGE;
- break;
- default:
- throw new IllegalStateException("Invalid break class: "
- + breakPenalty.getBreakClass());
- }
+ nextSequenceStartsOn = considerBreakClass(breakPenalty);
}
+*/
blockList.addAll(returnedList);
+ /* postpone ending the block sequence;
+ * for now set seq equal to blockList;
+ * when can endBlockSequence return null?
BlockSequence seq = null;
seq = blockList.endBlockSequence(breakPosition);
+ */
+ BlockSequence seq = blockList;
if (seq != null) {
blockLists.add(seq);
}
Modified: xmlgraphics/fop/branches/Temp_Interleaved_Page_Line_Breaking/src/java/org/apache/fop/layoutmgr/AbstractLayoutManager.java
URL: http://svn.apache.org/viewvc/xmlgraphics/fop/branches/Temp_Interleaved_Page_Line_Breaking/src/java/org/apache/fop/layoutmgr/AbstractLayoutManager.java?rev=579095&r1=579094&r2=579095&view=diff
==============================================================================
--- xmlgraphics/fop/branches/Temp_Interleaved_Page_Line_Breaking/src/java/org/apache/fop/layoutmgr/AbstractLayoutManager.java (original)
+++ xmlgraphics/fop/branches/Temp_Interleaved_Page_Line_Breaking/src/java/org/apache/fop/layoutmgr/AbstractLayoutManager.java Mon Sep 24 23:53:44 2007
@@ -389,4 +389,30 @@
Map atts = getFObj().getForeignAttributes();
targetArea.setForeignAttributes(atts);
}
+
+
+ /* (non-Javadoc)
+ * @see org.apache.fop.layoutmgr.LayoutManager#rewrapPosition(org.apache.fop.layoutmgr.Position)
+ */
+ public Position rewrapPosition(Position pos, Position basePos) {
+ if (pos.getLM() != this) {
+ throw new IllegalStateException("rewrap Position: LM" + this + "is not owner of Position" + pos);
+ }
+ if (basePos.getLM() == this) {
+ return basePos;
+ }
+ Position subPos = pos.getPosition();
+ if (subPos == null) {
+ throw new IllegalStateException("rewrap Position: expected subposition in " + pos + "; got null");
+ }
+ subPos = subPos.getLM().rewrapPosition(subPos, basePos);
+ Position newPos = new NonLeafPosition(this, subPos);
+ newPos.setIndex(pos.getIndex());
+ if (isLast(pos)) {
+ pos.setIndex(-1);
+ notifyPos(pos);
+ }
+ return newPos;
+ }
+
}
Modified: xmlgraphics/fop/branches/Temp_Interleaved_Page_Line_Breaking/src/java/org/apache/fop/layoutmgr/BreakingAlgorithm.java
URL: http://svn.apache.org/viewvc/xmlgraphics/fop/branches/Temp_Interleaved_Page_Line_Breaking/src/java/org/apache/fop/layoutmgr/BreakingAlgorithm.java?rev=579095&r1=579094&r2=579095&view=diff
==============================================================================
--- xmlgraphics/fop/branches/Temp_Interleaved_Page_Line_Breaking/src/java/org/apache/fop/layoutmgr/BreakingAlgorithm.java (original)
+++ xmlgraphics/fop/branches/Temp_Interleaved_Page_Line_Breaking/src/java/org/apache/fop/layoutmgr/BreakingAlgorithm.java Mon Sep 24 23:53:44 2007
@@ -21,7 +21,6 @@
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
-
import org.apache.fop.fo.FONode;
/**
@@ -39,6 +38,9 @@
* }
* </pre>
*/
+/**
+ *
+ */
public abstract class BreakingAlgorithm {
/** the logger for the class */
@@ -109,8 +111,6 @@
protected int alignment;
/** Alignment of the paragraph's last line. */
protected int alignmentLast;
- /** Used to handle the text-indent property (indent the first line of a paragraph). */
- protected boolean bFirst;
/**
* The set of active nodes in ascending line order. For each line l, activeLines[2l] contains a
@@ -167,11 +167,10 @@
* item
*/
public BreakingAlgorithm(int align, int alignLast,
- boolean first, boolean partOverflowRecovery,
+ boolean partOverflowRecovery,
int maxFlagCount) {
alignment = align;
alignmentLast = alignLast;
- bFirst = first;
this.partOverflowRecoveryActivated = partOverflowRecovery;
this.best = new BestRecords();
maxFlaggedPenaltiesCount = maxFlagCount;
@@ -403,6 +402,7 @@
return findBreakingPoints(par, 0, threshold, force, allowedBreaks);
}
+
/** Finds an optimal set of breakpoints for the given paragraph.
* @param par the paragraph to break
* @param startIndex index of the Knuth element at which the breaking must start
@@ -433,19 +433,24 @@
// previous element in the paragraph is a KnuthBox?
boolean previousIsBox = false;
- // index of the first KnuthBox in the sequence
- int firstBoxIndex = startIndex;
- if (alignment != org.apache.fop.fo.Constants.EN_CENTER) {
- while (par.size() > firstBoxIndex
- && !((KnuthElement) par.get(firstBoxIndex)).isBox()) {
- firstBoxIndex++;
+ {
+ // index of the first KnuthBox in the sequence
+ int firstBoxIndex = startIndex;
+ if (alignment != org.apache.fop.fo.Constants.EN_CENTER) {
+ while (par.size() > firstBoxIndex) {
+ // scan for unresolved elements and paragraphs
+ resolveElements(par, firstBoxIndex);
+ thisElement = (KnuthElement) par.get(firstBoxIndex);
+ if (thisElement.isBox()) {
+ break;
+ }
+ firstBoxIndex++;
+ }
}
+ // create an active node representing the starting point
+ addNode(0, createNode(firstBoxIndex, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, null));
}
-
- // create an active node representing the starting point
- activeLines = new KnuthNode[20];
- addNode(0, createNode(firstBoxIndex, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, null));
-
+
if (log.isTraceEnabled()) {
log.trace("Looping over " + (par.size() - startIndex) + " elements");
}
@@ -454,7 +459,11 @@
// main loop
for (int i = startIndex; i < par.size(); i++) {
- thisElement = getElement(i);
+ resolveElements(par, i);
+ if (i == par.size() - 1) {
+ par.endBlockSequence();
+ }
+ thisElement = (KnuthElement) par.get(i);
if (thisElement.isBox()) {
// a KnuthBox object is not a legal line break
totalWidth += thisElement.getW();
@@ -569,6 +578,15 @@
activeLines = null;
return line;
+ }
+
+ /**
+ * This method is only implemented in a non-trivial way in PageBreakingAlgorithm
+ * @param seq the Knuth Sequence
+ * @param startIndex the start index
+ */
+ void resolveElements(KnuthSequence seq, int startIndex) {
+ ;
}
/**
Modified: xmlgraphics/fop/branches/Temp_Interleaved_Page_Line_Breaking/src/java/org/apache/fop/layoutmgr/FlowLayoutManager.java
URL: http://svn.apache.org/viewvc/xmlgraphics/fop/branches/Temp_Interleaved_Page_Line_Breaking/src/java/org/apache/fop/layoutmgr/FlowLayoutManager.java?rev=579095&r1=579094&r2=579095&view=diff
==============================================================================
--- xmlgraphics/fop/branches/Temp_Interleaved_Page_Line_Breaking/src/java/org/apache/fop/layoutmgr/FlowLayoutManager.java (original)
+++ xmlgraphics/fop/branches/Temp_Interleaved_Page_Line_Breaking/src/java/org/apache/fop/layoutmgr/FlowLayoutManager.java Mon Sep 24 23:53:44 2007
@@ -64,10 +64,6 @@
/** @see org.apache.fop.layoutmgr.LayoutManager */
public LinkedList getNextKnuthElements(LayoutContext context, int alignment) {
- // set layout dimensions
- int flowIPD = getCurrentPV().getCurrentSpan().getColumnWidth();
- int flowBPD = (int) getCurrentPV().getBodyRegion().getBPD();
-
// currently active LM
LayoutManager curLM;
LinkedList returnedList;
@@ -90,7 +86,9 @@
log.debug("span change from " + currentSpan + " to " + span);
context.signalSpanChange(span);
currentSpan = span;
+ /* postpone space resolution
SpaceResolver.resolveElementList(returnList);
+ */
return returnList;
}
@@ -119,7 +117,9 @@
&& ElementListUtils.endsWithForcedBreak(returnedList)) {
// a descendant of this flow has break-before
returnList.addAll(returnedList);
+ /* postpone space resolution
SpaceResolver.resolveElementList(returnList);
+ */
return returnList;
} else {
if (returnList.size() > 0) {
@@ -142,7 +142,9 @@
returnList.addAll(returnedList);
if (ElementListUtils.endsWithForcedBreak(returnList)) {
// a descendant of this flow has break-after
+ /* postpone space resolution
SpaceResolver.resolveElementList(returnList);
+ */
return returnList;
}
}
@@ -154,7 +156,9 @@
}
}
+ /* postpone space resolution
SpaceResolver.resolveElementList(returnList);
+ */
setFinished(true);
if (returnList.size() > 0) {
Modified: xmlgraphics/fop/branches/Temp_Interleaved_Page_Line_Breaking/src/java/org/apache/fop/layoutmgr/KnuthSequence.java
URL: http://svn.apache.org/viewvc/xmlgraphics/fop/branches/Temp_Interleaved_Page_Line_Breaking/src/java/org/apache/fop/layoutmgr/KnuthSequence.java?rev=579095&r1=579094&r2=579095&view=diff
==============================================================================
--- xmlgraphics/fop/branches/Temp_Interleaved_Page_Line_Breaking/src/java/org/apache/fop/layoutmgr/KnuthSequence.java (original)
+++ xmlgraphics/fop/branches/Temp_Interleaved_Page_Line_Breaking/src/java/org/apache/fop/layoutmgr/KnuthSequence.java Mon Sep 24 23:53:44 2007
@@ -58,6 +58,17 @@
public abstract KnuthSequence endSequence();
/**
+ * Only BlockSequence has a non-trivial implementation of this method;
+ * that is where the weird name derives from.
+ * Any KnuthSequence must implement this method because it is used
+ * in BreakingAlgorithm.findBreakingPoints.
+ * @return
+ */
+ public KnuthSequence endBlockSequence() {
+ return null;
+ }
+
+ /**
* Can sequence be appended to this sequence?
* @param sequence The sequence that may be appended.
* @return whether the sequence can be appended to this sequence.
Modified: xmlgraphics/fop/branches/Temp_Interleaved_Page_Line_Breaking/src/java/org/apache/fop/layoutmgr/LayoutManager.java
URL: http://svn.apache.org/viewvc/xmlgraphics/fop/branches/Temp_Interleaved_Page_Line_Breaking/src/java/org/apache/fop/layoutmgr/LayoutManager.java?rev=579095&r1=579094&r2=579095&view=diff
==============================================================================
--- xmlgraphics/fop/branches/Temp_Interleaved_Page_Line_Breaking/src/java/org/apache/fop/layoutmgr/LayoutManager.java (original)
+++ xmlgraphics/fop/branches/Temp_Interleaved_Page_Line_Breaking/src/java/org/apache/fop/layoutmgr/LayoutManager.java Mon Sep 24 23:53:44 2007
@@ -29,6 +29,9 @@
/**
* The interface for all LayoutManagers.
*/
+/**
+ *
+ */
public interface LayoutManager extends PercentBaseContext {
/**
@@ -227,4 +230,27 @@
* @return the same Position but with a position index
*/
Position notifyPos(Position pos);
+
+ /**
+ * Wrap the position of each element in the list in a NonLeafPosition for this LM
+ * Currently BlockStackingLM has wrapPositionElements, LineLM wraps positions in
+ * postProcessSequences, and KnuthSequence has wrapPositions(lm). BlockStackingLM
+ * copies all elements from sourceList to targetList; the other ones modify the
+ * position in place.
+ * @param elementList the list of elements whose positions need to be wrapped
+ */
+ void wrapPositionElements(List elementList);
+
+ /**
+ * Create a new position stack which is a copy of the stack in pos.
+ * If pos is from the same LM as the base position, return the base position.
+ * Otherwise, return a new position, whose index is the index of pos.
+ * If pos is last, increment its index.
+ * Call the LM of the subposition to do the same,
+ * and wrap the new subposition in the new position.
+ * @param pos the position to be copied
+ * @param basePos the base position to be wrapped in the new position stack
+ */
+ Position rewrapPosition(Position pos, Position basePos);
+
}
Added: xmlgraphics/fop/branches/Temp_Interleaved_Page_Line_Breaking/src/java/org/apache/fop/layoutmgr/LineBreakingAlgorithm.java
URL: http://svn.apache.org/viewvc/xmlgraphics/fop/branches/Temp_Interleaved_Page_Line_Breaking/src/java/org/apache/fop/layoutmgr/LineBreakingAlgorithm.java?rev=579095&view=auto
==============================================================================
--- xmlgraphics/fop/branches/Temp_Interleaved_Page_Line_Breaking/src/java/org/apache/fop/layoutmgr/LineBreakingAlgorithm.java (added)
+++ xmlgraphics/fop/branches/Temp_Interleaved_Page_Line_Breaking/src/java/org/apache/fop/layoutmgr/LineBreakingAlgorithm.java Mon Sep 24 23:53:44 2007
@@ -0,0 +1,269 @@
+/*
+ * Copyright 2007 The Apache Software Foundation.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+/* $Id$ */
+
+package org.apache.fop.layoutmgr;
+
+import org.apache.fop.fo.Constants;
+import org.apache.fop.fo.FONode;
+import org.apache.fop.fo.flow.Block;
+import org.apache.fop.layoutmgr.inline.KnuthParagraph;
+import org.apache.fop.layoutmgr.inline.LineLayoutManager;
+import org.apache.fop.layoutmgr.inline.LineLayoutPossibilities;
+import org.apache.fop.traits.MinOptMax;
+
+
+/**
+ *
+ */
+public class LineBreakingAlgorithm extends BreakingAlgorithm {
+ private LineLayoutManager thisLLM;
+ private KnuthParagraph par;
+ private int pageAlignment;
+ private int activePossibility;
+ private int addedPositions;
+ private int textIndent;
+ private int lineWidth;
+ private int maxDiff;
+ private LineLayoutPossibilities lineLayouts;
+ private static final double MAX_DEMERITS = 10e6;
+
+ public LineBreakingAlgorithm(int pageAlign, int lineWidth,
+ KnuthParagraph par) {
+ super(par.textAlignment, par.textAlignmentLast, false, par.maxFlaggedPenaltiesCount);
+
+ this.thisLLM = par.getLineLayoutManager();
+ this.pageAlignment = pageAlign;
+ this.lineWidth = lineWidth;
+ this.par = par;
+
+ this.textIndent = par.textIndent;
+
+ activePossibility = -1;
+ maxDiff = ((Block) thisLLM.getFObj()).getWidows() >= ((Block) thisLLM.getFObj()).getOrphans()
+ ? ((Block) thisLLM.getFObj()).getWidows()
+ : ((Block) thisLLM.getFObj()).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:");
+ }
+ }
+
+ public void updateData2(KnuthNode bestActiveNode,
+ KnuthSequence seq,
+ int total) {
+ KnuthParagraph par = (KnuthParagraph) seq;
+ // compute indent and adjustment ratio, according to
+ // the value of text-align and text-align-last
+ int indent = 0;
+ int difference = bestActiveNode.difference;
+ int textAlign = (bestActiveNode.line < total) ? alignment : alignmentLast;
+ indent += (textAlign == Constants.EN_CENTER)
+ ? difference / 2 : (textAlign == Constants.EN_END) ? difference : 0;
+ indent += (bestActiveNode.line == 1) ? textIndent : 0;
+ double ratio = (textAlign == Constants.EN_JUSTIFY
+ || difference < 0 && -difference <= bestActiveNode.availableShrink)
+ ? bestActiveNode.adjustRatio : 0;
+
+ // add nodes at the beginning of the list, as they are found
+ // backwards, from the last one to the first one
+
+ // the first time this method is called, initialize activePossibility
+ if (activePossibility == -1) {
+ activePossibility = 0;
+ addedPositions = 0;
+ }
+
+ if (addedPositions == lineLayouts.getLineCount(activePossibility)) {
+ activePossibility++;
+ addedPositions = 0;
+ }
+
+ if (difference + bestActiveNode.availableShrink < 0) {
+ if (super.log.isWarnEnabled()) {
+ super.log.warn(FONode.decorateWithContextInfo(
+ "Line " + (addedPositions + 1)
+ + " of a paragraph overflows the available area.", thisLLM.getFObj()));
+ }
+ }
+
+ //log.debug("LLM> (" + (lineLayouts.getLineNumber(activePossibility) - addedPositions)
+ // + ") difference = " + difference + " ratio = " + ratio);
+ MinOptMax lineFiller = par.getLineFiller();
+ lineLayouts.addBreakPosition(thisLLM.makeLineBreakPosition(par,
+ (bestActiveNode.line > 1 ? bestActiveNode.previous.position + 1 : 0),
+ bestActiveNode.position,
+ bestActiveNode.availableShrink - (addedPositions > 0
+ ? 0 : lineFiller.opt - lineFiller.min),
+ bestActiveNode.availableStretch,
+ difference, ratio, indent), activePossibility);
+ addedPositions++;
+ }
+
+ /* reset activePossibility, as if breakpoints have not yet been computed
+ */
+ public void resetAlgorithm() {
+ activePossibility = -1;
+ }
+
+ protected int filterActiveNodes() {
+ KnuthNode bestActiveNode = null;
+
+ if (pageAlignment == Constants.EN_JUSTIFY) {
+ // leave all active nodes and find the optimum line number
+ //log.debug("LBA.filterActiveNodes> " + activeNodeCount + " layouts");
+ for (int i = startLine; i < endLine; i++) {
+ for (KnuthNode node = getNode(i); node != null; node = node.next) {
+ //log.debug(" + lines = " + node.line + " demerits = " + node.totalDemerits);
+ bestActiveNode = compareNodes(bestActiveNode, node);
+ }
+ }
+
+ // scan the node set once again and remove some nodes
+ //log.debug("LBA.filterActiveList> layout selection");
+ for (int i = startLine; i < endLine; i++) {
+ for (KnuthNode node = getNode(i); node != null; node = node.next) {
+ //if (Math.abs(node.line - bestActiveNode.line) > maxDiff) {
+ //if (false) {
+ if (node.line != bestActiveNode.line
+ && node.totalDemerits > MAX_DEMERITS) {
+ //log.debug(" XXX lines = " + node.line + " demerits = " + node.totalDemerits);
+ removeNode(i, node);
+ } else {
+ //log.debug(" ok lines = " + node.line + " demerits = " + node.totalDemerits);
+ }
+ }
+ }
+ } else {
+ // leave only the active node with fewest total demerits
+ for (int i = startLine; i < endLine; i++) {
+ for (KnuthNode node = getNode(i); node != null; node = node.next) {
+ bestActiveNode = compareNodes(bestActiveNode, node);
+ if (node != bestActiveNode) {
+ removeNode(i, node);
+ }
+ }
+ }
+ }
+ return bestActiveNode.line;
+ }
+
+ /**
+ * Fint the optimal linebreaks for a paragraph
+ * @param alignment alignment of the paragraph
+ * @param currPar the Paragraph for which the linebreaks are found
+ * @return the line layout possibilities for the paragraph
+ */
+ public LineLayoutPossibilities findOptimalBreakingPoints() {
+ // use the member lineLayouts, which is read by LineBreakingAlgorithm.updateData1 and 2
+ lineLayouts = new LineLayoutPossibilities();
+ double maxAdjustment = 1;
+ int iBPcount = 0;
+ if (thisLLM.hyphenationProperties.hyphenate == Constants.EN_TRUE
+ && ((Block) thisLLM.getFObj()).getWrapOption() != Constants.EN_NO_WRAP) {
+ thisLLM.findHyphenationPoints(par);
+ }
+
+ // first try
+ int allowedBreaks;
+ if (((Block) thisLLM.getFObj()).getWrapOption() == Constants.EN_NO_WRAP) {
+ allowedBreaks = BreakingAlgorithm.ONLY_FORCED_BREAKS;
+ } else {
+ allowedBreaks = BreakingAlgorithm.NO_FLAGGED_PENALTIES;
+ }
+ setConstantLineWidth(lineWidth);
+ iBPcount = findBreakingPoints(par, maxAdjustment, false, allowedBreaks);
+ if (iBPcount == 0 || alignment == Constants.EN_JUSTIFY) {
+ // if the first try found a set of breaking points, save them
+ if (iBPcount > 0) {
+ resetAlgorithm();
+ lineLayouts.savePossibilities(false);
+ } else {
+ // the first try failed
+ log.debug("No set of breaking points found with maxAdjustment = " + maxAdjustment);
+ }
+
+ // now try something different
+ log.debug("Hyphenation possible? " + (thisLLM.hyphenationProperties.hyphenate == Constants.EN_TRUE));
+ if (thisLLM.hyphenationProperties.hyphenate == Constants.EN_TRUE
+ && !(allowedBreaks == BreakingAlgorithm.ONLY_FORCED_BREAKS)) {
+ // consider every hyphenation point as a legal break
+ allowedBreaks = BreakingAlgorithm.ALL_BREAKS;
+ } else {
+ // try with a higher threshold
+ maxAdjustment = 5;
+ }
+
+ if ((iBPcount
+ = findBreakingPoints(par, maxAdjustment, false, allowedBreaks)) == 0) {
+ // the second try failed too, try with a huge threshold
+ // and force the algorithm to find
+ // a set of breaking points
+ log.debug("No set of breaking points found with maxAdjustment = "
+ + maxAdjustment
+ + (thisLLM.hyphenationProperties.hyphenate == Constants.EN_TRUE
+ ? " and hyphenation" : ""));
+ maxAdjustment = 20;
+ iBPcount
+ = findBreakingPoints(par, maxAdjustment, true, allowedBreaks);
+ }
+
+ // use non-hyphenated breaks, when possible
+ lineLayouts.restorePossibilities();
+
+ /* extension (not in the XSL FO recommendation): if vertical alignment
+ is justify and the paragraph has only one layout, try using
+ shorter or longer lines */
+ //TODO This code snippet is disabled. Reenable?
+ if (false && alignment == Constants.EN_JUSTIFY && alignment == Constants.EN_JUSTIFY) {
+ //log.debug("LLM.getNextKnuthElements> layouts with more lines? " + lineLayouts.canUseMoreLines());
+ //log.debug(" layouts with fewer lines? " + lineLayouts.canUseLessLines());
+ if (!lineLayouts.canUseMoreLines()) {
+ resetAlgorithm();
+ lineLayouts.savePossibilities(true);
+ // try with shorter lines
+ int savedLineWidth = lineWidth;
+ lineWidth = (int) (lineWidth * 0.95);
+ iBPcount = findBreakingPoints(par, maxAdjustment, true, allowedBreaks);
+ // use normal lines, when possible
+ lineLayouts.restorePossibilities();
+ lineWidth = savedLineWidth;
+ }
+ if (!lineLayouts.canUseLessLines()) {
+ resetAlgorithm();
+ lineLayouts.savePossibilities(true);
+ // try with longer lines
+ int savedLineWidth = lineWidth;
+ lineWidth = (int) (lineWidth * 1.05);
+ setConstantLineWidth(lineWidth);
+ iBPcount = findBreakingPoints(par, maxAdjustment, true, allowedBreaks);
+ // use normal lines, when possible
+ lineLayouts.restorePossibilities();
+ lineWidth = savedLineWidth;
+ }
+ //log.debug("LLM.getNextKnuthElements> now, layouts with more lines? " + lineLayouts.canUseMoreLines());
+ //log.debug(" now, layouts with fewer lines? " + lineLayouts.canUseLessLines());
+ }
+ }
+ return lineLayouts;
+ }
+
+}
Propchange: xmlgraphics/fop/branches/Temp_Interleaved_Page_Line_Breaking/src/java/org/apache/fop/layoutmgr/LineBreakingAlgorithm.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: xmlgraphics/fop/branches/Temp_Interleaved_Page_Line_Breaking/src/java/org/apache/fop/layoutmgr/LineBreakingAlgorithm.java
------------------------------------------------------------------------------
svn:keywords = Id
Modified: xmlgraphics/fop/branches/Temp_Interleaved_Page_Line_Breaking/src/java/org/apache/fop/layoutmgr/PageBreakingAlgorithm.java
URL: http://svn.apache.org/viewvc/xmlgraphics/fop/branches/Temp_Interleaved_Page_Line_Breaking/src/java/org/apache/fop/layoutmgr/PageBreakingAlgorithm.java?rev=579095&r1=579094&r2=579095&view=diff
==============================================================================
--- xmlgraphics/fop/branches/Temp_Interleaved_Page_Line_Breaking/src/java/org/apache/fop/layoutmgr/PageBreakingAlgorithm.java (original)
+++ xmlgraphics/fop/branches/Temp_Interleaved_Page_Line_Breaking/src/java/org/apache/fop/layoutmgr/PageBreakingAlgorithm.java Mon Sep 24 23:53:44 2007
@@ -29,7 +29,6 @@
import org.apache.fop.fo.FONode;
import org.apache.fop.fo.FObj;
import org.apache.fop.layoutmgr.AbstractBreaker.PageBreakPosition;
-
import org.apache.fop.traits.MinOptMax;
class PageBreakingAlgorithm extends BreakingAlgorithm {
@@ -100,7 +99,7 @@
MinOptMax footnoteSeparatorLength,
boolean partOverflowRecovery, boolean autoHeight,
boolean favorSinglePart) {
- super(alignment, alignmentLast, true, partOverflowRecovery, 0);
+ super(alignment, alignmentLast, partOverflowRecovery, 0);
this.topLevelLM = topLevelLM;
this.pageProvider = pageProvider;
this.layoutListener = layoutListener;
@@ -730,14 +729,6 @@
pageBreaks.addFirst(pageBreak);
}
- private int getPartCount() {
- if (pageBreaks == null) {
- return 0;
- } else {
- return pageBreaks.size();
- }
- }
-
public void updateData1(int total, double demerits) {
}
@@ -811,6 +802,35 @@
((KnuthPageNode) bestActiveNode).footnoteListIndex,
((KnuthPageNode) bestActiveNode).footnoteElementIndex,
ratio, difference));
+ }
+
+ /**
+ * This method iterates over seq starting at startIndex.
+ * If it finds a ParagraphListElement, the paragraph is broken into lines,
+ * and the ParagraphListElement is replaced by the resulting elements.
+ * The iteration stops at the first resolved element (after line breaking).
+ * Then space resolution is done on seq starting at startIndex.
+ * It is now guaranteed that seq does not to contain ParagraphListElements
+ * until the first resolved element.
+ * @param seq the Knuth Sequence
+ * @param startIndex the start index
+ */
+ void resolveElements(KnuthSequence seq, int startIndex) {
+ for (int i = startIndex; i < seq.size(); ++i) {
+ ListElement elt = (ListElement) seq.get(i);
+ if (!elt.isUnresolvedElement() && !(elt instanceof ParagraphListElement)) {
+ break;
+ }
+ if (elt instanceof ParagraphListElement) {
+ LinkedList lineElts = ((ParagraphListElement) elt).doLineBreaking();
+ seq.remove(i);
+ seq.addAll(i, lineElts);
+ // consider the new element at i
+ --i;
+ continue;
+ }
+ }
+ SpaceResolver.resolveElementList(seq, startIndex);
}
protected int filterActiveNodes() {
Modified: xmlgraphics/fop/branches/Temp_Interleaved_Page_Line_Breaking/src/java/org/apache/fop/layoutmgr/PageSequenceLayoutManager.java
URL: http://svn.apache.org/viewvc/xmlgraphics/fop/branches/Temp_Interleaved_Page_Line_Breaking/src/java/org/apache/fop/layoutmgr/PageSequenceLayoutManager.java?rev=579095&r1=579094&r2=579095&view=diff
==============================================================================
--- xmlgraphics/fop/branches/Temp_Interleaved_Page_Line_Breaking/src/java/org/apache/fop/layoutmgr/PageSequenceLayoutManager.java (original)
+++ xmlgraphics/fop/branches/Temp_Interleaved_Page_Line_Breaking/src/java/org/apache/fop/layoutmgr/PageSequenceLayoutManager.java Mon Sep 24 23:53:44 2007
@@ -271,7 +271,14 @@
while (!childFLM.isFinished() && contentList == null) {
contentList = childFLM.getNextKnuthElements(context, alignment);
}
-
+ /* postpone getting footnote elements
+ getFootnoteKnuthElements(contentList, context, alignment);
+ */
+ return contentList;
+ }
+
+ private void getFootnoteKnuthElements(LinkedList contentList,
+ LayoutContext context, int alignment) {
// scan contentList, searching for footnotes
boolean bFootnotesPresent = false;
if (contentList != null) {
@@ -326,7 +333,6 @@
footnoteSeparatorLength = new MinOptMax(separatorArea.getBPD());
}
- return contentList;
}
protected int getCurrentDisplayAlign() {
Added: xmlgraphics/fop/branches/Temp_Interleaved_Page_Line_Breaking/src/java/org/apache/fop/layoutmgr/ParagraphListElement.java
URL: http://svn.apache.org/viewvc/xmlgraphics/fop/branches/Temp_Interleaved_Page_Line_Breaking/src/java/org/apache/fop/layoutmgr/ParagraphListElement.java?rev=579095&view=auto
==============================================================================
--- xmlgraphics/fop/branches/Temp_Interleaved_Page_Line_Breaking/src/java/org/apache/fop/layoutmgr/ParagraphListElement.java (added)
+++ xmlgraphics/fop/branches/Temp_Interleaved_Page_Line_Breaking/src/java/org/apache/fop/layoutmgr/ParagraphListElement.java Mon Sep 24 23:53:44 2007
@@ -0,0 +1,77 @@
+/*
+ * Copyright 2007 The Apache Software Foundation.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+/* $Id$ */
+
+package org.apache.fop.layoutmgr;
+
+import java.util.Iterator;
+import java.util.LinkedList;
+
+import org.apache.fop.layoutmgr.inline.KnuthParagraph;
+
+/**
+ * This class represents a List Element for a Knuth Paragraph
+ */
+public class ParagraphListElement extends ListElement {
+
+ private KnuthParagraph para;
+
+ /**
+ * @param para The Knuth Paragraph
+ * @param position The position of this List Element
+ */
+ public ParagraphListElement(KnuthParagraph para, Position position) {
+ super(position);
+ this.para = para;
+ }
+
+ /**
+ * @return the Knuth Paragraph
+ */
+ public KnuthParagraph getPara() {
+ return para;
+ }
+
+ /* (non-Javadoc)
+ * @see org.apache.fop.layoutmgr.ListElement#isUnresolvedElement()
+ */
+ public boolean isUnresolvedElement() {
+ return false;
+ }
+
+ public LinkedList doLineBreaking() {
+ LinkedList returnList = para.getLineLayoutManager().createLineBreaks(para);
+ wrapPositions(returnList);
+ return returnList;
+ }
+
+ /**
+ * Wrap the position in each element in list in a position stack
+ * which is a copy of the position stack of this paragraph list element.
+ * @param list
+ */
+ private void wrapPositions(LinkedList list) {
+ Iterator iter = list.iterator();
+ while (iter.hasNext()) {
+ ListElement elt = (ListElement) iter.next();
+ Position pos = getPosition();
+ pos = pos.getLM().rewrapPosition(pos, elt.getPosition());
+ elt.setPosition(pos);
+ }
+ }
+
+}
Propchange: xmlgraphics/fop/branches/Temp_Interleaved_Page_Line_Breaking/src/java/org/apache/fop/layoutmgr/ParagraphListElement.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: xmlgraphics/fop/branches/Temp_Interleaved_Page_Line_Breaking/src/java/org/apache/fop/layoutmgr/ParagraphListElement.java
------------------------------------------------------------------------------
svn:keywords = Id
Modified: xmlgraphics/fop/branches/Temp_Interleaved_Page_Line_Breaking/src/java/org/apache/fop/layoutmgr/SpaceResolver.java
URL: http://svn.apache.org/viewvc/xmlgraphics/fop/branches/Temp_Interleaved_Page_Line_Breaking/src/java/org/apache/fop/layoutmgr/SpaceResolver.java?rev=579095&r1=579094&r2=579095&view=diff
==============================================================================
--- xmlgraphics/fop/branches/Temp_Interleaved_Page_Line_Breaking/src/java/org/apache/fop/layoutmgr/SpaceResolver.java (original)
+++ xmlgraphics/fop/branches/Temp_Interleaved_Page_Line_Breaking/src/java/org/apache/fop/layoutmgr/SpaceResolver.java Mon Sep 24 23:53:44 2007
@@ -607,6 +607,8 @@
/**
* Resolves unresolved elements applying the space resolution rules defined in 4.3.1.
+ * This is the original method, which resolves the whole list at once.
+ * Eventually all invocations must be replaced with the following version.
* @param elems the element list
*/
public static void resolveElementList(LinkedList elems) {
@@ -683,6 +685,165 @@
}
first = false;
}
+ }
+
+ /**
+ * Resolves unresolved elements applying the space resolution rules defined in 4.3.1.
+ * Takes the elements from startIndex until the first resolved element into consideration.
+ * The first resolved element should not be a ParagraphListElement.
+ * @param elems the element list
+ */
+ public static void resolveElementList(KnuthSequence elems, int startIndex) {
+ if (log.isTraceEnabled()) {
+ log.trace(elems);
+ }
+ boolean first = true;
+ boolean last = false;
+ boolean skipNextElement = false;
+ List unresolvedFirst = new java.util.ArrayList();
+ List unresolvedSecond = new java.util.ArrayList();
+ List currentGroup;
+ ListIterator iter = elems.listIterator(startIndex);
+ while (iter.hasNext()) {
+ ListElement el = (ListElement)iter.next();
+ if (!el.isUnresolvedElement()) {
+ break;
+ }
+ if (log.isTraceEnabled()) {
+ log.trace("unresolved found: " + el + " " + first + "/" + last);
+ }
+ BreakElement breakPoss = null;
+ //Clear temp lists
+ unresolvedFirst.clear();
+ unresolvedSecond.clear();
+ //Collect groups
+ if (el instanceof BreakElement) {
+ breakPoss = (BreakElement)el;
+ currentGroup = unresolvedSecond;
+ } else {
+ currentGroup = unresolvedFirst;
+ currentGroup.add(el);
+ }
+ iter.remove();
+ last = true;
+ skipNextElement = true;
+ while (iter.hasNext()) {
+ el = (ListElement)iter.next();
+ if (el instanceof BreakElement && breakPoss != null) {
+ skipNextElement = false;
+ last = false;
+ break;
+ } else if (currentGroup == unresolvedFirst && (el instanceof BreakElement)) {
+ breakPoss = (BreakElement)el;
+ iter.remove();
+ currentGroup = unresolvedSecond;
+ } else if (el.isUnresolvedElement()) {
+ currentGroup.add(el);
+ iter.remove();
+ } else {// !el.isUnresolvedElement()
+ last = false;
+ // the next (resolved) element will cause the loop to break
+ skipNextElement = false;
+ break;
+ }
+ }
+ //last = !iter.hasNext();
+ if (breakPoss == null && unresolvedSecond.size() == 0 && !last) {
+ log.trace("Swap first and second parts in no-break condition,"
+ + " second part is empty.");
+ //The first list is reversed, so swap if this shouldn't happen
+ List swapList = unresolvedSecond;
+ unresolvedSecond = unresolvedFirst;
+ unresolvedFirst = swapList;
+ }
+
+ log.debug("----start space resolution (first=" + first + ", last=" + last + ")...");
+ SpaceResolver resolver =
+ new SpaceResolver(unresolvedFirst, breakPoss, unresolvedSecond, first, last);
+ if (!last) {
+ iter.previous();
+ }
+ resolver.generate(iter);
+ if (!last && skipNextElement) {
+ iter.next();
+ }
+ log.debug("----end space resolution.");
+ first = false;
+ }
+ }
+
+ public static void resolveElementListOld(KnuthSequence elems, int startIndex) {
+ if (log.isTraceEnabled()) {
+ log.trace(elems);
+ }
+ ListIterator iter = elems.listIterator(startIndex);
+ // startIndex is at end of list
+ if (!iter.hasNext()) {
+ return;
+ }
+ ListElement el = (ListElement)iter.next();
+ // startIndex is not at an unresolved element
+ if (!el.isUnresolvedElement()) {
+ return;
+ }
+
+ boolean first = true;
+ boolean last = false;
+ List unresolvedFirst = new java.util.ArrayList();
+ List unresolvedSecond = new java.util.ArrayList();
+ List currentGroup;
+ if (log.isTraceEnabled()) {
+ log.trace("unresolved found: " + el + " " + first + "/" + last);
+ }
+ BreakElement breakPoss = null;
+ //Clear temp lists
+ unresolvedFirst.clear();
+ unresolvedSecond.clear();
+ //Collect groups
+ if (el instanceof BreakElement) {
+ breakPoss = (BreakElement)el;
+ currentGroup = unresolvedSecond;
+ } else {
+ currentGroup = unresolvedFirst;
+ currentGroup.add(el);
+ }
+ iter.remove();
+ last = true;
+ while (iter.hasNext()) {
+ el = (ListElement)iter.next();
+ if (el instanceof BreakElement && breakPoss != null) {
+ last = false;
+ break;
+ } else if (currentGroup == unresolvedFirst && (el instanceof BreakElement)) {
+ breakPoss = (BreakElement)el;
+ iter.remove();
+ currentGroup = unresolvedSecond;
+ } else if (el.isUnresolvedElement()) {
+ currentGroup.add(el);
+ iter.remove();
+ } else {
+ last = false;
+ break;
+ }
+ }
+ if (breakPoss == null && unresolvedSecond.size() == 0 && !last) {
+ log.trace("Swap first and second parts in no-break condition,"
+ + " second part is empty.");
+ //The first list is reversed, so swap if this shouldn't happen
+ List swapList = unresolvedSecond;
+ unresolvedSecond = unresolvedFirst;
+ unresolvedFirst = swapList;
+ }
+
+ log.debug("----start space resolution (first=" + first + ", last=" + last + ")...");
+ SpaceResolver resolver =
+ new SpaceResolver(unresolvedFirst, breakPoss, unresolvedSecond,
+ first, last);
+ if (!last) {
+ iter.previous();
+ }
+ resolver.generate(iter);
+ log.debug("----end space resolution.");
}
/**
Modified: xmlgraphics/fop/branches/Temp_Interleaved_Page_Line_Breaking/src/java/org/apache/fop/layoutmgr/inline/ContentLayoutManager.java
URL: http://svn.apache.org/viewvc/xmlgraphics/fop/branches/Temp_Interleaved_Page_Line_Breaking/src/java/org/apache/fop/layoutmgr/inline/ContentLayoutManager.java?rev=579095&r1=579094&r2=579095&view=diff
==============================================================================
--- xmlgraphics/fop/branches/Temp_Interleaved_Page_Line_Breaking/src/java/org/apache/fop/layoutmgr/inline/ContentLayoutManager.java (original)
+++ xmlgraphics/fop/branches/Temp_Interleaved_Page_Line_Breaking/src/java/org/apache/fop/layoutmgr/inline/ContentLayoutManager.java Mon Sep 24 23:53:44 2007
@@ -19,9 +19,19 @@
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;
+
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.apache.fop.apps.FOUserAgent;
+import org.apache.fop.area.Area;
+import org.apache.fop.area.Block;
+import org.apache.fop.area.LineArea;
+import org.apache.fop.area.inline.InlineArea;
import org.apache.fop.fo.Constants;
import org.apache.fop.fo.pagination.Title;
import org.apache.fop.layoutmgr.AbstractBaseLayoutManager;
@@ -34,19 +44,8 @@
import org.apache.fop.layoutmgr.Position;
import org.apache.fop.layoutmgr.PositionIterator;
import org.apache.fop.layoutmgr.SpaceSpecifier;
-import org.apache.fop.area.Area;
-import org.apache.fop.area.LineArea;
-import org.apache.fop.area.inline.InlineArea;
-
-import java.util.LinkedList;
-import java.util.List;
-import java.util.ListIterator;
-import java.util.ArrayList;
-import java.util.Iterator;
import org.apache.fop.traits.MinOptMax;
-import org.apache.fop.area.Block;
-
/**
* Content Layout Manager.
* For use with objects that contain inline areas such as
@@ -373,6 +372,14 @@
* @see org.apache.fop.layoutmgr.LayoutManager#notifyPos(org.apache.fop.layoutmgr.Position)
*/
public Position notifyPos(Position pos) {
+ return pos;
+ }
+
+ /**
+ * not quite applicable to this LM; just return the first argument
+ * @see org.apache.fop.layoutmgr.LayoutManager#rewrapPosition(org.apache.fop.layoutmgr.Position, org.apache.fop.layoutmgr.LeafPosition)
+ */
+ public Position rewrapPosition(Position pos, Position basePos) {
return pos;
}
Added: xmlgraphics/fop/branches/Temp_Interleaved_Page_Line_Breaking/src/java/org/apache/fop/layoutmgr/inline/KnuthParagraph.java
URL: http://svn.apache.org/viewvc/xmlgraphics/fop/branches/Temp_Interleaved_Page_Line_Breaking/src/java/org/apache/fop/layoutmgr/inline/KnuthParagraph.java?rev=579095&view=auto
==============================================================================
--- xmlgraphics/fop/branches/Temp_Interleaved_Page_Line_Breaking/src/java/org/apache/fop/layoutmgr/inline/KnuthParagraph.java (added)
+++ xmlgraphics/fop/branches/Temp_Interleaved_Page_Line_Breaking/src/java/org/apache/fop/layoutmgr/inline/KnuthParagraph.java Mon Sep 24 23:53:44 2007
@@ -0,0 +1,185 @@
+/*
+ * Copyright 2007 The Apache Software Foundation.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+/* $Id$ */
+
+package org.apache.fop.layoutmgr.inline;
+
+import org.apache.fop.layoutmgr.InlineKnuthSequence;
+import org.apache.fop.layoutmgr.KnuthElement;
+import org.apache.fop.layoutmgr.KnuthGlue;
+import org.apache.fop.layoutmgr.KnuthPenalty;
+import org.apache.fop.layoutmgr.KnuthSequence;
+import org.apache.fop.traits.MinOptMax;
+import org.apache.fop.fo.Constants;
+
+/**
+ * This class represents the Knuth representation of a paragraph
+ */
+public class KnuthParagraph extends InlineKnuthSequence {
+
+ private LineLayoutManager lineLM;
+
+ /** Number of elements to ignore at the beginning of the list. */
+ private int ignoreAtStart = 0;
+ /** Number of elements to ignore at the end of the list. */
+ private int ignoreAtEnd = 0;
+
+ // space at the end of the last line (in millipoints)
+ private MinOptMax lineFiller;
+ public int textAlignment;
+ public int textAlignmentLast;
+ // textIndent is 0 if the first line of this paragraph should not be indented
+ // i.e. if it is not the first paragraph of a Block
+ public int textIndent;
+ public int lastLineEndIndent;
+ public int lineWidth;
+ public int maxFlaggedPenaltiesCount;
+ private LineLayoutPossibilities llPoss;
+
+ public KnuthParagraph(int alignment, int alignmentLast, int indent, int endIndent,
+ int maxFlaggedPenaltiesCount, LineLayoutManager lineLM) {
+ super();
+ textAlignment = alignment;
+ textAlignmentLast = alignmentLast;
+ textIndent = indent;
+ lastLineEndIndent = endIndent;
+ this.maxFlaggedPenaltiesCount = maxFlaggedPenaltiesCount;
+ this.lineLM = lineLM;
+ }
+
+ /**
+ * @return the lineFiller
+ */
+ public MinOptMax getLineFiller() {
+ return lineFiller;
+ }
+
+ /**
+ * @return the ignoreAtEnd
+ */
+ public int getIgnoreAtEnd() {
+ return ignoreAtEnd;
+ }
+
+ /**
+ * @return the ignoreAtStart
+ */
+ public int getIgnoreAtStart() {
+ return ignoreAtStart;
+ }
+
+ /**
+ * @return the lineLM
+ */
+ public LineLayoutManager getLineLayoutManager() {
+ return lineLM;
+ }
+
+
+ /**
+ * @return the llPoss
+ */
+ public LineLayoutPossibilities getLlPoss() {
+ return llPoss;
+ }
+
+
+ /**
+ * @param llPoss the llPoss to set
+ */
+ public void setLlPoss(LineLayoutPossibilities llPos) {
+ this.llPoss = llPos;
+ }
+
+ public void startParagraph(int lw) {
+ // this is an early value of the linewidth;
+ // it is used as the max value of the lineFiller
+ lineWidth = lw;
+ startSequence();
+ }
+
+ public void startSequence() {
+ // set the minimum amount of empty space at the end of the
+ // last line
+ if (textAlignment == Constants.EN_CENTER) {
+ lineFiller = new MinOptMax(lastLineEndIndent);
+ } else {
+ lineFiller = new MinOptMax(lastLineEndIndent, lastLineEndIndent, lineWidth);
+ }
+
+ // add auxiliary elements at the beginning of the paragraph
+ if (textAlignment == Constants.EN_CENTER && textAlignmentLast != Constants.EN_JUSTIFY) {
+ this.add(new KnuthGlue(0, 3 * LineLayoutManager.DEFAULT_SPACE_WIDTH, 0,
+ null, false));
+ ignoreAtStart++;
+ }
+
+ // add the element representing text indentation
+ // at the beginning of the first paragraph
+ if (textIndent != 0) {
+ this.add(new KnuthInlineBox(textIndent, null, null, false));
+ ignoreAtStart++;
+ }
+ }
+
+ public KnuthSequence endSequence() {
+ if (this.size() > ignoreAtStart) {
+ if (textAlignment == Constants.EN_CENTER
+ && textAlignmentLast != Constants.EN_JUSTIFY) {
+ this.add(new KnuthGlue(0, 3 * LineLayoutManager.DEFAULT_SPACE_WIDTH, 0,
+ null, false));
+ this.add(new KnuthPenalty(lineFiller.opt, -KnuthElement.INFINITE,
+ false, null, false));
+ ignoreAtEnd = 2;
+ } else if (textAlignmentLast != Constants.EN_JUSTIFY) {
+ // add the elements representing the space
+ // at the end of the last line
+ // and the forced break
+ this.add(new KnuthPenalty(0, KnuthElement.INFINITE,
+ false, null, false));
+ this.add(new KnuthGlue(0,
+ lineFiller.max - lineFiller.opt,
+ lineFiller.opt - lineFiller.min, null, false));
+ this.add(new KnuthPenalty(lineFiller.opt, -KnuthElement.INFINITE,
+ false, null, false));
+ ignoreAtEnd = 3;
+ } else {
+ // add only the element representing the forced break
+ this.add(new KnuthPenalty(lineFiller.opt, -KnuthElement.INFINITE,
+ false, null, false));
+ ignoreAtEnd = 1;
+ }
+ return this;
+ } else {
+ this.clear();
+ return null;
+ }
+ }
+
+ /**
+ * @return true if the sequence contains a box
+ */
+ public boolean containsBox() {
+ for (int i = 0; i < this.size(); i++) {
+ KnuthElement el = (KnuthElement) this.get(i);
+ if (el.isBox()) {
+ return true;
+ }
+ }
+ return false;
+ }
+}
Propchange: xmlgraphics/fop/branches/Temp_Interleaved_Page_Line_Breaking/src/java/org/apache/fop/layoutmgr/inline/KnuthParagraph.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: xmlgraphics/fop/branches/Temp_Interleaved_Page_Line_Breaking/src/java/org/apache/fop/layoutmgr/inline/KnuthParagraph.java
------------------------------------------------------------------------------
svn:keywords = Id
---------------------------------------------------------------------
To unsubscribe, e-mail: fop-commits-unsubscribe@xmlgraphics.apache.org
For additional commands, e-mail: fop-commits-help@xmlgraphics.apache.org