From 97c7ac4289c1563c55d367c0e2f16a75eb8fe268 Mon Sep 17 00:00:00 2001 From: Maarten Bent Date: Sun, 12 Jun 2016 16:43:51 +0200 Subject: [PATCH] Code cleanup in wxSVGFileDC. Consistent white-space usage. Use wxS macros for strings. Check if output stream is OK when writing. Removed unnecessary Borland pragmas. --- include/wx/dcsvg.h | 5 -- src/common/dcsvg.cpp | 129 ++++++++++++++++++++----------------------- 2 files changed, 59 insertions(+), 75 deletions(-) diff --git a/include/wx/dcsvg.h b/include/wx/dcsvg.h index d19bba169c..5f668066fb 100644 --- a/include/wx/dcsvg.h +++ b/include/wx/dcsvg.h @@ -18,11 +18,6 @@ #define wxSVGVersion wxT("v0101") -#ifdef __BORLANDC__ -#pragma warn -8008 -#pragma warn -8066 -#endif - class WXDLLIMPEXP_FWD_BASE wxFileOutputStream; class WXDLLIMPEXP_FWD_CORE wxSVGFileDC; diff --git a/src/common/dcsvg.cpp b/src/common/dcsvg.cpp index 1cce7464da..86e0b1bacf 100644 --- a/src/common/dcsvg.cpp +++ b/src/common/dcsvg.cpp @@ -373,15 +373,15 @@ void wxSVGFileDC::SetBitmapHandler(wxSVGBitmapHandler* handler) wxIMPLEMENT_ABSTRACT_CLASS(wxSVGFileDCImpl, wxDC); -wxSVGFileDCImpl::wxSVGFileDCImpl( wxSVGFileDC *owner, const wxString &filename, - int width, int height, double dpi, const wxString &title ) : - wxDCImpl( owner ) - { - Init( filename, width, height, dpi, title ); - } +wxSVGFileDCImpl::wxSVGFileDCImpl(wxSVGFileDC *owner, const wxString &filename, + int width, int height, double dpi, const wxString &title) + : wxDCImpl(owner) +{ + Init(filename, width, height, dpi, title); +} -void wxSVGFileDCImpl::Init (const wxString &filename, int Width, int Height, - double dpi, const wxString &title) +void wxSVGFileDCImpl::Init(const wxString &filename, int Width, int Height, + double dpi, const wxString &title) { m_width = Width; m_height = Height; @@ -393,8 +393,8 @@ void wxSVGFileDCImpl::Init (const wxString &filename, int Width, int Height, m_clipUniqueId = 0; m_clipNestingLevel = 0; - m_mm_to_pix_x = dpi/25.4; - m_mm_to_pix_y = dpi/25.4; + m_mm_to_pix_x = dpi / 25.4; + m_mm_to_pix_y = dpi / 25.4; m_backgroundBrush = *wxTRANSPARENT_BRUSH; m_textForegroundColour = *wxBLACK; @@ -405,27 +405,24 @@ void wxSVGFileDCImpl::Init (const wxString &filename, int Width, int Height, m_font = *wxNORMAL_FONT; m_brush = *wxWHITE_BRUSH; + m_filename = filename; m_graphics_changed = true; + m_sub_images = 0; ////////////////////code here m_bmp_handler.reset(); - m_outfile.reset(new wxFileOutputStream(filename)); - m_OK = m_outfile->IsOk(); - if (m_OK) - { - m_filename = filename; - m_sub_images = 0; - wxString s; - s += wxS("\n"); - s += wxS("\n\n"); - s += wxS("\n"), NumStr(float(Width) / dpi*2.54), NumStr(float(Height) / dpi*2.54), Width, Height); - s += wxString::Format(wxS("%s\n"), title); - s += wxString(wxS("Picture generated by wxSVG ")) + wxSVGVersion + wxS("\n\n"); - s += wxS("\n"); - write(s); - } + m_outfile.reset(new wxFileOutputStream(m_filename)); + + wxString s; + s += wxS("\n"); + s += wxS("\n\n"); + s += wxS("\n"), NumStr(float(Width) / dpi*2.54), NumStr(float(Height) / dpi*2.54), Width, Height); + s += wxString::Format(wxS("%s\n"), title); + s += wxString(wxS("Picture generated by wxSVG ")) + wxSVGVersion + wxS("\n\n"); + s += wxS("\n"); + write(s); } wxSVGFileDCImpl::~wxSVGFileDCImpl() @@ -440,7 +437,7 @@ wxSVGFileDCImpl::~wxSVGFileDCImpl() write(s); } -void wxSVGFileDCImpl::DoGetSizeMM( int *width, int *height ) const +void wxSVGFileDCImpl::DoGetSizeMM(int *width, int *height) const { if (width) *width = wxRound( (double)m_width / m_mm_to_pix_x ); @@ -451,7 +448,7 @@ void wxSVGFileDCImpl::DoGetSizeMM( int *width, int *height ) const wxSize wxSVGFileDCImpl::GetPPI() const { - return wxSize( wxRound(m_dpi), wxRound(m_dpi) ); + return wxSize(wxRound(m_dpi), wxRound(m_dpi)); } void wxSVGFileDCImpl::Clear() @@ -514,12 +511,12 @@ void wxSVGFileDCImpl::DoDrawPoint(wxCoord x1, wxCoord y1) void wxSVGFileDCImpl::DoDrawCheckMark(wxCoord x1, wxCoord y1, wxCoord width, wxCoord height) { - wxDCImpl::DoDrawCheckMark (x1,y1,width,height); + wxDCImpl::DoDrawCheckMark(x1, y1, width, height); } void wxSVGFileDCImpl::DoDrawText(const wxString& text, wxCoord x1, wxCoord y1) { - DoDrawRotatedText(text, x1,y1,0.0); + DoDrawRotatedText(text, x1, y1, 0.0); } void wxSVGFileDCImpl::DoDrawRotatedText(const wxString& sText, wxCoord x, wxCoord y, double angle) @@ -941,7 +938,7 @@ void wxSVGFileDCImpl::DestroyClippingRegion() svg << "\n"; // Close clipping group elements - for ( size_t i = 0; i < m_clipUniqueId; i++ ) + for (size_t i = 0; i < m_clipUniqueId; i++) { svg << "\n"; } @@ -956,20 +953,20 @@ void wxSVGFileDCImpl::DestroyClippingRegion() m_clipUniqueId = 0; } -void wxSVGFileDCImpl::DoGetTextExtent(const wxString& string, wxCoord *w, wxCoord *h, wxCoord *descent , wxCoord *externalLeading , const wxFont *font) const - +void wxSVGFileDCImpl::DoGetTextExtent(const wxString& string, wxCoord *w, wxCoord *h, wxCoord *descent, wxCoord *externalLeading, const wxFont *font) const { wxScreenDC sDC; - sDC.SetFont (m_font); - if ( font != NULL ) sDC.SetFont ( *font ); - sDC.GetTextExtent(string, w, h, descent, externalLeading ); + sDC.SetFont(m_font); + if (font != NULL) + sDC.SetFont(*font); + sDC.GetTextExtent(string, w, h, descent, externalLeading); } wxCoord wxSVGFileDCImpl::GetCharHeight() const { wxScreenDC sDC; - sDC.SetFont (m_font); + sDC.SetFont(m_font); return sDC.GetCharHeight(); @@ -978,7 +975,7 @@ wxCoord wxSVGFileDCImpl::GetCharHeight() const wxCoord wxSVGFileDCImpl::GetCharWidth() const { wxScreenDC sDC; - sDC.SetFont (m_font); + sDC.SetFont(m_font); return sDC.GetCharWidth(); } @@ -988,13 +985,12 @@ wxCoord wxSVGFileDCImpl::GetCharWidth() const // wxSVGFileDCImpl - set functions // ---------------------------------------------------------- -void wxSVGFileDCImpl::SetBackground( const wxBrush &brush ) +void wxSVGFileDCImpl::SetBackground(const wxBrush &brush) { m_backgroundBrush = brush; } - -void wxSVGFileDCImpl::SetBackgroundMode( int mode ) +void wxSVGFileDCImpl::SetBackgroundMode(int mode) { m_backgroundMode = mode; } @@ -1014,7 +1010,6 @@ void wxSVGFileDCImpl::SetBrush(const wxBrush& brush) write(pattern); } - void wxSVGFileDCImpl::SetPen(const wxPen& pen) { // width, color, ends, joins : currently implemented @@ -1040,49 +1035,47 @@ void wxSVGFileDCImpl::DoStartNewGraphics() { wxString s, sBrush, sPenCap, sPenJoin, sPenStyle, sLast; - sBrush = wxS(""), + sLast = wxString::Format(wxS("stroke-width:%d\" transform=\"translate(%s %s) scale(%s %s)\">"), m_pen.GetWidth(), NumStr((m_deviceOriginX - m_logicalOriginX)* m_signX), NumStr((m_deviceOriginY - m_logicalOriginY)* m_signY), NumStr(m_scaleX * m_signX), NumStr(m_scaleY * m_signY)); - s = sBrush + sPenCap + sPenJoin + sPenStyle + sLast + wxT("\n"); + s = sBrush + sPenCap + sPenJoin + sPenStyle + sLast + wxS("\n"); write(s); } - void wxSVGFileDCImpl::SetFont(const wxFont& font) - { m_font = font; } @@ -1095,34 +1088,34 @@ bool wxSVGFileDCImpl::DoBlit(wxCoord xdest, wxCoord ydest, wxCoord width, wxCoor { if (logicalFunc != wxCOPY) { - wxASSERT_MSG(false, wxT("wxSVGFileDC::DoBlit Call requested nonCopy mode; this is not possible")); + wxASSERT_MSG(false, wxS("wxSVGFileDC::DoBlit Call requested nonCopy mode; this is not possible")); return false; } if (useMask != false) { - wxASSERT_MSG(false, wxT("wxSVGFileDC::DoBlit Call requested false mask; this is not possible")); + wxASSERT_MSG(false, wxS("wxSVGFileDC::DoBlit Call requested false mask; this is not possible")); return false; } - wxBitmap myBitmap (width, height); + wxBitmap myBitmap(width, height); wxMemoryDC memDC; - memDC.SelectObject( myBitmap ); + memDC.SelectObject(myBitmap); memDC.Blit(0, 0, width, height, source, xsrc, ysrc); - memDC.SelectObject( wxNullBitmap ); + memDC.SelectObject(wxNullBitmap); DoDrawBitmap(myBitmap, xdest, ydest); return false; } void wxSVGFileDCImpl::DoDrawIcon(const class wxIcon & myIcon, wxCoord x, wxCoord y) { - wxBitmap myBitmap (myIcon.GetWidth(), myIcon.GetHeight() ); + wxBitmap myBitmap(myIcon.GetWidth(), myIcon.GetHeight()); wxMemoryDC memDC; - memDC.SelectObject( myBitmap ); - memDC.DrawIcon(myIcon,0,0); - memDC.SelectObject( wxNullBitmap ); + memDC.SelectObject(myBitmap); + memDC.DrawIcon(myIcon, 0, 0); + memDC.SelectObject(wxNullBitmap); DoDrawBitmap(myBitmap, x, y); } -void wxSVGFileDCImpl::DoDrawBitmap(const class wxBitmap & bmp, wxCoord x, wxCoord y , bool WXUNUSED(bTransparent) /*=0*/ ) +void wxSVGFileDCImpl::DoDrawBitmap(const class wxBitmap & bmp, wxCoord x, wxCoord y, bool WXUNUSED(bTransparent) /*=0*/) { NewGraphicsIfNeeded(); @@ -1135,16 +1128,12 @@ void wxSVGFileDCImpl::DoDrawBitmap(const class wxBitmap & bmp, wxCoord x, wxCoor void wxSVGFileDCImpl::write(const wxString &s) { + m_OK = 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(); } - -#ifdef __BORLANDC__ -#pragma warn .rch -#pragma warn .ccc -#endif - #endif // wxUSE_SVG -