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

@@ -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("<?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");
s += wxS("<svg xmlns=\"http://www.w3.org/2000/svg\" xmlns:xlink=\"http://www.w3.org/1999/xlink\"");
s += wxString::Format(wxS(" width=\"%scm\" height=\"%scm\" viewBox=\"0 0 %d %d\">\n"), NumStr(float(Width) / dpi*2.54), NumStr(float(Height) / dpi*2.54), Width, Height);
s += wxString::Format(wxS("<title>%s</title>\n"), title);
s += wxString(wxS("<desc>Picture generated by wxSVG ")) + wxSVGVersion + wxS("</desc>\n\n");
s += wxS("<g style=\"fill:black; stroke:black; stroke-width:1\">\n");
write(s);
}
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");
s += wxS("<svg xmlns=\"http://www.w3.org/2000/svg\" xmlns:xlink=\"http://www.w3.org/1999/xlink\"");
s += wxString::Format(wxS(" width=\"%scm\" height=\"%scm\" viewBox=\"0 0 %d %d\">\n"), NumStr(float(Width) / dpi*2.54), NumStr(float(Height) / dpi*2.54), Width, Height);
s += wxString::Format(wxS("<title>%s</title>\n"), title);
s += wxString(wxS("<desc>Picture generated by wxSVG ")) + wxSVGVersion + wxS("</desc>\n\n");
s += wxS("<g style=\"fill:black; stroke:black; stroke-width:1\">\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 << "</g>\n";
// Close clipping group elements
for ( size_t i = 0; i < m_clipUniqueId; i++ )
for (size_t i = 0; i < m_clipUniqueId; i++)
{
svg << "</g>\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("<g style=\"") + wxBrushString ( m_brush.GetColour(), m_brush.GetStyle() )
sBrush = wxS("<g style=\"") + wxBrushString(m_brush.GetColour(), m_brush.GetStyle())
+ wxPenString(m_pen.GetColour(), m_pen.GetStyle());
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,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