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.
This commit is contained in:
Maarten Bent
2016-06-12 16:43:51 +02:00
parent 1e0719ad81
commit 97c7ac4289
2 changed files with 59 additions and 75 deletions

View File

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

View File

@@ -374,8 +374,8 @@ 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 )
int width, int height, double dpi, const wxString &title)
: wxDCImpl(owner)
{
Init(filename, width, height, dpi, title);
}
@@ -405,17 +405,15 @@ 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;
m_outfile.reset(new wxFileOutputStream(m_filename));
wxString s;
s += wxS("<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"no\"?>\n");
s += wxS("<!DOCTYPE svg PUBLIC \"-//W3C//DTD SVG 1.0//EN\" \"http://www.w3.org/TR/2001/REC-SVG-20010904/DTD/svg10.dtd\">\n\n");
@@ -426,7 +424,6 @@ void wxSVGFileDCImpl::Init (const wxString &filename, int Width, int Height,
s += wxS("<g style=\"fill:black; stroke:black; stroke-width:1\">\n");
write(s);
}
}
wxSVGFileDCImpl::~wxSVGFileDCImpl()
{
@@ -957,12 +954,12 @@ void wxSVGFileDCImpl::DestroyClippingRegion()
}
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 );
if (font != NULL)
sDC.SetFont(*font);
sDC.GetTextExtent(string, w, h, descent, externalLeading);
}
@@ -993,7 +990,6 @@ void wxSVGFileDCImpl::SetBackground( const wxBrush &brush )
m_backgroundBrush = brush;
}
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
@@ -1046,43 +1041,41 @@ void wxSVGFileDCImpl::DoStartNewGraphics()
switch ( m_pen.GetCap() )
{
case wxCAP_PROJECTING :
sPenCap = wxT("stroke-linecap:square; ");
sPenCap = wxS("stroke-linecap:square; ");
break;
case wxCAP_BUTT :
sPenCap = wxT("stroke-linecap:butt; ");
sPenCap = wxS("stroke-linecap:butt; ");
break;
case wxCAP_ROUND :
default :
sPenCap = wxT("stroke-linecap:round; ");
sPenCap = wxS("stroke-linecap:round; ");
}
switch ( m_pen.GetJoin() )
{
case wxJOIN_BEVEL :
sPenJoin = wxT("stroke-linejoin:bevel; ");
sPenJoin = wxS("stroke-linejoin:bevel; ");
break;
case wxJOIN_MITER :
sPenJoin = wxT("stroke-linejoin:miter; ");
sPenJoin = wxS("stroke-linejoin:miter; ");
break;
case wxJOIN_ROUND :
default :
sPenJoin = wxT("stroke-linejoin:round; ");
sPenJoin = wxS("stroke-linejoin:round; ");
}
sLast.Printf(wxT("stroke-width:%d\" transform=\"translate(%s %s) scale(%s %s)\">"),
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,12 +1088,12 @@ 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);
@@ -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