Class ImageRenderer
java.lang.Object
com.itextpdf.layout.renderer.AbstractRenderer
com.itextpdf.layout.renderer.ImageRenderer
- All Implemented Interfaces:
IPropertyContainer, ILeafElementRenderer, IRenderer
- Direct Known Subclasses:
SvgImageRenderer
-
Field Summary
FieldsModifier and TypeFieldDescriptionprotected floatprivate booleanprotected Floatprotected Floatprivate Floatprotected floatprotected floatprivate Rectangle(package private) float[]protected floatprivate floatprivate floatprivate floatprivate 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
ConstructorsConstructorDescriptionImageRenderer(Image image) Creates an ImageRenderer from its corresponding layout object. -
Method Summary
Modifier and TypeMethodDescriptionprivate floatadjustPositionAfterRotation(float angle, float maxWidth, float maxHeight) private voidapplyConcatMatrix(DrawContext drawContext, Float angle) private voidapplyObjectFit(ObjectFit objectFit, float imageWidth, float imageHeight) protected RectangleapplyPaddings(Rectangle rect, UnitValue[] paddings, boolean reverse) Applies given paddings to the given rectangle.private voidapplyRotationLayout(float angle) protected ImageRendererautoScale(LayoutArea layoutArea) private voidbeginObjectFitImageClipping(PdfCanvas canvas) private voidcalculateImageDimensions(Rectangle layoutBox, AffineTransform t, PdfXObject xObject) voiddraw(DrawContext drawContext) Flushes the renderer subtree contents, i.e.private voidendObjectFitImageClipping(PdfCanvas canvas) floatGets the maximum offset above the base line that thisILeafElementRendererextends to.(package private) FloatGets intrinsic aspect ratio for this renderer.Gets the border box of a renderer.floatGets the maximum offset below the base line that thisILeafElementRendererextends to.floatGets original height of the image, not the height set byImage.setHeight(float)method.floatGets original width of the image, not the width set byImage.setWidth(float)method.private voidgetMatrix(AffineTransform t, float imageItselfScaledWidth, float imageItselfScaledHeight) 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, ifIRenderer.layout(LayoutContext)is called more than once.(package private) booleanChecks if this renderer has intrinsic aspect ratio.layout(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 voidtranslateImage(float xDistance, float yDistance, AffineTransform t) Methods inherited from class AbstractRenderer
addAllChildRenderers, addAllChildRenderers, addAllProperties, addChild, addChildRenderer, alignChildHorizontally, allowLastYLineRecursiveExtraction, applyAbsolutePosition, applyAbsolutePositionIfNeeded, applyAction, applyBorderBox, applyBorderBox, applyDestination, applyDestinationsAndAnnotation, applyLinkAnnotation, applyMargins, applyMargins, applyMarginsBordersPaddings, applyPaddings, applyRelativePositioningTranslation, beginElementOpacityApplying, beginTransformationIfApplied, calculateAbsolutePdfBBox, calculateAdditionalWidth, calculateBBox, calculatePaddingBorderHeight, calculatePaddingBorderWidth, calculateShiftToPositionBBoxOfPointsAt, clipBackgroundArea, clipBackgroundArea, clipBorderArea, createFontCharacteristics, createXObject, deleteOwnProperty, deleteProperty, drawBackground, drawBorder, drawChildren, drawPositionedChildren, endElementOpacityApplying, endTransformationIfApplied, getBackgroundArea, 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, 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, retrieveWidth, returnBackOwnProperty, setBorders, setChildRenderer, setChildRenderers, setMinMaxWidthBasedOnFixedWidth, setParent, setProperty, setThisAsParent, shrinkOccupiedAreaForAbsolutePosition, toString, transformPoints, updateHeight, updateHeightsOnSplit, updateHeightsOnSplit, updateMaxHeight, updateMinHeight, updateWidthMethods inherited from class Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, waitMethods inherited from interface IPropertyContainer
deleteOwnProperty, getDefaultProperty, getOwnProperty, getProperty, hasOwnProperty, hasProperty, setPropertyMethods inherited from interface IRenderer
addChild, getChildRenderers, getModelElement, getOccupiedArea, getParent, getProperty, isFlushed, setParent
-
Field Details
-
fixedXPosition
-
fixedYPosition
-
pivotY
protected float pivotY -
deltaX
protected float deltaX -
imageWidth
protected float imageWidth -
imageHeight
protected float imageHeight -
matrix
float[] matrix -
height
-
width
-
renderedImageHeight
private float renderedImageHeight -
renderedImageWidth
private float renderedImageWidth -
doesObjectFitRequireCutting
private boolean doesObjectFitRequireCutting -
initialOccupiedAreaBBox
-
rotatedDeltaX
private float rotatedDeltaX -
rotatedDeltaY
private float rotatedDeltaY
-
-
Constructor Details
-
ImageRenderer
-
-
Method Details
-
layout
Description copied from interface:IRendererThis 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. -
draw
Description copied from class:AbstractRendererFlushes 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
-
getNextRenderer
Description copied from interface:IRendererGets a new instance of this class to be used as a next renderer, after this renderer is used, ifIRenderer.layout(LayoutContext)is called more than once.- Specified by:
getNextRendererin interfaceIRenderer- Returns:
- new renderer instance
-
getBorderAreaBBox
Description copied from class:AbstractRendererGets the border box of a renderer. This is a box used to draw borders.- Overrides:
getBorderAreaBBoxin classAbstractRenderer- Returns:
- border box of a renderer
-
hasAspectRatio
boolean hasAspectRatio()Checks if this renderer has intrinsic aspect ratio.- Overrides:
hasAspectRatioin classAbstractRenderer- Returns:
- true, if aspect ratio is defined for this renderer, false otherwise
-
getAspectRatio
Float getAspectRatio()Gets intrinsic aspect ratio for this renderer.- Overrides:
getAspectRatioin classAbstractRenderer- Returns:
- aspect ratio, if it is defined for this renderer, null otherwise
-
getImageWidth
public float getImageWidth()Gets original width of the image, not the width set byImage.setWidth(float)method.- Returns:
- original image width
-
getImageHeight
public float getImageHeight()Gets original height of the image, not the height set byImage.setHeight(float)method.- Returns:
- original image height
-
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
-
move
public void move(float dxRight, float dyUp) Description copied from class:AbstractRendererMoves 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.
-
getMinMaxWidth
Description copied from class:AbstractRendererCalculates min and max width values for current renderer.- Overrides:
getMinMaxWidthin classAbstractRenderer- Returns:
- instance of
MinMaxWidth
-
autoScale
-
applyObjectFit
-
beginObjectFitImageClipping
-
endObjectFitImageClipping
-
calculateImageDimensions
-
getMatrix
private void getMatrix(AffineTransform t, float imageItselfScaledWidth, float imageItselfScaledHeight) -
adjustPositionAfterRotation
private float adjustPositionAfterRotation(float angle, float maxWidth, float maxHeight) -
translateImage
-
applyConcatMatrix
-
applyRotationLayout
private void applyRotationLayout(float angle) -
getAscent
public float getAscent()Description copied from interface:ILeafElementRendererGets the maximum offset above the base line that thisILeafElementRendererextends to.- Specified by:
getAscentin interfaceILeafElementRenderer- Returns:
- the upwards vertical offset of this
ILeafElementRenderer
-
getDescent
public float getDescent()Description copied from interface:ILeafElementRendererGets the maximum offset below the base line that thisILeafElementRendererextends to.- Specified by:
getDescentin interfaceILeafElementRenderer- Returns:
- the downwards vertical offset of this
ILeafElementRenderer
-