Recent

Author Topic: Blurry text on TLabel's  (Read 1091 times)

jdp1024

  • Newbie
  • Posts: 5
Blurry text on TLabel's
« on: July 01, 2025, 03:29:59 pm »
In Lazarus 4.0 + Windows 11 64-bit, DPI=144 (150% scale), all text in TLabels are blurry while sharp in TStaticText and all other controls.

This screenshot is taken from a dummy form without any code. Just 2 TLables and 2 TStaticText in different sizes.
« Last Edit: July 01, 2025, 03:31:45 pm by jdp1024 »

wp

  • Hero Member
  • *****
  • Posts: 13646
Re: Blurry text on TLabel's
« Reply #1 on: July 02, 2025, 12:37:57 am »
I cannot reproduce this effect... Although your description reads simple there are still open questions: What are the scaling settings used? For simplicity please post a compilable project which demonstrates the issue. Pack .pas, .lfm, .lpr, and .lpi files together into a zip which you can upload here under "Attachments and other options". Do not include any compiler-generated files in the zip.

jdp1024

  • Newbie
  • Posts: 5
Re: Blurry text on TLabel's
« Reply #2 on: July 02, 2025, 06:02:26 am »
I think I found the problem.

In customlabel.inc,

procedure TCustomLabel.DoDrawText(var Rect: TRect; Flags: Longint);
...
begin
...
  TextOut(Canvas.Handle, 0,0,PChar(LabelText), Length(LabelText));
  DrawText(Canvas.Handle, PChar(LabelText), Length(LabelText), Rect, Flags or DT_NOCLIP);
  Canvas.Font.Color := OldFontColor;
end;

There is a TextOut call before the DrawText call. So the text is actually drawn 3 times:

(1) DoDrawText called with DT_CALCRECT, TextOut is called, and DrawText is used to calculate the rectangle.

(2) DoDrawText called without DT_CALCRECT, TextOut is called, then

(3) DrawText is called to draw the text.

I removed the TextOut call, and the TLabel looks fine.
« Last Edit: July 02, 2025, 06:03:57 am by jdp1024 »

jdp1024

  • Newbie
  • Posts: 5
Re: Blurry text on TLabel's
« Reply #3 on: July 02, 2025, 06:09:59 am »
I cannot reproduce this effect... Although your description reads simple there are still open questions: What are the scaling settings used? For simplicity please post a compilable project which demonstrates the issue. Pack .pas, .lfm, .lpr, and .lpi files together into a zip which you can upload here under "Attachments and other options". Do not include any compiler-generated files in the zip.

I also found this problem can be only reproduced in some AMD integrated display cards like my AMD Radeon. All my Intel and nvidia cards don't have this problem.

440bx

  • Hero Member
  • *****
  • Posts: 6572
Re: Blurry text on TLabel's
« Reply #4 on: July 02, 2025, 06:48:15 am »
I also found this problem can be only reproduced in some AMD integrated display cards like my AMD Radeon. All my Intel and nvidia cards don't have this problem.
In that case, have you tried upgrading the video card driver ?... if it's a driver problem, upgrading may get rid of it.
FPC v3.2.2 and Lazarus v4.0rc3 on Windows 7 SP1 64bit.

wp

  • Hero Member
  • *****
  • Posts: 13646
Re: Blurry text on TLabel's
« Reply #5 on: July 02, 2025, 09:48:46 am »
There is a TextOut call before the DrawText call.
Really? This is the original Laz-4.0 code of TCustomlabel.DoDraw - no TextOut:
Code: Pascal  [Select][+][-]
  1. procedure TCustomLabel.DoDrawText(var Rect: TRect; Flags: Longint);
  2. var
  3.   LabelText: string;
  4.   OldFontColor: TColor;
  5.   Rect2: TRect;
  6. begin
  7.   LabelText := GetLabelText;
  8.   OldFontColor := Canvas.Font.Color;
  9.   if not IsEnabled and (Flags and DT_CALCRECT = 0) then
  10.     if ThemeServices.ThemesEnabled then
  11.       Canvas.Font.Color := clGrayText
  12.     else
  13.     begin
  14.       Canvas.Font.Color := clBtnHighlight;
  15.       Rect2 := Rect;
  16.       Types.OffsetRect(Rect2, 1, 1);
  17.       DrawText(Canvas.Handle, PChar(LabelText), Length(LabelText), Rect2, Flags);
  18.       Canvas.Font.Color := clBtnShadow;
  19.     end;
  20.   DrawText(Canvas.Handle, PChar(LabelText), Length(LabelText), Rect, Flags or DT_NOCLIP);
  21.   Canvas.Font.Color := OldFontColor;
  22. end;
Maybe you added that TextOut yourself and forgot about it? One of the most typical bugs added by myself...

jdp1024

  • Newbie
  • Posts: 5
Re: Blurry text on TLabel's
« Reply #6 on: July 02, 2025, 11:13:57 am »
You are right, I checked against the git version. I have totally no clue when this line was added.  >:D


Nicole

  • Hero Member
  • *****
  • Posts: 1324
Re: Blurry text on TLabel's
« Reply #7 on: July 02, 2025, 03:18:25 pm »
Probably this is not the case in this case:
I found this effect by having changed the size of something by mistake by a few pixels. The effect was alike.
Setting back the "original" size helped.

Just want to mention if anybody has the same problem: Double-check the item's size parameters.

 

TinyPortal © 2005-2018