Recent

Author Topic: HI-DPI font scale bug with dynamic TFrame  (Read 2148 times)

Mr. George

  • New Member
  • *
  • Posts: 30
HI-DPI font scale bug with dynamic TFrame
« on: August 26, 2025, 08:36:03 pm »
Hi!
I have an old project that was created in Lazarus 2.x. I recently upgraded Lazarus to 4.2.19 (the About dialog shows 4.3, fixes branch).
After opening the project, it upgraded the form modules (lfm).
I develop on a 4K monitor; the form property DesigntimePPI = 144.
The program has a TFrame that contains a TEdit with a nonstandard font size.
I create the Frame at runtime with similar code:

Code: Pascal  [Select][+][-]
  1.  
  2. Frame1 := TFrame1.Create(FormMain);
  3. Frame1.Parent := FormMain;
  4. Frame1.Visible := True;
  5.  

When I run the program on a 96 PPI monitor, the font inside the TEdit is displayed incorrectly.
If I add the Frame at design time (via the component palette) and select that same Frame, the font size in the TEdit is correct on the 96 PPI monitor (at runtime).
So it seems some font-size recalculation that should run automatically is missing.
« Last Edit: August 29, 2025, 10:41:39 am by Mr. George »

jamie

  • Hero Member
  • *****
  • Posts: 7319
Re: TEdit font scale with TFrame
« Reply #1 on: August 26, 2025, 11:56:12 pm »
Maybe you need to match the DesignTimePPI for the Tframe with the TFORM designTimePPI property when you create it at run-time.

Jamie
The only true wisdom is knowing you know nothing

Mr. George

  • New Member
  • *
  • Posts: 30
Re: TEdit font scale with TFrame
« Reply #2 on: August 28, 2025, 09:19:47 am »
It doesn't help, it looks fine on 4k (where was compiled), but on 2k the font is huge.
Looks like a bug in LCL.

Code: Pascal  [Select][+][-]
  1.   Frame1 := TFrame1.Create(FormMain);
  2.  
  3.   Frame1.Scaled := True;
  4.   Frame1.DesignTimePPI := FormMain.DesignTimePPI;
  5.   Frame1.PixelsPerInch := FormMain.PixelsPerInch;
  6.   //Frame1.ParentFont := True;
  7.   //Frame1.ScaleFontsPPI(96, 1);
  8.  
  9.   Frame1.Parent := FormMain;
  10.   Frame1.Visible := True;
  11.  
« Last Edit: August 29, 2025, 10:56:28 am by Mr. George »

tetrastes

  • Hero Member
  • *****
  • Posts: 694
Re: TEdit font scale with TFrame
« Reply #3 on: August 28, 2025, 05:36:42 pm »
Try
Code: Pascal  [Select][+][-]
  1. Frame1.Edit1.Font.Size := YourSize;

Mr. George

  • New Member
  • *
  • Posts: 30
Re: TEdit font scale with TFrame
« Reply #4 on: August 28, 2025, 06:13:04 pm »
This helps, will work as a workaround, thanks.

jamie

  • Hero Member
  • *****
  • Posts: 7319
Re: TEdit font scale with TFrame
« Reply #5 on: August 29, 2025, 12:04:52 am »
Try setting the Scale = True after you have set the Pixel DPI ranges not before.

It that was me designing that I would have set a flag internally indicating that it has already been scaled so further scaling is not accepted.
 
  It's just a test and how I think, which is strange I know.

Jamie
The only true wisdom is knowing you know nothing

Mr. George

  • New Member
  • *
  • Posts: 30
Re: TEdit font scale with TFrame
« Reply #6 on: August 29, 2025, 09:41:47 am »
Same behavior, so far only manual font size assignment works.

Code: Pascal  [Select][+][-]
  1.   Frame1 := TFrame1.Create(FormMain);
  2.  
  3.   Frame1.DesignTimePPI := FormMain.DesignTimePPI;
  4.   Frame1.PixelsPerInch := FormMain.PixelsPerInch;
  5.   Frame1.Scaled := True;
  6.   //Frame1.Edit1.Font.Size := -15;
  7.  
  8.   Frame1.Parent := FormMain;
  9.   Frame1.Visible := True;
  10.  

Mr. George

  • New Member
  • *
  • Posts: 30
Re: TEdit font scale with TFrame
« Reply #7 on: August 29, 2025, 10:40:58 am »
In fact, this also applies to TLabel and TButton. It seems that if the component has a non-standard font size, a scaling error occurs.

wp

  • Hero Member
  • *****
  • Posts: 13219
Re: TEdit font scale with TFrame
« Reply #8 on: August 29, 2025, 10:42:55 am »
Was it intentional that you have Frame.ParentFont = false in the demo project? Resetting this (and that of Edit1) to true fixes the scaling issue without any further changes.

If you insist on ParentFont=false you are saying: I need this font size and I'll take care of everything. In this case you should override to ScaleFontsPPI method of the frame:
Code: Pascal  [Select][+][-]
  1. procedure TFrame1.ScaleFontsPPI(const AToPPI: Integer; const AProportion: Double);
  2. begin
  3.   DoScaleFontPPI(Edit2.Font, AToPPI, AProportion);
  4. end;

See your modified project in the attachment containing edit controls with both ParentFont=true and ParentFont=false.

Mr. George

  • New Member
  • *
  • Posts: 30
Re: HI-DPI font scale bug with dynamic TFrame
« Reply #9 on: August 29, 2025, 11:48:18 am »
Quote
Was it intentional that you have Frame.ParentFont = false in the demo project?
For the frame - no, it wasn't. For the Edit - yes.

When changing the font size of a component from default to custom, ParentFont becomes false.
We say: "Don't inherit the font size, we need a specific size for the current DPI", which in my case is 144.
This should not be related to scaling at all, the LCL should automatically convert such values ​​using designtimeppi.
I can't imagine that the developer would have to manually set the font size for each component with a custom font size.

Also, I have not had any problems before (with ParentFont=false), on Lazarus 2.x.

Quote
If you insist on ParentFont=false you are saying: I need this font size and I'll take care of everything.
Even with ParentFont=false everything works as expected if I add a frame using the component palette.
I attached a new demo: the same frame works fine in one case, but not in the other.
« Last Edit: August 29, 2025, 12:03:05 pm by Mr. George »

Martin_fr

  • Administrator
  • Hero Member
  • *
  • Posts: 11824
  • Debugger - SynEdit - and more
    • wiki
Re: HI-DPI font scale bug with dynamic TFrame
« Reply #10 on: September 12, 2025, 04:19:04 pm »
I can't currently test this (time restraints), and likely wont be able to look at this for a good while...

From a quick glace at the thread
- Add everything in the designer => Frame.Font is scaled according to actual DPI
- Add frame from code (in TForm.Create) => Frame.Font is NOT scaled according to actual DPI

Sounds like a bug / Should be reported (With a simple app to reproduce it / E.g. the app could be set to have DesignTimePPI = 48 => then it would scale for everyone)




From memory / not sure if related.

There had been another scaling issue, where scaling went wrong when changes were made in an overridden Form.Create.
I don't know if this is the same issue.

Maybe the Frame can be added at a later point. (as workaround / if indeed that actually makes a difference). I don't know if that will help...

 

TinyPortal © 2005-2018