Class LineLayoutManager

All Implemented Interfaces:
PercentBaseContext, Constants, BlockLevelLayoutManager, BreakOpportunity, InlineLevelLayoutManager, LayoutManager

public class LineLayoutManager extends InlineStackingLayoutManager implements BlockLevelLayoutManager
LayoutManager for lines. It builds one or more lines containing inline areas generated by its sub layout managers. A break is found for each line which may contain one of more breaks from the child layout managers. Once a break is found then it is return for the parent layout manager to handle. When the areas are being added to the page this manager creates a line area to contain the inline areas added by the child layout managers.
  • Field Details

    • 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:
  • Constructor Details

    • 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 Details

    • initialize

      public void initialize()
      initialize the layout manager. Allows each layout manager to calculate often used values.
      Specified by:
      initialize in interface LayoutManager
      Overrides:
      initialize in class AbstractLayoutManager
    • getNextKnuthElements

      public 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 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:
    • mustKeepTogether

      public boolean mustKeepTogether()
      Specified by:
      mustKeepTogether in interface BlockLevelLayoutManager
      Returns:
      true if this element must be kept together
    • getKeepTogetherProperty

      public KeepProperty getKeepTogetherProperty()
      Returns the keep-together property specified on the FObj.
      Specified by:
      getKeepTogetherProperty in interface BlockLevelLayoutManager
      Returns:
      the keep-together property
    • getKeepWithPreviousProperty

      public KeepProperty getKeepWithPreviousProperty()
      Returns the keep-with-previous property specified on the FObj.
      Specified by:
      getKeepWithPreviousProperty in interface BlockLevelLayoutManager
      Returns:
      the keep-together property
    • getKeepWithNextProperty

      public KeepProperty getKeepWithNextProperty()
      Returns the keep-with-next property specified on the FObj.
      Specified by:
      getKeepWithNextProperty in interface BlockLevelLayoutManager
      Returns:
      the keep-together property
    • getKeepTogether

      public Keep getKeepTogether()
      Returns the keep-together strength for this element.
      Specified by:
      getKeepTogether in interface BlockLevelLayoutManager
      Returns:
      the keep-together strength
    • mustKeepWithPrevious

      public boolean mustKeepWithPrevious()
      Specified by:
      mustKeepWithPrevious in interface BlockLevelLayoutManager
      Returns:
      true if this element must be kept with the previous element.
    • mustKeepWithNext

      public boolean mustKeepWithNext()
      Specified by:
      mustKeepWithNext in interface BlockLevelLayoutManager
      Returns:
      true if this element must be kept with the next element.
    • getKeepWithNext

      public Keep getKeepWithNext()
      Returns the keep-with-next strength for this element.
      Specified by:
      getKeepWithNext in interface BlockLevelLayoutManager
      Returns:
      the keep-with-next strength
    • getKeepWithPrevious

      public Keep getKeepWithPrevious()
      Returns the keep-with-previous strength for this element.
      Specified by:
      getKeepWithPrevious in interface BlockLevelLayoutManager
      Returns:
      the keep-with-previous strength
    • 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
    • discardSpace

      public void discardSpace(KnuthGlue spaceGlue)
      Discard space.
      Specified by:
      discardSpace in interface BlockLevelLayoutManager
      Parameters:
      spaceGlue - the space
    • getChangedKnuthElements

      public List getChangedKnuthElements(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 List getChangedKnuthElements(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
    • 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
    • hasLineAreaDescendant

      public boolean hasLineAreaDescendant()
      Description copied from interface: LayoutManager
      Whether the FO handled by this layout manager has a descendant (including itself) that will generate a line-area.
      Specified by:
      hasLineAreaDescendant in interface LayoutManager
      Overrides:
      hasLineAreaDescendant in class AbstractLayoutManager
      Returns:
      true if a descendant line-area will be generated, false otherwise
    • getBaselineOffset

      public int getBaselineOffset()
      Description copied from interface: LayoutManager
      Returns the position of the dominant-baseline of this FO's first descendant line-area.

      The behavior of this method is undefined if this FO has no descendant line-area, and an exception may be thrown. See LayoutManager.hasLineAreaDescendant()

      Specified by:
      getBaselineOffset in interface LayoutManager
      Overrides:
      getBaselineOffset in class AbstractLayoutManager
      Returns:
      this FO's space-before plus the distance from the before-edge of its allocation-rectangle to the dominant-baseline of the first line-area descendant
      See Also:
    • addAreas

      public void addAreas(PositionIterator parentIter, LayoutContext context)
      Add the areas with the break points.
      Specified by:
      addAreas in interface LayoutManager
      Overrides:
      addAreas in class AbstractLayoutManager
      Parameters:
      parentIter - the iterator of break positions
      context - the context for adding areas
    • 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
    • getGeneratesBlockArea

      public boolean getGeneratesBlockArea()
      Returns an indication if the layout manager generates a block area.
      Specified by:
      getGeneratesBlockArea in interface LayoutManager
      Overrides:
      getGeneratesBlockArea in class AbstractBaseLayoutManager
      Returns:
      True if the layout manager generates a block area
    • getGeneratesLineArea

      public boolean getGeneratesLineArea()
      Returns an indication if the layout manager generates a line area.
      Specified by:
      getGeneratesLineArea in interface LayoutManager
      Overrides:
      getGeneratesLineArea in class AbstractBaseLayoutManager
      Returns:
      True if the layout manager generates a line area
    • 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