Class LineLayoutManager

    • Field Detail

      • DEFAULT_SPACE_WIDTH

        public static final int DEFAULT_SPACE_WIDTH
        this constant is used to create elements when text-align is center: every TextLM descendant of LineLM must use the same value, otherwise the line breaking algorithm does not find the right break point
        See Also:
        Constant Field Values
      • log

        private static org.apache.commons.logging.Log log
        logging instance
      • fobj

        private final Block fobj
      • isFirstInBlock

        private boolean isFirstInBlock
      • bidiLevel

        private int bidiLevel
      • textAlignment

        private int textAlignment
      • textAlignmentLast

        private int textAlignmentLast
      • effectiveAlignment

        private int effectiveAlignment
      • textIndent

        private Length textIndent
      • lastLineEndIndent

        private Length lastLineEndIndent
      • hyphenationLadderCount

        private Numeric hyphenationLadderCount
      • wrapOption

        private int wrapOption
      • whiteSpaceTreament

        private int whiteSpaceTreament
      • lineHeight

        private final Length lineHeight
      • lead

        private final int lead
      • follow

        private final int follow
      • baselineOffset

        private int baselineOffset
      • knuthParagraphs

        private java.util.List<KnuthSequence> knuthParagraphs
      • ipd

        private int ipd
      • hyphenationPerformed

        private boolean hyphenationPerformed
        When layout must be re-started due to a change of IPD, there is no need to perform hyphenation on the remaining Knuth sequence once again.
      • constantLineHeight

        private int constantLineHeight
    • Constructor Detail

      • LineLayoutManager

        public LineLayoutManager​(Block block,
                                 Length lh,
                                 int l,
                                 int f)
        Create a new Line Layout Manager. This is used by the block layout manager to create line managers for handling inline areas flowing into line areas.
        Parameters:
        block - the block formatting object
        lh - the default line height
        l - the default lead, from top to baseline
        f - the default follow, from baseline to bottom
    • Method Detail

      • getEffectiveAlignment

        private int getEffectiveAlignment​(int alignment,
                                          int alignmentLast)
      • getNextKnuthElements

        public 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:
        getNextKnuthElements in interface LayoutManager
        Overrides:
        getNextKnuthElements in class AbstractLayoutManager
        Parameters:
        context - the LayoutContext used to store layout information
        alignment - the desired text alignment
        Returns:
        the list of KnuthElements
      • getNextKnuthElements

        public java.util.List getNextKnuthElements​(LayoutContext context,
                                                   int alignment,
                                                   LeafPosition restartPosition)
        Get a sequence of KnuthElements representing the content of the node assigned to the LM.
        Parameters:
        context - the LayoutContext used to store layout information
        alignment - the desired text alignment
        restartPosition - position at restart
        Returns:
        the list of KnuthElements
        See Also:
        LayoutManager.getNextKnuthElements(LayoutContext,int)
      • collectInlineKnuthElements

        private void collectInlineKnuthElements​(LayoutContext context)
        Phase 1 of Knuth algorithm: Collect all inline Knuth elements before determining line breaks.
        Parameters:
        context - the LayoutContext
      • createLineBreaks

        private java.util.List<ListElement> createLineBreaks​(int alignment,
                                                             LayoutContext context)
        Phase 2 of Knuth algorithm: find optimal break points.
        Parameters:
        alignment - alignment in BP direction of the paragraph
        context - the layout context
        Returns:
        a list of Knuth elements representing broken lines
      • findOptimalBreakingPoints

        private LineLayoutPossibilities findOptimalBreakingPoints​(int alignment,
                                                                  LineLayoutManager.Paragraph currPar,
                                                                  boolean isLastPar)
        Find the optimal linebreaks for a paragraph
        Parameters:
        alignment - alignment of the paragraph
        currPar - the Paragraph for which the linebreaks are found
        isLastPar - flag indicating whether currPar is the last paragraph
        Returns:
        the line layout possibilities for the paragraph
      • postProcessLineBreaks

        private java.util.List<ListElement> postProcessLineBreaks​(int alignment,
                                                                  LayoutContext context)
        Creates the element list in BP direction for the broken lines.
        Parameters:
        alignment - the currently applicable vertical alignment
        context - the layout context
        Returns:
        the newly built element list
      • negotiateBPDAdjustment

        public int negotiateBPDAdjustment​(int adj,
                                          KnuthElement lastElement)
        Negotiate BPD adjustment.
        Specified by:
        negotiateBPDAdjustment in interface BlockLevelLayoutManager
        Parameters:
        adj - amount to adjust
        lastElement - the last knuth element
        Returns:
        the resulting adjusted BPD
      • getChangedKnuthElements

        public java.util.List getChangedKnuthElements​(java.util.List oldList,
                                                      int alignment,
                                                      int depth)
        Get a sequence of KnuthElements representing the content of the node assigned to the LM, after changes have been applied
        Specified by:
        getChangedKnuthElements in interface InlineLevelLayoutManager
        Overrides:
        getChangedKnuthElements in class InlineStackingLayoutManager
        Parameters:
        oldList - the elements to replace
        alignment - the desired text alignment
        depth - the depth at which the Positions for this LM in oldList are found
        Returns:
        the updated list of KnuthElements
      • getChangedKnuthElements

        public java.util.List getChangedKnuthElements​(java.util.List oldList,
                                                      int alignment)
        Get a sequence of KnuthElements representing the content of the node assigned to the LM, after changes have been applied In the context of line breaking, this method is called after hyphenation has been performed, in order to receive the sequence of elements representing the text together with all possible hyphenation points. For example, if the text "representation" originates a single box element when getNextKnuthElements() is called, it will be now split in syllables (rep-re-sen-ta-tion) each one originating a box and divided by additional elements allowing a line break. In the context of page breaking, this method is called only if the pages need to be "vertically justified" modifying (also) the quantity of lines created by the paragraphs, and after a first page breaking has been performed. According to the result of the first page breaking, each paragraph now knows how many lines it must create (among the existing layout possibilities) and has to create a sequence of elements representing this layout; in particular, each box, representing a line, will contain a LineBreakPositions that will be used in the addAreas() phase. LMs having children look at the old list of elements in order to know which ones they must get the new elements from, as break conditions of preserved linefeeds can divide children into smaller groups (page sequences or paragraphs). LMs having no children can simply return the old elements if they have nothing to change. Inline LMs need to know the text alignment because it affects the elements representing feasible breaks between syllables.
        Specified by:
        getChangedKnuthElements in interface LayoutManager
        Overrides:
        getChangedKnuthElements in class InlineStackingLayoutManager
        Parameters:
        oldList - the elements to replace
        alignment - the desired text alignment
        Returns:
        the updated list of KnuthElements
      • findHyphenationPoints

        private void findHyphenationPoints​(LineLayoutManager.Paragraph currPar)
        Find hyphenation points for every word in the current paragraph.
        Parameters:
        currPar - the paragraph whose words will be hyphenated
      • hasLeadingFence

        protected boolean hasLeadingFence​(boolean isNotFirst)
        Line area is always considered to act as a fence.
        Overrides:
        hasLeadingFence in class InlineStackingLayoutManager
        Parameters:
        isNotFirst - ignored
        Returns:
        always true
      • hasTrailingFence

        protected boolean hasTrailingFence​(boolean isNotLast)
        Line area is always considered to act as a fence.
        Overrides:
        hasTrailingFence in class InlineStackingLayoutManager
        Parameters:
        isNotLast - ignored
        Returns:
        always true
      • getHyphenContext

        private HyphContext getHyphenContext​(java.lang.StringBuffer sbChars)
      • addInlineArea

        private void addInlineArea​(LayoutContext context,
                                   LineLayoutManager.LineBreakPosition lbp,
                                   boolean isLastPosition)
        Add a line with inline content
        Parameters:
        context - the context for adding areas
        lbp - the position for which the line is generated
        isLastPosition - true if this is the last position of this LM
      • addBlockArea

        private void addBlockArea​(LayoutContext context,
                                  Position pos,
                                  boolean isLastPosition)
        Add a line with block content
        Parameters:
        context - the context for adding areas
        pos - the position for which the line is generated
        isLastPosition - true if this is the last position of this LM
      • addChildArea

        public void addChildArea​(Area childArea)
        Add a child area to the current area. If this causes the maximum dimension of the current area to be exceeded, the parent LM is called to add it.
        Specified by:
        addChildArea in interface LayoutManager
        Overrides:
        addChildArea in class AbstractLayoutManager
        Parameters:
        childArea - the child area to be added
      • isRestartable

        public boolean isRestartable()
        Returns true if this layout manager is able to re-generate its Knuth elements after an IPD change.
        Specified by:
        isRestartable in interface LayoutManager
        Overrides:
        isRestartable in class AbstractBaseLayoutManager
        Returns:
        true if this layout manager can be restarted after an IPD change
      • handleOverflow

        public boolean handleOverflow​(int milliPoints)
        Whether this LM can handle horizontal overflow error messages (only a BlockContainerLayoutManager can).
        Parameters:
        milliPoints - horizontal overflow
        Returns:
        true if handled by a BlockContainerLayoutManager