Class TextRenderer
- All Implemented Interfaces:
IPropertyContainer, ILeafElementRenderer, IRenderer
- Direct Known Subclasses:
FormFieldValueNonTrimmingTextRenderer, LinkRenderer, ListRenderer.ConstantFontTextRenderer
renderer object for a Text
object. It will draw the glyphs of the textual content on the DrawContext.-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionprivate static final classprivate static classprivate static class -
Field Summary
FieldsModifier and TypeFieldDescriptionprivate static final floatprivate PdfFontprivate static final floatprivate intprivate static final floatprotected GlyphLineprotected booleanprotected List<int[]> protected GlyphLineprivate intprotected Stringprotected floatprotected GlyphLineprotected static final float(package private) static final float(package private) static final intprotected 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
ConstructorsModifierConstructorDescriptionTextRenderer(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.protectedTextRenderer(TextRenderer other) -
Method Summary
Modifier and TypeMethodDescriptionvoidapplyOtf()protected intstatic float[]Get ascender and descender from font metrics.static float[]calculateAscenderDescender(PdfFont font, RenderingMode mode) Get ascender and descender from font metrics.protected floatintcharAt(int pos) Gets char code at given position for the text belonging to this renderer.(package private) static booleancodePointIsOfSpecialScript(int codePoint) private GlyphLineconvertToGlyphLine(String text) protected TextRenderercreateCopy(GlyphLine gl, PdfFont font) protected TextRendererprotected TextRenderervoiddraw(DrawContext drawContext) Flushes the renderer subtree contents, i.e.private voiddrawAndTagSingleUnderline(boolean isTagged, Underline underline, TransparentColor fontStrokeColor, PdfCanvas canvas, float fontSize, float italicAngleTan) protected voiddrawSingleUnderline(Underline underline, TransparentColor fontColor, PdfCanvas canvas, float fontSize, float italicAngleTan) private voiddrawText(PdfCanvas canvas, UnitValue fontSize, boolean italicSimulation, Integer textRenderingMode, Float strokeWidth, TransparentColor fontColor, TransparentColor strokeColor) (package private) static intfindPossibleBreaksSplitPosition(List<Integer> list, int textStartBasedInitialOverflowTextPos, boolean amongPresentOnly) floatGets the maximum offset above the base line that this Text extends to.protected RectanglegetBackgroundArea(Rectangle occupiedAreaWithMargins) Evaluate the actual backgroundprivate floatgetCharWidth(Glyph g, float fontSize, Float hScale, Float characterSpacing, Float wordSpacing) floatGets the maximum offset below the base line that this Text extends to.protected FloatGets the first yLine of the nested children recursively.private floatgetGlyphLineWidth(GlyphLine glyphLine, float fontSize, float hScale, Float characterSpacing, Float wordSpacing) protected FloatCalculates 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(package private) List<int[]> (package private) intfloatgetText()private int[]getWordBoundsForHyphenation(GlyphLine text, int leftTextPos, int rightTextPos, int wordMiddleCharPos) floatgetYLine()Gets the position on the canvas of the imaginary horizontal line upon which theText's contents will be written.private static booleanglyphBelongsToNonBreakingHyphenRelatedChunk(GlyphLine text, int ind) private booleanprivate voidincreaseYLineOffset(UnitValue[] paddings, Border[] borders, UnitValue[] margins) (package private) List<int[]> private boolean(package private) boolean[]isStartsWithSplitCharWhiteSpaceAndEndsWithSplitChar(ISplitCharacters splitCharacters) Identifies two properties for the layouted text renderer text: start and end break possibilities.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.intlength()The length of the whole text assigned to this renderer.protected intReturns the length of thelinewhich is the result of the layout call.voidmoveYLineTo(float y) Moves the vertical position to the parameter's value.private static booleanprivate static intnumberOfElementsLessThan(ArrayList<Integer> numbers, int n) private static intnumberOfElementsLessThanOrEqual(ArrayList<Integer> numbers, int n) (package private) TextRenderer(package private) PdfFontresolveFirstPdfFont(String[] font, FontProvider provider, FontCharacteristics fc, FontSet additionalFonts) Get first validPdfFontfor this renderer, based on given font-families, font provider and font characteristics.protected booleanresolveFonts(List<IRenderer> addTo) ResolveProperty.FONTString[] value.private voidsaveWordBreakIfNotYetSaved(Glyph wordBreak) private floatscaleXAdvance(float xAdvance, float fontSize, Float hScale) (package private) voidsetIndexOfFirstCharacterToBeForcedToOverflow(int indexOfFirstCharacterToBeForcedToOverflow) protected voidsetProcessedGlyphLineAndFont(GlyphLine gl, PdfFont font) (package private) voidsetSpecialScriptFirstNotFittingIndex(int lastFittingIndex) (package private) voidsetSpecialScriptsWordBreakPoints(List<Integer> specialScriptsWordBreakPoints) voidManually set a GlyphLine and PdfFont for rendering.voidManually sets the contents of the Text's representation on the canvas, regardless of the Text's own contents.protected TextRenderer[]split(int initialOverflowTextPos) private TextRenderer[]splitIgnoreFirstNewLine(int currentTextPos) (package private) booleantextContainsSpecialScriptGlyphs(boolean analyzeSpecialScriptsWordBreakPointsOnly) Analyzes/checks whethertext, bounded by start and end, contains glyphs belonging to special script.toString()Returns a string representation of the renderer.voidTrims any whitespace characters from the start of theGlyphLineto be rendered.(package private) floattrimLast()private void(package private) static voidupdateRangeBasedOnRemovedCharacters(ArrayList<Integer> removedIds, int[] range) Methods inherited from class AbstractRenderer
addAllChildRenderers, addAllChildRenderers, addAllProperties, addChild, addChildRenderer, alignChildHorizontally, allowLastYLineRecursiveExtraction, applyAbsolutePosition, applyAbsolutePositionIfNeeded, applyAction, applyBorderBox, applyBorderBox, applyDestination, applyDestinationsAndAnnotation, applyLinkAnnotation, applyMargins, applyMargins, applyMarginsBordersPaddings, applyPaddings, applyPaddings, applyRelativePositioningTranslation, beginElementOpacityApplying, beginTransformationIfApplied, calculateAbsolutePdfBBox, calculateAdditionalWidth, calculateBBox, calculatePaddingBorderHeight, calculatePaddingBorderWidth, calculateShiftToPositionBBoxOfPointsAt, clipBackgroundArea, clipBackgroundArea, clipBorderArea, createFontCharacteristics, createXObject, deleteOwnProperty, deleteProperty, drawBackground, drawBorder, drawChildren, drawPositionedChildren, endElementOpacityApplying, endTransformationIfApplied, getAspectRatio, getBorderAreaBBox, getBorderRadii, getBorders, getBorders, getChildRenderers, getDefaultProperty, getInnerAreaBBox, getMargins, getMinMaxWidth, getModelElement, getOccupiedArea, getOccupiedAreaBBox, getOwnProperties, getOwnProperty, getPaddings, getParent, getPdfDocument, getProperty, getProperty, getPropertyAsBoolean, getPropertyAsColor, getPropertyAsFloat, getPropertyAsFloat, getPropertyAsFloat, getPropertyAsFont, getPropertyAsInteger, getPropertyAsTransparentColor, getPropertyAsUnitValue, getPropertyAsUnitValue, getRootRenderer, hasAbsoluteUnitValue, hasAspectRatio, hasOwnOrModelProperty, hasOwnProperty, hasProperty, hasRelativeUnitValue, initElementAreas, isAbsolutePosition, isBorderBoxSizing, isFirstOnRootArea, isFirstOnRootArea, isFixedLayout, isFlushed, isKeepTogether, isKeepTogether, isNotFittingHeight, isNotFittingLayoutArea, isNotFittingWidth, isOverflowFit, isOverflowProperty, isOverflowProperty, isOverflowProperty, isPositioned, isRelativePosition, isStaticLayout, logWarningIfGetNextRendererNotOverridden, move, noAbsolutePositionInfo, preparePositionedRendererAndAreaForLayout, processWaitingDrawing, rectangleToPointsList, removeAllChildRenderers, removeChildRenderer, replaceOwnProperty, resolveFirstPdfFont, retrieveHeight, retrieveMaxHeight, retrieveMaxWidth, retrieveMinHeight, retrieveMinWidth, retrieveResolvedDeclaredHeight, retrieveUnitValue, retrieveUnitValue, retrieveWidth, returnBackOwnProperty, setBorders, setChildRenderer, setChildRenderers, setMinMaxWidthBasedOnFixedWidth, setParent, setProperty, setThisAsParent, shrinkOccupiedAreaForAbsolutePosition, 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, move, setParent
-
Field Details
-
TEXT_SPACE_COEFF
protected static final float TEXT_SPACE_COEFF- See Also:
-
TYPO_ASCENDER_SCALE_COEFF
static final float TYPO_ASCENDER_SCALE_COEFF- See Also:
-
UNDEFINED_FIRST_CHAR_TO_FORCE_OVERFLOW
static final int UNDEFINED_FIRST_CHAR_TO_FORCE_OVERFLOW- See Also:
-
ITALIC_ANGLE
private static final float ITALIC_ANGLE- See Also:
-
BOLD_SIMULATION_STROKE_COEFF
private static final float BOLD_SIMULATION_STROKE_COEFF- See Also:
-
HEIGHT_EPS
private static final float HEIGHT_EPS- See Also:
-
yLineOffset
protected float yLineOffset -
font
-
text
-
line
-
strToBeConverted
-
otfFeaturesApplied
protected boolean otfFeaturesApplied -
tabAnchorCharacterPosition
protected float tabAnchorCharacterPosition -
reversedRanges
-
savedWordBreakAtLineEnding
-
specialScriptsWordBreakPoints
-
specialScriptFirstNotFittingIndex
private int specialScriptFirstNotFittingIndex -
indexOfFirstCharacterToBeForcedToOverflow
private int indexOfFirstCharacterToBeForcedToOverflow
-
-
Constructor Details
-
TextRenderer
-
TextRenderer
-
TextRenderer
-
-
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. -
increaseYLineOffset
-
applyOtf
public void applyOtf() -
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
-
trimFirst
public void trimFirst()Trims any whitespace characters from the start of theGlyphLineto be rendered. -
trimLast
float trimLast() -
getAscent
public float getAscent()Gets the maximum offset above the base line that this Text extends to.- Specified by:
getAscentin 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:
getDescentin 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
-
getText
-
length
public int length()The length of the whole text assigned to this renderer.- Returns:
- the text length
-
toString
Description copied from class:AbstractRendererReturns a string representation of the renderer.- Overrides:
toStringin 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
TextRendereroverflows 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:
getNextRendererin 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 extractedmode- 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
-
getReversedRanges
List<int[]> getReversedRanges() -
initReversedRanges
List<int[]> initReversedRanges() -
removeReversedRanges
TextRenderer removeReversedRanges() -
splitIgnoreFirstNewLine
-
convertToGlyphLine
-
hasOtfFont
private boolean hasOtfFont() -
textContainsSpecialScriptGlyphs
boolean textContainsSpecialScriptGlyphs(boolean analyzeSpecialScriptsWordBreakPointsOnly) Analyzes/checks whethertext, bounded by start and end, contains glyphs belonging to special script. Mind that the behavior of this method depends on the analyzeSpecialScriptsWordBreakPointsOnly parameter: - passfalseif you need to analyze thetextby checking each of its glyphs AND to fillspecialScriptsWordBreakPointslist afterwards, i.e. when analyzing a sequence of TextRenderers prior to layouting; - passtrueif you want to check if text contains glyphs belonging to special scripts, according to the already filledspecialScriptsWordBreakPointslist.- Parameters:
analyzeSpecialScriptsWordBreakPointsOnly- false if analysis of each glyph is required, true if analysis has already been performed earlier and the results are stored inspecialScriptsWordBreakPoints- Returns:
- true if
text, bounded by start and end, contains glyphs belonging to special script, otherwise false - See Also:
-
setSpecialScriptsWordBreakPoints
-
getSpecialScriptsWordBreakPoints
-
setSpecialScriptFirstNotFittingIndex
void setSpecialScriptFirstNotFittingIndex(int lastFittingIndex) -
getSpecialScriptFirstNotFittingIndex
int getSpecialScriptFirstNotFittingIndex() -
setIndexOfFirstCharacterToBeForcedToOverflow
void setIndexOfFirstCharacterToBeForcedToOverflow(int indexOfFirstCharacterToBeForcedToOverflow) -
getBackgroundArea
Description copied from class:AbstractRendererEvaluate the actual background- Overrides:
getBackgroundAreain classAbstractRenderer- Parameters:
occupiedAreaWithMargins- the current occupied area with applied margins- Returns:
- the actual background area
-
getFirstYLineRecursively
Description copied from class:AbstractRendererGets 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:
getFirstYLineRecursivelyin classAbstractRenderer- Returns:
- the first yline of the nested children, null if there is no text found
-
getLastYLineRecursively
- Overrides:
getLastYLineRecursivelyin classAbstractRenderer
-
lineLength
protected int lineLength()Returns the length of thelinewhich is the result of the layout call.- Returns:
- the length of the line
-
baseCharactersCount
protected int baseCharactersCount() -
getMinMaxWidth
Description copied from class:AbstractRendererCalculates min and max width values for current renderer.- Overrides:
getMinMaxWidthin classAbstractRenderer- Returns:
- instance of
MinMaxWidth
-
getNumberOfSpaces
protected int getNumberOfSpaces() -
createSplitRenderer
-
createOverflowRenderer
-
split
-
drawSingleUnderline
protected void drawSingleUnderline(Underline underline, TransparentColor fontColor, PdfCanvas canvas, float fontSize, float italicAngleTan) -
calculateLineWidth
protected float calculateLineWidth() -
resolveFonts
ResolveProperty.FONTString[] value.- Parameters:
addTo- add all processed renderers to.- Returns:
- true, if new
TextRendererhas been created.
-
setProcessedGlyphLineAndFont
-
createCopy
Creates a copy of thisTextRenderer, which corresponds to the passedGlyphLinewithPdfFont.While processing
TextRenderer, iText uses this method to createglyph linesof specificfonts, which represent theTextRenderer's parts. If one extendsTextRenderer, one should override this method, otherwise ifFontSelectorrelated logic is triggered, copies of thisTextRendererwill have the default behavior rather than the custom one.- Parameters:
gl- aGlyphLinewhich represents some of thisTextRenderer's contentfont- aPdfFontfor this part of theTextRenderer's content- Returns:
- copy of this
TextRenderer, which correspond to the passedGlyphLinewithPdfFont
-
updateRangeBasedOnRemovedCharacters
-
findPossibleBreaksSplitPosition
-
codePointIsOfSpecialScript
static boolean codePointIsOfSpecialScript(int codePoint) -
resolveFirstPdfFont
PdfFont resolveFirstPdfFont(String[] font, FontProvider provider, FontCharacteristics fc, FontSet additionalFonts) Description copied from class:AbstractRendererGet first validPdfFontfor this renderer, based on given font-families, font provider and font characteristics. This method will not change font property of renderer. Also it is not guarantied that returned font will contain all glyphs used in renderer or its children.This method is usually needed for evaluating some layout characteristics like ascender or descender.
- Overrides:
resolveFirstPdfFontin classAbstractRenderer- Returns:
- a valid
PdfFontinstance based on rendererProperty.FONTproperty.
-
isStartsWithSplitCharWhiteSpaceAndEndsWithSplitChar
Identifies two properties for the layouted text renderer text: start and end break possibilities. First - if it ends with split character, second - if it starts with the split character which is at the same time is a whitespace character. These properties will later be used for identifying if we can consider this and previous/next text renderers chunks to be a part of a single word spanning across the text renderers boundaries. In the start of the text renderer we only care about split characters, which are white spaces, because only such will allow soft-breaks before them: normally split characters allow breaks only after them.- Parameters:
splitCharacters- current rendererISplitCharactersproperty value- Returns:
- a boolean array of two elements, where first element identifies start break possibility, and second - end break possibility.
-
drawText
private void drawText(PdfCanvas canvas, UnitValue fontSize, boolean italicSimulation, Integer textRenderingMode, Float strokeWidth, TransparentColor fontColor, TransparentColor strokeColor) -
drawAndTagSingleUnderline
private void drawAndTagSingleUnderline(boolean isTagged, Underline underline, TransparentColor fontStrokeColor, PdfCanvas canvas, float fontSize, float italicAngleTan) -
getCharWidth
-
scaleXAdvance
-
getGlyphLineWidth
-
getWordBoundsForHyphenation
private int[] getWordBoundsForHyphenation(GlyphLine text, int leftTextPos, int rightTextPos, int wordMiddleCharPos) -
isGlyphPartOfWordForHyphenation
-
updateFontAndText
private void updateFontAndText() -
saveWordBreakIfNotYetSaved
-
numberOfElementsLessThan
-
numberOfElementsLessThanOrEqual
-
noPrint
-
glyphBelongsToNonBreakingHyphenRelatedChunk
-