Package com.itextpdf.layout.renderer
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
public class ImageRenderer extends AbstractRenderer implements ILeafElementRenderer
-
-
Field Summary
Fields Modifier and Type Field Description protected float
deltaX
private boolean
doesObjectFitRequireCutting
protected java.lang.Float
fixedXPosition
protected java.lang.Float
fixedYPosition
private java.lang.Float
height
protected float
imageHeight
protected float
imageWidth
private Rectangle
initialOccupiedAreaBBox
(package private) float[]
matrix
protected float
pivotY
private float
renderedImageHeight
private float
renderedImageWidth
private float
rotatedDeltaX
private float
rotatedDeltaY
private java.lang.Float
width
-
Fields inherited from class com.itextpdf.layout.renderer.AbstractRenderer
BOTTOM_SIDE, childRenderers, EPS, flushed, INF, isLastRendererForModelElement, LEFT_SIDE, modelElement, occupiedArea, OVERLAP_EPSILON, parent, positionedRenderers, properties, RIGHT_SIDE, TOP_SIDE
-
-
Constructor Summary
Constructors Constructor Description ImageRenderer(Image image)
Creates an ImageRenderer from its corresponding layout object.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description private float
adjustPositionAfterRotation(float angle, float maxWidth, float maxHeight)
private void
applyConcatMatrix(DrawContext drawContext, java.lang.Float angle)
private void
applyObjectFit(ObjectFit objectFit, float imageWidth, float imageHeight)
protected Rectangle
applyPaddings(Rectangle rect, UnitValue[] paddings, boolean reverse)
Applies given paddings to the given rectangle.private void
applyRotationLayout(float angle)
protected ImageRenderer
autoScale(LayoutArea layoutArea)
private void
beginObjectFitImageClipping(PdfCanvas canvas)
private void
calculateImageDimensions(Rectangle layoutBox, AffineTransform t, PdfXObject xObject)
void
draw(DrawContext drawContext)
Flushes the renderer subtree contents, i.e.private void
endObjectFitImageClipping(PdfCanvas canvas)
float
getAscent()
Gets the maximum offset above the base line that thisILeafElementRenderer
extends to.(package private) java.lang.Float
getAspectRatio()
Gets intrinsic aspect ratio for this renderer.Rectangle
getBorderAreaBBox()
Gets the border box of a renderer.float
getDescent()
Gets the maximum offset below the base line that thisILeafElementRenderer
extends to.float
getImageHeight()
Gets original height of the image, not the height set byImage.setHeight(float)
method.float
getImageWidth()
Gets original width of the image, not the width set byImage.setWidth(float)
method.private void
getMatrix(AffineTransform t, float imageItselfScaledWidth, float imageItselfScaledHeight)
MinMaxWidth
getMinMaxWidth()
Calculates min and max width values for current renderer.IRenderer
getNextRenderer()
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) boolean
hasAspectRatio()
Checks if this renderer has intrinsic aspect ratio.LayoutResult
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.void
move(float dxRight, float dyUp)
Moves the renderer subtree by the specified offset.private void
translateImage(float xDistance, float yDistance, AffineTransform t)
-
Methods inherited from class com.itextpdf.layout.renderer.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, 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, retrieveUnitValue, retrieveUnitValue, retrieveWidth, returnBackOwnProperty, setBorders, setChildRenderer, setChildRenderers, setMinMaxWidthBasedOnFixedWidth, setParent, setProperty, setThisAsParent, shrinkOccupiedAreaForAbsolutePosition, toString, transformPoints, updateHeight, updateHeightsOnSplit, updateHeightsOnSplit, updateMaxHeight, updateMinHeight, updateWidth
-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
-
Methods inherited from interface com.itextpdf.layout.IPropertyContainer
deleteOwnProperty, getDefaultProperty, getOwnProperty, getProperty, hasOwnProperty, hasProperty, setProperty
-
Methods inherited from interface com.itextpdf.layout.renderer.IRenderer
addChild, getChildRenderers, getModelElement, getOccupiedArea, getParent, getProperty, isFlushed, setParent
-
-
-
-
Field Detail
-
fixedXPosition
protected java.lang.Float fixedXPosition
-
fixedYPosition
protected java.lang.Float fixedYPosition
-
pivotY
protected float pivotY
-
deltaX
protected float deltaX
-
imageWidth
protected float imageWidth
-
imageHeight
protected float imageHeight
-
matrix
float[] matrix
-
height
private java.lang.Float height
-
width
private java.lang.Float width
-
renderedImageHeight
private float renderedImageHeight
-
renderedImageWidth
private float renderedImageWidth
-
doesObjectFitRequireCutting
private boolean doesObjectFitRequireCutting
-
initialOccupiedAreaBBox
private Rectangle initialOccupiedAreaBBox
-
rotatedDeltaX
private float rotatedDeltaX
-
rotatedDeltaY
private float rotatedDeltaY
-
-
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 theLayoutResult
, 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
usesTextLayoutResult
as 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
public void draw(DrawContext drawContext)
Description copied from class:AbstractRenderer
Flushes the renderer subtree contents, i.e. draws itself on canvas, adds necessary objects to thePdfDocument
etc.- Specified by:
draw
in interfaceIRenderer
- Overrides:
draw
in classAbstractRenderer
- Parameters:
drawContext
- contains thePdfDocument
to which the renderer subtree if flushed, thePdfCanvas
on which the renderer subtree is drawn and other additional parameters needed to perform drawing
-
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, ifIRenderer.layout(LayoutContext)
is called more than once.- Specified by:
getNextRenderer
in interfaceIRenderer
- Returns:
- new renderer instance
-
getBorderAreaBBox
public Rectangle getBorderAreaBBox()
Description copied from class:AbstractRenderer
Gets the border box of a renderer. This is a box used to draw borders.- Overrides:
getBorderAreaBBox
in classAbstractRenderer
- Returns:
- border box of a renderer
-
hasAspectRatio
boolean hasAspectRatio()
Checks if this renderer has intrinsic aspect ratio.- Overrides:
hasAspectRatio
in classAbstractRenderer
- Returns:
- true, if aspect ratio is defined for this renderer, false otherwise
-
getAspectRatio
java.lang.Float getAspectRatio()
Gets intrinsic aspect ratio for this renderer.- Overrides:
getAspectRatio
in 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
protected Rectangle applyPaddings(Rectangle rect, UnitValue[] paddings, boolean reverse)
Description copied from class:AbstractRenderer
Applies given paddings to the given rectangle.- Overrides:
applyPaddings
in 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 box
of the renderer
-
move
public void move(float dxRight, float dyUp)
Description copied from class:AbstractRenderer
Moves the renderer subtree by the specified offset. This method affects occupied area of the renderer.- Specified by:
move
in interfaceIRenderer
- Overrides:
move
in 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
public MinMaxWidth getMinMaxWidth()
Description copied from class:AbstractRenderer
Calculates min and max width values for current renderer.- Overrides:
getMinMaxWidth
in classAbstractRenderer
- Returns:
- instance of
MinMaxWidth
-
autoScale
protected ImageRenderer autoScale(LayoutArea layoutArea)
-
applyObjectFit
private void applyObjectFit(ObjectFit objectFit, float imageWidth, float imageHeight)
-
beginObjectFitImageClipping
private void beginObjectFitImageClipping(PdfCanvas canvas)
-
endObjectFitImageClipping
private void endObjectFitImageClipping(PdfCanvas canvas)
-
calculateImageDimensions
private void calculateImageDimensions(Rectangle layoutBox, AffineTransform t, PdfXObject xObject)
-
getMatrix
private void getMatrix(AffineTransform t, float imageItselfScaledWidth, float imageItselfScaledHeight)
-
adjustPositionAfterRotation
private float adjustPositionAfterRotation(float angle, float maxWidth, float maxHeight)
-
translateImage
private void translateImage(float xDistance, float yDistance, AffineTransform t)
-
applyConcatMatrix
private void applyConcatMatrix(DrawContext drawContext, java.lang.Float angle)
-
applyRotationLayout
private void applyRotationLayout(float angle)
-
getAscent
public float getAscent()
Description copied from interface:ILeafElementRenderer
Gets the maximum offset above the base line that thisILeafElementRenderer
extends to.- Specified by:
getAscent
in interfaceILeafElementRenderer
- Returns:
- the upwards vertical offset of this
ILeafElementRenderer
-
getDescent
public float getDescent()
Description copied from interface:ILeafElementRenderer
Gets the maximum offset below the base line that thisILeafElementRenderer
extends to.- Specified by:
getDescent
in interfaceILeafElementRenderer
- Returns:
- the downwards vertical offset of this
ILeafElementRenderer
-
-