Movatterモバイル変換


[0]ホーム

URL:


Skip to main content

This browser is no longer supported.

Upgrade to Microsoft Edge to take advantage of the latest features, security updates, and technical support.

Download Microsoft EdgeMore info about Internet Explorer and Microsoft Edge
Table of contentsExit focus mode

Interoperating with GDI

  • 2020-08-19
Feedback

In this article

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:

Introduction

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.

Part 1: IDWriteGdiInterop

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);}

Part 2: Font Objects

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.

Part 3: Rendering

To render DirectWrite text to a GDI surface you use a custom text renderer. See theRender to a GDI Surface topic.

 

 


Feedback

Was this page helpful?

YesNo

In this article

Was this page helpful?

YesNo