I’m using GDI+ in C++. (This issue might exist in C# too).
I notice that whenever I call Graphics::MeasureString() or Graphics::DrawString(), the string is padded with blank space on the left and right.
For example, if I am using a Courier font, (not italic!) and I measure ‘P’ I get 90, but ‘PP’ gives me 150. I would expect a monospace font to give exactly double the width for ‘PP’.
My question is: is this intended or documented behaviour, and how do I disable this?
RectF Rect(0,0,32767,32767); RectF Bounds1, Bounds2; graphics->MeasureString(L'PP', 1, font, Rect, &Bounds1); graphics->MeasureString(L'PP', 2, font, Rect, &Bounds2); margin = Bounds1.Width * 2 - Bounds2.Width;
It’s by design, that method doesn’t use the actual glyphs to measure the width and so adds a little padding in the case of overhangs.
MSDN suggests using a different method if you need more accuracy: