0

I call GetTextMetrics on a fixed width font (Consolas).

I expected to see tmAveCharWidth == tmMaxCharWidth but no, they have different values. So which is the correct one?

I know I could just guess and use the one that seems correct, but that's not really a good plan given that I might get different results if I choose other fonts.

Here is what I have:

enter image description here

Armen Michaeli
  • 8,625
  • 8
  • 58
  • 95
pm100
  • 48,078
  • 23
  • 82
  • 145
  • Can you post your code in the form of a [mre]? – Ken White Oct 02 '20 at 00:50
  • Related: https://learn.microsoft.com/en-us/windows/win32/gdi/string-widths-and-heights – Jerry Jeremiah Oct 02 '20 at 00:51
  • Does this help? https://stackoverflow.com/questions/1126730/how-to-find-the-width-of-a-string-in-pixels-in-win32 or https://stackoverflow.com/questions/17222825/winapi-get-string-width-in-pixels – Jerry Jeremiah Oct 02 '20 at 00:52
  • @JonathanPorter - that would not explain the difference 9..19 – Vlad Feinstein Oct 02 '20 at 00:59
  • @KenWhite the dupe says its caused by cleartype. Not sure what that means or how it helps. Cannot show my code becuase this is now closed - sigh – pm100 Oct 02 '20 at 01:06
  • @JerryJeremiah thats telling me to do what I am doing. – pm100 Oct 02 '20 at 01:07
  • anyway - I just used ave width and its fine – pm100 Oct 02 '20 at 01:08
  • ClearType is the Windows functionaltiy that tries to smooth fonts to remove the pixelation on curves on higher resolution screens. Google ClearType. – Ken White Oct 02 '20 at 01:10
  • You have to take into account that CJK (Chinese, Japanese and Korean) graphic characters can be classed into fullwidth and halfwidth characters with differing widths. Emoji are also known for using nonstandard widths even for fixed pitch fonts. Treating all fonts as proportional (by measuring widths with API calls) solves most of the problems, unless you are forced to work with fixed grid of characters. – Daniel Sęk Oct 02 '20 at 10:47
  • @DanielSęk I am working with a fixed grid – pm100 Oct 02 '20 at 13:57

0 Answers0