From: Vadim Zeitlin Date: Mon, 14 Mar 2011 23:25:58 +0000 (+0000) Subject: No changes, just clean up wxSVGFileDC code a little. X-Git-Url: https://git.saurik.com/wxWidgets.git/commitdiff_plain/1f4d7e441c3706ae396a4153df76871080ea3802?hp=8864388cf203f3238d45f283676744f624304c71 No changes, just clean up wxSVGFileDC code a little. Use literal strings instead of macros such as "newline", "space" and "semicolon" and also use wxColour::GetAsString() instead of reimplementing it. Closes #13037. git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@67195 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775 --- diff --git a/src/common/dcsvg.cpp b/src/common/dcsvg.cpp index 1a5a0cf80f..648e7684b0 100644 --- a/src/common/dcsvg.cpp +++ b/src/common/dcsvg.cpp @@ -31,12 +31,6 @@ #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 // ---------------------------------------------------------- @@ -46,22 +40,9 @@ namespace inline double DegToRad(double deg) { return (deg * M_PI) / 180.0; } -wxString wxColStr ( wxColour c ) -{ - 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; -} - - 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 : @@ -75,7 +56,7 @@ 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; } @@ -135,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"), 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); } } @@ -203,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(""); @@ -250,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(" "), NumStr(-angle), x,y ); - s = s + sTmp + newline; + s = s + sTmp + wxT("\n"); write(s); } //now do the text itself @@ -264,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("; "); + 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(" ") + newline; + s = s + sTmp + sText + wxT(" ") + wxT("\n"); if (m_OK) { write(s); @@ -295,7 +276,7 @@ void wxSVGFileDCImpl::DoDrawRoundedRectangle(wxCoord x, wxCoord y, wxCoord width s.Printf ( wxT(" ") + newline; + s = s + wxT(" /> ") + wxT("\n"); write(s); wxASSERT_MSG(!wxSVG_DEBUG, wxT("wxSVGFileDC::DoDrawRoundedRectangle Call executed")); @@ -320,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")); @@ -340,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); @@ -389,7 +370,7 @@ void wxSVGFileDCImpl::DoDrawArc(wxCoord x1, wxCoord y1, wxCoord x2, wxCoord y2, 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) @@ -453,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) { @@ -544,7 +525,7 @@ void wxSVGFileDCImpl::NewGraphics () wxString s, sBrush, sPenCap, sPenJoin, sPenStyle, sLast, sWarn; sBrush = wxT("\n"), 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")); @@ -673,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) {