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
This commit is contained in:
@@ -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("<?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=\"%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);
|
||||
}
|
||||
}
|
||||
@@ -203,7 +184,7 @@ void wxSVGFileDCImpl::DoDrawPoint (wxCoord x1, wxCoord y1)
|
||||
{
|
||||
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>");
|
||||
@@ -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(" <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("; ");
|
||||
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 + 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("</text> ") + newline;
|
||||
s = s + sTmp + sText + wxT("</text> ") + wxT("\n");
|
||||
if (m_OK)
|
||||
{
|
||||
write(s);
|
||||
@@ -295,7 +276,7 @@ void wxSVGFileDCImpl::DoDrawRoundedRectangle(wxCoord x, wxCoord y, wxCoord width
|
||||
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"));
|
||||
@@ -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("<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);
|
||||
|
||||
@@ -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("</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 () )
|
||||
{
|
||||
@@ -587,7 +568,7 @@ void wxSVGFileDCImpl::NewGraphics ()
|
||||
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"));
|
||||
@@ -673,7 +654,7 @@ void wxSVGFileDCImpl::DoDrawBitmap(const class wxBitmap & bmp, wxCoord x, wxCoor
|
||||
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)
|
||||
{
|
||||
|
Reference in New Issue
Block a user