Direct2D is a 2D graphics API introduced in Windows 7. It was backported to Windows Vista and is available to users that have installed the Vista Platform Update. It is the replacement for the older Windows 2D graphics API known as GDI/GDI+. Direct2D is the only 2D graphics API available on Windows RT and for Metro applications. Metro applications are a special class of applications that operate on Windows 8 x32/x64 and Windows RT. Only Metro applications will be allowed in the new Windows App Store. Direct2D will likely be the only 2D graphics API available on Windows Phone 8 (Edit Oct 31: Windows Phone 8 does not support Direct2D.). Direct2D has sister API called DirectWrite which is used for text rendering in Direct2D.
Juce Direct2D Background
Juce has the ability to change how it renders its graphics. On Windows there are currently two working renderers: the Software Renderer and the OpenGL renderer. Around 2010, Jules began work on a Direct2D renderer however it was never completed and remains unfinished in the Juce source tree. In Nov 2011, Jules introduced support for text rendering via DirectWrite and in May 2012 he introduced support for font families and font styles with DirectWrite.
Juce Font Rendering Background
The Juce software renderer and OpenGL renderer do not support font hinting or LCD optimized rendering via Juce APIs. Jules will not implement font hinting in Juce itself but has helped to allow 3rd party code to implement hinting. TheVinn has written such code which allows you to have hinted font rendering by utilizing FreeType. This library is only able to hint fonts that have been included as an Embedded CustomTypeface. It currently does not allow you to hint fonts from a font file or from the system font collection. It likely could be adapted to do so but TheVinn has no plans on doing this himself as it is beyond his own needs for the library.
Now that the DirectWrite work is pretty much complete. I thought I’d take a look at the Direct2D code Juce wrote. While not done, it is actually near complete functionality wise. The current code was broken around font handling so I updated that code to use the new DirectWrite code.
I just picked two fonts at random without putting much thought into it. I have no idea whether these fonts were manually hinted, auto-hinted or have no hints at all. Though by the looks of it, I’m pretty sure MS Gothic has some sort of hinting going on.
English - Verdana
Chinese - MS Gothic
I suppose I probably should have looked harder for specifically hinted fonts.
Software Renderer vs Direct2D Renderer - English
Software Renderer vs Direct2D Renderer - Chinese
Juce Text Rendering vs Sub-pixel ClearType
Work To Do
While everything looks good visually, the performance is not good. Just simple mouse over standard buttons is laggy and the Animated Graphics Demo in the Juce Demo has a bad framerate.
I am hopeful the performance can be improved, IE9 and Firefox both use D2D and can render all sorts of complex graphics quickly, but it will take a lot of optimization.
The small amount of missing functionality needs to be added and the code should be refactored a bit to make it production ready.
If anyone is interested in helping out getting this into tip, please let me know.
Thanks to TheVinn who’s test app served as the inspiration for my test app.