From: Vadim Zeitlin Date: Mon, 14 Mar 2011 11:54:43 +0000 (+0000) Subject: Produce correct SVG files in all locales. X-Git-Url: https://git.saurik.com/wxWidgets.git/commitdiff_plain/caef3ffacc79373de63a3c406d31d8dffedcf903 Produce correct SVG files in all locales. Using wxSVGFileDC in locales using comma as decimal separator resulted in invalid SVG files being created as a decimal period should always be used in them. Fix this by replacing "%g" format specification with wxString::FromCDouble() call (wrapped in a convenient NumStr() helper function). Closes #12008. git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@67188 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775 --- diff --git a/docs/changes.txt b/docs/changes.txt index 0a1297d4ef..91e69c97c0 100644 --- a/docs/changes.txt +++ b/docs/changes.txt @@ -484,6 +484,7 @@ All (GUI): - Fix wxWrapSizer minimal size calculation (Catalin Raceanu). - Added wxFont::Underlined() and MakeUnderlined() methods. - Added wxFont::SetSymbolicSize() and related methods. +- Fix SVG files generation in locales using decimal comma (snowleopard). GTK: diff --git a/src/common/dcsvg.cpp b/src/common/dcsvg.cpp index 3abd5a6389..1a5a0cf80f 100644 --- a/src/common/dcsvg.cpp +++ b/src/common/dcsvg.cpp @@ -41,7 +41,10 @@ // Global utilities // ---------------------------------------------------------- -static inline double DegToRad(double deg) { return (deg * M_PI) / 180.0; } +namespace +{ + +inline double DegToRad(double deg) { return (deg * M_PI) / 180.0; } wxString wxColStr ( wxColour c ) { @@ -76,6 +79,17 @@ wxString wxBrushString ( wxColour c, int style ) 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 // ---------------------------------------------------------- @@ -127,9 +141,9 @@ void wxSVGFileDCImpl::Init (const wxString &filename, int Width, int Height, dou write(s); s = wxT("\"http://www.w3.org/TR/2001/REC-SVG-20010904/DTD/svg10.dtd\"> ") + newline; write(s); - s = wxT(" \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("SVG Picture created as ") + wxFileName(filename).GetFullName() + wxT(" ") + newline; write(s); @@ -238,7 +252,7 @@ void wxSVGFileDCImpl::DoDrawRotatedText(const wxString& sText, wxCoord x, wxCoor sTmp.Printf ( wxT(" "), -angle, x,y ); + sTmp.Printf ( wxT("\" transform=\"rotate( %s %d %d ) \">"), NumStr(-angle), x,y ); s = s + sTmp + newline; write(s); } @@ -258,7 +272,7 @@ void wxSVGFileDCImpl::DoDrawRotatedText(const wxString& sText, wxCoord x, wxCoor 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 ); + sTmp.Printf ( wxT("stroke-width:0;\" transform=\"rotate( %s %d %d ) \" >"), NumStr(-angle), x,y ); s = s + sTmp + sText + wxT(" ") + newline; if (m_OK) { @@ -278,8 +292,8 @@ void wxSVGFileDCImpl::DoDrawRoundedRectangle(wxCoord x, wxCoord y, wxCoord width if (m_graphics_changed) NewGraphics (); wxString s; - s.Printf ( wxT(" ") + newline; write(s); @@ -371,8 +385,8 @@ void wxSVGFileDCImpl::DoDrawArc(wxCoord x1, wxCoord y1, wxCoord x2, wxCoord y2, int fSweep = 0; // flag for sweep always 0 - s.Printf ( wxT(" ") + newline; @@ -570,8 +584,8 @@ void wxSVGFileDCImpl::NewGraphics () sWarn = sWarn + wxT(" \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; write(s);