开发者

How can I obtain the Line Height of a GDI HFONT?

I'm adding SVG export support to an old application built with MFC and using plain old GDI. As SVG 1.1 doesn't support text wrapping, I am forced to do this manually.

The application provides me with a CFont instance (which contains an HFONT). I can calculate the width of a piece of text using CFont::GetTextExtentPoint(), but I haven't found out how to obtain the line height of a font yet.

How can I obtain the line height of my font? Or does CFont::GetTextExtentPoint() always return the line height in the Y coordinate (ins开发者_JS百科tead the actual height of the text's tight-fitting bounding box)?


I think I have a possible answer:

CDC desktopDC;
desktopDC.Attach(::GetDC(0));
desktopDC.SelecTObject(&font);

::TEXTMETRIC metrics;
desktopDC.GetTextMetrics(&metrics);

int lineHeight = metrics.tmHeight + metrics.tmExternalLeading;

It's a bit cumbersome, so if there's a shorter, more obvious solution (or if anyone can confirm that CFont::GetTextExtentPoint() provides me with the actual line height), I'd be happy to hear it still ;)


See the answer I gave in this question. The question's about the text width, but you can get the text height as well.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