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.
This commit is contained in:
Vadim Zeitlin
2018-06-18 16:54:50 +02:00
parent 6a442d2723
commit 070336470f
2 changed files with 34 additions and 0 deletions

View File

@@ -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

View File

@@ -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