Package org.apache.fop.layoutmgr
Class PageBreaker
- java.lang.Object
-
- org.apache.fop.layoutmgr.AbstractBreaker
-
- org.apache.fop.layoutmgr.PageBreaker
-
public class PageBreaker extends AbstractBreaker
Handles the breaking of pages in an fo:flow
-
-
Nested Class Summary
-
Nested classes/interfaces inherited from class org.apache.fop.layoutmgr.AbstractBreaker
AbstractBreaker.BlockSequence, AbstractBreaker.FloatPosition, AbstractBreaker.PageBreakPosition
-
-
Field Summary
-
Fields inherited from class org.apache.fop.layoutmgr.AbstractBreaker
alignment, blockListIndex, blockLists, firstElementsForRestart, footnoteSeparatorLength, log, originalRestartAtLM, positionAtBreak, pslm
-
-
Constructor Summary
Constructors Constructor Description PageBreaker(PageSequenceLayoutManager pslm)Construct page breaker.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description protected voidaddAreas(PositionIterator posIter, LayoutContext context)Adds an area to the flow layout managerprotected voidaddAreasForFloats(PageBreakingAlgorithm alg, int startPart, int partCount, AbstractBreaker.BlockSequence originalList, AbstractBreaker.BlockSequence effectiveList, LayoutContext childLC, int lastBreak, int startElementIndex, int endElementIndex)private voidaddFootnoteAreas(java.util.List<KnuthElement> footnote)private voidaddFootnoteAreas(java.util.List<KnuthElement> footnote, int startIndex, int endIndex)private booleancontainsFootnotes(java.util.List contentList, LayoutContext context)protected PageBreakingAlgorithm.PageBreakingLayoutListenercreateLayoutListener()Creates and returns a PageBreakingLayoutListener for the PageBreakingAlgorithm to notify about layout problems.(package private) booleandoLayout(int flowBPD)Starts the page breaking process.protected voiddoPhase3(PageBreakingAlgorithm alg, int partCount, AbstractBreaker.BlockSequence originalList, AbstractBreaker.BlockSequence effectiveList)Phase 3 of Knuth algorithm: Adds the areasprotected voidfinishPart(PageBreakingAlgorithm alg, AbstractBreaker.PageBreakPosition pbp)Finish part.protected FlowLayoutManagergetCurrentChildLM()protected intgetCurrentDisplayAlign()protected intgetFloatHeight()protected intgetFloatYOffset()static java.util.List<java.util.List<KnuthElement>>getFootnoteKnuthElements(FlowLayoutManager flowLM, LayoutContext context, java.util.List<FootnoteBodyLayoutManager> footnoteBodyLMs)protected intgetNextBlockList(LayoutContext childLC, int nextSequenceStartsOn)Gets the next block list (sequence) and adds it to a list of block lists if it's not empty.protected intgetNextBlockList(LayoutContext childLC, int nextSequenceStartsOn, Position positionAtIPDChange, LayoutManager restartLM, java.util.List firstElements)Gets the next block list (sequence) and adds it to a list of block lists if it's not empty.protected java.util.ListgetNextKnuthElements(LayoutContext context, int alignment)Get a sequence of KnuthElements representing the content of the node assigned to the LMprotected java.util.ListgetNextKnuthElements(LayoutContext context, int alignment, Position positionAtIPDChange, LayoutManager restartAtLM)Get a sequence of KnuthElements representing the content of the node assigned to the LMintgetOffsetDueToFloat()protected PageProvidergetPageProvider()Returns the PageProvider if any.protected LayoutManagergetTopLevelLM()private voidhandleBreakBeforeFollowingPage(int breakVal)private voidhandleBreakTrait(int breakVal)Depending on the kind of break condition, move to next column or page.private voidhandleBreakTrait(int breakVal, boolean emptyContent)protected voidhandleEmptyContent()This method is called when no content is available for a part.protected voidhandleEndOfFloat(int fHeight)protected inthandleFloatLayout(PageBreakingAlgorithm alg, int optimalPageCount, AbstractBreaker.BlockSequence blockList, LayoutContext childLC)private voidhandleFootnoteSeparator()protected inthandleSpanChange(LayoutContext childLC, int nextSequenceStartsOn)Handles span changes reported through theLayoutContext.protected voidhandleStartOfFloat(int fHeight, int fYOffset)protected booleanhandlingEndOfFloat()protected booleanhandlingFloat()protected booleanhandlingStartOfFloat()protected booleanhasMoreContent()voidholdFootnotes(java.util.List fl, java.util.List ll, int tfl, int ifl, boolean fp, boolean nf, int fnfi, int fli, int fei, MinOptMax fsl, int pfli, int pfei)protected booleanlastPageHasIPDChange(int optimalPageCount)private booleanneedBlankPageBeforeNew(int breakVal)Check if a blank page is needed to accommodate desired even or odd page number.private booleanneedNewPage(int breakVal)See if need to generate a new pageprotected voidobserveElementList(java.util.List elementList)Used for debugging purposes.protected voidprepareToRedoLayout(PageBreakingAlgorithm alg, int partCount, AbstractBreaker.BlockSequence originalList, AbstractBreaker.BlockSequence effectiveList)private voidredoLayout(PageBreakingAlgorithm alg, int partCount, AbstractBreaker.BlockSequence originalList, AbstractBreaker.BlockSequence effectiveList)Restart the algorithm at the break corresponding to the given partCount.voidretrieveFootones(PageBreakingAlgorithm alg)private voidsetLastPageIndex(int currentPageNum)protected booleanshouldRedoLayout()protected booleanshouldRedoLayout(int partCount)protected voidstartPart(AbstractBreaker.BlockSequence list, int breakClass, boolean emptyContent)Start part.protected voidupdateLayoutContext(LayoutContext context)Used to update the LayoutContext in subclasses prior to starting a new element list.protected booleanwasLayoutRedone()-
Methods inherited from class org.apache.fop.layoutmgr.AbstractBreaker
addAreas, addAreas, addAreas, containsNonRestartableLM, createLayoutContext, doLayout, getBreakClassName, isEmpty, isPartOverflowRecoveryActivated, isSinglePartFavored
-
-
-
-
Field Detail
-
firstPart
private boolean firstPart
-
pageBreakHandled
private boolean pageBreakHandled
-
needColumnBalancing
private boolean needColumnBalancing
-
pageProvider
private PageProvider pageProvider
-
separatorArea
private Block separatorArea
-
spanAllActive
private boolean spanAllActive
-
layoutRedone
private boolean layoutRedone
-
previousIndex
private int previousIndex
-
handlingStartOfFloat
private boolean handlingStartOfFloat
-
handlingEndOfFloat
private boolean handlingEndOfFloat
-
floatHeight
private int floatHeight
-
floatYOffset
private int floatYOffset
-
relayedFootnotesList
private java.util.List relayedFootnotesList
-
relayedLengthList
private java.util.List relayedLengthList
-
relayedTotalFootnotesLength
private int relayedTotalFootnotesLength
-
relayedInsertedFootnotesLength
private int relayedInsertedFootnotesLength
-
relayedFootnotesPending
private boolean relayedFootnotesPending
-
relayedNewFootnotes
private boolean relayedNewFootnotes
-
relayedFirstNewFootnoteIndex
private int relayedFirstNewFootnoteIndex
-
relayedFootnoteListIndex
private int relayedFootnoteListIndex
-
relayedFootnoteElementIndex
private int relayedFootnoteElementIndex
-
relayedFootnoteSeparatorLength
private MinOptMax relayedFootnoteSeparatorLength
-
previousFootnoteListIndex
private int previousFootnoteListIndex
-
previousFootnoteElementIndex
private int previousFootnoteElementIndex
-
prevousColumnCount
private int prevousColumnCount
-
childFLM
private FlowLayoutManager childFLM
The FlowLayoutManager object, which processes the single fo:flow of the fo:page-sequence
-
footnoteSeparatorLM
private StaticContentLayoutManager footnoteSeparatorLM
-
-
Constructor Detail
-
PageBreaker
public PageBreaker(PageSequenceLayoutManager pslm)
Construct page breaker.- Parameters:
pslm- the page sequence layout manager
-
-
Method Detail
-
updateLayoutContext
protected void updateLayoutContext(LayoutContext context)
Used to update the LayoutContext in subclasses prior to starting a new element list.- Overrides:
updateLayoutContextin classAbstractBreaker- Parameters:
context- the LayoutContext to update
-
getTopLevelLM
protected LayoutManager getTopLevelLM()
- Specified by:
getTopLevelLMin classAbstractBreaker- Returns:
- top level layout manager
-
getPageProvider
protected PageProvider getPageProvider()
Returns the PageProvider if any. PageBreaker overrides this method because each page may have a different available BPD which needs to be accessible to the breaking algorithm.- Overrides:
getPageProviderin classAbstractBreaker- Returns:
- the applicable PageProvider, or null if not applicable
-
doLayout
boolean doLayout(int flowBPD)
Starts the page breaking process.- Parameters:
flowBPD- the constant available block-progression-dimension (used for every part)
-
createLayoutListener
protected PageBreakingAlgorithm.PageBreakingLayoutListener createLayoutListener()
Creates and returns a PageBreakingLayoutListener for the PageBreakingAlgorithm to notify about layout problems.- Overrides:
createLayoutListenerin classAbstractBreaker- Returns:
- the listener instance or null if no notifications are needed
-
handleSpanChange
protected int handleSpanChange(LayoutContext childLC, int nextSequenceStartsOn)
Handles span changes reported through theLayoutContext. Only used by the PSLM and called bygetNextBlockList().- Overrides:
handleSpanChangein classAbstractBreaker- Parameters:
childLC- the LayoutContextnextSequenceStartsOn- previous value for break handling- Returns:
- effective value for break handling
-
getNextBlockList
protected int getNextBlockList(LayoutContext childLC, int nextSequenceStartsOn)
Gets the next block list (sequence) and adds it to a list of block lists if it's not empty.- Overrides:
getNextBlockListin classAbstractBreaker- Parameters:
childLC- LayoutContext to usenextSequenceStartsOn- indicates on what page the next sequence should start- Returns:
- the page on which the next content should appear after a hard break
-
getNextBlockList
protected int getNextBlockList(LayoutContext childLC, int nextSequenceStartsOn, Position positionAtIPDChange, LayoutManager restartLM, java.util.List firstElements)
Gets the next block list (sequence) and adds it to a list of block lists if it's not empty.- Overrides:
getNextBlockListin classAbstractBreaker- Parameters:
childLC- LayoutContext to usenextSequenceStartsOn- indicates on what page the next sequence should startpositionAtIPDChange- last element on the part before an IPD changerestartLM- the layout manager from which to restart, if IPD change occurs between two LMsfirstElements- elements from non-restartable LMs on the new page- Returns:
- the page on which the next content should appear after a hard break
-
containsFootnotes
private boolean containsFootnotes(java.util.List contentList, LayoutContext context)
-
getFootnoteKnuthElements
public static java.util.List<java.util.List<KnuthElement>> getFootnoteKnuthElements(FlowLayoutManager flowLM, LayoutContext context, java.util.List<FootnoteBodyLayoutManager> footnoteBodyLMs)
-
handleFootnoteSeparator
private void handleFootnoteSeparator()
-
getNextKnuthElements
protected java.util.List getNextKnuthElements(LayoutContext context, int alignment)
Get a sequence of KnuthElements representing the content of the node assigned to the LM- Specified by:
getNextKnuthElementsin classAbstractBreaker- Parameters:
context- the LayoutContext used to store layout informationalignment- the desired text alignment- Returns:
- the list of KnuthElements
-
getNextKnuthElements
protected java.util.List getNextKnuthElements(LayoutContext context, int alignment, Position positionAtIPDChange, LayoutManager restartAtLM)
Get a sequence of KnuthElements representing the content of the node assigned to the LM- Overrides:
getNextKnuthElementsin classAbstractBreaker- Parameters:
context- the LayoutContext used to store layout informationalignment- the desired text alignmentpositionAtIPDChange- last element on the part before an IPD changerestartAtLM- the layout manager from which to restart, if IPD change occurs between two LMs- Returns:
- the list of KnuthElements
-
getCurrentDisplayAlign
protected int getCurrentDisplayAlign()
- Specified by:
getCurrentDisplayAlignin classAbstractBreaker- Returns:
- current display alignment
-
hasMoreContent
protected boolean hasMoreContent()
- Specified by:
hasMoreContentin classAbstractBreaker- Returns:
- whether or not this flow has more page break opportunities
-
addAreas
protected void addAreas(PositionIterator posIter, LayoutContext context)
Adds an area to the flow layout manager- Specified by:
addAreasin classAbstractBreaker- Parameters:
posIter- the position iteratorcontext- the layout context
-
doPhase3
protected void doPhase3(PageBreakingAlgorithm alg, int partCount, AbstractBreaker.BlockSequence originalList, AbstractBreaker.BlockSequence effectiveList)
Phase 3 of Knuth algorithm: Adds the areas This implementation checks whether to trigger column-balancing, or whether to take into account a 'last-page' condition.- Specified by:
doPhase3in classAbstractBreaker- Parameters:
alg- PageBreakingAlgorithm instance which determined the breakspartCount- number of parts (pages) to be renderedoriginalList- original Knuth element listeffectiveList- effective Knuth element list (after adjustments)
-
prepareToRedoLayout
protected void prepareToRedoLayout(PageBreakingAlgorithm alg, int partCount, AbstractBreaker.BlockSequence originalList, AbstractBreaker.BlockSequence effectiveList)
- Overrides:
prepareToRedoLayoutin classAbstractBreaker
-
redoLayout
private void redoLayout(PageBreakingAlgorithm alg, int partCount, AbstractBreaker.BlockSequence originalList, AbstractBreaker.BlockSequence effectiveList)
Restart the algorithm at the break corresponding to the given partCount. Used to re-do the part after the last break in case of either column-balancing or a last page-master.
-
setLastPageIndex
private void setLastPageIndex(int currentPageNum)
-
startPart
protected void startPart(AbstractBreaker.BlockSequence list, int breakClass, boolean emptyContent)
Start part.- Overrides:
startPartin classAbstractBreaker- Parameters:
list- a block sequencebreakClass- a break class
-
handleEmptyContent
protected void handleEmptyContent()
This method is called when no content is available for a part. Used to force empty pages.- Overrides:
handleEmptyContentin classAbstractBreaker
-
finishPart
protected void finishPart(PageBreakingAlgorithm alg, AbstractBreaker.PageBreakPosition pbp)
Finish part.- Specified by:
finishPartin classAbstractBreaker- Parameters:
alg- a page breaking algorithmpbp- a page break posittion
-
addFootnoteAreas
private void addFootnoteAreas(java.util.List<KnuthElement> footnote)
-
addFootnoteAreas
private void addFootnoteAreas(java.util.List<KnuthElement> footnote, int startIndex, int endIndex)
-
getCurrentChildLM
protected FlowLayoutManager getCurrentChildLM()
- Specified by:
getCurrentChildLMin classAbstractBreaker- Returns:
- current child layout manager
-
observeElementList
protected void observeElementList(java.util.List elementList)
Used for debugging purposes. Notifies all registered observers about the element list. Override to set different parameters.- Overrides:
observeElementListin classAbstractBreaker- Parameters:
elementList- the Knuth element list
-
handleBreakTrait
private void handleBreakTrait(int breakVal)
Depending on the kind of break condition, move to next column or page. May need to make an empty page if next page would not have the desired "handedness".- Parameters:
breakVal- - value of break-before or break-after trait.
-
handleBreakTrait
private void handleBreakTrait(int breakVal, boolean emptyContent)
-
handleBreakBeforeFollowingPage
private void handleBreakBeforeFollowingPage(int breakVal)
-
needBlankPageBeforeNew
private boolean needBlankPageBeforeNew(int breakVal)
Check if a blank page is needed to accommodate desired even or odd page number.- Parameters:
breakVal- - value of break-before or break-after trait.
-
needNewPage
private boolean needNewPage(int breakVal)
See if need to generate a new page- Parameters:
breakVal- - value of break-before or break-after trait.
-
shouldRedoLayout
protected boolean shouldRedoLayout()
- Overrides:
shouldRedoLayoutin classAbstractBreaker
-
shouldRedoLayout
protected boolean shouldRedoLayout(int partCount)
-
wasLayoutRedone
protected boolean wasLayoutRedone()
- Overrides:
wasLayoutRedonein classAbstractBreaker
-
lastPageHasIPDChange
protected boolean lastPageHasIPDChange(int optimalPageCount)
- Overrides:
lastPageHasIPDChangein classAbstractBreaker
-
handlingStartOfFloat
protected boolean handlingStartOfFloat()
-
handleStartOfFloat
protected void handleStartOfFloat(int fHeight, int fYOffset)
-
getFloatHeight
protected int getFloatHeight()
-
getFloatYOffset
protected int getFloatYOffset()
-
handlingEndOfFloat
protected boolean handlingEndOfFloat()
-
handleEndOfFloat
protected void handleEndOfFloat(int fHeight)
-
handlingFloat
protected boolean handlingFloat()
-
getOffsetDueToFloat
public int getOffsetDueToFloat()
-
handleFloatLayout
protected int handleFloatLayout(PageBreakingAlgorithm alg, int optimalPageCount, AbstractBreaker.BlockSequence blockList, LayoutContext childLC)
- Overrides:
handleFloatLayoutin classAbstractBreaker
-
addAreasForFloats
protected void addAreasForFloats(PageBreakingAlgorithm alg, int startPart, int partCount, AbstractBreaker.BlockSequence originalList, AbstractBreaker.BlockSequence effectiveList, LayoutContext childLC, int lastBreak, int startElementIndex, int endElementIndex)
- Overrides:
addAreasForFloatsin classAbstractBreaker
-
holdFootnotes
public void holdFootnotes(java.util.List fl, java.util.List ll, int tfl, int ifl, boolean fp, boolean nf, int fnfi, int fli, int fei, MinOptMax fsl, int pfli, int pfei)
-
retrieveFootones
public void retrieveFootones(PageBreakingAlgorithm alg)
-
-