fop 0.92beta

org.apache.fop.layoutmgr
Class BreakingAlgorithm

java.lang.Object
  |
  +--org.apache.fop.layoutmgr.BreakingAlgorithm
Direct Known Subclasses:
org.apache.fop.layoutmgr.PageBreakingAlgorithm

public abstract class BreakingAlgorithm
extends java.lang.Object

The set of nodes is sorted into lines indexed into activeLines. The nodes in each line are linked together in a single linked list by the KnuthNode.next field. The activeLines array contains a link to the head of the linked list in index 'line*2' and a link to the tail at index 'line*2+1'.

The set of active nodes can be traversed by

 for (int line = startLine; line < endLine; line++) {
     for (KnuthNode node = getNode(line); node != null; node = node.next) {
         // Do something with 'node'
     }
 }
 


Inner Class Summary
protected  class BreakingAlgorithm.BestRecords
           
 class BreakingAlgorithm.KnuthNode
           
 
Field Summary
protected  BreakingAlgorithm.KnuthNode[] activeLines
          The set of active nodes.
protected  int activeNodeCount
          The number of active nodes.
protected  int alignment
           
protected  int alignmentLast
           
static int ALL_BREAKS
           
protected  BreakingAlgorithm.BestRecords best
           
protected  boolean bFirst
           
protected  boolean considerTooShort
          If set to true, doesn't ignore break possibilities which are definitely too short.
protected  int endLine
          The highest + 1 available line in the set of active nodes.
protected  int incompatibleFitnessDemerit
           
protected static int INFINITE_RATIO
           
protected  BreakingAlgorithm.KnuthNode lastDeactivatedNode
           
protected  int lineWidth
          The width of a line (or height of a column in page-breaking mode).
protected static org.apache.commons.logging.Log log
          the logger
protected  int maxFlaggedPenaltiesCount
           
static int NO_FLAGGED_PENALTIES
           
static int ONLY_FORCED_BREAKS
           
protected  KnuthSequence par
          The paragraph of KnuthElements.
protected  int repeatedFlaggedDemerit
           
protected  int startLine
          The lowest available line in the set of active nodes.
protected  int totalShrink
          The total shrink of all elements handled so far.
protected  int totalStretch
          The total stretch of all elements handled so far.
protected  int totalWidth
          The total width of all elements handled so far.
 
Constructor Summary
BreakingAlgorithm(int align, int alignLast, boolean first, boolean partOverflowRecovery, int maxFlagCount)
           
 
Method Summary
protected  void addNode(int line, BreakingAlgorithm.KnuthNode node)
          Add a KnuthNode at the end of line 'line'.
protected  BreakingAlgorithm.KnuthNode compareNodes(BreakingAlgorithm.KnuthNode node1, BreakingAlgorithm.KnuthNode node2)
          Compare two KnuthNodes and return the node with the least demerit.
protected  double computeAdjustmentRatio(BreakingAlgorithm.KnuthNode activeNode, int difference)
          Return the adjust ration needed to make up for the difference.
protected  double computeDemerits(BreakingAlgorithm.KnuthNode activeNode, KnuthElement element, int fitnessClass, double r)
           
protected  int computeDifference(BreakingAlgorithm.KnuthNode activeNode, KnuthElement element, int elementIndex)
          Return the difference between the line width and the width of the break that ends in 'element'.
protected  void considerLegalBreak(KnuthElement element, int elementIdx)
           
protected  BreakingAlgorithm.KnuthNode createNode(int position, int line, int fitness, int totalWidth, int totalStretch, int totalShrink)
           
protected  BreakingAlgorithm.KnuthNode createNode(int position, int line, int fitness, int totalWidth, int totalStretch, int totalShrink, double adjustRatio, int availableShrink, int availableStretch, int difference, double totalDemerits, BreakingAlgorithm.KnuthNode previous)
           
