views:

142

answers:

2

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)?

A: 

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 ;)

Cygon
A: 

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

djeidot
Sorry, that's not what I'm looking for. I need the line height: the offset from one line to the next, which is the static text height (which is not dependent on the actual string) plus the spacing between lines.
Cygon