在.NET GDI +字体大小的差异?字体大小、差异、NET、GDI

2023-09-04 01:10:51 作者:冬天里胖子

我是令人头大我的大脑在试图理解字体之间的差异大小不一的用户选择或指定(例如,使用一个 FontDialog类)和EM-大小报告在字体类.NET。

例如:

 使用(FontDialog类DLG =新FontDialog类()){
    如果(dlg.ShowDialog()== DialogResult.OK){
        Console.WriteLine(选择字体大小:+ dlg.Font.SizeInPoints.ToString()0 ##);
    }
}
 

使用上述code,你会得到一些混乱的结果:

在对话框中选择11产生11.25

12选择在对话框中产生12

在对话框中选择14产生14.25

在对话框中选择16,产生15.75

如何在Mac上更改 字体 窗口中的字体大小呢

此行​​为发生,无论你选择的字体。正如你从上面可以看到,存在的差异没有模式,它似乎随机变化+0.25和-0.25之间。

我这个愿望在用户界面通过永远只能显示的字体大小为圆形整数,但我发誓,我所看到的文字处理/ DTP软件,使用户可以选择小数字体大小 - 这些软件包不显示与Windows字体对话框进行交互时,上述行为。

任何人都可以提供一个合理的解释呢?是否有一个最佳实践技术在UI中显示的字体大小?如何当用户想要的分数大小如'10 0.5'?

解决方案   

没有在差异无图案

正如你所看到的,字体大小会发生在0.75的增量。

编辑:您可以微调的大小,如果你不使用的字体对话框,但是结果我怀疑会比'preferred'大小不中看

I am wracking my brains in trying to understand the discrepancy between the font sizes users select or specify (for example, using a FontDialog) and the em-size reported by the Font class in .NET.

For example:

using (FontDialog dlg = new FontDialog()) {
    if (dlg.ShowDialog() == DialogResult.OK) {
        Console.WriteLine("Selected font size: " + dlg.Font.SizeInPoints.ToString("0.##"));
    }
}

Using the above code, you will get some confusing results:

Selecting 11 in the dialog produces 11.25

Selecting 12 in the dialog produces 12

Selecting 14 in the dialog produces 14.25

Selecting 16 in the dialog produces 15.75

This behaviour occurs regardless of the font you choose. As you can see from above, there is no pattern in the discrepancy, it seems to vary randomly between +0.25 and -0.25.

I get around this in user interfaces by only ever displaying the font size as a rounded whole number, but I swear that I have seen word processing/DTP packages that allow users to select fractional font sizes - and these packages do not show the above behaviour when interacting with Windows font dialog boxes.

Can anyone provide a rational explanation for this? Is there a best practice technique for displaying the font size in a UI? How about when the user wants a fractional size such as '10.5'?

解决方案

there is no pattern in the discrepancy

As you can see, font sizes happen in increments of 0.75.

Edit: You can fine tune sizes if you do not use the font dialog, but the results I suspect will be less pleasing than the 'preferred' sizes.