Skip to content

Commit ebdb184

Browse files
committed
Fix issues with High DPI support on Windows (#358).
Both main process and subprocesses are now set to be DPI aware when cef.DpiAware.EnableHighDpiSupport function is called. - Update docs/MigrationGuide.md document. - Update examples/wxpython.py - Add DpiAware.EnableHighDpiSupport function. - Deprecate DpiAware.SetProcessDpiAware function. - Deprecate ApplicationSettings.auto_zooming "system_dpi" value
1 parent 5810d67 commit ebdb184

13 files changed

+80
-22
lines changed

.gitignore

+2
Original file line numberDiff line numberDiff line change
@@ -7,3 +7,5 @@ __pycache__/
77
cefclient
88
webcache/
99
examples/screenshot.png
10+
examples/pyinstaller/build/
11+
examples/pyinstaller/dist/

README.md

+1
Original file line numberDiff line numberDiff line change
@@ -476,6 +476,7 @@ Additional information for v31.2 release:
476476
* [DownloadHandler](api/DownloadHandler.md#downloadhandler)
477477
* [DpiAware (class)](api/DpiAware.md#dpiaware-class)
478478
* [CalculateWindowSize](api/DpiAware.md#calculatewindowsize)
479+
* [EnableHighDpiSupport](api/DpiAware.md#enablehighdpisupport)
479480
* [GetSystemDpi](api/DpiAware.md#getsystemdpi)
480481
* [IsProcessDpiAware](api/DpiAware.md#isprocessdpiaware)
481482
* [SetProcessDpiAware](api/DpiAware.md#setprocessdpiaware)

api/API-index.md

+1
Original file line numberDiff line numberDiff line change
@@ -209,6 +209,7 @@
209209
* [DownloadHandler](DownloadHandler.md#downloadhandler)
210210
* [DpiAware (class)](DpiAware.md#dpiaware-class)
211211
* [CalculateWindowSize](DpiAware.md#calculatewindowsize)
212+
* [EnableHighDpiSupport](DpiAware.md#enablehighdpisupport)
212213
* [GetSystemDpi](DpiAware.md#getsystemdpi)
213214
* [IsProcessDpiAware](DpiAware.md#isprocessdpiaware)
214215
* [SetProcessDpiAware](DpiAware.md#setprocessdpiaware)

api/ApplicationSettings.md

+6-3
Original file line numberDiff line numberDiff line change
@@ -84,14 +84,17 @@ all processes.
8484
### auto_zooming
8585

8686
(string)
87-
Windows only. Perform automatic zooming of browser contents. Example values for auto_zooming (numeric value means a zoom level):
87+
Windows only. Perform automatic zooming of browser contents. Example
88+
values for auto_zooming (numeric value means a zoom level):
8889

89-
* "system_dpi" - use system DPI settings, see the [DpiAware](DpiAware.md) wiki page for more details.
90+
* "" - default is empty string
9091
* "0.0" (96 DPI)
9192
* "1.0" (120 DPI)
9293
* "2.0" (144 DPI)
9394
* "-1.0" (72 DPI)
94-
* "" - if cefpython detects that application is DPI aware it will automatically set `auto_zooming` to "system_dpi". If you do not wish such behavior set `auto_zooming` to an empty string. See the [DpiAware](DpiAware.md) wiki page for more details on that.
95+
* "system_dpi" - Deprecated. Use system DPI settings. This value is
96+
deprecated, as it is no more required to set auto_zooming to this
97+
value after High DPI support was enabled.
9598

9699
Example values that can be set in Win7 DPI settings (Control Panel Appearance and Personalization Display):
97100

api/DpiAware.md

+24-9
Original file line numberDiff line numberDiff line change
@@ -12,23 +12,19 @@ Table of contents:
1212
* [Introduction](#introduction)
1313
* [Static methods](#static-methods)
1414
* [CalculateWindowSize](#calculatewindowsize)
15+
* [EnableHighDpiSupport](#enablehighdpisupport)
1516
* [GetSystemDpi](#getsystemdpi)
1617
* [IsProcessDpiAware](#isprocessdpiaware)
1718
* [SetProcessDpiAware](#setprocessdpiaware)
1819

1920

20-
## Introduction
21-
22-
By default if DPI awareness is not enabled in application, then OS performs display scaling. That causes text to look fuzzy on high DPI displays. The solution is to enable DPI awareness and use the ApplicationSettings.`auto_zooming` option. High DPI support is available only on Windows.
23-
24-
Enabling High DPI support in app can be done by embedding a DPI awareness xml manifest in executable (see [Issue #112](../issues/112) comment #2), or by calling the `DpiAware.SetProcessDpiAware` method. Embedding xml manifest is the most reliable method. There is also an another way by writing registry key, but we won't discuss this method here.
25-
26-
The downside of calling `SetProcessDpiAware` is that scrollbar in CEF browser is very small. This is because DPI awareness was set too late, after executable and the CEF dll was loaded. To fix that embed DPI awareness xml manifest in the .exe file.
2721

28-
Additionally you have to set the ApplicationSettings.`auto_zomming` option to "system_dpi". This will cause browser content to be zoomed automatically using system DPI settings. On Win7 these can be set in: Control Panel > Appearance and Personalization > Display.
22+
## Introduction
2923

30-
When cefpyhon detects that application is DPI aware, it will automatically set ApplicationSettings."auto_zooming" to "system_dpi". User can manually enable DPI awareness in application by going to .exe properties > Compatibility tab > and checking the box labeled "Disable display scaling on high DPI settings". If you wish to not enable auto zooming in such case then set "auto_zooming" to an empty string.
24+
By default if DPI awareness is not enabled in application, then OS performs display scaling. That causes text to look blurry on high DPI displays. To resolve this you have to
25+
call `cef.DpiAware.EnableHighDpiSupport` method. High DPI support is available only on Windows.
3126

27+
Enabling High DPI support in app can be done by embedding a DPI awareness xml manifest in both main executable and subprocess executable (see [Issue #112](../issues/112) comment #2), or by calling the `cef.DpiAware.EnableHighDpiSupport` method.
3228

3329
## Static methods
3430

@@ -49,6 +45,21 @@ Calculation for DPI < 96 is not yet supported. Use
4945
the `GetSystemDpi` method for that.
5046

5147

48+
### EnableHighDpiSupport
49+
50+
| | |
51+
| --- | --- |
52+
| __Return__ | void |
53+
54+
Calling this function will set current process and subprocesses
55+
to be DPI aware.
56+
57+
Description from upstream CEF:
58+
> Call during process startup to enable High-DPI support on Windows 7 or newer.
59+
> Older versions of Windows should be left DPI-unaware because they do not
60+
> support DirectWrite and GDI fonts are kerned very badly.
61+
62+
5263
### GetSystemDpi
5364

5465
| | |
@@ -90,4 +101,8 @@ On Win8 this will return True if DPI awareness is set to either "System DPI awar
90101
| --- | --- |
91102
| __Return__ | void |
92103

104+
Calling this method is deprecated, call instead `EnableHighDpiSupport()`.
105+
See [Issue #358](../../../issues/358) for how the behavior changed in
106+
latest CEF. This method now internally calls `EnableHighDpiSupport()`.
107+
93108
Enables DPI awareness for the running process. Embedding a DPI manifest in .exe is the prefered way, as it gives more reliable results, otherwise some display bugs may appear (discussed in the "Introduction" section on this page).

docs/Migration-guide.md

+14
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ Table of contents:
3535
* [v55+ HTTPS cache problems on pages with certificate errors](#v55-https-cache-problems-on-pages-with-certificate-errors)
3636
* [v55.3+ Handlers' callbacks and other interfaces](#v553-handlers-callbacks-and-other-interfaces)
3737
* [v56+ MacOS 10.9+ required to run](#v56-macos-109-required-to-run)
38+
* [v57.1+ High DPI support on Windows](#v571-high-dpi-support-on-windows)
3839

3940

4041

@@ -281,3 +282,16 @@ your code will definitely break, unless you've also used
281282
## v56+ MacOS 10.9+ required to run
282283

283284
CEF v55 was the last version to support MacOS 10.7.
285+
286+
287+
## v57.1+ High DPI support on Windows
288+
289+
The `cef.DpiAware.SetProcessDpiAware` function is now deprecated.
290+
Use cef.DpiAware.[EnableHighDpiSupport](../api/DpiAware.md#enablehighdpisupport)
291+
function instead.
292+
293+
The ApplicationSettings.[auto_zooming](../api/ApplicationSettings.md#auto_zooming)
294+
option should have its value set to an empty string (a default now)
295+
for High DPI support. In previous versions the default value was
296+
"system_dpi" and if you have set it explicitilly in your application,
297+
then you should change it to an empty string now.

examples/wxpython.py

+1-2
Original file line numberDiff line numberDiff line change
@@ -34,9 +34,8 @@ def main():
3434
sys.excepthook = cef.ExceptHook # To shutdown all CEF processes on error
3535
settings = {}
3636
if WINDOWS:
37-
settings["auto_zooming"] = "system_dpi" # High DPI support
3837
# noinspection PyUnresolvedReferences, PyArgumentList
39-
cef.DpiAware.SetProcessDpiAware() # Alternative is to embed manifest
38+
cef.DpiAware.EnableHighDpiSupport()
4039
cef.Initialize(settings=settings)
4140
app = CefApp(False)
4241
app.MainLoop()

src/cefpython.pyx

-4
Original file line numberDiff line numberDiff line change
@@ -666,10 +666,6 @@ def Initialize(applicationSettings=None, commandLineSwitches=None, **kwargs):
666666
application_settings["downloads_enabled"] = True
667667
if "remote_debugging_port" not in application_settings:
668668
application_settings["remote_debugging_port"] = 0
669-
if "auto_zooming" not in application_settings:
670-
IF UNAME_SYSNAME == "Windows":
671-
if DpiAware.IsProcessDpiAware():
672-
application_settings["auto_zooming"] = "system_dpi"
673669
if "app_user_model_id" in application_settings:
674670
g_commandLineSwitches["app-user-model-id"] =\
675671
application_settings["app_user_model_id"]

src/compile_time_constants.pxi

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
# This file was generated by setup.py
2-
DEF UNAME_SYSNAME = "Linux"
3-
DEF PY_MAJOR_VERSION = 2
2+
DEF UNAME_SYSNAME = "Windows"
3+
DEF PY_MAJOR_VERSION = 3

src/dpi_aware_win.pyx

+8-1
Original file line numberDiff line numberDiff line change
@@ -37,4 +37,11 @@ class DpiAware:
3737

3838
@staticmethod
3939
def SetProcessDpiAware():
40-
SetProcessDpiAware()
40+
"""Deprecated."""
41+
DpiAware.EnableHighDpiSupport()
42+
43+
@staticmethod
44+
def EnableHighDpiSupport():
45+
# This CEF function sets process to be DPI aware. This
46+
# CEF func is also called in subprocesses.
47+
CefEnableHighDPISupport()

src/extern/cef/cef_app.pxd

+2
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,8 @@ cdef extern from "include/cef_app.h":
2323
cdef cppclass CefApp:
2424
pass
2525

26+
cdef void CefEnableHighDPISupport() nogil
27+
2628
cdef int CefExecuteProcess(CefMainArgs& args,
2729
CefRefPtr[CefApp] application,
2830
void* windows_sandbox_info

src/subprocess/cefpython_app.cpp

+8-1
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,9 @@
1515
#endif // OS_WIN
1616

1717
#ifdef BROWSER_PROCESS
18-
#ifdef OS_LINUX
18+
#ifdef OS_WIN
19+
#include "client_handler/dpi_aware.h"
20+
#elif OS_LINUX // OS_WIN
1921
#include <gtk/gtk.h>
2022
#include <gdk/gdk.h>
2123
#include <gdk/gdkx.h>
@@ -175,6 +177,11 @@ void CefPythonApp::OnBeforeChildProcessLaunch(
175177
#ifdef BROWSER_PROCESS
176178
// This is included only in the Browser process, when building
177179
// the libcefpythonapp library.
180+
if (IsProcessDpiAware()) {
181+
// It is required to set DPI awareness in subprocesses
182+
// as well, see Issue #358.
183+
command_line->AppendSwitch("enable-high-dpi-support");
184+
}
178185
BrowserProcessHandler_OnBeforeChildProcessLaunch(command_line);
179186
#endif // BROWSER_PROCESS
180187

src/subprocess/main.cpp

+11
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,17 @@ int APIENTRY wWinMain(HINSTANCE hInstance,
1414
{
1515
UNREFERENCED_PARAMETER(hPrevInstance);
1616
UNREFERENCED_PARAMETER(lpCmdLine);
17+
18+
// lpCmdLine does not include program name argument, must
19+
// use GetCommandLineW(). Cannot use CefCommandLine::GetGlobalCommandLine,
20+
// as CEF was not yet initialized.
21+
CefRefPtr<CefCommandLine> command_line = \
22+
CefCommandLine::CreateCommandLine();
23+
command_line->InitFromString(GetCommandLineW());
24+
if (command_line->HasSwitch("enable-high-dpi-support")) {
25+
CefEnableHighDPISupport();
26+
}
27+
1728
CefMainArgs mainArgs(hInstance);
1829

1930
#else // defined(OS_WIN)

0 commit comments

Comments
 (0)