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:
@@ -18,11 +18,6 @@
|
|||||||
|
|
||||||
#define wxSVGVersion wxT("v0101")
|
#define wxSVGVersion wxT("v0101")
|
||||||
|
|
||||||
#ifdef __BORLANDC__
|
|
||||||
#pragma warn -8008
|
|
||||||
#pragma warn -8066
|
|
||||||
#endif
|
|
||||||
|
|
||||||
class WXDLLIMPEXP_FWD_BASE wxFileOutputStream;
|
class WXDLLIMPEXP_FWD_BASE wxFileOutputStream;
|
||||||
|
|
||||||
class WXDLLIMPEXP_FWD_CORE wxSVGFileDC;
|
class WXDLLIMPEXP_FWD_CORE wxSVGFileDC;
|
||||||
|
@@ -373,15 +373,15 @@ void wxSVGFileDC::SetBitmapHandler(wxSVGBitmapHandler* handler)
|
|||||||
|
|
||||||
wxIMPLEMENT_ABSTRACT_CLASS(wxSVGFileDCImpl, wxDC);
|
wxIMPLEMENT_ABSTRACT_CLASS(wxSVGFileDCImpl, wxDC);
|
||||||
|
|
||||||
wxSVGFileDCImpl::wxSVGFileDCImpl( wxSVGFileDC *owner, const wxString &filename,
|
wxSVGFileDCImpl::wxSVGFileDCImpl(wxSVGFileDC *owner, const wxString &filename,
|
||||||
int width, int height, double dpi, const wxString &title ) :
|
int width, int height, double dpi, const wxString &title)
|
||||||
wxDCImpl( owner )
|
: wxDCImpl(owner)
|
||||||
{
|
{
|
||||||
Init( filename, width, height, dpi, title );
|
Init(filename, width, height, dpi, title);
|
||||||
}
|
}
|
||||||
|
|
||||||
void wxSVGFileDCImpl::Init (const wxString &filename, int Width, int Height,
|
void wxSVGFileDCImpl::Init(const wxString &filename, int Width, int Height,
|
||||||
double dpi, const wxString &title)
|
double dpi, const wxString &title)
|
||||||
{
|
{
|
||||||
m_width = Width;
|
m_width = Width;
|
||||||
m_height = Height;
|
m_height = Height;
|
||||||
@@ -393,8 +393,8 @@ void wxSVGFileDCImpl::Init (const wxString &filename, int Width, int Height,
|
|||||||
m_clipUniqueId = 0;
|
m_clipUniqueId = 0;
|
||||||
m_clipNestingLevel = 0;
|
m_clipNestingLevel = 0;
|
||||||
|
|
||||||
m_mm_to_pix_x = dpi/25.4;
|
m_mm_to_pix_x = dpi / 25.4;
|
||||||
m_mm_to_pix_y = dpi/25.4;
|
m_mm_to_pix_y = dpi / 25.4;
|
||||||
|
|
||||||
m_backgroundBrush = *wxTRANSPARENT_BRUSH;
|
m_backgroundBrush = *wxTRANSPARENT_BRUSH;
|
||||||
m_textForegroundColour = *wxBLACK;
|
m_textForegroundColour = *wxBLACK;
|
||||||
@@ -405,27 +405,24 @@ void wxSVGFileDCImpl::Init (const wxString &filename, int Width, int Height,
|
|||||||
m_font = *wxNORMAL_FONT;
|
m_font = *wxNORMAL_FONT;
|
||||||
m_brush = *wxWHITE_BRUSH;
|
m_brush = *wxWHITE_BRUSH;
|
||||||
|
|
||||||
|
m_filename = filename;
|
||||||
m_graphics_changed = true;
|
m_graphics_changed = true;
|
||||||
|
m_sub_images = 0;
|
||||||
|
|
||||||
////////////////////code here
|
////////////////////code here
|
||||||
|
|
||||||
m_bmp_handler.reset();
|
m_bmp_handler.reset();
|
||||||
m_outfile.reset(new wxFileOutputStream(filename));
|
m_outfile.reset(new wxFileOutputStream(m_filename));
|
||||||
m_OK = m_outfile->IsOk();
|
|
||||||
if (m_OK)
|
wxString s;
|
||||||
{
|
s += wxS("<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"no\"?>\n");
|
||||||
m_filename = filename;
|
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");
|
||||||
m_sub_images = 0;
|
s += wxS("<svg xmlns=\"http://www.w3.org/2000/svg\" xmlns:xlink=\"http://www.w3.org/1999/xlink\"");
|
||||||
wxString s;
|
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 += wxS("<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"no\"?>\n");
|
s += wxString::Format(wxS("<title>%s</title>\n"), title);
|
||||||
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 += wxString(wxS("<desc>Picture generated by wxSVG ")) + wxSVGVersion + wxS("</desc>\n\n");
|
||||||
s += wxS("<svg xmlns=\"http://www.w3.org/2000/svg\" xmlns:xlink=\"http://www.w3.org/1999/xlink\"");
|
s += wxS("<g style=\"fill:black; stroke:black; stroke-width:1\">\n");
|
||||||
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);
|
write(s);
|
||||||
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()
|
wxSVGFileDCImpl::~wxSVGFileDCImpl()
|
||||||
@@ -440,7 +437,7 @@ wxSVGFileDCImpl::~wxSVGFileDCImpl()
|
|||||||
write(s);
|
write(s);
|
||||||
}
|
}
|
||||||
|
|
||||||
void wxSVGFileDCImpl::DoGetSizeMM( int *width, int *height ) const
|
void wxSVGFileDCImpl::DoGetSizeMM(int *width, int *height) const
|
||||||
{
|
{
|
||||||
if (width)
|
if (width)
|
||||||
*width = wxRound( (double)m_width / m_mm_to_pix_x );
|
*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
|
wxSize wxSVGFileDCImpl::GetPPI() const
|
||||||
{
|
{
|
||||||
return wxSize( wxRound(m_dpi), wxRound(m_dpi) );
|
return wxSize(wxRound(m_dpi), wxRound(m_dpi));
|
||||||
}
|
}
|
||||||
|
|
||||||
void wxSVGFileDCImpl::Clear()
|
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)
|
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)
|
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)
|
void wxSVGFileDCImpl::DoDrawRotatedText(const wxString& sText, wxCoord x, wxCoord y, double angle)
|
||||||
@@ -941,7 +938,7 @@ void wxSVGFileDCImpl::DestroyClippingRegion()
|
|||||||
svg << "</g>\n";
|
svg << "</g>\n";
|
||||||
|
|
||||||
// Close clipping group elements
|
// 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";
|
svg << "</g>\n";
|
||||||
}
|
}
|
||||||
@@ -956,20 +953,20 @@ void wxSVGFileDCImpl::DestroyClippingRegion()
|
|||||||
m_clipUniqueId = 0;
|
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;
|
wxScreenDC sDC;
|
||||||
|
|
||||||
sDC.SetFont (m_font);
|
sDC.SetFont(m_font);
|
||||||
if ( font != NULL ) sDC.SetFont ( *font );
|
if (font != NULL)
|
||||||
sDC.GetTextExtent(string, w, h, descent, externalLeading );
|
sDC.SetFont(*font);
|
||||||
|
sDC.GetTextExtent(string, w, h, descent, externalLeading);
|
||||||
}
|
}
|
||||||
|
|
||||||
wxCoord wxSVGFileDCImpl::GetCharHeight() const
|
wxCoord wxSVGFileDCImpl::GetCharHeight() const
|
||||||
{
|
{
|
||||||
wxScreenDC sDC;
|
wxScreenDC sDC;
|
||||||
sDC.SetFont (m_font);
|
sDC.SetFont(m_font);
|
||||||
|
|
||||||
return sDC.GetCharHeight();
|
return sDC.GetCharHeight();
|
||||||
|
|
||||||
@@ -978,7 +975,7 @@ wxCoord wxSVGFileDCImpl::GetCharHeight() const
|
|||||||
wxCoord wxSVGFileDCImpl::GetCharWidth() const
|
wxCoord wxSVGFileDCImpl::GetCharWidth() const
|
||||||
{
|
{
|
||||||
wxScreenDC sDC;
|
wxScreenDC sDC;
|
||||||
sDC.SetFont (m_font);
|
sDC.SetFont(m_font);
|
||||||
|
|
||||||
return sDC.GetCharWidth();
|
return sDC.GetCharWidth();
|
||||||
}
|
}
|
||||||
@@ -988,13 +985,12 @@ wxCoord wxSVGFileDCImpl::GetCharWidth() const
|
|||||||
// wxSVGFileDCImpl - set functions
|
// wxSVGFileDCImpl - set functions
|
||||||
// ----------------------------------------------------------
|
// ----------------------------------------------------------
|
||||||
|
|
||||||
void wxSVGFileDCImpl::SetBackground( const wxBrush &brush )
|
void wxSVGFileDCImpl::SetBackground(const wxBrush &brush)
|
||||||
{
|
{
|
||||||
m_backgroundBrush = brush;
|
m_backgroundBrush = brush;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void wxSVGFileDCImpl::SetBackgroundMode(int mode)
|
||||||
void wxSVGFileDCImpl::SetBackgroundMode( int mode )
|
|
||||||
{
|
{
|
||||||
m_backgroundMode = mode;
|
m_backgroundMode = mode;
|
||||||
}
|
}
|
||||||
@@ -1014,7 +1010,6 @@ void wxSVGFileDCImpl::SetBrush(const wxBrush& brush)
|
|||||||
write(pattern);
|
write(pattern);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void wxSVGFileDCImpl::SetPen(const wxPen& pen)
|
void wxSVGFileDCImpl::SetPen(const wxPen& pen)
|
||||||
{
|
{
|
||||||
// width, color, ends, joins : currently implemented
|
// width, color, ends, joins : currently implemented
|
||||||
@@ -1040,49 +1035,47 @@ void wxSVGFileDCImpl::DoStartNewGraphics()
|
|||||||
{
|
{
|
||||||
wxString s, sBrush, sPenCap, sPenJoin, sPenStyle, sLast;
|
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());
|
+ wxPenString(m_pen.GetColour(), m_pen.GetStyle());
|
||||||
|
|
||||||
switch ( m_pen.GetCap() )
|
switch ( m_pen.GetCap() )
|
||||||
{
|
{
|
||||||
case wxCAP_PROJECTING :
|
case wxCAP_PROJECTING :
|
||||||
sPenCap = wxT("stroke-linecap:square; ");
|
sPenCap = wxS("stroke-linecap:square; ");
|
||||||
break;
|
break;
|
||||||
case wxCAP_BUTT :
|
case wxCAP_BUTT :
|
||||||
sPenCap = wxT("stroke-linecap:butt; ");
|
sPenCap = wxS("stroke-linecap:butt; ");
|
||||||
break;
|
break;
|
||||||
case wxCAP_ROUND :
|
case wxCAP_ROUND :
|
||||||
default :
|
default :
|
||||||
sPenCap = wxT("stroke-linecap:round; ");
|
sPenCap = wxS("stroke-linecap:round; ");
|
||||||
}
|
}
|
||||||
|
|
||||||
switch ( m_pen.GetJoin() )
|
switch ( m_pen.GetJoin() )
|
||||||
{
|
{
|
||||||
case wxJOIN_BEVEL :
|
case wxJOIN_BEVEL :
|
||||||
sPenJoin = wxT("stroke-linejoin:bevel; ");
|
sPenJoin = wxS("stroke-linejoin:bevel; ");
|
||||||
break;
|
break;
|
||||||
case wxJOIN_MITER :
|
case wxJOIN_MITER :
|
||||||
sPenJoin = wxT("stroke-linejoin:miter; ");
|
sPenJoin = wxS("stroke-linejoin:miter; ");
|
||||||
break;
|
break;
|
||||||
case wxJOIN_ROUND :
|
case wxJOIN_ROUND :
|
||||||
default :
|
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(),
|
m_pen.GetWidth(),
|
||||||
NumStr((m_deviceOriginX - m_logicalOriginX)* m_signX),
|
NumStr((m_deviceOriginX - m_logicalOriginX)* m_signX),
|
||||||
NumStr((m_deviceOriginY - m_logicalOriginY)* m_signY),
|
NumStr((m_deviceOriginY - m_logicalOriginY)* m_signY),
|
||||||
NumStr(m_scaleX * m_signX),
|
NumStr(m_scaleX * m_signX),
|
||||||
NumStr(m_scaleY * m_signY));
|
NumStr(m_scaleY * m_signY));
|
||||||
|
|
||||||
s = sBrush + sPenCap + sPenJoin + sPenStyle + sLast + wxT("\n");
|
s = sBrush + sPenCap + sPenJoin + sPenStyle + sLast + wxS("\n");
|
||||||
write(s);
|
write(s);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void wxSVGFileDCImpl::SetFont(const wxFont& font)
|
void wxSVGFileDCImpl::SetFont(const wxFont& font)
|
||||||
|
|
||||||
{
|
{
|
||||||
m_font = font;
|
m_font = font;
|
||||||
}
|
}
|
||||||
@@ -1095,34 +1088,34 @@ bool wxSVGFileDCImpl::DoBlit(wxCoord xdest, wxCoord ydest, wxCoord width, wxCoor
|
|||||||
{
|
{
|
||||||
if (logicalFunc != wxCOPY)
|
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;
|
return false;
|
||||||
}
|
}
|
||||||
if (useMask != 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;
|
return false;
|
||||||
}
|
}
|
||||||
wxBitmap myBitmap (width, height);
|
wxBitmap myBitmap(width, height);
|
||||||
wxMemoryDC memDC;
|
wxMemoryDC memDC;
|
||||||
memDC.SelectObject( myBitmap );
|
memDC.SelectObject(myBitmap);
|
||||||
memDC.Blit(0, 0, width, height, source, xsrc, ysrc);
|
memDC.Blit(0, 0, width, height, source, xsrc, ysrc);
|
||||||
memDC.SelectObject( wxNullBitmap );
|
memDC.SelectObject(wxNullBitmap);
|
||||||
DoDrawBitmap(myBitmap, xdest, ydest);
|
DoDrawBitmap(myBitmap, xdest, ydest);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
void wxSVGFileDCImpl::DoDrawIcon(const class wxIcon & myIcon, wxCoord x, wxCoord y)
|
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;
|
wxMemoryDC memDC;
|
||||||
memDC.SelectObject( myBitmap );
|
memDC.SelectObject(myBitmap);
|
||||||
memDC.DrawIcon(myIcon,0,0);
|
memDC.DrawIcon(myIcon, 0, 0);
|
||||||
memDC.SelectObject( wxNullBitmap );
|
memDC.SelectObject(wxNullBitmap);
|
||||||
DoDrawBitmap(myBitmap, x, y);
|
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();
|
NewGraphicsIfNeeded();
|
||||||
|
|
||||||
@@ -1135,16 +1128,12 @@ void wxSVGFileDCImpl::DoDrawBitmap(const class wxBitmap & bmp, wxCoord x, wxCoor
|
|||||||
|
|
||||||
void wxSVGFileDCImpl::write(const wxString &s)
|
void wxSVGFileDCImpl::write(const wxString &s)
|
||||||
{
|
{
|
||||||
|
m_OK = m_outfile->IsOk();
|
||||||
|
if (!m_OK)
|
||||||
|
return;
|
||||||
const wxCharBuffer buf = s.utf8_str();
|
const wxCharBuffer buf = s.utf8_str();
|
||||||
m_outfile->Write(buf, strlen((const char *)buf));
|
m_outfile->Write(buf, strlen((const char *)buf));
|
||||||
m_OK = m_outfile->IsOk();
|
m_OK = m_outfile->IsOk();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
#ifdef __BORLANDC__
|
|
||||||
#pragma warn .rch
|
|
||||||
#pragma warn .ccc
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#endif // wxUSE_SVG
|
#endif // wxUSE_SVG
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user