Recent

Author Topic: Why TBitBtn font rendering so "grayscale"?  (Read 926 times)

tersion

  • New Member
  • *
  • Posts: 11
Why TBitBtn font rendering so "grayscale"?
« on: March 16, 2021, 09:16:48 pm »
Why TBitBtn font rendering so "grayscale"? Here the scaled to 500% print screen image in attachments, with another type of buttons for comparison. For that reason, when look on that type of button in normal 100% scale, it's looks blurry. How to fix that?

engkin

  • Hero Member
  • *****
  • Posts: 2699
Re: Why TBitBtn font rendering so "grayscale"?
« Reply #1 on: March 16, 2021, 09:25:32 pm »
What OS, WS, Laz version, 32 or 64?

tersion

  • New Member
  • *
  • Posts: 11
Re: Why TBitBtn font rendering so "grayscale"?
« Reply #2 on: March 17, 2021, 11:32:08 am »
What OS, WS, Laz version, 32 or 64?
OS - Windows 7 (Pro) 64bit, Lazarus 2.0.12 (with fpc-3.2.0-win32) but recompiled for using BGRAControls controls (installed from Package Manager). Maybe influence of BGRAControls?

wp

  • Hero Member
  • *****
  • Posts: 8402
Re: Why TBitBtn font rendering so "grayscale"?
« Reply #3 on: March 17, 2021, 11:41:12 am »
What is the pixel density of your screen? 100% or larger? Blurry rendering occurs when Windows upscales the controls created at 100%. The correct way to handle this situation in Lazarus is to go to the project options, check "Use LCL scaling" and select "on" in the "DPI awareness" combobox.

To me, however, your screenshots do not look blurred. I get similar images (100% - no scaling), and I can confirm that the TBitBtn has these gray extra pixels unlike TButton and TSpeedbutton.

I do not think that this has anything to do with BGRABitmap because the LCL is rendered by native routines, without BGRABitmap.
« Last Edit: March 17, 2021, 03:11:58 pm by wp »
Mainly Lazarus trunk / fpc 3.2.0 / all 32-bit on Win-10, but many more...

FTurtle

  • Sr. Member
  • ****
  • Posts: 289
Re: Why TBitBtn font rendering so "grayscale"?
« Reply #4 on: March 17, 2021, 12:54:52 pm »
Looks like for TButton and TSpeedButton used ClearType but for TBitBtn used other font smoothing method.

tersion

  • New Member
  • *
  • Posts: 11
Re: Why TBitBtn font rendering so "grayscale"?
« Reply #5 on: March 20, 2021, 12:22:08 pm »
So I decided write to bug-tracker: https://bugs.freepascal.org/view.php?id=38643
Maybe someone can help find, where the rendering method is applied to this component?

tersion

  • New Member
  • *
  • Posts: 11
Re: Why TBitBtn font rendering so "grayscale"?
« Reply #6 on: March 20, 2021, 03:54:38 pm »
Even Lazarus IDE itself using different font smoothing algorithm in project settings, where you can change icon. Look at this four buttons (pic. in attachments). All buttons is TButton type, I've checked through special utility from AutoIt project. Strange that this is happening between buttons of the same class type.

jamie

  • Hero Member
  • *****
  • Posts: 4447
Re: Why TBitBtn font rendering so "grayscale"?
« Reply #7 on: March 20, 2021, 03:59:09 pm »
You know most of the old timers here, including me :o, wouldn't care about that since its not even noticed..

But in your case the difference is between a OS drawing the caption verses the local code pasting it via an image..

Looking at Delphi it looks like it may also have a difference in looks.
The only true wisdom is knowing you know nothing

FTurtle

  • Sr. Member
  • ****
  • Posts: 289
Re: Why TBitBtn font rendering so "grayscale"?
« Reply #8 on: March 20, 2021, 05:01:01 pm »
Even Lazarus IDE itself using different font smoothing algorithm in project settings, where you can change icon. Look at this four buttons (pic. in attachments). All buttons is TButton type, I've checked through special utility from AutoIt project. Strange that this is happening between buttons of the same class type.

1. On your screenshot only one button is TButton, all other - TBitBtn
2. In trunk all of them are TBitBtn. See here:
https://bugs.freepascal.org/view.php?id=34578

wp

  • Hero Member
  • *****
  • Posts: 8402
Re: Why TBitBtn font rendering so "grayscale"?
« Reply #9 on: March 20, 2021, 05:11:49 pm »
2. In trunk all of them are TBitBtn. See here:
https://bugs.freepascal.org/view.php?id=34578
Do you want to say that TButton "is" a TBitBtn, i.e. inherits from TBitBtn? No - this would be wrong. Here is the inheritance diagram of these button classes:
  • TButton > TCustomButton > TButtonControl > TWinControl
  • TBitBtn > TCustomBitBtn > TCustomButton > TButtonControl > TWinControl
