Calculating the logical font size

北城余情 提交于 2019-12-11 12:06:47

问题


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.



来源:https://stackoverflow.com/questions/10268470/calculating-the-logical-font-size

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!