From 2171d407e176cef44a37003c4ebb0070cfa911d0 Mon Sep 17 00:00:00 2001 From: Maarten Bent Date: Tue, 15 Mar 2016 23:48:53 +0100 Subject: [PATCH] Support more brush styles in wxSVGFileDC. --- src/common/dcsvg.cpp | 108 ++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 101 insertions(+), 7 deletions(-) diff --git a/src/common/dcsvg.cpp b/src/common/dcsvg.cpp index 31a4315194..925fa52a7a 100644 --- a/src/common/dcsvg.cpp +++ b/src/common/dcsvg.cpp @@ -97,18 +97,23 @@ wxString wxPenString(wxColour c, int style = wxPENSTYLE_SOLID) wxString wxBrushString(wxColour c, int style = wxBRUSHSTYLE_SOLID) { float opacity; - wxString s = wxT("fill:") + Col2SVG(c, &opacity) + wxT("; "); + wxString s = wxS("fill:") + Col2SVG(c, &opacity) + wxS("; "); switch ( style ) { case wxBRUSHSTYLE_SOLID: - s += wxString::Format(wxT("fill-opacity:%s; "), NumStr(opacity)); + case wxBRUSHSTYLE_FDIAGONAL_HATCH: + case wxBRUSHSTYLE_CROSSDIAG_HATCH: + case wxBRUSHSTYLE_CROSS_HATCH: + case wxBRUSHSTYLE_VERTICAL_HATCH: + case wxBRUSHSTYLE_HORIZONTAL_HATCH: + s += wxString::Format(wxS("fill-opacity:%s; "), NumStr(opacity)); break; case wxBRUSHSTYLE_TRANSPARENT: - s += wxT("fill-opacity:0.0; "); + s += wxS("fill-opacity:0.0; "); break; default : - wxASSERT_MSG(false, wxT("wxSVGFileDC::Requested Brush Style not available")); + wxASSERT_MSG(false, wxS("wxSVGFileDC::Requested Brush Style not available")); } return s; @@ -179,6 +184,92 @@ wxString wxGetPenPattern(wxPen& pen) return s; } +wxString wxGetBrushStyleName(wxBrush& brush) +{ + wxString brushStyle; + + switch (brush.GetStyle()) + { + case wxBRUSHSTYLE_FDIAGONAL_HATCH: + brushStyle = wxS("FdiagonalHatch"); + break; + case wxBRUSHSTYLE_CROSSDIAG_HATCH: + brushStyle = wxS("CrossDiagHatch"); + break; + case wxBRUSHSTYLE_CROSS_HATCH: + brushStyle = wxS("CrossHatch"); + break; + case wxBRUSHSTYLE_VERTICAL_HATCH: + brushStyle = wxS("VerticalHatch"); + break; + case wxBRUSHSTYLE_HORIZONTAL_HATCH: + brushStyle = wxS("HorizontalHatch"); + break; + 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: + case wxBRUSHSTYLE_TRANSPARENT: + case wxBRUSHSTYLE_INVALID: + // these brushstyles do not need a fill. + break; + } + + return brushStyle; +} + +wxString wxGetBrushFill(wxBrush& brush) +{ + wxString s; + wxString brushStyle = wxGetBrushStyleName(brush); + + if (!brushStyle.IsEmpty()) + s = wxS(" fill=\"url(#") + brushStyle + brush.GetColour().GetAsString(wxC2S_HTML_SYNTAX).substr(1) + wxS(")\""); + + return s; +} + +wxString wxCreateBrushFill(wxBrush& brush) +{ + wxString s; + wxString patternName = wxGetBrushStyleName(brush); + + if (!patternName.IsEmpty()) + { + patternName += brush.GetColour().GetAsString(wxC2S_HTML_SYNTAX).substr(1); + s = wxS("\n"); + s += wxS(" \n\n"); + } + + return s; +} + } // anonymous namespace // ---------------------------------------------------------------------------- @@ -577,8 +668,8 @@ void wxSVGFileDCImpl::DoDrawRoundedRectangle(wxCoord x, wxCoord y, wxCoord width NewGraphicsIfNeeded(); wxString s; - s.Printf ( wxT(" \n"); write(s); @@ -599,7 +690,7 @@ void wxSVGFileDCImpl::DoDrawPolygon(int n, const wxPoint points[], else s += wxT("fill-rule:nonzero; "); - s += wxT("\" \npoints=\""); + s += wxT("\"") + wxGetBrushFill(m_brush) + wxT("\npoints=\""); for (int i = 0; i < n; i++) { @@ -886,6 +977,9 @@ void wxSVGFileDCImpl::SetBrush(const wxBrush& brush) m_brush = brush; m_graphics_changed = true; + + wxString pattern = wxCreateBrushFill(m_brush); + write(pattern); }