summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--vcl/inc/win/salgdi.h8
-rw-r--r--vcl/win/gdi/salprn.cxx3
2 files changed, 11 insertions, 0 deletions
diff --git a/vcl/inc/win/salgdi.h b/vcl/inc/win/salgdi.h
index 9555cc158b75..974c58ae81ad 100644
--- a/vcl/inc/win/salgdi.h
+++ b/vcl/inc/win/salgdi.h
@@ -141,6 +141,13 @@ public:
void fill(sal_uInt32 color);
};
+/**
+ * WinSalGraphics never owns the HDC it uses to draw, because the HDC can have
+ * various origins with different ways to correctly free it. And WinSalGraphics
+ * stores all default values (mhDef*) of the HDC, which must be restored when
+ * the HDC changes (setHDC) or the SalGraphics is destructed. So think of the
+ * HDC in terms of Rust's Borrowing semantics.
+ */
class WinSalGraphics : public SalGraphics
{
friend class WinSalGraphicsImpl;
@@ -177,6 +184,7 @@ public:
HFONT ImplDoSetFont(vcl::font::FontSelectPattern const & i_rFont, const vcl::font::PhysicalFontFace * i_pFontFace, HFONT& o_rOldFont);
HDC getHDC() const { return mhLocalDC; }
+ // NOTE: this doesn't transfer ownership! See class comment.
void setHDC(HDC aNew);
HPALETTE getDefPal() const;
diff --git a/vcl/win/gdi/salprn.cxx b/vcl/win/gdi/salprn.cxx
index 86e1e616a57f..332c7a8dfaae 100644
--- a/vcl/win/gdi/salprn.cxx
+++ b/vcl/win/gdi/salprn.cxx
@@ -1373,6 +1373,9 @@ WinSalPrinter::~WinSalPrinter()
HDC hDC = mhDC;
if ( hDC )
{
+ // explicitly reset(), so the mxGraphics's borrowed HDC defaults are
+ // restored and WinSalGraphics's destructor won't work on a deleted HDC.
+ mxGraphics.reset();
DeleteDC( hDC );
}