Solved

List of available font size for selected font

Posted on 2004-10-20
4
236 Views
Last Modified: 2013-12-03
Hi!
   I would appreciate any advice how can I find out list of available font sizes for selected font.
 
0
Comment
Question by:gelbert
  • 2
4 Comments
 
LVL 48

Expert Comment

by:Mikal613
ID: 12364829
0
 
LVL 8

Author Comment

by:gelbert
ID: 12369373
       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.
0
 
LVL 14

Accepted Solution

by:
RichieHindle earned 125 total points
ID: 12370855
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);
   DeleteDC(screenDC);
   return 0;
}


0
 
LVL 14

Expert Comment

by:RichieHindle
ID: 12378452
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.
0

Featured Post

PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article describes how to add a user-defined command button to the Windows 7 Explorer toolbar.  In the previous article (http://www.experts-exchange.com/A_2172.html), we saw how to put the Delete button back there where it belongs.  "Delete" is …
Entering time in Microsoft Access can be difficult. An input mask often bothers users more than helping them and won't catch all typing errors. This article shows how to create a textbox for 24-hour time input with full validation politely catching …
This is Part 3 in a 3-part series on Experts Exchange to discuss error handling in VBA code written for Excel. Part 1 of this series discussed basic error handling code using VBA. http://www.experts-exchange.com/videos/1478/Excel-Error-Handlin…
Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…

770 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question