wx.ScreenDC.GetMultiLineTextExtent() is inaccurate on Mac

In testing the same wxPython application on several platforms, I discovered that wx.ScreenDC.GetMultiLineTextExtent() on the Mac (Cocoa) is not trustworthy in calculating width.

The inaccuracy depends on the font used: some seem correct, but others vary widely. Sometimes the width reported is too great, sometimes too little. I think this depends on the particular characters in the string.

I wrote a small test application (attached) that enumerates all the faces available and allows selection via a ComboBox. Then we display several lines of meaningless text in the chosen face, size 14. For each, we query the screen size and add a wx.Panel of the reported size just below the text.

Here’s an example of the result:


The system is a rather old XServe running OS 10.7;

wxPython 3.0.2.0, wxWidgets 3.0.2.

Has anyone else encountered this?

SizingTest.py (2.95 KB)