Class TextLayoutManager

All Implemented Interfaces:
PercentBaseContext, Constants, InlineLevelLayoutManager, LayoutManager

public class TextLayoutManager extends LeafNodeLayoutManager
LayoutManager for text (a sequence of characters) which generates one or more inline areas.
  • Field Details

    • SOFT_HYPHEN_PENALTY

      private static final int SOFT_HYPHEN_PENALTY
      See Also:
    • LOG

      private static final org.apache.commons.logging.Log LOG
      logging instance
    • mappings

      private final List<GlyphMapping> mappings
    • BREAK_CHARS

      private static final String BREAK_CHARS
      Non-space characters on which we can end a line.
      See Also:
    • foText

      private final FOText foText
    • letterSpaceAdjustArray

      private final MinOptMax[] letterSpaceAdjustArray
      Contains an array of widths to adjust for kerning. The first entry can be used to influence the start position of the first letter. The entry i+1 defines the cursor advancement after the character i. A null entry means no special advancement.
    • spaceFont

      private Font spaceFont
      Font used for the space between words.
    • nextStart

      private int nextStart
      Start index of next TextArea
    • spaceCharIPD

      private int spaceCharIPD
      size of a space character (U+0020) glyph in current font
    • wordSpaceIPD

      private MinOptMax wordSpaceIPD
    • letterSpaceIPD

      private MinOptMax letterSpaceIPD
    • hyphIPD

      private int hyphIPD
      size of the hyphen character glyph in current font
    • hasChanged

      private boolean hasChanged
    • returnedIndices

      private int[] returnedIndices
    • changeOffset

      private int changeOffset
    • thisStart

      private int thisStart
    • tempStart

      private int tempStart
    • changeList

      private List changeList
    • alignmentContext

      private AlignmentContext alignmentContext
    • lineStartBAP

      private int lineStartBAP
      The width to be reserved for border and padding at the start of the line.
    • lineEndBAP

      private int lineEndBAP
      The width to be reserved for border and padding at the end of the line.
    • keepTogether

      private boolean keepTogether
    • auxiliaryPosition

      private final Position auxiliaryPosition
    • userAgent

      private FOUserAgent userAgent
  • Constructor Details

    • TextLayoutManager

      public TextLayoutManager(FOText node, FOUserAgent userAgent)
      Create a Text layout manager.
      Parameters:
      node - The FOText object to be rendered
  • Method Details

    • makeZeroWidthPenalty

      private KnuthPenalty makeZeroWidthPenalty(int penaltyValue)
    • makeAuxiliaryZeroWidthBox

      private KnuthBox makeAuxiliaryZeroWidthBox()
    • 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
    • addAreas

      public void addAreas(PositionIterator posIter, LayoutContext context)
      Generate and add areas to parent area. This can either generate an area for each TextArea and each space, or an area containing all text with a parameter controlling the size of the word space. The latter is most efficient for PDF generation. Set size of each area.
      Specified by:
      addAreas in interface LayoutManager
      Overrides:
      addAreas in class LeafNodeLayoutManager
      Parameters:
      posIter - Iterator over Position information returned by this LayoutManager.
      context - LayoutContext for adjustments
    • addMappingAreas

      private void addMappingAreas(GlyphMapping mapping, int wordSpaceCount, int letterSpaceCount, int firstMappingIndex, int lastMappingIndex, MinOptMax realWidth, LayoutContext context)
    • addGlyphMapping

      private void addGlyphMapping(GlyphMapping mapping)
    • addGlyphMapping

      private void addGlyphMapping(int index, GlyphMapping mapping)
    • removeGlyphMapping

      private void removeGlyphMapping(int index)
    • getGlyphMapping

      private GlyphMapping getGlyphMapping(int index)
    • 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 LeafNodeLayoutManager
      Parameters:
      context - the LayoutContext used to store layout information
      alignment - the desired text alignment
      Returns:
      the list of KnuthElements
    • processLinebreak

      private KnuthSequence processLinebreak(List returnList, KnuthSequence sequence)
    • processLeftoverGlyphMapping

      private void processLeftoverGlyphMapping(int alignment, KnuthSequence sequence, GlyphMapping mapping, boolean breakOpportunityAfter)
    • processWhitespace

      private GlyphMapping processWhitespace(int alignment, KnuthSequence sequence, boolean breakOpportunity, int level)
    • processWord

      private GlyphMapping processWord(int alignment, KnuthSequence sequence, GlyphMapping prevMapping, char ch, boolean breakOpportunity, boolean checkEndsWithHyphen, int level, boolean retainControls)
    • addALetterSpaceTo

      public List addALetterSpaceTo(List oldList)
      Tell the LM to modify its data, adding a letter space to the word fragment represented by the given elements, and returning the corrected elements
      Specified by:
      addALetterSpaceTo in interface InlineLevelLayoutManager
      Overrides:
      addALetterSpaceTo in class LeafNodeLayoutManager
      Parameters:
      oldList - the elements which must be given one more letter space
      Returns:
      the new elements replacing the old ones
    • addALetterSpaceTo

      public List addALetterSpaceTo(List oldList, int depth)
      Tell the LM to modify its data, adding a letter space to the word fragment represented by the given elements, and returning the corrected elements Only TextLM has a meaningful implementation of this method
      Specified by:
      addALetterSpaceTo in interface InlineLevelLayoutManager
      Overrides:
      addALetterSpaceTo in class LeafNodeLayoutManager
      Parameters:
      oldList - the elements which must be given one more letter space
      depth - the depth at which the Positions for this LM in oldList are found
      Returns:
      the new elements replacing the old ones
    • hyphenate

      public void hyphenate(Position pos, HyphContext hyphContext)
      Tell the LM to hyphenate a word
      Specified by:
      hyphenate in interface InlineLevelLayoutManager
      Overrides:
      hyphenate in class LeafNodeLayoutManager
      Parameters:
      pos - the Position referring to the word
      hyphContext - the HyphContext storing hyphenation information
    • applyChanges

      public boolean applyChanges(List oldList)
      Tell the LM to apply the changes due to hyphenation
      Specified by:
      applyChanges in interface InlineLevelLayoutManager
      Overrides:
      applyChanges in class LeafNodeLayoutManager
      Parameters:
      oldList - the list of the old elements the changes refer to
      Returns:
      true if the LM had to change its data, false otherwise
    • applyChanges

      public boolean applyChanges(List oldList, int depth)
      Tell the LM to apply the changes due to hyphenation Only TextLM has a meaningful implementation of this method
      Specified by:
      applyChanges in interface InlineLevelLayoutManager
      Overrides:
      applyChanges in class LeafNodeLayoutManager
      Parameters:
      oldList - the list of the old elements the changes refer to
      depth - the depth at which the Positions for this LM in oldList are found
      Returns:
      true if the LM had to change its data, false otherwise
    • 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 LeafNodeLayoutManager
      Parameters:
      oldList - the elements to replace
      alignment - the desired text alignment
      Returns:
      the updated list of KnuthElements
    • getWordChars

      public String getWordChars(Position pos)
      Get the word chars corresponding to the given position.
      Specified by:
      getWordChars in interface InlineLevelLayoutManager
      Overrides:
      getWordChars in class LeafNodeLayoutManager
      Parameters:
      pos - the position referring to the needed word chars.
      Returns:
      the word chars
    • addElementsForASpace

      private void addElementsForASpace(List baseList, int alignment, GlyphMapping mapping, int leafValue)
    • getElementsForBreakingSpace

      private List getElementsForBreakingSpace(int alignment, GlyphMapping mapping, Position pos2, int p2WidthOffset, Position pos3, int p3WidthOffset, boolean skipZeroCheck)
    • getElementsForJustifiedText

      private List getElementsForJustifiedText(GlyphMapping mapping, Position pos2, int p2WidthOffset, Position pos3, int p3WidthOffset, boolean skipZeroCheck, int shrinkability)
    • addElementsForAWordFragment

      private void addElementsForAWordFragment(List baseList, int alignment, GlyphMapping mapping, int leafValue)
    • addElementsForAHyphen

      private void addElementsForAHyphen(List baseList, int alignment, int widthIfBreakOccurs, MinOptMax widthIfNoBreakOccurs, boolean unflagged)
    • getChangeBarList

      public List<ChangeBar> getChangeBarList()
      Description copied from class: AbstractBaseLayoutManager
      Returns the active change bar list.
      Overrides:
      getChangeBarList in class AbstractBaseLayoutManager
      Returns:
      The active change bar list
    • toString

      public String toString()
      Overrides:
      toString in class AbstractLayoutManager