1

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?

jedivader
  • 828
  • 10
  • 23

1 Answers1

2

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.

David Heffernan
  • 601,492
  • 42
  • 1,072
  • 1,490
  • So, you're saying it's not possible? I don't expect to be able to set different anti-aliasing to different parts of the text, but surely they (Microsoft) could (and should) have easily implemented a way to set the global anti-aliasing of the entire control (and that's what I want to do). It's obviously not fixed, as it respects the system settings, so why not just let the programmers be able to set it themselves? If they really didn't implement a way, that's a big miss on their part. – jedivader Mar 18 '14 at 18:00
  • @jedi - Find all about rich edit [here](http://msdn.microsoft.com/en-us/library/bb787605%28v=vs.85%29.aspx). – Sertac Akyuz Mar 18 '14 at 19:02
  • @Sertac if I had found something on this issue on msdn, I would not have asked the question. If you have found something about anti-aliasing there, then please, do share the exact link. – jedivader Mar 19 '14 at 11:27
  • @jedi - No, I posted the link as an evidence that rich edit does not have any explicit support for font quality. It should be obvious that it would need explicit support since it have the capability to render different fonts and hence a `WM_SETFONT` is not deterministic like other controls. – Sertac Akyuz Mar 19 '14 at 11:38
  • @Sertac Yeah, seems like I'm stuck. – jedivader Mar 19 '14 at 12:07