C# Class SharpDX.DirectWrite.TextLayout

Show file Open project: sharpdx/SharpDX Class Usage Examples

Public Methods

Method Description
Draw ( TextRenderer renderer, float originX, float originY ) : void

Draws text using the specified client drawing context.

To draw text with this method, a textLayout object needs to be created by the application using SharpDX.DirectWrite.Factory.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.

Draw ( object clientDrawingContext, TextRenderer renderer, float originX, float originY ) : void

Draws text using the specified client drawing context.

To draw text with this method, a textLayout object needs to be created by the application using SharpDX.DirectWrite.Factory.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.

GetClusterMetrics ( ) : ClusterMetrics[]

Retrieves logical properties and measurements of each glyph cluster.

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 currentPosition ) : ComObject

Gets the application-defined drawing effect at the specified text position.

GetDrawingEffect ( int currentPosition, SharpDX.DirectWrite.TextRange &textRange ) : ComObject

Gets the application-defined drawing effect at the specified text position.

GetFontCollection ( int currentPosition ) : SharpDX.DirectWrite.FontCollection

Gets the font collection associated with the text at the specified position.

GetFontFamilyName ( int currentPosition ) : string

Gets the font family name of the text at the specified position.

GetFontFamilyName ( int currentPosition, SharpDX.DirectWrite.TextRange &textRange ) : string

Gets the font family name of the text at the specified position.

GetFontSize ( int currentPosition ) : float

Gets the font em height of the text at the specified position.

GetFontStretch ( int currentPosition ) : FontStretch

Gets the font stretch of the text at the specified position.

GetFontStyle ( int currentPosition ) : FontStyle

Gets the font style (also known as slope) of the text at the specified position.

GetFontWeight ( int currentPosition ) : FontWeight

Gets the font weight of the text at the specified position.

GetInlineObject ( int currentPosition ) : InlineObject

Gets the inline object at the specified position.

GetLineMetrics ( ) : LineMetrics[]

Retrieves the information about each individual text line of the text string.

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 currentPosition ) : string

Gets the locale name of the text at the specified position.

GetLocaleName ( int currentPosition, SharpDX.DirectWrite.TextRange &textRange ) : string

Gets the locale name of the text at the specified position.

GetTypography ( int currentPosition ) : SharpDX.DirectWrite.Typography

Gets the typography setting of the text at the specified position.

HasStrikethrough ( int currentPosition ) : bool

Get the strikethrough presence of the text at the specified position.

HasUnderline ( int currentPosition ) : bool

Gets the underline presence of the text at the specified position.

HitTestTextRange ( int textPosition, int textLength, float originX, float originY ) : HitTestMetrics[]

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).

SetDrawingEffect ( SharpDX drawingEffect, SharpDX textRange ) : void

Sets the application-defined drawing effect.

An SharpDX.Direct2D1.Brush, such as a color or gradient brush, can be set as a drawing effect if you are using the RenderTarget.DrawTextLayout(System.Drawing.PointF,SharpDX.DirectWrite.TextLayout,SharpDX.Direct2D1.Brush,SharpDX.Direct2D1.DrawTextOptions) 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.

SetInlineObject ( InlineObject inlineObject, SharpDX textRange ) : void

Sets the inline object.

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.

TextLayout ( Factory factory, string text, SharpDX textFormat, float maxWidth, float maxHeight ) : System

Takes a string, text format, and associated constraints, and produces an object that represents the fully analyzed and formatted result.

TextLayout ( Factory factory, string text, SharpDX.DirectWrite.TextFormat textFormat, float layoutWidth, float layoutHeight, float pixelsPerDip, RawMatrix3x2 transform, bool useGdiNatural ) : System

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.

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 factory, string text, SharpDX.DirectWrite.TextFormat textFormat, float layoutWidth, float layoutHeight, float pixelsPerDip, bool useGdiNatural ) : System

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.

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.

Method Details

Draw() public method

Draws text using the specified client drawing context.
To draw text with this method, a textLayout object needs to be created by the application using SharpDX.DirectWrite.Factory.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.
public Draw ( TextRenderer renderer, float originX, float originY ) : void
renderer TextRenderer Pointer to the set of callback functions used to draw parts of a text string.
originX float The x-coordinate of the layout's left side.
originY float The y-coordinate of the layout's top side.
return void

Draw() public method

Draws text using the specified client drawing context.
To draw text with this method, a textLayout object needs to be created by the application using SharpDX.DirectWrite.Factory.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.
public Draw ( object clientDrawingContext, TextRenderer renderer, float originX, float originY ) : void
clientDrawingContext object An application-defined drawing context.
renderer TextRenderer Pointer to the set of callback functions used to draw parts of a text string.
originX float The x-coordinate of the layout's left side.
originY float The y-coordinate of the layout's top side.
return void

GetClusterMetrics() public method

Retrieves logical properties and measurements of each glyph cluster.
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.
public GetClusterMetrics ( ) : ClusterMetrics[]
return ClusterMetrics[]

GetDrawingEffect() public method

Gets the application-defined drawing effect at the specified text position.
public GetDrawingEffect ( int currentPosition ) : ComObject
currentPosition int The position of the text whose drawing effect is to be retrieved.
return ComObject

GetDrawingEffect() public method

Gets the application-defined drawing effect at the specified text position.
public GetDrawingEffect ( int currentPosition, SharpDX.DirectWrite.TextRange &textRange ) : ComObject
currentPosition int The position of the text whose drawing effect is to be retrieved.
textRange SharpDX.DirectWrite.TextRange Contains 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.
return ComObject

GetFontCollection() public method

