Class TextRenderer
public class TextRenderer : AbstractRenderer, ILeafElementRenderer, IRenderer, IPropertyContainer
- Inheritance
-
TextRenderer
- Implements
- Derived
- Inherited Members
Remarks
This class represents the renderer object for a Text object. It will draw the glyphs of the textual content on the DrawContext.
Constructors
TextRenderer(Text)
Creates a TextRenderer from its corresponding layout object.
public TextRenderer(Text textElement)
Parameters
TextRenderer(Text, string)
Creates a TextRenderer from its corresponding layout object, with a custom text to replace the contents of the Text.
public TextRenderer(Text textElement, string text)
Parameters
TextRenderer(TextRenderer)
protected TextRenderer(TextRenderer other)
Parameters
other
TextRenderer
Fields
TEXT_SPACE_COEFF
protected const float TEXT_SPACE_COEFF = 1000
Field Value
line
protected GlyphLine line
Field Value
otfFeaturesApplied
protected bool otfFeaturesApplied
Field Value
reversedRanges
protected IList<int[]> reversedRanges
Field Value
savedWordBreakAtLineEnding
protected GlyphLine savedWordBreakAtLineEnding
Field Value
strToBeConverted
protected string strToBeConverted
Field Value
tabAnchorCharacterPosition
protected float tabAnchorCharacterPosition
Field Value
text
protected GlyphLine text
Field Value
yLineOffset
protected float yLineOffset
Field Value
Methods
ApplyOtf()
public virtual void ApplyOtf()
BaseCharactersCount()
protected virtual int BaseCharactersCount()
Returns
CalculateAscenderDescender(PdfFont)
Get ascender and descender from font metrics.
public static float[] CalculateAscenderDescender(PdfFont font)
Parameters
font
PdfFontfrom which metrics will be extracted
Returns
- float[]
array in which the first element is an ascender and the second is a descender
Remarks
Get ascender and descender from font metrics. If these values are obtained from typo metrics they are normalized with a scale coefficient.
CalculateAscenderDescender(PdfFont, RenderingMode?)
Get ascender and descender from font metrics.
public static float[] CalculateAscenderDescender(PdfFont font, RenderingMode? mode)
Parameters
font
PdfFontfrom which metrics will be extracted
mode
RenderingMode?mode in which metrics will be obtained. Impact on the use of scale coefficient
Returns
- float[]
array in which the first element is an ascender and the second is a descender
Remarks
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.
CalculateLineWidth()
protected virtual float CalculateLineWidth()
Returns
CharAt(int)
Gets char code at given position for the text belonging to this renderer.
public virtual int CharAt(int pos)
Parameters
pos
intthe position in range [0; length())
Returns
- int
Unicode char code
CreateCopy(GlyphLine, PdfFont)
Creates a copy of this TextRenderer , which corresponds to the passed GlyphLine with PdfFont.
protected virtual TextRenderer CreateCopy(GlyphLine gl, PdfFont font)
Parameters
gl
GlyphLinea GlyphLine which represents some of this TextRenderer 's content
font
PdfFonta PdfFont for this part of the TextRenderer 's content
Returns
- TextRenderer
copy of this TextRenderer , which correspond to the passed GlyphLine with PdfFont
Remarks
Creates a copy of this 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.CreateOverflowRenderer()
protected virtual TextRenderer CreateOverflowRenderer()
Returns
CreateSplitRenderer()
protected virtual TextRenderer CreateSplitRenderer()
Returns
Draw(DrawContext)
public override void Draw(DrawContext drawContext)
Parameters
drawContext
DrawContext
DrawSingleUnderline(Underline, TransparentColor, PdfCanvas, float, float)
protected virtual void DrawSingleUnderline(Underline underline, TransparentColor fontStrokeColor, PdfCanvas canvas, float fontSize, float italicAngleTan)
Parameters
underline
UnderlinefontStrokeColor
TransparentColorcanvas
PdfCanvasfontSize
floatitalicAngleTan
float
GetAscent()
Gets the maximum offset above the base line that this Text extends to.
public virtual float GetAscent()
Returns
GetBackgroundArea(Rectangle)
protected override Rectangle GetBackgroundArea(Rectangle occupiedAreaWithMargins)
Parameters
occupiedAreaWithMargins
Rectangle
Returns
GetDescent()
Gets the maximum offset below the base line that this Text extends to.
public virtual float GetDescent()
Returns
GetFirstYLineRecursively()
protected override float? GetFirstYLineRecursively()
Returns
GetLastYLineRecursively()
protected override float? GetLastYLineRecursively()
Returns
GetMinMaxWidth()
public override MinMaxWidth GetMinMaxWidth()
Returns
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.
public override IRenderer GetNextRenderer()
Returns
- IRenderer
new renderer instance
Remarks
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.
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.GetNumberOfSpaces()
protected virtual int GetNumberOfSpaces()
Returns
GetTabAnchorCharacterPosition()
public virtual float GetTabAnchorCharacterPosition()
Returns
GetText()
public virtual GlyphLine GetText()
Returns
GetYLine()
Gets the position on the canvas of the imaginary horizontal line upon which the Text 's contents will be written.
public virtual float GetYLine()
Returns
- float
the y position of this text on the DrawContext
Layout(LayoutContext)
public override LayoutResult Layout(LayoutContext layoutContext)
Parameters
layoutContext
LayoutContext
Returns
Length()
The length of the whole text assigned to this renderer.
public virtual int Length()
Returns
- int
the text length
LineLength()
Returns the length of the line which is the result of the layout call.
protected virtual int LineLength()
Returns
- int
the length of the line
MoveYLineTo(float)
Moves the vertical position to the parameter's value.
public virtual void MoveYLineTo(float y)
Parameters
y
floatthe new vertical position of the Text
ResolveFonts(IList<IRenderer>)
Resolve FONT String[] value.
protected virtual bool ResolveFonts(IList<IRenderer> addTo)
Parameters
Returns
- bool
true, if new TextRenderer has been created.
SetProcessedGlyphLineAndFont(GlyphLine, PdfFont)
protected virtual void SetProcessedGlyphLineAndFont(GlyphLine gl, PdfFont font)
Parameters
SetText(string)
Manually sets the contents of the Text's representation on the canvas, regardless of the Text's own contents.
public virtual void SetText(string text)
Parameters
text
stringthe replacement text
SetText(GlyphLine, PdfFont)
Manually set a GlyphLine and PdfFont for rendering.
public virtual void SetText(GlyphLine text, PdfFont font)
Parameters
Split(int)
protected virtual TextRenderer[] Split(int initialOverflowTextPos)
Parameters
initialOverflowTextPos
int
Returns
ToString()
public override string ToString()
Returns
TrimFirst()
Trims any whitespace characters from the start of the GlyphLine to be rendered.
public virtual void TrimFirst()