Solved

List of available font size for selected font

Posted on 2004-10-20
4
264 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

Instantly Create Instructional Tutorials

Contextual Guidance at the moment of need helps your employees adopt to new software or processes instantly. Boost knowledge retention and employee engagement step-by-step with one easy solution.

Question has a verified solution.

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

This article shows how to make a Windows 7 gadget that extends its U/I with a flyout panel -- a window that pops out next to the gadget.  The example gadget shows several additional techniques:  How to automatically resize a gadget or flyout panel t…
For most people, the WrapPanel seems like a magic when they switch from WinForms to WPF. Most of us will think that the code that is used to write a control like that would be difficult. However, most of the work is done by the WPF engine, and the W…
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…

691 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