Articles   Members Online:
-Article/Tip Search
-News Group Search over 21 Million news group articles.
Member Area
-Account Center
-Top 10 NEW!!
-Submit Article/Tip
-Forums Upgraded!!
-My Articles
-Edit Information
-Become a Member
-Why sign up!
-Chat Online!
-Indexes NEW!!
-Build your resume
-Find a job
-Post a job
-Resume Search
-Link to us
Visit Embarcadero
Embarcadero Community
How to use all the capabilities of windows fonts? 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
Delphi 3.x
User Rating
No Votes
# Votes
DSP, Administrator
Reference URL:
			Author: Fernando Silva

TFont doesn't give you all the capabilities of Windows fonts when you need to draw 
some text.
This is because the mechanism TFont uses differs from the one Windows have.


TFont is a descent of TGraphicsObject. This is the abstract base class for objects 
which encapsulate a system graphics object: TBrush, TFont, and TPen.
Internally TFont uses the TFontData record to keep track of all changes to our font.

While TFontData structure is like this:

1   TFontData = record
2     Handle: HFont;
3     Height: Integer;
4     Pitch: TFontPitch;
5     Style: TFontStylesBase;
6     Charset: TFontCharset;
7     Name: TFontDataName;
8   end;

windows LogFont structure defines the following attributes of a font:

9   tagLOGFONTA = packed record
10    lfHeight: Longint;
11    lfWidth: Longint;
12    lfEscapement: Longint;
13    lfOrientation: Longint;
14    lfWeight: Longint;
15    lfItalic: Byte;
16    lfUnderline: Byte;
17    lfStrikeOut: Byte;
18    lfCharSet: Byte;
19    lfOutPrecision: Byte;
20    lfClipPrecision: Byte;
21    lfQuality: Byte;
22    lfPitchAndFamily: Byte;
23    lfFaceName: array[0..LF_FACESIZE - 1] of AnsiChar;
24  end;
26  TLogFontA = tagLOGFONTA;
27  TLogFont = TLogFontA;

you can already see the difference between both. Anyway, while trying to simplify 
the process Delphi team forgot to add to TFontData : lfEscapment, lfOrientation 
(with the two we can rotate a font) and lfQuality (this one give us the possibility 
of drawing an antialised font).

When you call TextOut, internally when the draw text routine gets the handle for 
the font to be used with the windows API ExtTextOut, TFont maps the TFont structure 
to windows logfont structure (much like the way I did the DrawText routine forward).

In TFont.GetHandle we see the following:

28  (...split...)
29  lfEscapement := 0; { only straight fonts }
30  lfOrientation := 0; { no rotation }
31  (...split...)
32  lfQuality := DEFAULT_QUALITY;
33  (...split...)

so... they didn't want to code just a little more :)

I thougth about changing (or even extending) TFont class to have these two 
properties available, anyway (if someone is interested I could do that) I'll just 
present here a routine that can draw some text (rotated and with more quality).
35  procedure DrawText(ACanvas: TCanvas; AAngle: Integer; AQuality: byte; X, Y: Integer;
36    AText: string);
37  var
38    lf: TLogFont;
40  begin
41    with ACanvas do
42    begin
43      GetObject(Font.Handle, SizeOf(lf), @lf);
44      with lf do
45      begin
46        lfQuality := AQuality;
47        lfOrientation := AAngle * 10;
48        lfEscapement := lfOrientation;
49      end;
50      Font.Handle := CreateFontIndirect(lf);
51      TextOut(X, Y, AText);
52    end;
53  end;

AQuality can be :
 Appearance of the font does not matter.
 Appearance of the font is less important than when PROOF_QUALITY is used. For GDI 
raster fonts, scaling is enabled, which means that more font sizes are available, 
but the quality may be lower. Bold, italic, underline, and strikeout fonts are 
synthesized if necessary.
 Character quality of the font is more important than exact matching of the 
logical-font attributes. For GDI raster fonts, scaling is disabled and the font 
closest in size is chosen. Although the chosen font size may not be mapped 
 exactly when PROOF_QUALITY is used, the quality of the font is high and there is 
no distortion of appearance. Bold, italic, underline, and strikeout fonts are 
synthesized if necessary.


Note: Remember that the 3 attributes just work with True Type Fonts.

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


Share this page
Download from Google

Copyright © Mendozi Enterprises LLC