Forum > LCL

Strange behavior TFontDialog component

(1/2) > >>

zoltanleo:
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  [+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i < x.length; i++) { x[i].style.maxHeight='none'; x[i].style.height = Math.min(x[i].clientHeight+15,306)+'px'; x[i].style.resize = "vertical";}};} ---procedure TForm1.Button1Click(Sender: TObject);begin  FontDialog1.Font.Assign(Label1.Font);  if FontDialog1.Execute then  begin    Label1.Font.Assign(FontDialog1.Font);    StaticText1.Font.Assign(FontDialog1.Font);  end;end; procedure TForm1.Button2Click(Sender: TObject);var  aLogFont: TLogFont;begin  //uses LCLType  //see also https://docs.microsoft.com/en-us/windows/win32/api/wingdi/ns-wingdi-logfonta  with aLogFont do  begin    lfCharSet:= Label1.Font.CharSet;    lfHeight:= Label1.Font.Height;     if (fsBold in Label1.Font.Style)      then lfWeight:= FW_BOLD      else lfWeight:= FW_NORMAL;     lfItalic:= Byte(fsItalic in Label1.Font.Style);    lfStrikeOut:= Byte(fsStrikeOut in Label1.Font.Style);    lfUnderline:= Byte(fsUnderline in Label1.Font.Style);     lfOrientation:= Label1.Font.Orientation;    lfOutPrecision:= OUT_DEFAULT_PRECIS;    lfClipPrecision:= CLIP_DEFAULT_PRECIS;    lfQuality:= Byte(Label1.Font.Quality);    lfPitchAndFamily:= Byte(Label1.Font.Pitch);    lfFaceName:= Label1.Font.Name;  end;  FontDialog1.Font.Assign(aLogFont);   if FontDialog1.Execute then  begin    with aLogFont do    begin      lfCharSet:= FontDialog1.Font.CharSet;      lfHeight:= FontDialog1.Font.Height;       if (fsBold in FontDialog1.Font.Style)        then lfWeight:= FW_BOLD        else lfWeight:= FW_NORMAL;       lfItalic:= Byte(fsItalic in FontDialog1.Font.Style);      lfStrikeOut:= Byte(fsStrikeOut in FontDialog1.Font.Style);      lfUnderline:= Byte(fsUnderline in FontDialog1.Font.Style);       lfOrientation:= FontDialog1.Font.Orientation;      lfOutPrecision:= OUT_DEFAULT_PRECIS;      lfClipPrecision:= CLIP_DEFAULT_PRECIS;      lfQuality:= Byte(FontDialog1.Font.Quality);      lfPitchAndFamily:= Byte(FontDialog1.Font.Pitch);      lfFaceName:= FontDialog1.Font.Name;    end;     Label1.Font.Assign(aLogFont);    StaticText1.Font.Assign(aLogFont);  end;end;                          
Does this mean that I'm using the component incorrectly? Or it's a bug?

I made a test project for experiments (see attachment)

PascalDragon:

--- Quote from: zoltanleo on May 17, 2022, 11:58:18 pm ---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).
--- End quote ---

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:
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?

zeljko:
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:

--- Quote from: zeljko 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.

--- End quote ---

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

Navigation

[0] Message Index

[#] Next page

Go to full version