fop 0.95

org.apache.fop.layoutmgr
Class BalancingColumnBreakingAlgorithm

java.lang.Object
  extended by org.apache.fop.layoutmgr.BreakingAlgorithm
      extended by org.apache.fop.layoutmgr.BalancingColumnBreakingAlgorithm

public class BalancingColumnBreakingAlgorithm
extends BreakingAlgorithm

This is a the breaking algorithm that is responsible for balancing columns in multi-column layout.


Nested Class Summary
static interface PageBreakingAlgorithm.PageBreakingLayoutListener
          Interface to notify about layout events during page breaking.
 
Nested classes/interfaces inherited from class org.apache.fop.layoutmgr.BreakingAlgorithm
BreakingAlgorithm.BestRecords, BreakingAlgorithm.KnuthNode
 
Field Summary
 
Fields inherited from class org.apache.fop.layoutmgr.BreakingAlgorithm
activeLines, activeNodeCount, alignment, alignmentLast, ALL_BREAKS, best, bFirst, considerTooShort, endLine, incompatibleFitnessDemerit, INFINITE_RATIO, lineWidth, maxFlaggedPenaltiesCount, NO_FLAGGED_PENALTIES, ONLY_FORCED_BREAKS, par, repeatedFlaggedDemerit, startLine, totalShrink, totalStretch, totalWidth
 
Constructor Summary
BalancingColumnBreakingAlgorithm(LayoutManager topLevelLM, PageProvider pageProvider, PageBreakingAlgorithm.PageBreakingLayoutListener layoutListener, int alignment, int alignmentLast, MinOptMax footnoteSeparatorLength, boolean partOverflowRecovery, int columnCount)
           
 
Method Summary
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)
          Computes the demerits of the current breaking (that is, up to the given element), if the next-to-last chosen breakpoint is the given active node.
protected  int computeDifference(BreakingAlgorithm.KnuthNode activeNode, KnuthElement element, int elementIndex)
          Return the difference between the natural width of a line that would be made between the given active node and the given element, and the available width of the real line.
protected  void considerLegalBreak(KnuthElement element, int elementIdx)
          Determines if the given breakpoint is a feasible breakpoint.
protected  BreakingAlgorithm.KnuthNode createNode(int position, int line, int fitness, int totalWidth, int totalStretch, int totalShrink)
          Creates a new active node for a break from the best active node of the given fitness class to the element at the given position.
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)
          Creates a new active node for a feasible breakpoint at the given position.
protected  int filterActiveNodes()
           
protected  void finish()
           
 FObj getFObj()
           
 java.util.LinkedList getFootnoteList(int index)
           
protected  int getLineWidth(int line)
          Returns the line/part width of a given line/part.
 java.util.LinkedList getPageBreaks()
           
protected  void handleBox(KnuthBox box)
          Page-breaking specific handling of the given box.
protected  void initialize()
          Resets the algorithm's variables.
 void insertPageBreakAsFirst(AbstractBreaker.PageBreakPosition pageBreak)
           
 void removeAllPageBreaks()
          Removes all page breaks from the result list.
protected  int restartFrom(BreakingAlgorithm.KnuthNode restartingNode, int currentIndex)
           
 void updateData1(int total, double demerits)
          Empty method, hook for subclasses.
 void updateData2(BreakingAlgorithm.KnuthNode bestActiveNode, KnuthSequence sequence, int total)
          Empty method, hook for subclasses.
 
Methods inherited from class org.apache.fop.layoutmgr.BreakingAlgorithm
addNode, compareNodes, findBreakingPoints, findBreakingPoints, getAlignment, getAlignmentLast, getElement, getLineWidth, getMaxRecoveryAttempts, getNode, isPartOverflowRecoveryActivated, removeNode, setConstantLineWidth, toString
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

BalancingColumnBreakingAlgorithm

public BalancingColumnBreakingAlgorithm(LayoutManager topLevelLM,
                                        PageProvider pageProvider,
                                        PageBreakingAlgorithm.PageBreakingLayoutListener layoutListener,
                                        int alignment,
                                        int alignmentLast,
                                        MinOptMax footnoteSeparatorLength,
                                        boolean partOverflowRecovery,
                                        int columnCount)
Method Detail

computeDemerits

protected double computeDemerits(BreakingAlgorithm.KnuthNode activeNode,
                                 KnuthElement element,
                                 int fitnessClass,
                                 double r)
Computes the demerits of the current breaking (that is, up to the given element), if the next-to-last chosen breakpoint is the given active node. This adds to the total demerits of the given active node, the demerits of a line starting at this node and ending at the given element.

Parameters:
activeNode - considered preceding line break
element - considered current line break
fitnessClass - fitness of the current line
r - adjustment ratio for the current line
Returns:
the demerit of the current line

initialize

protected void initialize()
Description copied from class: BreakingAlgorithm
Resets the algorithm's variables.

Overrides:
initialize in class BreakingAlgorithm

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)
Description copied from class: BreakingAlgorithm
Creates a new active node for a feasible breakpoint at the given position. Only called in forced mode.

