Link to home
Start Free TrialLog in
Avatar of czechmate
czechmate

asked on

How to find available sizes of a given font?

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

Avatar of marcoszorrilla
marcoszorrilla

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.
Avatar of Mohammed Nasman
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
ASKER CERTIFIED SOLUTION
Avatar of ginsonic
ginsonic
Flag of Romania image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
I put again the URL because the '.' return a rong address .

 http://www.lmc-mediaagentur.de/dpool.htm
Sorry... me agin .
Go to SEARCH ... choice TIPS ONLY ... type 'font' in search combo . Then select 34th result .
Avatar of czechmate

ASKER

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?
And the points go to ginsonic.  Thanks for the tip,
cj