to detect the default/standard font of the OS/Widgetset lazarus / 23-Operating Systems ---------------------------------------------------------------------- af0815 · 2019-08-27 07:31 Is it possible to detect the standard or default font on a OS. Or which Font the user have decided to use for the apps. Actual i have on windows 10 'ArialMT' on RasPi Jessi 'LiberationSans', on RasPi Wheezy (and Buster) 'FreeSans'. But i found no function to detect the actual system standardfont. How can i detect this ? Because Lazarus can handle this - can somebody give me an advice where the detection in Lazarus resides. ---------------------------------------------------------------------- dbannon · 2019-08-27 09:13 Andreas, I had this problem in tomboy-ng. I found a workaround that does, sort of work for me. KMemo always seemed to pop up with the default font but if it was changed, you needed to know what to change it back to.  So, at startup, I'd push a bit of text into the KMemo control, read its font, and then clear that text. User unaware. Can you apply this model to whatever control you are using ? Davo ---------------------------------------------------------------------- korba812 · 2019-08-27 09:37 "Screen.SystemFont" indicates default system font. ---------------------------------------------------------------------- wp · 2019-08-27 21:44 Quote from: af0815 on August 27, 2019, 09:31:28 amBut i found no function to detect the actual system standardfont. Do you really need this? Just name the font "default" like the Object Inspector does. ---------------------------------------------------------------------- winni · 2019-08-28 00:44 The Font property is a problem since years. You can write every nonsens into the Font.Name and you dont't even get an error message, that the font was not found. Test this (just done in Linux): The Font in Tooglebox1 is "Sans standard" which is the Linux default. Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i ToggleBox1.Font.Name := 'HonkDiHonk'; where 'HonkDiHonk' is pure nonsense. No error message. Nothing changes. The font is still default. But now it gets funny: Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i showMessage (ToggleBox1.Font.Name); And he shows you not 'default'. And he shows you not 'Sans standard' He shows you 'HonkDiHonk' So even if you ask for the component.Font.Name, you might get not the right answer. And yes, @wp: some people like design. And not only a machine for number crunshing. Winni ---------------------------------------------------------------------- sstvmaster · 2019-08-28 12:48 Something like this? Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i function GetDefaultFontSize: integer;var  fd: TFontData;begin  fd := GetFontData( Form1.Font.Handle );  result := round((fd.Height * 72 / Form1.Font.PixelsPerInch) * (-1));end; procedure TForm1.FormCreate(Sender: TObject);begin  // set font name to nonsense  Form1.Font.name := 'GoodMorningStarshine';  Label1.Caption := 'Default font name : ' + GetFontData(Self.Font.Handle).Name;  Label2.Caption := 'Default font size : ' + IntToStr(GetDefaultFontSize);   // get and set system font name/size  Form1.Font.Name := Screen.SystemFont.Name; // only to be shure  Form1.Font.SetDefault; // <-- important !!!  Label3.Caption := 'System font name : ' + Screen.SystemFont.Name;  Label4.Caption := 'System font size : ' + IntToStr(Screen.SystemFont.Size); end; ---------------------------------------------------------------------- winni · 2019-08-28 13:07 Yes, that is the way it is normaly done. But insert in your Formcreate as first line the following: Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i Form1.Font.name := 'GoodMorningStarshine';  And suddenly you don't know nothing! Winni ---------------------------------------------------------------------- sstvmaster · 2019-08-28 22:03 And why i should do this? If you override the font name with nonsense, you get nonsense. I have updated the code in my post please try. ---------------------------------------------------------------------- winni · 2019-08-28 23:34 Yeah, that's what I wanted to show. Everywhere the compiler or the RTL tries to keep you away from nonsense, but not in this case. Think about those scenarios: *In the Formcreate you make a typo inside the string Font.Name: The compiler will not detect it and the RTL - as shown - doesn't care about your nonsens. No error message is given. * Your program starts on a computer, where the desired font is not installed. As above: No errors detected and no message given. That was what I wanted to show. Winni ---------------------------------------------------------------------- af0815 · 2019-08-30 08:23 The Problem i have, is on different RasPi versions the fonts differs and i have a report without bindings to the lcl. So i have to say the reportengine the correct font and size. And this font must available. This must also be done if i use a lcl renderer. Now i have some Parts to deal with. Thanks ---------------------------------------------------------------------- Thaddy · 2019-08-30 11:33 If your application relies on a font being present it may be a better idea to include the font as a resource. ---------------------------------------------------------------------- winni · 2019-08-30 12:50 In Windows installing a font from a resourcee is possible. In Linux you need root rights. Very old, unsolved subject. ---------------------------------------------------------------------- sash · 2019-08-30 13:29 Quote from: winni on August 30, 2019, 02:50:05 pminstalling a font from a resourcee ... In Linux you need root rights I always thought it's possible to do on per user basis: Code: Bash  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i cp yourfont.ttf ~/.fonts ---------------------------------------------------------------------- sstvmaster · 2019-08-30 15:52 Is it possible do this in Linux? Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i ...var  vFont, vFontName: String;... procedure TForm1.FormCreate(Sender: TObject);begin  vFont := 'arial.ttf';  // font in same folder as exe  vFontName := 'Arial';   if AddFontResource(PChar(GetCurrentDir + PathDelim + vFont)) <> 0 then begin    Font.Name := vFontName;    Font.Size := 12;  end;end; procedure TForm1.FormClose(Sender: TObject; var CloseAction: TCloseAction);begin  if Font.Name = vFontName then  RemoveFontResource(PChar(GetCurrentDir + PathDelim + vFont));end; ---------------------------------------------------------------------- winni · 2019-08-30 17:34 No, this Windows only. ---------------------------------------------------------------------- winni · 2019-08-30 18:00 Discussion and workaround is here: https://forum.lazarus.freepascal.org/index.php/topic,26003.msg159027.h tml Winni ---------------------------------------------------------------------- winni · 2019-08-30 19:32 @sash QuoteI always thought it's possible to do on per user basis: cp yourfont.ttf ~/.fonts In Fedora the folder path is /home/{user}/.local/share/fonts Winni ---------------------------------------------------------------------- sash · 2019-08-30 19:57 IMO, should work both, I just wrote ~/.fonts beacuse it's shorter (and actually it is deprecated in favor of ~/.local/share/fonts). But point was there's no need for root. ---------------------------------------------------------------------- af0815 · 2019-08-30 20:43 back to topic - i want the actual font, not to inject my own font. ---------------------------------------------------------------------- af0815 · 2019-08-30 20:47 Quote from: Thaddy on August 30, 2019, 01:33:47 pmIf your application relies on a font being present it may be a better idea to include the font as a resource. No, i want to know, what is the default font. Background: Between Jessi and Wheezy there must be a change in Raspbian in the default font (from liberationSans to freeSans). Actual i have update my installscripts and install booth font-package. fpreport cannot detect the font and use a predefined, not existing font :-( and on a LCL printout you see NOTHING. But there is another Bug ? prevent for a correct printout. I have fixed this with a 'hard' patch, but the issue with the font was only prevent by install all fonts on the systems. Regardless if they are Jessi or Wheezy (Buster) based. ---------------------------------------------------------------------- winni · 2019-08-30 21:31 After installing new fonts in Linux you must update the cache: Code: Bash  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i fc-cache -fv Did you do it? Winni ---------------------------------------------------------------------- sash · 2019-08-31 10:46 Quote from: Thaddy on August 30, 2019, 01:33:47 pmIf your application relies on a font being present it may be a better idea to include the font as a resource. And maybe even introduce an option where user selects a font explicitly with TFontDialog.