Recent

Author Topic: Strange behavior TFontDialog component  (Read 1400 times)

zoltanleo

  • Sr. Member
  • ****
  • Posts: 486
Strange behavior TFontDialog component
« on: May 17, 2022, 11:58:18 pm »
Hi folks.

Please help me figure out how it works TFontDialog component.

When I use it under Windows I can set the font color via the Dialog Option (fig 1). When using Linux (GTK2) I can't set the font color using FontDialog at all. (fig 2). When I use the FontDialog under Darwin, I can select the font color as well as some font styles in the dialog, but they are not applied after Execute method is executed (fig 3).

Some code
Code: Pascal  [Select][+][-]
  1. procedure TForm1.Button1Click(Sender: TObject);
  2. begin
  3.   FontDialog1.Font.Assign(Label1.Font);
  4.   if FontDialog1.Execute then
  5.   begin
  6.     Label1.Font.Assign(FontDialog1.Font);
  7.     StaticText1.Font.Assign(FontDialog1.Font);
  8.   end;
  9. end;
  10.  
  11. procedure TForm1.Button2Click(Sender: TObject);
  12. var
  13.   aLogFont: TLogFont;
  14. begin
  15.   //uses LCLType
  16.   //see also https://docs.microsoft.com/en-us/windows/win32/api/wingdi/ns-wingdi-logfonta
  17.   with aLogFont do
  18.   begin
  19.     lfCharSet:= Label1.Font.CharSet;
  20.     lfHeight:= Label1.Font.Height;
  21.  
  22.     if (fsBold in Label1.Font.Style)
  23.       then lfWeight:= FW_BOLD
  24.       else lfWeight:= FW_NORMAL;
  25.  
  26.     lfItalic:= Byte(fsItalic in Label1.Font.Style);
  27.     lfStrikeOut:= Byte(fsStrikeOut in Label1.Font.Style);
  28.     lfUnderline:= Byte(fsUnderline in Label1.Font.Style);
  29.  
  30.     lfOrientation:= Label1.Font.Orientation;
  31.     lfOutPrecision:= OUT_DEFAULT_PRECIS;
  32.     lfClipPrecision:= CLIP_DEFAULT_PRECIS;
  33.     lfQuality:= Byte(Label1.Font.Quality);
  34.     lfPitchAndFamily:= Byte(Label1.Font.Pitch);
  35.     lfFaceName:= Label1.Font.Name;
  36.   end;
  37.   FontDialog1.Font.Assign(aLogFont);
  38.  
  39.   if FontDialog1.Execute then
  40.   begin
  41.     with aLogFont do
  42.     begin
  43.       lfCharSet:= FontDialog1.Font.CharSet;
  44.       lfHeight:= FontDialog1.Font.Height;
  45.  
  46.       if (fsBold in FontDialog1.Font.Style)
  47.         then lfWeight:= FW_BOLD
  48.         else lfWeight:= FW_NORMAL;
  49.  
  50.       lfItalic:= Byte(fsItalic in FontDialog1.Font.Style);
  51.       lfStrikeOut:= Byte(fsStrikeOut in FontDialog1.Font.Style);
  52.       lfUnderline:= Byte(fsUnderline in FontDialog1.Font.Style);
  53.  
  54.       lfOrientation:= FontDialog1.Font.Orientation;
  55.       lfOutPrecision:= OUT_DEFAULT_PRECIS;
  56.       lfClipPrecision:= CLIP_DEFAULT_PRECIS;
  57.       lfQuality:= Byte(FontDialog1.Font.Quality);
  58.       lfPitchAndFamily:= Byte(FontDialog1.Font.Pitch);
  59.       lfFaceName:= FontDialog1.Font.Name;
  60.     end;
  61.  
  62.     Label1.Font.Assign(aLogFont);
  63.     StaticText1.Font.Assign(aLogFont);
  64.   end;
  65. end;                        
  66.  

Does this mean that I'm using the component incorrectly? Or it's a bug?

I made a test project for experiments (see attachment)
« Last Edit: May 18, 2022, 12:00:46 am by zoltanleo »
Win10 LTSC x64/Deb 11 amd64(gtk2/qt5)/Darwin Cocoa (Monterey):
Lazarus x32/x64 2.3(trunk); FPC 3.3.1 (trunk), FireBird 3.0.10; IBX by TonyW

Sorry for my bad English, I'm using translator ;)

PascalDragon

  • Hero Member
  • *****
  • Posts: 5446
  • Compiler Developer
Re: Strange behavior TFontDialog component
« Reply #1 on: May 18, 2022, 08:57:02 am »
When I use it under Windows I can set the font color via the Dialog Option (fig 1). When using Linux (GTK2) I can't set the font color using FontDialog at all. (fig 2). When I use the FontDialog under Darwin, I can select the font color as well as some font styles in the dialog, but they are not applied after Execute method is executed (fig 3).

As Lazarus uses the native font dialog not every option might be supported on every OS. E.g. on GTK2 the dialog doesn't allow you to change the color so that is simply not supported then.

