From 215f844502405c9b82b93d929eb2c8a1361274ca Mon Sep 17 00:00:00 2001 From: Maarten Bent Date: Sat, 10 Aug 2019 19:33:33 +0200 Subject: [PATCH 01/12] Improve whitespace formatting in generated SVG Write coordinates first, then styles. --- src/common/dcsvg.cpp | 149 +++++++++++++++++++++++-------------------- 1 file changed, 81 insertions(+), 68 deletions(-) diff --git a/src/common/dcsvg.cpp b/src/common/dcsvg.cpp index 6229cd863f..f8b2176255 100644 --- a/src/common/dcsvg.cpp +++ b/src/common/dcsvg.cpp @@ -48,7 +48,10 @@ namespace // in this code originally). inline wxString NumStr(double f) { - return wxString::FromCDouble(f, 2); + if ( f == 0 ) + return wxS("0.00"); + else + return wxString::FromCDouble(f, 2); } // Return the colour representation as HTML-like "#rrggbb" string and also @@ -74,7 +77,7 @@ wxString Col2SVG(wxColour c, float *opacity) wxString wxPenString(wxColour c, int style = wxPENSTYLE_SOLID) { float opacity; - wxString s = wxS("stroke:") + Col2SVG(c, &opacity) + wxS("; "); + wxString s = wxS("stroke:") + Col2SVG(c, &opacity) + wxS(";"); switch ( style ) { @@ -84,10 +87,10 @@ wxString wxPenString(wxColour c, int style = wxPENSTYLE_SOLID) case wxPENSTYLE_LONG_DASH: case wxPENSTYLE_DOT_DASH: case wxPENSTYLE_USER_DASH: - s += wxString::Format(wxS("stroke-opacity:%s; "), NumStr(opacity)); + s += wxString::Format(wxS(" stroke-opacity:%s;"), NumStr(opacity)); break; case wxPENSTYLE_TRANSPARENT: - s += wxS("stroke-opacity:0.0; "); + s += wxS(" stroke-opacity:0.0;"); break; default: wxASSERT_MSG(false, wxS("wxSVGFileDC::Requested Pen Style not available")); @@ -99,7 +102,7 @@ wxString wxPenString(wxColour c, int style = wxPENSTYLE_SOLID) wxString wxBrushString(wxColour c, int style = wxBRUSHSTYLE_SOLID) { float opacity; - wxString s = wxS("fill:") + Col2SVG(c, &opacity) + wxS("; "); + wxString s = wxS("fill:") + Col2SVG(c, &opacity) + wxS(";"); switch ( style ) { @@ -109,10 +112,10 @@ wxString wxBrushString(wxColour c, int style = wxBRUSHSTYLE_SOLID) case wxBRUSHSTYLE_CROSS_HATCH: case wxBRUSHSTYLE_VERTICAL_HATCH: case wxBRUSHSTYLE_HORIZONTAL_HATCH: - s += wxString::Format(wxS("fill-opacity:%s; "), NumStr(opacity)); + s += wxString::Format(wxS(" fill-opacity:%s;"), NumStr(opacity)); break; case wxBRUSHSTYLE_TRANSPARENT: - s += wxS("fill-opacity:0.0; "); + s += wxS(" fill-opacity:0.0;"); break; default: wxASSERT_MSG(false, wxS("wxSVGFileDC::Requested Brush Style not available")); @@ -139,16 +142,16 @@ wxString wxGetPenPattern(wxPen& pen) switch (pen.GetStyle()) { case wxPENSTYLE_DOT: - s = wxString::Format(wxS("stroke-dasharray=\"%f,%f\" "), w * 2, w * 5); + s = wxString::Format(wxS("stroke-dasharray=\"%f,%f\""), w * 2, w * 5); break; case wxPENSTYLE_SHORT_DASH: - s = wxString::Format(wxS("stroke-dasharray=\"%f,%f\" "), w * 10, w * 8); + s = wxString::Format(wxS("stroke-dasharray=\"%f,%f\""), w * 10, w * 8); break; case wxPENSTYLE_LONG_DASH: - s = wxString::Format(wxS("stroke-dasharray=\"%f,%f\" "), w * 15, w * 8); + s = wxString::Format(wxS("stroke-dasharray=\"%f,%f\""), w * 15, w * 8); break; case wxPENSTYLE_DOT_DASH: - s = wxString::Format(wxS("stroke-dasharray=\"%f,%f,%f,%f\" "), w * 8, w * 8, w * 2, w * 8); + s = wxString::Format(wxS("stroke-dasharray=\"%f,%f,%f,%f\""), w * 8, w * 8, w * 2, w * 8); break; case wxPENSTYLE_USER_DASH: { @@ -164,7 +167,7 @@ wxString wxGetPenPattern(wxPen& pen) s << ","; } } - s += wxS("\" "); + s += wxS("\""); break; } case wxPENSTYLE_STIPPLE_MASK_OPAQUE: @@ -230,7 +233,7 @@ wxString wxGetBrushFill(wxBrush& brush) wxString brushStyle = wxGetBrushStyleName(brush); if (!brushStyle.IsEmpty()) - s = wxS(" fill=\"url(#") + brushStyle + brush.GetColour().GetAsString(wxC2S_HTML_SYNTAX).substr(1) + wxS(")\""); + s = wxS("fill=\"url(#") + brushStyle + brush.GetColour().GetAsString(wxC2S_HTML_SYNTAX).substr(1) + wxS(")\""); return s; } @@ -242,32 +245,35 @@ wxString wxCreateBrushFill(wxBrush& brush) if (!patternName.IsEmpty()) { - patternName += brush.GetColour().GetAsString(wxC2S_HTML_SYNTAX).substr(1); - s = wxS("\n"); - s += wxS(" \n\n"); + wxString brushColourStr = brush.GetColour().GetAsString(wxC2S_HTML_SYNTAX); + + s += wxString::Format(wxS(" \n"), + patternName, brushColourStr.substr(1)); + s += wxString::Format(wxS(" \n"), + brushColourStr, pattern); + s += wxS(" \n"); } return s; @@ -490,7 +496,8 @@ void wxSVGFileDCImpl::DoDrawLine(wxCoord x1, wxCoord y1, wxCoord x2, wxCoord y2) NewGraphicsIfNeeded(); wxString s; - s = wxString::Format(wxS(" \n"), wxGetPenPattern(m_pen), x1, y1, x2, y2); + s = wxString::Format(wxS(" \n"), + x1, y1, x2, y2, wxGetPenPattern(m_pen)); write(s); @@ -505,8 +512,9 @@ void wxSVGFileDCImpl::DoDrawLines(int n, const wxPoint points[], wxCoord xoffset NewGraphicsIfNeeded(); wxString s; - s = wxS(" \n"); + s += wxString::Format(wxS("\" style=\"fill:none\" %s/>\n"), + wxGetPenPattern(m_pen)); write(s); } @@ -523,12 +532,16 @@ void wxSVGFileDCImpl::DoDrawLines(int n, const wxPoint points[], wxCoord xoffset void wxSVGFileDCImpl::DoDrawPoint(wxCoord x1, wxCoord y1) { - wxString s; NewGraphicsIfNeeded(); - s = wxS("\n"); + + wxString s; + + s = wxS(" \n "); write(s); + DoDrawLine(x1, y1, x1, y1); - s = wxS("\n"); + + s = wxS(" \n"); write(s); } @@ -666,10 +679,10 @@ void wxSVGFileDCImpl::DoDrawRoundedRectangle(wxCoord x, wxCoord y, wxCoord width NewGraphicsIfNeeded(); wxString s; - s = wxString::Format(wxS(" \n"), + x, y, width, height, NumStr(radius), + wxGetPenPattern(m_pen), wxGetBrushFill(m_brush)); - s += wxS("/>\n"); write(s); CalcBoundingBox(x, y); @@ -681,22 +694,21 @@ void wxSVGFileDCImpl::DoDrawPolygon(int n, const wxPoint points[], wxPolygonFillMode fillStyle) { NewGraphicsIfNeeded(); + wxString s; - s = wxS(" \n"); + + s += wxString::Format(wxS("\" %s %s style=\"fill-rule:%s;\"/>\n"), + wxGetPenPattern(m_pen), wxGetBrushFill(m_brush), + (fillStyle == wxODDEVEN_RULE) ? wxS("evenodd") : wxS("nonzero")); + write(s); } @@ -750,8 +762,8 @@ void wxSVGFileDCImpl::DoDrawEllipse(wxCoord x, wxCoord y, wxCoord width, wxCoord int rw = width / 2; wxString s; - s = wxString::Format(wxS(" \n"); write(s); @@ -803,8 +815,8 @@ void wxSVGFileDCImpl::DoDrawArc(wxCoord x1, wxCoord y1, wxCoord x2, wxCoord y2, if (x1 == x2 && y1 == y2) { // drawing full circle fails with default arc. Draw two half arcs instead. - s = wxString::Format(wxS(" \n"); + s += wxString::Format(wxS("\" %s/>\n"), wxGetPenPattern(m_pen)); write(s); } @@ -883,15 +894,15 @@ void wxSVGFileDCImpl::DoDrawEllipticArc(wxCoord x, wxCoord y, wxCoord w, wxCoord { // Drawing full circle fails with default arc. Draw two half arcs instead. fArc = 1; - arcPath = wxString::Format(wxS(" \n"); + arcFill += wxString::Format(wxS(" L%s %s z\" %s/>\n"), + NumStr(xc), NumStr(yc), wxGetPenPattern(m_pen)); write(arcFill); } wxDCBrushChanger setTransp(*GetOwner(), *wxTRANSPARENT_BRUSH); NewGraphicsIfNeeded(); - wxString arcLine = arcPath + wxS("\"/>\n"); + wxString arcLine = wxString::Format(wxS("%s\" %s/>\n"), + arcPath, wxGetPenPattern(m_pen)); write(arcLine); } @@ -1051,45 +1063,46 @@ void wxSVGFileDCImpl::NewGraphicsIfNeeded() void wxSVGFileDCImpl::DoStartNewGraphics() { - wxString s, sBrush, sPenCap, sPenJoin, sPenStyle, sLast; - - sBrush = wxS(""), + sLast = wxString::Format(wxS("stroke-width:%d\" transform=\"translate(%s %s) scale(%s %s)\""), m_pen.GetWidth(), NumStr((m_deviceOriginX - m_logicalOriginX)* m_signX), NumStr((m_deviceOriginY - m_logicalOriginY)* m_signY), NumStr(m_scaleX * m_signX), NumStr(m_scaleY * m_signY)); - s = sBrush + sPenCap + sPenJoin + sPenStyle + sLast + wxS("\n"); + + s = wxString::Format(wxS("\n"), + wxBrushString(m_brush.GetColour(), m_brush.GetStyle()), + wxPenString(m_pen.GetColour(), m_pen.GetStyle()), + sPenCap, sPenJoin, sLast); write(s); } From e7c03a5646b96ba15be41298c46feda89bfaf541 Mon Sep 17 00:00:00 2001 From: Maarten Bent Date: Sat, 10 Aug 2019 20:17:55 +0200 Subject: [PATCH 02/12] Use const references in SVG helper functions Add helper function to get pen style. Use Col2SVG for wxBrush colours. --- src/common/dcsvg.cpp | 119 +++++++++++++++++++++++-------------------- 1 file changed, 65 insertions(+), 54 deletions(-) diff --git a/src/common/dcsvg.cpp b/src/common/dcsvg.cpp index f8b2176255..edfe87f27d 100644 --- a/src/common/dcsvg.cpp +++ b/src/common/dcsvg.cpp @@ -46,7 +46,7 @@ namespace // 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) +inline wxString NumStr(double const& f) { if ( f == 0 ) return wxS("0.00"); @@ -56,11 +56,12 @@ inline wxString NumStr(double f) // Return the colour representation as HTML-like "#rrggbb" string and also // returns its alpha as opacity number in 0..1 range. -wxString Col2SVG(wxColour c, float *opacity) +wxString Col2SVG(wxColour c, float *opacity = NULL) { if ( c.Alpha() != wxALPHA_OPAQUE ) { - *opacity = c.Alpha() / 255.0f; + if ( opacity ) + *opacity = c.Alpha() / 255.0f; // Remove the alpha before using GetAsString(wxC2S_HTML_SYNTAX) as it // doesn't support colours with alpha channel. @@ -68,13 +69,14 @@ wxString Col2SVG(wxColour c, float *opacity) } else // No alpha. { - *opacity = 1.; + if ( opacity ) + *opacity = 1.; } return c.GetAsString(wxC2S_HTML_SYNTAX); } -wxString wxPenString(wxColour c, int style = wxPENSTYLE_SOLID) +wxString wxStrokeString(wxColour const& c, int style = wxPENSTYLE_SOLID) { float opacity; wxString s = wxS("stroke:") + Col2SVG(c, &opacity) + wxS(";"); @@ -94,12 +96,13 @@ wxString wxPenString(wxColour c, int style = wxPENSTYLE_SOLID) break; default: wxASSERT_MSG(false, wxS("wxSVGFileDC::Requested Pen Style not available")); + break; } return s; } -wxString wxBrushString(wxColour c, int style = wxBRUSHSTYLE_SOLID) +wxString wxFillString(wxColour c, int style = wxBRUSHSTYLE_SOLID) { float opacity; wxString s = wxS("fill:") + Col2SVG(c, &opacity) + wxS(";"); @@ -119,13 +122,13 @@ wxString wxBrushString(wxColour c, int style = wxBRUSHSTYLE_SOLID) break; default: wxASSERT_MSG(false, wxS("wxSVGFileDC::Requested Brush Style not available")); + break; } return s; } -static -wxString wxGetPenPattern(wxPen& pen) +wxString wxGetPenPattern(wxPen const& pen) { wxString s; @@ -190,7 +193,44 @@ wxString wxGetPenPattern(wxPen& pen) return s; } -wxString wxGetBrushStyleName(wxBrush& brush) +wxString wxGetPenStyle(wxPen const& pen) +{ + wxString penStyle; + + penStyle += wxString::Format(wxS("stroke-width:%d;"), pen.GetWidth()); + + switch (pen.GetCap()) + { + case wxCAP_PROJECTING: + penStyle += wxS(" stroke-linecap:square;"); + break; + case wxCAP_BUTT: + penStyle += wxS(" stroke-linecap:butt;"); + break; + case wxCAP_ROUND: + default: + penStyle += wxS(" stroke-linecap:round;"); + break; + } + + switch (pen.GetJoin()) + { + case wxJOIN_BEVEL: + penStyle += wxS(" stroke-linejoin:bevel;"); + break; + case wxJOIN_MITER: + penStyle += wxS(" stroke-linejoin:miter;"); + break; + case wxJOIN_ROUND: + default: + penStyle += wxS(" stroke-linejoin:round;"); + break; + } + + return penStyle; +} + +wxString wxGetBrushStyleName(wxBrush const& brush) { wxString brushStyle; @@ -227,13 +267,13 @@ wxString wxGetBrushStyleName(wxBrush& brush) return brushStyle; } -wxString wxGetBrushFill(wxBrush& brush) +wxString wxGetBrushFill(wxBrush const& brush) { wxString s; wxString brushStyle = wxGetBrushStyleName(brush); if (!brushStyle.IsEmpty()) - s = wxS("fill=\"url(#") + brushStyle + brush.GetColour().GetAsString(wxC2S_HTML_SYNTAX).substr(1) + wxS(")\""); + s = wxS("fill=\"url(#") + brushStyle + Col2SVG(brush.GetColour()).substr(1) + wxS(")\""); return s; } @@ -267,7 +307,7 @@ wxString wxCreateBrushFill(wxBrush& brush) break; } - wxString brushColourStr = brush.GetColour().GetAsString(wxC2S_HTML_SYNTAX); + wxString brushColourStr = Col2SVG(brush.GetColour()); s += wxString::Format(wxS(" \n"), patternName, brushColourStr.substr(1)); @@ -609,8 +649,8 @@ void wxSVGFileDCImpl::DoDrawRotatedText(const wxString& sText, wxCoord x, wxCoor style += wxString::Format(wxS("font-size:%spt; "), NumStr(m_font.GetFractionalPointSize())); style += wxString::Format(wxS("text-decoration:%s; "), textDecoration); style += wxString::Format(wxS("%s %s stroke-width:0; "), - wxBrushString(m_textForegroundColour), - wxPenString(m_textForegroundColour)); + wxFillString(m_textForegroundColour), + wxStrokeString(m_textForegroundColour)); style += wxS("white-space: pre;"); style += wxS("\""); @@ -637,8 +677,8 @@ void wxSVGFileDCImpl::DoDrawRotatedText(const wxString& sText, wxCoord x, wxCoor // draw text background const wxString rectStyle = wxString::Format( wxS("style=\"%s %s stroke-width:1;\""), - wxBrushString(m_textBackgroundColour), - wxPenString(m_textBackgroundColour)); + wxFillString(m_textBackgroundColour), + wxStrokeString(m_textBackgroundColour)); const wxString rectTransform = wxString::Format( wxS("transform=\"rotate(%s %d %d)\""), @@ -1063,46 +1103,17 @@ void wxSVGFileDCImpl::NewGraphicsIfNeeded() void wxSVGFileDCImpl::DoStartNewGraphics() { - wxString s, sPenCap, sPenJoin, sLast; + wxString s; - switch ( m_pen.GetCap() ) - { - case wxCAP_PROJECTING: - sPenCap = wxS("stroke-linecap:square;"); - break; - case wxCAP_BUTT: - sPenCap = wxS("stroke-linecap:butt;"); - break; - case wxCAP_ROUND: - default: - sPenCap = wxS("stroke-linecap:round;"); - } + s = wxString::Format(wxS("\n"), + wxGetPenStyle(m_pen), + wxFillString(m_brush.GetColour(), m_brush.GetStyle()), + wxStrokeString(m_pen.GetColour(), m_pen.GetStyle()), + NumStr((m_deviceOriginX - m_logicalOriginX) * m_signX), + NumStr((m_deviceOriginY - m_logicalOriginY) * m_signY), + NumStr(m_scaleX * m_signX), + NumStr(m_scaleY * m_signY)); - switch (m_pen.GetJoin()) - { - case wxJOIN_BEVEL: - sPenJoin = wxS("stroke-linejoin:bevel;"); - break; - case wxJOIN_MITER: - sPenJoin = wxS("stroke-linejoin:miter;"); - break; - case wxJOIN_ROUND: - default: - sPenJoin = wxS("stroke-linejoin:round;"); - } - - sLast = wxString::Format(wxS("stroke-width:%d\" transform=\"translate(%s %s) scale(%s %s)\""), - m_pen.GetWidth(), - NumStr((m_deviceOriginX - m_logicalOriginX)* m_signX), - NumStr((m_deviceOriginY - m_logicalOriginY)* m_signY), - NumStr(m_scaleX * m_signX), - NumStr(m_scaleY * m_signY)); - - - s = wxString::Format(wxS("\n"), - wxBrushString(m_brush.GetColour(), m_brush.GetStyle()), - wxPenString(m_pen.GetColour(), m_pen.GetStyle()), - sPenCap, sPenJoin, sLast); write(s); } From 9412aea1f6664f9a27f5ab93eb83067f85af8393 Mon Sep 17 00:00:00 2001 From: Maarten Bent Date: Sat, 10 Aug 2019 20:22:42 +0200 Subject: [PATCH 03/12] Implement wxBRUSHSTYLE_BDIAGONAL_HATCH for wxSVGFileDC Create new graphics group before writing brush pattern, so pattern appears in the same group as the elements using it. --- src/common/dcsvg.cpp | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/src/common/dcsvg.cpp b/src/common/dcsvg.cpp index edfe87f27d..e9ae18ba4a 100644 --- a/src/common/dcsvg.cpp +++ b/src/common/dcsvg.cpp @@ -110,6 +110,7 @@ wxString wxFillString(wxColour c, int style = wxBRUSHSTYLE_SOLID) switch ( style ) { case wxBRUSHSTYLE_SOLID: + case wxBRUSHSTYLE_BDIAGONAL_HATCH: case wxBRUSHSTYLE_FDIAGONAL_HATCH: case wxBRUSHSTYLE_CROSSDIAG_HATCH: case wxBRUSHSTYLE_CROSS_HATCH: @@ -236,6 +237,9 @@ wxString wxGetBrushStyleName(wxBrush const& brush) switch (brush.GetStyle()) { + case wxBRUSHSTYLE_BDIAGONAL_HATCH: + brushStyle = wxS("BdiagonalHatch"); + break; case wxBRUSHSTYLE_FDIAGONAL_HATCH: brushStyle = wxS("FdiagonalHatch"); break; @@ -254,7 +258,6 @@ wxString wxGetBrushStyleName(wxBrush const& brush) case wxBRUSHSTYLE_STIPPLE_MASK_OPAQUE: case wxBRUSHSTYLE_STIPPLE_MASK: case wxBRUSHSTYLE_STIPPLE: - case wxBRUSHSTYLE_BDIAGONAL_HATCH: wxASSERT_MSG(false, wxS("wxSVGFileDC::Requested Brush Fill not available")); break; case wxBRUSHSTYLE_SOLID: @@ -288,6 +291,9 @@ wxString wxCreateBrushFill(wxBrush& brush) wxString pattern; switch (brush.GetStyle()) { + case wxBRUSHSTYLE_BDIAGONAL_HATCH: + pattern = wxS("d=\"M-1,1 l2,-2 M0,8 l8,-8 M7,9 l2,-2\""); + break; case wxBRUSHSTYLE_FDIAGONAL_HATCH: pattern = wxS("d=\"M7,-1 l2,2 M0,0 l8,8 M-1,7 l2,2\""); break; @@ -1079,7 +1085,12 @@ void wxSVGFileDCImpl::SetBrush(const wxBrush& brush) m_graphics_changed = true; wxString pattern = wxCreateBrushFill(m_brush); - write(pattern); + if ( !pattern.IsEmpty() ) + { + NewGraphicsIfNeeded(); + + write(pattern); + } } void wxSVGFileDCImpl::SetPen(const wxPen& pen) From 75f08dfd51a29986bc0ef68b9a13daa45c8423fa Mon Sep 17 00:00:00 2001 From: Maarten Bent Date: Sat, 10 Aug 2019 20:52:15 +0200 Subject: [PATCH 04/12] Use floating point positions in wxSVGFileDC DrawRotatedText and DrawEllipse --- src/common/dcsvg.cpp | 32 ++++++++++++++++---------------- 1 file changed, 16 insertions(+), 16 deletions(-) diff --git a/src/common/dcsvg.cpp b/src/common/dcsvg.cpp index e9ae18ba4a..f5029d7f34 100644 --- a/src/common/dcsvg.cpp +++ b/src/common/dcsvg.cpp @@ -668,15 +668,15 @@ void wxSVGFileDCImpl::DoDrawRotatedText(const wxString& sText, wxCoord x, wxCoor const wxArrayString lines = wxSplit(sText, '\n', '\0'); for (size_t lineNum = 0; lineNum < lines.size(); lineNum++) { - const int xRect = x + wxRound(lineNum * dx); - const int yRect = y + wxRound(lineNum * dy); + const double xRect = x + lineNum * dx; + const double yRect = y + lineNum * dy; // convert x,y to SVG text x,y (the coordinates of the text baseline) wxCoord ww, hh, desc; wxString const& line = lines[lineNum]; DoGetTextExtent(line, &ww, &hh, &desc); - const int xText = xRect + (hh - desc) * sin(rad); - const int yText = yRect + (hh - desc) * cos(rad); + const double xText = xRect + (hh - desc) * sin(rad); + const double yText = yRect + (hh - desc) * cos(rad); if (m_backgroundMode == wxBRUSHSTYLE_SOLID) { @@ -687,23 +687,23 @@ void wxSVGFileDCImpl::DoDrawRotatedText(const wxString& sText, wxCoord x, wxCoor wxStrokeString(m_textBackgroundColour)); const wxString rectTransform = wxString::Format( - wxS("transform=\"rotate(%s %d %d)\""), - NumStr(-angle), xRect, yRect); + wxS("transform=\"rotate(%s %s %s)\""), + NumStr(-angle), NumStr(xRect), NumStr(yRect)); s = wxString::Format( - wxS(" \n"), - xRect, yRect, ww, hh, rectStyle, rectTransform); + wxS(" \n"), + NumStr(xRect), NumStr(yRect), ww, hh, rectStyle, rectTransform); write(s); } const wxString transform = wxString::Format( - wxS("transform=\"rotate(%s %d %d)\""), - NumStr(-angle), xText, yText); + wxS("transform=\"rotate(%s %s %s)\""), + NumStr(-angle), NumStr(xText), NumStr(yText)); s = wxString::Format( - wxS(" %s\n"), - xText, yText, ww, style, transform, + wxS(" %s\n"), + NumStr(xText), NumStr(yText), ww, style, transform, #if wxUSE_MARKUP wxMarkupParser::Quote(line) #else @@ -804,12 +804,12 @@ void wxSVGFileDCImpl::DoDrawEllipse(wxCoord x, wxCoord y, wxCoord width, wxCoord { NewGraphicsIfNeeded(); - int rh = height / 2; - int rw = width / 2; + const double rh = height / 2.0; + const double rw = width / 2.0; wxString s; - s = wxString::Format(wxS(" \n"); write(s); From a41a8ded79998cecbbcd1402b964d4adf9eb71a8 Mon Sep 17 00:00:00 2001 From: Maarten Bent Date: Sat, 10 Aug 2019 21:56:14 +0200 Subject: [PATCH 05/12] Allow to set wxSVGFileDC shape rendering mode --- include/wx/dcsvg.h | 20 +++++++++-- interface/wx/dcsvg.h | 28 +++++++++++++++ src/common/dcsvg.cpp | 81 ++++++++++++++++++++++++++++++++------------ 3 files changed, 105 insertions(+), 24 deletions(-) diff --git a/include/wx/dcsvg.h b/include/wx/dcsvg.h index 2a64f8882c..964e3166a9 100644 --- a/include/wx/dcsvg.h +++ b/include/wx/dcsvg.h @@ -11,16 +11,25 @@ #ifndef _WX_DCSVG_H_ #define _WX_DCSVG_H_ +#if wxUSE_SVG + #include "wx/string.h" #include "wx/filename.h" #include "wx/dc.h" - -#if wxUSE_SVG - #include "wx/scopedptr.h" #define wxSVGVersion wxT("v0101") +enum wxSVGShapeRenderingMode +{ + wxSVG_SHAPE_RENDERING_AUTO = 0, + wxSVG_SHAPE_RENDERING_OPTIMIZE_SPEED, + wxSVG_SHAPE_RENDERING_CRISP_EDGES, + wxSVG_SHAPE_RENDERING_GEOMETRIC_PRECISION, + + wxSVG_SHAPE_RENDERING_OPTIMISE_SPEED = wxSVG_SHAPE_RENDERING_OPTIMIZE_SPEED +}; + class WXDLLIMPEXP_FWD_BASE wxFileOutputStream; class WXDLLIMPEXP_FWD_CORE wxSVGFileDC; @@ -146,6 +155,8 @@ public: void SetBitmapHandler(wxSVGBitmapHandler* handler); + void SetShapeRenderingMode(wxSVGShapeRenderingMode renderingMode); + private: virtual bool DoGetPixel(wxCoord, wxCoord, wxColour *) const wxOVERRIDE { @@ -255,6 +266,7 @@ private: double m_dpi; wxScopedPtr m_outfile; wxScopedPtr m_bmp_handler; // class to handle bitmaps + wxSVGShapeRenderingMode m_renderingMode; // The clipping nesting level is incremented by every call to // SetClippingRegion() and reset when DestroyClippingRegion() is called. @@ -284,6 +296,8 @@ public: // Use a custom bitmap handler: takes ownership of the handler. void SetBitmapHandler(wxSVGBitmapHandler* handler); + + void SetShapeRenderingMode(wxSVGShapeRenderingMode renderingMode); }; #endif // wxUSE_SVG diff --git a/interface/wx/dcsvg.h b/interface/wx/dcsvg.h index f4d55e22a1..bc6355139d 100644 --- a/interface/wx/dcsvg.h +++ b/interface/wx/dcsvg.h @@ -5,6 +5,23 @@ // Licence: wxWindows licence ///////////////////////////////////////////////////////////////////////////// +/** + SVG shape rendering mode. + + These options represent the values defined in the SVG specification: + https://svgwg.org/svg2-draft/painting.html#ShapeRenderingProperty +*/ +enum wxSVGShapeRenderingMode +{ + wxSVG_SHAPE_RENDERING_AUTO = 0, + wxSVG_SHAPE_RENDERING_OPTIMIZE_SPEED, + wxSVG_SHAPE_RENDERING_CRISP_EDGES, + wxSVG_SHAPE_RENDERING_GEOMETRIC_PRECISION, + + wxSVG_SHAPE_RENDERING_OPTIMISE_SPEED = wxSVG_SHAPE_RENDERING_OPTIMIZE_SPEED +}; + + /** @class wxSVGFileDC @@ -74,6 +91,17 @@ public: */ void SetBitmapHandler(wxSVGBitmapHandler* handler); + /** + Set the shape rendering mode of the generated SVG. + All subsequent drawing calls will have this rendering mode set in the + SVG file. + + The default mode is wxSVG_SHAPE_RENDERING_AUTO. + + @since 3.1.3 + */ + void SetShapeRenderingMode(wxSVGShapeRenderingMode renderingMode); + /** Sets the clipping region for this device context to the intersection of the given region described by the parameters of this method and the previously diff --git a/src/common/dcsvg.cpp b/src/common/dcsvg.cpp index f5029d7f34..9d6b16b265 100644 --- a/src/common/dcsvg.cpp +++ b/src/common/dcsvg.cpp @@ -281,7 +281,30 @@ wxString wxGetBrushFill(wxBrush const& brush) return s; } -wxString wxCreateBrushFill(wxBrush& brush) +wxString wxRenderMode(wxSVGShapeRenderingMode const& style) +{ + wxString mode; + switch (style) { + case wxSVG_SHAPE_RENDERING_OPTIMIZE_SPEED: + mode = wxS("optimizeSpeed"); + break; + case wxSVG_SHAPE_RENDERING_CRISP_EDGES: + mode = wxS("crispEdges"); + break; + case wxSVG_SHAPE_RENDERING_GEOMETRIC_PRECISION: + mode = wxS("geometricPrecision"); + break; + case wxSVG_SHAPE_RENDERING_AUTO: + default: + mode = wxS("auto"); + break; + } + + wxString s = wxString::Format(wxS("shape-rendering=\"%s\""), mode); + return s; +} + +wxString wxCreateBrushFill(wxBrush& brush, wxSVGShapeRenderingMode mode) { wxString s; wxString patternName = wxGetBrushStyleName(brush); @@ -317,8 +340,8 @@ wxString wxCreateBrushFill(wxBrush& brush) s += wxString::Format(wxS(" \n"), patternName, brushColourStr.substr(1)); - s += wxString::Format(wxS(" \n"), - brushColourStr, pattern); + s += wxString::Format(wxS(" \n"), + brushColourStr, pattern, wxRenderMode(mode)); s += wxS(" \n"); } @@ -444,6 +467,11 @@ void wxSVGFileDC::SetBitmapHandler(wxSVGBitmapHandler* handler) ((wxSVGFileDCImpl*)GetImpl())->SetBitmapHandler(handler); } +void wxSVGFileDC::SetShapeRenderingMode(wxSVGShapeRenderingMode renderingMode) +{ + ((wxSVGFileDCImpl*)GetImpl())->SetShapeRenderingMode(renderingMode); +} + // ---------------------------------------------------------- // wxSVGFileDCImpl // ---------------------------------------------------------- @@ -484,6 +512,8 @@ void wxSVGFileDCImpl::Init(const wxString &filename, int Width, int Height, m_filename = filename; m_graphics_changed = true; + m_renderingMode = wxSVG_SHAPE_RENDERING_AUTO; + ////////////////////code here m_bmp_handler.reset(); @@ -542,8 +572,8 @@ void wxSVGFileDCImpl::DoDrawLine(wxCoord x1, wxCoord y1, wxCoord x2, wxCoord y2) NewGraphicsIfNeeded(); wxString s; - s = wxString::Format(wxS(" \n"), - x1, y1, x2, y2, wxGetPenPattern(m_pen)); + s = wxString::Format(wxS(" \n"), + x1, y1, x2, y2, wxRenderMode(m_renderingMode), wxGetPenPattern(m_pen)); write(s); @@ -569,8 +599,8 @@ void wxSVGFileDCImpl::DoDrawLines(int n, const wxPoint points[], wxCoord xoffset CalcBoundingBox(points[i].x + xoffset, points[i].y + yoffset); } - s += wxString::Format(wxS("\" style=\"fill:none\" %s/>\n"), - wxGetPenPattern(m_pen)); + s += wxString::Format(wxS("\" style=\"fill:none\" %s %s/>\n"), + wxRenderMode(m_renderingMode), wxGetPenPattern(m_pen)); write(s); } @@ -691,8 +721,9 @@ void wxSVGFileDCImpl::DoDrawRotatedText(const wxString& sText, wxCoord x, wxCoor NumStr(-angle), NumStr(xRect), NumStr(yRect)); s = wxString::Format( - wxS(" \n"), - NumStr(xRect), NumStr(yRect), ww, hh, rectStyle, rectTransform); + wxS(" \n"), + NumStr(xRect), NumStr(yRect), ww, hh, + wxRenderMode(m_renderingMode), rectStyle, rectTransform); write(s); } @@ -725,9 +756,9 @@ void wxSVGFileDCImpl::DoDrawRoundedRectangle(wxCoord x, wxCoord y, wxCoord width NewGraphicsIfNeeded(); wxString s; - s = wxString::Format(wxS(" \n"), + s = wxString::Format(wxS(" \n"), x, y, width, height, NumStr(radius), - wxGetPenPattern(m_pen), wxGetBrushFill(m_brush)); + wxRenderMode(m_renderingMode), wxGetPenPattern(m_pen), wxGetBrushFill(m_brush)); write(s); @@ -751,8 +782,8 @@ void wxSVGFileDCImpl::DoDrawPolygon(int n, const wxPoint points[], CalcBoundingBox(points[i].x + xoffset, points[i].y + yoffset); } - s += wxString::Format(wxS("\" %s %s style=\"fill-rule:%s;\"/>\n"), - wxGetPenPattern(m_pen), wxGetBrushFill(m_brush), + s += wxString::Format(wxS("\" %s %s %s style=\"fill-rule:%s;\"/>\n"), + wxRenderMode(m_renderingMode), wxGetPenPattern(m_pen), wxGetBrushFill(m_brush), (fillStyle == wxODDEVEN_RULE) ? wxS("evenodd") : wxS("nonzero")); write(s); @@ -808,8 +839,9 @@ void wxSVGFileDCImpl::DoDrawEllipse(wxCoord x, wxCoord y, wxCoord width, wxCoord const double rw = width / 2.0; wxString s; - s = wxString::Format(wxS(" \n"); write(s); @@ -877,7 +909,8 @@ void wxSVGFileDCImpl::DoDrawArc(wxCoord x1, wxCoord y1, wxCoord x2, wxCoord y2, x1, y1, NumStr(r1), NumStr(r2), fArc, fSweep, x2, y2, line); } - s += wxString::Format(wxS("\" %s/>\n"), wxGetPenPattern(m_pen)); + s += wxString::Format(wxS("\" %s %s/>\n"), + wxRenderMode(m_renderingMode), wxGetPenPattern(m_pen)); write(s); } @@ -962,16 +995,17 @@ void wxSVGFileDCImpl::DoDrawEllipticArc(wxCoord x, wxCoord y, wxCoord w, wxCoord NewGraphicsIfNeeded(); wxString arcFill = arcPath; - arcFill += wxString::Format(wxS(" L%s %s z\" %s/>\n"), - NumStr(xc), NumStr(yc), wxGetPenPattern(m_pen)); + arcFill += wxString::Format(wxS(" L%s %s z\" %s %s/>\n"), + NumStr(xc), NumStr(yc), + wxRenderMode(m_renderingMode), wxGetPenPattern(m_pen)); write(arcFill); } wxDCBrushChanger setTransp(*GetOwner(), *wxTRANSPARENT_BRUSH); NewGraphicsIfNeeded(); - wxString arcLine = wxString::Format(wxS("%s\" %s/>\n"), - arcPath, wxGetPenPattern(m_pen)); + wxString arcLine = wxString::Format(wxS("%s\" %s %s/>\n"), + arcPath, wxRenderMode(m_renderingMode), wxGetPenPattern(m_pen)); write(arcLine); } @@ -1078,13 +1112,18 @@ void wxSVGFileDCImpl::SetBitmapHandler(wxSVGBitmapHandler* handler) m_bmp_handler.reset(handler); } +void wxSVGFileDCImpl::SetShapeRenderingMode(wxSVGShapeRenderingMode renderingMode) +{ + m_renderingMode = renderingMode; +} + void wxSVGFileDCImpl::SetBrush(const wxBrush& brush) { m_brush = brush; m_graphics_changed = true; - wxString pattern = wxCreateBrushFill(m_brush); + wxString pattern = wxCreateBrushFill(m_brush, m_renderingMode); if ( !pattern.IsEmpty() ) { NewGraphicsIfNeeded(); From 26b273bef910977bf0e770da58261e21e11f56ff Mon Sep 17 00:00:00 2001 From: Maarten Bent Date: Sat, 10 Aug 2019 22:22:32 +0200 Subject: [PATCH 06/12] Fix RTTI class declarations of wxSVGFileDC wxIMPLEMENT_DYNAMIC_CLASS requires a default constructor (no filename). Check if m_outfile is initialized with a valid filename before using it. --- include/wx/dcsvg.h | 9 +++++++++ src/common/dcsvg.cpp | 18 +++++++++++++++--- 2 files changed, 24 insertions(+), 3 deletions(-) diff --git a/include/wx/dcsvg.h b/include/wx/dcsvg.h index 964e3166a9..4773c6152c 100644 --- a/include/wx/dcsvg.h +++ b/include/wx/dcsvg.h @@ -277,6 +277,7 @@ private: size_t m_clipUniqueId; wxDECLARE_ABSTRACT_CLASS(wxSVGFileDCImpl); + wxDECLARE_NO_COPY_CLASS(wxSVGFileDCImpl); }; @@ -298,6 +299,14 @@ public: void SetBitmapHandler(wxSVGBitmapHandler* handler); void SetShapeRenderingMode(wxSVGShapeRenderingMode renderingMode); + +private: + wxSVGFileDC() + : wxDC(new wxSVGFileDCImpl(this, wxString())) + { + } + + wxDECLARE_DYNAMIC_CLASS(wxSVGFileDC); }; #endif // wxUSE_SVG diff --git a/src/common/dcsvg.cpp b/src/common/dcsvg.cpp index 9d6b16b265..a02bbd6f5b 100644 --- a/src/common/dcsvg.cpp +++ b/src/common/dcsvg.cpp @@ -462,6 +462,8 @@ wxSVGBitmapFileHandler::ProcessBitmap(const wxBitmap& bmp, // wxSVGFileDC (specialisations) // ---------------------------------------------------------- +wxIMPLEMENT_DYNAMIC_CLASS(wxSVGFileDC, wxDC); + void wxSVGFileDC::SetBitmapHandler(wxSVGBitmapHandler* handler) { ((wxSVGFileDCImpl*)GetImpl())->SetBitmapHandler(handler); @@ -476,7 +478,7 @@ void wxSVGFileDC::SetShapeRenderingMode(wxSVGShapeRenderingMode renderingMode) // wxSVGFileDCImpl // ---------------------------------------------------------- -wxIMPLEMENT_ABSTRACT_CLASS(wxSVGFileDCImpl, wxDC); +wxIMPLEMENT_ABSTRACT_CLASS(wxSVGFileDCImpl, wxDCImpl); wxSVGFileDCImpl::wxSVGFileDCImpl(wxSVGFileDC *owner, const wxString &filename, int width, int height, double dpi, const wxString &title) @@ -517,7 +519,11 @@ void wxSVGFileDCImpl::Init(const wxString &filename, int Width, int Height, ////////////////////code here m_bmp_handler.reset(); - m_outfile.reset(new wxFileOutputStream(m_filename)); + + if ( m_filename.IsEmpty() ) + m_outfile.reset(); + else + m_outfile.reset(new wxFileOutputStream(m_filename)); wxString s; s += wxS("\n"); @@ -1215,14 +1221,20 @@ void wxSVGFileDCImpl::DoDrawBitmap(const class wxBitmap & bmp, wxCoord x, wxCoor if ( !m_bmp_handler ) m_bmp_handler.reset(new wxSVGBitmapFileHandler(m_filename)); + m_OK = m_outfile && m_outfile->IsOk(); + if (!m_OK) + return; + m_bmp_handler->ProcessBitmap(bmp, x, y, *m_outfile); + m_OK = m_outfile->IsOk(); } void wxSVGFileDCImpl::write(const wxString &s) { - m_OK = m_outfile->IsOk(); + m_OK = m_outfile && m_outfile->IsOk(); if (!m_OK) return; + const wxCharBuffer buf = s.utf8_str(); m_outfile->Write(buf, strlen((const char *)buf)); m_OK = m_outfile->IsOk(); From dfe76430cc5634ff611a08671e83fe9d8089cfdf Mon Sep 17 00:00:00 2001 From: Maarten Bent Date: Sun, 11 Aug 2019 18:25:09 +0200 Subject: [PATCH 07/12] Implement GradientFillLinear and GradientFillConcentric for wxSVGFileDC --- include/wx/dcsvg.h | 13 +++++++ src/common/dcsvg.cpp | 82 ++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 95 insertions(+) diff --git a/include/wx/dcsvg.h b/include/wx/dcsvg.h index 4773c6152c..d0176c2295 100644 --- a/include/wx/dcsvg.h +++ b/include/wx/dcsvg.h @@ -220,6 +220,16 @@ private: return false; } + virtual void DoGradientFillLinear(const wxRect& rect, + const wxColour& initialColour, + const wxColour& destColour, + wxDirection nDirection = wxEAST) wxOVERRIDE; + + virtual void DoGradientFillConcentric(const wxRect& rect, + const wxColour& initialColour, + const wxColour& destColour, + const wxPoint& circleCenter) wxOVERRIDE; + virtual void DoGetSize(int * x, int *y) const wxOVERRIDE { if ( x ) @@ -276,6 +286,9 @@ private: // incremented in each SetClippingRegion() call. size_t m_clipUniqueId; + // Unique ID for every gradient. + size_t m_gradientUniqueId; + wxDECLARE_ABSTRACT_CLASS(wxSVGFileDCImpl); wxDECLARE_NO_COPY_CLASS(wxSVGFileDCImpl); }; diff --git a/src/common/dcsvg.cpp b/src/common/dcsvg.cpp index a02bbd6f5b..422b36b6c4 100644 --- a/src/common/dcsvg.cpp +++ b/src/common/dcsvg.cpp @@ -500,6 +500,8 @@ void wxSVGFileDCImpl::Init(const wxString &filename, int Width, int Height, m_clipUniqueId = 0; m_clipNestingLevel = 0; + m_gradientUniqueId = 0; + m_mm_to_pix_x = dpi / 25.4; m_mm_to_pix_y = dpi / 25.4; @@ -1015,6 +1017,86 @@ void wxSVGFileDCImpl::DoDrawEllipticArc(wxCoord x, wxCoord y, wxCoord w, wxCoord write(arcLine); } +void wxSVGFileDCImpl::DoGradientFillLinear(const wxRect& rect, + const wxColour& initialColour, + const wxColour& destColour, + wxDirection nDirection) +{ + NewGraphicsIfNeeded(); + + float initOpacity; + float destOpacity; + wxString initCol = Col2SVG(initialColour, &initOpacity); + wxString destCol = Col2SVG(destColour, &destOpacity); + + const int x1 = ((nDirection & wxLEFT) > 0) ? 100 : 0; + const int y1 = ((nDirection & wxUP) > 0) ? 100 : 0; + const int x2 = ((nDirection & wxRIGHT) > 0) ? 100 : 0; + const int y2 = ((nDirection & wxDOWN) > 0) ? 100 : 0; + + wxString s; + s += wxS(" \n"); + s += wxString::Format(wxS(" \n"), + m_gradientUniqueId, x1, y1, x2, y2); + s += wxString::Format(wxS(" \n"), + initCol, NumStr(initOpacity)); + s += wxString::Format(wxS(" \n"), + destCol, NumStr(destOpacity)); + s += wxS(" \n"); + s += wxS(" \n"); + + s += wxString::Format(wxS(" \n"), + rect.x, rect.y, rect.width, rect.height, m_gradientUniqueId, + wxRenderMode(m_renderingMode), wxGetPenPattern(m_pen), wxGetBrushFill(m_brush)); + + m_gradientUniqueId++; + + write(s); + + CalcBoundingBox(rect.x, rect.y); + CalcBoundingBox(rect.x + rect.width, rect.y + rect.height); +} + +void wxSVGFileDCImpl::DoGradientFillConcentric(const wxRect& rect, + const wxColour& initialColour, + const wxColour& destColour, + const wxPoint& circleCenter) +{ + NewGraphicsIfNeeded(); + + float initOpacity; + float destOpacity; + wxString initCol = Col2SVG(initialColour, &initOpacity); + wxString destCol = Col2SVG(destColour, &destOpacity); + + const double cx = circleCenter.x * 100.0 / rect.GetWidth(); + const double cy = circleCenter.y * 100.0 / rect.GetHeight(); + const double fx = cx; + const double fd = cy; + + wxString s; + s += wxS(" \n"); + s += wxString::Format(wxS(" \n"), + m_gradientUniqueId, NumStr(cx), NumStr(cy), NumStr(fx), NumStr(fd)); + s += wxString::Format(wxS(" \n"), + initCol, NumStr(initOpacity)); + s += wxString::Format(wxS(" \n"), + destCol, NumStr(destOpacity)); + s += wxS(" \n"); + s += wxS(" \n"); + + s += wxString::Format(wxS(" \n"), + rect.x, rect.y, rect.width, rect.height, m_gradientUniqueId, + wxRenderMode(m_renderingMode), wxGetPenPattern(m_pen), wxGetBrushFill(m_brush)); + + m_gradientUniqueId++; + + write(s); + + CalcBoundingBox(rect.x, rect.y); + CalcBoundingBox(rect.x + rect.width, rect.y + rect.height); +} + void wxSVGFileDCImpl::DoSetClippingRegion(int x, int y, int width, int height) { wxString svg; From 64be484db2507f41fe92c34b8566ca8beb5dc339 Mon Sep 17 00:00:00 2001 From: Maarten Bent Date: Tue, 20 Aug 2019 19:52:50 +0200 Subject: [PATCH 08/12] Use pen width 1 for DrawPoint in wxSVGFileDC This is consistent with other DCs. --- src/common/dcsvg.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/common/dcsvg.cpp b/src/common/dcsvg.cpp index 422b36b6c4..8679b1d38e 100644 --- a/src/common/dcsvg.cpp +++ b/src/common/dcsvg.cpp @@ -620,7 +620,7 @@ void wxSVGFileDCImpl::DoDrawPoint(wxCoord x1, wxCoord y1) wxString s; - s = wxS(" \n "); + s = wxS(" \n "); write(s); DoDrawLine(x1, y1, x1, y1); From 75486529e3a70b092cdf20517c232cb06d9c4d41 Mon Sep 17 00:00:00 2001 From: Maarten Bent Date: Wed, 21 Aug 2019 21:15:38 +0200 Subject: [PATCH 09/12] Process review comments in wxSVGFileDC --- include/wx/dcsvg.h | 40 ++++++++++++------------ src/common/dcsvg.cpp | 72 ++++++++++++++++++++++++-------------------- 2 files changed, 59 insertions(+), 53 deletions(-) diff --git a/include/wx/dcsvg.h b/include/wx/dcsvg.h index d0176c2295..2eec273762 100644 --- a/include/wx/dcsvg.h +++ b/include/wx/dcsvg.h @@ -85,9 +85,9 @@ public: class WXDLLIMPEXP_CORE wxSVGFileDCImpl : public wxDCImpl { public: - wxSVGFileDCImpl(wxSVGFileDC *owner, const wxString &filename, + wxSVGFileDCImpl(wxSVGFileDC* owner, const wxString& filename, int width = 320, int height = 240, double dpi = 72.0, - const wxString &title = wxString()); + const wxString& title = wxString()); virtual ~wxSVGFileDCImpl(); @@ -110,7 +110,7 @@ public: virtual wxCoord GetCharWidth() const wxOVERRIDE; #if wxUSE_PALETTE - virtual void SetPalette(const wxPalette& WXUNUSED(palette)) wxOVERRIDE + virtual void SetPalette(const wxPalette& WXUNUSED(palette)) wxOVERRIDE { wxFAIL_MSG(wxT("wxSVGFILEDC::SetPalette not implemented")); } @@ -145,7 +145,7 @@ public: m_graphics_changed = true; } - virtual void SetBackground(const wxBrush &brush) wxOVERRIDE; + virtual void SetBackground(const wxBrush& brush) wxOVERRIDE; virtual void SetBackgroundMode(int mode) wxOVERRIDE; virtual void SetBrush(const wxBrush& brush) wxOVERRIDE; virtual void SetFont(const wxFont& font) wxOVERRIDE; @@ -158,13 +158,13 @@ public: void SetShapeRenderingMode(wxSVGShapeRenderingMode renderingMode); private: - virtual bool DoGetPixel(wxCoord, wxCoord, wxColour *) const wxOVERRIDE + virtual bool DoGetPixel(wxCoord, wxCoord, wxColour*) const wxOVERRIDE { wxFAIL_MSG(wxT("wxSVGFILEDC::DoGetPixel Call not implemented")); return true; } - virtual bool DoBlit(wxCoord, wxCoord, wxCoord, wxCoord, wxDC *, + virtual bool DoBlit(wxCoord, wxCoord, wxCoord, wxCoord, wxDC*, wxCoord, wxCoord, wxRasterOperationMode = wxCOPY, bool = 0, int = -1, int = -1) wxOVERRIDE; @@ -175,7 +175,7 @@ private: virtual void DoDrawArc(wxCoord, wxCoord, wxCoord, wxCoord, wxCoord, wxCoord) wxOVERRIDE; - virtual void DoDrawBitmap(const wxBitmap &, wxCoord, wxCoord, bool = false) wxOVERRIDE; + virtual void DoDrawBitmap(const wxBitmap&, wxCoord, wxCoord, bool = false) wxOVERRIDE; virtual void DoDrawCheckMark(wxCoord x, wxCoord y, wxCoord w, wxCoord h) wxOVERRIDE; @@ -184,7 +184,7 @@ private: virtual void DoDrawEllipticArc(wxCoord x, wxCoord y, wxCoord w, wxCoord h, double sa, double ea) wxOVERRIDE; - virtual void DoDrawIcon(const wxIcon &, wxCoord, wxCoord) wxOVERRIDE; + virtual void DoDrawIcon(const wxIcon&, wxCoord, wxCoord) wxOVERRIDE; virtual void DoDrawLine(wxCoord x1, wxCoord y1, wxCoord x2, wxCoord y2) wxOVERRIDE; @@ -226,11 +226,11 @@ private: wxDirection nDirection = wxEAST) wxOVERRIDE; virtual void DoGradientFillConcentric(const wxRect& rect, - const wxColour& initialColour, - const wxColour& destColour, - const wxPoint& circleCenter) wxOVERRIDE; + const wxColour& initialColour, + const wxColour& destColour, + const wxPoint& circleCenter) wxOVERRIDE; - virtual void DoGetSize(int * x, int *y) const wxOVERRIDE + virtual void DoGetSize(int* x, int*y) const wxOVERRIDE { if ( x ) *x = m_width; @@ -238,10 +238,10 @@ private: *y = m_height; } - virtual void DoGetTextExtent(const wxString& string, wxCoord *w, wxCoord *h, - wxCoord *descent = NULL, - wxCoord *externalLeading = NULL, - const wxFont *font = NULL) const wxOVERRIDE; + virtual void DoGetTextExtent(const wxString& string, wxCoord* w, wxCoord* h, + wxCoord* descent = NULL, + wxCoord* externalLeading = NULL, + const wxFont* font = NULL) const wxOVERRIDE; virtual void DoSetDeviceClippingRegion(const wxRegion& region) wxOVERRIDE { @@ -251,14 +251,14 @@ private: virtual void DoSetClippingRegion(int x, int y, int width, int height) wxOVERRIDE; - virtual void DoGetSizeMM(int *width, int *height) const wxOVERRIDE; + virtual void DoGetSizeMM(int* width, int* height) const wxOVERRIDE; virtual wxSize GetPPI() const wxOVERRIDE; - void Init(const wxString &filename, int width, int height, - double dpi, const wxString &title); + void Init(const wxString& filename, int width, int height, + double dpi, const wxString& title); - void write(const wxString &s); + void write(const wxString& s); private: // If m_graphics_changed is true, close the current element and start a diff --git a/src/common/dcsvg.cpp b/src/common/dcsvg.cpp index 8679b1d38e..6a96c9bd87 100644 --- a/src/common/dcsvg.cpp +++ b/src/common/dcsvg.cpp @@ -46,9 +46,10 @@ namespace // 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 const& f) +inline wxString NumStr(const double f) { if ( f == 0 ) + // prevent -0.00 return wxS("0.00"); else return wxString::FromCDouble(f, 2); @@ -56,7 +57,7 @@ inline wxString NumStr(double const& f) // Return the colour representation as HTML-like "#rrggbb" string and also // returns its alpha as opacity number in 0..1 range. -wxString Col2SVG(wxColour c, float *opacity = NULL) +wxString Col2SVG(wxColour c, float* opacity = NULL) { if ( c.Alpha() != wxALPHA_OPAQUE ) { @@ -70,13 +71,13 @@ wxString Col2SVG(wxColour c, float *opacity = NULL) else // No alpha. { if ( opacity ) - *opacity = 1.; + *opacity = 1.0f; } return c.GetAsString(wxC2S_HTML_SYNTAX); } -wxString wxStrokeString(wxColour const& c, int style = wxPENSTYLE_SOLID) +wxString wxStrokeString(const wxColour& c, int style = wxPENSTYLE_SOLID) { float opacity; wxString s = wxS("stroke:") + Col2SVG(c, &opacity) + wxS(";"); @@ -102,7 +103,7 @@ wxString wxStrokeString(wxColour const& c, int style = wxPENSTYLE_SOLID) return s; } -wxString wxFillString(wxColour c, int style = wxBRUSHSTYLE_SOLID) +wxString wxFillString(const wxColour& c, int style = wxBRUSHSTYLE_SOLID) { float opacity; wxString s = wxS("fill:") + Col2SVG(c, &opacity) + wxS(";"); @@ -129,7 +130,7 @@ wxString wxFillString(wxColour c, int style = wxBRUSHSTYLE_SOLID) return s; } -wxString wxGetPenPattern(wxPen const& pen) +wxString wxGetPenPattern(const wxPen& pen) { wxString s; @@ -160,7 +161,7 @@ wxString wxGetPenPattern(wxPen const& pen) case wxPENSTYLE_USER_DASH: { s = wxS("stroke-dasharray=\""); - wxDash *dashes; + wxDash* dashes; int count = pen.GetDashes(&dashes); if ((dashes != NULL) && (count > 0)) { @@ -194,7 +195,7 @@ wxString wxGetPenPattern(wxPen const& pen) return s; } -wxString wxGetPenStyle(wxPen const& pen) +wxString wxGetPenStyle(const wxPen& pen) { wxString penStyle; @@ -231,7 +232,7 @@ wxString wxGetPenStyle(wxPen const& pen) return penStyle; } -wxString wxGetBrushStyleName(wxBrush const& brush) +wxString wxGetBrushStyleName(const wxBrush& brush) { wxString brushStyle; @@ -270,21 +271,22 @@ wxString wxGetBrushStyleName(wxBrush const& brush) return brushStyle; } -wxString wxGetBrushFill(wxBrush const& brush) +wxString wxGetBrushFill(const wxBrush& brush) { wxString s; wxString brushStyle = wxGetBrushStyleName(brush); - if (!brushStyle.IsEmpty()) + if (!brushStyle.empty()) s = wxS("fill=\"url(#") + brushStyle + Col2SVG(brush.GetColour()).substr(1) + wxS(")\""); return s; } -wxString wxRenderMode(wxSVGShapeRenderingMode const& style) +wxString wxRenderMode(const wxSVGShapeRenderingMode style) { wxString mode; - switch (style) { + switch (style) + { case wxSVG_SHAPE_RENDERING_OPTIMIZE_SPEED: mode = wxS("optimizeSpeed"); break; @@ -295,7 +297,6 @@ wxString wxRenderMode(wxSVGShapeRenderingMode const& style) mode = wxS("geometricPrecision"); break; case wxSVG_SHAPE_RENDERING_AUTO: - default: mode = wxS("auto"); break; } @@ -304,12 +305,12 @@ wxString wxRenderMode(wxSVGShapeRenderingMode const& style) return s; } -wxString wxCreateBrushFill(wxBrush& brush, wxSVGShapeRenderingMode mode) +wxString wxCreateBrushFill(const wxBrush& brush, wxSVGShapeRenderingMode mode) { wxString s; wxString patternName = wxGetBrushStyleName(brush); - if (!patternName.IsEmpty()) + if (!patternName.empty()) { wxString pattern; switch (brush.GetStyle()) @@ -412,7 +413,7 @@ wxSVGBitmapEmbedHandler::ProcessBitmap(const wxBitmap& bmp, // write to the SVG file const wxCharBuffer buf = s.utf8_str(); - stream.Write(buf, strlen((const char *)buf)); + stream.Write(buf, strlen((const char*)buf)); return stream.IsOk(); } @@ -437,7 +438,7 @@ wxSVGBitmapFileHandler::ProcessBitmap(const wxBitmap& bmp, { sPNG.SetFullName(wxString::Format("%s%simage%d.png", sPNG.GetName(), - sPNG.GetName().IsEmpty() ? "" : "_", + sPNG.GetName().empty() ? "" : "_", sub_images++)); } while ( sPNG.FileExists() ); @@ -480,15 +481,15 @@ void wxSVGFileDC::SetShapeRenderingMode(wxSVGShapeRenderingMode renderingMode) wxIMPLEMENT_ABSTRACT_CLASS(wxSVGFileDCImpl, wxDCImpl); -wxSVGFileDCImpl::wxSVGFileDCImpl(wxSVGFileDC *owner, const wxString &filename, - int width, int height, double dpi, const wxString &title) +wxSVGFileDCImpl::wxSVGFileDCImpl(wxSVGFileDC* owner, const wxString& filename, + int width, int height, double dpi, const wxString& title) : wxDCImpl(owner) { Init(filename, width, height, dpi, title); } -void wxSVGFileDCImpl::Init(const wxString &filename, int Width, int Height, - double dpi, const wxString &title) +void wxSVGFileDCImpl::Init(const wxString& filename, int Width, int Height, + double dpi, const wxString& title) { m_width = Width; m_height = Height; @@ -522,7 +523,7 @@ void wxSVGFileDCImpl::Init(const wxString &filename, int Width, int Height, m_bmp_handler.reset(); - if ( m_filename.IsEmpty() ) + if ( m_filename.empty() ) m_outfile.reset(); else m_outfile.reset(new wxFileOutputStream(m_filename)); @@ -550,7 +551,7 @@ wxSVGFileDCImpl::~wxSVGFileDCImpl() write(s); } -void wxSVGFileDCImpl::DoGetSizeMM(int *width, int *height) const +void wxSVGFileDCImpl::DoGetSizeMM(int* width, int* height) const { if (width) *width = wxRound( (double)m_width / GetMMToPXx() ); @@ -683,7 +684,7 @@ void wxSVGFileDCImpl::DoDrawRotatedText(const wxString& sText, wxCoord x, wxCoor textDecoration += wxS(" underline"); if (m_font.GetStrikethrough()) textDecoration += wxS(" line-through"); - if (textDecoration.IsEmpty()) + if (textDecoration.empty()) textDecoration = wxS(" none"); wxString style = wxS("style=\""); @@ -792,7 +793,7 @@ void wxSVGFileDCImpl::DoDrawPolygon(int n, const wxPoint points[], s += wxString::Format(wxS("\" %s %s %s style=\"fill-rule:%s;\"/>\n"), wxRenderMode(m_renderingMode), wxGetPenPattern(m_pen), wxGetBrushFill(m_brush), - (fillStyle == wxODDEVEN_RULE) ? wxS("evenodd") : wxS("nonzero")); + fillStyle == wxODDEVEN_RULE ? wxS("evenodd") : wxS("nonzero")); write(s); } @@ -1155,7 +1156,12 @@ void wxSVGFileDCImpl::DestroyClippingRegion() wxDCImpl::DestroyClippingRegion(); } -void wxSVGFileDCImpl::DoGetTextExtent(const wxString& string, wxCoord *w, wxCoord *h, wxCoord *descent, wxCoord *externalLeading, const wxFont *font) const +void wxSVGFileDCImpl::DoGetTextExtent(const wxString& string, + wxCoord* w, + wxCoord* h, + wxCoord* descent, + wxCoord* externalLeading, + const wxFont* font) const { wxScreenDC sDC; wxSetScaledScreenDCFont(sDC, font ? *font : m_font); @@ -1185,7 +1191,7 @@ wxCoord wxSVGFileDCImpl::GetCharWidth() const // wxSVGFileDCImpl - set functions // ---------------------------------------------------------- -void wxSVGFileDCImpl::SetBackground(const wxBrush &brush) +void wxSVGFileDCImpl::SetBackground(const wxBrush& brush) { m_backgroundBrush = brush; } @@ -1212,7 +1218,7 @@ void wxSVGFileDCImpl::SetBrush(const wxBrush& brush) m_graphics_changed = true; wxString pattern = wxCreateBrushFill(m_brush, m_renderingMode); - if ( !pattern.IsEmpty() ) + if ( !pattern.empty() ) { NewGraphicsIfNeeded(); @@ -1285,7 +1291,7 @@ bool wxSVGFileDCImpl::DoBlit(wxCoord xdest, wxCoord ydest, wxCoord width, wxCoor return false; } -void wxSVGFileDCImpl::DoDrawIcon(const class wxIcon & myIcon, wxCoord x, wxCoord y) +void wxSVGFileDCImpl::DoDrawIcon(const wxIcon& myIcon, wxCoord x, wxCoord y) { wxBitmap myBitmap(myIcon.GetWidth(), myIcon.GetHeight()); wxMemoryDC memDC; @@ -1295,7 +1301,7 @@ void wxSVGFileDCImpl::DoDrawIcon(const class wxIcon & myIcon, wxCoord x, wxCoord DoDrawBitmap(myBitmap, x, y); } -void wxSVGFileDCImpl::DoDrawBitmap(const class wxBitmap & bmp, wxCoord x, wxCoord y, bool WXUNUSED(bTransparent) /*=0*/) +void wxSVGFileDCImpl::DoDrawBitmap(const wxBitmap& bmp, wxCoord x, wxCoord y, bool WXUNUSED(bTransparent)) { NewGraphicsIfNeeded(); @@ -1311,14 +1317,14 @@ void wxSVGFileDCImpl::DoDrawBitmap(const class wxBitmap & bmp, wxCoord x, wxCoor m_OK = m_outfile->IsOk(); } -void wxSVGFileDCImpl::write(const wxString &s) +void wxSVGFileDCImpl::write(const wxString& s) { m_OK = m_outfile && m_outfile->IsOk(); if (!m_OK) return; const wxCharBuffer buf = s.utf8_str(); - m_outfile->Write(buf, strlen((const char *)buf)); + m_outfile->Write(buf, strlen((const char*)buf)); m_OK = m_outfile->IsOk(); } From 0b728d1beaa5e5adb15ab0b9231c5aa394814ad1 Mon Sep 17 00:00:00 2001 From: Maarten Bent Date: Wed, 21 Aug 2019 21:19:59 +0200 Subject: [PATCH 10/12] Use base version of DrawCheckMark directly in wxSVGFileDC --- include/wx/dcsvg.h | 2 -- src/common/dcsvg.cpp | 5 ----- 2 files changed, 7 deletions(-) diff --git a/include/wx/dcsvg.h b/include/wx/dcsvg.h index 2eec273762..82799b9999 100644 --- a/include/wx/dcsvg.h +++ b/include/wx/dcsvg.h @@ -177,8 +177,6 @@ private: virtual void DoDrawBitmap(const wxBitmap&, wxCoord, wxCoord, bool = false) wxOVERRIDE; - virtual void DoDrawCheckMark(wxCoord x, wxCoord y, wxCoord w, wxCoord h) wxOVERRIDE; - virtual void DoDrawEllipse(wxCoord x, wxCoord y, wxCoord w, wxCoord h) wxOVERRIDE; virtual void DoDrawEllipticArc(wxCoord x, wxCoord y, wxCoord w, wxCoord h, diff --git a/src/common/dcsvg.cpp b/src/common/dcsvg.cpp index 6a96c9bd87..dd34f2af20 100644 --- a/src/common/dcsvg.cpp +++ b/src/common/dcsvg.cpp @@ -630,11 +630,6 @@ void wxSVGFileDCImpl::DoDrawPoint(wxCoord x1, wxCoord y1) write(s); } -void wxSVGFileDCImpl::DoDrawCheckMark(wxCoord x1, wxCoord y1, wxCoord width, wxCoord height) -{ - wxDCImpl::DoDrawCheckMark(x1, y1, width, height); -} - void wxSVGFileDCImpl::DoDrawText(const wxString& text, wxCoord x1, wxCoord y1) { DoDrawRotatedText(text, x1, y1, 0.0); From 72ce980d1ed750aafee1e6a0db614af3c600855e Mon Sep 17 00:00:00 2001 From: Maarten Bent Date: Wed, 21 Aug 2019 21:26:19 +0200 Subject: [PATCH 11/12] Rename wxSVGFileDC anonymous functions --- src/common/dcsvg.cpp | 68 ++++++++++++++++++++++---------------------- 1 file changed, 34 insertions(+), 34 deletions(-) diff --git a/src/common/dcsvg.cpp b/src/common/dcsvg.cpp index dd34f2af20..3294823d60 100644 --- a/src/common/dcsvg.cpp +++ b/src/common/dcsvg.cpp @@ -77,7 +77,7 @@ wxString Col2SVG(wxColour c, float* opacity = NULL) return c.GetAsString(wxC2S_HTML_SYNTAX); } -wxString wxStrokeString(const wxColour& c, int style = wxPENSTYLE_SOLID) +wxString GetPenStroke(const wxColour& c, int style = wxPENSTYLE_SOLID) { float opacity; wxString s = wxS("stroke:") + Col2SVG(c, &opacity) + wxS(";"); @@ -103,7 +103,7 @@ wxString wxStrokeString(const wxColour& c, int style = wxPENSTYLE_SOLID) return s; } -wxString wxFillString(const wxColour& c, int style = wxBRUSHSTYLE_SOLID) +wxString GetBrushFill(const wxColour& c, int style = wxBRUSHSTYLE_SOLID) { float opacity; wxString s = wxS("fill:") + Col2SVG(c, &opacity) + wxS(";"); @@ -130,7 +130,7 @@ wxString wxFillString(const wxColour& c, int style = wxBRUSHSTYLE_SOLID) return s; } -wxString wxGetPenPattern(const wxPen& pen) +wxString GetPenPattern(const wxPen& pen) { wxString s; @@ -195,7 +195,7 @@ wxString wxGetPenPattern(const wxPen& pen) return s; } -wxString wxGetPenStyle(const wxPen& pen) +wxString GetPenStyle(const wxPen& pen) { wxString penStyle; @@ -232,7 +232,7 @@ wxString wxGetPenStyle(const wxPen& pen) return penStyle; } -wxString wxGetBrushStyleName(const wxBrush& brush) +wxString GetBrushStyleName(const wxBrush& brush) { wxString brushStyle; @@ -271,10 +271,10 @@ wxString wxGetBrushStyleName(const wxBrush& brush) return brushStyle; } -wxString wxGetBrushFill(const wxBrush& brush) +wxString GetBrushPattern(const wxBrush& brush) { wxString s; - wxString brushStyle = wxGetBrushStyleName(brush); + wxString brushStyle = GetBrushStyleName(brush); if (!brushStyle.empty()) s = wxS("fill=\"url(#") + brushStyle + Col2SVG(brush.GetColour()).substr(1) + wxS(")\""); @@ -282,7 +282,7 @@ wxString wxGetBrushFill(const wxBrush& brush) return s; } -wxString wxRenderMode(const wxSVGShapeRenderingMode style) +wxString GetRenderMode(const wxSVGShapeRenderingMode style) { wxString mode; switch (style) @@ -305,10 +305,10 @@ wxString wxRenderMode(const wxSVGShapeRenderingMode style) return s; } -wxString wxCreateBrushFill(const wxBrush& brush, wxSVGShapeRenderingMode mode) +wxString CreateBrushFill(const wxBrush& brush, wxSVGShapeRenderingMode mode) { wxString s; - wxString patternName = wxGetBrushStyleName(brush); + wxString patternName = GetBrushStyleName(brush); if (!patternName.empty()) { @@ -342,14 +342,14 @@ wxString wxCreateBrushFill(const wxBrush& brush, wxSVGShapeRenderingMode mode) s += wxString::Format(wxS(" \n"), patternName, brushColourStr.substr(1)); s += wxString::Format(wxS(" \n"), - brushColourStr, pattern, wxRenderMode(mode)); + brushColourStr, pattern, GetRenderMode(mode)); s += wxS(" \n"); } return s; } -void wxSetScaledScreenDCFont(wxScreenDC& sDC, const wxFont& font) +void SetScaledScreenDCFont(wxScreenDC& sDC, const wxFont& font) { const double scale = sDC.GetContentScaleFactor(); if ( scale > 1 ) @@ -582,7 +582,7 @@ void wxSVGFileDCImpl::DoDrawLine(wxCoord x1, wxCoord y1, wxCoord x2, wxCoord y2) wxString s; s = wxString::Format(wxS(" \n"), - x1, y1, x2, y2, wxRenderMode(m_renderingMode), wxGetPenPattern(m_pen)); + x1, y1, x2, y2, GetRenderMode(m_renderingMode), GetPenPattern(m_pen)); write(s); @@ -609,7 +609,7 @@ void wxSVGFileDCImpl::DoDrawLines(int n, const wxPoint points[], wxCoord xoffset } s += wxString::Format(wxS("\" style=\"fill:none\" %s %s/>\n"), - wxRenderMode(m_renderingMode), wxGetPenPattern(m_pen)); + GetRenderMode(m_renderingMode), GetPenPattern(m_pen)); write(s); } @@ -689,8 +689,8 @@ void wxSVGFileDCImpl::DoDrawRotatedText(const wxString& sText, wxCoord x, wxCoor style += wxString::Format(wxS("font-size:%spt; "), NumStr(m_font.GetFractionalPointSize())); style += wxString::Format(wxS("text-decoration:%s; "), textDecoration); style += wxString::Format(wxS("%s %s stroke-width:0; "), - wxFillString(m_textForegroundColour), - wxStrokeString(m_textForegroundColour)); + GetBrushFill(m_textForegroundColour), + GetPenStroke(m_textForegroundColour)); style += wxS("white-space: pre;"); style += wxS("\""); @@ -717,8 +717,8 @@ void wxSVGFileDCImpl::DoDrawRotatedText(const wxString& sText, wxCoord x, wxCoor // draw text background const wxString rectStyle = wxString::Format( wxS("style=\"%s %s stroke-width:1;\""), - wxFillString(m_textBackgroundColour), - wxStrokeString(m_textBackgroundColour)); + GetBrushFill(m_textBackgroundColour), + GetPenStroke(m_textBackgroundColour)); const wxString rectTransform = wxString::Format( wxS("transform=\"rotate(%s %s %s)\""), @@ -727,7 +727,7 @@ void wxSVGFileDCImpl::DoDrawRotatedText(const wxString& sText, wxCoord x, wxCoor s = wxString::Format( wxS(" \n"), NumStr(xRect), NumStr(yRect), ww, hh, - wxRenderMode(m_renderingMode), rectStyle, rectTransform); + GetRenderMode(m_renderingMode), rectStyle, rectTransform); write(s); } @@ -762,7 +762,7 @@ void wxSVGFileDCImpl::DoDrawRoundedRectangle(wxCoord x, wxCoord y, wxCoord width s = wxString::Format(wxS(" \n"), x, y, width, height, NumStr(radius), - wxRenderMode(m_renderingMode), wxGetPenPattern(m_pen), wxGetBrushFill(m_brush)); + GetRenderMode(m_renderingMode), GetPenPattern(m_pen), GetBrushPattern(m_brush)); write(s); @@ -787,7 +787,7 @@ void wxSVGFileDCImpl::DoDrawPolygon(int n, const wxPoint points[], } s += wxString::Format(wxS("\" %s %s %s style=\"fill-rule:%s;\"/>\n"), - wxRenderMode(m_renderingMode), wxGetPenPattern(m_pen), wxGetBrushFill(m_brush), + GetRenderMode(m_renderingMode), GetPenPattern(m_pen), GetBrushPattern(m_brush), fillStyle == wxODDEVEN_RULE ? wxS("evenodd") : wxS("nonzero")); write(s); @@ -845,7 +845,7 @@ void wxSVGFileDCImpl::DoDrawEllipse(wxCoord x, wxCoord y, wxCoord width, wxCoord wxString s; s = wxString::Format(wxS(" \n"); write(s); @@ -914,7 +914,7 @@ void wxSVGFileDCImpl::DoDrawArc(wxCoord x1, wxCoord y1, wxCoord x2, wxCoord y2, } s += wxString::Format(wxS("\" %s %s/>\n"), - wxRenderMode(m_renderingMode), wxGetPenPattern(m_pen)); + GetRenderMode(m_renderingMode), GetPenPattern(m_pen)); write(s); } @@ -1001,7 +1001,7 @@ void wxSVGFileDCImpl::DoDrawEllipticArc(wxCoord x, wxCoord y, wxCoord w, wxCoord wxString arcFill = arcPath; arcFill += wxString::Format(wxS(" L%s %s z\" %s %s/>\n"), NumStr(xc), NumStr(yc), - wxRenderMode(m_renderingMode), wxGetPenPattern(m_pen)); + GetRenderMode(m_renderingMode), GetPenPattern(m_pen)); write(arcFill); } @@ -1009,7 +1009,7 @@ void wxSVGFileDCImpl::DoDrawEllipticArc(wxCoord x, wxCoord y, wxCoord w, wxCoord NewGraphicsIfNeeded(); wxString arcLine = wxString::Format(wxS("%s\" %s %s/>\n"), - arcPath, wxRenderMode(m_renderingMode), wxGetPenPattern(m_pen)); + arcPath, GetRenderMode(m_renderingMode), GetPenPattern(m_pen)); write(arcLine); } @@ -1043,7 +1043,7 @@ void wxSVGFileDCImpl::DoGradientFillLinear(const wxRect& rect, s += wxString::Format(wxS(" \n"), rect.x, rect.y, rect.width, rect.height, m_gradientUniqueId, - wxRenderMode(m_renderingMode), wxGetPenPattern(m_pen), wxGetBrushFill(m_brush)); + GetRenderMode(m_renderingMode), GetPenPattern(m_pen), GetBrushPattern(m_brush)); m_gradientUniqueId++; @@ -1083,7 +1083,7 @@ void wxSVGFileDCImpl::DoGradientFillConcentric(const wxRect& rect, s += wxString::Format(wxS(" \n"), rect.x, rect.y, rect.width, rect.height, m_gradientUniqueId, - wxRenderMode(m_renderingMode), wxGetPenPattern(m_pen), wxGetBrushFill(m_brush)); + GetRenderMode(m_renderingMode), GetPenPattern(m_pen), GetBrushPattern(m_brush)); m_gradientUniqueId++; @@ -1159,7 +1159,7 @@ void wxSVGFileDCImpl::DoGetTextExtent(const wxString& string, const wxFont* font) const { wxScreenDC sDC; - wxSetScaledScreenDCFont(sDC, font ? *font : m_font); + SetScaledScreenDCFont(sDC, font ? *font : m_font); sDC.GetTextExtent(string, w, h, descent, externalLeading); } @@ -1167,7 +1167,7 @@ void wxSVGFileDCImpl::DoGetTextExtent(const wxString& string, wxCoord wxSVGFileDCImpl::GetCharHeight() const { wxScreenDC sDC; - wxSetScaledScreenDCFont(sDC, m_font); + SetScaledScreenDCFont(sDC, m_font); return sDC.GetCharHeight(); @@ -1176,7 +1176,7 @@ wxCoord wxSVGFileDCImpl::GetCharHeight() const wxCoord wxSVGFileDCImpl::GetCharWidth() const { wxScreenDC sDC; - wxSetScaledScreenDCFont(sDC, m_font); + SetScaledScreenDCFont(sDC, m_font); return sDC.GetCharWidth(); } @@ -1212,7 +1212,7 @@ void wxSVGFileDCImpl::SetBrush(const wxBrush& brush) m_graphics_changed = true; - wxString pattern = wxCreateBrushFill(m_brush, m_renderingMode); + wxString pattern = CreateBrushFill(m_brush, m_renderingMode); if ( !pattern.empty() ) { NewGraphicsIfNeeded(); @@ -1245,9 +1245,9 @@ void wxSVGFileDCImpl::DoStartNewGraphics() wxString s; s = wxString::Format(wxS("\n"), - wxGetPenStyle(m_pen), - wxFillString(m_brush.GetColour(), m_brush.GetStyle()), - wxStrokeString(m_pen.GetColour(), m_pen.GetStyle()), + GetPenStyle(m_pen), + GetBrushFill(m_brush.GetColour(), m_brush.GetStyle()), + GetPenStroke(m_pen.GetColour(), m_pen.GetStyle()), NumStr((m_deviceOriginX - m_logicalOriginX) * m_signX), NumStr((m_deviceOriginY - m_logicalOriginY) * m_signY), NumStr(m_scaleX * m_signX), From bee61680769f24d68c889e25b73fffb10b7001eb Mon Sep 17 00:00:00 2001 From: Maarten Bent Date: Wed, 21 Aug 2019 21:49:25 +0200 Subject: [PATCH 12/12] Make wxSVGFileDC function parameter names consistent with wxDC --- include/wx/dcsvg.h | 62 ++++++++++++++++++++++++++------------------ src/common/dcsvg.cpp | 53 +++++++++++++++++++------------------ 2 files changed, 65 insertions(+), 50 deletions(-) diff --git a/include/wx/dcsvg.h b/include/wx/dcsvg.h index 82799b9999..939b0dd36e 100644 --- a/include/wx/dcsvg.h +++ b/include/wx/dcsvg.h @@ -158,61 +158,71 @@ public: void SetShapeRenderingMode(wxSVGShapeRenderingMode renderingMode); private: - virtual bool DoGetPixel(wxCoord, wxCoord, wxColour*) const wxOVERRIDE + virtual bool DoGetPixel(wxCoord WXUNUSED(x), wxCoord WXUNUSED(y), + wxColour* WXUNUSED(col)) const wxOVERRIDE { wxFAIL_MSG(wxT("wxSVGFILEDC::DoGetPixel Call not implemented")); return true; } - virtual bool DoBlit(wxCoord, wxCoord, wxCoord, wxCoord, wxDC*, - wxCoord, wxCoord, wxRasterOperationMode = wxCOPY, - bool = 0, int = -1, int = -1) wxOVERRIDE; + virtual bool DoBlit(wxCoord xdest, wxCoord ydest, + wxCoord width, wxCoord height, + wxDC* source, + wxCoord xsrc, wxCoord ysrc, + wxRasterOperationMode rop, + bool useMask = false, + wxCoord xsrcMask = wxDefaultCoord, + wxCoord ysrcMask = wxDefaultCoord) wxOVERRIDE; - virtual void DoCrossHair(wxCoord, wxCoord) wxOVERRIDE + virtual void DoCrossHair(wxCoord WXUNUSED(x), wxCoord WXUNUSED(y)) wxOVERRIDE { wxFAIL_MSG(wxT("wxSVGFILEDC::CrossHair Call not implemented")); } - virtual void DoDrawArc(wxCoord, wxCoord, wxCoord, wxCoord, wxCoord, wxCoord) wxOVERRIDE; + virtual void DoDrawArc(wxCoord x1, wxCoord y1, + wxCoord x2, wxCoord y2, + wxCoord xc, wxCoord yc) wxOVERRIDE; - virtual void DoDrawBitmap(const wxBitmap&, wxCoord, wxCoord, bool = false) wxOVERRIDE; + virtual void DoDrawBitmap(const wxBitmap& bmp, wxCoord x, wxCoord y, + bool useMask = false) wxOVERRIDE; - virtual void DoDrawEllipse(wxCoord x, wxCoord y, wxCoord w, wxCoord h) wxOVERRIDE; + virtual void DoDrawEllipse(wxCoord x, wxCoord y, + wxCoord width, wxCoord height) wxOVERRIDE; virtual void DoDrawEllipticArc(wxCoord x, wxCoord y, wxCoord w, wxCoord h, double sa, double ea) wxOVERRIDE; - virtual void DoDrawIcon(const wxIcon&, wxCoord, wxCoord) wxOVERRIDE; + virtual void DoDrawIcon(const wxIcon& icon, wxCoord x, wxCoord y) wxOVERRIDE; virtual void DoDrawLine(wxCoord x1, wxCoord y1, wxCoord x2, wxCoord y2) wxOVERRIDE; virtual void DoDrawLines(int n, const wxPoint points[], - wxCoord xoffset = 0, wxCoord yoffset = 0) wxOVERRIDE; + wxCoord xoffset, wxCoord yoffset) wxOVERRIDE; - virtual void DoDrawPoint(wxCoord, wxCoord) wxOVERRIDE; + virtual void DoDrawPoint(wxCoord x, wxCoord y) wxOVERRIDE; virtual void DoDrawPolygon(int n, const wxPoint points[], wxCoord xoffset, wxCoord yoffset, - wxPolygonFillMode fillStyle) wxOVERRIDE; + wxPolygonFillMode fillStyle = wxODDEVEN_RULE) wxOVERRIDE; virtual void DoDrawPolyPolygon(int n, const int count[], const wxPoint points[], wxCoord xoffset, wxCoord yoffset, wxPolygonFillMode fillStyle) wxOVERRIDE; - virtual void DoDrawRectangle(wxCoord x, wxCoord y, wxCoord w, wxCoord h) wxOVERRIDE; + virtual void DoDrawRectangle(wxCoord x, wxCoord y, wxCoord width, wxCoord height) wxOVERRIDE; virtual void DoDrawRotatedText(const wxString& text, wxCoord x, wxCoord y, double angle) wxOVERRIDE; virtual void DoDrawRoundedRectangle(wxCoord x, wxCoord y, - wxCoord w, wxCoord h, - double radius = 20) wxOVERRIDE; + wxCoord width, wxCoord height, + double radius) wxOVERRIDE; virtual void DoDrawText(const wxString& text, wxCoord x, wxCoord y) wxOVERRIDE; virtual bool DoFloodFill(wxCoord WXUNUSED(x), wxCoord WXUNUSED(y), const wxColour& WXUNUSED(col), - wxFloodFillStyle WXUNUSED(style) = wxFLOOD_SURFACE) wxOVERRIDE + wxFloodFillStyle WXUNUSED(style)) wxOVERRIDE { wxFAIL_MSG(wxT("wxSVGFILEDC::DoFloodFill Call not implemented")); return false; @@ -221,25 +231,26 @@ private: virtual void DoGradientFillLinear(const wxRect& rect, const wxColour& initialColour, const wxColour& destColour, - wxDirection nDirection = wxEAST) wxOVERRIDE; + wxDirection nDirection) wxOVERRIDE; virtual void DoGradientFillConcentric(const wxRect& rect, const wxColour& initialColour, const wxColour& destColour, const wxPoint& circleCenter) wxOVERRIDE; - virtual void DoGetSize(int* x, int*y) const wxOVERRIDE + virtual void DoGetSize(int* width, int* height) const wxOVERRIDE { - if ( x ) - *x = m_width; - if ( y ) - *y = m_height; + if ( width ) + *width = m_width; + if ( height ) + *height = m_height; } - virtual void DoGetTextExtent(const wxString& string, wxCoord* w, wxCoord* h, + virtual void DoGetTextExtent(const wxString& string, + wxCoord* x, wxCoord* y, wxCoord* descent = NULL, wxCoord* externalLeading = NULL, - const wxFont* font = NULL) const wxOVERRIDE; + const wxFont* theFont = NULL) const wxOVERRIDE; virtual void DoSetDeviceClippingRegion(const wxRegion& region) wxOVERRIDE { @@ -247,7 +258,8 @@ private: region.GetBox().width, region.GetBox().height); } - virtual void DoSetClippingRegion(int x, int y, int width, int height) wxOVERRIDE; + virtual void DoSetClippingRegion(wxCoord x, wxCoord y, + wxCoord w, wxCoord h) wxOVERRIDE; virtual void DoGetSizeMM(int* width, int* height) const wxOVERRIDE; diff --git a/src/common/dcsvg.cpp b/src/common/dcsvg.cpp index 3294823d60..65e4d94aa2 100644 --- a/src/common/dcsvg.cpp +++ b/src/common/dcsvg.cpp @@ -488,11 +488,11 @@ wxSVGFileDCImpl::wxSVGFileDCImpl(wxSVGFileDC* owner, const wxString& filename, Init(filename, width, height, dpi, title); } -void wxSVGFileDCImpl::Init(const wxString& filename, int Width, int Height, +void wxSVGFileDCImpl::Init(const wxString& filename, int width, int height, double dpi, const wxString& title) { - m_width = Width; - m_height = Height; + m_width = width; + m_height = height; m_dpi = dpi; @@ -532,7 +532,7 @@ void wxSVGFileDCImpl::Init(const wxString& filename, int Width, int Height, s += wxS("\n"); s += wxS("\n\n"); s += wxS("\n"), NumStr(float(Width) / dpi * 2.54), NumStr(float(Height) / dpi * 2.54), Width, Height); + s += wxString::Format(wxS(" width=\"%scm\" height=\"%scm\" viewBox=\"0 0 %d %d\">\n"), NumStr(float(m_width) / dpi * 2.54), NumStr(float(m_height) / dpi * 2.54), m_width, m_height); s += wxString::Format(wxS("%s\n"), title); s += wxString(wxS("Picture generated by wxSVG ")) + wxSVGVersion + wxS("\n\n"); s += wxS("\n"); @@ -615,7 +615,7 @@ void wxSVGFileDCImpl::DoDrawLines(int n, const wxPoint points[], wxCoord xoffset } } -void wxSVGFileDCImpl::DoDrawPoint(wxCoord x1, wxCoord y1) +void wxSVGFileDCImpl::DoDrawPoint(wxCoord x, wxCoord y) { NewGraphicsIfNeeded(); @@ -624,15 +624,15 @@ void wxSVGFileDCImpl::DoDrawPoint(wxCoord x1, wxCoord y1) s = wxS(" \n "); write(s); - DoDrawLine(x1, y1, x1, y1); + DoDrawLine(x, y, x, y); s = wxS(" \n"); write(s); } -void wxSVGFileDCImpl::DoDrawText(const wxString& text, wxCoord x1, wxCoord y1) +void wxSVGFileDCImpl::DoDrawText(const wxString& text, wxCoord x, wxCoord y) { - DoDrawRotatedText(text, x1, y1, 0.0); + DoDrawRotatedText(text, x, y, 0.0); } void wxSVGFileDCImpl::DoDrawRotatedText(const wxString& sText, wxCoord x, wxCoord y, double angle) @@ -752,7 +752,7 @@ void wxSVGFileDCImpl::DoDrawRotatedText(const wxString& sText, wxCoord x, wxCoor void wxSVGFileDCImpl::DoDrawRectangle(wxCoord x, wxCoord y, wxCoord width, wxCoord height) { - DoDrawRoundedRectangle(x, y, width, height, 0); + DoDrawRoundedRectangle(x, y, width, height, 0.0); } void wxSVGFileDCImpl::DoDrawRoundedRectangle(wxCoord x, wxCoord y, wxCoord width, wxCoord height, double radius) @@ -1093,7 +1093,7 @@ void wxSVGFileDCImpl::DoGradientFillConcentric(const wxRect& rect, CalcBoundingBox(rect.x + rect.width, rect.y + rect.height); } -void wxSVGFileDCImpl::DoSetClippingRegion(int x, int y, int width, int height) +void wxSVGFileDCImpl::DoSetClippingRegion(wxCoord x, wxCoord y, wxCoord width, wxCoord height) { wxString svg; @@ -1152,16 +1152,16 @@ void wxSVGFileDCImpl::DestroyClippingRegion() } void wxSVGFileDCImpl::DoGetTextExtent(const wxString& string, - wxCoord* w, - wxCoord* h, + wxCoord* x, + wxCoord* y, wxCoord* descent, wxCoord* externalLeading, - const wxFont* font) const + const wxFont* theFont) const { wxScreenDC sDC; - SetScaledScreenDCFont(sDC, font ? *font : m_font); + SetScaledScreenDCFont(sDC, theFont ? *theFont : m_font); - sDC.GetTextExtent(string, w, h, descent, externalLeading); + sDC.GetTextExtent(string, x, y, descent, externalLeading); } wxCoord wxSVGFileDCImpl::GetCharHeight() const @@ -1261,13 +1261,15 @@ void wxSVGFileDCImpl::SetFont(const wxFont& font) m_font = font; } -// export a bitmap as a raster image in png -bool wxSVGFileDCImpl::DoBlit(wxCoord xdest, wxCoord ydest, wxCoord width, wxCoord height, - wxDC* source, wxCoord xsrc, wxCoord ysrc, - wxRasterOperationMode logicalFunc /*= wxCOPY*/, bool useMask /*= false*/, - wxCoord /*xsrcMask = -1*/, wxCoord /*ysrcMask = -1*/) +bool wxSVGFileDCImpl::DoBlit(wxCoord xdest, wxCoord ydest, + wxCoord width, wxCoord height, + wxDC* source, + wxCoord xsrc, wxCoord ysrc, + wxRasterOperationMode rop, + bool useMask, + wxCoord WXUNUSED(xsrcMask), wxCoord WXUNUSED(ysrcMask)) { - if (logicalFunc != wxCOPY) + if (rop != wxCOPY) { wxASSERT_MSG(false, wxS("wxSVGFileDC::DoBlit Call requested nonCopy mode; this is not possible")); return false; @@ -1286,17 +1288,18 @@ bool wxSVGFileDCImpl::DoBlit(wxCoord xdest, wxCoord ydest, wxCoord width, wxCoor return false; } -void wxSVGFileDCImpl::DoDrawIcon(const wxIcon& myIcon, wxCoord x, wxCoord y) +void wxSVGFileDCImpl::DoDrawIcon(const wxIcon& icon, wxCoord x, wxCoord y) { - wxBitmap myBitmap(myIcon.GetWidth(), myIcon.GetHeight()); + wxBitmap myBitmap(icon.GetWidth(), icon.GetHeight()); wxMemoryDC memDC; memDC.SelectObject(myBitmap); - memDC.DrawIcon(myIcon, 0, 0); + memDC.DrawIcon(icon, 0, 0); memDC.SelectObject(wxNullBitmap); DoDrawBitmap(myBitmap, x, y); } -void wxSVGFileDCImpl::DoDrawBitmap(const wxBitmap& bmp, wxCoord x, wxCoord y, bool WXUNUSED(bTransparent)) +void wxSVGFileDCImpl::DoDrawBitmap(const wxBitmap& bmp, wxCoord x, wxCoord y, + bool WXUNUSED(useMask)) { NewGraphicsIfNeeded();