// Purpose: SVG sample
// Author: Chris Elliott
// Modified by:
-// RCS-ID: $Id$
// Licence: wxWindows licence
/////////////////////////////////////////////////////////////////////////////
m_OK = true;
+ m_clipUniqueId = 0;
+ m_clipNestingLevel = 0;
+
m_mm_to_pix_x = dpi/25.4;
m_mm_to_pix_y = dpi/25.4;
m_filename = filename;
m_sub_images = 0;
wxString s;
- s = wxT("<?xml version=\"1.0\" standalone=\"no\"?>") + wxString(wxT("\n"));
+ s = wxT("<?xml version=\"1.0\" standalone=\"no\"?>\n");
write(s);
- s = wxT("<!DOCTYPE svg PUBLIC \"-//W3C//DTD SVG 20010904//EN\" ") + wxString(wxT("\n"));
+ s = wxT("<!DOCTYPE svg PUBLIC \"-//W3C//DTD SVG 20010904//EN\"\n");
write(s);
- s = wxT("\"http://www.w3.org/TR/2001/REC-SVG-20010904/DTD/svg10.dtd\"> ") + wxString(wxT("\n"));
+ s = wxT("\"http://www.w3.org/TR/2001/REC-SVG-20010904/DTD/svg10.dtd\">\n");
write(s);
- s = wxT("<svg xmlns=\"http://www.w3.org/2000/svg\" xmlns:xlink=\"http://www.w3.org/1999/xlink\" ") + wxString(wxT("\n"));
+ s = wxT("<svg xmlns=\"http://www.w3.org/2000/svg\" xmlns:xlink=\"http://www.w3.org/1999/xlink\"\n");
write(s);
- s.Printf( wxT(" 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.Printf( wxT(" 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 = wxT("<title>SVG Picture created as ") + wxFileName(filename).GetFullName() + wxT(" </title>") + wxT("\n");
+ s = wxT("<title>SVG Picture created as ") + wxFileName(filename).GetFullName() + wxT(" </title>\n");
write(s);
- s = wxString (wxT("<desc>Picture generated by wxSVG ")) + wxSVGVersion + wxT(" </desc>")+ wxT("\n");
+ s = wxString (wxT("<desc>Picture generated by wxSVG ")) + wxSVGVersion + wxT(" </desc>\n");
write(s);
- s = wxT("<g style=\"fill:black; stroke:black; stroke-width:1\">") + wxString(wxT("\n"));
+ s = wxT("<g style=\"fill:black; stroke:black; stroke-width:1\">\n");
write(s);
}
}
CalcBoundingBox(x2, y2);
}
-void wxSVGFileDCImpl::DoDrawLines(int n, wxPoint points[], wxCoord xoffset , wxCoord yoffset )
+void wxSVGFileDCImpl::DoDrawLines(int n, const wxPoint points[], wxCoord xoffset , wxCoord yoffset )
{
for ( int i = 1; i < n; i++ )
{
{
wxString s;
NewGraphicsIfNeeded();
- s = wxT("<g style = \"stroke-linecap:round;\" > ") + wxString(wxT("\n"));
+ s = wxT("<g style = \"stroke-linecap:round;\" > \n");
write(s);
DoDrawLine ( x1,y1,x1,y1 );
s = wxT("</g>");
CalcBoundingBox(x + width, y + height);
}
-void wxSVGFileDCImpl::DoDrawPolygon(int n, wxPoint points[],
+void wxSVGFileDCImpl::DoDrawPolygon(int n, const wxPoint points[],
wxCoord xoffset, wxCoord yoffset,
wxPolygonFillMode fillStyle)
{
}
}
+void wxSVGFileDCImpl::DoSetClippingRegion( int x, int y, int width, int height )
+{
+ wxString svg;
+
+ // End current graphics group to ensure proper xml nesting (e.g. so that
+ // graphics can be subsequently changed inside the clipping region)
+ svg << "</g>\n"
+ "<defs>\n"
+ "<clipPath id=\"clip" << m_clipNestingLevel << "\">\n"
+ "<rect id=\"cliprect" << m_clipNestingLevel << "\" "
+ "x=\"" << x << "\" "
+ "y=\"" << y << "\" "
+ "width=\"" << width << "\" "
+ "height=\"" << height << "\" "
+ "style=\"stroke: gray; fill: none;\"/>\n"
+ "</clipPath>\n"
+ "</defs>\n"
+ "<g style=\"clip-path: url(#clip" << m_clipNestingLevel << ");\">\n";
+
+ write(svg);
+
+ // Re-apply current graphics to ensure proper xml nesting
+ DoStartNewGraphics();
+
+ m_clipUniqueId++;
+ m_clipNestingLevel++;
+}
+
+void wxSVGFileDCImpl::DestroyClippingRegion()
+{
+ wxString svg;
+
+ // End current graphics element to ensure proper xml nesting (e.g. graphics
+ // might have been changed inside the clipping region)
+ svg << "</g>\n";
+
+ // Close clipping group elements
+ for ( size_t i = 0; i < m_clipUniqueId; i++ )
+ {
+ svg << "</g>";
+ }
+ svg << "\n";
+
+ write(svg);
+
+ // Re-apply current graphics (e.g. brush may have been changed inside one
+ // of the clipped regions - that change will have been lost after xml
+ // elements for the clipped region have been closed).
+ DoStartNewGraphics();
+
+ m_clipUniqueId = 0;
+}
+
void wxSVGFileDCImpl::DoGetTextExtent(const wxString& string, wxCoord *w, wxCoord *h, wxCoord *descent , wxCoord *externalLeading , const wxFont *font) const
{
m_graphics_changed = false;
+ write(wxS("</g>\n"));
+
+ DoStartNewGraphics();
+}
+
+void wxSVGFileDCImpl::DoStartNewGraphics()
+{
wxString s, sBrush, sPenCap, sPenJoin, sPenStyle, sLast;
- sBrush = wxT("</g>\n<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() )