Overview

To use the DirectWrite library, include the dwrite_3.h header.

#include <dwrite_3.h>

Initialization

Factory

The DirectWrite factory is the main object that creates other DirectWrite objects.

A factory is represented by the IDWriteFactory7 interface.

Microsoft::WRL::ComPtr<IDWriteFactory7> writeFactory;

To create a DirectWrite Factory, call the DWriteCreateFactory function.

HRESULT hr = DWriteCreateFactory(
		DWRITE_FACTORY_TYPE_SHARED,
		__uuidof(IDWriteFactory7),
		&writeFactory);

if (FAILED(HR))
{
}

Format

An IDWriteTextFormat object represents the formatting information for a paragraph of text.

To create a text format, call the IDWriteFactory::CreateTextFormat method on the factory.

Layout

An IDWriteTextLayout object represents the layout for a paragraph of text using a IDWriteTextFormat object with a specific dimension of the space constraint.

To create a text layout, call the IWriteFactory::CreateTextLayout method on the factory with an input string, the layout constraints, and a IDWriteTextFormat.

Drawing

An application can then render the text using the DrawText or DrawTextLayout functions from Direct2D, or by implementing a custom callback function.

When you need to draw the same text multiple times, call the DrawTextLayout function to create a layout that can be reused.

<aside> 💡 Set the text antialiasing mode to D2D1_TEXT_ANTIALIAS_MODE_GRAYSCALE. The quality of rendering grayscale text is comparable to ClearType but is much faster.

</aside>