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 #if wxUSE_SVG
#define wxSVGVersion wxT("v0100") #define wxSVGVersion wxT("v0101")
#ifdef __BORLANDC__ #ifdef __BORLANDC__
#pragma warn -8008 #pragma warn -8008

View File

@@ -294,9 +294,7 @@ wxSVGBitmapEmbedHandler::ProcessBitmap(const wxBitmap& bmp,
// write image meta information // write image meta information
wxString s; wxString s;
s += wxString::Format(" <image x=\"%d\" y=\"%d\" " s += wxString::Format(" <image x=\"%d\" y=\"%d\" width=\"%dpx\" height=\"%dpx\"",
"width=\"%dpx\" height=\"%dpx\" "
"title=\"Image from wxSVG\"\n",
x, y, bmp.GetWidth(), bmp.GetHeight()); x, y, bmp.GetWidth(), bmp.GetHeight());
s += wxString::Format(" id=\"image%d\" " s += wxString::Format(" id=\"image%d\" "
"xlink:href=\"data:image/png;base64,\n", "xlink:href=\"data:image/png;base64,\n",
@@ -309,7 +307,7 @@ wxSVGBitmapEmbedHandler::ProcessBitmap(const wxBitmap& bmp,
if (i < data.size() - WRAP) if (i < data.size() - WRAP)
s += data.Mid(i, WRAP) + "\n"; s += data.Mid(i, WRAP) + "\n";
else 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 // write to the SVG file
@@ -349,11 +347,9 @@ wxSVGBitmapFileHandler::ProcessBitmap(const wxBitmap& bmp,
// reference the bitmap from the SVG doc // reference the bitmap from the SVG doc
wxString s; wxString s;
s += wxString::Format(" <image x=\"%d\" y=\"%d\" " s += wxString::Format(" <image x=\"%d\" y=\"%d\" width=\"%dpx\" height=\"%dpx\"",
"width=\"%dpx\" height=\"%dpx\" "
"title=\"Image from wxSVG\"\n",
x, y, bmp.GetWidth(), bmp.GetHeight()); 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 // write to the SVG file
const wxCharBuffer buf = s.utf8_str(); const wxCharBuffer buf = s.utf8_str();
@@ -421,21 +417,13 @@ void wxSVGFileDCImpl::Init (const wxString &filename, int Width, int Height,
m_filename = filename; m_filename = filename;
m_sub_images = 0; m_sub_images = 0;
wxString s; wxString s;
s = wxT("<?xml version=\"1.0\" standalone=\"no\"?>\n"); s += wxS("<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"no\"?>\n");
write(s); 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 = wxT("<!DOCTYPE svg PUBLIC \"-//W3C//DTD SVG 20010904//EN\"\n"); s += wxS("<svg xmlns=\"http://www.w3.org/2000/svg\" xmlns:xlink=\"http://www.w3.org/1999/xlink\"");
write(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 = wxT("\"http://www.w3.org/TR/2001/REC-SVG-20010904/DTD/svg10.dtd\">\n"); s += wxString::Format(wxS("<title>%s</title>\n"), title);
write(s); s += wxString(wxS("<desc>Picture generated by wxSVG ")) + wxSVGVersion + wxS("</desc>\n\n");
s = wxT("<svg xmlns=\"http://www.w3.org/2000/svg\" xmlns:xlink=\"http://www.w3.org/1999/xlink\"\n"); s += wxS("<g style=\"fill:black; stroke:black; stroke-width:1\">\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");
write(s); 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; wxString s;
NewGraphicsIfNeeded(); NewGraphicsIfNeeded();
s = wxT("<g style = \"stroke-linecap:round;\" > \n"); s = wxS("<g style=\"stroke-linecap:round;\">\n");
write(s); write(s);
DoDrawLine ( x1,y1,x1,y1 ); DoDrawLine(x1, y1, x1, y1);
s = wxT("</g>"); s = wxS("</g>\n");
write(s); write(s);
} }
@@ -663,16 +651,15 @@ void wxSVGFileDCImpl::DoDrawRectangle(wxCoord x, wxCoord y, wxCoord width, wxCoo
DoDrawRoundedRectangle(x, y, width, height, 0); 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(); NewGraphicsIfNeeded();
wxString s; wxString s;
s.Printf ( wxT(" <rect x=\"%d\" y=\"%d\" width=\"%d\" height=\"%d\" rx=\"%s\" %s"), 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)); x, y, width, height, NumStr(radius), wxGetBrushFill(m_brush));
s += wxT(" /> \n"); s += wxS("/>\n");
write(s); write(s);
CalcBoundingBox(x, y); CalcBoundingBox(x, y);
@@ -684,22 +671,22 @@ void wxSVGFileDCImpl::DoDrawPolygon(int n, const wxPoint points[],
wxPolygonFillMode fillStyle) wxPolygonFillMode fillStyle)
{ {
NewGraphicsIfNeeded(); NewGraphicsIfNeeded();
wxString s, sTmp; wxString s;
s = wxT("<polygon style=\"");
if ( fillStyle == wxODDEVEN_RULE ) s = wxS(" <polygon style=\"");
s += wxT("fill-rule:evenodd; "); if (fillStyle == wxODDEVEN_RULE)
s += wxS("fill-rule:evenodd;");
else 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 += wxString::Format(wxS("%d %d "), points[i].x + xoffset, points[i].y + yoffset);
s += sTmp + wxT("\n"); CalcBoundingBox(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); write(s);
} }