This browser is no longer supported.
Upgrade to Microsoft Edge to take advantage of the latest features, security updates, and technical support.
Note
Access to this page requires authorization. You can trysigning in orchanging directories.
Access to this page requires authorization. You can trychanging directories.
DirectWrite provides a migration path from, and some interoperability with, GDI's font model, as well as interfaces for rendering text to a bitmap that can then be drawn on a window.
This overview contains the following parts:
DirectWrite provides methods for converting between GDI's LOGFONT structure and DirectWrite font interfaces. This allows you to use GDI for some or all of the font enumeration and selection, while taking advantage of the improved functionality and performance of DirectWrite. DirectWrite also has interfaces for rendering to a bitmap if you want to display text on a GDI surface.
TheIDWriteGdiInterop interface is used to convert between GDI font structures andDirectWrite font interfaces, and also to create anIDWriteBitmapRenderTarget object. Get anIDWriteGdiInterop object by using theIDWriteFactory::GetGdiInterop method, as shown in the following code.
// Create a GDI interop interface.if (SUCCEEDED(hr)){ hr = g_pDWriteFactory->GetGdiInterop(&g_pGdiInterop);}
GDI uses the LOGFONT structure to store information about the font and style of text. TheIDWriteGdiInterop::CreateFontFromLOGFONT method will convert a LOGFONT structure to anIDWriteFont object, as seen in the following code.
// Convert to a DirectWrite font.if (SUCCEEDED(hr)){ hr = g_pGdiInterop->CreateFontFromLOGFONT(&lf, &pFont);}
However,IDWriteFont does not encapsulate all of the same information that a LOGFONT does. A LOGFONT structure contains the font size, weight, style, underline, strikeout, font face name, and some other information.IDWriteFont objects contain information about a font and its weight and style, but not the font size, underline, and so on. WithDirectWrite, formatting information elements such as these are encapsulated by anIDWriteTextFormat object or, for specific ranges of text, anIDWriteTextLayout object.
You do have the option to convert aIDWriteFont to a LOGFONT by using theIDWriteGdiInterop::ConvertFontToLOGFONT.
To render DirectWrite text to a GDI surface you use a custom text renderer. See theRender to a GDI Surface topic.
Was this page helpful?
Was this page helpful?