Phoenix
Phoenix copied to clipboard
Windows scaling factor is applied twice to SVG images when loaded from XRC
Operating system: Win 11 64bit wxPython version & source: 4.2.3 msw (phoenix) wxWidgets 3.2.7 from PyPI Python version & source: 3.13.8 (main, Oct 7 2025, 15:31:04) [MSC v.1944 64 bit (AMD64)]
Description of the problem:
In Windows Display Settings, set Scale to 100%. Example app below looks as expected:
Set Scale to 200%, button is scaled to 200% but SVG to 400%:
When loading the SVG manually, scaling works fine, see commented section in demo_dialog.py below - although I would have expected the need to use FromDIP(), but when I do that we're back to 400%.
Code Example (click to expand)
demo_dialog.py
import ctypes
PROCESS_PER_MONITOR_DPI_AWARE = 2
ctypes.windll.shcore.SetProcessDpiAwareness(PROCESS_PER_MONITOR_DPI_AWARE)
import wx
import wx.xrc
app = wx.App()
dialog = wx.xrc.XmlResource("demo_dialog.xrc").LoadDialog(None, "DemoDialog")
# Workaround:
#import wx.svg
#svg_img = wx.svg.SVGimage.CreateFromFile("icon.svg")
#bitmap = svg_img.ConvertToScaledBitmap(wx.Size(55, 44))
#dialog.FindWindowByName("svg").SetBitmap(bitmap)
dialog.ShowModal()
dialog.Destroy()
app.MainLoop()
demo_dialog.xrc
<?xml version="1.0" ?>
<resource>
<object class="wxDialog" name="DemoDialog">
<object class="wxBoxSizer">
<orient>wxHORIZONTAL</orient>
<object class="sizeritem">
<object class="wxStaticBitmap">
<bitmap default_size="55,44">icon.svg</bitmap>
</object>
</object>
<object class="sizeritem">
<object class="wxButton">
<label>Button</label>
<size>55,44</size>
</object>
</object>
</object>
</object>
</resource>
icon.svg
<?xml version='1.0' encoding='utf-8'?>
<svg xmlns="http://www.w3.org/2000/svg" width="800px" height="800px" viewBox="-3 -3 30 30">
<g><rect x="-3" y="-3" width="30" height="30" rx="0" fill="red" /></g>
<path d="M5 6H19M5 10H19M5 14H19M5 18H19" stroke="#000000" />
</svg>