We help IT Professionals succeed at work.

How to find available sizes of a given font?

czechmate
czechmate asked
on
Hi, I want to display font sizes (in a combo) that are
available to a particular font.  I looked in Borland
RichEdit demo, they use this function to enumerate fonts:

function EnumFontsProc(var LogFont: TLogFont; var TextMetric: TTextMetric;
  FontType: Integer; Data: Pointer): Integer; stdcall;
begin
  TStrings(Data).Add(LogFont.lfFaceName);
  Result := 1;
end;

To increase or decrease a font size they use UpDown
linked to Edit and assign new size to

CurrText.Size:=StrToInt(Edit.Text);

CurrText, in turn, is implemented like this:

function TMainForm.CurrText: TTextAttributes;
begin
  if Editor.SelLength > 0 then
     Result := Editor.SelAttributes
  else
     Result := Editor.DefAttributes;
end;

UpDown value changes in steps of 1 and that does not
work very well.  Certain sizes produce no visible change,
simply (I think) because a particular font size is not
available.


So when user selects different font how can I get the
available sizes?  I am using Delphi 5.

Regards
cj

Comment
Watch Question

Why dont use the FontDialog.

Drop a FontDialog, palette Dialogs in a Form

and a Button with this code on the OnClick event:
fontdialog1.Execute;


Maybe with this it is enough



Most applications don't enumarate the fonts, but instead put some numbers themselves. Now when you click you change the font size to whatever in the combo box. You can notice that effect in WordPad, and even Microsoft Word.

So simply put the font sizes that you'd like to see, as well as a font dialog so they can manipulate the font further more.

Usually the size start at about 8 and end at about 72 or so. Those are not enumarated but are simply added during construction of the apps.
I meant to say don't enumerate the font sizes, they DO enumarate the fonts.
Mohammed NasmanSoftware Developer
BRONZE EXPERT

Commented:
Hello
  the true type fonts can be resize to any size even more than 300 or 400, but with windows there some fonts not true type and with limit size like "MS Sans Serif" this font has a limit size from 8 to 24, and if you resize it to more than that, they font will not show well, so if you want fonts to be resized, choose true type like arial or times new roman
if you want to list all availbe fonts in ur system, use screen.fonts as :

  ListBox1.Items := Screen.Fonts;

to check if the font is true type or not, see this link, it's for simonet one of the experts in delphi area
http://www.bhnet.com.br/~simonet/tipstricks/truetype.htm
Commented:
Go to http://www.lmc-mediaagentur.de/dpool.htm. Select SEARCH and type font .

At 34th position you can see next tip :
How to enum font sizes like TFontDialog does.  

I don't put here the tip , I wish to respect the author .        

Commented:
I put again the URL because the '.' return a rong address .

 http://www.lmc-mediaagentur.de/dpool.htm

Commented:
Sorry... me agin .
Go to SEARCH ... choice TIPS ONLY ... type 'font' in search combo . Then select 34th result .

Author

Commented:
Thanks guys for the words of wisdom:)  Looks like
Viktornet and Mnasman are right in saying the sizes are
determined by the app, however that seems to apply to TT
fonts only.  For raster fonts, the algo Ginsonic pointed
me to actually does the job.  So I am having hard time
deciding who gets the points:))

Any ideas?

Author

Commented:
And the points go to ginsonic.  Thanks for the tip,
cj

Explore More ContentExplore courses, solutions, and other research materials related to this topic.