Class PageProvider

  • All Implemented Interfaces:
    Constants

    public class PageProvider
    extends java.lang.Object
    implements Constants

    This class delivers Page instances. It also caches them as necessary.

    Additional functionality makes sure that surplus instances that are requested by the page breaker are properly discarded, especially in situations where hard breaks cause blank pages. The reason for that: The page breaker sometimes needs to preallocate additional pages since it doesn't know exactly until the end how many pages it really needs.

    • Field Detail

      • log

        private org.apache.commons.logging.Log log
      • RELTO_PAGE_SEQUENCE

        public static final int RELTO_PAGE_SEQUENCE
        Indices are evaluated relative to the first page in the page-sequence.
        See Also:
        Constant Field Values
      • RELTO_CURRENT_ELEMENT_LIST

        public static final int RELTO_CURRENT_ELEMENT_LIST
        Indices are evaluated relative to the first page in the current element list.
        See Also:
        Constant Field Values
      • startPageOfPageSequence

        private int startPageOfPageSequence
      • startPageOfCurrentElementList

        private int startPageOfCurrentElementList
      • startColumnOfCurrentElementList

        private int startColumnOfCurrentElementList
      • spanAllForCurrentElementList

        private boolean spanAllForCurrentElementList
      • cachedPages

        private java.util.List<Page> cachedPages
      • lastPageIndex

        private int lastPageIndex
      • indexOfCachedLastPage

        private int indexOfCachedLastPage
      • lastRequestedIndex

        private int lastRequestedIndex
      • lastReportedBPD

        private int lastReportedBPD
      • areaTreeHandler

        private AreaTreeHandler areaTreeHandler
        AreaTreeHandler which activates the PSLM and controls the rendering of its pages.
      • pageSeq

        private PageSequence pageSeq
        fo:page-sequence formatting object being processed by this class
      • skipPagePositionOnly

        protected boolean skipPagePositionOnly
    • Constructor Detail

      • PageProvider

        public PageProvider​(AreaTreeHandler ath,
                            PageSequence ps)
        Main constructor.
        Parameters:
        ath - the area tree handler
        ps - The page-sequence the provider operates on
    • Method Detail

      • initialize

        public void initialize()
      • setStartOfNextElementList

        public void setStartOfNextElementList​(int startPage,
                                              int startColumn,
                                              boolean spanAll)
        The page breaker notifies the provider about the page number an element list starts on so it can later retrieve PageViewports relative to this first page.
        Parameters:
        startPage - the number of the first page for the element list.
        startColumn - the starting column number for the element list.
        spanAll - true if the current element list is for a column-spanning section
      • setLastPageIndex

        public void setLastPageIndex​(int index)
        Sets the index of the last page. This is done as soon as the position of the last page is known or assumed.
        Parameters:
        index - the index relative to the first page in the page-sequence
      • getAvailableBPD

        public int getAvailableBPD​(int index)
        Returns the available BPD for the part/page indicated by the index parameter. The index is the part/page relative to the start of the current element list. This method takes multiple columns into account.
        Parameters:
        index - zero-based index of the requested part/page
        Returns:
        the available BPD
      • compareIPDs

        public int compareIPDs​(int index)
        Compares the IPD of the given part with the following one.
        Parameters:
        index - index of the current part
        Returns:
        a negative integer, zero or a positive integer as the current IPD is less than, equal to or greater than the IPD of the following part
      • startPage

        boolean startPage​(int index)
        Checks if a break at the passed index would start a new page
        Parameters:
        index - the index of the element before the break
        Returns:
        true if the break starts a new page
      • endPage

        boolean endPage​(int index)
        Checks if a break at the passed index would end a page
        Parameters:
        index - the index of the element before the break
        Returns:
        true if the break ends a page
      • getColumnCount

        int getColumnCount​(int index)
        Obtain the applicable column-count for the element at the passed index
        Parameters:
        index - the index of the element
        Returns:
        the number of columns
      • getStartingPartIndexForLastPage

        public int getStartingPartIndexForLastPage​(int partCount)
        Returns the part index (0<x<partCount) which denotes the first part on the last page generated by the current element list.
        Parameters:
        partCount - Number of parts determined by the breaking algorithm
        Returns:
        the requested part index
      • getPageFromColumnIndex

        Page getPageFromColumnIndex​(int columnIndex)
      • getPage

        public Page getPage​(boolean isBlank,
                            int index,
                            int relativeTo)
        Returns a Page.
        Parameters:
        isBlank - true if this page is supposed to be blank.
        index - Index of the page (see relativeTo)
        relativeTo - Defines which value the index parameter should be evaluated relative to. (One of PageProvider.RELTO_*)
        Returns:
        the requested Page
      • getPage

        protected Page getPage​(boolean isBlank,
                               int index)
        Returns a Page.
        Parameters:
        isBlank - true if the Page should be a blank one
        index - the Page's index
        Returns:
        a Page instance
      • discardCacheStartingWith

        protected void discardCacheStartingWith​(int index)
      • cacheNextPage

        private Page cacheNextPage​(int index,
                                   boolean isBlank,
                                   boolean isLastPage,
                                   boolean spanAll)
      • getIndexOfCachedLastPage

        public int getIndexOfCachedLastPage()
      • getLastPageIndex

        public int getLastPageIndex()
      • getLastPageIPD

        public int getLastPageIPD()
      • getCurrentIPD

        public int getCurrentIPD()
      • getNextIPD

        public int getNextIPD()
      • getCurrentColumnCount

        public int getCurrentColumnCount()
      • isOnFirstPage

        boolean isOnFirstPage​(int partIndex)
        Indicates whether the column/page at the given index is on the first page of the page sequence.
        Returns:
        true if the given part is on the first page of the sequence