[]
IDWriteTextLayout
[Guid("53737037-6d14-410b-9bfe-0b182bb70961")]
public class TextLayout : TextFormat, IDisposable, IUnknown
Initializes a new instance of the TextLayout class.
public TextLayout(IntPtr nativePtr)
nativePtr
System.IntPtrThe native pointer.
GetMetrics
public TextMetrics Metrics { get; }
GetOverhangMetrics
public OverhangMetrics OverhangMetrics { get; }
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 static TextLayout Create(Factory factory, string text, TextFormat textFormat, float layoutWidth, float layoutHeight, float pixelsPerDip, bool useGdiNatural)
factory
Factoryan instance of Factory
text
stringAn array of characters that contains the string to create a new C1.Win.DX.DirectWrite.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.
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.
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 static TextLayout Create(Factory factory, string text, TextFormat textFormat, float layoutWidth, float layoutHeight, float pixelsPerDip, Matrix3x2? transform, bool useGdiNatural)
factory
Factoryan instance of Factory
text
stringAn array of characters that contains the string to create a new C1.Win.DX.DirectWrite.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
Matrix3x2?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.
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.
Takes a string, text format, and associated constraints, and produces an object that represents the fully analyzed and formatted result.
public static TextLayout Create(Factory factory, string text, TextFormat textFormat, float maxWidth, float maxHeight)
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.
HRESULT IDWriteTextLayout::DetermineMinWidth([Out] float* minWidth)
public float DetermineMinWidth()
Draws text using the specified client drawing context.
public void Draw(ITextRenderer renderer, float originX, float originY)
renderer
ITextRendererPointer 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.
To draw text with this method, a textLayout object needs to be created by the application using CreateTextLayout(string, int, TextFormat, float, float). 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.
Draws text using the specified client drawing context.
public void Draw(object clientDrawingContext, ITextRenderer renderer, float originX, float originY)
clientDrawingContext
objectAn application-defined drawing context.
renderer
ITextRendererPointer 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.
To draw text with this method, a textLayout object needs to be created by the application using CreateTextLayout(string, int, TextFormat, float, float). 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.
Retrieves logical properties and measurements of each glyph cluster.
public ClusterMetrics[] GetClusterMetrics()
Returns metrics, such as line-break or total advance width, for a 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.
HRESULT IDWriteTextLayout::GetClusterMetrics([Out, Buffer, Optional] DWRITE_CLUSTER_METRICS* clusterMetrics,[In] unsigned int maxClusterCount,[Out] unsigned int* actualClusterCount)
public HResult GetClusterMetrics(ClusterMetrics[] clusterMetrics, int maxClusterCount, out int actualClusterCount)
clusterMetrics
ClusterMetrics[]maxClusterCount
intactualClusterCount
intHRESULT IDWriteTextLayout::GetDrawingEffect([In] unsigned int currentPosition,[Out] void** drawingEffect,[Out, Optional] DWRITE_TEXT_RANGE* textRange)
public IntPtr GetDrawingEffect(int currentPosition, out TextRange textRange)
currentPosition
inttextRange
TextRangeGets the application-defined drawing effect at the specified text position.
public IntPtr GetDrawingEffect(int currentPosition)
currentPosition
intThe position of the text whose drawing effect is to be retrieved.
a reference to the current application-defined drawing effect. Usually this effect is a foreground brush that is used in glyph drawing.
HRESULT IDWriteTextLayout::GetFontCollection([In] unsigned int currentPosition,[Out] IDWriteFontCollection** fontCollection,[Out, Optional] DWRITE_TEXT_RANGE* textRange)
public FontCollection GetFontCollection(int currentPosition, out TextRange textRange)
currentPosition
inttextRange
TextRangeGets the font collection associated with the text at the specified position.
public FontCollection GetFontCollection(int currentPosition)
currentPosition
intThe position of the text to inspect.
a reference to the current font collection.
Gets the font family name of the text at the specified position.
public string GetFontFamilyName(int currentPosition, out TextRange textRange)
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.
the font family name
HRESULT IDWriteTextLayout::GetFontFamilyName([In] unsigned int currentPosition,[Out, Buffer] wchar_t* fontFamilyName,[In] unsigned int nameSize,[Out, Optional] DWRITE_TEXT_RANGE* textRange)
public void GetFontFamilyName(int currentPosition, IntPtr fontFamilyName, int nameSize, out TextRange textRange)
currentPosition
intfontFamilyName
System.IntPtrnameSize
inttextRange
TextRangeGets the font family name of the text at the specified position.
public string GetFontFamilyName(int currentPosition)
currentPosition
intThe position of the text to examine.
the font family name
HRESULT IDWriteTextLayout::GetFontFamilyNameLength([In] unsigned int currentPosition,[Out] unsigned int* nameLength,[Out, Optional] DWRITE_TEXT_RANGE* textRange)
public void GetFontFamilyNameLength(int currentPosition, out int nameLength, out TextRange textRange)
currentPosition
intnameLength
inttextRange
TextRangeHRESULT IDWriteTextLayout::GetFontSize([In] unsigned int currentPosition,[Out] float* fontSize,[Out, Optional] DWRITE_TEXT_RANGE* textRange)
public float GetFontSize(int currentPosition, out TextRange textRange)
currentPosition
inttextRange
TextRangeGets the font em height of the text at the specified position.
public float GetFontSize(int currentPosition)
currentPosition
intThe position of the text to inspect.
the size of the font in ems of the text at the specified position.
HRESULT IDWriteTextLayout::GetFontStretch([In] unsigned int currentPosition,[Out] DWRITE_FONT_STRETCH* fontStretch,[Out, Optional] DWRITE_TEXT_RANGE* textRange)
public FontStretch GetFontStretch(int currentPosition, out TextRange textRange)
currentPosition
inttextRange
TextRangeGets the font stretch of the text at the specified position.
public FontStretch GetFontStretch(int currentPosition)
currentPosition
intThe position of the text to inspect.
a value which indicates the type of font stretch (also known as width) being applied at the specified position.
HRESULT IDWriteTextLayout::GetFontStyle([In] unsigned int currentPosition,[Out] DWRITE_FONT_STYLE* fontStyle,[Out, Optional] DWRITE_TEXT_RANGE* textRange)
public FontStyle GetFontStyle(int currentPosition, out TextRange textRange)
currentPosition
inttextRange
TextRangeGets the font style (also known as slope) of the text at the specified position.
public FontStyle GetFontStyle(int currentPosition)
currentPosition
intThe position of the text to inspect.
a value which indicates the type of font style (also known as slope or incline) being applied at the specified position.
HRESULT IDWriteTextLayout::GetFontWeight([In] unsigned int currentPosition,[Out] DWRITE_FONT_WEIGHT* fontWeight,[Out, Optional] DWRITE_TEXT_RANGE* textRange)
public FontWeight GetFontWeight(int currentPosition, out TextRange textRange)
currentPosition
inttextRange
TextRangeGets the font weight of the text at the specified position.
public FontWeight GetFontWeight(int currentPosition)
currentPosition
intThe position of the text to inspect.
a value which indicates the type of font weight being applied at the specified position.
HRESULT IDWriteTextLayout::GetInlineObject([In] unsigned int currentPosition,[Out] IDWriteInlineObject** inlineObject,[Out, Optional] DWRITE_TEXT_RANGE* textRange)
public IInlineObject GetInlineObject(int currentPosition, out TextRange textRange)
currentPosition
inttextRange
TextRangeGets the inline object at the specified position.
public IInlineObject GetInlineObject(int currentPosition)
currentPosition
intThe specified text position.
an application-defined inline object.
Retrieves the information about each individual text line of the text string.
public LineMetrics[] GetLineMetrics()
If the method succeeds, it returns S_OK. Otherwise, it returns an HRESULT error code.
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.
HRESULT IDWriteTextLayout::GetLineMetrics([Out, Buffer, Optional] DWRITE_LINE_METRICS* lineMetrics,[In] unsigned int maxLineCount,[Out] unsigned int* actualLineCount)
public HResult GetLineMetrics(LineMetrics[] lineMetrics, int maxLineCount, out int actualLineCount)
lineMetrics
LineMetrics[]maxLineCount
intactualLineCount
intGets the locale name of the text at the specified position.
public string GetLocaleName(int currentPosition, out TextRange textRange)
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.
the locale name of the text at the specified position.
HRESULT IDWriteTextLayout::GetLocaleName([In] unsigned int currentPosition,[Out, Buffer] wchar_t* localeName,[In] unsigned int nameSize,[Out, Optional] DWRITE_TEXT_RANGE* textRange)
public void GetLocaleName(int currentPosition, IntPtr localeName, int nameSize, out TextRange textRange)
currentPosition
intlocaleName
System.IntPtrnameSize
inttextRange
TextRangeGets the locale name of the text at the specified position.
public string GetLocaleName(int currentPosition)
currentPosition
intThe position of the text to inspect.
the locale name of the text at the specified position.
HRESULT IDWriteTextLayout::GetLocaleNameLength([In] unsigned int currentPosition,[Out] unsigned int* nameLength,[Out, Optional] DWRITE_TEXT_RANGE* textRange)
public void GetLocaleNameLength(int currentPosition, out int nameLength, out TextRange textRange)
currentPosition
intnameLength
inttextRange
TextRangefloat IDWriteTextLayout::GetMaxHeight()
public float GetMaxHeight()
float IDWriteTextLayout::GetMaxWidth()
public float GetMaxWidth()
HRESULT IDWriteTextLayout::GetMetrics([Out] DWRITE_TEXT_METRICS* textMetrics)
public void GetMetrics(out TextMetrics textMetrics)
textMetrics
TextMetricsHRESULT IDWriteTextLayout::GetOverhangMetrics([Out] DWRITE_OVERHANG_METRICS* overhangs)
public void GetOverhangMetrics(out OverhangMetrics overhangs)
overhangs
OverhangMetricsHRESULT IDWriteTextLayout::GetTypography([In] unsigned int currentPosition,[Out] IDWriteTypography** typography,[Out, Optional] DWRITE_TEXT_RANGE* textRange)
public Typography GetTypography(int currentPosition, out TextRange textRange)
currentPosition
inttextRange
TextRangeGets the typography setting of the text at the specified position.
public Typography GetTypography(int currentPosition)
currentPosition
intThe position of the text to inspect.
a reference to the current typography setting.
HRESULT IDWriteTextLayout::GetStrikethrough([In] unsigned int currentPosition,[Out] BOOL* hasStrikethrough,[Out, Optional] DWRITE_TEXT_RANGE* textRange)
public bool HasStrikethrough(int currentPosition, out TextRange textRange)
currentPosition
inttextRange
TextRangeGet the strikethrough presence of the text at the specified position.
public bool HasStrikethrough(int currentPosition)
currentPosition
intThe position of the text to inspect.
A Boolean flag that indicates whether strikethrough is present at the position indicated by currentPosition.
HRESULT IDWriteTextLayout::GetUnderline([In] unsigned int currentPosition,[Out] BOOL* hasUnderline,[Out, Optional] DWRITE_TEXT_RANGE* textRange)
public bool HasUnderline(int currentPosition, out TextRange textRange)
currentPosition
inttextRange
TextRangeGets the underline presence of the text at the specified position.
public bool HasUnderline(int currentPosition)
currentPosition
intThe current text position.
A Boolean flag that indicates whether underline is present at the position indicated by currentPosition.
HRESULT IDWriteTextLayout::HitTestPoint([In] float pointX,[In] float pointY,[Out] BOOL* isTrailingHit,[Out] BOOL* isInside,[Out] DWRITE_HIT_TEST_METRICS* hitTestMetrics)
public HitTestMetrics HitTestPoint(float pointX, float pointY, out Bool isTrailingHit, out Bool isInside)
HRESULT IDWriteTextLayout::HitTestTextPosition([In] unsigned int textPosition,[In] BOOL isTrailingHit,[Out] float* pointX,[Out] float* pointY,[Out] DWRITE_HIT_TEST_METRICS* hitTestMetrics)
public HitTestMetrics HitTestTextPosition(int textPosition, Bool isTrailingHit, out float pointXRef, out float pointYRef)
textPosition
intisTrailingHit
BoolpointXRef
floatpointYRef
floatHRESULT IDWriteTextLayout::HitTestTextRange([In] unsigned int textPosition,[In] unsigned int textLength,[In] float originX,[In] float originY,[Out, Buffer, Optional] DWRITE_HIT_TEST_METRICS* hitTestMetrics,[In] unsigned int maxHitTestMetricsCount,[Out] unsigned int* actualHitTestMetricsCount)
public HResult HitTestTextRange(int textPosition, int textLength, float originX, float originY, HitTestMetrics[] hitTestMetrics, int maxHitTestMetricsCount, out int actualHitTestMetricsCount)
textPosition
inttextLength
intoriginX
floatoriginY
floathitTestMetrics
HitTestMetrics[]maxHitTestMetricsCount
intactualHitTestMetricsCount
intThe 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)
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.
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.
Sets the application-defined drawing effect.
public void SetDrawingEffect(Brush brush, TextRange textRange)
brush
BrushThe color or gradient brush.
textRange
TextRangeThe text range to which this change applies.
HRESULT IDWriteTextLayout::SetDrawingEffect([In] void* drawingEffect,[In] DWRITE_TEXT_RANGE textRange)
public void SetDrawingEffect(IntPtr drawingEffect, TextRange textRange)
drawingEffect
System.IntPtrtextRange
TextRangeSets the application-defined drawing effect.
public IntPtr SetDrawingEffect(object drawingEffect, TextRange textRange)
drawingEffect
objectApplication-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.
If the method succeeds, it returns S_OK. Otherwise, it returns an HRESULT error code.
An Brush, such as a color or gradient brush, can be set as a drawing effect if you are using the RenderTarget.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.
HRESULT IDWriteTextLayout::SetFontCollection([In] IDWriteFontCollection* fontCollection,[In] DWRITE_TEXT_RANGE textRange)
public void SetFontCollection(FontCollection fontCollection, TextRange textRange)
fontCollection
FontCollectiontextRange
TextRangeHRESULT IDWriteTextLayout::SetFontFamilyName([In] const wchar_t* fontFamilyName,[In] DWRITE_TEXT_RANGE textRange)
public void SetFontFamilyName(string fontFamilyName, TextRange textRange)
fontFamilyName
stringtextRange
TextRangeHRESULT IDWriteTextLayout::SetFontSize([In] float fontSize,[In] DWRITE_TEXT_RANGE textRange)
public void SetFontSize(float fontSize, TextRange textRange)
fontSize
floattextRange
TextRangeHRESULT IDWriteTextLayout::SetFontStretch([In] DWRITE_FONT_STRETCH fontStretch,[In] DWRITE_TEXT_RANGE textRange)
public void SetFontStretch(FontStretch fontStretch, TextRange textRange)
fontStretch
FontStretchtextRange
TextRangeHRESULT IDWriteTextLayout::SetFontStyle([In] DWRITE_FONT_STYLE fontStyle,[In] DWRITE_TEXT_RANGE textRange)
public void SetFontStyle(FontStyle fontStyle, TextRange textRange)
HRESULT IDWriteTextLayout::SetFontWeight([In] DWRITE_FONT_WEIGHT fontWeight,[In] DWRITE_TEXT_RANGE textRange)
public void SetFontWeight(FontWeight fontWeight, TextRange textRange)
fontWeight
FontWeighttextRange
TextRangeSets the inline object.
public void SetInlineObject(IInlineObject inlineObject, TextRange textRange)
inlineObject
IInlineObjectAn application-defined inline object.
textRange
TextRangeText range to which this change applies.
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.
HRESULT IDWriteTextLayout::SetLocaleName([In] const wchar_t* localeName,[In] DWRITE_TEXT_RANGE textRange)
public void SetLocaleName(string localeName, TextRange textRange)
localeName
stringtextRange
TextRangeHRESULT IDWriteTextLayout::SetMaxHeight([In] float maxHeight)
public void SetMaxHeight(float maxHeight)
maxHeight
floatHRESULT IDWriteTextLayout::SetMaxWidth([In] float maxWidth)
public void SetMaxWidth(float maxWidth)
maxWidth
floatHRESULT IDWriteTextLayout::SetStrikethrough([In] BOOL hasStrikethrough,[In] DWRITE_TEXT_RANGE textRange)
public void SetStrikethrough(Bool hasStrikethrough, TextRange textRange)
HRESULT IDWriteTextLayout::SetTypography([In] IDWriteTypography* typography,[In] DWRITE_TEXT_RANGE textRange)
public void SetTypography(Typography typography, TextRange textRange)
typography
TypographytextRange
TextRangeHRESULT IDWriteTextLayout::SetUnderline([In] BOOL hasUnderline,[In] DWRITE_TEXT_RANGE textRange)
public void SetUnderline(Bool hasUnderline, TextRange textRange)
Performs an explicit conversion from System.IntPtr to TextLayout.
public static explicit operator TextLayout(IntPtr nativePointer)
nativePointer
System.IntPtr