Class TextBlock
A block of text that wraps at its width, with an optional border, background and padding. Without a height the block is as tall as its text; with one the text that does not fit is cut, and the lines are aligned to the top, the center or the bottom of the block.
Use a TextBlock for one run of text in one font: a label, a note, a table cell or a paragraph in a box. It breaks words that do not fit on a line, wraps right to left and Thai text, highlights keywords and can be cut to a height. Use a TextColumn for paragraphs of TextLine objects that differ in font or color, for justified text or for a rotated column, and a TextFrame for text that flows from one frame to the next. See Example_01, 10 and 11.
public class TextBlock : IDrawable
- Inheritance
-
TextBlock
- Implements
- Inherited Members
Constructors
TextBlock(Font, string)
Creates a text block with the specified font and text.
public TextBlock(Font font, string textContent)
Parameters
Methods
DrawOn(Page)
Draws this text block on the specified page.
public float[] DrawOn(Page page)
Parameters
pagePage
Returns
- float[]
GetBackgroundColor()
Returns the background color.
public float[] GetBackgroundColor()
Returns
- float[]
GetBorderColor()
Returns the border color, or null.
public float[] GetBorderColor()
Returns
- float[]
GetBorderWidth()
Returns the border width.
public float GetBorderWidth()
Returns
GetFont()
Returns the font of the text.
public Font GetFont()
Returns
GetHeight()
Returns the height of this text block as it is drawn: the height set with SetHeight or SetSize, or the height of the text and padding without one.
public float GetHeight()
Returns
GetLocation()
Returns the x and y coordinates of the top left corner of this text block.
public float[] GetLocation()
Returns
- float[]
GetPadding()
Returns the space between the text and the border.
public float GetPadding()
Returns
GetStrikeout()
Returns whether the text is struck out.
public bool GetStrikeout()
Returns
GetText()
Returns the text.
public string GetText()
Returns
GetTextAlignment()
Returns the horizontal alignment of the text.
public Alignment GetTextAlignment()
Returns
GetTextColor()
Returns the text color.
public float[] GetTextColor()
Returns
- float[]
GetUnderline()
Returns whether the text is underlined.
public bool GetUnderline()
Returns
GetVerticalAlignment()
Returns the vertical alignment of the text.
public Alignment GetVerticalAlignment()
Returns
GetWidth()
Returns the width of this text block.
public float GetWidth()
Returns
SetBackgroundColor(int)
Sets the background color as a 0xRRGGBB value. Color.transparent removes the background.
public TextBlock SetBackgroundColor(int color)
Parameters
colorint
Returns
SetBackgroundColor(float[])
Sets the background color from an array of red, green and blue values.
public TextBlock SetBackgroundColor(float[] rgbColor)
Parameters
rgbColorfloat[]
Returns
SetBorderColor(int)
Sets the border color as a 0xRRGGBB value. Color.transparent removes the border.
public TextBlock SetBorderColor(int color)
Parameters
colorint
Returns
SetBorderColor(float[])
Sets the border color from an array of red, green and blue values.
public TextBlock SetBorderColor(float[] rgbColor)
Parameters
rgbColorfloat[]
Returns
SetBorderWidth(float)
Sets the border width.
public TextBlock SetBorderWidth(float borderWidth)
Parameters
borderWidthfloat
Returns
SetCornerRadius(float)
Sets the radius of the border corners.
public TextBlock SetCornerRadius(float borderCornerRadius)
Parameters
borderCornerRadiusfloat
Returns
SetFallbackFont(Font)
Sets the font used for characters the main font does not have.
public TextBlock SetFallbackFont(Font font)
Parameters
fontFont
Returns
SetFallbackFontSize(float)
Sets the size of the characters drawn in the fallback font. By default they are drawn at the font size.
public TextBlock SetFallbackFontSize(float fontSize)
Parameters
fontSizefloat
Returns
SetFont(Font)
Sets the font of the text. The fallback font changes with it, unless a different fallback font was set.
public TextBlock SetFont(Font font)
Parameters
fontFont
Returns
SetFontSize(float)
Sets the font size.
public TextBlock SetFontSize(float fontSize)
Parameters
fontSizefloat
Returns
SetHeight(float)
Sets the height of this text block. With a height above 0 the block is that tall: the lines that do not fit are cut, the last line that fits ends with "...", and the lines are aligned by the vertical alignment. A height of 0 is the height of the text.
public TextBlock SetHeight(float height)
Parameters
heightfloat
Returns
SetHighlightColors(Dictionary<string, int>)
Sets the colors used to highlight keywords. The keywords are matched ignoring case.
public TextBlock SetHighlightColors(Dictionary<string, int> map)
Parameters
mapDictionary<string, int>
Returns
SetLanguage(string)
Sets the language of the text, for example "he", "ar" or "fa", as a BCP 47 language tag. The text is marked with it, for screen readers and text extraction.
public TextBlock SetLanguage(string language)
Parameters
languagestring
Returns
SetLineSpacing(float)
Sets the line spacing as a multiple of the font's body height.
public TextBlock SetLineSpacing(float lineSpacing)
Parameters
lineSpacingfloat
Returns
SetLocation(float, float)
Sets the location of the top left corner of this text block.
public TextBlock SetLocation(float x, float y)
Parameters
Returns
SetPadding(float)
Sets the space between the text and the border.
public TextBlock SetPadding(float padding)
Parameters
paddingfloat
Returns
SetRightToLeft(bool)
Sets whether the text is right to left, like Arabic and Hebrew text. Each paragraph is wrapped at the width in logical order, and each line is then reordered with Bidi.ReorderVisually, which also shapes the Arabic letters, and aligned to the right, unless the text alignment is Alignment.CENTER.
public TextBlock SetRightToLeft(bool rightToLeft)
Parameters
rightToLeftbool
Returns
SetSize(float, float)
Sets the size of this text block. With a height above 0 the block is that tall: the lines that do not fit are cut, the last line that fits ends with "...", and the lines are aligned by the vertical alignment. A height of 0 is the height of the text.
public TextBlock SetSize(float width, float height)
Parameters
Returns
SetStrikeout(bool)
Sets whether the text is struck out.
public TextBlock SetStrikeout(bool strikeout)
Parameters
strikeoutbool
Returns
SetStructureType(StructElem)
Sets the structure element type of this text block, for example StructElem.P, the default, or StructElem.H1 for a heading, as a tagged document, PDF/UA or a PDF/A of level A, tags it.
public TextBlock SetStructureType(StructElem structureType)
Parameters
structureTypeStructElem
Returns
SetText(string)
Sets the text.
public TextBlock SetText(string text)
Parameters
textstring
Returns
SetTextAlignment(Alignment)
Sets the horizontal alignment of the text.
public TextBlock SetTextAlignment(Alignment textAlignment)
Parameters
textAlignmentAlignment
Returns
SetTextColor(int)
Sets the text color as a 0xRRGGBB value. Color.transparent leaves the text color unchanged.
public TextBlock SetTextColor(int color)
Parameters
colorint
Returns
SetTextColor(float[])
Sets the text color from an array of red, green and blue values. A null color leaves the text color unchanged.
public TextBlock SetTextColor(float[] textColor)
Parameters
textColorfloat[]
Returns
SetURIAction(string)
Sets the URI opened when this text block is clicked.
public TextBlock SetURIAction(string uri)
Parameters
uristring
Returns
SetUnderline(bool)
Sets whether the text is underlined.
public TextBlock SetUnderline(bool underline)
Parameters
underlinebool
Returns
SetVerticalAlignment(Alignment)
Sets the vertical alignment of the text in a block with a height: Alignment.TOP, the default, Alignment.CENTER or Alignment.BOTTOM.
public TextBlock SetVerticalAlignment(Alignment verticalAlignment)
Parameters
verticalAlignmentAlignment
Returns
SetWidth(float)
Sets the width of this text block and resets its height, so the height fits the text.
public TextBlock SetWidth(float width)
Parameters
widthfloat