X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/526954c5968baa29218c994ec48e476ae2bd4b9f..34b239ec5d9c20a78adaa2dd680bd482b43a68f7:/src/common/dcsvg.cpp diff --git a/src/common/dcsvg.cpp b/src/common/dcsvg.cpp index 3abd5a6389..4d1074384a 100644 --- a/src/common/dcsvg.cpp +++ b/src/common/dcsvg.cpp @@ -1,5 +1,5 @@ ///////////////////////////////////////////////////////////////////////////// -// Name: svg.cpp +// Name: src/common/svg.cpp // Purpose: SVG sample // Author: Chris Elliott // Modified by: @@ -31,34 +31,18 @@ #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 : @@ -72,10 +56,21 @@ wxString wxBrushString ( wxColour c, int style ) 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 // ---------------------------------------------------------- @@ -121,21 +116,21 @@ void wxSVGFileDCImpl::Init (const wxString &filename, int Width, int Height, dou m_filename = filename; m_sub_images = 0; wxString s; - s = wxT(""); s = s + newline; + s = wxT("") + wxString(wxT("\n")); write(s); - s = wxT(" ") + newline; + s = wxT("\"http://www.w3.org/TR/2001/REC-SVG-20010904/DTD/svg10.dtd\"> ") + wxString(wxT("\n")); 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; + s = wxT("SVG Picture created as ") + wxFileName(filename).GetFullName() + wxT(" ") + wxT("\n"); write(s); - s = wxString (wxT("Picture generated by wxSVG ")) + wxSVGVersion + wxT(" ")+ newline; + s = wxString (wxT("Picture generated by wxSVG ")) + wxSVGVersion + wxT(" ")+ wxT("\n"); write(s); - s = wxT("") + newline; + s = wxT("") + wxString(wxT("\n")); write(s); } } @@ -189,7 +184,7 @@ void wxSVGFileDCImpl::DoDrawPoint (wxCoord x1, wxCoord y1) { wxString s; if (m_graphics_changed) NewGraphics (); - s = wxT(" ") + newline; + s = wxT(" ") + wxString(wxT("\n")); write(s); DoDrawLine ( x1,y1,x1,y1 ); s = wxT(""); @@ -236,10 +231,10 @@ void wxSVGFileDCImpl::DoDrawRotatedText(const wxString& sText, wxCoord x, wxCoor wxASSERT_MSG(!wxSVG_DEBUG, wxT("wxSVGFileDC::Draw Rotated Text Call plotting text background")); sTmp.Printf ( wxT(" "), -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 @@ -250,16 +245,16 @@ void wxSVGFileDCImpl::DoDrawRotatedText(const wxString& sText, wxCoord x, wxCoor 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(" ") + 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(" ") + wxT("\n"); if (m_OK) { write(s); @@ -278,10 +273,10 @@ void wxSVGFileDCImpl::DoDrawRoundedRectangle(wxCoord x, wxCoord y, wxCoord width if (m_graphics_changed) NewGraphics (); wxString s; - s.Printf ( wxT(" ") + newline; + s = s + wxT(" /> ") + wxT("\n"); write(s); wxASSERT_MSG(!wxSVG_DEBUG, wxT("wxSVGFileDC::DoDrawRoundedRectangle Call executed")); @@ -306,11 +301,11 @@ void wxSVGFileDCImpl::DoDrawPolygon(int n, wxPoint points[], 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")); @@ -326,7 +321,7 @@ void wxSVGFileDCImpl::DoDrawEllipse (wxCoord x, wxCoord y, wxCoord width, wxCoor wxString s; s.Printf ( wxT(" ") + newline; + s = s + wxT(" /> ") + wxT("\n"); write(s); @@ -371,11 +366,11 @@ void wxSVGFileDCImpl::DoDrawArc(wxCoord x1, wxCoord y1, wxCoord x2, wxCoord y2, int fSweep = 0; // flag for sweep always 0 - s.Printf ( wxT(" ") + newline; + s = s + wxT(" \" /> ") + wxT("\n"); if (m_OK) @@ -439,7 +434,7 @@ void wxSVGFileDCImpl::DoDrawEllipticArc(wxCoord x,wxCoord y,wxCoord w,wxCoord h, fArc, fSweep, int(xe), int(ye), int(xc), int(yc) ); - s = s + wxT(" \" /> ") + newline; + s = s + wxT(" \" /> ") + wxT("\n"); if (m_OK) { @@ -530,7 +525,7 @@ void wxSVGFileDCImpl::NewGraphics () wxString s, sBrush, sPenCap, sPenJoin, sPenStyle, sLast, sWarn; sBrush = wxT("\n \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")); @@ -659,7 +654,7 @@ void wxSVGFileDCImpl::DoDrawBitmap(const class wxBitmap & bmp, wxCoord x, wxCoor sTmp.Printf ( wxT(" \n"), sPNG.c_str() ); - s = s + sTmp + wxT("Image from wxSVG ") + newline; + s = s + sTmp + wxT("Image from wxSVG ") + wxT("\n"); if (m_OK && bPNG_OK) {