Browse Source

Some cleanups and attempts at improving code-readability and -extensibility:

* added inner holder class to BreakingAlgorithm to contain everything related to the fitness classes. Improves readability of both the code and the trace messages.
* extracted blocks of code in BreakingAlgorithm.findBreakingPoints() into protected methods. Following the already existing handleBox(), added handleGlueAt() and handlePenaltyAt() to provide extension points to subclasses. Extraction of the code-blocks related to the node-recovery mechanism.
* extracted blocks of code in BreakingAlgorithm.considerLegalBreak() into protected methods: deactivateNode(), activateNode() and forceNode()
* factored the functionality to obtain the index of the first box into KnuthSequence... just seemed to make sense; may be useful elsewhere.
* some (but not all :() javadoc fixups
* minor changes to LineLayoutManager and PageBreakingAlgorithm to take into account above changes

git-svn-id: https://svn.apache.org/repos/asf/xmlgraphics/fop/trunk@790142 13f79535-47bb-0310-9956-ffa450edef68
pull/37/head
Andreas L. Delmelle 15 years ago
parent
commit
6261edf5b6

+ 467
- 278
src/java/org/apache/fop/layoutmgr/BreakingAlgorithm.java
File diff suppressed because it is too large
View File


+ 52
- 14
src/java/org/apache/fop/layoutmgr/KnuthSequence.java View File

@@ -19,6 +19,8 @@

package org.apache.fop.layoutmgr;

import org.apache.fop.util.ListUtil;

import java.util.ArrayList;
import java.util.List;
import java.util.ListIterator;
@@ -26,9 +28,6 @@ import java.util.ListIterator;
/**
* Represents a list of Knuth elements.
*/
/**
*
*/
public abstract class KnuthSequence extends ArrayList {
/**
* Creates a new and empty list.
@@ -132,11 +131,9 @@ public abstract class KnuthSequence extends ArrayList {
* @return the last element of this sequence.
*/
public ListElement getLast() {
int idx = size();
if (idx == 0) {
return null;
}
return (ListElement) get(idx - 1);
return (isEmpty()
? null
: (ListElement) ListUtil.getLast(this));
}

/**
@@ -144,11 +141,9 @@ public abstract class KnuthSequence extends ArrayList {
* @return the removed element.
*/
public ListElement removeLast() {
int idx = size();
if (idx == 0) {
return null;
}
return (ListElement) remove(idx - 1);
return (isEmpty()
? null
: (ListElement) ListUtil.removeLast(this));
}

/**
@@ -156,7 +151,45 @@ public abstract class KnuthSequence extends ArrayList {
* @return the element at index index.
*/
public ListElement getElement(int index) {
return (ListElement) get(index);
return (index >= size() || index < 0)
? null
: (ListElement) get(index);
}

/** @return the position index of the first box in this sequence */
protected int getFirstBoxIndex() {
if (isEmpty()) {
return -1;
} else {
return getFirstBoxIndex(0);
}
}

/**
* Get the position index of the first box in this sequence,
* starting at the given index. If there is no box after the
* passed {@code startIndex}, the starting index itself is returned.
* @param startIndex the starting index for the lookup
* @return the absolute position index of the next box element
*/
protected int getFirstBoxIndex(int startIndex) {
if (isEmpty() || startIndex < 0 || startIndex >= size()) {
return -1;
} else {
ListElement element = null;
int posIndex = startIndex;
int lastIndex = size();
while (posIndex < lastIndex
&& !(element = getElement(posIndex)).isBox()) {
posIndex++;
}
if (posIndex != startIndex
&& element.isBox()) {
return posIndex - 1;
} else {
return startIndex;
}
}
}

/**
@@ -165,4 +198,9 @@ public abstract class KnuthSequence extends ArrayList {
*/
public abstract boolean isInlineSequence();

/** {@inheritDoc} */
public String toString() {
return "<KnuthSequence " + super.toString() + ">";
}

}

+ 1
- 0
src/java/org/apache/fop/layoutmgr/PageBreakingAlgorithm.java View File

@@ -214,6 +214,7 @@ class PageBreakingAlgorithm extends BreakingAlgorithm {
* @param box a block-level element possibly containing foonotes citations
*/
protected void handleBox(KnuthBox box) {
super.handleBox(box);
if (box instanceof KnuthBlockBox
&& ((KnuthBlockBox) box).hasAnchors()) {
handleFootnotes(((KnuthBlockBox) box).getElementLists());

+ 1
- 1
src/java/org/apache/fop/layoutmgr/inline/LineLayoutManager.java View File

@@ -362,7 +362,7 @@ public class LineLayoutManager extends InlineStackingLayoutManager
int textAlign = (bestActiveNode.line < total) ? alignment : alignmentLast;
indent += (textAlign == Constants.EN_CENTER)
? difference / 2 : (textAlign == Constants.EN_END) ? difference : 0;
indent += (bestActiveNode.line == 1 && bFirst && isFirstInBlock) ? textIndent : 0;
indent += (bestActiveNode.line == 1 && indentFirstPart && isFirstInBlock) ? textIndent : 0;
double ratio = (textAlign == Constants.EN_JUSTIFY
|| difference < 0 && -difference <= bestActiveNode.availableShrink)
? bestActiveNode.adjustRatio : 0;

Loading…
Cancel
Save