Jon Tackabury Jon Tackabury - 11 months ago 68
C# Question

How do you convert LOGFONT.lfHeight to pixels?

I have a

LOGFONT.lfHeight
value of -11. However, I know that the font size is actually 8 so do I need to convert this number to a different unit of measurement? I found this formula in the MSDN docs:

int height = abs((pixels * DOTSY) / 72);


This takes pixels and makes it into a height value that
LOGFONT
can use. If I work this the other way:

int pixels = abs((height / DOTSY) * 72);


This gives me a value of 8.24. Am I correct in assuming this is all I need to do to convert the font height into a usable value?

Answer Source

Yes. DOTSY will be 96, which is the default monitor resolution in DPI in Windows. You will need to ensure that this value is correct for the device you're writing to - printers will usually have a much higher resolution, and the monitor resolution can be changed. lfHeight is negative to indicate that the font mapper should use character height instead of cell height to match, so only the absolute value is important here.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download