Mainly Lazarus trunk / fpc 3.2.0 / all 32-bit on Win-10, but many more...

engkin

  • Hero Member
  • *****
  • Posts: 2699
Re: Why TBitBtn font rendering so "grayscale"?
« Reply #10 on: March 20, 2021, 05:21:29 pm »
On Windows, BitBtns are drawn using DrawBitBtnImage in:
Lazarus\lcl\interfaces\win32\win32wsbuttons.pp:
Code: Pascal  [Select][+][-]
  1. procedure DrawBitBtnImage(BitBtn: TCustomBitBtn; const ButtonCaption: string);
  2. ...
  3.   procedure DrawBitmap(AState: TButtonState; UseThemes, AlphaDraw: Boolean);
  4.     if PaintBuffer = 0 then
  5. ..
  6.       DrawStateW(TmpDC, 0, nil, LPARAM(ButtonCaptionW), 0, XDestText, YDestText, 0, 0, TextFlags);
  7. ..
  8.     else
  9. ..
  10.       TWin32ThemeServices(ThemeServices).DrawTextEx(TmpDC, Details, ButtonCaption,
  11.         Rect(XDestText, YDestText, XDestText + TextSize.cx, YDestText + TextSize.cy),
  12.         TextFlags, @Options);
  13. ...

TBitBtn text is different from other buttons because it is the only button that is custom drawn.
« Last Edit: March 20, 2021, 05:33:23 pm by engkin »

FTurtle

  • Sr. Member
  • ****
  • Posts: 289
Re: Why TBitBtn font rendering so "grayscale"?
« Reply #11 on: March 20, 2021, 05:29:13 pm »
2. In trunk all of them are TBitBtn. See here:
https://bugs.freepascal.org/view.php?id=34578
Do you want to say that TButton "is" a TBitBtn, i.e. inherits from TBitBtn? No - this would be wrong. Here is the inheritance diagram of these button classes:
  • TButton > TCustomButton > TButtonControl > TWinControl
  • TBitBtn > TCustomBitBtn > TCustomButton > TButtonControl > TWinControl

Did you see my link?
I meant that in trunk now:
Quote
Description:
1. Changed class of button "Load Default": TButton -> TBitBtn
2. Assigned icon for button "Load Default"
3. Buttons were aligned on width

tersion

  • New Member
  • *
  • Posts: 11
Re: Why TBitBtn font rendering so "grayscale"?
« Reply #12 on: March 20, 2021, 06:22:01 pm »
On Windows, BitBtns are drawn using DrawBitBtnImage in:
Lazarus\lcl\interfaces\win32\win32wsbuttons.pp:
After you pointed out where is drawing function, I found another very old (form 2011) issue in bug-tracker: https://bugs.freepascal.org/view.php?id=15139
Here main quote:
Quote
After few trials I see no way to fix it.

1. To have alpha transparency on a themed canvas we need to create a 32bpp bitmap and a 32bpp imagelist. Our paint operation must support alpha channel too. So we are using BufferedPaint and DrawThemeTextEx functions. DrawThemeTextEx supports drawing without destructing alpha channel when DTT_COMPOSITED is set in flags. And when DTT_COMPOSITED is set it draws cleartype subpixels with gray color. I don't know why it is so. When DTT_COMPOSITED is not set then it draws it with colors but destroys the background.

2. We alternatively can draw the entire button ourself but in this case we will not have vista/w7 glow when button is focused.

Without having an idea to fix DTT_COMPOSITED problem I want to close this issue as unfixable but maybe someone else will have a luck to fix it. So I just change the target to post 1.0
So I suppose there are no fix still...

wp

  • Hero Member
  • *****
  • Posts: 8402
Re: Why TBitBtn font rendering so "grayscale"?
« Reply #13 on: March 20, 2021, 06:23:07 pm »
Did you see my link?
Yes.
I think I misunderstood you. You were only referring to the screenshot in reply #6. But I understood the "in trunk all of them are TBitBtn" as "in trunk all TButtons are TBitBtns". Sorry, rereading it again, you're wordings are correct, but my reading was false.
Mainly Lazarus trunk / fpc 3.2.0 / all 32-bit on Win-10, but many more...

tersion

  • New Member
  • *
  • Posts: 11
Re: Why TBitBtn font rendering so "grayscale"?
« Reply #14 on: March 20, 2021, 07:24:00 pm »
1. On your screenshot only one button is TButton, all other - TBitBtn
2. In trunk all of them are TBitBtn. See here:
https://bugs.freepascal.org/view.php?id=34578
Oh, now it's clear. Thanks about pointed on that.

 

TinyPortal © 2005-2018