On Windows at least there is handling for colors in the dialog related code, so if that doesn't work this might be a bug.

On macOS (I assume Cocoa) this might be a bug as well, at least if the LCL in general supports such styles.

zoltanleo

  • Sr. Member
  • ****
  • Posts: 486
Re: Strange behavior TFontDialog component
« Reply #2 on: May 18, 2022, 09:56:27 am »
Hi PascalDragon

Thank U for answer. Does this fact mean that I have to create my own dialog in order to achieve the desired result?
Win10 LTSC x64/Deb 11 amd64(gtk2/qt5)/Darwin Cocoa (Monterey):
Lazarus x32/x64 2.3(trunk); FPC 3.3.1 (trunk), FireBird 3.0.10; IBX by TonyW

Sorry for my bad English, I'm using translator ;)

zeljko

  • Hero Member
  • *****
  • Posts: 1594
    • http://wiki.lazarus.freepascal.org/User:Zeljan
Re: Strange behavior TFontDialog component
« Reply #3 on: May 18, 2022, 12:54:37 pm »
Maybe it's time to create LCL FontDialog, similar to win32, qt/qt5 also have fontdialog without color and eg choose only monospace font.

zoltanleo

  • Sr. Member
  • ****
  • Posts: 486
Re: Strange behavior TFontDialog component
« Reply #4 on: May 19, 2022, 01:52:36 pm »
Maybe it's time to create LCL FontDialog, similar to win32, qt/qt5 also have fontdialog without color and eg choose only monospace font.

I agree.  For my application, I had to write my own analogue of the dialog box. Also, there is a similar project in the Lazarus "Example" folder
Win10 LTSC x64/Deb 11 amd64(gtk2/qt5)/Darwin Cocoa (Monterey):
Lazarus x32/x64 2.3(trunk); FPC 3.3.1 (trunk), FireBird 3.0.10; IBX by TonyW

Sorry for my bad English, I'm using translator ;)

zoltanleo

  • Sr. Member
  • ****
  • Posts: 486
Re: Strange behavior TFontDialog component
« Reply #5 on: May 20, 2022, 06:50:25 am »
Hmmm....

I found that for nix OS, some TWinControl  descendans cannot have the font style fsStrikeOut and fsUnderline. But descendants of TGraphicControl (e.g. TLabel) display these styles correctly. What is it: a bug or a feature?
Win10 LTSC x64/Deb 11 amd64(gtk2/qt5)/Darwin Cocoa (Monterey):
Lazarus x32/x64 2.3(trunk); FPC 3.3.1 (trunk), FireBird 3.0.10; IBX by TonyW

Sorry for my bad English, I'm using translator ;)

trev

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 2020
  • Former Delphi 1-7, 10.2 user
Re: Strange behavior TFontDialog component
« Reply #6 on: May 20, 2022, 07:18:36 am »
What does the Lazarus restriction browser show?

skalogryz

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 2770
    • havefunsoft.com
Re: Strange behavior TFontDialog component
« Reply #7 on: May 24, 2022, 06:47:18 am »
When I use the FontDialog under Darwin, I can select the font color as well as some font styles in the dialog, but they are not applied after Execute method is executed (fig 3).
fixed here: https://github.com/skalogryz/Lazarus/commit/8d136662f3a6ef9dd2813b612f71d8378d635dfa

zeljko

  • Hero Member
  • *****
  • Posts: 1594
    • http://wiki.lazarus.freepascal.org/User:Zeljan
Re: Strange behavior TFontDialog component
« Reply #8 on: May 24, 2022, 08:11:11 am »
Hmmm....

I found that for nix OS, some TWinControl  descendans cannot have the font style fsStrikeOut and fsUnderline. But descendants of TGraphicControl (e.g. TLabel) display these styles correctly. What is it: a bug or a feature?

It works with qt and qt5 widgetset.

zoltanleo

  • Sr. Member
  • ****
  • Posts: 486
Re: Strange behavior TFontDialog component
« Reply #9 on: May 25, 2022, 05:58:22 pm »
When I use the FontDialog under Darwin, I can select the font color as well as some font styles in the dialog, but they are not applied after Execute method is executed (fig 3).
fixed here: https://github.com/skalogryz/Lazarus/commit/8d136662f3a6ef9dd2813b612f71d8378d635dfa

Can you create a ticket in the bug tracker or provide a link if the topic exists?

Upd: the ticket is already exists

https://gitlab.com/freepascal.org/lazarus/lazarus/-/issues/39765
« Last Edit: May 25, 2022, 06:05:38 pm by zoltanleo »
Win10 LTSC x64/Deb 11 amd64(gtk2/qt5)/Darwin Cocoa (Monterey):
Lazarus x32/x64 2.3(trunk); FPC 3.3.1 (trunk), FireBird 3.0.10; IBX by TonyW

Sorry for my bad English, I'm using translator ;)

 

TinyPortal © 2005-2018