Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

List of available font size for selected font

Posted on 2004-10-20
4
Medium Priority
?
296 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 500 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

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

Question has a verified solution.

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

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…
zlib is a free compression library (a DLL) on which the popular gzip utility is built.  In this article, we'll see how to use the zlib functions to compress and decompress data in memory; that is, without needing to use a temporary file.  We'll be c…
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…

810 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