View Issue Details

IDProjectCategoryView StatusLast Update
0036571PatchesWidgetsetpublic2020-01-14 19:58
ReporterYuriy SydorovAssigned ToOndrej Pokorny 
PrioritynormalSeverityminorReproducibilityalways
Status closedResolutionfixed 
Product Version2.1 (SVN)Product Build 
Target VersionFixed in Version 
Summary0036571: [patch] Windows: Properly use DefFontData.Name as the default font
DescriptionThe attached patch fixes the following issues for Windows:
- When you set the DefFontData.Name to a desired font name, this font is not applied everywhere.
- In some cases when the font height is set to 0 the default font height is not used.
TagsNo tags attached.
Fixed in Revision62549
LazTarget-
WidgetsetWin32/Win64
Attached Files
  • win32_deffont.patch (920 bytes)
    Index: lcl/interfaces/win32/win32winapi.inc
    ===================================================================
    --- lcl/interfaces/win32/win32winapi.inc	(revision 62547)
    +++ lcl/interfaces/win32/win32winapi.inc	(working copy)
    @@ -849,16 +849,16 @@
       FontName := LogFont.lfFaceName;
     
       TempLogFont := LogFont;
    -  if SameText(FontName, DefFontData.Name) then
    +  if SameText(FontName, DefFontData.Name) and IsFontNameDefault(DefFontData.Name) then
       begin
         TempLogFontW.lfFaceName := UTF8ToUTF16(FMetrics.lfMessageFont.lfFaceName); // FMetrics must be UTF16
    -    if TempLogFont.lfHeight = 0 then
    -      TempLogFont.lfHeight := FMetrics.lfMessageFont.lfHeight;
       end
       else
       begin
         TempLogFontW.lfFaceName := UTF8ToUTF16(FontName);
       end;
    +  if TempLogFont.lfHeight = 0 then
    +    TempLogFont.lfHeight := FMetrics.lfMessageFont.lfHeight;
       Result := Windows.CreateFontIndirectW(@TempLogFontW);
     end;
     
    
    win32_deffont.patch (920 bytes)

Activities

CudaText man

2020-01-14 13:34

reporter   ~0120426

+ if SameText(FontName, DefFontData.Name) and SameText(DefFontData.Name, 'default') then

we have helper func IsFontNameDefault().

Yuriy Sydorov

2020-01-14 13:41

developer   ~0120428

Thanks. I've attached the new patch which uses IsFontNameDefault().

win32_deffont.patch (920 bytes)
Index: lcl/interfaces/win32/win32winapi.inc
===================================================================
--- lcl/interfaces/win32/win32winapi.inc	(revision 62547)
+++ lcl/interfaces/win32/win32winapi.inc	(working copy)
@@ -849,16 +849,16 @@
   FontName := LogFont.lfFaceName;
 
   TempLogFont := LogFont;
-  if SameText(FontName, DefFontData.Name) then
+  if SameText(FontName, DefFontData.Name) and IsFontNameDefault(DefFontData.Name) then
   begin
     TempLogFontW.lfFaceName := UTF8ToUTF16(FMetrics.lfMessageFont.lfFaceName); // FMetrics must be UTF16
-    if TempLogFont.lfHeight = 0 then
-      TempLogFont.lfHeight := FMetrics.lfMessageFont.lfHeight;
   end
   else
   begin
     TempLogFontW.lfFaceName := UTF8ToUTF16(FontName);
   end;
+  if TempLogFont.lfHeight = 0 then
+    TempLogFont.lfHeight := FMetrics.lfMessageFont.lfHeight;
   Result := Windows.CreateFontIndirectW(@TempLogFontW);
 end;
 
win32_deffont.patch (920 bytes)

Ondrej Pokorny

2020-01-14 15:21

developer   ~0120433

> When you set the DefFontData.Name to a desired font name, this font is not applied everywhere.

How do you do that? DefFontData.Name is const.

Ondrej Pokorny

2020-01-14 15:37

developer   ~0120434

Thanks for the patch. Please test and close if OK.

Yuriy Sydorov

2020-01-14 16:56

developer   ~0120438

Last edited: 2020-01-14 16:58

View 4 revisions

> How do you do that? DefFontData.Name is const.

Historically typed consts are writable. So you can change DefFontData.Name and it must be used by an application. It is Delphi compatible.

> Thanks for the patch. Please test and close if OK.

You've changed my patch and it doesn't work as expected.

Expected:
- When the font is 'default' it must result in the font with the DefFontData.Name name.
- When TForm.ParentFont is True, the font described by DefFontData must be used (Delphi compatible).

When you do the following at the startup:

  DefFontData.Name:='Courier New';
  DefFontData.Height:=13;

This must change the font and size for the whole application.
Delphi and GTK2 works like this.

--

