From 7f5ca30e3eebbdb85222fbe329a5100b4da65804 Mon Sep 17 00:00:00 2001 From: Vadim Zeitlin Date: Sat, 25 May 2024 23:18:12 +0200 Subject: [PATCH] Do not scale the size of bitmap in wxMSW Create(size, dc) overload The size passed to Create() should be interpreted in the same way as the size passed to CreateWithLogicalSize() and in wxMSW this means that it should _not_ be scaled. This makes the size of the bitmap returned by this function overload consistent with wxDC::GetSize(), so it looks like the right thing to do, even if it's a backwards-incompatible change. Closes #24559. --- docs/changes.txt | 4 ++++ src/msw/bitmap.cpp | 6 ++---- tests/graphics/bitmap.cpp | 4 ++++ 3 files changed, 10 insertions(+), 4 deletions(-) diff --git a/docs/changes.txt b/docs/changes.txt index 5d24d45e2b..346fc4319f 100644 --- a/docs/changes.txt +++ b/docs/changes.txt @@ -92,6 +92,10 @@ Changes in behaviour not resulting in compilation errors made is behaviour there incompatible with the other platforms. Please call wxWebRequest::EnablePersistentStorage() explicitly if you need it. +- In wxMSW, behaviour of wxBitmap::Create(size, dc) overload has changed to + not scale the size by the content scale factor of the DC any longer, as the + size here is expressed in physical pixels and not in DIPs. + Changes in behaviour which may result in build errors ----------------------------------------------------- diff --git a/src/msw/bitmap.cpp b/src/msw/bitmap.cpp index 66f455acc6..5e8164071b 100644 --- a/src/msw/bitmap.cpp +++ b/src/msw/bitmap.cpp @@ -751,12 +751,10 @@ bool wxBitmap::Create(int width, int height, const wxDC& dc) { wxCHECK_MSG( dc.IsOk(), false, wxT("invalid HDC in wxBitmap::Create()") ); - const double scale = dc.GetContentScaleFactor(); - - if ( !DoCreate(wxRound(width*scale), wxRound(height*scale), -1, dc.GetHDC()) ) + if ( !DoCreate(width, height, -1, dc.GetHDC()) ) return false; - GetBitmapData()->m_scaleFactor = scale; + GetBitmapData()->m_scaleFactor = dc.GetContentScaleFactor(); return true; } diff --git a/tests/graphics/bitmap.cpp b/tests/graphics/bitmap.cpp index 7f9e901d5d..5dd92cb530 100644 --- a/tests/graphics/bitmap.cpp +++ b/tests/graphics/bitmap.cpp @@ -1839,7 +1839,11 @@ TEST_CASE("Bitmap::ScaleFactor", "[bitmap][dc][scale]") // A bitmap "compatible" with this DC should also use the same scale factor. wxBitmap bmp2(4, 4, dc); CHECK( bmp2.GetScaleFactor() == 2 ); +#ifdef wxHAS_DPI_INDEPENDENT_PIXELS CHECK( bmp2.GetSize() == wxSize(8, 8) ); +#else + CHECK( bmp2.GetSize() == wxSize(4, 4) ); +#endif // A compatible bitmap created from wxImage and this DC should also inherit // the same scale factor, but its size should be still the same as that of