IDWriteTextFormat interface

The IDWriteTextFormat interface describes the font and paragraph properties used to format text, and it describes locale information.

Methods

The IDWriteTextFormat interface has these methods.

Method Description
IDWriteTextFormat::GetFlowDirection Gets the direction that text lines flow.
IDWriteTextFormat::GetFontCollection Gets the current font collection.
IDWriteTextFormat::GetFontFamilyName Gets a copy of the font family name.
IDWriteTextFormat::GetFontFamilyNameLength Gets the length of the font family name.
IDWriteTextFormat::GetFontSize Gets the font size in DIP unites.
IDWriteTextFormat::GetFontStretch Gets the font stretch of the text.
IDWriteTextFormat::GetFontStyle Gets the font style of the text.
IDWriteTextFormat::GetFontWeight Gets the font weight of the text.
IDWriteTextFormat::GetIncrementalTabStop Gets the incremental tab stop position.
IDWriteTextFormat::GetLineSpacing Gets the line spacing adjustment set for a multiline text paragraph.
IDWriteTextFormat::GetLocaleName Gets a copy of the locale name.
IDWriteTextFormat::GetLocaleNameLength Gets the length of the locale name.
IDWriteTextFormat::GetParagraphAlignment Gets the alignment option of a paragraph which is relative to the top and bottom edges of a layout box.
IDWriteTextFormat::GetReadingDirection Gets the current reading direction for text in a paragraph.
IDWriteTextFormat::GetTextAlignment Gets the alignment option of text relative to the layout box's leading and trailing edge.
IDWriteTextFormat::GetTrimming Gets the trimming options for text that overflows the layout box.
IDWriteTextFormat::GetWordWrapping Gets the word wrapping option.
IDWriteTextFormat::SetFlowDirection Sets the paragraph flow direction.
IDWriteTextFormat::SetIncrementalTabStop Sets a fixed distance between two adjacent tab stops.
IDWriteTextFormat::SetLineSpacing Sets the line spacing.
IDWriteTextFormat::SetParagraphAlignment Sets the alignment option of a paragraph relative to the layout box's top and bottom edge.
IDWriteTextFormat::SetReadingDirection Sets the paragraph reading direction.
IDWriteTextFormat::SetTextAlignment Sets the alignment of text in a paragraph, relative to the leading and trailing edge of a layout box for a IDWriteTextFormat interface.
IDWriteTextFormat::SetTrimming Sets trimming options for text overflowing the layout width.
IDWriteTextFormat::SetWordWrapping Sets the word wrapping option.

Remarks

To get a reference to the IDWriteTextFormat interface, the application must call the IDWriteFactory::CreateTextFormat method as shown in the following code.


if (SUCCEEDED(hr))
{
    hr = pDWriteFactory_->CreateTextFormat(
        L"Gabriola",
        NULL,
        DWRITE_FONT_WEIGHT_REGULAR,
        DWRITE_FONT_STYLE_NORMAL,
        DWRITE_FONT_STRETCH_NORMAL,
        72.0f,
        L"en-us",
        &pTextFormat_
        );
}


When creating an IDWriteTextFormat object using the CreateTextFormat function, the application specifies the font family, font collection, font weight, font size, and locale name for the text format.

These properties cannot be changed after the IDWriteTextFormat object is created. To change these properties, a new IDWriteTextFormat object must be created with the desired properties.

The IDWriteTextFormat interface is used to draw text with a single format

To draw text with multiple formats, or to use a custom text renderer, use the IDWriteTextLayout interface. IDWriteTextLayout enables the application to change the format for ranges of text within the string. The IDWriteFactory::CreateTextLayout takes an IDWriteTextFormat object as a parameter and initially applies the format information to the entire string.

This object may not be thread-safe, and it may carry the state of text format change.

DirectWrite and Direct2D

To draw simple text with a single format, Direct2D provides the ID2D1RenderTarget::DrawText method, which draws a string using the format information provided by an IDWriteTextFormat object.

Requirements

   
Minimum supported client Windows 7, Windows Vista with SP2 and Platform Update for Windows Vista [desktop apps | UWP apps]
Minimum supported server Windows Server 2008 R2, Windows Server 2008 with SP2 and Platform Update for Windows Server 2008 [desktop apps | UWP apps]
Target Platform Windows
Header dwrite.h