Generate valid XML in wxSVGFileDC and updated wxSVGVersion.

Use the correct doc-type and specify the encoding. 'title' is not a valid attribute of <image> so remove it.
Removed superfluous white-space and improved indenting in generated XML.
This commit is contained in:
Maarten Bent 2016-03-15 23:51:41 +01:00
parent 045265a7bb
commit b55a18f6b8
2 changed files with 31 additions and 44 deletions

View File

@ -16,7 +16,7 @@
#if wxUSE_SVG
#define wxSVGVersion wxT("v0100")
#define wxSVGVersion wxT("v0101")
#ifdef __BORLANDC__
#pragma warn -8008

View File

@ -294,9 +294,7 @@ wxSVGBitmapEmbedHandler::ProcessBitmap(const wxBitmap& bmp,
// write image meta information
wxString s;
s += wxString::Format(" <image x=\"%d\" y=\"%d\" "
"width=\"%dpx\" height=\"%dpx\" "
"title=\"Image from wxSVG\"\n",
s += wxString::Format(" <image x=\"%d\" y=\"%d\" width=\"%dpx\" height=\"%dpx\"",
x, y, bmp.GetWidth(), bmp.GetHeight());
s += wxString::Format(" id=\"image%d\" "
"xlink:href=\"data:image/png;base64,\n",
@ -309,7 +307,7 @@ wxSVGBitmapEmbedHandler::ProcessBitmap(const wxBitmap& bmp,
if (i < data.size() - WRAP)
s += data.Mid(i, WRAP) + "\n";
else
s += data.Mid(i, s.size() - i) + "\"\n/>"; // last line
s += data.Mid(i, s.size() - i) + "\"\n />\n"; // last line
}
// write to the SVG file
@ -349,11 +347,9 @@ wxSVGBitmapFileHandler::ProcessBitmap(const wxBitmap& bmp,
// reference the bitmap from the SVG doc
wxString s;
s += wxString::Format(" <image x=\"%d\" y=\"%d\" "
"width=\"%dpx\" height=\"%dpx\" "
"title=\"Image from wxSVG\"\n",
s += wxString::Format(" <image x=\"%d\" y=\"%d\" width=\"%dpx\" height=\"%dpx\"",
x, y, bmp.GetWidth(), bmp.GetHeight());
s += wxString::Format(" xlink:href=\"%s\">\n</image>\n", sPNG);
s += wxString::Format(" xlink:href=\"%s\"/>\n", sPNG);
// write to the SVG file
const wxCharBuffer buf = s.utf8_str();
@ -421,21 +417,13 @@ void wxSVGFileDCImpl::Init (const wxString &filename, int Width, int Height,
m_filename = filename;
m_sub_images = 0;
wxString s;
s = wxT("<?xml version=\"1.0\" standalone=\"no\"?>\n");
write(s);
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\">\n");
write(s);
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 );
write(s);
s = wxT("<title>") + title + wxT("</title>\n");
write(s);
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\">\n");
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);
}
}
@ -514,14 +502,14 @@ void wxSVGFileDCImpl::DoDrawLines(int n, const wxPoint points[], wxCoord xoffset
}
}
void wxSVGFileDCImpl::DoDrawPoint (wxCoord x1, wxCoord y1)
void wxSVGFileDCImpl::DoDrawPoint(wxCoord x1, wxCoord y1)
{
wxString s;
NewGraphicsIfNeeded();
s = wxT("<g style = \"stroke-linecap:round;\" > \n");
s = wxS("<g style=\"stroke-linecap:round;\">\n");
write(s);
DoDrawLine ( x1,y1,x1,y1 );
s = wxT("</g>");
DoDrawLine(x1, y1, x1, y1);
s = wxS("</g>\n");
write(s);
}
@ -663,16 +651,15 @@ void wxSVGFileDCImpl::DoDrawRectangle(wxCoord x, wxCoord y, wxCoord width, wxCoo
DoDrawRoundedRectangle(x, y, width, height, 0);
}
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)
{
NewGraphicsIfNeeded();
wxString s;
s.Printf ( wxT(" <rect x=\"%d\" y=\"%d\" width=\"%d\" height=\"%d\" rx=\"%s\" %s"),
x, y, width, height, NumStr(radius) , wxGetBrushFill(m_brush));
s = wxString::Format(wxS(" <rect x=\"%d\" y=\"%d\" width=\"%d\" height=\"%d\" rx=\"%s\"%s"),
x, y, width, height, NumStr(radius), wxGetBrushFill(m_brush));
s += wxT(" /> \n");
s += wxS("/>\n");
write(s);
CalcBoundingBox(x, y);
@ -684,22 +671,22 @@ void wxSVGFileDCImpl::DoDrawPolygon(int n, const wxPoint points[],
wxPolygonFillMode fillStyle)
{
NewGraphicsIfNeeded();
wxString s, sTmp;
s = wxT("<polygon style=\"");
if ( fillStyle == wxODDEVEN_RULE )
s += wxT("fill-rule:evenodd; ");
wxString s;
s = wxS(" <polygon style=\"");
if (fillStyle == wxODDEVEN_RULE)
s += wxS("fill-rule:evenodd;");
else
s += wxT("fill-rule:nonzero; ");
s += wxS("fill-rule:nonzero;");
s += wxT("\"") + wxGetBrushFill(m_brush) + wxT("\npoints=\"");
s += wxS("\"") + wxGetBrushFill(m_brush) + wxS(" points=\"");
for (int i = 0; i < n; i++)
for (int i = 0; i < n; i++)
{
sTmp.Printf ( wxT("%d,%d"), points [i].x+xoffset, points[i].y+yoffset );
s += sTmp + wxT("\n");
CalcBoundingBox ( points [i].x+xoffset, points[i].y+yoffset);
s += wxString::Format(wxS("%d %d "), points[i].x + xoffset, points[i].y + yoffset);
CalcBoundingBox(points[i].x + xoffset, points[i].y + yoffset);
}
s += wxT("\" /> \n");
s += wxS("\"/>\n");
write(s);
}