Disclosure Statement: This site contains affiliate links, which means that I may receive a commission if you make a purchase using these links. As an eBay Partner, I earn from qualifying purchases.

OSR can't change font size after DPI is changed

Post Reply
tad.chen
Posts: 104
Joined: Fri Jan 04, 2019 1:39 am

OSR can't change font size after DPI is changed

Post by tad.chen »

In OSR Demo program, it hasn't changed font size in web page after monitor DPI is changed.

It does have code to handle DPI changing in FormAfterMonitorDpiChanged function, in which it calls NotifyScreenInfoChanged and WasResized to repaint the web page.

But it has a bug, the value of GlobalCEFApp.DeviceScaleFactor will not be changed! Then, in the following chrmosrGetViewRect event and so on, it still repaints the web page in the way before DPI is changed.
User avatar
salvadordf
Posts: 4016
Joined: Thu Feb 02, 2017 12:24 pm
Location: Spain
Contact:

Re: OSR can't change font size after DPI is changed

Post by salvadordf »

Please, check that you set GlobalCEFApp.EnableHighDPISupport to true before the GlobalCEFApp.StartMainProcess call in the DPR file.

The value of GlobalCEFApp.DeviceScaleFactor can be updated by calling GlobalCEFApp.UpdateDeviceScaleFactor if your application detects that the monitor DPI value has changed.
tad.chen
Posts: 104
Joined: Fri Jan 04, 2019 1:39 am

Re: OSR can't change font size after DPI is changed

Post by tad.chen »

Yes, GlobalCEFApp.EnableHighDPISupport is set to true.

But, after I add GlobalCEFApp.UpdateDeviceScaleFactor in FormAfterMonitorDpiChanged function, the value of GlobalCEFApp.DeviceScaleFactor is still not changed.
User avatar
salvadordf
Posts: 4016
Joined: Thu Feb 02, 2017 12:24 pm
Location: Spain
Contact:

Re: OSR can't change font size after DPI is changed

Post by salvadordf »

Check that the manifest in the application options has "Per monitor" or "Per monitor v2" in the "DPI awareness" box.
tad.chen
Posts: 104
Joined: Fri Jan 04, 2019 1:39 am

Re: OSR can't change font size after DPI is changed

Post by tad.chen »

I checked, It's "PerMonitor".

But, after I change it to "PerMonitorV2", it's the same. GlobalCEFApp.DeviceScaleFactor has no change when monitor DPI is changed.
User avatar
salvadordf
Posts: 4016
Joined: Thu Feb 02, 2017 12:24 pm
Location: Spain
Contact:

Re: OSR can't change font size after DPI is changed

Post by salvadordf »

Thanks for reporting this issue!

I just tried this issue and I see that the function that reads the current monitor DPI value keeps getting the same value after a DPI change.
I'll fix it as soon as I can.
User avatar
salvadordf
Posts: 4016
Joined: Thu Feb 02, 2017 12:24 pm
Location: Spain
Contact:

Re: OSR can't change font size after DPI is changed

Post by salvadordf »

Please, download the latest CEF4Delphi version from GitHub to fix this issue.
tad.chen
Posts: 104
Joined: Fri Jan 04, 2019 1:39 am

Re: OSR can't change font size after DPI is changed

Post by tad.chen »

Thank you! I'll test it.

But I now use an old version which support chromium 7X.X.X.X. Is it possible to update it?
User avatar
salvadordf
Posts: 4016
Joined: Thu Feb 02, 2017 12:24 pm
Location: Spain
Contact:

Re: OSR can't change font size after DPI is changed

Post by salvadordf »

Sorry but I don't keep separate branches for each Chromium version and I can't update old versions.

However, you can easily apply the changes manually. This is the commit with all the changes but you only have to apply 4 of them :
https://github.com/salvadordf/CEF4Delph ... f33f12910e
  • Add the RunningWindows10OrNewer and GetDPIForHandle functions in uCEFMiscFunctions.pas
  • Make UpdateDeviceScaleFactor virtual in uCEFApplicationCore.pas and override it in uCEFApplication.pas
  • Call GlobalCEFApp.UpdateDeviceScaleFactor; inside the TForm.OnAfterMonitorDpiChanged event as you can see in uSimpleOSRBrowser.pas
  • Modify GetScreenScale in uCEFBufferPanel.pas
tad.chen
Posts: 104
Joined: Fri Jan 04, 2019 1:39 am

Re: OSR can't change font size after DPI is changed

Post by tad.chen »

OK, I'll try it.

Thank you for your advice.
Post Reply