Does how does Graphics::MeasureString compute the bounding box
rectangle height for a single line of text? Does it just call
Font::GetHeight?
I hope future versions of GDI+ are not released before the
documentation is improved and the implementation is finished. Are
there any KB articles besides the GDI vs GDI+ text one yet?
--------------------
From a recent post in microsoft.public.win32.programmer.gdi by one of my
teammates:
>>In general the GdiPlus question that you are asking is "How do I
calculate
a placement point such that the baseline of the first line of text is
aligned at a specific point?"
The answer is: calculate that point from the font metrics using code
similar to the following:
UINT16 ascent = fontFamily3.GetCellAscent(fontStyle);
UINT16 ascentPixel = (UINT16)(font3.GetSize() * ascent /
fontFamily3.GetEmHeight(fontStyle)+ 0.5);
PointF txpt(pt.X, pt.Y-ascentPixel);
graphics.DrawString(string2, -1, &font3, txpt, strFormat, &solidBrush3);
Here, ascent gets the design unit height of the ascender for the font of
the type style contained in fontStyle. We then convert this metric into
ascentPixel by using ascent to determine the proportion of the pixel height
of the font that contains the ascender and then round the result.
This is information taken from the "Obtaining Text Metrics" topic in Gdi
Plus.
For a given device at any given resolution, this should be good to within a
pixel or two. Since there is no fine, resolution specific, control over
glyph placement, this is the best that you can expect to achieve.<<
We also recently published KB article Q307208 on text output in GDI+,
available at:
http://support.microsoft.com/default.aspx?scid=kb;EN-US;Q307208
Thanks,
- John
Microsoft Developer Support
This posting is provided "AS IS" with no warranties, and confers no rights.