简体   繁体   中英

Calculating the logical font size

Many examples show the following way of calculating a font's logical size from its point size, which is also how my code has been doing it for years:

SizeLogical = -MulDiv(SizePt, GetDeviceCaps(hdc, LOGPIXELSY), 72);

But I recently noticed that examples like this one use a factor of 96 instead of 72. Is this because the monitors' physical resolution has increased over the years, so they display 96 pixels per inch as opposed to typography's classic 72 points per inch? If so, the correct solution would be to determine the factor dynamically, but which Windows API does one call to do that? Or am I misunderstanding it all anyway?

72 is the number of points per inch, this never changes. 96 is the number of pixels per inch, and it can change from system to system.

I believe the formula you're using is straight from the Microsoft documentation. Edit - Here it is: http://msdn.microsoft.com/en-us/library/dd183499%28v=vs.85%29.aspx

You don't have to worry about the 96 because that's what is being returned by GetDeviceCaps.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM