void Init (const wxString &filename, int width, int height, double dpi);
- void NewGraphics();
-
void write( const wxString &s );
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;
wxString m_filename;
int m_sub_images; // number of png format images we have
bool m_OK;
- bool m_graphics_changed;
+ bool m_graphics_changed; // set by Set{Brush,Pen}()
int m_width, m_height;
double m_dpi;
void wxSVGFileDCImpl::DoDrawLine (wxCoord x1, wxCoord y1, wxCoord x2, wxCoord y2)
{
- if (m_graphics_changed) NewGraphics();
+ NewGraphicsIfNeeded();
wxString s;
s.Printf ( wxT("<path d=\"M%d %d L%d %d\" /> \n"), x1,y1,x2,y2 );
if (m_OK)
void wxSVGFileDCImpl::DoDrawPoint (wxCoord x1, wxCoord y1)
{
wxString s;
- if (m_graphics_changed) NewGraphics();
+ NewGraphicsIfNeeded();
s = wxT("<g style = \"stroke-linecap:round;\" > ") + wxString(wxT("\n"));
write(s);
DoDrawLine ( x1,y1,x1,y1 );
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
- if (m_graphics_changed) NewGraphics();
+ NewGraphicsIfNeeded();
wxString s, sTmp;
// calculate bounding box
void wxSVGFileDCImpl::DoDrawRoundedRectangle(wxCoord x, wxCoord y, wxCoord width, wxCoord height, double radius )
{
- if (m_graphics_changed) NewGraphics();
+ NewGraphicsIfNeeded();
wxString s;
s.Printf ( wxT(" <rect x=\"%d\" y=\"%d\" width=\"%d\" height=\"%d\" rx=\"%s\" "),
wxCoord xoffset, wxCoord yoffset,
wxPolygonFillMode fillStyle)
{
- if (m_graphics_changed) NewGraphics();
+ NewGraphicsIfNeeded();
wxString s, sTmp;
s = wxT("<polygon style=\"");
if ( fillStyle == wxODDEVEN_RULE )
void wxSVGFileDCImpl::DoDrawEllipse (wxCoord x, wxCoord y, wxCoord width, wxCoord height)
{
- if (m_graphics_changed) NewGraphics();
+ NewGraphicsIfNeeded();
int rh = height /2;
int rw = width /2;
Might be better described as Pie drawing */
- if (m_graphics_changed) NewGraphics();
+ NewGraphicsIfNeeded();
wxString s;
// we need the radius of the circle which has two estimates
//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;
//radius
void wxSVGFileDCImpl::SetBrush(const wxBrush& brush)
-
{
m_brush = brush;
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;
sBrush = wxT("</g>\n<g style=\"") + wxBrushString ( m_brush.GetColour(), m_brush.GetStyle() )
s = sBrush + sPenCap + sPenJoin + sPenStyle + sLast + wxT("\n") + sWarn;
write(s);
- m_graphics_changed = false;
}
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;
if ( wxImage::FindHandler(wxBITMAP_TYPE_PNG) == NULL )