Until now the toolkit has been using a small custom engine for drawing text. Not any more, it’s time to shift over to the TextRenderer class.

In an ideal world I would like to use GDI+ to draw text because it offers the ability to draw using a Brush which allows some really nice effects. You can use gradient fills or even overlay an image to get just the right subtle texture. Unfortunately we all know that the GDI+ versions of MeasureString and DrawString are useless. They are just not reliable in getting an accurate measure of the text size. Well I suppose they are reliable in that they always give you an answer way bigger than the actual text size. But as I need to get pretty close to pixel perfect measuring they will not suffice.

So instead I created a little engine that draws the text one character at a time and does some rather slow jiggery pockery to get the pixel exact size of the text that is being drawn. Up to a point it did work and so it has been there right from the start of the toolkit. But it does not handle complex scripts very well and even simple English text does not appear exactly the same way it would on other windows controls. So it is time to ditch the custom engine and make the switch to the .NET2 provided TextRenderer class.

There are however a couple of drawbacks to using the TextRenderer class. First of all it only draws text using a single color. No more gradient, radial or image effects. This is a shame but not a big a deal as it is not the most used feature of the toolkit. Second is that it cannot be used to draw at an angle.

Now you can get around the second issue by drawing onto a bitmap first and then blitting the bitmap onto the screen using a rotate transform to get the required angle. Unfortunately there is yet another limitation because when you draw onto a bitmap it will not use transparency. Why it cannot do this is a complete mystery to me but it cannot.

So the next version of the toolkit will be using the TextRenderer and so draw in any language and complex script that you care to use in your application. But you need to be careful in choosing your font if you need controls that are orientated vertically as they will ignore the anti aliasing.

Leave a Reply