Overrides:
createNode in class BreakingAlgorithm
Parameters:
position - index of the element in the Knuth sequence
line - number of the line ending at the breakpoint
fitness - fitness class of the line ending at the breakpoint. One of 0, 1, 2, 3.
totalWidth - accumulated width of the KnuthElements up to after the breakpoint
totalStretch - accumulated stretchability of the KnuthElements up to after the breakpoint
totalShrink - accumulated shrinkability of the KnuthElements up to after the breakpoint
adjustRatio - adjustment ratio if the line ends at this breakpoint
availableShrink - available stretch of the line ending at this breakpoint
availableStretch - available shrink of the line ending at this breakpoint
difference - difference between target and actual line width
totalDemerits - minimum total demerits up to the breakpoint
previous - active node for the preceding breakpoint

createNode

protected BreakingAlgorithm.KnuthNode createNode(int position,
                                                 int line,
                                                 int fitness,
                                                 int totalWidth,
                                                 int totalStretch,
                                                 int totalShrink)
Description copied from class: BreakingAlgorithm
Creates a new active node for a break from the best active node of the given fitness class to the element at the given position.

Overrides:
createNode in class BreakingAlgorithm
See Also:
BreakingAlgorithm.createNode(int, int, int, int, int, int, double, int, int, int, double, org.apache.fop.layoutmgr.BreakingAlgorithm.KnuthNode), BreakingAlgorithm.BestRecords

handleBox

protected void handleBox(KnuthBox box)
Page-breaking specific handling of the given box. Currently it adds the footnotes cited in the given box to the list of to-be-handled footnotes.

Overrides:
handleBox in class BreakingAlgorithm
Parameters:
box - a block-level element possibly containing foonotes citations

restartFrom

protected int restartFrom(BreakingAlgorithm.KnuthNode restartingNode,
                          int currentIndex)
Overrides:
restartFrom in class BreakingAlgorithm

considerLegalBreak

protected void considerLegalBreak(KnuthElement element,
                                  int elementIdx)
Description copied from class: BreakingAlgorithm
Determines if the given breakpoint is a feasible breakpoint. That is, if a decent line may be built between one of the currently active nodes and this breakpoint.

Overrides:
considerLegalBreak in class BreakingAlgorithm
Parameters:
element - the paragraph's element to consider
elementIdx - the element's index inside the paragraph

computeDifference

protected int computeDifference(BreakingAlgorithm.KnuthNode activeNode,
                                KnuthElement element,
                                int elementIndex)
Description copied from class: BreakingAlgorithm
Return the difference between the natural width of a line that would be made between the given active node and the given element, and the available width of the real line.

Overrides:
computeDifference in class BreakingAlgorithm
Parameters:
activeNode - node for the previous breakpoint
element - currently considered breakpoint
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)
Description copied from class: BreakingAlgorithm
Return the adjust ration needed to make up for the difference. A ration of

Overrides:
computeAdjustmentRatio in class BreakingAlgorithm
Returns:
The ration.

finish

protected void finish()
Overrides:
finish in class BreakingAlgorithm

getPageBreaks

public java.util.LinkedList getPageBreaks()
Returns:
a list of PageBreakPosition elements

insertPageBreakAsFirst

public void insertPageBreakAsFirst(AbstractBreaker.PageBreakPosition pageBreak)

removeAllPageBreaks

public void removeAllPageBreaks()
Removes all page breaks from the result list. This is used by block-containers and static-content when it is only desired to know where there is an overflow but later the whole content should be painted as one part.


updateData1

public void updateData1(int total,
                        double demerits)
Description copied from class: BreakingAlgorithm
Empty method, hook for subclasses. Called before determining the optimal breakpoints corresponding to a given active node.

Specified by:
updateData1 in class BreakingAlgorithm
Parameters:
total - number of lines for the active node
demerits - total demerits of the paragraph for the active node

updateData2

public void updateData2(BreakingAlgorithm.KnuthNode bestActiveNode,
                        KnuthSequence sequence,
                        int total)
Description copied from class: BreakingAlgorithm
Empty method, hook for subclasses. Called when determining the optimal breakpoints for a given active node.

Specified by:
updateData2 in class BreakingAlgorithm
Parameters:
bestActiveNode - a node in the chain of best active nodes, corresponding to one of the optimal breakpoints
sequence - the corresponding paragraph
total - the number of lines into which the paragraph will be broken
See Also:
BreakingAlgorithm.calculateBreakPoints(KnuthNode, KnuthSequence, int)

filterActiveNodes

protected int filterActiveNodes()
Specified by:
filterActiveNodes in class BreakingAlgorithm

getFootnoteList

public java.util.LinkedList getFootnoteList(int index)

getFObj

public FObj getFObj()
Returns:
the associated top-level formatting object.

getLineWidth

protected int getLineWidth(int line)
Returns the line/part width of a given line/part.

Overrides:
getLineWidth in class BreakingAlgorithm
Parameters:
line - the line/part number
Returns:
the width/length in millipoints

fop 0.95

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