Class TextRenderer
- All Implemented Interfaces:
-
IPropertyContainer
,ILeafElementRenderer
,IRenderer
- Direct Known Subclasses:
-
LinkRenderer
renderer
object for a Text
object. It will draw the glyphs of the textual content on the DrawContext
.
-
Field Summary
Modifier and TypeFieldDescriptionprotected GlyphLine
protected boolean
protected List
protected GlyphLine
protected String
protected float
protected GlyphLine
protected static final float
protected float
Fields inherited from class com.itextpdf.layout.renderer.AbstractRenderer
childRenderers, EPS, flushed, INF, isLastRendererForModelElement, modelElement, occupiedArea, OVERLAP_EPSILON, parent, positionedRenderers, properties
-
Constructor Summary
ModifierConstructorDescriptionTextRenderer
(Text textElement) Creates a TextRenderer from its corresponding layout object.TextRenderer
(Text textElement, String text) Creates a TextRenderer from its corresponding layout object, with a custom text to replace the contents of theText
.protected
TextRenderer
(TextRenderer other) -
Method Summary
Modifier and TypeMethodDescriptionvoid
applyOtf()
protected int
static float[]
Get ascender and descender from font metrics.static float[]
calculateAscenderDescender
(PdfFont font, RenderingMode mode) Get ascender and descender from font metrics.protected float
int
charAt
(int pos) Gets char code at given position for the text belonging to this renderer.protected TextRenderer
createCopy
(GlyphLine gl, PdfFont font) protected TextRenderer
protected TextRenderer
void
draw
(DrawContext drawContext) Flushes the renderer subtree contents, i.e.protected void
drawSingleUnderline
(Underline underline, TransparentColor fontStrokeColor, PdfCanvas canvas, float fontSize, float italicAngleTan) float
Gets the maximum offset above the base line that this Text extends to.protected Rectangle
getBackgroundArea
(Rectangle occupiedAreaWithMargins) Evaluate the actual backgroundfloat
Gets the maximum offset below the base line that this Text extends to.protected Float
Gets the first yLine of the nested children recursively.protected Float
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.protected int
float
getText()
float
getYLine()
Gets the position on the canvas of the imaginary horizontal line upon which theText
's contents will be written.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.int
length()
The length of the whole text assigned to this renderer.protected int
Returns the length of theline
which is the result of the layout call.void
moveYLineTo
(float y) Moves the vertical position to the parameter's value.protected boolean
resolveFonts
(List<IRenderer> addTo) ResolveProperty.FONT
String[] value.protected void
setProcessedGlyphLineAndFont
(GlyphLine gl, PdfFont font) void
Manually set a GlyphLine and PdfFont for rendering.void
Manually sets the contents of the Text's representation on the canvas, regardless of the Text's own contents.protected TextRenderer[]
split
(int initialOverflowTextPos) toString()
Returns a string representation of the renderer.void
Trims any whitespace characters from the start of theGlyphLine
to be rendered.Methods inherited from class com.itextpdf.layout.renderer.AbstractRenderer
addAllProperties, addChild, alignChildHorizontally, allowLastYLineRecursiveExtraction, applyAbsolutePosition, applyAction, applyBorderBox, applyBorderBox, applyDestination, applyDestinationsAndAnnotation, applyLinkAnnotation, applyMargins, applyMargins, applyPaddings, applyPaddings, applyRelativePositioningTranslation, beginElementOpacityApplying, beginTransformationIfApplied, calculateAbsolutePdfBBox, calculateBBox, calculateShiftToPositionBBoxOfPointsAt, clipBackgroundArea, clipBackgroundArea, clipBorderArea, createXObject, deleteOwnProperty, deleteProperty, drawBackground, drawBorder, drawChildren, endElementOpacityApplying, endTransformationIfApplied, getBorderAreaBBox, getBorderRadii, getBorders, getChildRenderers, getDefaultProperty, getInnerAreaBBox, getMargins, getModelElement, getOccupiedArea, getOccupiedAreaBBox, getOwnProperties, getOwnProperty, getPaddings, getParent, getProperty, getProperty, getPropertyAsBoolean, getPropertyAsColor, getPropertyAsFloat, getPropertyAsFloat, getPropertyAsFont, getPropertyAsInteger, getPropertyAsTransparentColor, getPropertyAsUnitValue, hasAbsoluteUnitValue, hasOwnOrModelProperty, hasOwnProperty, hasProperty, hasRelativeUnitValue, initElementAreas, isAbsolutePosition, isBorderBoxSizing, isFirstOnRootArea, isFixedLayout, isFlushed, isKeepTogether, isNotFittingHeight, isNotFittingLayoutArea, isNotFittingWidth, isOverflowFit, isOverflowProperty, isOverflowProperty, isOverflowProperty, isPositioned, isRelativePosition, isStaticLayout, move, rectangleToPointsList, retrieveHeight, retrieveMaxHeight, retrieveMaxWidth, retrieveMinHeight, retrieveMinWidth, retrieveUnitValue, retrieveUnitValue, retrieveWidth, setBorders, setMinMaxWidthBasedOnFixedWidth, setParent, setProperty, transformPoints, updateHeight, 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, move, setParent
-
Field Details
-
TEXT_SPACE_COEFF
protected static final float TEXT_SPACE_COEFF- See Also:
-
yLineOffset
protected float yLineOffset -
text
-
line
-
strToBeConverted
-
otfFeaturesApplied
protected boolean otfFeaturesApplied -
tabAnchorCharacterPosition
protected float tabAnchorCharacterPosition -
reversedRanges
-
savedWordBreakAtLineEnding
-
-
Constructor Details
-
TextRenderer
Creates a TextRenderer from its corresponding layout object.- Parameters:
-
textElement
- theText
which this object should manage
-
TextRenderer
Creates a TextRenderer from its corresponding layout object, with a custom text to replace the contents of theText
.- Parameters:
-
textElement
- theText
which this object should manage -
text
- the replacement text
-
TextRenderer
-
-
Method Details
-
layout
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. -
applyOtf
public void applyOtf() -
draw
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
-
trimFirst
public void trimFirst()Trims any whitespace characters from the start of theGlyphLine
to be rendered. -
getAscent
public float getAscent()Gets the maximum offset above the base line that this Text extends to.- Specified by:
-
getAscent
in interfaceILeafElementRenderer
- Returns:
-
the upwards vertical offset of this
Text
-
getDescent
public float getDescent()Gets the maximum offset below the base line that this Text extends to.- Specified by:
-
getDescent
in interfaceILeafElementRenderer
- Returns:
-
the downwards vertical offset of this
Text
-
getYLine
public float getYLine()Gets the position on the canvas of the imaginary horizontal line upon which theText
's contents will be written.- Returns:
-
the y position of this text on the
DrawContext
-
moveYLineTo
public void moveYLineTo(float y) Moves the vertical position to the parameter's value.- Parameters:
-
y
- the new vertical position of the Text
-
setText
Manually sets the contents of the Text's representation on the canvas, regardless of the Text's own contents.- Parameters:
-
text
- the replacement text
-
setText
Manually set a GlyphLine and PdfFont for rendering.- Parameters:
-
text
- theGlyphLine
-
font
- the font
-
getText
-
length
public int length()The length of the whole text assigned to this renderer.- Returns:
- the text length
-
toString
Description copied from class:AbstractRenderer
Returns a string representation of the renderer.- Overrides:
-
toString
in classAbstractRenderer
- Returns:
-
a
String
- See Also:
-
charAt
public int charAt(int pos) Gets char code at given position for the text belonging to this renderer.- Parameters:
-
pos
- the position in range [0; length()) - Returns:
- Unicode char code
-
getTabAnchorCharacterPosition
public float getTabAnchorCharacterPosition() -
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
TextRenderer
overflows to the next line, iText uses this method to create a renderer for the overflow part. So if one wants to extendTextRenderer
, one should override this method: otherwise the default method will be used and thus the default rather than the custom renderer will be created. Another method that should be overridden in case ofTextRenderer
's extension iscreateCopy(GlyphLine, PdfFont)
. This method is responsible for creation ofTextRenderer
's copies, which represent its parts of specific font.- Specified by:
-
getNextRenderer
in interfaceIRenderer
- Returns:
- new renderer instance
-
calculateAscenderDescender
Get ascender and descender from font metrics. If these values are obtained from typo metrics they are normalized with a scale coefficient.- Parameters:
-
font
- from which metrics will be extracted - Returns:
- array in which the first element is an ascender and the second is a descender
-
calculateAscenderDescender
Get ascender and descender from font metrics. In RenderingMode.DEFAULT_LAYOUT_MODE if these values are obtained from typo metrics they are normalized with a scale coefficient.- Parameters:
-
font
- from which metrics will be extracted -
mode
- mode in which metrics will be obtained. Impact on the use of scale coefficient - Returns:
- array in which the first element is an ascender and the second is a descender
-
getBackgroundArea
Description copied from class:AbstractRenderer
Evaluate the actual background- Overrides:
-
getBackgroundArea
in classAbstractRenderer
- Parameters:
-
occupiedAreaWithMargins
- the current occupied area with applied margins - Returns:
- the actual background area
-
getFirstYLineRecursively
Description copied from class:AbstractRenderer
Gets the first yLine of the nested children recursively. E.g. for a list, this will be the yLine of the first item (if the first item is indeed a paragraph). NOTE: this method will no go further than the first child.- Overrides:
-
getFirstYLineRecursively
in classAbstractRenderer
- Returns:
- the first yline of the nested children, null if there is no text found
-
getLastYLineRecursively
- Overrides:
-
getLastYLineRecursively
in classAbstractRenderer
-
lineLength
protected int lineLength()Returns the length of theline
which is the result of the layout call.- Returns:
- the length of the line
-
baseCharactersCount
protected int baseCharactersCount() -
getMinMaxWidth
Description copied from class:AbstractRenderer
Calculates min and max width values for current renderer.- Overrides:
-
getMinMaxWidth
in classAbstractRenderer
- Returns:
-
instance of
MinMaxWidth
-
getNumberOfSpaces
protected int getNumberOfSpaces() -
createSplitRenderer
-
createOverflowRenderer
-
split
-
drawSingleUnderline
protected void drawSingleUnderline(Underline underline, TransparentColor fontStrokeColor, PdfCanvas canvas, float fontSize, float italicAngleTan) -
calculateLineWidth
protected float calculateLineWidth() -
resolveFonts
ResolveProperty.FONT
String[] value.- Parameters:
-
addTo
- add all processed renderers to. - Returns:
-
true, if new
TextRenderer
has been created.
-
setProcessedGlyphLineAndFont
-
createCopy
Creates a copy of thisTextRenderer
, which corresponds to the passedGlyphLine
withPdfFont
.While processing
TextRenderer
, iText uses this method to createglyph lines
of specificfonts
, which represent theTextRenderer
's parts. If one extendsTextRenderer
, one should override this method, otherwise ifFontSelector
related logic is triggered, copies of thisTextRenderer
will have the default behavior rather than the custom one.- Parameters:
-
gl
- aGlyphLine
which represents some of thisTextRenderer
's content -
font
- aPdfFont
for this part of theTextRenderer
's content - Returns:
-
copy of this
TextRenderer
, which correspond to the passedGlyphLine
withPdfFont
-