Hi,
I think the link in Christopher's post indicates (at least to me) that this
isn't a bug - it's how the APIs work. You're getting the "B" width, not
the ABC width. I don't know offhand how to get the ABC width, but the API
behavior is consistent with the desktop.
As I said in my earlier response, this aspect of GDI certainly isn't my
strong point either, but here's my thoughts on the topic...
The ABC widths for a given character can apparently be determined by calling
the GetCharABCWidths API
(
http://msdn2.microsoft.com/en-us/library/ms901130.aspx), if it is present
on your platform.
As discussed in a desktop specific article "Drawing Text from Different
Fonts on the Same Line" (available on MSDN at
http://msdn2.microsoft.com/en-us/library/ms534212(VS.85).aspx) drawing
styled text is inheriently more difficult, especially when different font
styles and sizes are involved.
For example regular text drawn immediatly after italic text probably needs
to be moved over slightly to avoid any sloping content hanging over from the
previously drawn italic string.
However if you were calling DrawText for a second time in a row with the
same (italic) font you obviously wouldn't need to avoid the sloping content
and would want to start off where the previous string ended.
The DrawText API (DT_CALCRECT) etc had to pick one way or the other. If it
returned a rectangle that bounded all pixels drawn to the screen then italic
text drawn via DrawText one character at a time would have large gaps
between letters. As you have found out the API designers choose the other
option, and this has gotchas for fonts with overhang etc.
Text rendering is a complex business, as the tutorial I referenced
highlights.
Like Chris Tacke, I'm not aware of what the nice "managed way" for getting
text metrics is (if there is in fact one on the Compact Framework).
Hope this helps,
Christopher Fairbairn