Incorrect code in /fontenum/ demo project lazarus / 21-General ---------------------------------------------------------------------- zoltanleo · 2022-05-23 20:16 Hi all While researching the demo application code (\examples\fontenum\), I found that the source code is: 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 EnumFamilyFonts(  var eLogFont: TEnumLogFontEx;  var Metric:TNewTextMetricEx;  FontType:longint;  Data:LParam):longint; stdcall;  // collect styles  s :=eLogFont.elfStyle;  if LStyles.IndexOf(s)<0 then begin    // encode bold, italic    n := eLogFont.elfLogFont.lfItalic;        if (eLogFont.elfLogFont.lfWeight > FW_MEDIUM) then n := n or 2;//<-- incorrect code  end;                                                                 returns the same font style for italic and italic bold (see screenshot). I made some changes. I think the bug has been fixed now. 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 //probably it's correct code    if (eLogFont.elfLogFont.lfWeight > FW_MEDIUM)  then n := (n or 2)  else    if (n > 0) then n:= (n xor 2); Can someone create a ticket in the bug tracker if I'm right and this problem is solved in this way? ---------------------------------------------------------------------- wp · 2022-05-24 13:39 Fixed it in main (replaced the "xor 2" by "and not 2" which is less of a mind-twister to me). ---------------------------------------------------------------------- zoltanleo · 2022-05-24 16:45 Quote from: wp on May 24, 2022, 03:39:17 pmFixed it in main (replaced the "xor 2" by "and not 2" which is less of a mind-twister to me). I did some more experimenting and found that text formatting "doesn't work" for Linux. As a result, I tried to make a few more changes in the code so that the demo example worked correctly. 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 EnumFamilyFonts(...);    //if (eLogFont.elfLogFont.lfWeight > FW_MEDIUM) then n:= n or 2; <--- instead     if (n = 0) //regular,bold    then      case eLogFont.elfLogFont.lfWeight of      FW_NORMAL: n:= 0;        FW_BOLD: n:= 2;      end    else //italic, italic bold      case eLogFont.elfLogFont.lfWeight of        FW_NORMAL: n:= 1;        FW_BOLD: n:= 3;      end; and 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 procedure TfrmMain.SelectFont;....  //F.Style := [];  //if i and 1 <> 0 then F.Style := F.Style + [fsItalic];  //if i and 2 <> 0 then F.Style := F.Style + [fsBold];   i := ptrint(lbStyles.Items.Objects[lbStyles.ItemIndex]);   case i of    1: F.Style := [fsItalic];    2: F.Style := [fsBold];    3: F.Style := [fsBold, fsItalic];  else F.Style:= [];  end;.... Someone test my work please ---------------------------------------------------------------------- wp · 2022-05-24 17:57 No, this is not working either. (it just rewrites the idea to set bit 1 for italic and bit 2 for bold styles in a different way (*) ). I tested Ubuntu and OpenSUSE (gtk2), as well as Mint (gkt2, qt), and in none of them the styles are displayed. When I add  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   with eLogFont do    DebugLn(Format('Name: %s, Style: %s - lfWeight: %d, lfItalic: %d', [      elfLogFont.lfFaceName, elfStyle, elfLogFont.lfWeight, elfLogFont.lfItalic    ])); after the "begin" of EnumFamilyFonts I see in the console output window that the elfLogFont members lfWeight and lfItalic are not reported correctly in Linux. lfWeight is always 400 (= FW_NORMAL) and lfItalic is always 0 (= false), no matter what eLogFont.elfStyle says. It would be tempting to extract the missing font style from the eLogFont.elfStyle string, but this is deceiving because the string is localized - at least on Windows. So, I think it must be accepted that this example does not work on Linux. But maybe the Linux experts have better ideas... ----------------- (*) I think that part can still be improved and coded in a way analogous to SelectFont: 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  // collect styles  s :=eLogFont.elfStyle;  if LStyles.IndexOf(s)<0 then begin    // encode italic (bit 1), bold (bit 2) -- see SelectFont()    n := 0;    if eLogFont.elfLogFont.lfItalic <> 0 then      n := n or 1;     if eLogFont.elfLogFont.lfWeight > FW_MEDIUM then      n := n or 2;     LStyles.AddObject(eLogFont.elfStyle, TObject(ptrint(n)));  end; ---------------------------------------------------------------------- wp · 2022-05-24 22:01 Found that the font styles are named consistently "Bold" and "Italic" in gtk2. In qt there is also an "Oblique", as well as several intermediate weight styles which the LCL does not paint anyway; there was only one font with localized style names on my notebook with qt. Therefore, I extended the EnumFamilyFonts function of the example to search these key words in the style string for the Linux widgetsets, and committed 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   // collect styles  s :=eLogFont.elfStyle;  if LStyles.IndexOf(s)<0 then begin    // encode bold (bit 0), italic (bit 1) -- see SelectFont    n := 0;    {$IFDEF LCLWin32}    if (eLogFont.elfLogFont.lfItalic <> 0) then      n := n or 1;    if (eLogFont.elfLogFont.lfWeight > FW_MEDIUM) then      n := n or 2;    {$ENDIF}    {$IF DEFINED(LCLGtk2) or DEFINED(LCLGtk3) or DEFINED(LCLQt) or DEFINED(LCLQt5)}    s := Lowercase(s);    if (pos('italic', s) <> 0) or (pos('oblique', s) <> 0) then      n := n or 1;    if (pos('bold', s) <> 0) then      n := n or 2;    {$ENDIF}    LStyles.AddObject(eLogFont.elfStyle, TObject(ptrint(n)));  end; Not very elegant and not perfect, but at least better than the present situation. ---------------------------------------------------------------------- zoltanleo · 2022-05-24 23:55 Quote from: wp on May 25, 2022, 12:01:26 am Therefore, I extended the EnumFamilyFonts function of the example to search these key words in the style string for the Linux widgetsets Thank U, Werner. Nice work! Also I found that the list of font styles is not showing for Darwin Cocoa. ---------------------------------------------------------------------- dbannon · 2022-05-25 00:13 WP's solution applies to only Linux and Windows. My Mac is Sierra so probably too old to be authoritative. Some Mac user ?? WP, these commits you are making wrt the Examples, there seems a lot of small fixes. I was trying to group all the changes I made into a small number of merges so it was easy to list them if and when its ultimately merged to a release. Is there a way to keep track of all these small merges ? Davo ---------------------------------------------------------------------- wp · 2022-05-25 04:41 Quote from: zoltanleo on May 25, 2022, 01:55:23 amAlso I found that the list of font styles is not showing for Darwin Cocoa. Yes. I guess the EnumFontFamiliesEx function is not fully implemented for the cocoa widgetset, yet. It only populates the filename and fullname members in the LogFont, and the Metric members are zero, as well. Your screenshot of the system dialog shows that the needed information does exist (of course), but I don't have the knowledge of extract it from mac's internal structures. ---------------------------------------------------------------------- wp · 2022-05-25 04:51 Quote from: dbannon on May 25, 2022, 02:13:42 amWP, these commits you are making wrt the Examples, there seems a lot of small fixes. I was trying to group all the changes I made into a small number of merges so it was easy to list them if and when its ultimately merged to a release. Is there a way to keep track of all these small merges ? I don't know. Of course I try to make commits of these small things as complete as possible. But it usually happens that after I committed a fix it comes to my mind that I should have checked also some other aspect. And this leads to the next commit, and so on... Sorry, that's the way it is. ---------------------------------------------------------------------- PascalDragon · 2022-05-25 07:23 Quote from: wp on May 25, 2022, 06:41:58 amQuote from: zoltanleo on May 25, 2022, 01:55:23 amAlso I found that the list of font styles is not showing for Darwin Cocoa. Yes. I guess the EnumFontFamiliesEx function is not fully implemented for the cocoa widgetset, yet. It only populates the filename and fullname members in the LogFont, and the Metric members are zero, as well. Your screenshot of the system dialog shows that the needed information does exist (of course), but I don't have the knowledge of extract it from mac's internal structures. Then best post it as a bug report and someone more knowledgable in Cocoa will take a look. ---------------------------------------------------------------------- zoltanleo · 2022-05-25 20:01 Quote from: PascalDragon on May 25, 2022, 09:23:38 amThen best post it as a bug report and someone more knowledgable in Cocoa will take a look. The corresponding ticket has been created: https://gitlab.com/freepascal.org/lazarus/lazarus/-/issues/39771 Thank a lot WP ---------------------------------------------------------------------- skalogryz · 2022-05-30 20:09 i did post the link to the branch with fixes at the issue.