From b5358cec9426cb6f7042a1c85e4f5ddbc3046940 Mon Sep 17 00:00:00 2001 From: Vadim Zeitlin Date: Thu, 7 Aug 2014 21:03:34 +0000 Subject: [PATCH] Fix drawing on wxDC when using right-to-left layout in wxMSW. Avoid integer overflow when setting wxDC scale. This affected (i.e. broke) drawing in RTL but probably not only that. Closes #16254. git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@77020 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775 --- src/msw/dc.cpp | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/src/msw/dc.cpp b/src/msw/dc.cpp index c9be187664..7b58ee93fa 100644 --- a/src/msw/dc.cpp +++ b/src/msw/dc.cpp @@ -1959,6 +1959,16 @@ void wxMSWDCImpl::RealizeScaleAndOrigin() ApplyEffectiveScale(m_scaleX, m_signX, &devExtX, &logExtX); ApplyEffectiveScale(m_scaleY, m_signY, &devExtY, &logExtY); + // In GDI anisotropic mode only devExt/logExt ratio is important + // so we can reduce the fractions to avoid large numbers + // which could cause arithmetic overflows inside Win API. + unsigned int gcd = wxGCD(abs(devExtX), abs(logExtX)); + devExtX /= gcd; + logExtX /= gcd; + gcd = wxGCD(abs(devExtY), abs(logExtY)); + devExtY /= gcd; + logExtY /= gcd; + ::SetViewportExtEx(GetHdc(), devExtX, devExtY, NULL); ::SetWindowExtEx(GetHdc(), logExtX, logExtY, NULL);