MFC Support for DirectWrite – Part 5: Typography

Some fonts like Microsoft’s Gabriola support a number of typographic features which allow users to control how they look, e.g by enabling some fancy stylistic text rendering. With DirectWrite we can do that by passing a IDWriteTypography object to IDWriteTextLayout::SetTypography method.

Set text layout typography with DirectWrite in an MFC application

We have not an MFC class which wraps IDWriteTypography but that’s not a problem. First, we can get a pointer to IDWriteFactory from a global AFX_GLOBAL_DATA structure.  Further create an IDWriteTypography instance, add desired font feature(s) and finally, set the typography in a range of the text layout. Here is an example:

Later update

In Visual Studio 2012, IDWriteFactory instance has been moved in a D2D-specific structure of type _AFX_D2D_STATE that can be accessed by calling AfxGetD2DState.
So, if using Visual Studio 2012 or newer you have to replace


See also: Getting Direct2D, DirectWrite and WIC Factories in MFC.

Demo application

Download: MFC Support for DirectWrite Demo (Part 5).zip (1422)

MFC Support for DirectWrite (Part 5) – Typography

MFC Support for DirectWrite (Part 5) – Typography

Resources and related articles

Leave a Reply