Class TextLayout
- Namespace
- SharpDX.DirectWrite
- Assembly
- SharpDX.Direct2D1.dll
[Guid("53737037-6d14-410b-9bfe-0b182bb70961")]
public class TextLayout : TextFormat
- Inheritance
-
TextLayout
- Derived
- Inherited Members
Constructors
TextLayout(Factory, string, TextFormat, float, float)
Takes a string, text format, and associated constraints, and produces an object that represents the fully analyzed and formatted result.
public TextLayout(Factory factory, string text, TextFormat textFormat, float maxWidth, float maxHeight)
Parameters
factory
Factoryan instance of Factory
text
stringAn array of characters that contains the string to create a new TextLayout object from. This array must be of length stringLength and can contain embedded NULL characters.
textFormat
TextFormatA pointer to an object that indicates the format to apply to the string.
maxWidth
floatThe width of the layout box.
maxHeight
floatThe height of the layout box.
TextLayout(Factory, string, TextFormat, float, float, float, bool)
Create a Gdi Compatible TextLayout. Takes a string, format, and associated constraints, and produces an object representing the result, formatted for a particular display resolution and measuring mode.
public TextLayout(Factory factory, string text, TextFormat textFormat, float layoutWidth, float layoutHeight, float pixelsPerDip, bool useGdiNatural)
Parameters
factory
Factoryan instance of Factory
text
stringAn array of characters that contains the string to create a new TextLayout object from. This array must be of length stringLength and can contain embedded NULL characters.
textFormat
TextFormatThe text formatting object to apply to the string.
layoutWidth
floatThe width of the layout box.
layoutHeight
floatThe height of the layout box.
pixelsPerDip
floatThe number of physical pixels per DIP (device independent pixel). For example, if rendering onto a 96 DPI device pixelsPerDip is 1. If rendering onto a 120 DPI device pixelsPerDip is 1.25 (120/96).
useGdiNatural
boolInstructs the text layout to use the same metrics as GDI bi-level text when set to FALSE. When set to TRUE, instructs the text layout to use the same metrics as text measured by GDI using a font created with CLEARTYPE_NATURAL_QUALITY.
Remarks
The resulting text layout should only be used for the intended resolution, and for cases where text scalability is desired {{CreateTextLayout}} should be used instead.
TextLayout(Factory, string, TextFormat, float, float, float, RawMatrix3x2?, bool)
Create a GDI Compatible TextLayout. Takes a string, format, and associated constraints, and produces an object representing the result, formatted for a particular display resolution and measuring mode.
public TextLayout(Factory factory, string text, TextFormat textFormat, float layoutWidth, float layoutHeight, float pixelsPerDip, RawMatrix3x2? transform, bool useGdiNatural)
Parameters
factory
Factoryan instance of Factory
text
stringAn array of characters that contains the string to create a new TextLayout object from. This array must be of length stringLength and can contain embedded NULL characters.
textFormat
TextFormatThe text formatting object to apply to the string.
layoutWidth
floatThe width of the layout box.
layoutHeight
floatThe height of the layout box.
pixelsPerDip
floatThe number of physical pixels per DIP (device independent pixel). For example, if rendering onto a 96 DPI device pixelsPerDip is 1. If rendering onto a 120 DPI device pixelsPerDip is 1.25 (120/96).
transform
RawMatrix3x2?An optional transform applied to the glyphs and their positions. This transform is applied after the scaling specifies the font size and pixels per DIP.
useGdiNatural
boolInstructs the text layout to use the same metrics as GDI bi-level text when set to FALSE. When set to TRUE, instructs the text layout to use the same metrics as text measured by GDI using a font created with CLEARTYPE_NATURAL_QUALITY.
Remarks
The resulting text layout should only be used for the intended resolution, and for cases where text scalability is desired {{CreateTextLayout}} should be used instead.
TextLayout(nint)
public TextLayout(nint nativePtr)
Parameters
nativePtr
nint
Properties
MaxHeight
Gets or sets the layout maximum height.
public float MaxHeight { get; set; }
Property Value
MaxWidth
Gets or sets the layout maximum width.
public float MaxWidth { get; set; }
Property Value
Metrics
Retrieves overall metrics for the formatted string.
public TextMetrics Metrics { get; }
Property Value
OverhangMetrics
Returns the overhangs (in DIPs) of the layout and all objects contained in it, including text glyphs and inline objects.
public OverhangMetrics OverhangMetrics { get; }
Property Value
Remarks
Underlines and strikethroughs 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.
Methods
DetermineMinWidth()
Determines the minimum possible width the layout can be set to without emergency breaking between the characters of whole words occurring.
public float DetermineMinWidth()
Returns
- float
Minimum width.
Draw(TextRenderer, float, float)
Draws text using the specified client drawing context.
public void Draw(TextRenderer renderer, float originX, float originY)
Parameters
renderer
TextRendererPointer to the set of callback functions used to draw parts of a text string.
originX
floatThe x-coordinate of the layout's left side.
originY
floatThe y-coordinate of the layout's top side.
Remarks
To draw text with this method, a textLayout object needs to be created by the application using SharpDX.DirectWrite.Factory.CreateTextLayout(System.String,System.Int32,SharpDX.DirectWrite.TextFormat,System.Single,System.Single,SharpDX.DirectWrite.TextLayout). After the textLayout object is obtained, the application calls the IDWriteTextLayout::Draw method to draw the text, decorations, and inline objects. The actual drawing is done through the callback interface passed in as the textRenderer argument; there, the corresponding DrawGlyphRun API is called.
Draw(nint, TextRenderer, float, float)
Draws text using the specified client drawing context.
public void Draw(nint clientDrawingContext, TextRenderer renderer, float originX, float originY)
Parameters
clientDrawingContext
nintAn application-defined drawing context.
renderer
TextRendererPointer to the set of callback functions used to draw parts of a text string.
originX
floatThe x-coordinate of the layout's left side.
originY
floatThe y-coordinate of the layout's top side.
Remarks
To draw text with this method, a textLayout object needs to be created by the application using IDWriteFactory::CreateTextLayout.
After the textLayout object is obtained, the application calls the IDWriteTextLayout::Draw method to draw the text, decorations, and inline objects. The actual drawing is done through the callback interface passed in as the textRenderer argument; there, the corresponding DrawGlyphRun API is called.
If you set a vertical text reading direction on TextLayout via SetReadingDirection with DWRITE_READING_DIRECTION_TOP_TO_BOTTOM (or bottom to top), then you must pass an interface that implements TextRenderer1. Otherwise you get the error DWRITE_E_TEXTRENDERERINCOMPATIBLE because the original TextRenderer interface only supported horizontal text.
Draw(object, TextRenderer, float, float)
Draws text using the specified client drawing context.
public void Draw(object clientDrawingContext, TextRenderer renderer, float originX, float originY)
Parameters
clientDrawingContext
objectAn application-defined drawing context.
renderer
TextRendererPointer to the set of callback functions used to draw parts of a text string.
originX
floatThe x-coordinate of the layout's left side.
originY
floatThe y-coordinate of the layout's top side.
Remarks
To draw text with this method, a textLayout object needs to be created by the application using SharpDX.DirectWrite.Factory.CreateTextLayout(System.String,System.Int32,SharpDX.DirectWrite.TextFormat,System.Single,System.Single,SharpDX.DirectWrite.TextLayout). After the textLayout object is obtained, the application calls the IDWriteTextLayout::Draw method to draw the text, decorations, and inline objects. The actual drawing is done through the callback interface passed in as the textRenderer argument; there, the corresponding DrawGlyphRun API is called.
GetClusterMetrics()
Retrieves logical properties and measurements of each glyph cluster.
public ClusterMetrics[] GetClusterMetrics()
Returns
- ClusterMetrics[]
Returns metrics, such as line-break or total advance width, for a glyph cluster.
Remarks
If maxClusterCount is not large enough, then E_NOT_SUFFICIENT_BUFFER, which is equivalent to HRESULT_FROM_WIN32(ERROR_INSUFFICIENT_BUFFER), is returned and actualClusterCount is set to the number of clusters needed.
GetDrawingEffect(int)
Gets the application-defined drawing effect at the specified text position.
public ComObject GetDrawingEffect(int currentPosition)
Parameters
currentPosition
intThe position of the text whose drawing effect is to be retrieved.
Returns
- ComObject
a reference to the current application-defined drawing effect. Usually this effect is a foreground brush that is used in glyph drawing.
GetDrawingEffect(int, out TextRange)
Gets the application-defined drawing effect at the specified text position.
public ComObject GetDrawingEffect(int currentPosition, out TextRange textRange)
Parameters
currentPosition
intThe position of the text whose drawing effect is to be retrieved.
textRange
TextRangeContains the range of text that has the same formatting as the text at the position specified by currentPosition. This means the run has the exact formatting as the position specified, including but not limited to the drawing effect.
Returns
- ComObject
a reference to the current application-defined drawing effect. Usually this effect is a foreground brush that is used in glyph drawing.
GetFontCollection(int)
Gets the font collection associated with the text at the specified position.
public FontCollection GetFontCollection(int currentPosition)
Parameters
currentPosition
intThe position of the text to inspect.
Returns
- FontCollection
a reference to the current font collection.
GetFontCollection(int, out TextRange)
Gets the font collection associated with the text at the specified position.
public FontCollection GetFontCollection(int currentPosition, out TextRange textRange)
Parameters
currentPosition
intThe position of the text to inspect.
textRange
TextRangeThe range of text that has the same formatting as the text at the position specified by currentPosition. This means the run has the exact formatting as the position specified, including but not limited to the underline.
Returns
- FontCollection
Contains an address of a reference to the current font collection.
GetFontFamilyName(int)
Gets the font family name of the text at the specified position.
public string GetFontFamilyName(int currentPosition)
Parameters
currentPosition
intThe position of the text to examine.
Returns
- string
the font family name
GetFontFamilyName(int, out TextRange)
Gets the font family name of the text at the specified position.
public string GetFontFamilyName(int currentPosition, out TextRange textRange)
Parameters
currentPosition
intThe position of the text to examine.
textRange
TextRangeThe range of text that has the same formatting as the text at the position specified by currentPosition. This means the run has the exact formatting as the position specified, including but not limited to the font family name.
Returns
- string
the font family name
GetFontSize(int)
Gets the font em height of the text at the specified position.
public float GetFontSize(int currentPosition)
Parameters
currentPosition
intThe position of the text to inspect.
Returns
- float
The size of the font in ems of the text at the specified position.
GetFontSize(int, out TextRange)
Gets the font em height of the text at the specified position.
public float GetFontSize(int currentPosition, out TextRange textRange)
Parameters
currentPosition
intThe position of the text to inspect.
textRange
TextRangeThe range of text that has the same formatting as the text at the position specified by currentPosition. This means the run has the exact formatting as the position specified, including but not limited to the font size.
Returns
- float
When this method returns, contains the size of the font in ems of the text at the specified position.
GetFontStretch(int)
Gets the font stretch of the text at the specified position.
public FontStretch GetFontStretch(int currentPosition)
Parameters
currentPosition
intThe position of the text to inspect.
Returns
- FontStretch
a value which indicates the type of font stretch (also known as width) being applied at the specified position.
GetFontStretch(int, out TextRange)
Gets the font stretch of the text at the specified position.
public FontStretch GetFontStretch(int currentPosition, out TextRange textRange)
Parameters
currentPosition
intThe position of the text to inspect.
textRange
TextRangeThe range of text that has the same formatting as the text at the position specified by currentPosition. This means the run has the exact formatting as the position specified, including but not limited to the font stretch.
Returns
- FontStretch
When this method returns, contains a value which indicates the type of font stretch (also known as width) being applied at the specified position.
GetFontStyle(int)
Gets the font style (also known as slope) of the text at the specified position.
public FontStyle GetFontStyle(int currentPosition)
Parameters
currentPosition
intThe position of the text to inspect.
Returns
- FontStyle
a value which indicates the type of font style (also known as slope or incline) being applied at the specified position.
GetFontStyle(int, out TextRange)
Gets the font style (also known as slope) of the text at the specified position.
public FontStyle GetFontStyle(int currentPosition, out TextRange textRange)
Parameters
currentPosition
intThe position of the text to inspect.
textRange
TextRangeThe range of text that has the same formatting as the text at the position specified by currentPosition. This means the run has the exact formatting as the position specified, including but not limited to the font style.
Returns
- FontStyle
When this method returns, contains a value which indicates the type of font style (also known as slope or incline) being applied at the specified position.
GetFontWeight(int)
Gets the font weight of the text at the specified position.
public FontWeight GetFontWeight(int currentPosition)
Parameters
currentPosition
intThe position of the text to inspect.
Returns
- FontWeight
a value which indicates the type of font weight being applied at the specified position.
GetFontWeight(int, out TextRange)
Gets the font weight of the text at the specified position.
public FontWeight GetFontWeight(int currentPosition, out TextRange textRange)
Parameters
currentPosition
intThe position of the text to inspect.
textRange
TextRangeThe range of text that has the same formatting as the text at the position specified by currentPosition. This means the run has the exact formatting as the position specified, including but not limited to the font weight.
Returns
- FontWeight
When this method returns, contains a value which indicates the type of font weight being applied at the specified position.
GetInlineObject(int)
Gets the inline object at the specified position.
public InlineObject GetInlineObject(int currentPosition)
Parameters
currentPosition
intThe specified text position.
Returns
- InlineObject
an application-defined inline object.
GetInlineObject(int, out TextRange)
Gets the inline object at the specified position.
public InlineObject GetInlineObject(int currentPosition, out TextRange textRange)
Parameters
currentPosition
intThe specified text position.
textRange
TextRangeThe range of text that has the same formatting as the text at the position specified by currentPosition. This means the run has the exact formatting as the position specified, including but not limited to the inline object.
Returns
- InlineObject
Contains the application-defined inline object.
GetLineMetrics()
Retrieves the information about each individual text line of the text string.
public LineMetrics[] GetLineMetrics()
Returns
- LineMetrics[]
If the method succeeds, it returns S_OK. Otherwise, it returns an HRESULT error code.
Remarks
If maxLineCount is not large enough E_NOT_SUFFICIENT_BUFFER, which is equivalent to HRESULT_FROM_WIN32(ERROR_INSUFFICIENT_BUFFER), is returned and *actualLineCount is set to the number of lines needed.
GetLocaleName(int)
Gets the locale name of the text at the specified position.
public string GetLocaleName(int currentPosition)
Parameters
currentPosition
intThe position of the text to inspect.
Returns
- string
the locale name of the text at the specified position.
GetLocaleName(int, out TextRange)
Gets the locale name of the text at the specified position.
public string GetLocaleName(int currentPosition, out TextRange textRange)
Parameters
currentPosition
intThe position of the text to inspect.
textRange
TextRangeThe range of text that has the same formatting as the text at the position specified by currentPosition. This means the run has the exact formatting as the position specified, including but not limited to the locale name.
Returns
- string
the locale name of the text at the specified position.
GetTypography(int)
Gets the typography setting of the text at the specified position.
public Typography GetTypography(int currentPosition)
Parameters
currentPosition
intThe position of the text to inspect.
Returns
- Typography
a reference to the current typography setting.
GetTypography(int, out TextRange)
Gets the typography setting of the text at the specified position.
public Typography GetTypography(int currentPosition, out TextRange textRange)
Parameters
currentPosition
intThe position of the text to inspect.
textRange
TextRangeThe range of text that has the same formatting as the text at the position specified by currentPosition. This means the run has the exact formatting as the position specified, including but not limited to the typography.
Returns
- Typography
When this method returns, contains an address of a reference to the current typography setting.
HasStrikethrough(int)
Get the strikethrough presence of the text at the specified position.
public bool HasStrikethrough(int currentPosition)
Parameters
currentPosition
intThe position of the text to inspect.
Returns
- bool
A Boolean flag that indicates whether strikethrough is present at the position indicated by currentPosition.
HasStrikethrough(int, out TextRange)
Get the strikethrough presence of the text at the specified position.
public RawBool HasStrikethrough(int currentPosition, out TextRange textRange)
Parameters
currentPosition
intThe position of the text to inspect.
textRange
TextRangeContains the range of text that has the same formatting as the text at the position specified by currentPosition. This means the run has the exact formatting as the position specified, including but not limited to strikethrough.
Returns
- RawBool
A Boolean flag that indicates whether strikethrough is present at the position indicated by currentPosition.
HasUnderline(int)
Gets the underline presence of the text at the specified position.
public bool HasUnderline(int currentPosition)
Parameters
currentPosition
intThe current text position.
Returns
- bool
A Boolean flag that indicates whether underline is present at the position indicated by currentPosition.
HasUnderline(int, out TextRange)
Gets the underline presence of the text at the specified position.
public RawBool HasUnderline(int currentPosition, out TextRange textRange)
Parameters
currentPosition
intThe current text position.
textRange
TextRangeThe range of text that has the same formatting as the text at the position specified by currentPosition. This means the run has the exact formatting as the position specified, including but not limited to the underline.
Returns
- RawBool
A Boolean flag that indicates whether underline is present at the position indicated by currentPosition.
HitTestPoint(float, float, out RawBool, out RawBool)
The application calls this function passing in a specific pixel location relative to the top-left location of the layout box and obtains the information about the correspondent hit-test metrics of the text string where the hit-test has occurred. When the specified pixel location is outside the text string, the function sets the output value *isInside to SharpDX.Result.False.
public HitTestMetrics HitTestPoint(float pointX, float pointY, out RawBool isTrailingHit, out RawBool isInside)
Parameters
pointX
floatThe pixel location X to hit-test, relative to the top-left location of the layout box.
pointY
floatThe pixel location Y to hit-test, relative to the top-left location of the layout box.
isTrailingHit
RawBoolAn output flag that indicates whether the hit-test location is at the leading or the trailing side of the character. When the output *isInside value is set to SharpDX.Result.False, this value is set according to the output hitTestMetrics->textPosition value to represent the edge closest to the hit-test location.
isInside
RawBoolAn output flag that indicates whether the hit-test location is inside the text string. When SharpDX.Result.False, the position nearest the text's edge is returned.
Returns
- HitTestMetrics
The output geometry fully enclosing the hit-test location. When the output *isInside value is set to SharpDX.Result.False, this structure represents the geometry enclosing the edge closest to the hit-test location.
HitTestTextPosition(int, RawBool, out float, out float)
The application calls this function to get the pixel location relative to the top-left of the layout box given the text position and the logical side of the position. This function is normally used as part of caret positioning of text where the caret is drawn at the location corresponding to the current text editing position. It may also be used as a way to programmatically obtain the geometry of a particular text position in UI automation.
public HitTestMetrics HitTestTextPosition(int textPosition, RawBool isTrailingHit, out float ointXRef, out float ointYRef)
Parameters
textPosition
intThe text position used to get the pixel location.
isTrailingHit
RawBoolA Boolean flag that indicates whether the pixel location is of the leading or the trailing side of the specified text position.
ointXRef
floatWhen this method returns, contains the output pixel location X, relative to the top-left location of the layout box.
ointYRef
floatWhen this method returns, contains the output pixel location Y, relative to the top-left location of the layout box.
Returns
- HitTestMetrics
When this method returns, contains the output geometry fully enclosing the specified text position.
HitTestTextRange(int, int, float, float)
The application calls this function to get a set of hit-test metrics corresponding to a range of text positions. One of the main usages is to implement highlight selection of the text string. The function returns E_NOT_SUFFICIENT_BUFFER, which is equivalent to HRESULT_FROM_WIN32(ERROR_INSUFFICIENT_BUFFER), when the buffer size of hitTestMetrics is too small to hold all the regions calculated by the function. In this situation, the function sets the output value *actualHitTestMetricsCount to the number of geometries calculated. The application is responsible for allocating a new buffer of greater size and calling the function again. A good value to use as an initial value for maxHitTestMetricsCount may be calculated from the following equation: maxHitTestMetricsCount = lineCount * maxBidiReorderingDepth where lineCount is obtained from the value of the output argument *actualLineCount (from the function IDWriteTextLayout::GetLineLengths), and the maxBidiReorderingDepth value from the DWRITE_TEXT_METRICS structure of the output argument *textMetrics (from the function IDWriteFactory::CreateTextLayout).
public HitTestMetrics[] HitTestTextRange(int textPosition, int textLength, float originX, float originY)
Parameters
textPosition
intThe first text position of the specified range.
textLength
intThe number of positions of the specified range.
originX
floatThe origin pixel location X at the left of the layout box. This offset is added to the hit-test metrics returned.
originY
floatThe origin pixel location Y at the top of the layout box. This offset is added to the hit-test metrics returned.
Returns
- HitTestMetrics[]
a reference to a buffer of the output geometry fully enclosing the specified position range. The buffer must be at least as large as maxHitTestMetricsCount.
SetDrawingEffect(ComObject, TextRange)
Sets the application-defined drawing effect.
public void SetDrawingEffect(ComObject drawingEffect, TextRange textRange)
Parameters
drawingEffect
ComObjectApplication-defined drawing effects that apply to the range. This data object will be passed back to the application's drawing callbacks for final rendering.
textRange
TextRangeThe text range to which this change applies.
Remarks
An Brush, such as a color or gradient brush, can be set as a drawing effect if you are using the
SetDrawingEffect(nint, TextRange)
Sets the application-defined drawing effect.
public void SetDrawingEffect(nint drawingEffect, TextRange textRange)
Parameters
drawingEffect
nintApplication-defined drawing effects that apply to the range. This data object will be passed back to the application's drawing callbacks for final rendering.
textRange
TextRangeThe text range to which this change applies.
Remarks
An Brush, such as a color or gradient brush, can be set as a drawing effect if you are using the ID2D1RenderTarget::DrawTextLayout to draw text and that brush will be used to draw the specified range of text.
This drawing effect is associated with the specified range and will be passed back to the application by way of the callback when the range is drawn at drawing time.
SetFontCollection(FontCollection, TextRange)
Sets the font collection.
public void SetFontCollection(FontCollection fontCollection, TextRange textRange)
Parameters
fontCollection
FontCollectionThe font collection to set.
textRange
TextRangeText range to which this change applies.
SetFontFamilyName(string, TextRange)
Sets null-terminated font family name for text within a specified text range.
public void SetFontFamilyName(string fontFamilyName, TextRange textRange)
Parameters
fontFamilyName
stringThe font family name that applies to the entire text string within the range specified by textRange.
textRange
TextRangeText range to which this change applies.
SetFontSize(float, TextRange)
Sets the font size in DIP units for text within a specified text range.
public void SetFontSize(float fontSize, TextRange textRange)
Parameters
fontSize
floatThe font size in DIP units to be set for text in the range specified by textRange.
textRange
TextRangeText range to which this change applies.
SetFontStretch(FontStretch, TextRange)
Sets the font stretch for text within a specified text range.
public void SetFontStretch(FontStretch fontStretch, TextRange textRange)
Parameters
fontStretch
FontStretchA value which indicates the type of font stretch for text within the range specified by textRange.
textRange
TextRangeText range to which this change applies.
SetFontStyle(FontStyle, TextRange)
Sets the font style for text within a text range specified by a TextRange structure.
public void SetFontStyle(FontStyle fontStyle, TextRange textRange)
Parameters
Remarks
The font style can be set to Normal, Italic or Oblique. The following illustration shows three styles for the Palatino font. For more information, see FontStyle.
SetFontWeight(FontWeight, TextRange)
Sets the font weight for text within a text range specified by a TextRange structure.
public void SetFontWeight(FontWeight fontWeight, TextRange textRange)
Parameters
fontWeight
FontWeightNo documentation.
textRange
TextRangeNo documentation.
Remarks
The font weight can be set to one of the predefined font weight values provided in the FontWeight enumeration or an integer from 1 to 999. Values outside this range will cause the method to fail with an E_INVALIDARG return value.
The following illustration shows an example of Normal and UltraBold weights for the Palatino Linotype typeface.
SetInlineObject(InlineObject, TextRange)
Sets the inline object.
public void SetInlineObject(InlineObject inlineObject, TextRange textRange)
Parameters
inlineObject
InlineObjectAn application-defined inline object.
textRange
TextRangeText range to which this change applies.
Remarks
The application may call this function to specify the set of properties describing an application-defined inline object for specific range.
This inline object applies to the specified range and will be passed back to the application by way of the DrawInlineObject callback when the range is drawn. Any text in that range will be suppressed.
SetLocaleName(string, TextRange)
Sets the locale name for text within a specified text range.
public void SetLocaleName(string localeName, TextRange textRange)
Parameters
localeName
stringA null-terminated locale name string.
textRange
TextRangeText range to which this change applies.
SetStrikethrough(RawBool, TextRange)
Sets strikethrough for text within a specified text range.
public void SetStrikethrough(RawBool hasStrikethrough, TextRange textRange)
Parameters
hasStrikethrough
RawBoolA Boolean flag that indicates whether strikethrough takes place in the range specified by textRange.
textRange
TextRangeText range to which this change applies.
SetTypography(Typography, TextRange)
Sets font typography features for text within a specified text range.
public void SetTypography(Typography typography, TextRange textRange)
Parameters
typography
TypographyPointer to font typography settings.
textRange
TextRangeText range to which this change applies.
SetUnderline(RawBool, TextRange)
The TextLayout interface represents a block of text after it has been fully analyzed and formatted.
public void SetUnderline(RawBool hasUnderline, TextRange textRange)
Parameters
hasUnderline
RawBoolNo documentation.
textRange
TextRangeNo documentation.
Remarks
To get a reference to the TextLayout interface, the application must call the IDWriteFactory::CreateTextLayout method, as shown in the following code.
// Create a text layout using the text format. if (SUCCEEDED(hr)) { SharpDX.Mathematics.Interop.RawRectangle rect; GetClientRect(hwnd_, &rect); float width = rect.right / dpiScaleX_; float height = rect.bottom / dpiScaleY_; hr = pDWriteFactory_->CreateTextLayout( wszText_, // The string to be laid out and formatted. cTextLength_, // The length of the string. pTextFormat_, // The text format to apply to the string (contains font information, etc). width, // The width of the layout box. height, // The height of the layout box. &pTextLayout_ // The TextLayout interface reference. ); }
The TextLayout interface allows the application to change the format for ranges of the text it represents, specified by a TextRange structure. The following example shows how to set the font weight for a text range.
// Set the font weight to bold for the first 5 letters. TextRange textRange = {0, 4}; if (SUCCEEDED(hr)) { hr = pTextLayout_->SetFontWeight(DWRITE_FONT_WEIGHT_BOLD, textRange); }
TextLayout also provides methods for adding strikethrough, underline, and inline objects to the text.
To draw the block of text represented by an TextLayout object, Direct2D provides the ID2D1RenderTarget::DrawTextLayout method. To draw using a custom renderer implement an TextRenderer interface and call the IDWriteTextLayout::Draw method
Operators
explicit operator TextLayout(nint)
public static explicit operator TextLayout(nint nativePtr)
Parameters
nativePtr
nint