/////////////////////////////////////////////////////////////////////////////
-// Name: svg.cpp
+// Name: src/common/svg.cpp
// Purpose: SVG sample
// Author: Chris Elliott
// Modified by:
#define wxSVG_DEBUG false
// or true to see the calls being executed
-#define newline wxString(wxT("\n"))
-#define space wxString(wxT(" "))
-#define semicolon wxString(wxT(";"))
-#define wx_round(a) (int)((a)+.5)
-
-
// ----------------------------------------------------------
// Global utilities
// ----------------------------------------------------------
-static inline double DegToRad(double deg) { return (deg * M_PI) / 180.0; }
-
-wxString wxColStr ( wxColour c )
+namespace
{
- unsigned char r, g, b;
- r = c.Red ();
- g = c.Green ();
- b = c. Blue ();
-
- // possible Unicode bug here
- wxString s = wxDecToHex(r) + wxDecToHex(g) + wxDecToHex(b);
- return s;
-}
+inline double DegToRad(double deg) { return (deg * M_PI) / 180.0; }
wxString wxBrushString ( wxColour c, int style )
{
- wxString s = wxT("fill:#") + wxColStr (c) + semicolon + space;
+ wxString s = wxT("fill:") + c.GetAsString(wxC2S_HTML_SYNTAX) + wxT("; ");
switch ( style )
{
case wxBRUSHSTYLE_SOLID :
wxASSERT_MSG(false, wxT("wxSVGFileDC::Requested Brush Style not available"));
}
- s = s + newline;
+ s = s + wxT("\n");
return s;
}
+// This function returns a string representation of a floating point number in
+// C locale (i.e. always using "." for the decimal separator) and with the
+// fixed precision (which is 2 for some unknown reason but this is what it was
+// in this code originally).
+inline wxString NumStr(double f)
+{
+ return wxString::FromCDouble(f, 2);
+}
+
+} // anonymous namespace
+
// ----------------------------------------------------------
// wxSVGFileDCImpl
// ----------------------------------------------------------
m_filename = filename;
m_sub_images = 0;
wxString s;
- s = wxT("<?xml version=\"1.0\" standalone=\"no\"?>"); s = s + newline;
+ s = wxT("<?xml version=\"1.0\" standalone=\"no\"?>") + wxString(wxT("\n"));
write(s);
- s = wxT("<!DOCTYPE svg PUBLIC \"-//W3C//DTD SVG 20010904//EN\" ") + newline;
+ s = wxT("<!DOCTYPE svg PUBLIC \"-//W3C//DTD SVG 20010904//EN\" ") + wxString(wxT("\n"));
write(s);
- s = wxT("\"http://www.w3.org/TR/2001/REC-SVG-20010904/DTD/svg10.dtd\"> ") + newline;
+ s = wxT("\"http://www.w3.org/TR/2001/REC-SVG-20010904/DTD/svg10.dtd\"> ") + wxString(wxT("\n"));
write(s);
- s = wxT("<svg xmlns=\"http://www.w3.org/2000/svg\" xmlns:xlink=\"http://www.w3.org/1999/xlink\" ") + newline;
+ s = wxT("<svg xmlns=\"http://www.w3.org/2000/svg\" xmlns:xlink=\"http://www.w3.org/1999/xlink\" ") + wxString(wxT("\n"));
write(s);
- s.Printf( wxT(" width=\"%.2gcm\" height=\"%.2gcm\" viewBox=\"0 0 %d %d \"> \n"), float(Width)/dpi*2.54, 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>") + newline;
+ s = wxT("<title>SVG Picture created as ") + wxFileName(filename).GetFullName() + wxT(" </title>") + wxT("\n");
write(s);
- s = wxString (wxT("<desc>Picture generated by wxSVG ")) + wxSVGVersion + wxT(" </desc>")+ newline;
+ s = wxString (wxT("<desc>Picture generated by wxSVG ")) + wxSVGVersion + wxT(" </desc>")+ wxT("\n");
write(s);
- s = wxT("<g style=\"fill:black; stroke:black; stroke-width:1\">") + newline;
+ s = wxT("<g style=\"fill:black; stroke:black; stroke-width:1\">") + wxString(wxT("\n"));
write(s);
}
}
{
wxString s;
if (m_graphics_changed) NewGraphics ();
- s = wxT("<g style = \"stroke-linecap:round;\" > ") + newline;
+ s = wxT("<g style = \"stroke-linecap:round;\" > ") + wxString(wxT("\n"));
write(s);
DoDrawLine ( x1,y1,x1,y1 );
s = wxT("</g>");
wxASSERT_MSG(!wxSVG_DEBUG, wxT("wxSVGFileDC::Draw Rotated Text Call plotting text background"));
sTmp.Printf ( wxT(" <rect x=\"%d\" y=\"%d\" width=\"%d\" height=\"%d\" "), x,y+desc-h, w, h );
- s = sTmp + wxT("style=\"fill:#") + wxColStr (m_textBackgroundColour) + wxT("; ");
- s = s + wxT("stroke-width:1; stroke:#") + wxColStr (m_textBackgroundColour) + wxT("; ");
- sTmp.Printf ( wxT("\" transform=\"rotate( %.2g %d %d ) \">"), -angle, x,y );
- s = s + sTmp + newline;
+ s = sTmp + wxT("style=\"fill:") + m_textBackgroundColour.GetAsString(wxC2S_HTML_SYNTAX) + wxT("; ");
+ s = s + wxT("stroke-width:1; stroke:") + m_textBackgroundColour.GetAsString(wxC2S_HTML_SYNTAX) + wxT("; ");
+ sTmp.Printf ( wxT("\" transform=\"rotate( %s %d %d ) \">"), NumStr(-angle), x,y );
+ s = s + sTmp + wxT("\n");
write(s);
}
//now do the text itself
else s = s + wxT("style=\" ");
wxString fontweights [3] = { wxT("normal"), wxT("lighter"), wxT("bold") };
- s = s + wxT("font-weight:") + fontweights[m_font.GetWeight() - wxNORMAL] + semicolon + space;
+ s = s + wxT("font-weight:") + fontweights[m_font.GetWeight() - wxNORMAL] + wxT("; ");
wxString fontstyles [5] = { wxT("normal"), wxT("style error"), wxT("style error"), wxT("italic"), wxT("oblique") };
- s = s + wxT("font-style:") + fontstyles[m_font.GetStyle() - wxNORMAL] + semicolon + space;
+ s = s + wxT("font-style:") + fontstyles[m_font.GetStyle() - wxNORMAL] + wxT("; ");
- sTmp.Printf (wxT("font-size:%dpt; fill:#"), m_font.GetPointSize () );
+ sTmp.Printf (wxT("font-size:%dpt; fill:"), m_font.GetPointSize () );
s = s + sTmp;
- s = s + wxColStr (m_textForegroundColour) + wxT("; stroke:#") + wxColStr (m_textForegroundColour) + wxT("; ");
- sTmp.Printf ( wxT("stroke-width:0;\" transform=\"rotate( %.2g %d %d ) \" >"), -angle, x,y );
- s = s + sTmp + sText + wxT("</text> ") + newline;
+ s = s + m_textForegroundColour.GetAsString(wxC2S_HTML_SYNTAX) + wxT("; stroke:") + m_textForegroundColour.GetAsString(wxC2S_HTML_SYNTAX) + wxT("; ");
+ sTmp.Printf ( wxT("stroke-width:0;\" transform=\"rotate( %s %d %d ) \" >"), NumStr(-angle), x,y );
+ s = s + sTmp + sText + wxT("</text> ") + wxT("\n");
if (m_OK)
{
write(s);
if (m_graphics_changed) NewGraphics ();
wxString s;
- s.Printf ( wxT(" <rect x=\"%d\" y=\"%d\" width=\"%d\" height=\"%d\" rx=\"%.2g\" "),
- x, y, width, height, radius );
+ s.Printf ( wxT(" <rect x=\"%d\" y=\"%d\" width=\"%d\" height=\"%d\" rx=\"%s\" "),
+ x, y, width, height, NumStr(radius) );
- s = s + wxT(" /> ") + newline;
+ s = s + wxT(" /> ") + wxT("\n");
write(s);
wxASSERT_MSG(!wxSVG_DEBUG, wxT("wxSVGFileDC::DoDrawRoundedRectangle Call executed"));
for (int i = 0; i < n; i++)
{
sTmp.Printf ( wxT("%d,%d"), points [i].x+xoffset, points[i].y+yoffset );
- s = s + sTmp + newline;
+ s = s + sTmp + wxT("\n");
CalcBoundingBox ( points [i].x+xoffset, points[i].y+yoffset);
}
s = s + wxT("\" /> ");
- s = s + newline;
+ s = s + wxT("\n");
write(s);
wxASSERT_MSG(!wxSVG_DEBUG, wxT("wxSVGFileDC::DoDrawPolygon Call executed"));
wxString s;
s.Printf ( wxT("<ellipse cx=\"%d\" cy=\"%d\" rx=\"%d\" ry=\"%d\" "), x+rw,y+rh, rw, rh );
- s = s + wxT(" /> ") + newline;
+ s = s + wxT(" /> ") + wxT("\n");
write(s);
int fSweep = 0; // flag for sweep always 0
- s.Printf ( wxT("<path d=\"M%d %d A%.2g %.2g 0.0 %d %d %d %d L%d %d z "),
- x1,y1, r1, r2, fArc, fSweep, x2, y2, xc, yc );
+ s.Printf ( wxT("<path d=\"M%d %d A%s %s 0.0 %d %d %d %d L%d %d z "),
+ x1,y1, NumStr(r1), NumStr(r2), fArc, fSweep, x2, y2, xc, yc );
// the z means close the path and fill
- s = s + wxT(" \" /> ") + newline;
+ s = s + wxT(" \" /> ") + wxT("\n");
if (m_OK)
fArc, fSweep, int(xe), int(ye), int(xc), int(yc) );
- s = s + wxT(" \" /> ") + newline;
+ s = s + wxT(" \" /> ") + wxT("\n");
if (m_OK)
{
wxString s, sBrush, sPenCap, sPenJoin, sPenStyle, sLast, sWarn;
sBrush = wxT("</g>\n<g style=\"") + wxBrushString ( m_brush.GetColour (), m_brush.GetStyle () )
- + wxT(" stroke:#") + wxColStr (c) + wxT("; ");
+ + wxT(" stroke:") + c.GetAsString(wxC2S_HTML_SYNTAX) + wxT("; ");
switch ( m_pen.GetCap () )
{
sWarn = sWarn + wxT("<!--- wxSVGFileDC::SetPen Call called to set a Style which is not available --> \n");
}
- sLast.Printf( wxT("stroke-width:%d\" \n transform=\"translate(%.2g %.2g) scale(%.2g %.2g)\">"),
- w, double(m_logicalOriginX), double(m_logicalOriginY), m_scaleX, m_scaleY );
+ sLast.Printf( wxT("stroke-width:%d\" \n transform=\"translate(%s %s) scale(%s %s)\">"),
+ w, NumStr(m_logicalOriginX), NumStr(m_logicalOriginY), NumStr(m_scaleX), NumStr(m_scaleY) );
- s = sBrush + sPenCap + sPenJoin + sPenStyle + sLast + newline + sWarn;
+ s = sBrush + sPenCap + sPenJoin + sPenStyle + sLast + wxT("\n") + sWarn;
write(s);
m_graphics_changed = false;
wxASSERT_MSG(!wxSVG_DEBUG, wxT("wxSVGFileDC::NewGraphics Call executed"));
sTmp.Printf ( wxT(" <image x=\"%d\" y=\"%d\" width=\"%dpx\" height=\"%dpx\" "), x,y,w,h );
s = s + sTmp;
sTmp.Printf ( wxT(" xlink:href=\"%s\"> \n"), sPNG.c_str() );
- s = s + sTmp + wxT("<title>Image from wxSVG</title> </image>") + newline;
+ s = s + sTmp + wxT("<title>Image from wxSVG</title> </image>") + wxT("\n");
if (m_OK && bPNG_OK)
{