Skip to content

Commit 331bfb5

Browse files
committed
Fix issues with High DPI support on Windows (cztomczak#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 682e273 commit 331bfb5

File tree

13 files changed

+136
-76
lines changed

13 files changed

+136
-76
lines changed

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,3 +6,5 @@ __pycache__/
66
cefclient
77
webcache/
88
examples/screenshot.png
9+
examples/pyinstaller/build/
10+
examples/pyinstaller/dist/

README.md

Lines changed: 56 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -158,65 +158,66 @@ directly.
158158

159159
### API categories
160160

161-
#### Modules
162-
163-
* [cefpython](api/cefpython.md#cefpython) module
164-
165-
166-
#### Settings
167-
168-
* [ApplicationSettings](api/ApplicationSettings.md#application-settings) dictionary
169-
* [BrowserSettings](api/BrowserSettings.md#browser-settings) dictionary
170-
* [CommandLineSwitches](api/CommandLineSwitches.md#command-line-switches) dictionary
171-
172-
173-
#### Classes and objects
174-
175-
* [Browser](api/Browser.md#browser-object) object
176-
* [Callback](api/Callback.md#callback-object) object
177-
* [Cookie](api/Cookie.md#cookie-class) class
178-
* [CookieManager](api/CookieManager.md#cookiemanager-class) class
179-
* [DpiAware](api/DpiAware.md#dpiaware-class) class (Win)
180-
* [DragData](api/DragData.md#dragdata-object) object
181-
* [Frame](api/Frame.md#frame-object) object
182-
* [Image](api/Image.md#image-object) object
183-
* [JavascriptBindings](api/JavascriptBindings.md#javascriptbindings-class) class
184-
* [JavascriptCallback](api/JavascriptCallback.md#javascriptcallback-object) object
185-
* [PaintBuffer](api/PaintBuffer.md#paintbuffer-object) object
186-
* [Request](api/Request.md#request-class) class
187-
* [Response](api/Response.md#response-object) object
188-
* [WebPluginInfo](api/WebPluginInfo.md#webplugininfo-object) object
189-
* [WebRequest](api/WebRequest.md#webrequest-class) class
190-
* [WindowInfo](api/WindowInfo.md#windowinfo-class) class
191-
* [WindowUtils](api/WindowUtils.md#windowutils-class) class
192-
193-
194-
#### Client handlers (interfaces)
195-
196-
* [DisplayHandler](api/DisplayHandler.md#displayhandler-interface)
197-
* [DownloadHandler](api/DownloadHandler.md#downloadhandler)
198-
* [FocusHandler](api/FocusHandler.md#focushandler-interface)
199-
* [JavascriptDialogHandler](api/JavascriptDialogHandler.md#javascriptdialoghandler-interface)
200-
* [KeyboardHandler](api/KeyboardHandler.md#keyboardhandler-interface)
201-
* [LifespanHandler](api/LifespanHandler.md#lifespanhandler-interface)
202-
* [LoadHandler](api/LoadHandler.md#loadhandler-interface)
203-
* [RenderHandler](api/RenderHandler.md#renderhandler-interface)
204-
* [RequestHandler](api/RequestHandler.md#requesthandler-interface)
205-
* [ResourceHandler](api/ResourceHandler.md#resourcehandler-interface)
206-
* [V8ContextHandler](api/V8ContextHandler.md#v8contexthandler-interface)
207-
208-
209-
#### Other interfaces
210-
211-
* [CookieVisitor](api/CookieVisitor.md#cookievisitor-interface) interface
212-
* [StringVisitor](api/StringVisitor.md#stringvisitor-interface) interface
213-
* [WebRequestClient](api/WebRequestClient.md#webrequestclient-interface) interface
214-
161+
#### Modules
162+
163+
* [cefpython](api/cefpython.md#cefpython) module
164+
165+
166+
#### Settings
167+
168+
* [ApplicationSettings](api/ApplicationSettings.md#application-settings) dictionary
169+
* [BrowserSettings](api/BrowserSettings.md#browser-settings) dictionary
170+
* [CommandLineSwitches](api/CommandLineSwitches.md#command-line-switches) dictionary
171+
172+
173+
#### Classes and objects
174+
175+
* [Browser](api/Browser.md#browser-object) object
176+
* [Callback](api/Callback.md#callback-object) object
177+
* [Cookie](api/Cookie.md#cookie-class) class
178+
* [CookieManager](api/CookieManager.md#cookiemanager-class) class
179+
* [DpiAware](api/DpiAware.md#dpiaware-class) class (Win)
180+
* [DragData](api/DragData.md#dragdata-object) object
181+
* [Frame](api/Frame.md#frame-object) object
182+
* [Image](api/Image.md#image-object) object
183+
* [JavascriptBindings](api/JavascriptBindings.md#javascriptbindings-class) class
184+
* [JavascriptCallback](api/JavascriptCallback.md#javascriptcallback-object) object
185+
* [PaintBuffer](api/PaintBuffer.md#paintbuffer-object) object
186+
* [Request](api/Request.md#request-class) class
187+
* [Response](api/Response.md#response-object) object
188+
* [WebPluginInfo](api/WebPluginInfo.md#webplugininfo-object) object
189+
* [WebRequest](api/WebRequest.md#webrequest-class) class
190+
* [WindowInfo](api/WindowInfo.md#windowinfo-class) class
191+
* [WindowUtils](api/WindowUtils.md#windowutils-class) class
192+
193+
194+
#### Client handlers (interfaces)
195+
196+
* [DisplayHandler](api/DisplayHandler.md#displayhandler-interface)
197+
* [DownloadHandler](api/DownloadHandler.md#downloadhandler)
198+
* [FocusHandler](api/FocusHandler.md#focushandler-interface)
199+
* [JavascriptDialogHandler](api/JavascriptDialogHandler.md#javascriptdialoghandler-interface)
200+
* [KeyboardHandler](api/KeyboardHandler.md#keyboardhandler-interface)
201+
* [LifespanHandler](api/LifespanHandler.md#lifespanhandler-interface)
202+
* [LoadHandler](api/LoadHandler.md#loadhandler-interface)
203+
* [RenderHandler](api/RenderHandler.md#renderhandler-interface)
204+
* [RequestHandler](api/RequestHandler.md#requesthandler-interface)
205+
* [ResourceHandler](api/ResourceHandler.md#resourcehandler-interface)
206+
* [V8ContextHandler](api/V8ContextHandler.md#v8contexthandler-interface)
207+
208+
209+
#### Other interfaces
210+
211+
* [CookieVisitor](api/CookieVisitor.md#cookievisitor-interface) interface
212+
* [StringVisitor](api/StringVisitor.md#stringvisitor-interface) interface
213+
* [WebRequestClient](api/WebRequestClient.md#webrequestclient-interface) interface
214+
215215

216216
### API index
217217

218218
* [Application settings](api/ApplicationSettings.md#application-settings)
219219
* [accept_language_list](api/ApplicationSettings.md#accept_language_list)
220+
* [app_user_model_id](api/ApplicationSettings.md#app_user_model_id)
220221
* [auto_zooming](api/ApplicationSettings.md#auto_zooming)
221222
* [background_color](api/ApplicationSettings.md#background_color)
222223
* [browser_subprocess_path](api/ApplicationSettings.md#browser_subprocess_path)
@@ -420,6 +421,7 @@ directly.
420421
* [DownloadHandler](api/DownloadHandler.md#downloadhandler)
421422
* [DpiAware (class)](api/DpiAware.md#dpiaware-class)
422423
* [CalculateWindowSize](api/DpiAware.md#calculatewindowsize)
424+
* [EnableHighDpiSupport](api/DpiAware.md#enablehighdpisupport)
423425
* [GetSystemDpi](api/DpiAware.md#getsystemdpi)
424426
* [IsProcessDpiAware](api/DpiAware.md#isprocessdpiaware)
425427
* [SetProcessDpiAware](api/DpiAware.md#setprocessdpiaware)

api/API-index.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
* [Application settings](ApplicationSettings.md#application-settings)
66
* [accept_language_list](ApplicationSettings.md#accept_language_list)
7+
* [app_user_model_id](ApplicationSettings.md#app_user_model_id)
78
* [auto_zooming](ApplicationSettings.md#auto_zooming)
89
* [background_color](ApplicationSettings.md#background_color)
910
* [browser_subprocess_path](ApplicationSettings.md#browser_subprocess_path)
@@ -207,6 +208,7 @@
207208
* [DownloadHandler](DownloadHandler.md#downloadhandler)
208209
* [DpiAware (class)](DpiAware.md#dpiaware-class)
209210
* [CalculateWindowSize](DpiAware.md#calculatewindowsize)
211+
* [EnableHighDpiSupport](DpiAware.md#enablehighdpisupport)
210212
* [GetSystemDpi](DpiAware.md#getsystemdpi)
211213
* [IsProcessDpiAware](DpiAware.md#isprocessdpiaware)
212214
* [SetProcessDpiAware](DpiAware.md#setprocessdpiaware)

api/ApplicationSettings.md

Lines changed: 6 additions & 3 deletions
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

Lines changed: 24 additions & 9 deletions
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

Lines changed: 14 additions & 0 deletions
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

Lines changed: 1 addition & 2 deletions
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

Lines changed: 0 additions & 4 deletions
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

Lines changed: 2 additions & 2 deletions
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

Lines changed: 8 additions & 1 deletion
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()

0 commit comments

Comments
 (0)