Class TableRenderer

    • Field Detail

      • captionRenderer

        protected DivRenderer captionRenderer
      • isOriginalNonSplitRenderer

        protected boolean isOriginalNonSplitRenderer
        True for newly created renderer. For split renderers this is set to false. Used for tricky layout.
      • columnWidths

        private float[] columnWidths
      • heights

        private java.util.List<java.lang.Float> heights
      • countedColumnWidth

        private float[] countedColumnWidth
      • totalWidthForColumns

        private float totalWidthForColumns
      • topBorderMaxWidth

        private float topBorderMaxWidth
    • Constructor Detail

      • TableRenderer

        private TableRenderer()
      • TableRenderer

        public TableRenderer​(Table modelElement,
                             Table.RowRange rowRange)
        Creates a TableRenderer from a Table which will partially render the table.
        Parameters:
        modelElement - the table to be rendered by this renderer
        rowRange - the table rows to be rendered
      • TableRenderer

        public TableRenderer​(Table modelElement)
        Creates a TableRenderer from a Table.
        Parameters:
        modelElement - the table to be rendered by this renderer
    • Method Detail

      • applyBorderBox

        protected Rectangle applyBorderBox​(Rectangle rect,
                                           Border[] borders,
                                           boolean reverse)
        Description copied from class: AbstractRenderer
        Applies the given border box (borders) on the given rectangle
        Overrides:
        applyBorderBox in class AbstractRenderer
        Parameters:
        rect - a rectangle paddings will be applied on.
        borders - the borders to be applied on the given rectangle
        reverse - indicates whether the border box will be applied inside (in case of false) or outside (in case of false) the rectangle.
        Returns:
        a border box of the renderer
      • applyPaddings

        protected Rectangle applyPaddings​(Rectangle rect,
                                          UnitValue[] paddings,
                                          boolean reverse)
        Description copied from class: AbstractRenderer
        Applies given paddings to the given rectangle.
        Overrides:
        applyPaddings in class AbstractRenderer
        Parameters:
        rect - a rectangle paddings will be applied on.
        paddings - the paddings to be applied on the given rectangle
        reverse - indicates whether paddings will be applied inside (in case of false) or outside (in case of true) the rectangle.
        Returns:
        a border box of the renderer
      • applySpacing

        private Rectangle applySpacing​(Rectangle rect,
                                       float horizontalSpacing,
                                       float verticalSpacing,
                                       boolean reverse)
        Applies the given spacings on the given rectangle
        Parameters:
        rect - a rectangle spacings will be applied on.
        horizontalSpacing - the horizontal spacing to be applied on the given rectangle
        verticalSpacing - the vertical spacing to be applied on the given rectangle
        reverse - indicates whether the spacings will be applied inside (in case of false) or outside (in case of false) the rectangle.
        Returns:
        a border box of the renderer
      • applySingleSpacing

        private Rectangle applySingleSpacing​(Rectangle rect,
                                             float spacing,
                                             boolean isHorizontal,
                                             boolean reverse)
        Applies the given horizontal or vertical spacing on the given rectangle
        Parameters:
        rect - a rectangle spacings will be applied on.
        spacing - the horizontal or vertical spacing to be applied on the given rectangle
        isHorizontal - defines whether the provided spacing should be applied as a horizontal or a vertical one
        reverse - indicates whether the spacings will be applied inside (in case of false) or outside (in case of false) the rectangle.
        Returns:
        a border box of the renderer
      • getTable

        Table getTable()
      • initializeHeaderAndFooter

        private void initializeHeaderAndFooter​(boolean isFirstOnThePage)
      • initializeCaptionRenderer

        private void initializeCaptionRenderer​(Div caption)
      • isOriginalRenderer

        private boolean isOriginalRenderer()
      • layout

        public LayoutResult layout​(LayoutContext layoutContext)
        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
      • draw

        public void draw​(DrawContext drawContext)
        Flushes the renderer subtree contents, i.e. draws itself on canvas, adds necessary objects to the PdfDocument etc.
        Specified by:
        draw in interface IRenderer
        Overrides:
        draw in class AbstractRenderer
        Parameters:
        drawContext - contains the PdfDocument to which the renderer subtree if flushed, the PdfCanvas on which the renderer subtree is drawn and other additional parameters needed to perform drawing
      • drawChildren

        public void drawChildren​(DrawContext drawContext)
        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.
      • drawBackgrounds

        protected void drawBackgrounds​(DrawContext drawContext)
      • drawCaption

        protected void drawCaption​(DrawContext drawContext)
      • getNextRenderer

        public IRenderer getNextRenderer()
        Gets a new instance of this class to be used as a next renderer, after this renderer is used, if layout(LayoutContext) is called more than once.

        If a renderer overflows to the next area, iText uses this method to create a renderer for the overflow part. So if one wants to extend TableRenderer, one should override this method: otherwise the default method will be used and thus the default rather than the custom renderer will be created.

        Returns:
        new renderer instance
      • move

        public void move​(float dxRight,
                         float dyUp)
        Moves the renderer subtree by the specified offset. This method affects occupied area of the renderer.
        Specified by:
        move in interface IRenderer
        Overrides:
        move in class AbstractRenderer
        Parameters:
        dxRight - the x-axis offset in points. Positive value will move the renderer subtree to the right.
        dyUp - the y-axis offset in points. Positive value will move the renderer subtree to the top.
      • split

        protected TableRenderer[] split​(int row,
                                        boolean hasContent)
      • split

        protected TableRenderer[] split​(int row,
                                        boolean hasContent,
                                        boolean cellWithBigRowspanAdded)
      • initializeTableLayoutBorders

        private void initializeTableLayoutBorders()
      • correctRowRange

        private void correctRowRange()
      • drawBorder

        public void drawBorder​(DrawContext drawContext)
        Description copied from class: AbstractRenderer
        Performs the drawing operation for the border of this renderer, if defined by any of the Property.BORDER values in either the layout element or this IRenderer itself.
        Overrides:
        drawBorder in class AbstractRenderer
        Parameters:
        drawContext - the context (canvas, document, etc) of this drawing operation.
      • drawBorders

        protected void drawBorders​(DrawContext drawContext)
      • drawBorders

        private void drawBorders​(DrawContext drawContext,
                                 boolean hasHeader,
                                 boolean hasFooter)
      • isEmptyTableRenderer

        private boolean isEmptyTableRenderer()
      • applyFixedXOrYPosition

        private void applyFixedXOrYPosition​(boolean isXPosition,
                                            Rectangle layoutBox)
      • adjustFooterAndFixOccupiedArea

        private void adjustFooterAndFixOccupiedArea​(Rectangle layoutBox,
                                                    float verticalBorderSpacing)
        If there is some space left, we will move the footer up, because initially the footer is at the very bottom of the area. We also will adjust the occupied area by the footer's size if it is present.
        Parameters:
        layoutBox - the layout box which represents the area which is left free.
      • adjustCaptionAndFixOccupiedArea

        private void adjustCaptionAndFixOccupiedArea​(Rectangle layoutBox,
                                                     float verticalBorderSpacing)
        If there is some space left, we will move the caption up, because initially the caption is at the very bottom of the area. We also will adjust the occupied area by the caption's size if it is present.
        Parameters:
        layoutBox - the layout box which represents the area which is left free.
      • correctLayoutedCellsOccupiedAreas

        private void correctLayoutedCellsOccupiedAreas​(LayoutResult[] splits,
                                                       int row,
                                                       int[] targetOverflowRowIndex,
                                                       java.lang.Float blockMinHeight,
                                                       Rectangle layoutBox,
                                                       java.util.List<java.lang.Boolean> rowsHasCellWithSetHeight,
                                                       boolean isLastRenderer,
                                                       boolean processBigRowspan,
                                                       boolean skip)
      • correctRowCellsOccupiedAreas

        private void correctRowCellsOccupiedAreas​(LayoutResult[] splits,
                                                  int row,
                                                  int[] targetOverflowRowIndex,
                                                  int currentRowIndex,
                                                  java.util.List<java.lang.Boolean> rowsHasCellWithSetHeight,
                                                  float cumulativeShift,
                                                  float additionalCellHeight)
      • setRowRange

        private void setRowRange​(Table.RowRange rowRange)
        This method is used to set row range for table renderer during creating a new renderer. The purpose to use this method is to remove input argument RowRange from createOverflowRenderer and createSplitRenderer methods.
      • initFooterOrHeaderRenderer

        private TableRenderer initFooterOrHeaderRenderer​(boolean footer,
                                                         Border[] tableBorders)
      • ensureFooterOrHeaderHasTheSamePropertiesAsParentTableRenderer

        private void ensureFooterOrHeaderHasTheSamePropertiesAsParentTableRenderer​(TableRenderer headerOrFooterRenderer)
      • prepareFooterOrHeaderRendererForLayout

        private TableRenderer prepareFooterOrHeaderRendererForLayout​(TableRenderer renderer,
                                                                     float layoutBoxWidth)
      • isHeaderRenderer

        private boolean isHeaderRenderer()
      • isFooterRenderer

        private boolean isFooterRenderer()
      • isFooterRendererOfLargeTable

        private boolean isFooterRendererOfLargeTable()
      • isTopTablePart

        private boolean isTopTablePart()
      • isBottomTablePart

        private boolean isBottomTablePart()
      • calculateColumnWidths

        private void calculateColumnWidths​(float availableWidth)
        Returns minWidth
      • getTableWidth

        private float getTableWidth()
      • applyMarginsAndPaddingsAndCalculateColumnWidths

        void applyMarginsAndPaddingsAndCalculateColumnWidths​(Rectangle layoutBox)