public class BalancingColumnBreakingAlgorithm extends BreakingAlgorithm
Modifier and Type | Class and Description |
---|---|
static interface |
PageBreakingAlgorithm.PageBreakingLayoutListener
Interface to notify about layout events during page breaking.
|
BreakingAlgorithm.BestRecords, BreakingAlgorithm.KnuthNode
activeLines, activeNodeCount, alignment, alignmentLast, ALL_BREAKS, best, considerTooShort, endLine, incompatibleFitnessDemerit, indentFirstPart, INFINITE_RATIO, lineWidth, maxFlaggedPenaltiesCount, NO_FLAGGED_PENALTIES, ONLY_FORCED_BREAKS, par, repeatedFlaggedDemerit, startLine, totalShrink, totalStretch, totalWidth
Constructor and Description |
---|
BalancingColumnBreakingAlgorithm(LayoutManager topLevelLM,
PageProvider pageProvider,
PageBreakingAlgorithm.PageBreakingLayoutListener layoutListener,
int alignment,
int alignmentLast,
MinOptMax footnoteSeparatorLength,
boolean partOverflowRecovery,
int columnCount)
Construct a balancing column breaking algorithm.
|
Modifier and Type | Method and Description |
---|---|
protected void |
addNode(int line,
BreakingAlgorithm.KnuthNode node)
Add a node at the end of the given line's existing active nodes.
|
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 adjustment ratio 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 boolean |
elementCanEndLine(KnuthElement element,
int line,
int difference)
Check if the given
KnuthElement can end the line with the given
number. |
protected int |
filterActiveNodes()
Filter active nodes.
|
protected void |
finish()
Hook for subclasses to trigger special behavior after ending the
main loop in
BreakingAlgorithm.findBreakingPoints(KnuthSequence,int,double,boolean,int) |
FObj |
getFObj() |
protected java.util.List<KnuthElement> |
getFootnoteList(int index)
Obtain the element-list corresponding to the footnote at the given index.
|
protected int |
getIPDdifference()
obtain ipd difference
|
protected int |
getLineWidth(int line)
Returns the line/part width of a given line/part.
|
java.util.LinkedList<AbstractBreaker.PageBreakPosition> |
getPageBreaks() |
protected void |
handleBox(KnuthBox box)
Page-breaking specific handling of the given box.
|
protected int |
handleIpdChange()
handle ipd change
|
protected void |
handlePenaltyAt(KnuthPenalty penalty,
int position,
int allowedBreaks)
Overridden to consider penalties with value
KnuthElement.INFINITE
as legal break-points, if the current keep-context allows this
(a keep-*.within-page="always" constraint still permits column-breaks)
Handle a KnuthPenalty at the given position,
taking into account the type of breaks allowed. |
protected void |
initialize()
Initializes the algorithm's variables.
|
void |
insertPageBreakAsFirst(AbstractBreaker.PageBreakPosition pageBreak)
Insert the given
AbstractBreaker.PageBreakPosition as the first
element in the list of page-breaks |
protected BreakingAlgorithm.KnuthNode |
recoverFromTooLong(BreakingAlgorithm.KnuthNode lastTooLong)
Overridden to defer a part to the next page, if it
must be kept within one page, but is too large to fit in
the last column.
|
void |
removeAllPageBreaks()
Removes all page breaks from the result list.
|
protected int |
restartFrom(BreakingAlgorithm.KnuthNode restartingNode,
int currentIndex)
Restart from the given node at the given index.
|
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.
|
activateNode, calculateBreakPoints, deactivateNode, findBreakingPoints, findBreakingPoints, forceNode, getAlignment, getAlignmentLast, getElement, getLastTooShort, getLineWidth, getMaxRecoveryAttempts, getNode, handleElementAt, handleGlueAt, isPartOverflowRecoveryActivated, recoverFromOverflow, removeNode, replaceLastDeactivated, setConstantLineWidth, toString
public BalancingColumnBreakingAlgorithm(LayoutManager topLevelLM, PageProvider pageProvider, PageBreakingAlgorithm.PageBreakingLayoutListener layoutListener, int alignment, int alignmentLast, MinOptMax footnoteSeparatorLength, boolean partOverflowRecovery, int columnCount)
topLevelLM
- the top level layout managerpageProvider
- the page providerlayoutListener
- the layout listeneralignment
- alignment of the paragraph/page. One of
Constants.EN_START
,
Constants.EN_JUSTIFY
,
Constants.EN_CENTER
,
Constants.EN_END
.
For pages, Constants.EN_BEFORE
and
Constants.EN_AFTER
are mapped to the corresponding inline properties,
Constants.EN_START
and
Constants.EN_END
.alignmentLast
- alignment of the paragraph's last linefootnoteSeparatorLength
- length of footnote separatorpartOverflowRecovery
- true
if too long elements should be moved to
the next line/partcolumnCount
- number of columnsPageBreakingAlgorithm
protected double computeDemerits(BreakingAlgorithm.KnuthNode activeNode, KnuthElement element, int fitnessClass, double r)
activeNode
- considered preceding line breakelement
- considered current line breakfitnessClass
- fitness of the current liner
- adjustment ratio for the current lineprotected void initialize()
initialize
in class BreakingAlgorithm
protected BreakingAlgorithm.KnuthNode recoverFromTooLong(BreakingAlgorithm.KnuthNode lastTooLong)
BreakingAlgorithm.KnuthNode
leading to a line that is too long.
The default implementation creates a new node corresponding to a break
point after the previous node that led to a line that was too short.recoverFromTooLong
in class BreakingAlgorithm
lastTooLong
- the node that leads to a "too long" lineprotected BreakingAlgorithm.KnuthNode compareNodes(BreakingAlgorithm.KnuthNode node1, BreakingAlgorithm.KnuthNode node2)
compareNodes
in class BreakingAlgorithm
node1
- The first knuth node.node2
- The other knuth node.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
in class BreakingAlgorithm
position
- index of the element in the Knuth sequenceline
- number of the line ending at the breakpointfitness
- 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 breakpointtotalStretch
- accumulated stretchability of the KnuthElements up to after the
breakpointtotalShrink
- accumulated shrinkability of the KnuthElements up to after the
breakpointadjustRatio
- adjustment ratio if the line ends at this breakpointavailableShrink
- available stretch of the line ending at this breakpointavailableStretch
- available shrink of the line ending at this breakpointdifference
- difference between target and actual line widthtotalDemerits
- minimum total demerits up to the breakpointprevious
- active node for the preceding breakpointprotected BreakingAlgorithm.KnuthNode createNode(int position, int line, int fitness, int totalWidth, int totalStretch, int totalShrink)
createNode
in class BreakingAlgorithm
position
- index of the element in the Knuth sequenceline
- number of the line ending at the breakpointfitness
- 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 breakpointtotalStretch
- accumulated stretchability of the KnuthElements up to after the
breakpointtotalShrink
- accumulated shrinkability of the KnuthElements up to after the
breakpointBreakingAlgorithm.createNode(int, int, int, int, int, int, double, int, int, int, double,
org.apache.fop.layoutmgr.BreakingAlgorithm.KnuthNode)
,
BreakingAlgorithm.BestRecords
protected void handleBox(KnuthBox box)
KnuthBox
.
super.handleBox(box)
to avoid unwanted side-effects.handleBox
in class BreakingAlgorithm
box
- the KnuthBox
to handleprotected void handlePenaltyAt(KnuthPenalty penalty, int position, int allowedBreaks)
KnuthElement.INFINITE
as legal break-points, if the current keep-context allows this
(a keep-*.within-page="always" constraint still permits column-breaks)
Handle a KnuthPenalty
at the given position,
taking into account the type of breaks allowed.handlePenaltyAt
in class BreakingAlgorithm
penalty
- the KnuthPenalty
to handleposition
- the position of the penalty in the listallowedBreaks
- the type of breaks that are allowedprotected int restartFrom(BreakingAlgorithm.KnuthNode restartingNode, int currentIndex)
restartFrom
in class BreakingAlgorithm
restartingNode
- the BreakingAlgorithm.KnuthNode
to restart fromcurrentIndex
- the current position indexprotected void considerLegalBreak(KnuthElement element, int elementIdx)
considerLegalBreak
in class BreakingAlgorithm
element
- the paragraph's element to considerelementIdx
- the element's index inside the paragraphprotected boolean elementCanEndLine(KnuthElement element, int line, int difference)
KnuthElement
can end the line with the given
number.elementCanEndLine
in class BreakingAlgorithm
element
- the elementline
- the line numberdifference
- an integertrue
if the element can end the lineprotected int computeDifference(BreakingAlgorithm.KnuthNode activeNode, KnuthElement element, int elementIndex)
computeDifference
in class BreakingAlgorithm
activeNode
- node for the previous breakpointelement
- currently considered breakpointelementIndex
- index of the element that is considered as a breakpointprotected double computeAdjustmentRatio(BreakingAlgorithm.KnuthNode activeNode, int difference)
computeAdjustmentRatio
in class BreakingAlgorithm
activeNode
- the currently active nodedifference
- the difference between content-length and available widthprotected void finish()
BreakingAlgorithm.findBreakingPoints(KnuthSequence,int,double,boolean,int)
finish
in class BreakingAlgorithm
public java.util.LinkedList<AbstractBreaker.PageBreakPosition> getPageBreaks()
AbstractBreaker.PageBreakPosition
elements
corresponding to the computed page- and column-breakspublic void insertPageBreakAsFirst(AbstractBreaker.PageBreakPosition pageBreak)
AbstractBreaker.PageBreakPosition
as the first
element in the list of page-breakspageBreak
- the position to insertpublic void removeAllPageBreaks()
public void updateData1(int total, double demerits)
updateData1
in class BreakingAlgorithm
total
- number of lines for the active nodedemerits
- total demerits of the paragraph for the active nodepublic void updateData2(BreakingAlgorithm.KnuthNode bestActiveNode, KnuthSequence sequence, int total)
updateData2
in class BreakingAlgorithm
bestActiveNode
- a node in the chain of best active nodes, corresponding to
one of the optimal breakpointssequence
- the corresponding paragraphtotal
- the number of lines into which the paragraph will be brokenprotected int filterActiveNodes()
filterActiveNodes
in class BreakingAlgorithm
protected final java.util.List<KnuthElement> getFootnoteList(int index)
index
- the index in the list of footnotespublic FObj getFObj()
protected int getLineWidth(int line)
getLineWidth
in class BreakingAlgorithm
line
- the line/part numberprotected int getIPDdifference()
getIPDdifference
in class BreakingAlgorithm
protected int handleIpdChange()
handleIpdChange
in class BreakingAlgorithm
protected void addNode(int line, BreakingAlgorithm.KnuthNode node)
addNode
in class BreakingAlgorithm
line
- number of the line ending at the node's corresponding breakpointnode
- the active node to addCopyright 1999-2012 The Apache Software Foundation. All Rights Reserved.