Class LineRenderer

    • Field Detail

      • MIN_MAX_WIDTH_CORRECTION_EPS

        private static final float MIN_MAX_WIDTH_CORRECTION_EPS
        See Also:
        Constant Field Values
      • logger

        private static final org.slf4j.Logger logger
      • maxAscent

        protected float maxAscent
      • maxDescent

        protected float maxDescent
      • levels

        protected byte[] levels
      • maxTextAscent

        float maxTextAscent
      • maxTextDescent

        float maxTextDescent
      • maxBlockAscent

        private float maxBlockAscent
      • maxBlockDescent

        private float maxBlockDescent
    • Constructor Detail

      • LineRenderer

        public LineRenderer()
    • Method Detail

      • layout

        public LayoutResult layout​(LayoutContext layoutContext)
        Description copied from interface: IRenderer
        This method simulates positioning of the renderer, including all of its children, and returns the LayoutResult, representing the layout result, including occupied area, status, i.e. if there was enough place to fit the renderer subtree, etc. LayoutResult can be extended to return custom layout results for custom elements, e.g. TextRenderer uses TextLayoutResult as its result. This method can be called standalone to learn how much area the renderer subtree needs, or can be called before IRenderer.draw(DrawContext), to prepare the renderer to be flushed to the output stream.
        Parameters:
        layoutContext - the description of layout area and any other additional information
        Returns:
        result of the layout process
      • getMaxAscent

        public float getMaxAscent()
      • getMaxDescent

        public float getMaxDescent()
      • getYLine

        public float getYLine()
      • getLeadingValue

        public float getLeadingValue​(Leading leading)
      • drawChildren

        public void drawChildren​(DrawContext drawContext)
        Description copied from class: AbstractRenderer
        Performs the drawing operation for all children of this renderer.
        Overrides:
        drawChildren in class AbstractRenderer
        Parameters:
        drawContext - the context (canvas, document, etc) of this drawing operation.
      • getNextRenderer

        public IRenderer getNextRenderer()
        Description copied from interface: IRenderer
        Gets a new instance of this class to be used as a next renderer, after this renderer is used, if IRenderer.layout(LayoutContext) is called more than once.
        Returns:
        new renderer instance
      • getFirstYLineRecursively

        protected java.lang.Float getFirstYLineRecursively()
        Description copied from class: AbstractRenderer
        Gets the first yLine of the nested children recursively. E.g. for a list, this will be the yLine of the first item (if the first item is indeed a paragraph). NOTE: this method will no go further than the first child.
        Overrides:
        getFirstYLineRecursively in class AbstractRenderer
        Returns:
        the first yline of the nested children, null if there is no text found
      • justify

        public void justify​(float width)
      • getNumberOfSpaces

        protected int getNumberOfSpaces()
      • length

        protected int length()
        Gets the total lengths of characters in this line. Other elements (images, tables) are not taken into account.
        Returns:
        the total lengths of characters in this line.
      • baseCharactersCount

        protected int baseCharactersCount()
        Returns the number of base characters, i.e. non-mark characters
        Returns:
        the number of base non-mark characters
      • toString

        public java.lang.String toString()
        Description copied from class: AbstractRenderer
        Returns a string representation of the renderer.
        Overrides:
        toString in class AbstractRenderer
        Returns:
        a String
        See Also:
        Object.toString()
      • createSplitRenderer

        protected LineRenderer createSplitRenderer()
      • createOverflowRenderer

        protected LineRenderer createOverflowRenderer()
      • adjustChildrenYLine

        protected LineRenderer adjustChildrenYLine()
      • applyLeading

        protected void applyLeading​(float deltaY)
      • containsImage

        public boolean containsImage()
      • retrieveResolvedDeclaredHeight

        protected java.lang.Float retrieveResolvedDeclaredHeight()
        Retrieve the resolved height declaration. If it has a relative height declaration, AbstractRenderer.retrieveHeight() is called.
        Overrides:
        retrieveResolvedDeclaredHeight in class AbstractRenderer
        Returns:
        null if no height declaration is set on the parent, or if its own height declaration cannot be resolved. The float value of the resolved height otherwise
      • hasChildRendererInHtmlMode

        boolean hasChildRendererInHtmlMode()
      • getTopLeadingIndent

        float getTopLeadingIndent​(Leading leading)
      • getBottomLeadingIndent

        float getBottomLeadingIndent​(Leading leading)
      • adjustChildPositionsAfterReordering

        static void adjustChildPositionsAfterReordering​(java.util.List<IRenderer> children,
                                                        float initialXPos)
      • replaceSplitRendererKidFloats

        private void replaceSplitRendererKidFloats​(java.util.Map<java.lang.Integer,​IRenderer> floatsToNextPageSplitRenderers,
                                                   LineRenderer splitRenderer)
      • getLastNonFloatChildRenderer

        private IRenderer getLastNonFloatChildRenderer()
      • getNextTabStop

        private TabStop getNextTabStop​(float curWidth)
      • calculateTab

        private TabStop calculateTab​(IRenderer childRenderer,
                                     float curWidth,
                                     float lineWidth)
        Calculates and sets encountered tab size. Returns null, if processing is finished and layout can be performed for the tab renderer; otherwise, in case when the tab should be processed after the next element in the line, this method returns corresponding tab stop.
      • calculateTab

        private float calculateTab​(Rectangle layoutBox,
                                   float curWidth,
                                   TabStop tabStop,
                                   java.util.List<IRenderer> affectedRenderers,
                                   IRenderer tabRenderer)
        Calculates and sets tab size with the account of the element that is next in the line after the tab. Returns resulting width of the tab.
      • processDefaultTab

        private void processDefaultTab​(IRenderer tabRenderer,
                                       float curWidth,
                                       float lineWidth)
      • updateChildrenParent

        private void updateChildrenParent()
      • trimFirst

        int trimFirst()
        Trim first child text renderers.
        Returns:
        total number of trimmed glyphs.
      • applyOtf

        private BaseDirection applyOtf()
        Apply OTF features and return the last(!) base direction of child renderer
        Returns:
        the last(!) base direction of child renderer.
      • isChildFloating

        static boolean isChildFloating​(IRenderer childRenderer)
      • isInlineBlockChild

        static boolean isInlineBlockChild​(IRenderer child)
      • isForceOverflowForTextRendererPartialResult

        boolean isForceOverflowForTextRendererPartialResult​(IRenderer childRenderer,
                                                            boolean wasXOverflowChanged,
                                                            OverflowPropertyValue oldXOverflow,
                                                            LayoutContext layoutContext,
                                                            Rectangle layoutBox,
                                                            boolean wasParentsHeightClipped)
        Checks if the word that's been split when has been layouted on this line can fit the next line without splitting.
        Parameters:
        childRenderer - the childRenderer containing the split word
        wasXOverflowChanged - true if Property.OVERFLOW_X has been changed during layouting of LineRenderer
        oldXOverflow - the value of Property.OVERFLOW_X before it's been changed during layouting of LineRenderer or null if Property.OVERFLOW_X hasn't been changed
        layoutContext - LayoutContext
        layoutBox - current layoutBox
        wasParentsHeightClipped - true if layoutBox's height has been clipped
        Returns:
        true if the split word can fit the next line without splitting
      • getAscentDescentOfLayoutedChildRenderer

        float[] getAscentDescentOfLayoutedChildRenderer​(IRenderer childRenderer,
                                                        LayoutResult childResult,
                                                        RenderingMode childRenderingMode,
                                                        boolean isInlineBlockChild)
        Extracts ascender and descender of an already layouted childRenderer.
        Parameters:
        childRenderer - an already layouted child who's ascender and descender are to be extracted
        childResult - LayoutResult of the childRenderer based on which ascender and descender are defined
        childRenderingMode - rendering mode
        isInlineBlockChild - true if childRenderer isInlineBlockChild(IRenderer)
        Returns:
        a two-element float array where first element is ascender value and second element is descender value
      • updateAscentDescentAfterTextRendererSequenceProcessing

        float[] updateAscentDescentAfterTextRendererSequenceProcessing​(int newChildPos,
                                                                       LineRenderer.LineAscentDescentState lineAscentDescentStateBeforeTextRendererSequence,
                                                                       java.util.Map<java.lang.Integer,​float[]> textRendererSequenceAscentDescent)
        Updates maxAscent, maxDescent, maxTextAscent and maxTextDescent after a TextRenderer sequence has been fully processed.
        Parameters:
        newChildPos - position of the last TextRenderer child of the sequence to remain on the line
        lineAscentDescentStateBeforeTextRendererSequence - a LineRenderer.LineAscentDescentState containing LineRenderer's maxAscent, maxDescent, maxTextAscent, maxTextDescent before TextRenderer sequence start
        textRendererSequenceAscentDescent - a Map with TextRenderer children's positions as keys and float arrays consisting of maxAscent, maxDescent, maxTextAscent, maxTextDescent of the corresponding TextRenderer children.
        Returns:
        a two-element float array where first element is a new LineRenderer's ascender and second element is a new LineRenderer's descender
      • updateBidiLevels

        private void updateBidiLevels​(int totalNumberOfTrimmedGlyphs,
                                      BaseDirection baseDirection)
      • resolveChildrenFonts

        private void resolveChildrenFonts()
        While resolving TextRenderer may split into several ones with different fonts.
      • decreaseRelativeWidthByChildAdditionalWidth

        private float decreaseRelativeWidthByChildAdditionalWidth​(IRenderer childRenderer,
                                                                  float normalizedChildWidth)
      • adjustChildrenYLineDefaultMode

        private void adjustChildrenYLineDefaultMode()
      • hasInlineBlocksWithVerticalAlignment

        private boolean hasInlineBlocksWithVerticalAlignment()
      • adjustChildrenXLine

        private void adjustChildrenXLine()
      • getMinMaxX

        private float[] getMinMaxX()
      • applyTextAnchor

        private float applyTextAnchor​(float textWidth)