Gets the font collection associated with the text at the specified position.
public GetFontCollection ( int currentPosition ) : SharpDX.DirectWrite.FontCollection
currentPosition int The position of the text to inspect.
return SharpDX.DirectWrite.FontCollection

GetFontFamilyName() public method

Gets the font family name of the text at the specified position.
public GetFontFamilyName ( int currentPosition ) : string
currentPosition int The position of the text to examine.
return string

GetFontFamilyName() public method

Gets the font family name of the text at the specified position.
public GetFontFamilyName ( int currentPosition, SharpDX.DirectWrite.TextRange &textRange ) : string
currentPosition int The position of the text to examine.
textRange SharpDX.DirectWrite.TextRange 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 font family name.
return string

GetFontSize() public method

Gets the font em height of the text at the specified position.
public GetFontSize ( int currentPosition ) : float
currentPosition int The position of the text to inspect.
return float

GetFontStretch() public method

Gets the font stretch of the text at the specified position.
public GetFontStretch ( int currentPosition ) : FontStretch
currentPosition int The position of the text to inspect.
return FontStretch

GetFontStyle() public method

Gets the font style (also known as slope) of the text at the specified position.
public GetFontStyle ( int currentPosition ) : FontStyle
currentPosition int The position of the text to inspect.
return FontStyle

GetFontWeight() public method

Gets the font weight of the text at the specified position.
public GetFontWeight ( int currentPosition ) : FontWeight
currentPosition int The position of the text to inspect.
return FontWeight

GetInlineObject() public method

Gets the inline object at the specified position.
public GetInlineObject ( int currentPosition ) : InlineObject
currentPosition int The specified text position.
return InlineObject

GetLineMetrics() public method

Retrieves the information about each individual text line of the text string.
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.
public GetLineMetrics ( ) : LineMetrics[]
return LineMetrics[]

GetLocaleName() public method

Gets the locale name of the text at the specified position.
public GetLocaleName ( int currentPosition ) : string
currentPosition int The position of the text to inspect.
return string

GetLocaleName() public method

Gets the locale name of the text at the specified position.
public GetLocaleName ( int currentPosition, SharpDX.DirectWrite.TextRange &textRange ) : string
currentPosition int The position of the text to inspect.
textRange SharpDX.DirectWrite.TextRange 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 locale name.
return string

GetTypography() public method

Gets the typography setting of the text at the specified position.
public GetTypography ( int currentPosition ) : SharpDX.DirectWrite.Typography
currentPosition int The position of the text to inspect.
return SharpDX.DirectWrite.Typography

HasStrikethrough() public method

Get the strikethrough presence of the text at the specified position.
public HasStrikethrough ( int currentPosition ) : bool
currentPosition int The position of the text to inspect.
return bool

HasUnderline() public method

Gets the underline presence of the text at the specified position.
public HasUnderline ( int currentPosition ) : bool
currentPosition int The current text position.
return bool

HitTestTextRange() public method

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 HitTestTextRange ( int textPosition, int textLength, float originX, float originY ) : HitTestMetrics[]
textPosition int The first text position of the specified range.
textLength int The number of positions of the specified range.
originX float The origin pixel location X at the left of the layout box. This offset is added to the hit-test metrics returned.
originY float The origin pixel location Y at the top of the layout box. This offset is added to the hit-test metrics returned.
return HitTestMetrics[]

SetDrawingEffect() public method

Sets the application-defined drawing effect.
An SharpDX.Direct2D1.Brush, such as a color or gradient brush, can be set as a drawing effect if you are using the RenderTarget.DrawTextLayout(System.Drawing.PointF,SharpDX.DirectWrite.TextLayout,SharpDX.Direct2D1.Brush,SharpDX.Direct2D1.DrawTextOptions) 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.
public SetDrawingEffect ( SharpDX drawingEffect, SharpDX textRange ) : void
drawingEffect SharpDX Application-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 SharpDX The text range to which this change applies.
return void

SetInlineObject() public method

Sets the inline object.
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.
public SetInlineObject ( InlineObject inlineObject, SharpDX textRange ) : void
inlineObject InlineObject An application-defined inline object.
textRange SharpDX Text range to which this change applies.
return void

TextLayout() public method

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, SharpDX textFormat, float maxWidth, float maxHeight ) : System
factory Factory an instance of
text string An array of characters that contains the string to create a new object from. This array must be of length stringLength and can contain embedded NULL characters.
textFormat SharpDX A pointer to an object that indicates the format to apply to the string.
maxWidth float The width of the layout box.
maxHeight float The height of the layout box.
return System

TextLayout() public method

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.
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.
public TextLayout ( Factory factory, string text, SharpDX.DirectWrite.TextFormat textFormat, float layoutWidth, float layoutHeight, float pixelsPerDip, RawMatrix3x2 transform, bool useGdiNatural ) : System
factory Factory an instance of
text string An array of characters that contains the string to create a new object from. This array must be of length stringLength and can contain embedded NULL characters.
textFormat SharpDX.DirectWrite.TextFormat The text formatting object to apply to the string.
layoutWidth float The width of the layout box.
layoutHeight float The height of the layout box.
pixelsPerDip float The 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 bool Instructs 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.
return System

TextLayout() public method

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.
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.
public TextLayout ( Factory factory, string text, SharpDX.DirectWrite.TextFormat textFormat, float layoutWidth, float layoutHeight, float pixelsPerDip, bool useGdiNatural ) : System
factory Factory an instance of
text string An array of characters that contains the string to create a new object from. This array must be of length stringLength and can contain embedded NULL characters.
textFormat SharpDX.DirectWrite.TextFormat The text formatting object to apply to the string.
layoutWidth float The width of the layout box.
layoutHeight float The height of the layout box.
pixelsPerDip float The 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 bool Instructs 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.
return System