List of available font size for selected font

   I would appreciate any advice how can I find out list of available font sizes for selected font.
Who is Participating?
You need to use EnumFontFamilies.  Note that the question is only meaningful for non-TrueType fonts because TrueType fonts will scale to any size.  Most applications offer 8, 9, 10, 11, 12, 14, 16, 18, 20, 22, 24, 26, 28, 36, 48, 72 as the available sizes for TrueType fonts, but also let you type in an arbitrary size.

Here's some code that prints the available sizes of the Courier font:

/* eefontsizes.c */
/* cl eefontsizes.c -link user32.lib gdi32.lib */

#include "windows.h"

#define PIXELS_PER_INCH 96

int CALLBACK FontProc(ENUMLOGFONT* EnumLogFont, NEWTEXTMETRIC* newTextMetric, int Type, LPARAM lParam)
   /* (Type & RASTER_FONTTYPE) is non-zero for non-scalable fonts. */
   /* The +36 allows for rounding errors. */
   printf("  %d pixels\n", (newTextMetric->ntmCellHeight * 72 + 36) / PIXELS_PER_INCH);
   return 1;

int main(void)
   HDC screenDC = CreateCompatibleDC(NULL);
   printf("Sizes for Courier:\n");
   EnumFontFamilies(screenDC, "Courier", (FONTENUMPROC) FontProc, 0);
   return 0;

gelbertAuthor Commented:
       I am looking how to get list of available sizes for specific font without showing "Font" dialog. I have a toolbar where I let user select font name and font size. I need to display actually available font sizes for selected font.
Ykikes - I've just spotted an error there.  The output should say "points", not "pixels".  Pixels are what newTextMetric->ntmCellHeight contains - the expression with the 72 in it is converting from pixels to points.
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.