MFC Support for DirectWrite – 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 … Read more

MFC Support for DirectWrite – Inline Images

DirectWrite allows inserting objects in a block of text, e.g. images, as shown in the picture. Let’s see how can be done! Implement IDWriteInlineObject interface methods to insert inline images Once we have created a CD2DTextLayout object, remains the following to do: Define a class for implementing IDWriteInlineObject interface, e.g. CInlineImage. We can derive it from … Read more

MFC Support for DirectWrite – Text Range Format

Once having a CD2DTextLayout object containing a formatted block of text and before drawing in the render target, we can change the formatting for particular ranges of text. For that purpose, call CD2DTextLayout::Get then directly use IDWriteTextLayout interface methods like SetFontWeight, SetUnderline, SetStrikethrough and whatever else we need and is available. An example of using … Read more

MFC Support for DirectWrite – Text Block Formatting

Beside the font attributes which can be set in the CD2DTextFormat MFC class constructor, DirectWrite supports more formatting for a block of text, e.g. text alignment, word wrapping, line spacing and so on. However, if taking a look at CD2DTextFormat documentation, we cannot find functions for doing that. Don’t worry, that’s not a problem at … Read more

MFC Support for DirectWrite – The Basics

A previous article shows how easy is to make an image viewer with MFC by enabling Direct2D support and using MFC wrappers over Direct2D interfaces. Now let’s discover MFC wrapper classes for DirectWrite. A simple example of drawing texts by using MFC DirectWrite wrapper classes Basically, must follow these steps: Enable MFC support for Direct2D. A … Read more

MFC Support for Direct2D – Part 2

A previous article shows how to use D2D MFC classes for easily make a simple image viewer. As said there, it can be made even easier. Enabling D2D support in MFC In the WM_CREATE message handler call CWnd::EnableD2DSupport. int CDemoView::OnCreate(LPCREATESTRUCT lpCreateStruct) { if (CScrollView::OnCreate(lpCreateStruct) == -1) return -1; EnableD2DSupport(); // Enable D2D support for this window: … Read more

MFC Support for Direct2D – Part 1

A few time ago, I begun writing a series of wrapper classes to make easier the using of Direct2D interfaces. Meanwhile, I discovered that MFC Library, beginning with Visual Studio 2010 SP1, offers an excelent built-in support. That’s pretty cool! So, let’s use Direct2D (D2D) MFC classes for making a simple image viewer. Image viewer … Read more

Using Direct2D for Rendering WIC Bitmap Sources

Once having a WIC (Windows Imaging Component) source, we can render it by using GDI, GDI+ or Direct2D. There are many examples over the internet including MSDN Library that describes how to perform this. This article describes how to use WIC Wrapper Library, which is designed for using WIC without worrying about directly deal with COM interfaces. … Read more