Question

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.

Was it helpful?

Solution

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.

OTHER TIPS

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.

This link explains how to enumerate fonts

This link explains how to measure strings

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.

If me, I will use Arial Narrow

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.

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.

I'm just answering the question without any comment on whether it's a good idea or the right solution for your problem.

  1. Enumerate the fonts.
  2. For each font, instantiate it, select it into the DC, and use call GetTextMetrics.
  3. Check the tmAveCharWidth field of the metrics structure. If it's smaller than the smallest found so far, remember it and the font.
  4. Select the font out of the DC and destroy it.
  5. Recreate the font with the smallest average character width and use it.
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top