Recent

Author Topic: How to turn off Antialiasing at TCanvas.TextOut()?  (Read 616 times)

gasensor

  • Jr. Member
  • **
  • Posts: 78
How to turn off Antialiasing at TCanvas.TextOut()?
« on: November 29, 2024, 06:55:24 am »
How to turn off Antialiasing at TCanvas.TextOut()?

I tried:
Code: Pascal  [Select][+][-]
  1. xxx := TCustomBitmap.Create();
  2. xxx.Canvas.Font.Quality:= fqDraft;
  3. xxx.Canvas.AntialiasingMode:=amOff;  

None of them worked. It can only be turned off in the operating system.

Lazarus: 4.0.0RC1/3.4.0
FPC: 3.2.2
OS: Linux MX 23.3 (x86_64)

paweld

  • Hero Member
  • *****
  • Posts: 1268
Re: How to turn off Antialiasing at TCanvas.TextOut()?
« Reply #1 on: November 29, 2024, 10:40:20 am »
Font.Quality
Code: Pascal  [Select][+][-]
  1. procedure TForm1.Button1Click(Sender: TObject);
  2. var
  3.   bmp: TBitmap;
  4. begin
  5.   bmp := TBitmap.Create;
  6.   bmp.SetSize(100, 100);
  7.   bmp.Canvas.Font.Size := 32;
  8.   bmp.Canvas.Font.Quality := fqNonAntialiased;
  9.   bmp.Canvas.TextOut(1, 0, 'T3$t');
  10.   Canvas.CopyRect(Rect(100, 100, 200, 200), bmp.Canvas, Rect(0, 0, 100, 100));
  11.   bmp.Free;
  12. end;  
  13.  
Best regards / Pozdrawiam
paweld

gasensor

  • Jr. Member
  • **
  • Posts: 78
Re: How to turn off Antialiasing at TCanvas.TextOut()?
« Reply #2 on: November 30, 2024, 08:12:45 am »
@paweld TKS
I tested it in detail and it didn't work. Attached is a screenshot of my test. Enlarge the output image and you will see that Antialias still works.

The Antialias technology is called ClearType on the win platform and is a sub-pixel rendering technology. But in my application, this technique can cause problems instead.

Test Code:
Code: Pascal  [Select][+][-]
  1. procedure TForm1.Button1Click(Sender: TObject);
  2. var
  3.   bmp: TBitmap;
  4. begin
  5.   //Init
  6.   bmp := TBitmap.Create;
  7.   bmp.SetSize(40, 20);
  8.   //Clear
  9.   bmp.Canvas.Brush.Color:=clWhite;
  10.   bmp.Canvas.FillRect(0,0,40,20);
  11.   //Font setting
  12.   bmp.Canvas.Font.Size := 12;
  13.   bmp.Canvas.Font.Quality := fqNonAntialiased;
  14.   //Draw Text
  15.   bmp.Canvas.TextOut(0, 0, 'T3$t');
  16.   //Enlarge
  17.   Canvas.CopyRect(Rect(0, 0, 400, 200), bmp.Canvas, Rect(0, 0, 40, 20));
  18.   //Raw
  19.   Canvas.CopyRect(Rect(0, 200, 40, 220), bmp.Canvas, Rect(0, 0, 40, 20));
  20.   bmp.Free;
  21. end;
  22.  

paweld

  • Hero Member
  • *****
  • Posts: 1268
Re: How to turn off Antialiasing at TCanvas.TextOut()?
« Reply #3 on: November 30, 2024, 08:39:32 am »
Hi,

I'll admit that I only checked on Windows, and it works there. On Linux, on the other hand, there is indeed a problem, and from what I found on the Internet it is a system setting that fonts have anti-aliasing enabled, and only you can turn it off in the fonts.config file (preferably in the user configuration) depending on the font name and/or size or other parameters - : https://wiki.archlinux.org/title/Font_configuration/Examples/No_anti-aliasing   

Important: this applies to the whole system
Best regards / Pozdrawiam
paweld

 

TinyPortal © 2005-2018