Article View: borland.public.delphi.nativeapi
Article #12198Re: Windows Fonts
From: Ben Hochstrasser
Date: Sat, 23 Nov 2002 13:15
Date: Sat, 23 Nov 2002 13:15
47 lines
2104 bytes
2104 bytes
Camiel Wijffels wrote:
> It is possible - many professional packages
> (like WP, Word and CorelDraw) have this ability.
Those programs usually choose a font size so that the resulting text is a
bit less wide than required. Then they simply enlarge the letter spacing
until it fits.
Note that no algorithm will replace a seasoned typographer, as e.g. the
spacing between 'T' and 'o' should be less expanded than between 'm' and
'n'. This is of course less true for displays than it is for printed
stuff.
Here's a simple example: Place a TEdit, a TPanel and a button on a form.
Choose some font for the Panel caption. Enter some text in the Edit Box.
Press the button.
procedure TForm1.Button1Click(Sender: TObject);
var
i: integer;
w: integer;
lbl: TLabel;
begin
i := 8;
lbl := TLabel.Create(Form1);
lbl.Parent := Form1;
lbl.Visible := false;
lbl.AutoSize := True;
lbl.Caption := Edit1.Text;
lbl.Font := Panel1.Font;
repeat
inc(i);
lbl.Font.Size := i;
w := lbl.Canvas.TextWidth(lbl.caption);
until w > Panel1.ClientWidth;
dec(i);
Panel1.Caption := lbl.Caption;
Panel1.Font.Size := i;
lbl.Free;
end;
The detour via the TLabel component is necessary for all controls that do
not have a Canvas property.
--
Ben
Technical Details
Message-ID:
<Xns92CF90F79DFC8bhoc@207.105.83.65>Path:
arc1-ca.pugleaf.net!archiver1.google.com!news1.google.com!sn-xit-03!sn-xit-01!sn-xit-08!supernews.com!newsfeed.online.be!feedme.news.mediaways.net!news.uni-x.net!newsgroups.borland.com!not-for-mailReferences:
<3dde62a7@newsgroups.borland.com>Show Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: f94dd,cd35213a00f4b682 X-Google-Attributes: gidf94dd,public X-Google-ArrivalTime: 2002-11-23 05:16:07 PST Newsgroups: borland.public.delphi.nativeapi Subject: Re: Windows Fonts From: Ben Hochstrasser <bhoc@surfeu123^H^H^H.ch> References: <3dde62a7@newsgroups.borland.com> Organization: Huh? Message-ID: <Xns92CF90F79DFC8bhoc@207.105.83.65> User-Agent: Xnews/5.04.25 NNTP-Posting-Host: 217.162.192.226 Date: 23 Nov 2002 05:15:04 -0800 X-Trace: newsgroups.borland.com 1038057304 217.162.192.226 (23 Nov 2002 05:15:04 -0800) Lines: 47 Path: arc1-ca.pugleaf.net!archiver1.google.com!news1.google.com!sn-xit-03!sn-xit-01!sn-xit-08!supernews.com!newsfeed.online.be!feedme.news.mediaways.net!news.uni-x.net!newsgroups.borland.com!not-for-mail