Class AdvancedTextRenderer
Advanced text renderer is used to perform the following tasks:
- draw justified text, text with custom line height, text containing html tags;
- calculate text height, get part of text that does not fit in the display rectangle;
- get paragraphs, lines, words and char sequence to perform accurate export to such formats as PDF, TXT, RTF
Inheritance
Namespace: FastReport.Utils
Assembly: FastReport.Base.dll
Syntax
public class AdvancedTextRenderer
Examples
Here is how one may operate the renderer items:
foreach (AdvancedTextRenderer.Paragraph paragraph in renderer.Paragraphs)
{
foreach (AdvancedTextRenderer.Line line in paragraph.Lines)
{
foreach (AdvancedTextRenderer.Word word in line.Words)
{
if (renderer.HtmlTags)
{
foreach (AdvancedTextRenderer.Run run in word.Runs)
{
using (Font f = run.GetFont())
using (Brush b = run.GetBrush())
{
g.DrawString(run.Text, f, b, run.Left, run.Top, renderer.Format);
}
}
}
else
{
g.DrawString(word.Text, renderer.Font, renderer.Brush, word.Left, word.Top, renderer.Format);
}
}
}
}
Constructors
AdvancedTextRenderer(String, IGraphics, Font, Brush, Pen, RectangleF, StringFormat, HorzAlign, VertAlign, Single, Int32, Single, Boolean, Boolean, Boolean, Boolean, Single, Single, InlineImageCache, Boolean)
Initializes a new instance of AdvancedTextRenderer class.
Declaration
public AdvancedTextRenderer(string text, IGraphics g, Font font, Brush brush, Pen outlinePen, RectangleF rect, StringFormat format, HorzAlign horzAlign, VertAlign vertAlign, float lineHeight, int angle, float widthRatio, bool forceJustify, bool wysiwyg, bool htmlTags, bool pdfMode, float scale, float fontScale, InlineImageCache cache, bool isPrinting = false)
Parameters
| Type | Name | Description |
|---|---|---|
| System.String | text | The text to render. |
| IGraphics | g | Graphics context. |
| Font | font | Default font. |
| Brush | brush | Text brush. |
| Pen | outlinePen | Text outline pen. |
| RectangleF | rect | Display rect. |
| StringFormat | format | String format. |
| HorzAlign | horzAlign | Horizontal text align. |
| VertAlign | vertAlign | Vertical text align. |
| System.Single | lineHeight | Line height. |
| System.Int32 | angle | Text angle. |
| System.Single | widthRatio | Font width ratio. |
| System.Boolean | forceJustify | Force text justification. |
| System.Boolean | wysiwyg | Wysiwyg mode. |
| System.Boolean | htmlTags | Enable simple html tags. |
| System.Boolean | pdfMode | PDF mode. |
| System.Single | scale | Scale factor. |
| System.Single | fontScale | Font scale. |
| InlineImageCache | cache | Image cache. |
| System.Boolean | isPrinting | Is printing. |
Properties
Angle
Gets text angle.
Declaration
public int Angle { get; }
Property Value
| Type | Description |
|---|---|
| System.Int32 |
Brush
Gets brush.
Declaration
public Brush Brush { get; }
Property Value
| Type | Description |
|---|---|
| Brush |
BrushColor
Gets a brush color.
Declaration
public Color BrushColor { get; }
Property Value
| Type | Description |
|---|---|
| Color |
Cache
Gets image cache.
Declaration
public InlineImageCache Cache { get; }
Property Value
| Type | Description |
|---|---|
| InlineImageCache |
DisplayRect
Gets display rect.
Declaration
public RectangleF DisplayRect { get; }
Property Value
| Type | Description |
|---|---|
| RectangleF |
Font
Gets initial font.
Declaration
public Font Font { get; }
Property Value
| Type | Description |
|---|---|
| Font |
FontLineHeight
Gets defaul font line height.
Declaration
public float FontLineHeight { get; }
Property Value
| Type | Description |
|---|---|
| System.Single |
FontScale
The scale for font tag
Declaration
public float FontScale { get; set; }
Property Value
| Type | Description |
|---|---|
| System.Single |
ForceJustify
Determines if horizontal justification should be forced.
Declaration
public bool ForceJustify { get; }
Property Value
| Type | Description |
|---|---|
| System.Boolean |
Format
Gets string format.
Declaration
public StringFormat Format { get; }
Property Value
| Type | Description |
|---|---|
| StringFormat |
Graphics
Gets graphics context.
Declaration
public IGraphics Graphics { get; }
Property Value
| Type | Description |
|---|---|
| IGraphics |
HasLineHeight
Determines if line height was set explicitly.
Declaration
public bool HasLineHeight { get; }
Property Value
| Type | Description |
|---|---|
| System.Boolean |
HorzAlign
Gets horizontal text align.
Declaration
public HorzAlign HorzAlign { get; }
Property Value
| Type | Description |
|---|---|
| HorzAlign |
HtmlTags
Gets html tags value.
Declaration
public bool HtmlTags { get; }
Property Value
| Type | Description |
|---|---|
| System.Boolean |
LineHeight
Gets line height.
Declaration
public float LineHeight { get; }
Property Value
| Type | Description |
|---|---|
| System.Single |
OutlinePen
Gets outline pen.
Declaration
public Pen OutlinePen { get; }
Property Value
| Type | Description |
|---|---|
| Pen |
Paragraphs
Gets a list of paragraphs.
Declaration
public List<AdvancedTextRenderer.Paragraph> Paragraphs { get; }
Property Value
| Type | Description |
|---|---|
| System.Collections.Generic.List<AdvancedTextRenderer.Paragraph> |
PDFMode
Gets PDF mode.
Declaration
public bool PDFMode { get; }
Property Value
| Type | Description |
|---|---|
| System.Boolean |
RightToLeft
Gets RTL value.
Declaration
public bool RightToLeft { get; }
Property Value
| Type | Description |
|---|---|
| System.Boolean |
Scale
Gets scale ratio.
Declaration
public float Scale { get; set; }
Property Value
| Type | Description |
|---|---|
| System.Single |
TabOffset
Gets tab offset.
Declaration
public float TabOffset { get; }
Property Value
| Type | Description |
|---|---|
| System.Single |
TabSize
Gets tab size.
Declaration
public float TabSize { get; }
Property Value
| Type | Description |
|---|---|
| System.Single |
VertAlign
Gets vertical text align.
Declaration
public VertAlign VertAlign { get; }
Property Value
| Type | Description |
|---|---|
| VertAlign |
WidthRatio
Gets font width ratio.
Declaration
public float WidthRatio { get; }
Property Value
| Type | Description |
|---|---|
| System.Single |
WordWrap
Gets word wrap.
Declaration
public bool WordWrap { get; }
Property Value
| Type | Description |
|---|---|
| System.Boolean |
Wysiwyg
Gets wysiwyg value.
Declaration
public bool Wysiwyg { get; }
Property Value
| Type | Description |
|---|---|
| System.Boolean |
Methods
CalcHeight()
Calculates text height.
Declaration
public float CalcHeight()
Returns
| Type | Description |
|---|---|
| System.Single | Text height. |
CalcHeight(out Int32, out AdvancedTextRenderer.StyleDescriptor)
Calculates text height.
Declaration
public float CalcHeight(out int charsFit, out AdvancedTextRenderer.StyleDescriptor style)
Parameters
| Type | Name | Description |
|---|---|---|
| System.Int32 | charsFit | Chars fitted. |
| AdvancedTextRenderer.StyleDescriptor | style | Style descriptor. |
Returns
| Type | Description |
|---|---|
| System.Single | Text height. |
CalcWidth()
Calculates text width.
Declaration
public float CalcWidth()
Returns
| Type | Description |
|---|---|
| System.Single | Text width. |
Draw()
Draws a text.
Declaration
public void Draw()