21
votes

I already know that sub-pixel positioning causes DirectWrite text rendering to be blurry compared to GDI.

However, my question is a bit more fundamental: Why can't DirectWrite (and related methods) be made to render text as sharply as GDI?

In other words:
What prevents DirectWrite from being able to snap text to the nearest pixel, the way GDI can?

Is it, for example, a hardware issue? A driver architecture issue? Is it simply not implemented? Or something else?


Smaller sample:

Larger samples:

Direct2D, aliased:

Direct2D, default:

Direct2D ("classic GDI"):

Direct2D ("natural GDI"):

Actual classic GDI:

![](http://i.stack.imgur.com/kbdPb.png)

Actual ClearType GDI:

enter image description here

1
Hmm, yeah, I'd like to see an answer to this. These technologies produce text that's far too blurry to make them worthwhile; I can't even use products that render text with DirectWrite (cough, Firefox). Unfortunately, I have a sneaking suspicion that the answer is nobody working on the project thinks it is important.Cody Gray♦
Because pixel snapping makes the width of the rendered text unpredictable. Resolution independent text rendering is the holy grail. Flubbed by GDI+, a hard requirement for WPF and sustainable improvements in display technology.Hans Passant
DWrite can do it, you just have to ask. Create custom render parameters with clearTypeLevel set to zero. Note that sharpness comes at the expense of accuracy. See for example the rotated text and how chunky it looks in GDI, and how uneven the spacing is in GDI compared to subpixel.Raymond Chen
@RaymondChen: I've actually tried that before (when trying to see if SciTE's accelerated text rendering can be made sharper), but it doesn't work. Maybe I was doing it wrong -- do you have a demo piece of code that shows it rendering sharply?user541686
@Mehrdad I never tried it myself, but from reading the docs it looks like it should have worked. Maybe it just switches to grayscale anti-aliasing? At any rate, if you don't like DirectWrite, then don't use it. (It's not so much that the width is unpredictable so much as it is uneven. At low resolutions, a whole pixel is BIG.)Raymond Chen

1 Answers

19
votes

You aren't comparing like with like. Your Direct2D samples are all rendered in grayscale, whereas the GDI and Linux samples are using sub-pixel anti-aliasing (aka ClearType on Windows).

This page describes what you need to do to enable cleartype: http://msdn.microsoft.com/en-us/library/windows/desktop/dd368170%28v=vs.85%29.aspx

N.B. When testing rendering like this, it's always worth using Windows Magnifier or similar to check that you are actually getting what you think you are getting.