Articles   Members Online:
-Article/Tip Search
-News Group Search over 21 Million news group articles.
-Delphi/Pascal
-CBuilder/C++
-C#Builder/C#
-JBuilder/Java
-Kylix
Member Area
-Home
-Account Center
-Top 10 NEW!!
-Submit Article/Tip
-Forums Upgraded!!
-My Articles
-Edit Information
-Login/Logout
-Become a Member
-Why sign up!
-Newsletter
-Chat Online!
-Indexes NEW!!
Employment
-Build your resume
-Find a job
-Post a job
-Resume Search
Contacts
-Contacts
-Feedbacks
-Link to us
-Privacy/Disclaimer
Embarcadero
Visit Embarcadero
Embarcadero Community
JEDI
Links
How to enum font sizes like TFontDialog does Turn on/off line numbers in source code. Switch to Orginial background IDE or DSP color Comment or reply to this aritlce/tip for discussion. Bookmark this article to my favorite article(s). Print this article
12-Oct-02
Category
Dialogs
Language
Delphi 2.x
Views
88
User Rating
No Votes
# Votes
0
Replies
0
Publisher:
DSP, Administrator
Reference URL:
DKB
			Author: Jonas Bilinkevicius

I would like to get all font sizes for the given font like TFontDialog does. 
Minimum and maximum font size would be nice, too.

Answer:

Note that the list of font sizes for Truetype fonts is just an arbitrary selection 
of often-used sizes, you can scale these fonts to nearly any size.

Example for the use of EnumFontFamilies. Project requires two listboxes on the 
form, nothing else.

1   unit Unit1;
2   
3   interface
4   
5   uses
6     Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs, 
7   StdCtrls;
8   
9   type
10    TForm1 = class(TForm)
11      ListBox1: TListBox;
12      ListBox2: TListBox;
13      procedure FormCreate(Sender: TObject);
14      procedure ListBox1Click(Sender: TObject);
15    private
16      { Private declarations }
17    public
18      { Public declarations }
19    end;
20  
21  var
22    Form1: TForm1;
23  
24  implementation
25  
26  {$R *.DFM}
27  
28  procedure TForm1.FormCreate(Sender: TObject);
29  begin
30    listbox1.items.assign(screen.fonts);
31  end;
32  
33  function EnumProc(var elf: TEnumLogFont; var ntm: TNewTextmetric;
34    fonttype: Integer; listbox: TListbox): Integer; stdcall;
35  var
36    S: string;
37  begin
38    if fonttype = TRUETYPE_FONTTYPE then
39    begin
40      listbox.Items.Add(Format('Name: %s', [elf.elfFullName]));
41      listbox.Items.Add(Format('Style: %s', [elf.elfStyle]));
42    end
43    else
44      listbox.Items.Add(Format('Name: %s', [elf.elfLogfont.lfFacename]));
45    listbox.Items.Add(Format('Size: %d', [elf.elfLogFont.lfHeight]));
46    listbox.Items.Add(Format('Weight: %d', [elf.elfLogFont.lfWeight]));
47    if elf.elfLogFont.lfItalic <> 0 then
48      listbox.Items.Add('This font is italic');
49    case fonttype of
50      DEVICE_FONTTYPE: S := 'device font';
51      RASTER_FONTTYPE: S := 'raster font';
52      TRUETYPE_FONTTYPE: S := 'truetype font'
53    else
54      S := 'unknown font type';
55    end;
56    listbox.Items.Add(Format('This is a %s', [S]));
57    Result := 1;
58  end;
59  
60  procedure TForm1.ListBox1Click(Sender: TObject);
61  begin
62    listbox2.clear;
63    with listbox1 do
64      if ItemIndex >= 0 then
65        EnumFontFamilies(Self.Canvas.Handle, PChar(Items[ItemIndex]),
66          @EnumProc, Longint(listbox2));
67  end;
68  
69  end.


			
Vote: How useful do you find this Article/Tip?
Bad Excellent
1 2 3 4 5 6 7 8 9 10

 

Advertisement
Share this page
Advertisement
Download from Google

Copyright © Mendozi Enterprises LLC