No real changes, just slightly simplify wxSVGFileDCImpl code.

Move m_graphics_changed check inside NewGraphics() itself instead of checking
whether it's true each time before calling it, it is better to both test the
flag and reset it inside this function rather than do the first part in the
caller and the second one in the callee.

Also rename the function to NewGraphicsIfNeeded() to make its meaning more
clear.

git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@72493 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
Vadim Zeitlin
2012-09-15 23:19:11 +00:00
parent e844dc641e
commit c9848e6318
2 changed files with 20 additions and 15 deletions

View File

@@ -186,16 +186,18 @@ private:
void Init (const wxString &filename, int width, int height, double dpi); void Init (const wxString &filename, int width, int height, double dpi);
void NewGraphics();
void write( const wxString &s ); void write( const wxString &s );
private: private:
// If m_graphics_changed is true, close the current <g> element and start a
// new one for the last pen/brush change.
void NewGraphicsIfNeeded();
wxFileOutputStream *m_outfile; wxFileOutputStream *m_outfile;
wxString m_filename; wxString m_filename;
int m_sub_images; // number of png format images we have int m_sub_images; // number of png format images we have
bool m_OK; bool m_OK;
bool m_graphics_changed; bool m_graphics_changed; // set by Set{Brush,Pen}()
int m_width, m_height; int m_width, m_height;
double m_dpi; double m_dpi;

View File

