Page 1 of 1

High resolutions with dpi unaware and bad fonts

Posted: Wed Sep 04, 2024 1:03 pm
by sebfischer83
Hi,

we've got an old Delphi Application that doesn't work with DPI Scaling, so the manifest looks like
<asmv3:application>
<asmv3:windowsSettings >
<dpiAware xmlns="http://schemas.microsoft.com/SMI/2005/WindowsSettings">false</dpiAware>
<dpiAwareness xmlns="http://schemas.microsoft.com/SMI/2016/WindowsSettings">unaware</dpiAwareness>
<gdiScaling xmlns="http://schemas.microsoft.com/SMI/2017/WindowsSettings">true</gdiScaling>
</asmv3:windowsSettings>
</asmv3:application>
The problem is, the fonts in the Chrome window look very bad on a computer with 4k resolution and 175% scaling. (on 1k and 100% everything is normal)
I tried to use the OSR browser to solve this, but doesn't really know where to start. Is it possible?

Re: High resolutions with dpi unaware and bad fonts

Posted: Wed Sep 04, 2024 1:16 pm
by salvadordf
Hi,

Open the SimpleOSRBrowser and add this code line to the TForm1.FormCreate procedure :

Code: Select all

Panel1.ForcedDeviceScaleFactor := 1.5;  // Use the real screen scale. 1.0 = 100% scale in Windows = 96 DPI

Re: High resolutions with dpi unaware and bad fonts

Posted: Wed Sep 04, 2024 1:30 pm
by sebfischer83
Hi,

ok the fonts are better now but the page content itself is doubled in its size.

Re: High resolutions with dpi unaware and bad fonts

Posted: Thu Sep 05, 2024 8:04 am
by salvadordf
Sorry, I was confused with some other DPI setting.

Delphi applications with a CEF browser work correctly with the default "DPI awareness" value in the manifest, which is "Per monitor v2". This is the recommended setting for CEF4Delphi.

If an application doesn't have a manifest then Chromium tries to set it in code with SetProcessDpiAwarenessContext, SetProcessDpiAwareness or SetProcessDPIAware calls.

If some other DPI configurations where the application appears too small in high resolution monitors then ForcedDeviceScaleFactor can be used in OSR browsers because it simulates a screen scale even when the rest of the application ignores it.

When the manifest has a DPI configuration that causes Windows to stretch the application then there's little we can do because Windows is stretching the UI as a bitmap. It's interpolating pixels and that generates weird looking text.

Read this issue for more details :
https://github.com/chromiumembedded/cef/issues/3452
https://github.com/cefsharp/CefSharp/issues/4410

Re: High resolutions with dpi unaware and bad fonts

Posted: Tue Sep 10, 2024 12:12 pm
by sebfischer83
Ok thanks, I thought it would be possible to let render the browser content large and paint it then on the form.

Re: High resolutions with dpi unaware and bad fonts

Posted: Tue Sep 10, 2024 1:18 pm
by salvadordf
The DPI settings affect everything in the process.

Consider using WebUI4Delphi instead. It uses the web browser in the operating system to show web contents.

Re: High resolutions with dpi unaware and bad fonts

Posted: Wed Sep 11, 2024 12:52 pm
by sebfischer83
Interesting, I will look into ist.