Calculating the logical font size

2019-07-28 03:06发布

问题:

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?

回答1:

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.