Hi, my name is Mikhail Leonov, and I’m a Senior Software Development Engineer on the DirectWrite team at Microsoft. I would like to address common user feedback on DirectWrite in a relatively informal ‘simple question – simple answer’ format. Feedback themes were gathered mostly from the user comments on various DirectWrite related blogs. Please feel free to post additional questions in the comments section right after this blog post. Throughout this post, I will assume the reader is familiar with DirectWrite basics. This link provides a good starting point: https://channel9.msdn.com/pdc2008/PC18/.
DirectWrite from the programmer’s point of view
I want to experiment with DirectWrite in my application. How do I start using it?
DirectWrite can be used from native C++ code by including DWrite.h header file and linking to the DWrite.lib library. At the runtime, the application will automatically load DWrite.dll.
To start with, the application needs to call
DWriteCreateFactory. The factory pointer returned by
IDWriteFactory interface, which can be used to perform actions such as creating DirectWrite font and layout objects.
For more information, please refer to the introductory DirectWrite materials linked in the beginning of this post.
DirectWrite on pre-Windows 7 operating systems
My application needs to work on Vista and XP. Is using DirectWrite an option for me?
DirectWrite technology will ship first with Windows 7. After Windows 7 ships, DirectWrite will be made available for Windows Vista as well. There are no plans today to make DirectWrite available on Windows XP.
Microsoft platforms and applications using DirectWrite
Does Microsoft use DirectWrite in its own products? I installed Windows 7, and I don’t see natural ClearType anywhere on the screen.
DirectWrite is used by the Windows 7 ClearType Text Tuner control panel applet and by the XPS Viewer application. It is worth noting that DirectWrite is a new technology, and it takes time for customers to evaluate their existing text functionality and determine how to take advantage of DirectWrite.
Supported font formats
Does DirectWrite only support TrueType fonts? How about Type 1 fonts or bitmap fonts?
DirectWrite supports font files conformant to the OpenType specification version 1.5, which can be accessed here: http://www.microsoft.com/typography/otspec/default.htm. This support includes OpenType fonts with both TrueType and CFF outlines, and TrueType fonts with embedded bitmaps. Simply speaking, if your font has a TTF, OTF or TTC extension, DirectWrite should support it well.
DirectWrite does not support bitmap or vector .FON font files, and DirectWrite does not support Adobe Type 1 .PFM/.PFB font files.
Installed fonts, local fonts, embedded fonts, per user fonts
My application uses a custom font for certain user interface elements. Do I have to install it on the system in order for DirectWrite to be able to use it?
No, one doesn’t have to install a font in order for DirectWrite to be able to use it. DirectWrite provides full support for font files that are local to an application.
The application that uses DirectWrite needs to register its own
IDWriteFontFileLoader interface implementation that manages the association between the font file location and contents. To support local font file enumeration functionality, the application needs to register its own
Rendering technologies to use DirectWrite with
Can I use DirectWrite in my GDI+ application? How about using DirectWrite with Direct3D or GDI?
DirectWrite font stack is designed to be independent from any rendering technology, so clients have flexibility to use any existing rendering mechanism in their
IDWriteTextRenderer implementation. In addition, DirectWrite is designed to work well with Direct2D rendering components, and Direct2D provides convenient wrappers such as
ID2D1RenderTarget::DrawText() for drawing text on D2D surfaces.
DirectWrite itself provides GDI interoperability helpers via
IDWriteGdiInterop interface. One can create a DirectWrite font face object that corresponds to a font selected in a GDI
HDC and easily replace
ExtTextOut(…, ETO_GLYPH_INDEX, …) calls with DirectWrite based glyph run drawing calls without requiring significant changes to the rest of the application code. One can also create a
LOGFONT description for a DirectWrite font face object to re-use existing GDI based controls from a DirectWrite based text processing component. On top of that, one can create GDI surfaces that satisfy DirectWrite rendering requirements through
IDWriteGdiInterop::CreateBitmapRenderTarget() method, and draw DirectWrite glyph runs on that surface using
Interoperability with GDI+ can be achieved via
FromHdc() methods provided by the GDI+
Graphics object. The client has a choice of starting with a
Graphics object and only switching to
HDC methods for DirectWrite interoperability calls, or starting with an
HDC obtained from
IDWriteBitmapRenderTarget::GetMemoryDC() and switching to
Graphics object derived from it. Which of these two approached is the best depends on the application needs.
Applications that render using Direct3D usually need to obtain text in either bitmap or outline form. To get the former, the client can ask DirectWrite to produce alpha textures containing text using
IDWriteGlyphRunAnalysis interface. To get the latter, the client can use
IDirectWriteFontFace::GetGlyphRunOutline() method to produce a geometry containing text.
How do I specify text rendering options in DirectWrite? I want to use the new natural ClearType for text paragraphs, while having text in my menus and buttons look like the rest of the operating system.
In your case, two different measuring modes should be used—
DWRITE_MEASURING_MODE_NATURAL for text paragraphs, and
DWRITE_MEASURING_MODE_GDI_CLASSIC for menu and button text. The measuring mode then gets passed to drawing calls such as
DrawGlyphRun() as an input parameter. For clients who create
DWRITE_MEASURING_MODE_NATURAL corresponds to calling
DWRITE_MEASURING_MODE_GDI_CLASSIC corresponds to calling
useGdiNatural set to