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 floatdeltaXprivate booleandoesObjectFitRequireCuttingprotected java.lang.FloatfixedXPositionprotected java.lang.FloatfixedYPositionprivate java.lang.Floatheightprotected floatimageHeightprotected floatimageWidthprivate RectangleinitialOccupiedAreaBBox(package private) float[]matrixprotected floatpivotYprivate floatrenderedImageHeightprivate floatrenderedImageWidthprivate floatrotatedDeltaXprivate floatrotatedDeltaYprivate java.lang.Floatwidth-
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 floatadjustPositionAfterRotation(float angle, float maxWidth, float maxHeight)private voidapplyConcatMatrix(DrawContext drawContext, java.lang.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)floatgetAscent()Gets the maximum offset above the base line that thisILeafElementRendererextends to.(package private) java.lang.FloatgetAspectRatio()Gets intrinsic aspect ratio for this renderer.RectanglegetBorderAreaBBox()Gets the border box of a renderer.floatgetDescent()Gets the maximum offset below the base line that thisILeafElementRendererextends to.floatgetImageHeight()Gets original height of the image, not the height set byImage.setHeight(float)method.floatgetImageWidth()Gets original width of the image, not the width set byImage.setWidth(float)method.private voidgetMatrix(AffineTransform t, float imageItselfScaledWidth, float imageItselfScaledHeight)MinMaxWidthgetMinMaxWidth()Calculates min and max width values for current renderer.IRenderergetNextRenderer()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) booleanhasAspectRatio()Checks if this renderer has intrinsic aspect ratio.LayoutResultlayout(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 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, 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, 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: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
public void draw(DrawContext drawContext)
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
public IRenderer 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
public Rectangle 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
java.lang.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
protected Rectangle applyPaddings(Rectangle rect, UnitValue[] paddings, boolean reverse)
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
public MinMaxWidth getMinMaxWidth()
Description copied from class:AbstractRendererCalculates min and max width values for current renderer.- Overrides:
getMinMaxWidthin 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: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
-
-