Class BlockStackingLayoutManager

All Implemented Interfaces:
PercentBaseContext, Constants, BlockLevelLayoutManager, LayoutManager
Direct Known Subclasses:
FlowLayoutManager, FootnoteBodyLayoutManager, ListItemContentLayoutManager, MultiCaseLayoutManager, MultiSwitchLayoutManager, SpacedBorderedPaddedBlockLayoutManager, StaticContentLayoutManager, TableAndCaptionLayoutManager, TableCaptionLayoutManager, TableCellLayoutManager

public abstract class BlockStackingLayoutManager extends AbstractLayoutManager implements BlockLevelLayoutManager
Base LayoutManager class for all areas which stack their child areas in the block-progression direction, such as Flow, Block, ListBlock.
  • Field Details

    • parentArea

      protected BlockParent parentArea
      parent area
    • bpUnit

      protected int bpUnit
      Value of the block-progression-unit (non-standard property)
    • adjustedSpaceBefore

      protected int adjustedSpaceBefore
      space-before value adjusted for block-progression-unit handling
    • adjustedSpaceAfter

      protected int adjustedSpaceAfter
      space-after value adjusted for block-progression-unit handling
    • storedList

      protected List<KnuthElement> storedList
      Only used to store the original list when createUnitElements is called
    • breakBeforeServed

      protected boolean breakBeforeServed
      Indicates whether break before has been served or not
    • firstVisibleMarkServed

      protected boolean firstVisibleMarkServed
      Indicates whether the first visible mark has been returned by this LM, yet
    • referenceIPD

      protected int referenceIPD
      Reference IPD available
    • startIndent

      protected int startIndent
      the effective start-indent value
    • endIndent

      protected int endIndent
      the effective end-indent value
    • foSpaceBefore

      protected MinOptMax foSpaceBefore
      Holds the (one-time use) fo:block space-before and -after properties. Large fo:blocks are split into multiple Area. Blocks to accomodate the subsequent regions (pages) they are placed on. space-before is applied at the beginning of the first Block and space-after at the end of the last Block used in rendering the fo:block.
    • foSpaceAfter

      protected MinOptMax foSpaceAfter
      see foSpaceBefore
  • Constructor Details

    • BlockStackingLayoutManager

      public BlockStackingLayoutManager(FObj node)
      Parameters:
      node - the fo this LM deals with
  • Method Details

    • getCurrentArea

      protected BlockParent getCurrentArea()
      Returns:
      current area being filled
    • setCurrentArea

      protected void setCurrentArea(BlockParent parentArea)
      Set the current area being filled.
      Parameters:
      parentArea - the current area to be filled
    • addBlockSpacing

      public void addBlockSpacing(double adjust, MinOptMax minoptmax)
      Add a block spacer for space before and space after a block. This adds an empty Block area that acts as a block space.
      Parameters:
      adjust - the adjustment value
      minoptmax - the min/opt/max value of the spacing
    • addChildToArea

      protected void addChildToArea(Area childArea, BlockParent parentArea)
      Add the childArea to the passed area. Called by child LayoutManager when it has filled one of its areas. The LM should already have an Area in which to put the child. See if the area will fit in the current area. If so, add it. Otherwise initiate breaking.
      Parameters:
      childArea - the area to add: will be some block-stacked Area.
      parentArea - the area in which to add the childArea
    • addChildArea

      public void addChildArea(Area childArea)
      Add the childArea to the current area. Called by child LayoutManager when it has filled one of its areas. The LM should already have an Area in which to put the child. See if the area will fit in the current area. If so, add it. Otherwise initiate breaking.
      Specified by:
      addChildArea in interface LayoutManager
      Overrides:
      addChildArea in class AbstractLayoutManager
      Parameters:
      childArea - the area to add: will be some block-stacked Area.
    • flush

      protected void flush()
      Force current area to be added to parent area.
    • getAuxiliaryPosition

      protected Position getAuxiliaryPosition()
      Returns:
      a cached auxiliary Position instance used for things like spaces.
    • neededUnits

      protected int neededUnits(int len)
      Parameters:
      len - length in millipoints to span with bp units
      Returns:
      the minimum integer n such that n * bpUnit >= len
    • updateContentAreaIPDwithOverconstrainedAdjust

      protected int updateContentAreaIPDwithOverconstrainedAdjust()
      Determines and sets the content area IPD based on available reference area IPD, start- and end-indent properties. end-indent is adjusted based on overconstrained geometry rules, if necessary.
      Returns:
      the resulting content area IPD
    • updateContentAreaIPDwithOverconstrainedAdjust

      protected int updateContentAreaIPDwithOverconstrainedAdjust(int contentIPD)
      Sets the content area IPD by directly supplying the value. end-indent is adjusted based on overconstrained geometry rules, if necessary.
      Parameters:
      contentIPD - the IPD of the content
      Returns:
      the resulting content area IPD
    • 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, Stack lmStack, Position restartPosition, LayoutManager restartAtLM)
      Returns an updated list of Knuth elements corresponding to this layout manager, after a change of IPD has been detected.
      Specified by:
      getNextKnuthElements in interface LayoutManager
      Overrides:
      getNextKnuthElements in class AbstractBaseLayoutManager
      Parameters:
      context - the layout context
      alignment - the alignment
      lmStack - the stack of LMs that are active at the IPD change
      restartPosition - the position corresponding to the element finishing the page before the IPD change
      restartAtLM - if not null, the layout manager from which to restart. That is, the IPD change occurs between two block elements and not inside a paragraph
      Returns:
      an updated list of elements, taking the new IPD into account
    • makeChildLayoutContext

      protected LayoutContext makeChildLayoutContext(LayoutContext context)
      Creates and initializes a LayoutContext to pass to the child LM
      Parameters:
      context - the parent LayoutContext
      Returns:
      a new child layout context
    • addFirstVisibleMarks

      protected void addFirstVisibleMarks(List<ListElement> elements, LayoutContext context, int alignment)
      Checks if this LM's first "visible marks" (= borders, padding, spaces) have already been processed, and if necessary, adds corresponding elements to the specified list, and updates the given layout context accordingly.
      Parameters:
      elements - the element list
      context - the layout context
      alignment - the vertical alignment
    • addLastVisibleMarks

      protected void addLastVisibleMarks(List<ListElement> elements, LayoutContext context, int alignment)
      Adds elements the LM's last/closing marks to the specified list, and updates the layout context accordingly.
      Parameters:
      elements - the element list
      context - the layout context
      alignment - the vertical alignment
    • breakBeforeServed

      protected boolean breakBeforeServed(LayoutContext context, List<ListElement> elements)
      Check whether there is a break-before condition. If so, and the specified context allows it, add the necessary elements to the given elements list.
      Parameters:
      context - the layout context
      elements - the element list
      Returns:
      false if there is a break-before condition, and it has not been served; true otherwise
    • getNextChildElements

      protected List<ListElement> getNextChildElements(LayoutManager childLM, LayoutContext context, LayoutContext childLC, int alignment, Stack<LayoutManager> lmStack, Position restartPosition, LayoutManager restartAtLM)
      Gets the next set of child elements for the given childLM. The default implementation basically copies the pending marks to the child layout context, and subsequently calls the appropriate variant of childLM.getNextKnuthElements(), passing it all relevant parameters.
      Parameters:
      childLM - the current child LM
      context - the layout context
      childLC - the child layout context
      alignment - the vertical alignment
      lmStack - the stack of currently active LMs (if any)
      restartPosition - the position to restart from (if any)
      restartAtLM - the LM to restart from (if any)
      Returns:
      list of elements corresponding to the content generated by childLM
    • addInBetweenBreak

      protected void addInBetweenBreak(List<ListElement> contentList, LayoutContext parentLC, LayoutContext childLC)
      Adds a break element to the content list between individual child elements.
      Parameters:
      contentList - the content list
      parentLC - the parent layout context
      childLC - the currently active child layout context
    • 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)
      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 AbstractLayoutManager
      Parameters:
      oldList - the elements to replace
      alignment - the desired text alignment
      Returns:
      the updated list of KnuthElements
    • getParentKeepTogether

      protected Keep getParentKeepTogether()
      Retrieves and returns the keep-together strength from the parent element.
      Returns:
      the keep-together strength
    • mustKeepTogether

      public boolean mustKeepTogether()
      Specified by:
      mustKeepTogether in interface BlockLevelLayoutManager
      Returns:
      true if this element must be kept together
    • 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.
    • getKeepTogether

      public Keep getKeepTogether()
      Returns the keep-together strength for this element.
      Specified by:
      getKeepTogether in interface BlockLevelLayoutManager
      Returns:
      the keep-together 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
    • 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
    • getKeepTogetherProperty

      public KeepProperty getKeepTogetherProperty()
      Returns the keep-together property specified on the FObj. Default implementation throws a IllegalStateException. Must be implemented by the subclass, if applicable.
      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. Default implementation throws a IllegalStateException. Must be implemented by the subclass, if applicable.
      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. Default implementation throws a IllegalStateException. Must be implemented by the subclass, if applicable.
      Specified by:
      getKeepWithNextProperty in interface BlockLevelLayoutManager
      Returns:
      the keep-together property
    • addPendingMarks

      protected void addPendingMarks(LayoutContext context)
      Adds the unresolved elements for border and padding to a layout context so break possibilities can be properly constructed.
      Parameters:
      context - the layout context
    • getSpaceBeforeProperty

      protected SpaceProperty getSpaceBeforeProperty()
      Returns:
      the space-before property
    • getSpaceAfterProperty

      protected SpaceProperty getSpaceAfterProperty()
      Returns:
      the space-after property
    • addKnuthElementsForBorderPaddingBefore

      protected void addKnuthElementsForBorderPaddingBefore(List returnList, boolean isFirst)
      Creates Knuth elements for before border padding and adds them to the return list.
      Parameters:
      returnList - return list to add the additional elements to
      isFirst - true if this is the first time a layout manager instance needs to generate border and padding
    • addKnuthElementsForBorderPaddingAfter

      protected void addKnuthElementsForBorderPaddingAfter(List returnList, boolean isLast)
      Creates Knuth elements for after border padding and adds them to the return list.
      Parameters:
      returnList - return list to add the additional elements to
      isLast - true if this is the last time a layout manager instance needs to generate border and padding
    • addKnuthElementsForBreakBefore

      protected boolean addKnuthElementsForBreakBefore(List returnList, LayoutContext context)
      Creates Knuth elements for break-before and adds them to the return list.
      Parameters:
      returnList - return list to add the additional elements to
      context - the layout context
      Returns:
      true if an element has been added due to a break-before.
    • getBreakBefore

      public int getBreakBefore()
      Returns the highest priority break-before value on this layout manager or its relevant descendants.
      Returns:
      the break-before value (Constants.EN_*)
      See Also:
    • addKnuthElementsForBreakAfter

      protected boolean addKnuthElementsForBreakAfter(List returnList, LayoutContext context)
      Creates Knuth elements for break-after and adds them to the return list.
      Parameters:
      returnList - return list to add the additional elements to
      context - the layout context
      Returns:
      true if an element has been added due to a break-after.
    • addKnuthElementsForSpaceBefore

      protected void addKnuthElementsForSpaceBefore(List returnList, int alignment)
      Creates Knuth elements for space-before and adds them to the return list.
      Parameters:
      returnList - return list to add the additional elements to
      alignment - vertical alignment
    • addKnuthElementsForSpaceAfter

      protected void addKnuthElementsForSpaceAfter(List returnList, int alignment)
      Creates Knuth elements for space-after and adds them to the return list.
      Parameters:
      returnList - return list to add the additional elements to
      alignment - vertical alignment
    • wrapPositionElements

      protected void wrapPositionElements(List sourceList, List targetList)
      "wrap" the Position inside each element moving the elements from SourceList to targetList
      Parameters:
      sourceList - source list
      targetList - target list receiving the wrapped position elements
    • wrapPositionElements

      protected void wrapPositionElements(List sourceList, List targetList, boolean force)
      "wrap" the Position inside each element moving the elements from SourceList to targetList
      Parameters:
      sourceList - source list
      targetList - target list receiving the wrapped position elements
      force - if true, every Position is wrapped regardless of its LM of origin
    • wrapPositionElement

      protected void wrapPositionElement(ListElement el, List targetList, boolean force)
      "wrap" the Position inside the given element and add it to the target list.
      Parameters:
      el - the list element
      targetList - target list receiving the wrapped position elements
      force - if true, every Position is wrapped regardless of its LM of origin
    • getIPIndents

      protected int getIPIndents()
      Returns:
      the sum of start-indent and end-indent
    • getContentAreaIPD

      public int getContentAreaIPD()
      Returns the IPD of the content area
      Specified by:
      getContentAreaIPD in interface LayoutManager
      Overrides:
      getContentAreaIPD in class AbstractBaseLayoutManager
      Returns:
      the IPD of the content area
    • setContentAreaIPD

      protected void setContentAreaIPD(int contentAreaIPD)
      Sets the IPD of the content area
      Parameters:
      contentAreaIPD - the IPD of the content area
    • getContentAreaBPD

      public int getContentAreaBPD()
      Returns the BPD of the content area
      Specified by:
      getContentAreaBPD in interface LayoutManager
      Overrides:
      getContentAreaBPD in class AbstractBaseLayoutManager
      Returns:
      the BPD of the content area
    • reset

      public void reset()
      Re-initializes this layout manager in order to re-generate its Knuth elements according to a new IPD value.
      Specified by:
      reset in interface LayoutManager
      Overrides:
      reset in class AbstractLayoutManager
    • 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
    • isRestartAtLM

      public boolean isRestartAtLM()