Partager via


DirectWrite Questions and Answers

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 DWriteCreateFactory implements 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: https://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 IDWriteFontCollectionLoader interface.

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 IDWriteBitmapRenderTarget::DrawGlyphRun() method.

Interoperability with GDI+ can be achieved via GetHdc() and 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.

Rendering quality

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 ID2D1RenderTarget::DrawText() and DrawGlyphRun() as an input parameter. For clients who create IDWriteTextLayout themselves, DWRITE_MEASURING_MODE_NATURAL corresponds to calling IDWriteFactory::CreateTextLayout(), and DWRITE_MEASURING_MODE_GDI_CLASSIC corresponds to calling IDWriteFactory::CreateGdiCompatibleTextLayout() with useGdiNatural set to FALSE.

Comments

  • Anonymous
    April 14, 2009
    The comment has been removed

  • Anonymous
    November 02, 2009
    The comment has been removed

  • Anonymous
    November 11, 2009
    DirectWrite is looking pretty powerful, but I've been wondering how reading in and writing out from a file will work, or how communication to a managed layer will work. Is there going to be anything like being able to pass around, read in, write out a formated string of sorts? perhaps a rich text formatted string? If not, what approach do you think developers should take to be able to read in/write out the information?

  • Anonymous
    November 12, 2009
    Brandon - The DWrite team has expanded to their own blog. You can get in contact with them at http://blogs.msdn.com/DirectX/

  • Anonymous
    March 20, 2010
    As I already heard, DirectWrite won't be available on XP/2003, but also IE9 will render texts via the DWrite, it means that IE9 will be only Win6 and Win7 browser, but a greatest part of people uses pre NT6 Windows versions. I know that a great part of companies won't move to NT6+ for a long time. IE9 will be available for very limited circle of users.  What MSFT think about it?

  • Anonymous
    March 22, 2010
    Drake – Your question seems to be targeted at Internet Explorer + DirectWrite.  Since I am not on the DirectWrite or Internet Explorer team, I am not in a good position to comment. I suggest you ask this question on the DirectWrite blog which is part of http://blogs.msdn.com/DirectX/ From a WPF point of view, WPF uses DirectWrite on Win7 systems since it is guaranteed to be available. On all other down-level systems we have revamped our text stack to produce the same rendering. This way all WPF4 apps look the same on all systems.

  • Anonymous
    April 07, 2010
    Hey i want to ask that in direct3d 9 if i want to render in a WPF owned window without a airspace restriction is using a d3dimage which gives no matched performance like onscreen rendering. Is there same restriction in direct3d11 also or we can use direct2d to render directly on WPF owned window.

  • Anonymous
    April 13, 2010
    Himanshu - I ran your question by our graphics team and got the following information. If you are asking does D3D11 or D2D remove the restriction of having to use either HWND hosted means  or D3DImage to get D3D content into a WPF application, the answer is no. They also suggested that you check out the link below. It has some good information on using DX11/D2D with D3DImage... as well as some invaluable comments on cheap designer clothes, pirated software, and video game tips :-p http://jmorrill.hjtcentral.com/Home/tabid/428/EntryId/437/Direct3D-10-11-Direct2D-in-WPF.aspx