jedivader
jedivader

Reputation: 847

How to change the font smoothing (anti-aliasing) quality of a RichEdit in Delphi?

I have a Delphi 7 application where I'm drawing text to a TBitmap. I need to be able to control the anti-aliasing quality of the text. For this purpose I'm using the following procedure:

procedure SetFontQuality(Font: TFont; Quality: Byte);
var
  lf: TLogFont;
begin
  GetObject(Font.Handle, SizeOf(TLogFont), @lf);
  lf.lfQuality := Quality;
  Font.Handle := CreateFontIndirect(lf);
end;

I'm calling it for my TBitmap like this: SetFontQuality(MyBitmap.Canvas.Font, ANTIALIASED_QUALITY). The goal here is to set the old anti-aliasing instead of the new ClearType one. This works great, if I'm using DrawText to draw the text on the TBitmap. However, I need to draw the text of a TRichEdit on it, so I'm using EM_FORMATRANGE for this purpose. But the text is drawn with whatever my Windows anti-aliasing is (so if I enable ClearType in Windows, it is ClearType, even if I set the old anti-aliasing with ANTIALIASED_QUALITY).

I suppose I need to change the font quality of the TRichEdit, so I applied the procedure to it: SetFontQuality(MyRichEdit.Font, ANTIALIASED_QUALITY), but that didn't change things.

I did a little bit of testing - I tried applying the procedure to the Font property of various controls - TButton, TMemo, TEdit, TLabel. It works like a charm on all of them. But when applied to a TRichEdit's Font property, the anti-aliasing doesn't change.

So, my question is: how do I change the anti-aliasing quality of a TRichEdit control?

Upvotes: 1

Views: 1786

Answers (1)

David Heffernan
David Heffernan

Reputation: 612934

A Delphi TRichEdit control is a loose wrapper around the native Windows rich edit control. The Windows rich edit control is based on the RTF standard. The content of the rich edit control can have different font properties for different parts of the text. The RTF standard, however, does not cover anti-aliasing. Thus you cannot apply an anti-aliasing setting to individual parts of the text. The control therefore uses the system setting to determine anti-aliasing.

Upvotes: 2

Related Questions