CanvasTextLayout Class |
Namespace: Microsoft.Graphics.Canvas.Text
public sealed class CanvasTextLayout : IDisposable
The CanvasTextLayout type exposes the following members.
Name | Description | |
---|---|---|
CanvasTextLayout | Initializes a new instance of the CanvasTextLayout class. |
Name | Description | |
---|---|---|
ClusterMetrics | Gets an array of metrics describing each cluster. | |
CustomTrimmingSign | Gets or sets a custom trimming sign. | |
DefaultFontFamily | Specifies the font family name for ranges of the layout that don't have an explicitly specified font family name. | |
DefaultFontSize | Specifies the font size for ranges of the layout without an explicitly specified font size. | |
DefaultFontStretch | Specifies the font stretch for ranges of the layout without an explicitly specified font stretch. | |
DefaultFontStyle | Specifies the font style for ranges of the layout without an explicitly specified font style. | |
DefaultFontWeight | Specifies the font weight for ranges of the layout without an explicitly specified font weight. | |
DefaultLocaleName | Specifies the locale name for ranges of the layout without an explicitly specified locale name. | |
Device | Gets the device associated with this text layout. | |
Direction | Specifies the direction in which the text is read. | |
DrawBounds | Gets the bounds of the parts of the text that would get drawn. | |
HorizontalAlignment | Specifies the horizontal paragraph alignment. | |
IncrementalTabStop | Specifies the incremental tab stop position. | |
LastLineWrapping | Specifies whether or not the last word on the last line is wrapped. | |
LayoutBounds | Gets the bounds of the parts of the text that align to the layout. | |
LayoutBoundsIncludingTrailingWhitespace | Gets a rectangle describing the bounds of text, plus any trailing whitespace. | |
LineCount | Gets the number of lines in the text layout. | |
LineMetrics | Gets an array of metrics describing each line. | |
LineSpacing | Negative values use default line spacing; non-negative values specify the line height. | |
LineSpacingBaseline | Specifies the distance from top of line to baseline. A reasonable ratio to lineSpacing is 80 percent. | |
LineSpacingMode | Specifies how lines are spaced apart. | |
MaximumBidiReorderingDepth | Gets the maximum reordering depth for direction changes of bi-directional text. | |
OpticalAlignment | Specifies the optical margin aligment for the text layout. | |
Options | Specifies text drawing options. | |
RequestedSize | Specifies the requested size. | |
TrimmingDelimiter |
A character used as the delimiter that signals the beginning of the portion of text to be preserved.
| |
TrimmingDelimiterCount | A value that indicates how many occurrences of the delimiter, counted from the end
of the text, are allowed before trimming is desired. | |
TrimmingGranularity | Specifies the granularity used to trim text overflowing the layout box. | |
TrimmingSign | Specifies the type of trimming sign used, when text is drawn outside a text layout's requested size extents. | |
VerticalAlignment | Specifies the vertical paragraph alignment. | |
VerticalGlyphOrientation | Specifies the orientation of glyphs when a vertical reading direction is used. | |
WordWrapping | Specifies word wrapping behavior. |
Name | Description | |
---|---|---|
Dispose | Releases all resources used by the CanvasTextLayout. | |
DrawToTextRenderer(ICanvasTextRenderer, Vector2) | Draws this text layout to an application-defined text renderer. | |
DrawToTextRenderer(ICanvasTextRenderer, Single, Single) | Draws this text layout to an application-defined text renderer. | |
GetBrush | Gets the brush associated with a character index in the text layout. | |
GetCaretPosition(Int32, Boolean) | Gets position where the caret (text cursor) would be, given the current text position and caret direction. | |
GetCaretPosition(Int32, Boolean, CanvasTextLayoutRegion) | Gets position where the caret (text cursor) would be, given the current text position and caret direction. | |
GetCharacterRegions | Gets an array of descriptions of the range of text. | |
GetCustomBrush | Gets the custom brush associated with a character index in the text layout. | |
GetFontFamily | Gets the font family of the character at the specified position. | |
GetFontSize | Gets the font size for the character at the specified position. | |
GetFontStretch | Gets the font stretch for the character at the specified position. | |
GetFontStyle | Gets the font style for the character at the specified position. | |
GetFontWeight | Gets the font weight for the character at the specified position. | |
GetFormatChangeIndices | Gets an array of position indices at which the text format changes. | |
GetGlyphOrientationTransform | Gets a transform matrix to use when drawing a glyph run. | |
GetInlineObject | Gets the inline object for the character at the position specified. | |
GetLeadingCharacterSpacing | Gets the the spacing before the character specified, in reading order. | |
GetLocaleName | Specifies the locale name for the character at the specified position. | |
GetMinimumCharacterAdvance | Gets the minimum advance of the character specified. | |
GetMinimumLineLength | Gets the minimum possible width/height the layout can be set to, without any emergency breakings between the characters of whole words. | |
GetPairKerning | Gets whether pair kerning is used for the character at the position specified. | |
GetStrikethrough | Gets whether the character at the specified position has strikethrough. | |
GetTrailingCharacterSpacing | Gets the spacing after the character specified, in reading order. | |
GetTypography |
Gets the typography features that affect the character at the position specified.
| |
GetUnderline | Gets whether the character at the specified position is underlined. | |
HitTest(Vector2) | Gets whether the point overlaps with any text in the text layout. | |
HitTest(Single, Single) | Gets whether the point overlaps with any text in the text layout. | |
HitTest(Vector2, CanvasTextLayoutRegion) | Gets whether the point overlaps with any text in the text layout. | |
HitTest(Single, Single, CanvasTextLayoutRegion) | Gets whether the point overlaps with any text in the text layout. | |
HitTest(Vector2, CanvasTextLayoutRegion, Boolean) | Gets whether the point overlaps with any text in the text layout. | |
HitTest(Single, Single, CanvasTextLayoutRegion, Boolean) | Gets whether the point overlaps with any text in the text layout. | |
SetBrush | Sets the brush associated with a group of characters in the text layout. | |
SetCharacterSpacing | Sets the spacing between characters. | |
SetColor | Sets the color associated with a group of characters in the text layout. | |
SetCustomBrush | Sets the custom brush associated with a group of characters in the text layout. | |
SetFontFamily | Sets the font family of the specified group of characters. | |
SetFontSize | Sets the font size of the specified group of characters. | |
SetFontStretch | Sets the font stretch of the specified group of characters. | |
SetFontStyle | Sets the font style of the specified group of characters. | |
SetFontWeight | Sets the font weight of the specified group of characters. | |
SetInlineObject | Sets the inline object for a specified group of characters. | |
SetLocaleName | Sets the local name of the specified group of characters. | |
SetPairKerning | Sets whether pair kerning is used for the group of characters specified. | |
SetStrikethrough | Applies strikethrough formatting to the specified group of characters. | |
SetTypography |
Sets the typography features that affect a specified group of characters.
| |
SetUnderline | Applies underline formatting to the specified group of characters. |
Use CanvasTextLayout to display rich text combining different formatting options, and to query the size and layout of such text after it has been wordwrapped.
If you are going to draw the same piece of text more than once, CanvasTextLayout can be faster than DrawText Overload, because it can reuse layout computations rather than repeating them every time the text is drawn.
When using Direct2D interop, this Win2D class corresponds to the Direct2D interface IDWriteTextLayout3.
var format = new CanvasTextFormat(); var textLayout = new CanvasTextLayout("A piece of text", format, layoutWidth, layoutHeight);
using (var ds = renderTarget.CreateDrawingSession()) { ds.DrawTextLayout(textLayout, 100, 200, Colors.White); // White text is drawn at (100, 200) }