From 119dce5eb8db37b60624a7b76e06e42b2b3e555c Mon Sep 17 00:00:00 2001 From: Vadim Zeitlin Date: Mon, 18 Jun 2018 10:21:59 +0200 Subject: [PATCH] Fix check for existing clipping region in wxDCClipper wxDC::GetClippingBox() is actually supposed to return a rectangle equal to the total wxDC area and not an empty rectangle if there is no clipping box at all, so avoid restoring the old clipping region unnecessarily in this case too: even if it should be harmless, it's still unnecessarily inefficient and, in practice, this is not really harmless neither as wxPdfDC (from the third party wxPdfDocument library) doesn't handle having a clipping region set when adding a new page correctly and so using wxDCClipper broke PDF generation. This fixes another fallout from 2a8c290e0de5e657f22a0c13817df65688b01345 See #13834. --- include/wx/dc.h | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/include/wx/dc.h b/include/wx/dc.h index cfc57cd1bd..76b5df8058 100644 --- a/include/wx/dc.h +++ b/include/wx/dc.h @@ -1459,7 +1459,14 @@ private: // Common part of all ctors. void Init(const wxRect& r) { + // GetClippingBox() is supposed to return the rectangle corresponding + // to the full DC area and some implementations actually do it, while + // others return an empty rectangle instead. Check for both possible + // results here to avoid restoring the clipping region unnecessarily in + // the dtor. m_dc.GetClippingBox(m_oldClipRect); + if ( m_oldClipRect == m_dc.GetSize() ) + m_oldClipRect = wxRect(); m_dc.SetClippingRegion(r); }