如何确定 Windows 上的“最窄”字体?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/1807640/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How do I determine the "narrowest" font on Windows?
提问by René Nyffenegger
I am looking for a way to find the font that uses the least average horizontal space per letter, since I have a few buttons in my application that need to show a rather long text in it, and the goal is to make the buttons with the minimal width necessary.
我正在寻找一种方法来找到每个字母使用最少平均水平空间的字体,因为我的应用程序中有几个按钮需要在其中显示相当长的文本,目标是使按钮具有所需的最小宽度。
Since I already know the environment where the application is going to be installed, the solution needs not necessarily be a script or program, it is sufficient for me to have the font at design time.
由于我已经知道应用程序将要安装的环境,因此解决方案不一定是脚本或程序,我在设计时拥有字体就足够了。
For what it is worth, it is going to be an ms-Access application.
就其价值而言,它将是一个 ms-Access 应用程序。
采纳答案by bobince
I don't think you really want the absolute narrowest font, as that may well be some kind of symbol/utility font which may not actually contain real characters. Certainly on my system here the ‘narrowest' font would be one that contains almost no Latin characters, making the width of the string rendered in it almost zero!
我不认为你真的想要绝对最窄的字体,因为这很可能是某种符号/实用字体,实际上可能不包含真正的字符。当然,在我的系统上,“最窄”字体将是一种几乎不包含拉丁字符的字体,这使得在其中呈现的字符串的宽度几乎为零!
Arial Narrow is installed by Office, so that would seem a reasonable choice for an Access application. If you want narrower than that I think you'd have to bundle a particular font of your own.
Arial Narrow 是由 Office 安装的,因此对于 Access 应用程序来说,这似乎是一个合理的选择。如果你想要比这更窄,我认为你必须捆绑你自己的特定字体。
回答by DisgruntledGoat
Can't believe this hasn't been mentioned yet: just reduce the amount of text on the buttons!
不敢相信这还没有被提及:只需减少按钮上的文字数量!
If you need to put a sentence on a button then You're Doing It Wrong. You should have one or two words, preferably with the action the user will do (as opposed to OK/Cancel). You can use the dialog for a more specific description of what each action entails, if necessary.
如果您需要在按钮上放置一个句子,那么您就错了。您应该有一个或两个词,最好是用户将执行的操作(而不是确定/取消)。如有必要,您可以使用该对话框更具体地描述每个操作的含义。
Not to mention a narrower font makes the text harder to read anyway, however much there is.
更不用说更窄的字体会使文本更难阅读,无论有多少。
回答by erikkallen
Try to enumerate all fonts, measuring "The quick brown fox jumped over the lazy dog" with each one and then take the one that occupies the least space.
尝试枚举所有字体,将“The quick brown fox jumped over the lazy dog”每一种都进行测量,然后选择占用空间最少的一种。
This linkexplains how to enumerate fonts
此链接解释了如何枚举字体
This linkexplains how to measure strings
此链接解释了如何测量字符串
回答by Adrian McCarthy
I'm just answering the question without any comment on whether it's a good idea or the right solution for your problem.
我只是回答这个问题,对它是否是一个好主意或对您的问题的正确解决方案没有任何评论。
- Enumerate the fonts.
- For each font, instantiate it, select it into the DC, and use call
GetTextMetrics
. - Check the
tmAveCharWidth
field of the metrics structure. If it's smaller than the smallest found so far, remember it and the font. - Select the font out of the DC and destroy it.
- Recreate the font with the smallest average character width and use it.
- 枚举字体。
- 对于每种字体,将其实例化,将其选择到 DC 中,然后使用 call
GetTextMetrics
。 - 检查
tmAveCharWidth
指标结构的字段。如果它比目前发现的最小的要小,记住它和字体。 - 从 DC 中选择字体并将其销毁。
- 重新创建具有最小平均字符宽度的字体并使用它。
回答by PhiLho
Just get some font viewer application like AMP Font Viewer. They often offer an option to list all installed fonts displayed with an arbitrary string with the font itself.
只需获取一些字体查看器应用程序,例如 AMP Font Viewer。他们通常提供一个选项来列出所有已安装的字体,并带有字体本身的任意字符串。
On my system, I see lot of fonts (non standard) narrower than Arial Narrow. Like the well known Haettenschweiler, or a number of "condensed" fonts.
在我的系统上,我看到很多字体(非标准)比 Arial Narrow 窄。像众所周知的 Haettenschweiler,或一些“浓缩”字体。
回答by YOU
If me, I will use Arial Narrow
如果我,我会用 Arial Narrow