Message Boards Message Boards

Avoid EMF exported with white spaces if screen text size sets to 150%?


Hi, I am on Windows 7 and have tried Mathematica v9 and v11, both have the same issue when the system's screen text size sets to 150% (you can do so by going to 'Screen Resolution'->'Make text and other items larger or smaller'), emf exported from a graph will come with white spaces on the bottom and right hand sides, like screen shot below. Other image types (png, jpg, bmp, pdf) are exported fine though. How do I work around this? It looks like a bug in Mathematica. enter image description here

1 year ago

Description of the problem

I confirm this problem with Mathematica versions 5.2 (Export as WMF because this version doesn't support EMF export), 8.0.4, 10.4.1 and 11.0.1 on Windows 7 x64 when the system-wide screen resolution is set to 150% on the OS level:


I've checked all the ways to produce a metafile (Export, Save Selection As…, Save Graphic As…, FrontEndTokenExecute[EvaluationNotebook[], "SelectionConvert", "Metafile"]) and got identical results: exported metafile has 50% white margins added at the right and at the bottom.


Changing FrontEnd option FontProperties -> {"ScreenResolution" -> 72} doesn't affect this behavior. The problem doesn't appear when the system-wide screen resolution is set to 100% or 125%.


On the corresponding Windows Control Panel page apart from three alternative resolutions 100%, 125% and 150% suggested on the right pane, there is the "Set custom text size (DPI)" item on the left pane:


When clicking on this item you get the following dialog:


Notice the "Use Windows XP style DPI scaling" checkbox - it is the key! But what it does? Citing this article (emphasis is mine),

Un-checking this checkbox causes Windows to use the desktop composition engine to perform DPI scaling for all applications that don’t explicitly mark themselves as DPI aware via manifest. In this case, the composition engine will use your graphics hardware to scale the bitmap output of the window to a larger size, and apply an input transform to any mouse-clicks on the window to route them back to the right place in "real coordinates" for the application. The OS will also virtualize the system DPI for that application, so that it thinks it is running at 96DPI. This applies to most traditional Win32, GDI based applications.

This checkbox is checked by default when you select resolution 100% or 125% on the right, but it is un-checked when you select resolution 150%. Moreover, if you manually check this checkbox for resolution 150%, it will be un-checked automatically! But it will be kept checked if you enter, for example, resolution 160% in the "Scale to this percentage of normal size" combo box of the second dialog. After changing the resolution you need to log off the user and log on the user again for the changes to take effect, and you'll see that the problem with Export to EMF disappeared!

  • A side note: according to the above citation, this checkbox shouldn't have effect on applications which correctly mark themselves as DPI aware via manifest. Therefore Mathematica version 11.0.1 either still isn't DPI aware or has a bug in how it marks itself as DPI aware...

So now we have at least a workaround. But what if you really need resolution exactly 150%? It is possible! By monitoring the system registry I've found that the "Use Windows XP style DPI scaling" checkbox in the second dialog corresponds to the "UseDpiScaling" DWORD key in HKEY_CURRENT_USER\Software\Microsoft\Windows\DWM. The value 0 corresponds to the checkbox being checked, and the value 1 corresponds to the un-checked checkbox.

A word of warning: modifying the system registry is a potentially dangerous operation which may damage your system. It is recommended to backup important data before you proceed.

For changing the value of this key, open the Windows Registry Editor and select HKEY_CURRENT_USER\Software\Microsoft\Windows\DWM key on le left:


Double click on the "UseDpiScaling" DWORD key on the right, enter 0 and press Enter. You'll see the following:


Now you need to log off the user and then log on the user again for the changes to take effect. Then check Export to EMF: now generated EMF figure has no white borders when pasted in MS Word:



P.S. Related articles:

POSTED BY: Alexey Popkov
1 year ago

Group Abstract Group Abstract