From 655afd603031bb35d83b69519897d4a427b17213 Mon Sep 17 00:00:00 2001 From: Maarten Bent Date: Sat, 28 May 2022 20:02:44 +0200 Subject: [PATCH 1/2] Fix wxBitmap::SetScaleFactor on macOS The internal scale representation has to be changed using CGContextScaleCTM. --- src/osx/core/bitmap.cpp | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/src/osx/core/bitmap.cpp b/src/osx/core/bitmap.cpp index 0f8824d81a..e1a93c67cc 100644 --- a/src/osx/core/bitmap.cpp +++ b/src/osx/core/bitmap.cpp @@ -76,7 +76,7 @@ public: bool HasAlpha() const; WXImage GetImage() const; - void SetScaleFactor(double scale) { m_scaleFactor = scale; } + void SetScaleFactor(double scale); double GetScaleFactor() const { return m_scaleFactor; } const void *GetRawAccess() const; @@ -369,6 +369,18 @@ WXImage wxBitmapRefData::GetImage() const return m_nsImage; } +void wxBitmapRefData::SetScaleFactor( double scale ) +{ + wxCHECK_RET( IsOk() , wxT("invalid bitmap") ) ; + + if ( m_scaleFactor == scale ) + return ; + + CGContextScaleCTM( m_hBitmap, 1 / GetScaleFactor(), -1 / GetScaleFactor() ); + m_scaleFactor = scale; + CGContextScaleCTM( m_hBitmap, GetScaleFactor(), -GetScaleFactor() ); +} + void wxBitmapRefData::UseAlpha( bool use ) { wxCHECK_RET( IsOk() , wxT("invalid bitmap") ) ; From 31de97a2c636d9be49bfecd88cc2e6756ff356a7 Mon Sep 17 00:00:00 2001 From: Maarten Bent Date: Sat, 28 May 2022 20:12:07 +0200 Subject: [PATCH 2/2] Use correct wxBitmap size for STC Create the wxBitmap in the expected physical size to fix rendering artifacts. CreateWithDIPSize cannot be used because when it scales the DIP size, it could be off-by-one. Remove obsolete mdc->GetImpl()->SetWindow(), this is not needed anymore because the DPI is now determined from the associated bitmap content scale factor, and not from the wxWindow. See #22450 --- src/stc/PlatWX.cpp | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/src/stc/PlatWX.cpp b/src/stc/PlatWX.cpp index 182f28e842..61d3551bdf 100644 --- a/src/stc/PlatWX.cpp +++ b/src/stc/PlatWX.cpp @@ -293,13 +293,12 @@ void SurfaceImpl::InitPixMap(int width, int height, Surface *surface, WindowID w wxMemoryDC* mdc = surface ? new wxMemoryDC(static_cast(surface)->hdc) : new wxMemoryDC(); - mdc->GetImpl()->SetWindow(GETWIN(winid)); hdc = mdc; hdcOwned = true; if (width < 1) width = 1; if (height < 1) height = 1; - bitmap = new wxBitmap(); - bitmap->CreateWithDIPSize(width, height,(GETWIN(winid))->GetDPIScaleFactor()); + bitmap = new wxBitmap(GETWIN(winid)->ToPhys(wxSize(width, height))); + bitmap->SetScaleFactor(GETWIN(winid)->GetDPIScaleFactor()); mdc->SelectObject(*bitmap); }