From 09521f81e9d72097de6b2d5f1122d9e5f33a542e Mon Sep 17 00:00:00 2001 From: Artur Wieczorek <7330332+a-wi@users.noreply.github.com> Date: Tue, 27 Dec 2022 11:14:18 +0100 Subject: [PATCH] Test whether wxDC attributes are unchanged by clipping operations --- tests/graphics/clippingbox.cpp | 66 ++++++++++++++++++++++++++++++++++ 1 file changed, 66 insertions(+) diff --git a/tests/graphics/clippingbox.cpp b/tests/graphics/clippingbox.cpp index 5b13cd8075..afcf63bccb 100644 --- a/tests/graphics/clippingbox.cpp +++ b/tests/graphics/clippingbox.cpp @@ -1817,6 +1817,37 @@ static void TwoDevRegionsNonOverlappingNegDim(wxDC& dc, const wxBitmap& bmp, boo 0, 0, 0, 0); } +static void DcAttributes(wxDC& dc) +{ + // Check if wxDC atrributes left unchanged + wxFont font = dc.GetFont().Bold().Smaller(); + wxPen pen(*wxYELLOW, 2); + wxBrush brush = *wxBLUE_BRUSH; + + wxDCFontChanger fontChanger(dc, font); + wxDCPenChanger penChanger(dc, pen); + wxDCBrushChanger brushChanger(dc, brush); + wxCoord chWidth = dc.GetCharWidth(); + wxCoord chHeight = dc.GetCharHeight(); + wxFontMetrics fm = dc.GetFontMetrics(); + + dc.SetClippingRegion(10, 20, 30, 40); + dc.DestroyClippingRegion(); + + CHECK(dc.GetFont() == font); + CHECK(dc.GetPen() == pen); + CHECK(dc.GetBrush() == brush); + CHECK(dc.GetCharWidth() == chWidth); + CHECK(dc.GetCharHeight() == chHeight); + wxFontMetrics fm2 = dc.GetFontMetrics(); + CHECK(fm2.ascent == fm.ascent); + CHECK(fm2.averageWidth == fm.averageWidth); + CHECK(fm2.descent == fm.descent); + CHECK(fm2.externalLeading == fm.externalLeading); + CHECK(fm2.height == fm.height); + CHECK(fm2.internalLeading == fm.internalLeading); +} + // Tests specific to wxGCDC #if wxUSE_GRAPHICS_CONTEXT static void InitialStateWithRotatedGCForDC(wxGCDC& dc, const wxBitmap& bmp, const wxPoint& parentDcOrigin) @@ -2198,6 +2229,11 @@ TEST_CASE("ClippingBoxTestCase::wxDC", "[clip][dc]") { TwoDevRegionsNonOverlappingNegDim(dc, bmp, true); } + + SECTION("DCAttributes") + { + DcAttributes(dc); + } } #if wxUSE_GRAPHICS_CONTEXT @@ -2537,6 +2573,11 @@ TEST_CASE("ClippingBoxTestCase::wxGCDC", "[clip][dc][gcdc]") TwoDevRegionsNonOverlappingNegDim(dc, bmp, true); } + SECTION("DCAttributes") + { + DcAttributes(dc); + } + SECTION("InitialStateWithRotatedGCForDC") { InitialStateWithRotatedGCForDC(dc, bmp, dcOrigin); @@ -2882,6 +2923,11 @@ TEST_CASE("ClippingBoxTestCase::wxGCDC(GDI+)", "[clip][dc][gcdc][gdiplus]") TwoDevRegionsNonOverlappingNegDim(dc, bmp, true); } + SECTION("DCAttributes") + { + DcAttributes(dc); + } + SECTION("InitialStateWithRotatedGCForDC") { InitialStateWithRotatedGCForDC(dc, bmp, dcOrigin); @@ -3226,6 +3272,11 @@ TEST_CASE("ClippingBoxTestCase::wxGCDC(Direct2D)", "[clip][dc][gcdc][direct2d]") TwoDevRegionsNonOverlappingNegDim(dc, bmp, true); } + SECTION("DCAttributes") + { + DcAttributes(dc); + } + SECTION("InitialStateWithRotatedGCForDC") { InitialStateWithRotatedGCForDC(dc, bmp, dcOrigin); @@ -3575,6 +3626,11 @@ TEST_CASE("ClippingBoxTestCase::wxGCDC(Cairo)", "[clip][dc][gcdc][cairo]") TwoDevRegionsNonOverlappingNegDim(dc, bmp, true); } + SECTION("DCAttributes") + { + DcAttributes(dc); + } + SECTION("InitialStateWithRotatedGCForDC") { InitialStateWithRotatedGCForDC(dc, bmp, dcOrigin); @@ -3901,6 +3957,11 @@ TEST_CASE("ClippingBoxTestCase::wxSVGFileDC", "[clip][dc][svgdc]") { TwoDevRegionsNonOverlappingNegDim(dc, bmp, true); } + + SECTION("DCAttributes") + { + DcAttributes(dc); + } } #endif // wxUSE_SVG @@ -4253,6 +4314,11 @@ TEST_CASE("ClippingBoxTestCase::wxPaintDC", "[clip][dc][paintdc]") TwoDevRegionsNonOverlappingNegDim(dc, bmp, true); } + SECTION("DCAttributes") + { + DcAttributes(dc); + } + paintExecuted = true; });