在高分辨率显示器上映射字体大小时使用什么缩放系数?

发布于 2024-07-27 12:17:22 字数 543 浏览 2 评论 0原文

我们的应用程序需要支持高分辨率显示器。 目前,当应用程序在高分辨率显示器中出现时,它显示的文本太小。 我们默认使用 Arial 12 点字体。

现在为了使文本可见,我需要按比例更改字体大小。 我发现很难想出一个公式来给我给定显示器分辨率的目标字体大小。

这是我对这个问题的理解。

1) 在 Windows 上,默认情况下 96 像素对应于 1 逻辑英寸。 这意味着当显示器分辨率增加时,以逻辑英寸为单位的屏幕尺寸也会增加。

2) 1 Point 字体是逻辑英寸的 1/72。 因此,结合每逻辑英寸有 96 个像素的事实,结果是,每个字体点有 96/72 个像素。

这意味着对于 12 点字体,它将占用的像素数为 12*96/72 = 16 像素。

现在我需要知道需要增加这些像素数的缩放因子,以便生成的字体正确可见。 如果我知道缩放后的像素数,我只需将其除以(96/72)即可获得字体大小,

建议的缩放因子是多少,可以确保在所有显示器分辨率上正确缩放字体?

另外,如果我的理解有误,还请指正。

We have a requirement where our application needs to support high resolution monitors. Currently, when the application comes up in High res monitor, the text that it displays is too small. We use Arial 12 point font by default.

Now to make the text visible, I need to change the font size proportionally. I am finding it tough to come up with a formula which would give me the target font size given the monitor resolution.

Here is my understanding of the problem.

1) On windows, by default 96 pixels correpond to 1 Logical inch. This means that when the monitor resolution increases, the screen size in logical inches also increase.

2) 1 Point font is 1/72 of a Logical Inch. So combined with the fact that there are 96 Pixels per Logical inch, it turns out that, there are 96/72 Pixels per Point of Font.

This means that for a 12 point font, The number of Pixels it will occupy is 12*96/72 = 16 Pixels.

Now I need to know the scaling factor by which I need to increase these Number of Pixels so that the resultant Font is properly visible. If I know the scaled pixel count, I can get the Font size simply by dividing it by (96/72)

What is the suggested scaling factor which would ensure properly scaled Fonts on all monitor resolutions?

Also, please correct if my understanding is wrong.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

∞琼窗梦回ˉ 2024-08-03 12:17:22

MSDN 页面上有一个 LOGFONT 结构< /a>. 您的理解是正确的,您需要将点大小缩放vertres / 72

lfHeight = -PointSize * GetDeviceCaps(hDC, LOGPIXELSY) / 72;

There's an example on the MSDN page for LOGFONT structure. Your understanding is correct, you need to scale the point size by vertres / 72.

lfHeight = -PointSize * GetDeviceCaps(hDC, LOGPIXELSY) / 72;
故事灯 2024-08-03 12:17:22

如果您在 Windows 中将分辨率设置为与物理显示器的分辨率相匹配,则无需进行调整。 任何编写良好的程序都会执行正确缩放字体所需的乘法和除法,并且在最新版本的 Windows 中,操作系统将谎报分辨率并自动缩放字体。

如果您希望在 Windows 设置之外处理此问题,只需将字体大小乘以实际 DPI,然后除以 96。

编辑:从 Windows Vista 开始,Windows 将不会报告您实际配置的 DPI,除非您编写 DPI 感知程序。 Microsoft 对此主题有一些指导。 您可能会发现 Microsoft 为非 DPI 感知程序提供的默认缩放足以满足您的目的。

If you set the resolution in Windows to match that of the physical monitor, no adjustment should be needed. Any well written program will do the multiplication and division necessary to scale the font properly, and in the newest versions of Windows the OS will lie about the resolution and scale the fonts automatically.

If you wish to handle this outside of the Windows settings, simply multiply your font size by your actual DPI and divide by 96.

Edit: Beginning with Windows Vista, Windows will not report your actual configured DPI unless you write a DPI-aware program. Microsoft has some guidance on the subject. You might find that the default scaling that Microsoft provides for non-DPI-aware programs is good enough for your purposes.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文