diff options
Diffstat (limited to 'win32/ScintillaWin.cxx')
-rw-r--r-- | win32/ScintillaWin.cxx | 37 |
1 files changed, 27 insertions, 10 deletions
diff --git a/win32/ScintillaWin.cxx b/win32/ScintillaWin.cxx index d3c1b87a5..efbe1f000 100644 --- a/win32/ScintillaWin.cxx +++ b/win32/ScintillaWin.cxx @@ -324,6 +324,8 @@ class ScintillaWin : static ATOM scintillaClassAtom; static ATOM callClassAtom; + int deviceScaleFactor = 1; + #if defined(USE_D2D) ID2D1RenderTarget *pRenderTarget; bool renderTargetValid; @@ -626,11 +628,23 @@ bool ScintillaWin::UpdateRenderingParams(bool force) noexcept { } hCurrentMonitor = monitor; + deviceScaleFactor = Internal::GetDeviceScaleFactorWhenGdiScalingActive(hRootWnd); renderingParams->defaultRenderingParams.reset(monitorRenderingParams); renderingParams->customRenderingParams.reset(customClearTypeRenderingParams); return true; } +namespace { + +D2D1_SIZE_U GetSizeUFromRect(const RECT &rc, const int scaleFactor) noexcept { + const long width = rc.right - rc.left; + const long height = rc.bottom - rc.top; + const UINT32 scaledWidth = width * scaleFactor; + const UINT32 scaledHeight = height * scaleFactor; + return D2D1::SizeU(scaledWidth, scaledHeight); +} + +} void ScintillaWin::EnsureRenderTarget(HDC hdc) { if (!renderTargetValid) { @@ -642,19 +656,15 @@ void ScintillaWin::EnsureRenderTarget(HDC hdc) { RECT rc; ::GetClientRect(hw, &rc); - const D2D1_SIZE_U size = D2D1::SizeU(rc.right - rc.left, rc.bottom - rc.top); - // Create a Direct2D render target. D2D1_RENDER_TARGET_PROPERTIES drtp {}; drtp.type = D2D1_RENDER_TARGET_TYPE_DEFAULT; - drtp.pixelFormat.format = DXGI_FORMAT_UNKNOWN; - drtp.pixelFormat.alphaMode = D2D1_ALPHA_MODE_UNKNOWN; - drtp.dpiX = 96.0; - drtp.dpiY = 96.0; drtp.usage = D2D1_RENDER_TARGET_USAGE_NONE; drtp.minLevel = D2D1_FEATURE_LEVEL_DEFAULT; if (technology == Technology::DirectWriteDC) { + drtp.dpiX = 96.f; + drtp.dpiY = 96.f; // Explicit pixel format needed. drtp.pixelFormat = D2D1::PixelFormat(DXGI_FORMAT_B8G8R8A8_UNORM, D2D1_ALPHA_MODE_IGNORE); @@ -669,9 +679,14 @@ void ScintillaWin::EnsureRenderTarget(HDC hdc) { } } else { + drtp.dpiX = 96.f * deviceScaleFactor; + drtp.dpiY = 96.f * deviceScaleFactor; + drtp.pixelFormat = D2D1::PixelFormat(DXGI_FORMAT_UNKNOWN, + D2D1_ALPHA_MODE_UNKNOWN); + D2D1_HWND_RENDER_TARGET_PROPERTIES dhrtp {}; dhrtp.hwnd = hw; - dhrtp.pixelSize = size; + dhrtp.pixelSize = ::GetSizeUFromRect(rc, deviceScaleFactor); dhrtp.presentOptions = (technology == Technology::DirectWriteRetain) ? D2D1_PRESENT_OPTIONS_RETAIN_CONTENTS : D2D1_PRESENT_OPTIONS_NONE; @@ -3594,10 +3609,12 @@ LRESULT PASCAL ScintillaWin::CTWndProc( surfaceWindow->Init(ps.hdc, hWnd); } else { #if defined(USE_D2D) + const int scaleFactor = sciThis->deviceScaleFactor; + // Create a Direct2D render target. D2D1_HWND_RENDER_TARGET_PROPERTIES dhrtp {}; dhrtp.hwnd = hWnd; - dhrtp.pixelSize = D2D1::SizeU(rc.right - rc.left, rc.bottom - rc.top); + dhrtp.pixelSize = ::GetSizeUFromRect(rc, scaleFactor); dhrtp.presentOptions = (sciThis->technology == Technology::DirectWriteRetain) ? D2D1_PRESENT_OPTIONS_RETAIN_CONTENTS : D2D1_PRESENT_OPTIONS_NONE; @@ -3605,8 +3622,8 @@ LRESULT PASCAL ScintillaWin::CTWndProc( drtp.type = D2D1_RENDER_TARGET_TYPE_DEFAULT; drtp.pixelFormat.format = DXGI_FORMAT_UNKNOWN; drtp.pixelFormat.alphaMode = D2D1_ALPHA_MODE_UNKNOWN; - drtp.dpiX = 96.0; - drtp.dpiY = 96.0; + drtp.dpiX = 96.f * scaleFactor; + drtp.dpiY = 96.f * scaleFactor; drtp.usage = D2D1_RENDER_TARGET_USAGE_NONE; drtp.minLevel = D2D1_FEATURE_LEVEL_DEFAULT; |