From 26b273bef910977bf0e770da58261e21e11f56ff Mon Sep 17 00:00:00 2001 From: Maarten Bent Date: Sat, 10 Aug 2019 22:22:32 +0200 Subject: [PATCH] Fix RTTI class declarations of wxSVGFileDC wxIMPLEMENT_DYNAMIC_CLASS requires a default constructor (no filename). Check if m_outfile is initialized with a valid filename before using it. --- include/wx/dcsvg.h | 9 +++++++++ src/common/dcsvg.cpp | 18 +++++++++++++++--- 2 files changed, 24 insertions(+), 3 deletions(-) diff --git a/include/wx/dcsvg.h b/include/wx/dcsvg.h index 964e3166a9..4773c6152c 100644 --- a/include/wx/dcsvg.h +++ b/include/wx/dcsvg.h @@ -277,6 +277,7 @@ private: size_t m_clipUniqueId; wxDECLARE_ABSTRACT_CLASS(wxSVGFileDCImpl); + wxDECLARE_NO_COPY_CLASS(wxSVGFileDCImpl); }; @@ -298,6 +299,14 @@ public: void SetBitmapHandler(wxSVGBitmapHandler* handler); void SetShapeRenderingMode(wxSVGShapeRenderingMode renderingMode); + +private: + wxSVGFileDC() + : wxDC(new wxSVGFileDCImpl(this, wxString())) + { + } + + wxDECLARE_DYNAMIC_CLASS(wxSVGFileDC); }; #endif // wxUSE_SVG diff --git a/src/common/dcsvg.cpp b/src/common/dcsvg.cpp index 9d6b16b265..a02bbd6f5b 100644 --- a/src/common/dcsvg.cpp +++ b/src/common/dcsvg.cpp @@ -462,6 +462,8 @@ wxSVGBitmapFileHandler::ProcessBitmap(const wxBitmap& bmp, // wxSVGFileDC (specialisations) // ---------------------------------------------------------- +wxIMPLEMENT_DYNAMIC_CLASS(wxSVGFileDC, wxDC); + void wxSVGFileDC::SetBitmapHandler(wxSVGBitmapHandler* handler) { ((wxSVGFileDCImpl*)GetImpl())->SetBitmapHandler(handler); @@ -476,7 +478,7 @@ void wxSVGFileDC::SetShapeRenderingMode(wxSVGShapeRenderingMode renderingMode) // wxSVGFileDCImpl // ---------------------------------------------------------- -wxIMPLEMENT_ABSTRACT_CLASS(wxSVGFileDCImpl, wxDC); +wxIMPLEMENT_ABSTRACT_CLASS(wxSVGFileDCImpl, wxDCImpl); wxSVGFileDCImpl::wxSVGFileDCImpl(wxSVGFileDC *owner, const wxString &filename, int width, int height, double dpi, const wxString &title) @@ -517,7 +519,11 @@ void wxSVGFileDCImpl::Init(const wxString &filename, int Width, int Height, ////////////////////code here m_bmp_handler.reset(); - m_outfile.reset(new wxFileOutputStream(m_filename)); + + if ( m_filename.IsEmpty() ) + m_outfile.reset(); + else + m_outfile.reset(new wxFileOutputStream(m_filename)); wxString s; s += wxS("\n"); @@ -1215,14 +1221,20 @@ void wxSVGFileDCImpl::DoDrawBitmap(const class wxBitmap & bmp, wxCoord x, wxCoor if ( !m_bmp_handler ) m_bmp_handler.reset(new wxSVGBitmapFileHandler(m_filename)); + m_OK = m_outfile && m_outfile->IsOk(); + if (!m_OK) + return; + m_bmp_handler->ProcessBitmap(bmp, x, y, *m_outfile); + m_OK = m_outfile->IsOk(); } void wxSVGFileDCImpl::write(const wxString &s) { - m_OK = m_outfile->IsOk(); + m_OK = m_outfile && m_outfile->IsOk(); if (!m_OK) return; + const wxCharBuffer buf = s.utf8_str(); m_outfile->Write(buf, strlen((const char *)buf)); m_OK = m_outfile->IsOk();