Fix wxMemoryDC::SetFont(wxNullFont) broken by recent changes
Fix crash in this function introduced by 9e5c8a8027 (Respect bitmap
content scale factor in wxMSW wxMemoryDC, 2022-03-26).
Also add a unit test ensuring that this doesn't get broken again under
MSW, which seems to be the only place where it works.
Closes #22240.
This commit is contained in:
@@ -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);
|
||||
}
|
||||
|
||||
|
||||
@@ -87,6 +87,14 @@ TEST_CASE("wxMemoryDC::GetTextExtent", "[memdc][text-extent]")
|
||||
wxBitmap bmp(100, 100);
|
||||
wxMemoryDC memdc(bmp);
|
||||
GetTextExtentTester<wxMemoryDC> 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<wxMemoryDC> testMemNoFont(memdc);
|
||||
#endif // __WXMSW__
|
||||
}
|
||||
|
||||
#if wxUSE_PRINTING_ARCHITECTURE && wxUSE_POSTSCRIPT
|
||||
|
||||
Reference in New Issue
Block a user