From 8217ce0fef83a0aea3c658489c885d9bb69a3056 Mon Sep 17 00:00:00 2001 From: Jacek Caban Date: Thu, 2 Sep 2021 14:14:00 +0200 Subject: [PATCH] gdi32: Use NtGdiGetRandomRgn for GetClipRgn. Signed-off-by: Jacek Caban Signed-off-by: Huw Davies Signed-off-by: Alexandre Julliard --- dlls/gdi32/clipping.c | 36 ++++++++---------------------------- dlls/gdi32/gdidc.c | 8 ++++++++ dlls/gdi32/tests/clipping.c | 7 ++++++- include/ntgdi.h | 3 +++ 4 files changed, 25 insertions(+), 29 deletions(-) diff --git a/dlls/gdi32/clipping.c b/dlls/gdi32/clipping.c index 28a314b76b9..4f22e6f3cde 100644 --- a/dlls/gdi32/clipping.c +++ b/dlls/gdi32/clipping.c @@ -392,31 +392,6 @@ INT WINAPI NtGdiGetAppClipBox( HDC hdc, RECT *rect ) } -/*********************************************************************** - * GetClipRgn (GDI32.@) - */ -INT WINAPI GetClipRgn( HDC hdc, HRGN hRgn ) -{ - INT ret = -1; - DC * dc; - if ((dc = get_dc_ptr( hdc ))) - { - if( dc->hClipRgn ) - { - if (NtGdiCombineRgn( hRgn, dc->hClipRgn, 0, RGN_COPY ) != ERROR) - { - ret = 1; - if (dc->attr->layout & LAYOUT_RTL) - mirror_region( hRgn, hRgn, dc->attr->vis_rect.right - dc->attr->vis_rect.left ); - } - } - else ret = 0; - release_dc_ptr( dc ); - } - return ret; -} - - /*********************************************************************** * GetMetaRgn (GDI32.@) */ @@ -460,11 +435,11 @@ INT WINAPI NtGdiGetRandomRgn( HDC hDC, HRGN hRgn, INT iCode ) if (!dc) return -1; - switch (iCode) + switch (iCode & ~NTGDI_RGN_MIRROR_RTL) { case 1: - if (dc->hClipRgn) NtGdiCombineRgn( hRgn, dc->hClipRgn, 0, RGN_COPY ); - else ret = 0; + if (!dc->hClipRgn) ret = 0; + else if (!NtGdiCombineRgn( hRgn, dc->hClipRgn, 0, RGN_COPY )) ret = -1; break; case 2: if (dc->hMetaRgn) NtGdiCombineRgn( hRgn, dc->hMetaRgn, 0, RGN_COPY ); @@ -496,6 +471,11 @@ INT WINAPI NtGdiGetRandomRgn( HDC hDC, HRGN hRgn, INT iCode ) ret = -1; break; } + + /* Wine extension */ + if (ret > 0 && (iCode & NTGDI_RGN_MIRROR_RTL) && (dc->attr->layout & LAYOUT_RTL)) + mirror_region( hRgn, hRgn, dc->attr->vis_rect.right - dc->attr->vis_rect.left ); + release_dc_ptr( dc ); return ret; } diff --git a/dlls/gdi32/gdidc.c b/dlls/gdi32/gdidc.c index 0be21c75d58..6f534dce061 100644 --- a/dlls/gdi32/gdidc.c +++ b/dlls/gdi32/gdidc.c @@ -1633,6 +1633,14 @@ BOOL WINAPI SelectClipPath( HDC hdc, INT mode ) return NtGdiSelectClipPath( hdc, mode ); } +/*********************************************************************** + * GetClipRgn (GDI32.@) + */ +INT WINAPI GetClipRgn( HDC hdc, HRGN rgn ) +{ + return NtGdiGetRandomRgn( hdc, rgn, NTGDI_RGN_MIRROR_RTL | 1 ); +} + /*********************************************************************** * IntersectClipRect (GDI32.@) */ diff --git a/dlls/gdi32/tests/clipping.c b/dlls/gdi32/tests/clipping.c index 484430b0cb9..37a96de2bb4 100644 --- a/dlls/gdi32/tests/clipping.c +++ b/dlls/gdi32/tests/clipping.c @@ -42,6 +42,8 @@ static void test_GetRandomRgn(void) ret = GetRandomRgn(hdc, hrgn, 1); ok(ret == 0, "GetRandomRgn rets %d\n", ret); + ret = GetRandomRgn(hdc, NULL, 1); + ok(ret == 0, "GetRandomRgn rets %d\n", ret); ret = GetRandomRgn(hdc, hrgn, 2); ok(ret == 0, "GetRandomRgn rets %d\n", ret); ret = GetRandomRgn(hdc, hrgn, 3); @@ -84,10 +86,13 @@ static void test_GetRandomRgn(void) IntersectClipRect(hdc, rc2.left, rc2.top, rc2.right, rc2.bottom); ret = GetRandomRgn(hdc, hrgn, 1); - ok(ret != 0, "GetRandomRgn rets %d\n", ret); + ok(ret > 0, "GetRandomRgn rets %d\n", ret); GetRgnBox(hrgn, &ret_rc); ok(EqualRect(&rc2, &ret_rc), "GetRandomRgn %s\n", wine_dbgstr_rect(&ret_rc)); + ret = GetRandomRgn(hdc, NULL, 1); + ok(ret == -1, "GetRandomRgn rets %d\n", ret); + ret = GetRandomRgn(hdc, hrgn, 2); ok(ret != 0, "GetRandomRgn rets %d\n", ret); GetRgnBox(hrgn, &ret_rc); diff --git a/include/ntgdi.h b/include/ntgdi.h index 00783975e18..061ed40779c 100644 --- a/include/ntgdi.h +++ b/include/ntgdi.h @@ -178,6 +178,9 @@ struct font_enum_entry NEWTEXTMETRICEXW tm; }; +/* flag for NtGdiGetRandomRgn to respect LAYOUT_RTL */ +#define NTGDI_RGN_MIRROR_RTL 0x80000000 + #endif /* __WINESRC__ */ struct font_realization_info