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.
If you find these projects useful please consider becoming a sponsor with Patreon, GitHub or Liberapay.

High resolutions with dpi unaware and bad fonts

Post Reply
sebfischer83
Posts: 14
Joined: Mon Nov 30, 2020 6:37 am

High resolutions with dpi unaware and bad fonts

Post 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?
User avatar
salvadordf
Posts: 4564
Joined: Thu Feb 02, 2017 12:24 pm
Location: Spain
Contact:

Re: High resolutions with dpi unaware and bad fonts

Post 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
sebfischer83
Posts: 14
Joined: Mon Nov 30, 2020 6:37 am

Re: High resolutions with dpi unaware and bad fonts

Post by sebfischer83 »

Hi,

ok the fonts are better now but the page content itself is doubled in its size.
User avatar
salvadordf
Posts: 4564
Joined: Thu Feb 02, 2017 12:24 pm
Location: Spain
Contact:

Re: High resolutions with dpi unaware and bad fonts

Post 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
sebfischer83
Posts: 14
Joined: Mon Nov 30, 2020 6:37 am

Re: High resolutions with dpi unaware and bad fonts

Post by sebfischer83 »

Ok thanks, I thought it would be possible to let render the browser content large and paint it then on the form.
User avatar
salvadordf
Posts: 4564
Joined: Thu Feb 02, 2017 12:24 pm
Location: Spain
Contact:

Re: High resolutions with dpi unaware and bad fonts

Post 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.
sebfischer83
Posts: 14
Joined: Mon Nov 30, 2020 6:37 am

Re: High resolutions with dpi unaware and bad fonts

Post by sebfischer83 »

Interesting, I will look into ist.
Post Reply