如果部署PC具有不同的字体DPI,如何计算合适的字体大小? [英] How can you calculate the appropriate Font Size if the deployment PC has a different font DPI?

查看:140
本文介绍了如果部署PC具有不同的字体DPI,如何计算合适的字体大小?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图找出目标Windows机器上的字体DPI大小,然后修改我们应用的字体,以使其显示的大小与目标计算机与开发机的dpi相同。 (因此,较大的Target DPI将意味着我们将使字体比开发时更小。)

I'm trying to figure out the font DPI size on the target Windows machine and modify our app's font so that it appears the same size as it would if the target machine had the same dpi as the dev machine. (So a larger Target DPI would mean we'd make our fonts smaller than at dev time).

我想知道是否存在任何问题。以下解决方案,特别是LOGPIXELSX = 88是否正确。

背景

我调整窗体上所有控件和字体的大小以匹配当前Windows屏幕分辨率。但是,如果某人将其Font DPI设置得较高,我们需要考虑到这一点,并使字体更小(这样最终在屏幕上显示的是正确的大小)。我们的字体已经很大(特别是因为我们使用屏幕分辨率调整字体大小)。 DPI较高会带来额外的尺寸,使文本太大。

I resize all controls and fonts on our forms to match the current Windows screen resolution. However, if someone has their Font DPI set higher, we need to account for that and make the font smaller (so it ends up being the right size on the screen). Our fonts are already quite large (especially since we resize them w/ screen res). The extra size from the higher DPI makes the text too large.

到目前为止我的解决方案
根据我的判断,是否我们使用如下所示的GetDeviceCaps,然后获取CurrentFontDPI并执行以下操作:
(由于新的屏幕分辨率而忽略了字体大小的修改):

My solution so far From what I can tell, if we use the GetDeviceCaps as below and then get the CurrentFontDPI and do this: (Ignoring the font size modification due to the new screen resolution):

NewFontSize = CurrentFontSize *(DevelopmentDPI / CurrentFontDPI)

NewFontSize=CurrentFontSize * (DevelopmentDPI/CurrentFontDPI)

 Function CurrentFontDPI
  Dim hwnd, hDC, logPix, r As Long
  Dim  LOGPIXELSX=88
  hwnd = GetDesktopWindow()
  hDC = GetDC(hwnd)
  logPix = GetDeviceCaps(hDC,LOGPIXELSX )
  r = ReleaseDC(hwnd, hDC)
  CurrentFontDPI= logPix

最终功能

仅供参考,以上代码是相关的SO问题] [1]中较大例程的一部分。我忽略了代码b / c的其余部分,看来至少有一个错误(它的NewFont = OldFont *(NewDPI- OldDPI),如果DPI不变,则字体高度为零)

FYI, the above code is part of a larger routine at "a related SO Question][1]. I left out the rest of the code b/c it seemed to at least one error (it had NewFont=OldFont * (NewDPI-OldDPI) which would give you zero height fontsize if the DPI hadn't changed)

[1]: http://www.BungalowSoftware.com 测试

推荐答案

这是来自Microsoft的好文章,涉及编写支持DPI的应用程序。 (请注意,本文与发布到相关问题的文章不同。)

Here's a good article from Microsoft on writing DPI-aware applications. (Note that this article is different than the one posted to your related question.)

LOGPIXELSX是Windows系统调用的参数;它不是DPI值。

LOGPIXELSX is a parameter for a Windows system call; it is not a DPI value.

在VB6(IIRC)中,可以使用开发时的TwipsPerPixel(X和Y)与TwipsPerPixel(X和Y)的比率。运行时是确定如何扩展的另一种方式。与您的DPI比率相同,但它利用了内置的VB属性。

In VB6 (IIRC) you can use the ratio of TwipsPerPixel (X and Y) at development time to TwipsPerPixel (X and Y) at runtime as another way to determining how to scale. Same as your DPI ratio but it takes advantage of built-in VB properties.

这篇关于如果部署PC具有不同的字体DPI,如何计算合适的字体大小?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