.Net 字体渲染不一致
我正在创建一个 .Net 2.0 SP2 windows 窗体应用程序。表单字体在我的机器上看起来很好,当我在另一台机器上尝试时,它看起来更大。 (这不是因为分辨率差异,字体相对于其他图标更大等)
我尝试调试问题,发现以下代码在不同的机器上返回不同的大小。
//inside a windows form
private void checkfont()
{
var g = this.CreateGraphics();
MessageBox.Show(g.MeasureString("Hello World", this.Font) + "," + this.Font);
}
我希望 Graphics.measurestring() 在不同的机器上为相同的参数返回相同的值。
对于字体“Verdana 8.25”,
- 在机器 1 上“Hello World”尺寸为 69.0px,14.7px
- 在机器 2 上“Hello World”尺寸为 86.3px,18.4px
为什么会出现这种差异?因此,我的应用程序字体看起来更大并影响布局。
编辑:
两台机器都有 .Net 2.0 SP2 ,但它们的分辨率和屏幕尺寸不同。据我了解,字体物理尺寸(在物理屏幕上)将随分辨率和屏幕尺寸而变化。但我的问题是为什么它们的像素单位尺寸不同?
机器 2 是 eeetop ET1602,默认为 Windows XP,其触摸屏系统它带有更大的所有桌面字体,但我已将 Windows 主题/Windows 字体重置为默认值。
I am creating an .Net 2.0 SP2 windows Forms Application. The form fonts looks fine in my machine, when i tried in another machine, it looks bigger. (This is not because of resolution difference, fonts are bigger relatively to other icons etc.)
I tried to debug the problem and found following code returns different sizes on different machine.
//inside a windows form
private void checkfont()
{
var g = this.CreateGraphics();
MessageBox.Show(g.MeasureString("Hello World", this.Font) + "," + this.Font);
}
I expect graphics.measurestring() to return same value for same arguments in different machines.
For font 'Verdana 8.25'
- On Machine 1 "Hello World" measures 69.0px,14.7px
- On Machine 2 "Hello World" measures 86.3px,18.4px
Why this difference ? because of this my application fonts looks bigger and affect layout.
edit:
Both Machines have .Net 2.0 SP2 , but their resolution and screen sizes differ. I understand that fonts physical dimension (on physical screen) will vary with resolution and screen size. But my question is why their dimension in pixel units differ ?
Machine 2 is eeetop ET1602 with windows xp, its touch screen system, by default it came with all desktop fonts bigger, but i have reset windows theme/windows fonts to default.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
当您指定“Verdana 8.25”时,这个8.25与像素没有直接关系,而是将它们视为“点”,如果屏幕DPI不同,它们在不同机器上的渲染将有所不同。
在 Windows 中,在桌面设置下,您可以选择增加屏幕字体大小而不更改分辨率。如果增加屏幕字体大小,则每像素点会发生变化,这可以测量不同机器上相同文本的不同像素大小。
这是因为老年人无法阅读较小的字体,这就是为什么他们可以增加桌面设置中的字体大小。而且你只能以磅为单位指定字体大小,如果将字体大小固定为像素,那么老年人或视障人士将很难正确阅读文本。这样整个操作系统的文本大小就由用户控制。
When you secify "Verdana 8.25" , this 8.25 has nothing to do with pixels directly, instead they are considered as "Points" and they will be rendered differently on different machines if the Screen DPI is different.
In Windows, under Desktop settings you have option of increasing the screen font size without changing the resolution. If you increase screen font size then the Dot per pixel changes which can measure different pixel size for same text on different machine.
This is due to fact that old people can not read smaller fonts, thats why they can increase the font size in desktop settings. And you can only specify the font size in points, if font size will be fixed to pixels, it will be difficult for the old or visually impaired people to read the text correctly. This way the text size of entire operating system is in control by the user.
这看起来像是 DPI 字体缩放设置为“大字体”?
编辑
请参阅 Akash Kava 的回复 - 他详细介绍了“大字体”设置。
This looks like DPI font scaling being set to "large fonts"?
EDIT
See Akash Kava's reply - he goes into more detail on the "large fonts" setting.