Class DWriteTextLayout
The IDWriteTextLayout interface represents a block of text after it has been fully analyzed and formatted. All coordinates are in device independent pixels (DIPs).
Implements
Inherited Members
Namespace: JeremyAnsel.DirectX.DWrite
Assembly: JeremyAnsel.DirectX.DWrite.dll
Syntax
[SecurityCritical]
public class DWriteTextLayout : DWriteTextFormat, IDisposable
Constructors
| Edit this page View SourceDWriteTextLayout(nint)
Initializes a new instance of the DWriteTextLayout class.
Declaration
public DWriteTextLayout(nint comPtr)
Parameters
| Type | Name | Description |
|---|---|---|
| nint | comPtr |
Fields
| Edit this page View SourceDWriteTextLayoutGuid
The interface GUID.
Declaration
public static readonly Guid DWriteTextLayoutGuid
Field Value
| Type | Description |
|---|---|
| Guid |
Properties
| Edit this page View SourceMaxHeight
Gets or sets the layout maximum height
Declaration
public float MaxHeight { get; set; }
Property Value
| Type | Description |
|---|---|
| float |
MaxWidth
Gets or sets the layout maximum width
Declaration
public float MaxWidth { get; set; }
Property Value
| Type | Description |
|---|---|
| float |
Methods
| Edit this page View SourceDetermineMinWidth()
Determines the minimum possible width the layout can be set to without emergency breaking between the characters of whole words.
Declaration
public float DetermineMinWidth()
Returns
| Type | Description |
|---|---|
| float |
GetFontCollection(uint, out DWriteTextRange)
Get the font collection where the current position is at.
Declaration
public DWriteFontCollection GetFontCollection(uint currentPosition, out DWriteTextRange textRange)
Parameters
| Type | Name | Description |
|---|---|---|
| uint | currentPosition | The current text position. |
| DWriteTextRange | textRange | Text range to which this change applies. |
Returns
| Type | Description |
|---|---|
| DWriteFontCollection |
GetFontFamilyName(uint, out DWriteTextRange)
Copy the font family name where the current position is at.
Declaration
public string GetFontFamilyName(uint currentPosition, out DWriteTextRange textRange)
Parameters
| Type | Name | Description |
|---|---|---|
| uint | currentPosition | The current text position. |
| DWriteTextRange | textRange | The position range of the current format. |
Returns
| Type | Description |
|---|---|
| string |
GetFontFamilyName(uint, out DWriteTextRange, Span<char>)
Copy the font family name where the current position is at.
Declaration
public void GetFontFamilyName(uint currentPosition, out DWriteTextRange textRange, Span<char> name)
Parameters
| Type | Name | Description |
|---|---|---|
| uint | currentPosition | The current text position. |
| DWriteTextRange | textRange | The position range of the current format. |
| Span<char> | name | The name. |
GetFontFamilyNameLength(uint, out DWriteTextRange)
Get the length of the font family name where the current position is at.
Declaration
public uint GetFontFamilyNameLength(uint currentPosition, out DWriteTextRange textRange)
Parameters
| Type | Name | Description |
|---|---|---|
| uint | currentPosition | The current text position. |
| DWriteTextRange | textRange | The position range of the current format. |
Returns
| Type | Description |
|---|---|
| uint |
GetFontSize(uint, out DWriteTextRange)
Get the font em height where the current position is at.
Declaration
public float GetFontSize(uint currentPosition, out DWriteTextRange textRange)
Parameters
| Type | Name | Description |
|---|---|---|
| uint | currentPosition | The current text position. |
| DWriteTextRange | textRange | The position range of the current format. |
Returns
| Type | Description |
|---|---|
| float |
GetFontStretch(uint, out DWriteTextRange)
Get the font stretch where the current position is at.
Declaration
public DWriteFontStretch GetFontStretch(uint currentPosition, out DWriteTextRange textRange)
Parameters
| Type | Name | Description |
|---|---|---|
| uint | currentPosition | The current text position. |
| DWriteTextRange | textRange | The position range of the current format. |
Returns
| Type | Description |
|---|---|
| DWriteFontStretch |
GetFontStyle(uint, out DWriteTextRange)
Get the font style where the current position is at.
Declaration
public DWriteFontStyle GetFontStyle(uint currentPosition, out DWriteTextRange textRange)
Parameters
| Type | Name | Description |
|---|---|---|
| uint | currentPosition | The current text position. |
| DWriteTextRange | textRange | The position range of the current format. |
Returns
| Type | Description |
|---|---|
| DWriteFontStyle |
GetFontWeight(uint, out DWriteTextRange)
Get the font weight where the current position is at.
Declaration
public DWriteFontWeight GetFontWeight(uint currentPosition, out DWriteTextRange textRange)
Parameters
| Type | Name | Description |
|---|---|---|
| uint | currentPosition | The current text position. |
| DWriteTextRange | textRange | The position range of the current format. |
Returns
| Type | Description |
|---|---|
| DWriteFontWeight |
GetLocaleName(uint, out DWriteTextRange)
Get the locale name where the current position is at.
Declaration
public string GetLocaleName(uint currentPosition, out DWriteTextRange textRange)
Parameters
| Type | Name | Description |
|---|---|---|
| uint | currentPosition | The current text position. |
| DWriteTextRange | textRange | The position range of the current format. |
Returns
| Type | Description |
|---|---|
| string |
GetLocaleName(uint, out DWriteTextRange, Span<char>)
Get the locale name where the current position is at.
Declaration
public void GetLocaleName(uint currentPosition, out DWriteTextRange textRange, Span<char> name)
Parameters
| Type | Name | Description |
|---|---|---|
| uint | currentPosition | The current text position. |
| DWriteTextRange | textRange | The position range of the current format. |
| Span<char> | name | The name. |
GetLocaleNameLength(uint, out DWriteTextRange)
Get the length of the locale name where the current position is at.
Declaration
public uint GetLocaleNameLength(uint currentPosition, out DWriteTextRange textRange)
Parameters
| Type | Name | Description |
|---|---|---|
| uint | currentPosition | The current text position. |
| DWriteTextRange | textRange | The position range of the current format. |
Returns
| Type | Description |
|---|---|
| uint |
GetMetrics()
GetMetrics retrieves overall metrics for the formatted string.
Declaration
public DWriteTextMetrics GetMetrics()
Returns
| Type | Description |
|---|---|
| DWriteTextMetrics |
Remarks
Drawing effects like underline and strikethrough do not contribute to the text size, which is essentially the sum of advance widths and line heights. Additionally, visible swashes and other graphic adornments may extend outside the returned width and height.
GetOverhangMetrics()
GetOverhangMetrics returns the overhangs (in DIPs) of the layout and all objects contained in it, including text glyphs and inline objects.
Declaration
public DWriteOverhangMetrics GetOverhangMetrics()
Returns
| Type | Description |
|---|---|
| DWriteOverhangMetrics |
Remarks
Any underline and strikethrough do not contribute to the black box determination, since these are actually drawn by the renderer, which is allowed to draw them in any variety of styles.
GetStrikethrough(uint, out DWriteTextRange)
Get the strikethrough presence where the current position is at.
Declaration
public bool GetStrikethrough(uint currentPosition, out DWriteTextRange textRange)
Parameters
| Type | Name | Description |
|---|---|---|
| uint | currentPosition | The current text position. |
| DWriteTextRange | textRange | The position range of the current format. |
Returns
| Type | Description |
|---|---|
| bool |
GetTypography(uint, out DWriteTextRange)
Get the typography setting where the current position is at.
Declaration
public DWriteTypography GetTypography(uint currentPosition, out DWriteTextRange textRange)
Parameters
| Type | Name | Description |
|---|---|---|
| uint | currentPosition | The current text position. |
| DWriteTextRange | textRange | The position range of the current format. |
Returns
| Type | Description |
|---|---|
| DWriteTypography |
GetUnderline(uint, out DWriteTextRange)
Get the underline presence where the current position is at.
Declaration
public bool GetUnderline(uint currentPosition, out DWriteTextRange textRange)
Parameters
| Type | Name | Description |
|---|---|---|
| uint | currentPosition | The current text position. |
| DWriteTextRange | textRange | The position range of the current format. |
Returns
| Type | Description |
|---|---|
| bool |
HitTestPoint(float, float, out bool, out bool)
Given a coordinate (in DIPs) relative to the top-left of the layout box, this returns the corresponding hit-test metrics of the text string where the hit-test has occurred. This is useful for mapping mouse clicks to caret positions. When the given coordinate is outside the text string, the function sets the output value isInside to false but returns the nearest character position.
Declaration
public DWriteHitTestMetrics HitTestPoint(float pointX, float pointY, out bool isTrailingHit, out bool isInside)
Parameters
| Type | Name | Description |
|---|---|---|
| float | pointX | X coordinate to hit-test, relative to the top-left location of the layout box. |
| float | pointY | Y coordinate to hit-test, relative to the top-left location of the layout box. |
| bool | isTrailingHit | Output flag indicating whether the hit-test location is at the leading or the trailing side of the character. When the output isInside value is set to false, this value is set according to the output position value to represent the edge closest to the hit-test location. |
| bool | isInside | Output flag indicating whether the hit-test location is inside the text string. When false, the position nearest the text's edge is returned. |
Returns
| Type | Description |
|---|---|
| DWriteHitTestMetrics |
HitTestTextPosition(uint, bool, out float, out float)
Given a text position and whether the caret is on the leading or trailing edge of that position, this returns the corresponding coordinate (in DIPs) relative to the top-left of the layout box. This is most useful for drawing the caret's current position, but it could also be used to anchor an IME to the typed text or attach a floating menu near the point of interest. It may also be used to programmatically obtain the geometry of a particular text position for UI automation.
Declaration
public DWriteHitTestMetrics HitTestTextPosition(uint textPosition, bool isTrailingHit, out float pointX, out float pointY)
Parameters
| Type | Name | Description |
|---|---|---|
| uint | textPosition | Text position to get the coordinate of. |
| bool | isTrailingHit | Flag indicating whether the location is of the leading or the trailing side of the specified text position. |
| float | pointX | Output caret X, relative to the top-left of the layout box. |
| float | pointY | Output caret Y, relative to the top-left of the layout box. |
Returns
| Type | Description |
|---|---|
| DWriteHitTestMetrics |
Remarks
When drawing a caret at the returned X,Y, it should be centered on X and drawn from the Y coordinate down. The height will be the size of the hit-tested text (which can vary in size within a line). Reading direction also affects which side of the character the caret is drawn. However, the returned X coordinate will be correct for either case. You can get a text length back that is larger than a single character. This happens for complex scripts when multiple characters form a single cluster, when diacritics join their base character, or when you test a surrogate pair.
SetFontCollection(DWriteFontCollection?, DWriteTextRange)
Set the font collection.
Declaration
public void SetFontCollection(DWriteFontCollection? fontCollection, DWriteTextRange textRange)
Parameters
| Type | Name | Description |
|---|---|---|
| DWriteFontCollection | fontCollection | The font collection to set |
| DWriteTextRange | textRange | Text range to which this change applies. |
SetFontFamilyName(ReadOnlySpan<char>, DWriteTextRange)
Set null-terminated font family name.
Declaration
public void SetFontFamilyName(ReadOnlySpan<char> fontFamilyName, DWriteTextRange textRange)
Parameters
| Type | Name | Description |
|---|---|---|
| ReadOnlySpan<char> | fontFamilyName | Font family name |
| DWriteTextRange | textRange | Text range to which this change applies. |
SetFontFamilyName(string, DWriteTextRange)
Set null-terminated font family name.
Declaration
public void SetFontFamilyName(string fontFamilyName, DWriteTextRange textRange)
Parameters
| Type | Name | Description |
|---|---|---|
| string | fontFamilyName | Font family name |
| DWriteTextRange | textRange | Text range to which this change applies. |
SetFontSize(float, DWriteTextRange)
Set font em height.
Declaration
public void SetFontSize(float fontSize, DWriteTextRange textRange)
Parameters
| Type | Name | Description |
|---|---|---|
| float | fontSize | Font em height |
| DWriteTextRange | textRange | Text range to which this change applies. |
SetFontStretch(DWriteFontStretch, DWriteTextRange)
Set font stretch.
Declaration
public void SetFontStretch(DWriteFontStretch fontStretch, DWriteTextRange textRange)
Parameters
| Type | Name | Description |
|---|---|---|
| DWriteFontStretch | fontStretch | font stretch |
| DWriteTextRange | textRange | Text range to which this change applies. |
SetFontStyle(DWriteFontStyle, DWriteTextRange)
Set font style.
Declaration
public void SetFontStyle(DWriteFontStyle fontStyle, DWriteTextRange textRange)
Parameters
| Type | Name | Description |
|---|---|---|
| DWriteFontStyle | fontStyle | Font style |
| DWriteTextRange | textRange | Text range to which this change applies. |
SetFontWeight(DWriteFontWeight, DWriteTextRange)
Set font weight.
Declaration
public void SetFontWeight(DWriteFontWeight fontWeight, DWriteTextRange textRange)
Parameters
| Type | Name | Description |
|---|---|---|
| DWriteFontWeight | fontWeight | Font weight |
| DWriteTextRange | textRange | Text range to which this change applies. |
SetLocaleName(ReadOnlySpan<char>, DWriteTextRange)
Set locale name.
Declaration
public void SetLocaleName(ReadOnlySpan<char> localeName, DWriteTextRange textRange)
Parameters
| Type | Name | Description |
|---|---|---|
| ReadOnlySpan<char> | localeName | Locale name |
| DWriteTextRange | textRange | Text range to which this change applies. |
SetLocaleName(string, DWriteTextRange)
Set locale name.
Declaration
public void SetLocaleName(string localeName, DWriteTextRange textRange)
Parameters
| Type | Name | Description |
|---|---|---|
| string | localeName | Locale name |
| DWriteTextRange | textRange | Text range to which this change applies. |
SetStrikethrough(bool, DWriteTextRange)
Set strikethrough.
Declaration
public void SetStrikethrough(bool hasStrikethrough, DWriteTextRange textRange)
Parameters
| Type | Name | Description |
|---|---|---|
| bool | hasStrikethrough | The Boolean flag indicates whether strikethrough takes place |
| DWriteTextRange | textRange | Text range to which this change applies. |
SetTypography(DWriteTypography?, DWriteTextRange)
Set font typography features.
Declaration
public void SetTypography(DWriteTypography? typography, DWriteTextRange textRange)
Parameters
| Type | Name | Description |
|---|---|---|
| DWriteTypography | typography | Pointer to font typography setting. |
| DWriteTextRange | textRange | Text range to which this change applies. |
SetUnderline(bool, DWriteTextRange)
Set underline.
Declaration
public void SetUnderline(bool hasUnderline, DWriteTextRange textRange)
Parameters
| Type | Name | Description |
|---|---|---|
| bool | hasUnderline | The Boolean flag indicates whether underline takes place |
| DWriteTextRange | textRange | Text range to which this change applies. |