@@ -195,7 +195,7 @@ wxSize wxSVGFileDCImpl::GetPPI() const
void wxSVGFileDCImpl::DoDrawLine (wxCoord x1, wxCoord y1, wxCoord x2, wxCoord y2) void wxSVGFileDCImpl::DoDrawLine (wxCoord x1, wxCoord y1, wxCoord x2, wxCoord y2)
{ {
if (m_graphics_changed) NewGraphics(); NewGraphicsIfNeeded();
wxString s; wxString s;
s.Printf ( wxT("<path d=\"M%d %d L%d %d\" /> \n"), x1,y1,x2,y2 ); s.Printf ( wxT("<path d=\"M%d %d L%d %d\" /> \n"), x1,y1,x2,y2 );
if (m_OK) if (m_OK)
@@ -218,7 +218,7 @@ void wxSVGFileDCImpl::DoDrawLines(int n, wxPoint points[], wxCoord xoffset , wxC
void wxSVGFileDCImpl::DoDrawPoint (wxCoord x1, wxCoord y1) void wxSVGFileDCImpl::DoDrawPoint (wxCoord x1, wxCoord y1)
{ {
wxString s; wxString s;
if (m_graphics_changed) NewGraphics(); NewGraphicsIfNeeded();
s = wxT("<g style = \"stroke-linecap:round;\" > ") + wxString(wxT("\n")); s = wxT("<g style = \"stroke-linecap:round;\" > ") + wxString(wxT("\n"));
write(s); write(s);
DoDrawLine ( x1,y1,x1,y1 ); DoDrawLine ( x1,y1,x1,y1 );
@@ -239,7 +239,7 @@ void wxSVGFileDCImpl::DoDrawText(const wxString& text, wxCoord x1, wxCoord y1)
void wxSVGFileDCImpl::DoDrawRotatedText(const wxString& sText, wxCoord x, wxCoord y, double angle) void wxSVGFileDCImpl::DoDrawRotatedText(const wxString& sText, wxCoord x, wxCoord y, double angle)
{ {
//known bug; if the font is drawn in a scaled DC, it will not behave exactly as wxMSW //known bug; if the font is drawn in a scaled DC, it will not behave exactly as wxMSW
if (m_graphics_changed) NewGraphics(); NewGraphicsIfNeeded();
wxString s, sTmp; wxString s, sTmp;
// calculate bounding box // calculate bounding box
@@ -303,7 +303,7 @@ void wxSVGFileDCImpl::DoDrawRectangle(wxCoord x, wxCoord y, wxCoord width, wxCoo
void wxSVGFileDCImpl::DoDrawRoundedRectangle(wxCoord x, wxCoord y, wxCoord width, wxCoord height, double radius ) void wxSVGFileDCImpl::DoDrawRoundedRectangle(wxCoord x, wxCoord y, wxCoord width, wxCoord height, double radius )
{ {
if (m_graphics_changed) NewGraphics(); NewGraphicsIfNeeded();
wxString s; wxString s;
s.Printf ( wxT(" <rect x=\"%d\" y=\"%d\" width=\"%d\" height=\"%d\" rx=\"%s\" "), s.Printf ( wxT(" <rect x=\"%d\" y=\"%d\" width=\"%d\" height=\"%d\" rx=\"%s\" "),
@@ -320,7 +320,7 @@ void wxSVGFileDCImpl::DoDrawPolygon(int n, wxPoint points[],
wxCoord xoffset, wxCoord yoffset, wxCoord xoffset, wxCoord yoffset,
wxPolygonFillMode fillStyle) wxPolygonFillMode fillStyle)
{ {
if (m_graphics_changed) NewGraphics(); NewGraphicsIfNeeded();
wxString s, sTmp; wxString s, sTmp;
s = wxT("<polygon style=\""); s = wxT("<polygon style=\"");
if ( fillStyle == wxODDEVEN_RULE ) if ( fillStyle == wxODDEVEN_RULE )
@@ -343,7 +343,7 @@ void wxSVGFileDCImpl::DoDrawPolygon(int n, wxPoint points[],
void wxSVGFileDCImpl::DoDrawEllipse (wxCoord x, wxCoord y, wxCoord width, wxCoord height) void wxSVGFileDCImpl::DoDrawEllipse (wxCoord x, wxCoord y, wxCoord width, wxCoord height)
{ {
if (m_graphics_changed) NewGraphics(); NewGraphicsIfNeeded();
int rh = height /2; int rh = height /2;
int rw = width /2; int rw = width /2;
@@ -369,7 +369,7 @@ void wxSVGFileDCImpl::DoDrawArc(wxCoord x1, wxCoord y1, wxCoord x2, wxCoord y2,
Might be better described as Pie drawing */ Might be better described as Pie drawing */
if (m_graphics_changed) NewGraphics(); NewGraphicsIfNeeded();
wxString s; wxString s;
// we need the radius of the circle which has two estimates // we need the radius of the circle which has two estimates
@@ -428,7 +428,7 @@ void wxSVGFileDCImpl::DoDrawEllipticArc(wxCoord x,wxCoord y,wxCoord w,wxCoord h,
//known bug: SVG draws with the current pen along the radii, but this does not happen in wxMSW //known bug: SVG draws with the current pen along the radii, but this does not happen in wxMSW
if (m_graphics_changed) NewGraphics(); NewGraphicsIfNeeded();
wxString s; wxString s;
//radius //radius
@@ -512,7 +512,6 @@ void wxSVGFileDCImpl::SetBackgroundMode( int mode )
void wxSVGFileDCImpl::SetBrush(const wxBrush& brush) void wxSVGFileDCImpl::SetBrush(const wxBrush& brush)
{ {
m_brush = brush; m_brush = brush;
@@ -529,8 +528,13 @@ void wxSVGFileDCImpl::SetPen(const wxPen& pen)
m_graphics_changed = true; m_graphics_changed = true;
} }
void wxSVGFileDCImpl::NewGraphics() void wxSVGFileDCImpl::NewGraphicsIfNeeded()
{ {
if ( !m_graphics_changed )
return;
m_graphics_changed = false;
wxString s, sBrush, sPenCap, sPenJoin, sPenStyle, sLast, sWarn; wxString s, sBrush, sPenCap, sPenJoin, sPenStyle, sLast, sWarn;
sBrush = wxT("</g>\n<g style=\"") + wxBrushString ( m_brush.GetColour(), m_brush.GetStyle() ) sBrush = wxT("</g>\n<g style=\"") + wxBrushString ( m_brush.GetColour(), m_brush.GetStyle() )
@@ -567,7 +571,6 @@ void wxSVGFileDCImpl::NewGraphics()
s = sBrush + sPenCap + sPenJoin + sPenStyle + sLast + wxT("\n") + sWarn; s = sBrush + sPenCap + sPenJoin + sPenStyle + sLast + wxT("\n") + sWarn;
write(s); write(s);
m_graphics_changed = false;
} }
@@ -614,7 +617,7 @@ void wxSVGFileDCImpl::DoDrawIcon(const class wxIcon & myIcon, wxCoord x, wxCoord
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*/ )
{ {
if (m_graphics_changed) NewGraphics(); NewGraphicsIfNeeded();
wxString sTmp, s, sPNG; wxString sTmp, s, sPNG;
if ( wxImage::FindHandler(wxBITMAP_TYPE_PNG) == NULL ) if ( wxImage::FindHandler(wxBITMAP_TYPE_PNG) == NULL )