From 070336470f27e046bc29f00688cea4833a6b218b Mon Sep 17 00:00:00 2001 From: Vadim Zeitlin Date: Mon, 18 Jun 2018 16:54:50 +0200 Subject: [PATCH] Make wxSVGFileDC::GetClippingBox() actually work wxSVGFileDCImpl class uses the default, i.e. inherited from wxDCImpl, implementation of this method, but for it to work, the clipping box coordinates stored in wxDCImpl need to be updated when the clipping region changes or is destroyed and this wasn't done before. Fix this now and add a unit test verifying that this indeed works. --- src/common/dcsvg.cpp | 6 ++++++ tests/graphics/clippingbox.cpp | 28 ++++++++++++++++++++++++++++ 2 files changed, 34 insertions(+) diff --git a/src/common/dcsvg.cpp b/src/common/dcsvg.cpp index ca44afcac3..9eb2f4f0fb 100644 --- a/src/common/dcsvg.cpp +++ b/src/common/dcsvg.cpp @@ -934,6 +934,9 @@ void wxSVGFileDCImpl::DoSetClippingRegion(int x, int y, int width, int height) m_clipUniqueId++; m_clipNestingLevel++; + + // Update the base class m_clip[XY][12] fields too. + wxDCImpl::DoSetClippingRegion(x, y, width, height); } void wxSVGFileDCImpl::DestroyClippingRegion() @@ -958,6 +961,9 @@ void wxSVGFileDCImpl::DestroyClippingRegion() DoStartNewGraphics(); m_clipUniqueId = 0; + + // Also update the base class clipping region information. + wxDCImpl::DestroyClippingRegion(); } void wxSVGFileDCImpl::DoGetTextExtent(const wxString& string, wxCoord *w, wxCoord *h, wxCoord *descent, wxCoord *externalLeading, const wxFont *font) const diff --git a/tests/graphics/clippingbox.cpp b/tests/graphics/clippingbox.cpp index 6068660f91..42eed74701 100644 --- a/tests/graphics/clippingbox.cpp +++ b/tests/graphics/clippingbox.cpp @@ -21,7 +21,9 @@ #if wxUSE_GRAPHICS_CONTEXT #include "wx/dcgraph.h" #endif // wxUSE_GRAPHICS_CONTEXT +#include "wx/dcsvg.h" +#include "testfile.h" // ---------------------------------------------------------------------------- // test class @@ -2122,3 +2124,29 @@ void ClippingBoxTestCaseGCBase::RegionsAndPushPopState() } #endif // wxUSE_GRAPHICS_CONTEXT + +#if wxUSE_SVG + +// We can't reuse the existing tests for wxSVGFileDC as we can't check its +// output, but we can still at least check the behaviour of GetClippingBox(). +TEST_CASE("ClippingBoxTestCaseSVGDC", "[clip][svgdc]") +{ + TestFile tf; + wxSVGFileDC dc(tf.GetName(), s_dcSize.x, s_dcSize.y); + + wxRect rect; + dc.GetClippingBox(rect); + CHECK( rect == wxRect(s_dcSize) ); + + const wxRect rectClip(10, 20, 80, 75); + dc.SetClippingRegion(rectClip); + + dc.GetClippingBox(rect); + CHECK( rect == rectClip ); + + dc.DestroyClippingRegion(); + dc.GetClippingBox(rect); + CHECK( rect == wxRect(s_dcSize) ); +} + +#endif // wxUSE_SVG