diff --git a/src/msw/dcmemory.cpp b/src/msw/dcmemory.cpp index 9d7c52b531..7218fa34eb 100644 --- a/src/msw/dcmemory.cpp +++ b/src/msw/dcmemory.cpp @@ -148,7 +148,8 @@ void wxMemoryDCImpl::SetFont(const wxFont& font) // We need to adjust the font size by the ratio between the scale factor we // use and the default/global scale factor used when creating fonts. wxFont scaledFont = font; - scaledFont.WXAdjustToPPI(wxDisplay::GetStdPPI()*m_contentScaleFactor); + if ( scaledFont.IsOk() ) + scaledFont.WXAdjustToPPI(wxDisplay::GetStdPPI()*m_contentScaleFactor); wxMSWDCImpl::SetFont(scaledFont); } diff --git a/tests/graphics/measuring.cpp b/tests/graphics/measuring.cpp index 9248db9674..284d93123a 100644 --- a/tests/graphics/measuring.cpp +++ b/tests/graphics/measuring.cpp @@ -87,6 +87,14 @@ TEST_CASE("wxMemoryDC::GetTextExtent", "[memdc][text-extent]") wxBitmap bmp(100, 100); wxMemoryDC memdc(bmp); GetTextExtentTester testMem(memdc); + + // Under MSW, this wxDC should work even without any valid font -- but + // this is not the case under wxGTK and probably neither elsewhere, so + // restrict this test to that platform only. +#ifdef __WXMSW__ + memdc.SetFont(wxNullFont); + GetTextExtentTester testMemNoFont(memdc); +#endif // __WXMSW__ } #if wxUSE_PRINTING_ARCHITECTURE && wxUSE_POSTSCRIPT