Reputation: 9610
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 (instead the actual height of the text's tight-fitting bounding box)?
Upvotes: 0
Views: 2108
Reputation: 4642
See the answer I gave in this question. The question's about the text width, but you can get the text height as well.
Upvotes: 0
Reputation: 9610
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 ;)
Upvotes: 3