From 527c11cf4d123b2c6a4bcb9f50774922dc3edbc0 Mon Sep 17 00:00:00 2001 From: James Tabor Date: Thu, 22 Dec 2016 16:39:33 +0000 Subject: [PATCH] [Win32SS|RTL] - Fix clipping for Draw Text. Inspired by Katayama Hirofumi MZ patch and ComCtl32/RichEd20/UxThmems. See CORE-2201. svn path=/trunk/; revision=73475 --- reactos/win32ss/user/rtl/text.c | 58 ++++++++++++++++++++++++++++++++- 1 file changed, 57 insertions(+), 1 deletion(-) diff --git a/reactos/win32ss/user/rtl/text.c b/reactos/win32ss/user/rtl/text.c index 00a38e09030..f278bffec4e 100644 --- a/reactos/win32ss/user/rtl/text.c +++ b/reactos/win32ss/user/rtl/text.c @@ -986,6 +986,9 @@ INT WINAPI DrawTextExWorker( HDC hdc, int prefix_offset; ellipsis_data ellip; BOOL invert_y=FALSE; + + HRGN hrgn = 0; + #ifdef _WIN32K_ TRACE("%S, %d, %08x\n", str, count, flags); #else @@ -1072,7 +1075,40 @@ INT WINAPI DrawTextExWorker( HDC hdc, } if (flags & DT_CALCRECT) flags |= DT_NOCLIP; - +#ifndef _WIN32K_ ///// Fix CORE-2201. + if (!(flags & DT_NOCLIP) ) + { + int hasClip; + hrgn = CreateRectRgn(0,0,0,0); + if (hrgn) + { + hasClip = GetClipRgn(hdc, hrgn); + // If the region to be retrieved is NULL, the return value is 0. + if (hasClip != 1) + { + DeleteObject(hrgn); + hrgn = NULL; + } + IntersectClipRect(hdc, rect->left, rect->top, rect->right, rect->bottom); + } + } +#else + if (!(flags & DT_NOCLIP) ) + { + int hasClip; + hrgn = NtGdiCreateRectRgn(0,0,0,0); + if (hrgn) + { + hasClip = NtGdiGetRandomRgn(hdc, hrgn, CLIPRGN); + if (hasClip != 1) + { + GreDeleteObject(hrgn); + hrgn = NULL; + } + NtGdiIntersectClipRect(hdc, rect->left, rect->top, rect->right, rect->bottom); + } + } +#endif ///// if (flags & DT_MODIFYSTRING) { size_retstr = (count + 4) * sizeof (WCHAR); @@ -1226,6 +1262,26 @@ INT WINAPI DrawTextExWorker( HDC hdc, } while (strPtr && !last_line); +#ifndef _WIN32K_ + if (!(flags & DT_NOCLIP) ) + { + SelectClipRgn(hdc, hrgn); + if (hrgn) + { + DeleteObject(hrgn); + } + } +#else + if (!(flags & DT_NOCLIP) ) + { + NtGdiExtSelectClipRgn(hdc, hrgn, RGN_COPY); + if (hrgn) + { + GreDeleteObject(hrgn); + } + } +#endif + if (flags & DT_CALCRECT) { rect->right = rect->left + max_width;