protected abstract  int filterActiveNodes()
           
 int findBreakingPoints(KnuthSequence par, double threshold, boolean force, int allowedBreaks)
           
 int findBreakingPoints(KnuthSequence par, int startIndex, double threshold, boolean force, int allowedBreaks)
           
protected  void finish()
           
 double getAdjustRatio(int line)
           
 int getAlignment()
           
 int getAlignmentLast()
           
 int getDifference(int line)
           
protected  KnuthElement getElement(int idx)
          Return the element at index idx in the paragraph.
 int getEnd(int line)
           
protected  int getLineWidth()
           
protected  int getLineWidth(int line)
           
protected  int getMaxRecoveryAttempts()
           
protected  BreakingAlgorithm.KnuthNode getNode(int line)
           
 int getStart(int line)
           
protected  void handleBox(KnuthBox box)
           
protected  void initialize()
           
protected  boolean isPartOverflowRecoveryActivated()
          Controls the behaviour of the algorithm in cases where the first element of a part overflows a line/page.
protected  void removeNode(int line, BreakingAlgorithm.KnuthNode node)
          Remove the first node in line 'line'.
protected  int restartFrom(BreakingAlgorithm.KnuthNode restartingNode, int currentIndex)
           
 void setConstantLineWidth(int lineWidth)
           
 java.lang.String toString(java.lang.String prepend)
           
abstract  void updateData1(int total, double demerits)
           
abstract  void updateData2(BreakingAlgorithm.KnuthNode bestActiveNode, KnuthSequence sequence, int total)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

log

protected static org.apache.commons.logging.Log log
the logger

INFINITE_RATIO

protected static final int INFINITE_RATIO

ALL_BREAKS

public static final int ALL_BREAKS

NO_FLAGGED_PENALTIES

public static final int NO_FLAGGED_PENALTIES

ONLY_FORCED_BREAKS

public static final int ONLY_FORCED_BREAKS

repeatedFlaggedDemerit

protected int repeatedFlaggedDemerit

incompatibleFitnessDemerit

protected int incompatibleFitnessDemerit

maxFlaggedPenaltiesCount

protected int maxFlaggedPenaltiesCount

par

protected KnuthSequence par
The paragraph of KnuthElements.

lineWidth

protected int lineWidth
The width of a line (or height of a column in page-breaking mode). -1 indicates that the line widths are different for each line.

considerTooShort

protected boolean considerTooShort
If set to true, doesn't ignore break possibilities which are definitely too short.

lastDeactivatedNode

protected BreakingAlgorithm.KnuthNode lastDeactivatedNode

alignment

protected int alignment

alignmentLast

protected int alignmentLast

bFirst

protected boolean bFirst

activeLines

protected BreakingAlgorithm.KnuthNode[] activeLines
The set of active nodes.

activeNodeCount

protected int activeNodeCount
The number of active nodes.

startLine

protected int startLine
The lowest available line in the set of active nodes.

endLine

protected int endLine
The highest + 1 available line in the set of active nodes.

totalWidth

protected int totalWidth
The total width of all elements handled so far.

totalStretch

protected int totalStretch
The total stretch of all elements handled so far.

totalShrink

protected int totalShrink
The total shrink of all elements handled so far.

best

protected BreakingAlgorithm.BestRecords best
Constructor Detail

BreakingAlgorithm

public BreakingAlgorithm(int align,
                         int alignLast,
                         boolean first,
                         boolean partOverflowRecovery,
                         int maxFlagCount)
Method Detail

getMaxRecoveryAttempts

protected int getMaxRecoveryAttempts()
Returns:
the number of times the algorithm should try to move overflowing content to the next line/page.

isPartOverflowRecoveryActivated

protected boolean isPartOverflowRecoveryActivated()
Controls the behaviour of the algorithm in cases where the first element of a part overflows a line/page.
Returns:
true if the algorithm should try to send the element to the next line/page.

updateData1

public abstract void updateData1(int total,
                                 double demerits)

updateData2

public abstract void updateData2(BreakingAlgorithm.KnuthNode bestActiveNode,
                                 KnuthSequence sequence,
                                 int total)

