Table of Contents

Class TextRenderer

Namespace
iText.Layout.Renderer
Assembly
itext.layout.dll

This class represents the renderer object for a Text object.

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

textElement Text

the Text which this object should manage

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

textElement Text

the Text which this object should manage

text string

the replacement text

TextRenderer(TextRenderer)

protected TextRenderer(TextRenderer other)

Parameters

other TextRenderer

Fields

TEXT_SPACE_COEFF

protected const float TEXT_SPACE_COEFF = 1000

Field Value

float

line

protected GlyphLine line

Field Value

GlyphLine

otfFeaturesApplied

protected bool otfFeaturesApplied

Field Value

bool

reversedRanges

protected IList<int[]> reversedRanges

Field Value

IList<int[]>

savedWordBreakAtLineEnding

protected GlyphLine savedWordBreakAtLineEnding

Field Value

GlyphLine

strToBeConverted

protected string strToBeConverted

Field Value

string

tabAnchorCharacterPosition

protected float tabAnchorCharacterPosition

Field Value

float

text

protected GlyphLine text

Field Value

GlyphLine

yLineOffset

protected float yLineOffset

Field Value

float

Methods

ApplyOtf()

public virtual void ApplyOtf()

BaseCharactersCount()

protected virtual int BaseCharactersCount()

Returns

int

CalculateAscenderDescender(PdfFont)

Get ascender and descender from font metrics.

public static float[] CalculateAscenderDescender(PdfFont font)

Parameters

font PdfFont

from 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 PdfFont

from 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

float

CharAt(int)

Gets char code at given position for the text belonging to this renderer.

public virtual int CharAt(int pos)

Parameters

pos int

the 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 GlyphLine

a GlyphLine which represents some of this TextRenderer 's content

font PdfFont

a 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

TextRenderer

CreateSplitRenderer()

protected virtual TextRenderer CreateSplitRenderer()

Returns

TextRenderer

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 Underline
fontStrokeColor TransparentColor
canvas PdfCanvas
fontSize float
italicAngleTan float

GetAscent()

Gets the maximum offset above the base line that this Text extends to.

public virtual float GetAscent()

Returns

float

the upwards vertical offset of this Text

GetBackgroundArea(Rectangle)

protected override Rectangle GetBackgroundArea(Rectangle occupiedAreaWithMargins)

Parameters

occupiedAreaWithMargins Rectangle

Returns

Rectangle

GetDescent()

Gets the maximum offset below the base line that this Text extends to.

public virtual float GetDescent()

Returns

float

the downwards vertical offset of this Text

GetFirstYLineRecursively()

protected override float? GetFirstYLineRecursively()

Returns

float?

GetLastYLineRecursively()

protected override float? GetLastYLineRecursively()

Returns

float?

GetMinMaxWidth()

public override MinMaxWidth GetMinMaxWidth()

Returns

MinMaxWidth

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

int

GetTabAnchorCharacterPosition()

public virtual float GetTabAnchorCharacterPosition()

Returns

float

GetText()

public virtual GlyphLine GetText()

Returns

GlyphLine

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

LayoutResult

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 float

the new vertical position of the Text

ResolveFonts(IList<IRenderer>)

Resolve FONT String[] value.

protected virtual bool ResolveFonts(IList<IRenderer> addTo)

Parameters

addTo IList<IRenderer>

add all processed renderers to.

Returns

bool

true, if new TextRenderer has been created.

SetProcessedGlyphLineAndFont(GlyphLine, PdfFont)

protected virtual void SetProcessedGlyphLineAndFont(GlyphLine gl, PdfFont font)

Parameters

gl GlyphLine
font PdfFont

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 string

the replacement text

SetText(GlyphLine, PdfFont)

Manually set a GlyphLine and PdfFont for rendering.

public virtual void SetText(GlyphLine text, PdfFont font)

Parameters

text GlyphLine

the GlyphLine

font PdfFont

the font

Split(int)

protected virtual TextRenderer[] Split(int initialOverflowTextPos)

Parameters

initialOverflowTextPos int

Returns

TextRenderer[]

ToString()

public override string ToString()

Returns

string

TrimFirst()

Trims any whitespace characters from the start of the GlyphLine to be rendered.

public virtual void TrimFirst()