Solved

List of available font size for selected font

Posted on 2004-10-20
4
227 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

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

If you have ever found yourself doing a repetitive action with the mouse and keyboard, and if you have even a little programming experience, there is a good chance that you can use a text editor to whip together a sort of macro to automate the proce…
This article describes a technique for converting RTF (Rich Text Format) data to HTML and provides C++ source that does it all in just a few lines of code. Although RTF is coming to be considered a "legacy" format, it is still in common use... po…
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…

708 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

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now