setConstantLineWidth

public void setConstantLineWidth(int lineWidth)

findBreakingPoints

public int findBreakingPoints(KnuthSequence par,
                              double threshold,
                              boolean force,
                              int allowedBreaks)

findBreakingPoints

public int findBreakingPoints(KnuthSequence par,
                              int startIndex,
                              double threshold,
                              boolean force,
                              int allowedBreaks)

initialize

protected void initialize()

createNode

protected BreakingAlgorithm.KnuthNode createNode(int position,
                                                 int line,
                                                 int fitness,
                                                 int totalWidth,
                                                 int totalStretch,
                                                 int totalShrink,
                                                 double adjustRatio,
                                                 int availableShrink,
                                                 int availableStretch,
                                                 int difference,
                                                 double totalDemerits,
                                                 BreakingAlgorithm.KnuthNode previous)

createNode

protected BreakingAlgorithm.KnuthNode createNode(int position,
                                                 int line,
                                                 int fitness,
                                                 int totalWidth,
                                                 int totalStretch,
                                                 int totalShrink)

handleBox

protected void handleBox(KnuthBox box)

restartFrom

protected int restartFrom(BreakingAlgorithm.KnuthNode restartingNode,
                          int currentIndex)

considerLegalBreak

protected void considerLegalBreak(KnuthElement element,
                                  int elementIdx)

computeDifference

protected int computeDifference(BreakingAlgorithm.KnuthNode activeNode,
                                KnuthElement element,
                                int elementIndex)
Return the difference between the line width and the width of the break that ends in 'element'.
Parameters:
activeNode -  
element -  
Returns:
The difference in width. Positive numbers mean extra space in the line, negative number that the line overflows.

computeAdjustmentRatio

protected double computeAdjustmentRatio(BreakingAlgorithm.KnuthNode activeNode,
                                        int difference)
Return the adjust ration needed to make up for the difference. A ration of
Parameters:
activeNode -  
difference -  
Returns:
The ration.

computeDemerits

protected double computeDemerits(BreakingAlgorithm.KnuthNode activeNode,
                                 KnuthElement element,
                                 int fitnessClass,
                                 double r)

finish

protected void finish()

getElement

protected KnuthElement getElement(int idx)
Return the element at index idx in the paragraph.
Parameters:
idx - index of the element.
Returns:
the element at index idx in the paragraph.

compareNodes

protected BreakingAlgorithm.KnuthNode compareNodes(BreakingAlgorithm.KnuthNode node1,
                                                   BreakingAlgorithm.KnuthNode node2)
Compare two KnuthNodes and return the node with the least demerit.
Parameters:
node1 - The first knuth node.
node2 - The other knuth node.
Returns:
the node with the least demerit.

addNode

protected void addNode(int line,
                       BreakingAlgorithm.KnuthNode node)
Add a KnuthNode at the end of line 'line'. If this is the first node in the line, adjust endLine accordingly.
Parameters:
line -  
node -  

removeNode

protected void removeNode(int line,
                          BreakingAlgorithm.KnuthNode node)
Remove the first node in line 'line'. If the line then becomes empty, adjust the startLine accordingly.
Parameters:
line -  
node -  

getNode

protected BreakingAlgorithm.KnuthNode getNode(int line)

getDifference

public int getDifference(int line)

getAdjustRatio

public double getAdjustRatio(int line)

getStart

public int getStart(int line)

getEnd

public int getEnd(int line)

getLineWidth

protected int getLineWidth(int line)

getLineWidth

protected int getLineWidth()

toString

public java.lang.String toString(java.lang.String prepend)

filterActiveNodes

protected abstract int filterActiveNodes()

getAlignment

public int getAlignment()
Returns:
the alignment for normal lines/parts

getAlignmentLast

public int getAlignmentLast()
Returns:
the alignment for the last line/part

fop 0.92beta

Copyright 1999-2006 The Apache Software Foundation. All Rights Reserved.