How to change the GraphicsContext backend

I’m using the wx.svg to render SVG drawings on Windows 10. It gets displayed, but missing the text in the drawing. The same SVG file is correctly rendered in Internet Explorer with text. Another issue is I get a green background, even thought I set the background color to “white” following the example in the documentation.

I wonder if these are due to the default GDI+ backend, the documentation says that Direct2D does better.

How do I change the backend to Direct2D from the default?

IIRC, text in the SVG code is still only partially implemented. If the text has been converted to shapes in the SVG file then it will be rendered as expected, but if it’s left as a text object then it will likely be ignored.

You can create a specific GC renderer with something like this:

        if 'wxMSW' in wx.PlatformInfo:
            self.renderer = wx.GraphicsRenderer.GetDirect2DRenderer()
        else:
            self.renderer = wx.GraphicsRenderer.GetDefaultRenderer()

And then in your EVT_PAINT handler you can create the context like this:

        ctx = self.renderer.CreateContext(dc)

Also, the Cairo renderer works well on Windows so you may want to try that too and compare. Finally, as shown in the demo you can also render the SVG directly to a wx.Bitmap without use of the GC renderers if that works better for your use-case.

Robin,

Thanks for the response. I rendered directly to wx.Bitmap and the background is no longer green. I prefer this approach as I wish to scale and move the image.