Watch, Follow, &
Connect with Us

For forums, blogs and more please visit our
Developer Tools Community.


Welcome, Guest
Guest Settings
Help

Thread: VCL dpi scaling problems...



Permlink Replies: 2 - Last Post: Dec 14, 2017 11:10 AM Last Post By: Lajos Juhasz Threads: [ Previous | Next ]
Gabriel Corneanu

Posts: 17
Registered: 11/9/99
VCL dpi scaling problems...
Click to report abuse...   Click to reply to this thread Reply
  Posted: Dec 14, 2017 3:47 AM
Hello everybody,

I am trying to update my code base to Delphi 10.2.2 (from Delphi XE5).
I don't know about others, but I have the feeling the dpi scaling is messed-up.
My only particular situation: I develop on a system (Windows 8) where DPI is set to 120. Our (current) policy is to develop on 120 dpi and to NOT scale anything (setting all forms scaled:= false).

I test on a trivial empty VCL application (File/New/VCL Forms...).

1. How is the scaling supposed to work? When setting scale := true, the form is suddenly bigger (when run). I expect to stay the same size as in my designer.
Looking through the code, it looks like the VCL assumes that I designed the form with 96 dpi (FCurrentPPI initialized to a constant) and scales to 120 dpi???
It seems I can partially hack to correct behavior by using
procedure TForm1.InitializeNewForm;
begin
  inherited;
  FCurrentPPI := 0;
end;

This uses a different branch in TCustomForm.ScaleForPPIRect and initializes FCurrentPPI to the saved FPixelsPerInch value.
I have the feeling this is the intended behavior...

2. This is actually worse (because I don't know how to avoid it); it is about forced/unwanted scaling for the menus.
Use this in OnCreate (needs "uses menus"):
procedure TForm1.FormCreate(Sender: TObject);
var
  MI : TMenuItem;
begin
  scaled := false; //set in designer
  Menu := TMainMenu.Create(self);
  Menu.Images := TImageList.Create(self);
  MI := NewItem('Item1', 0, false, true, nil, 0, '');
  Menu.Items.Add(MI);
  MI.Add(NewItem('Item2', 0, false, true, nil, 0, ''));
  MI.Items[0].ImageIndex := 0;
end;

I just create a simple menu. On my system, "Item2" uses a bigger font!
I found, deep in TMenuItem.MeasureItem/MeasureThemedMenuItem, a similar problem:
      aCanvas.Font.Size := MulDiv(aCanvas.Font.Size, LPPI, OriginalPPI);

where OriginalPPI is constant 96 dpi! How the hack can I avoid this??
There is also a big inconsistency, the top menu ("Item1") is drawn by GDI using the original size, obviously smaller than "Item2".
That's because only "Item2" (by imageindex >= 0) triggers a measure callback... I can force all items by setting "Menu.OwnerDraw := true".

This is very inconvenient, any usage of menu images triggers this problem. I don't see how one can correctly implement this, menus don't have an "original" dpi to compare with...
To me it's obviously wrong, the menu font size is bigger than all other Windows applications. Even the Delphi IDE shows normal menu size, even though it has images attached to menu items...

Isn't anyone else seeing these problems?? It's enough to set the screen resolution to "medium" (125% or greater).

Edit: ok, I'm not the only one :)
https://quality.embarcadero.com/browse/RSP-19166

Regards,
Gabriel

Edited by: Gabriel Corneanu on Dec 14, 2017 4:07 AM

Gabriel Corneanu

Posts: 17
Registered: 11/9/99
Re: VCL dpi scaling problems...
Click to report abuse...   Click to reply to this thread Reply
  Posted: Dec 14, 2017 4:29 AM   in response to: Gabriel Corneanu in response to: Gabriel Corneanu
Now I'm realizing, who decided to scale the menus font didn't read the specs / code...
The font.size is already scaled for current dpi, read the TFont.GetSize method.
So what we get is "double" scaling...

Gabriel
Lajos Juhasz

Posts: 801
Registered: 3/14/14
Re: VCL dpi scaling problems... [Edit]
Click to report abuse...   Click to reply to this thread Reply
  Posted: Dec 14, 2017 11:10 AM   in response to: Gabriel Corneanu in response to: Gabriel Corneanu
Gabriel Corneanu wrote:

[snip]

I cannot test at the moment, I am going to install 10.2.2 only next
week, but in the design time you should change the PixelsPerInch
property of your forms.

From the help (from XE5):
Represents the proportion of the font on the system on which the form
was designed.
 
Use PixelsPerInch at runtime to change how the form is scaled to the
current screen resolution. If PixelsPerInch is changed from its default
value, the form will not have the same proportion on every screen
resolution.
 
At design time, PixelsPerInch is set automatically when the form is
saved. Changes to PixelsPerInch made in the Object Inspector only
affect the form at runtime.
 
The form's Scaled property must be true for PixelsPerInch to have an
effect.
Legend
Helpful Answer (5 pts)
Correct Answer (10 pts)

Server Response from: ETNAJIVE02