|
fop 2.2 | |||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectorg.apache.fop.layoutmgr.BreakingAlgorithm
public abstract class BreakingAlgorithm
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
BreakingAlgorithm.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' } }
Nested Class Summary | |
---|---|
protected class |
BreakingAlgorithm.BestRecords
Class that stores, for each fitness class, the best active node that could start a line of the corresponding fitness ending at the current element. |
class |
BreakingAlgorithm.KnuthNode
Class recording all the informations of a feasible breaking point. |
Field Summary | |
---|---|
protected BreakingAlgorithm.KnuthNode[] |
activeLines
The set of active nodes in ascending line order. |
protected int |
activeNodeCount
The number of active nodes. |
protected int |
alignment
Alignment of the paragraph/page. |
protected int |
alignmentLast
Alignment of the paragraph's last line. |
static int |
ALL_BREAKS
All feasible breaks are ok. |
protected BreakingAlgorithm.BestRecords |
best
Best records. |
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
Demerit for consecutive lines belonging to incompatible fitness classes . |
protected boolean |
indentFirstPart
Used to handle the text-indent property (indent the first line of a paragraph). |
protected static int |
INFINITE_RATIO
Maximum adjustment ration |
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 for the class |
protected int |
maxFlaggedPenaltiesCount
Maximum number of consecutive lines ending with a flagged penalty. |
static int |
NO_FLAGGED_PENALTIES
This forbids hyphenation. |
static int |
ONLY_FORCED_BREAKS
wrap-option = "no-wrap". |
protected KnuthSequence |
par
The paragraph of KnuthElements. |
protected int |
repeatedFlaggedDemerit
Demerit for consecutive lines ending at flagged penalties. |
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)
Create a new instance. |
Method Summary | |
---|---|
protected void |
activateNode(BreakingAlgorithm.KnuthNode node,
int difference,
double r,
double demerits,
int fitnessClass,
int availableShrink,
int availableStretch)
Activate the given node. |
protected void |
addNode(int line,
BreakingAlgorithm.KnuthNode node)
Add a node at the end of the given line's existing active nodes. |
protected void |
calculateBreakPoints(BreakingAlgorithm.KnuthNode node,
KnuthSequence par,
int total)
Determines the set of optimal breakpoints corresponding to the given active node. |
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 void |
createForcedNodes(BreakingAlgorithm.KnuthNode node,
int line,
int elementIdx,
int difference,
double r,
double demerits,
int fitnessClass,
int availableShrink,
int availableStretch,
int newWidth,
int newStretch,
int newShrink)
|
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 void |
deactivateNode(BreakingAlgorithm.KnuthNode node,
int line)
Deactivate the given node |
protected void |
disableFloatHandling()
|
protected boolean |
elementCanEndLine(KnuthElement element,
int line,
int difference)
Check if the given KnuthElement can end the line with the given
number. |
protected abstract int |
filterActiveNodes()
Filter active nodes. |
int |
findBreakingPoints(KnuthSequence par,
double threshold,
boolean force,
int allowedBreaks)
|
int |
findBreakingPoints(KnuthSequence par,
int startIndex,
double threshold,
boolean force,
int allowedBreaks)
Finds an optimal set of breakpoints for the given paragraph. |
protected void |
finish()
Hook for subclasses to trigger special behavior after ending the main loop in findBreakingPoints(KnuthSequence,int,double,boolean,int) |
protected void |
forceNode(BreakingAlgorithm.KnuthNode node,
int line,
int elementIdx,
int difference,
double r,
double demerits,
int fitnessClass,
int availableShrink,
int availableStretch)
Force the given BreakingAlgorithm.KnuthNode , and register it. |
int |
getAlignment()
|
int |
getAlignmentLast()
|
protected KnuthElement |
getElement(int idx)
Return the element at index idx in the paragraph. |
protected int |
getIPDdifference()
obtain ipd difference |
protected BreakingAlgorithm.KnuthNode |
getLastTooLong()
|
protected BreakingAlgorithm.KnuthNode |
getLastTooShort()
Return the last node that yielded a too short line. |
protected int |
getLineWidth()
|
protected int |
getLineWidth(int line)
Returns the line/part width of a given line/part. |
protected int |
getMaxRecoveryAttempts()
|
protected BreakingAlgorithm.KnuthNode |
getNode(int line)
Returns the first active node for the given line. |
protected void |
handleBox(KnuthBox box)
Handle a KnuthBox . |
protected KnuthElement |
handleElementAt(int position,
boolean previousIsBox,
int allowedBreaks)
Generic handler for a KnuthElement at the given position ,
taking into account whether the preceding element was a box, and which
type(s) of breaks are allowed. |
protected int |
handleFloat()
|
protected void |
handleGlueAt(KnuthGlue glue,
int position,
boolean previousIsBox,
int allowedBreaks)
Handle a KnuthGlue at the given position,
taking into account the additional parameters. |
protected int |
handleIpdChange()
handle ipd change |
protected void |
handlePenaltyAt(KnuthPenalty penalty,
int position,
int allowedBreaks)
Handle a KnuthPenalty at the given position,
taking into account the type of breaks allowed. |
protected boolean |
handlingFloat()
|
protected void |
initialize()
Initializes the algorithm's variables. |
protected boolean |
isPartOverflowRecoveryActivated()
Controls the behaviour of the algorithm in cases where the first element of a part overflows a line/page. |
protected BreakingAlgorithm.KnuthNode |
recoverFromOverflow()
Recover from an overflow condition. |
protected BreakingAlgorithm.KnuthNode |
recoverFromTooLong(BreakingAlgorithm.KnuthNode lastTooLong)
Recover from a BreakingAlgorithm.KnuthNode leading to a line that is too long. |
protected void |
removeNode(int line,
BreakingAlgorithm.KnuthNode node)
Remove the given active node registered for the given line. |
protected void |
replaceLastDeactivated()
Replace the last too-long or too-short node by the last deactivated node, if applicable. |
protected int |
restartFrom(BreakingAlgorithm.KnuthNode restartingNode,
int currentIndex)
Restart from the given node at the given index. |
void |
setConstantLineWidth(int lineWidth)
|
java.lang.String |
toString(java.lang.String prepend)
Creates a string representation of the active nodes. |
abstract void |
updateData1(int total,
double demerits)
Empty method, hook for subclasses. |
abstract void |
updateData2(BreakingAlgorithm.KnuthNode bestActiveNode,
KnuthSequence sequence,
int total)
Empty method, hook for subclasses. |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
---|
protected static final org.apache.commons.logging.Log log
protected static final int INFINITE_RATIO
public static final int ALL_BREAKS
public static final int NO_FLAGGED_PENALTIES
public static final int ONLY_FORCED_BREAKS
protected int repeatedFlaggedDemerit
protected int incompatibleFitnessDemerit
protected int maxFlaggedPenaltiesCount
protected KnuthSequence par
protected int lineWidth
protected boolean considerTooShort
protected int alignment
protected int alignmentLast
protected boolean indentFirstPart
protected BreakingAlgorithm.KnuthNode[] activeLines
protected int activeNodeCount
protected int startLine
protected int endLine
protected int totalWidth
protected int totalStretch
protected int totalShrink
protected BreakingAlgorithm.BestRecords best
Constructor Detail |
---|
public BreakingAlgorithm(int align, int alignLast, boolean first, boolean partOverflowRecovery, int maxFlagCount)
align
- 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
.alignLast
- alignment of the paragraph's last linefirst
- for the text-indent property (true
if the first line
of a paragraph should be indented)partOverflowRecovery
- true
if too long elements should be moved to
the next line/partmaxFlagCount
- maximum allowed number of consecutive lines ending at a flagged penalty
itemMethod Detail |
---|
protected int getMaxRecoveryAttempts()
protected boolean isPartOverflowRecoveryActivated()
protected BreakingAlgorithm.KnuthNode getLastTooLong()
public abstract void updateData1(int total, double demerits)
total
- number of lines for the active nodedemerits
- total demerits of the paragraph for the active nodepublic abstract void updateData2(BreakingAlgorithm.KnuthNode bestActiveNode, KnuthSequence sequence, int total)
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 brokenpublic void setConstantLineWidth(int lineWidth)
lineWidth
- the line widthpublic int findBreakingPoints(KnuthSequence par, double threshold, boolean force, int allowedBreaks)
par
- the paragraph to breakthreshold
- upper bound of the adjustment ratioforce
- true
if a set of breakpoints must be found, even
if there are no feasible onesallowedBreaks
- the type(s) of breaks allowed. One of ONLY_FORCED_BREAKS
,
NO_FLAGGED_PENALTIES
or ALL_BREAKS
.
findBreakingPoints(KnuthSequence, int, double, boolean, int)
public int findBreakingPoints(KnuthSequence par, int startIndex, double threshold, boolean force, int allowedBreaks)
par
- the paragraph to breakstartIndex
- index of the Knuth element at which the breaking must startthreshold
- upper bound of the adjustment ratioforce
- true
if a set of breakpoints must be found, even
if there are no feasible onesallowedBreaks
- the type(s) of breaks allowed. One of ONLY_FORCED_BREAKS
,
NO_FLAGGED_PENALTIES
or ALL_BREAKS
.
protected int getIPDdifference()
protected int handleIpdChange()
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.
lastTooLong
- the node that leads to a "too long" line
protected void initialize()
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)
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 breakpoint
protected BreakingAlgorithm.KnuthNode createNode(int position, int line, int fitness, int totalWidth, int totalStretch, int totalShrink)
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
breakpoint
createNode(int, int, int, int, int, int, double, int, int, int, double,
org.apache.fop.layoutmgr.BreakingAlgorithm.KnuthNode)
,
BreakingAlgorithm.BestRecords
protected final BreakingAlgorithm.KnuthNode getLastTooShort()
protected final KnuthElement handleElementAt(int position, boolean previousIsBox, int allowedBreaks)
KnuthElement
at the given position
,
taking into account whether the preceding element was a box, and which
type(s) of breaks are allowed.
Non-overridable. This method simply serves to route the call to one of the
more specific handlers (handleBox(KnuthBox)
,
handleGlueAt(KnuthGlue,int,boolean,int)
or
handlePenaltyAt(KnuthPenalty,int,int)
. The specialized handlers
can be overridden by subclasses to add to or modify the default behavior
for the different types of elements.
position
- the position index of the element in the paragraphpreviousIsBox
- true
if the previous element is a boxallowedBreaks
- the type(s) of breaks allowed; should be one
of ALL_BREAKS
, NO_FLAGGED_PENALTIES
or ONLY_FORCED_BREAKS
protected void handleBox(KnuthBox box)
KnuthBox
.
super.handleBox(box)
to avoid unwanted side-effects.
box
- the KnuthBox
to handleprotected void handleGlueAt(KnuthGlue glue, int position, boolean previousIsBox, int allowedBreaks)
KnuthGlue
at the given position,
taking into account the additional parameters.
glue
- the KnuthGlue
to handleposition
- the position of the glue in the listpreviousIsBox
- true
if the preceding element is a boxallowedBreaks
- the type of breaks that are allowedprotected void handlePenaltyAt(KnuthPenalty penalty, int position, int allowedBreaks)
KnuthPenalty
at the given position,
taking into account the type of breaks allowed.
penalty
- the KnuthPenalty
to handleposition
- the position of the penalty in the listallowedBreaks
- the type of breaks that are allowedprotected final void replaceLastDeactivated()
protected BreakingAlgorithm.KnuthNode recoverFromOverflow()
lastForced
nodeprotected int restartFrom(BreakingAlgorithm.KnuthNode restartingNode, int currentIndex)
restartingNode
- the BreakingAlgorithm.KnuthNode
to restart fromcurrentIndex
- the current position index
protected void considerLegalBreak(KnuthElement element, int elementIdx)
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.
element
- the elementline
- the line numberdifference
- an integer
true
if the element can end the lineprotected void forceNode(BreakingAlgorithm.KnuthNode node, int line, int elementIdx, int difference, double r, double demerits, int fitnessClass, int availableShrink, int availableStretch)
BreakingAlgorithm.KnuthNode
, and register it.
node
- the nodeline
- the line numberelementIdx
- the position index of the elementdifference
- the difference between content-length and available widthr
- the adjustment ratiodemerits
- demerits produced by the nodefitnessClass
- the fitness classavailableShrink
- the available amount of shrinkavailableStretch
- tha available amount of stretchprotected void createForcedNodes(BreakingAlgorithm.KnuthNode node, int line, int elementIdx, int difference, double r, double demerits, int fitnessClass, int availableShrink, int availableStretch, int newWidth, int newStretch, int newShrink)
protected void activateNode(BreakingAlgorithm.KnuthNode node, int difference, double r, double demerits, int fitnessClass, int availableShrink, int availableStretch)
BreakingAlgorithm.KnuthNode
being registered as a feasible breakpoint, if the demerits
are better
than that of the best node registered for the given fitnessClass
.
node
- the nodedifference
- the difference between content-length and available widthr
- the adjustment ratiodemerits
- demerits produced by the nodefitnessClass
- the fitness classavailableShrink
- the available amount of shrinkavailableStretch
- the available amount of stretchprotected void deactivateNode(BreakingAlgorithm.KnuthNode node, int line)
node
- the nodeline
- the line numberprotected int computeDifference(BreakingAlgorithm.KnuthNode activeNode, KnuthElement element, int elementIndex)
activeNode
- node for the previous breakpointelement
- currently considered breakpointelementIndex
- index of the element that is considered as a breakpoint
protected double computeAdjustmentRatio(BreakingAlgorithm.KnuthNode activeNode, int difference)
activeNode
- the currently active nodedifference
- the difference between content-length and available width
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 line
protected void finish()
findBreakingPoints(KnuthSequence,int,double,boolean,int)
protected KnuthElement getElement(int idx)
idx
- index of the element.
protected BreakingAlgorithm.KnuthNode compareNodes(BreakingAlgorithm.KnuthNode node1, BreakingAlgorithm.KnuthNode node2)
node1
- The first knuth node.node2
- The other knuth node.
protected void addNode(int line, BreakingAlgorithm.KnuthNode node)
line
- number of the line ending at the node's corresponding breakpointnode
- the active node to addprotected void removeNode(int line, BreakingAlgorithm.KnuthNode node)
line
- number of the line ending at the node's corresponding breakpointnode
- the node to deactivateprotected BreakingAlgorithm.KnuthNode getNode(int line)
line
- the line/part number
protected int getLineWidth(int line)
line
- the line/part number
protected int getLineWidth()
public java.lang.String toString(java.lang.String prepend)
prepend
- a string to prepend on each entry
protected abstract int filterActiveNodes()
protected void calculateBreakPoints(BreakingAlgorithm.KnuthNode node, KnuthSequence par, int total)
node
- the active nodepar
- the corresponding paragraphtotal
- the number of lines into which the paragraph will be brokenpublic int getAlignment()
public int getAlignmentLast()
protected boolean handlingFloat()
protected int handleFloat()
protected void disableFloatHandling()
|
fop 2.2 | |||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |