Thank $deity for harsh critics
Friday, April 23rd, 2010We had an email from an irate customer complaining about the ugliness of the fonts in Resolver One. A quick investigation revealed that the Calibri font looks hideous; our own default is Tahoma, and we don’t tend to use Calibri internally, so we’d not really noticed — but because Calibri is the default in Microsoft Excel, an Excel import resulted in a horrible-looking spreadsheet. A further investigation revealed that this problem wasn’t just present in the grid component that we’re getting rid of: the same ugliness was present in the new, shiny grid that we are working on.
Our first thought was that it was a simple anti-alias issue and that we could fix it that way. The following screenshots show the dilemma we were faced with: The two settings (ClearType and AntiAliasGridFit) that made one of the fonts acceptable, made the other one ugly.

Resolver One with GDI+ and AntiAliasGridFit

Resolver One with GDI+ and ClearType
The second version is what you would see in the current version of Resolver One, and was also what you would have seen with the new grid if we’d not heard about this problem.
After some swearing and googling, Giles discovered this post that led us to the solution. We switched from using the DrawString method of System.Drawing.Graphics (which uses GDI+ to do the drawing) to DrawText on the System.Drawing.TextRenderer (which uses GDI to do the drawing). The result is that the two fonts look great:

Resolver One with GDI DrawText
An unexpected benefit is that another issue that we were worried about has also been solved: When switching to and from edit mode in a cell, the font appearance changed. This was a result of the switch from GDI rendering in the TextBox to the GDI+ rendering in the grid.
There are two lessons here:
- Harsh critics are your best friends when you’re writing software. Their criticisms improve your product. Listen to them.
- If you’re ever drawing stuff in .NET and it looks terrible, make sure you’re using the nasty old GDI API to do your drawing instead on the shiny, new GDI+ API.
