Search code examples
windowswinapifontsmonospace

Find out if font has monospaced numbers


There are proportional fonts (i.e. not monospaced) that nevertheless provide monospaced numbers. E.g. see this Excel screenshot using Arial:

Excel screenshot

Note how the numbers are nicely aligned. How can I find out programmatically (probably WinAPI) if a font supports this feature?


Solution

  • You won't find an API for that because there isn't any specific metadata value within the font file to indicate "the glyphs for digits in this font have fixed width". Some fonts may support both proportional and fixed-width ("lining") digits, in which case the font is likely to support the 'lnum' OpenType Layout feature. You should pick a font that supports this feature and then explicitly activate that feature when drawing the text.