Class TableRenderer
java.lang.Object
com.itextpdf.layout.renderer.AbstractRenderer
com.itextpdf.layout.renderer.TableRenderer
- All Implemented Interfaces:
IPropertyContainer, IRenderer
This class represents the
renderer object for a Table
object. It will delegate its drawing operations on to the CellRenderer
instances associated with the table cells.-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionprivate static classThis are a structs used for convenience in layout.private static classUtility class that copies overflow renderer rows on cell replacement so it won't affect original renderer -
Field Summary
FieldsModifier and TypeFieldDescription(package private) TableBordersprotected DivRendererprivate float[]private float[]protected TableRendererprotected TableRendererprotected booleanTrue for newly created renderer.protected Table.RowRangeprotected List<CellRenderer[]> private floatprivate floatFields inherited from class AbstractRenderer
BOTTOM_SIDE, childRenderers, EPS, flushed, INF, isLastRendererForModelElement, LEFT_SIDE, modelElement, occupiedArea, OVERLAP_EPSILON, parent, positionedRenderers, properties, RIGHT_SIDE, TOP_SIDE -
Constructor Summary
ConstructorsModifierConstructorDescriptionprivateTableRenderer(Table modelElement) Creates a TableRenderer from aTable.TableRenderer(Table modelElement, Table.RowRange rowRange) Creates a TableRenderer from aTablewhich will partially render the table. -
Method Summary
Modifier and TypeMethodDescriptionvoidAdds a child to the current rendererprivate voidadjustCaptionAndFixOccupiedArea(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.private voidadjustFooterAndFixOccupiedArea(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.protected booleanprotected RectangleapplyBorderBox(Rectangle rect, Border[] borders, boolean reverse) Applies the given border box (borders) on the given rectangleprivate voidapplyFixedXOrYPosition(boolean isXPosition, Rectangle layoutBox) (package private) voidapplyPaddings(Rectangle rect, boolean reverse) Applies paddings of the renderer on the given rectangleprotected RectangleapplyPaddings(Rectangle rect, UnitValue[] paddings, boolean reverse) Applies given paddings to the given rectangle.private RectangleapplySingleSpacing(Rectangle rect, float spacing, boolean isHorizontal, boolean reverse) Applies the given horizontal or vertical spacing on the given rectangleprivate RectangleapplySpacing(Rectangle rect, float horizontalSpacing, float verticalSpacing, boolean reverse) Applies the given spacings on the given rectangleprivate voidcalculateColumnWidths(float availableWidth) Returns minWidthprivate voidcorrectLayoutedCellsOccupiedAreas(LayoutResult[] splits, int row, int[] targetOverflowRowIndex, Float blockMinHeight, Rectangle layoutBox, List<Boolean> rowsHasCellWithSetHeight, boolean isLastRenderer, boolean processBigRowspan, boolean skip) private voidcorrectRowCellsOccupiedAreas(LayoutResult[] splits, int row, int[] targetOverflowRowIndex, int currentRowIndex, List<Boolean> rowsHasCellWithSetHeight, float cumulativeShift, float additionalCellHeight) private voidprotected TableRenderercreateOverflowRenderer(Table.RowRange rowRange) protected TableRenderercreateSplitRenderer(Table.RowRange rowRange) voiddraw(DrawContext drawContext) Flushes the renderer subtree contents, i.e.voiddrawBackground(DrawContext drawContext) Draws a background layer if it is defined by a keyProperty.BACKGROUNDin either the layout element or thisIRendereritself.protected voiddrawBackgrounds(DrawContext drawContext) voiddrawBorder(DrawContext drawContext) Performs the drawing operation for the border of this renderer, if defined by theProperty.BORDER_TOP,Property.BORDER_RIGHT,Property.BORDER_BOTTOMandProperty.BORDER_LEFTvalues in either the layout element or thisIRendereritself.protected voiddrawBorders(DrawContext drawContext) private voiddrawBorders(DrawContext drawContext, boolean hasHeader, boolean hasFooter) protected voiddrawCaption(DrawContext drawContext) voiddrawChildren(DrawContext drawContext) Performs the drawing operation for allchildrenof this renderer.private voidenlargeCell(int col, int row, int minRowspan, CellRenderer[] currentRow, TableRenderer.OverflowRowsWrapper overflowRows, int[] targetOverflowRowIndex, TableRenderer[] splitResult) private voidenlargeCellWithBigRowspan(CellRenderer[] currentRow, TableRenderer.OverflowRowsWrapper overflowRows, int row, int col, int minRowspan, TableRenderer[] splitResult, int[] targetOverflowRowIndex) private voidensureFooterOrHeaderHasTheSamePropertiesAsParentTableRenderer(TableRenderer headerOrFooterRenderer) protected voidextendLastRow(CellRenderer[] lastRow, Rectangle freeBox) Calculates min and max width values for current renderer.Gets a new instance of this class to be used as a next renderer, after this renderer is used, iflayout(LayoutContext)is called more than once.(package private) TablegetTable()private floatprivate TableRendererinitFooterOrHeaderRenderer(boolean footer, Border[] tableBorders) private voidinitializeCaptionRenderer(Div caption) private voidinitializeHeaderAndFooter(boolean isFirstOnThePage) private voidprivate booleanprivate booleanprivate booleanprivate booleanprivate booleanprivate booleanprivate booleanlayout(LayoutContext layoutContext) This method simulates positioning of the renderer, including all of its children, and returns theLayoutResult, representing the layout result, including occupied area, status, i.e.voidmove(float dxRight, float dyUp) Moves the renderer subtree by the specified offset.private TableRendererprepareFooterOrHeaderRendererForLayout(TableRenderer renderer, float layoutBoxWidth) protected FloatretrieveWidth(float parentBoxWidth) Retrieves element's fixed content box width, if it's set.private voidsetRowRange(Table.RowRange rowRange) This method is used to set row range for table renderer during creating a new renderer.protected TableRenderer[]split(int row) protected TableRenderer[]split(int row, boolean hasContent) protected TableRenderer[]split(int row, boolean hasContent, boolean cellWithBigRowspanAdded) Methods inherited from class AbstractRenderer
addAllChildRenderers, addAllChildRenderers, addAllProperties, addChildRenderer, alignChildHorizontally, applyAbsolutePosition, applyAbsolutePositionIfNeeded, applyAction, applyBorderBox, applyDestination, applyDestinationsAndAnnotation, applyLinkAnnotation, applyMargins, applyMargins, applyMarginsBordersPaddings, applyRelativePositioningTranslation, beginElementOpacityApplying, beginTransformationIfApplied, calculateAbsolutePdfBBox, calculateAdditionalWidth, calculateBBox, calculatePaddingBorderHeight, calculatePaddingBorderWidth, calculateShiftToPositionBBoxOfPointsAt, clipBackgroundArea, clipBackgroundArea, clipBorderArea, createFontCharacteristics, createXObject, deleteOwnProperty, deleteProperty, drawPositionedChildren, endElementOpacityApplying, endTransformationIfApplied, getAspectRatio, getBackgroundArea, getBorderAreaBBox, getBorderRadii, getBorders, getBorders, getChildRenderers, getDefaultProperty, getFirstYLineRecursively, getInnerAreaBBox, getLastYLineRecursively, getMargins, getMinMaxWidth, getModelElement, getOccupiedArea, getOccupiedAreaBBox, getOwnProperties, getOwnProperty, getPaddings, getParent, getPdfDocument, getProperty, getProperty, getPropertyAsBoolean, getPropertyAsColor, getPropertyAsFloat, getPropertyAsFloat, getPropertyAsFloat, getPropertyAsFont, getPropertyAsInteger, getPropertyAsTransparentColor, getPropertyAsUnitValue, getPropertyAsUnitValue, getRootRenderer, hasAbsoluteUnitValue, hasAspectRatio, hasOwnOrModelProperty, hasOwnProperty, hasProperty, hasRelativeUnitValue, initElementAreas, isAbsolutePosition, isBorderBoxSizing, isFirstOnRootArea, isFirstOnRootArea, isFixedLayout, isFlushed, isKeepTogether, isKeepTogether, isNotFittingHeight, isNotFittingLayoutArea, isNotFittingWidth, isOverflowFit, isOverflowProperty, isOverflowProperty, isOverflowProperty, isPositioned, isRelativePosition, isStaticLayout, logWarningIfGetNextRendererNotOverridden, noAbsolutePositionInfo, preparePositionedRendererAndAreaForLayout, processWaitingDrawing, rectangleToPointsList, removeAllChildRenderers, removeChildRenderer, replaceOwnProperty, resolveFirstPdfFont, resolveFirstPdfFont, retrieveHeight, retrieveMaxHeight, retrieveMaxWidth, retrieveMinHeight, retrieveMinWidth, retrieveResolvedDeclaredHeight, retrieveUnitValue, retrieveUnitValue, returnBackOwnProperty, setBorders, setChildRenderer, setChildRenderers, setMinMaxWidthBasedOnFixedWidth, setParent, setProperty, setThisAsParent, shrinkOccupiedAreaForAbsolutePosition, toString, transformPoints, updateHeight, updateHeightsOnSplit, updateHeightsOnSplit, updateMaxHeight, updateMinHeight, updateWidth
-
Field Details
-
rows
-
rowRange
-
headerRenderer
-
captionRenderer
-
isOriginalNonSplitRenderer
protected boolean isOriginalNonSplitRendererTrue for newly created renderer. For split renderers this is set to false. Used for tricky layout. -
bordersHandler
TableBorders bordersHandler -
columnWidths
private float[] columnWidths -
heights
-
countedColumnWidth
private float[] countedColumnWidth -
totalWidthForColumns
private float totalWidthForColumns -
topBorderMaxWidth
private float topBorderMaxWidth
-
-
Constructor Details
-
TableRenderer
private TableRenderer() -
TableRenderer
Creates a TableRenderer from aTablewhich will partially render the table.- Parameters:
modelElement- the table to be rendered by this rendererrowRange- the table rows to be rendered
-
TableRenderer
-
-
Method Details
-
addChild
Adds a child to the current renderer- Specified by:
addChildin interfaceIRenderer- Overrides:
addChildin classAbstractRenderer- Parameters:
renderer- a child to be added
-
applyBorderBox
Description copied from class:AbstractRendererApplies the given border box (borders) on the given rectangle- Overrides:
applyBorderBoxin classAbstractRenderer- Parameters:
rect- a rectangle paddings will be applied on.borders- thebordersto be applied on the given rectanglereverse- indicates whether the border box will be applied inside (in case of false) or outside (in case of false) the rectangle.- Returns:
- a
border boxof the renderer
-
applyPaddings
Description copied from class:AbstractRendererApplies given paddings to the given rectangle.- Overrides:
applyPaddingsin classAbstractRenderer- Parameters:
rect- a rectangle paddings will be applied on.paddings- the paddings to be applied on the given rectanglereverse- indicates whether paddings will be applied inside (in case of false) or outside (in case of true) the rectangle.- Returns:
- a
border boxof the renderer
-
applyPaddings
Description copied from class:AbstractRendererApplies paddings of the renderer on the given rectangle- Overrides:
applyPaddingsin classAbstractRenderer- Parameters:
rect- a rectangle paddings will be applied on.reverse- indicates whether paddings will be applied inside (in case of false) or outside (in case of true) the rectangle.- Returns:
- a
border boxof the renderer - See Also:
-
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 rectangleverticalSpacing- the vertical spacing to be applied on the given rectanglereverse- indicates whether the spacings will be applied inside (in case of false) or outside (in case of false) the rectangle.- Returns:
- a
border boxof 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 rectangleisHorizontal- defines whether the provided spacing should be applied as a horizontal or a vertical onereverse- indicates whether the spacings will be applied inside (in case of false) or outside (in case of false) the rectangle.- Returns:
- a
border boxof the renderer
-
getTable
Table getTable() -
initializeCaptionRenderer
-
isOriginalRenderer
private boolean isOriginalRenderer() -
layout
This method simulates positioning of the renderer, including all of its children, and returns theLayoutResult, representing the layout result, including occupied area, status, i.e. if there was enough place to fit the renderer subtree, etc.LayoutResultcan be extended to return custom layout results for custom elements, e.g.TextRendererusesTextLayoutResultas its result. This method can be called standalone to learn how much area the renderer subtree needs, or can be called beforeIRenderer.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
Flushes the renderer subtree contents, i.e. draws itself on canvas, adds necessary objects to thePdfDocumentetc.- Specified by:
drawin interfaceIRenderer- Overrides:
drawin classAbstractRenderer- Parameters:
drawContext- contains thePdfDocumentto which the renderer subtree if flushed, thePdfCanvason which the renderer subtree is drawn and other additional parameters needed to perform drawing
-
drawChildren
Performs the drawing operation for allchildrenof this renderer.- Overrides:
drawChildrenin classAbstractRenderer- Parameters:
drawContext- the context (canvas, document, etc) of this drawing operation.
-
drawBackgrounds
-
drawCaption
-
drawBackground
Description copied from class:AbstractRendererDraws a background layer if it is defined by a keyProperty.BACKGROUNDin either the layout element or thisIRendereritself.- Overrides:
drawBackgroundin classAbstractRenderer- Parameters:
drawContext- the context (canvas, document, etc) of this drawing operation.
-
getNextRenderer
Gets a new instance of this class to be used as a next renderer, after this renderer is used, iflayout(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:
movein interfaceIRenderer- Overrides:
movein classAbstractRenderer- 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
-
split
-
split
-
createSplitRenderer
-
createOverflowRenderer
-
retrieveWidth
Description copied from class:AbstractRendererRetrieves element's fixed content box width, if it's set. Takes into accountProperty.BOX_SIZING,Property.MIN_WIDTH, andProperty.MAX_WIDTHproperties.- Overrides:
retrieveWidthin classAbstractRenderer- Parameters:
parentBoxWidth- width of the parent element content box. If element has relative width, it will be calculated relatively to this parameter.- Returns:
- element's fixed content box width or null if it's not set.
- See Also:
-
getMinMaxWidth
Description copied from class:AbstractRendererCalculates min and max width values for current renderer.- Overrides:
getMinMaxWidthin classAbstractRenderer- Returns:
- instance of
MinMaxWidth
-
allowLastYLineRecursiveExtraction
protected boolean allowLastYLineRecursiveExtraction()- Overrides:
allowLastYLineRecursiveExtractionin classAbstractRenderer
-
initializeTableLayoutBorders
private void initializeTableLayoutBorders() -
correctRowRange
private void correctRowRange() -
drawBorder
Description copied from class:AbstractRendererPerforms the drawing operation for the border of this renderer, if defined by theProperty.BORDER_TOP,Property.BORDER_RIGHT,Property.BORDER_BOTTOMandProperty.BORDER_LEFTvalues in either the layout element or thisIRendereritself.- Overrides:
drawBorderin classAbstractRenderer- Parameters:
drawContext- the context (canvas, document, etc.) of this drawing operation
-
drawBorders
-
drawBorders
-
isEmptyTableRenderer
private boolean isEmptyTableRenderer() -
applyFixedXOrYPosition
-
adjustCaptionAndFixOccupiedArea
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, Float blockMinHeight, Rectangle layoutBox, List<Boolean> rowsHasCellWithSetHeight, boolean isLastRenderer, boolean processBigRowspan, boolean skip) -
correctRowCellsOccupiedAreas
private void correctRowCellsOccupiedAreas(LayoutResult[] splits, int row, int[] targetOverflowRowIndex, int currentRowIndex, List<Boolean> rowsHasCellWithSetHeight, float cumulativeShift, float additionalCellHeight) -
extendLastRow
-
setRowRange
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. -
isHeaderRenderer
private boolean isHeaderRenderer() -
isTopTablePart
private boolean isTopTablePart() -
isBottomTablePart
private boolean isBottomTablePart() -
calculateColumnWidths
private void calculateColumnWidths(float availableWidth) Returns minWidth -
getTableWidth
private float getTableWidth() -
enlargeCellWithBigRowspan
private void enlargeCellWithBigRowspan(CellRenderer[] currentRow, TableRenderer.OverflowRowsWrapper overflowRows, int row, int col, int minRowspan, TableRenderer[] splitResult, int[] targetOverflowRowIndex) -
enlargeCell
private void enlargeCell(int col, int row, int minRowspan, CellRenderer[] currentRow, TableRenderer.OverflowRowsWrapper overflowRows, int[] targetOverflowRowIndex, TableRenderer[] splitResult) -
applyMarginsAndPaddingsAndCalculateColumnWidths
-