public class TextRenderer extends AbstractRenderer implements ILeafElementRenderer
renderer object for a Text object. It will draw the glyphs of the textual content on the DrawContext.
| Modifier and Type | Field and Description |
|---|---|
protected GlyphLine |
line |
protected boolean |
otfFeaturesApplied |
protected List |
reversedRanges |
protected GlyphLine |
savedWordBreakAtLineEnding |
protected String |
strToBeConverted |
protected float |
tabAnchorCharacterPosition |
protected GlyphLine |
text |
protected static float |
TEXT_SPACE_COEFF |
protected float |
yLineOffset |
childRenderers, EPS, flushed, INF, isLastRendererForModelElement, modelElement, occupiedArea, OVERLAP_EPSILON, parent, positionedRenderers, properties| Modifier | Constructor and Description |
|---|---|
|
TextRenderer(Text textElement)
Creates a TextRenderer from its corresponding layout object.
|
protected |
TextRenderer(TextRenderer other) |
|
TextRenderer(Text textElement, String text)
Creates a TextRenderer from its corresponding layout object, with a custom text to replace the contents of the Text.
|
| Modifier and Type | Method and Description |
|---|---|
void |
applyOtf() |
protected int |
baseCharactersCount() |
static float[] |
calculateAscenderDescender(PdfFont font)
Get ascender and descender from font metrics.
|
static float[] |
calculateAscenderDescender(PdfFont font, RenderingMode mode)
Get ascender and descender from font metrics.
|
protected float |
calculateLineWidth() |
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 |
createOverflowRenderer() |
protected TextRenderer |
createSplitRenderer() |
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 |
getAscent()
Gets the maximum offset above the base line that this Text extends to.
|
protected Rectangle |
getBackgroundArea(Rectangle occupiedAreaWithMargins)
Evaluate the actual background
|
float |
getDescent()
Gets the maximum offset below the base line that this Text extends to.
|
protected Float |
getFirstYLineRecursively()
Gets the first yLine of the nested children recursively.
|
protected Float |
getLastYLineRecursively() |
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, if layout(LayoutContext) is called more than once.
|
protected int |
getNumberOfSpaces() |
float |
getTabAnchorCharacterPosition() |
GlyphLine |
getText() |
float |
getYLine()
Gets the position on the canvas of the imaginary horizontal line upon which the Text's contents will be written.
|
LayoutResult |
layout(LayoutContext layoutContext)
This method simulates positioning of the renderer, including all of its children, and returns the LayoutResult, representing the layout result, including occupied area, status, i.e.
|
int |
length()
The length of the whole text assigned to this renderer.
|
protected int |
lineLength()
Returns the length of the line 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)
Resolve Property.FONT String[] value.
|
protected void |
setProcessedGlyphLineAndFont(GlyphLine gl, PdfFont font) |
void |
setText(GlyphLine text, PdfFont font)
Manually set a GlyphLine and PdfFont for rendering.
|
void |
setText(String text)
Manually sets the contents of the Text's representation on the canvas, regardless of the Text's own contents.
|
protected TextRenderer[] |
split(int initialOverflowTextPos) |
String |
toString()
Returns a string representation of the renderer.
|
void |
trimFirst()
Trims any whitespace characters from the start of the GlyphLine to be rendered.
|
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, updateWidthclone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, waitaddChild, getChildRenderers, getModelElement, getOccupiedArea, getParent, getProperty, isFlushed, move, setParentdeleteOwnProperty, getDefaultProperty, getOwnProperty, getProperty, hasOwnProperty, hasProperty, setPropertyprotected static final float TEXT_SPACE_COEFF
protected float yLineOffset
protected GlyphLine text
protected GlyphLine line
protected String strToBeConverted
protected boolean otfFeaturesApplied
protected float tabAnchorCharacterPosition
protected ListreversedRanges
protected GlyphLine savedWordBreakAtLineEnding
public TextRenderer(Text textElement)
textElement - the Text which this object should manage
public TextRenderer(Text textElement, String text)
Text.
textElement - the Text which this object should manage
text - the replacement text
protected TextRenderer(TextRenderer other)
public LayoutResult layout(LayoutContext layoutContext)
IRenderer
LayoutResult, 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 uses TextLayoutResult as its result. This method can be called standalone to learn how much area the renderer subtree needs, or can be called before IRenderer.draw(DrawContext), to prepare the renderer to be flushed to the output stream.
public void applyOtf()
public void draw(DrawContext drawContext)
AbstractRenderer
PdfDocument etc.
draw in interface IRenderer
draw in class AbstractRenderer
drawContext - contains the PdfDocument to which the renderer subtree if flushed, the PdfCanvas on which the renderer subtree is drawn and other additional parameters needed to perform drawing
public void trimFirst()
GlyphLine to be rendered.
public float getAscent()
getAscent in interface ILeafElementRenderer
Text
public float getDescent()
getDescent in interface ILeafElementRenderer
Text
public float getYLine()
Text's contents will be written.
DrawContext
public void moveYLineTo(float y)
y - the new vertical position of the Text
public void setText(String text)
text - the replacement text
public void setText(GlyphLine text, PdfFont font)
text - the GlyphLine
font - the font
public GlyphLine getText()
public int length()
public String toString()
AbstractRenderer
toString in class AbstractRenderer
String
Object.toString()
public int charAt(int pos)
pos - the position in range [0; length())
public float getTabAnchorCharacterPosition()
public IRenderer getNextRenderer()
layout(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 extend TextRenderer, 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 of TextRenderer's extension is createCopy(GlyphLine, PdfFont). This method is responsible for creation of TextRenderer's copies, which represent its parts of specific font.
getNextRenderer in interface IRenderer
public static float[] calculateAscenderDescender(PdfFont font)
font - from which metrics will be extracted
public static float[] calculateAscenderDescender(PdfFont font, RenderingMode mode)
font - from which metrics will be extracted
mode - mode in which metrics will be obtained. Impact on the use of scale coefficient
protected Rectangle getBackgroundArea(Rectangle occupiedAreaWithMargins)
AbstractRenderer
getBackgroundArea in class AbstractRenderer
occupiedAreaWithMargins - the current occupied area with applied margins
protected Float getFirstYLineRecursively()
AbstractRenderer
getFirstYLineRecursively in class AbstractRenderer
protected Float getLastYLineRecursively()
getLastYLineRecursively in class AbstractRenderer
protected int lineLength()
line which is the result of the layout call.
protected int baseCharactersCount()
public MinMaxWidth getMinMaxWidth()
AbstractRenderer
getMinMaxWidth in class AbstractRenderer
MinMaxWidth
protected int getNumberOfSpaces()
protected TextRenderer createSplitRenderer()
protected TextRenderer createOverflowRenderer()
protected TextRenderer[] split(int initialOverflowTextPos)
protected void drawSingleUnderline(Underline underline, TransparentColor fontStrokeColor, PdfCanvas canvas, float fontSize, float italicAngleTan)
protected float calculateLineWidth()
protected boolean resolveFonts(List<IRenderer> addTo)
Property.FONT String[] value.
addTo - add all processed renderers to.
TextRenderer has been created.
protected void setProcessedGlyphLineAndFont(GlyphLine gl, PdfFont font)
protected TextRenderer createCopy(GlyphLine gl, PdfFont font)
TextRenderer, which corresponds to the passed GlyphLine with PdfFont.
While processing TextRenderer, iText uses this method to create glyph lines of specific fonts, which represent the TextRenderer's parts. If one extends TextRenderer, one should override this method, otherwise if FontSelector related logic is triggered, copies of this TextRenderer will have the default behavior rather than the custom one.
gl - a GlyphLine which represents some of this TextRenderer's content
font - a PdfFont for this part of the TextRenderer's content
TextRenderer, which correspond to the passed GlyphLine with PdfFont
Copyright © 1998–2022 iText Group NV. All rights reserved.