This line in the patch means both DefFontData.Name and FontName are 'default':
  if SameText(FontName, DefFontData.Name) and IsFontNameDefault(DefFontData.Name) then

Only in this case it is needed to get the font name from Windows.

You changed this to:
  if IsFontNameDefault(FontName) then

Which use the system font for any font named 'default'.

Also you've changed meaning of IsFontNameDefault(). It must just compare to the string 'defalt' as before.

Ondrej Pokorny

2020-01-14 17:43

developer   ~0120442

Last edited: 2020-01-14 17:45

View 2 revisions

Thanks for the feedback.

If DefFontData is to be changed, better to declare it as var. Then it makes more sense. (I did it in r62554.) The const is more a hack.

I reverted the IsFontNameDefault change.

Does it now work as you expect?

/Citation begin/
This line in the patch means both DefFontData.Name and FontName are 'default':
  if SameText(FontName, DefFontData.Name) and IsFontNameDefault(DefFontData.Name) then

Only in this case it is needed to get the font name from Windows.

You changed this to:
  if IsFontNameDefault(FontName) then

Which use the system font for any font named 'default'.
/Citation end/
IMO, this is correct, isn't it? If you change DefFontData.Name, then this changed name should be applied instead of the system default one. And 'default' should always point to system default, regardless of the DefFontData.Name. Or am I wrong here?

Yuriy Sydorov

2020-01-14 18:01

developer   ~0120444

> If DefFontData is to be changed, better to declare it as var. Then it makes more sense. (I did it in r62554.) The const is more a hack.

Sure. It is more clear.

> If you change DefFontData.Name, then this changed name should be applied instead of the system default one. And 'default' should always point to system default, regardless of the DefFontData.Name. Or am I wrong here?

When the font is 'default' the DefFontData.Name must be used. And when DefFontData.Name is _also_ 'default' then the default OS font is used. This allows easily change the font of the whole app if 'default' and/or ParentFont is used everywhere in the app.

So this more clear check must be used:

if IsFontNameDefault(FontName) and IsFontNameDefault(DefFontData.Name) then
  // Use OS default font name

Ondrej Pokorny

2020-01-14 18:07

developer   ~0120445

> When the font is 'default' the DefFontData.Name must be used.

IMO this is not correct. You have to set DefFontData.Name before the fonts are created.

'default' means system default and not DefFontData.Name.

Yuriy Sydorov

2020-01-14 19:58

developer   ~0120447

Actually in the current state, after using "if IsFontNameDefault(FontName) then" the win32 widgetset works properly. The same check is made in other widgetsets when creating a font.

FYI: If the font name equals DefFontData.Name, the name is not stored in the .lfm. So we can assume that 'default' means DefFontData.Name when a form is loaded.

So the issue can be closed now.

Issue History

Date Modified Username Field Change
2020-01-14 12:28 Yuriy Sydorov New Issue
2020-01-14 12:28 Yuriy Sydorov File Added: win32_deffont.patch
2020-01-14 13:34 CudaText man Note Added: 0120426
2020-01-14 13:40 Yuriy Sydorov File Deleted: win32_deffont.patch
2020-01-14 13:41 Yuriy Sydorov File Added: win32_deffont.patch
2020-01-14 13:41 Yuriy Sydorov Note Added: 0120428
2020-01-14 15:21 Ondrej Pokorny Note Added: 0120433
2020-01-14 15:21 Ondrej Pokorny Assigned To => Ondrej Pokorny
2020-01-14 15:21 Ondrej Pokorny Status new => assigned
2020-01-14 15:37 Ondrej Pokorny Status assigned => resolved
2020-01-14 15:37 Ondrej Pokorny Resolution open => fixed
2020-01-14 15:37 Ondrej Pokorny Fixed in Revision => 62549
2020-01-14 15:37 Ondrej Pokorny LazTarget => -
2020-01-14 15:37 Ondrej Pokorny Widgetset Win32/Win64 => Win32/Win64
2020-01-14 15:37 Ondrej Pokorny Note Added: 0120434
2020-01-14 16:56 Yuriy Sydorov Note Added: 0120438
2020-01-14 16:57 Yuriy Sydorov Note Edited: 0120438 View Revisions
2020-01-14 16:57 Yuriy Sydorov Note Edited: 0120438 View Revisions
2020-01-14 16:58 Yuriy Sydorov Note Edited: 0120438 View Revisions
2020-01-14 17:43 Ondrej Pokorny Note Added: 0120442
2020-01-14 17:45 Ondrej Pokorny Note Edited: 0120442 View Revisions
2020-01-14 18:01 Yuriy Sydorov Note Added: 0120444
2020-01-14 18:07 Ondrej Pokorny Note Added: 0120445
2020-01-14 19:58 Yuriy Sydorov Note Added: 0120447
2020-01-14 19:58 Yuriy Sydorov Status resolved => closed