X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/a1b806b98241ab649c169aaa1f134df85e80fb8b..08670ea85abf4b4946a9ce64971b591d7b1ee30b:/src/common/dcsvg.cpp diff --git a/src/common/dcsvg.cpp b/src/common/dcsvg.cpp index 449ad4791a..9aeb7e9530 100644 --- a/src/common/dcsvg.cpp +++ b/src/common/dcsvg.cpp @@ -46,55 +46,63 @@ inline wxString NumStr(double f) return wxString::FromCDouble(f, 2); } -wxString wxPenString(wxColour c, int style = wxPENSTYLE_SOLID) +// 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 s = wxT("stroke:") + c.GetAsString(wxC2S_HTML_SYNTAX) + wxT("; "); - // Use the color's alpha value (if not opaque) for the opacity. - // Note that a transparent pen will override the alpha value. - if (c.Alpha() != wxALPHA_OPAQUE && style != wxPENSTYLE_TRANSPARENT) + if ( c.Alpha() != wxALPHA_OPAQUE ) { - s += wxString::Format(wxT("stroke-opacity:%s; "), NumStr(c.Alpha()/255.)); + *opacity = c.Alpha()/255.; + + // Remove the alpha before using GetAsString(wxC2S_HTML_SYNTAX) as it + // doesn't support colours with alpha channel. + c = wxColour(c.GetRGB()); } - else + else // No alpha. { - switch ( style ) - { - case wxPENSTYLE_SOLID: - s += wxT("stroke-opacity:1.0; "); - break; - case wxPENSTYLE_TRANSPARENT: - s += wxT("stroke-opacity:0.0; "); - break; - default : - wxASSERT_MSG(false, wxT("wxSVGFileDC::Requested Pen Style not available")); - } + *opacity = 1.; } - return s; + + return c.GetAsString(wxC2S_HTML_SYNTAX); } -wxString wxBrushString(wxColour c, int style = wxBRUSHSTYLE_SOLID) +wxString wxPenString(wxColour c, int style = wxPENSTYLE_SOLID) { - wxString s = wxT("fill:") + c.GetAsString(wxC2S_HTML_SYNTAX) + wxT("; "); - // Use the color's alpha value (if not opaque) for the opacity. - // Note that a transparent brush will override the alpha value. - if (c.Alpha() != wxALPHA_OPAQUE && style != wxBRUSHSTYLE_TRANSPARENT) + float opacity; + wxString s = wxT("stroke:") + Col2SVG(c, &opacity) + wxT("; "); + + switch ( style ) { - s += wxString::Format(wxT("fill-opacity:%s; "), NumStr(c.Alpha()/255.)); + case wxPENSTYLE_SOLID: + s += wxString::Format(wxT("stroke-opacity:%s; "), NumStr(opacity)); + break; + case wxPENSTYLE_TRANSPARENT: + s += wxT("stroke-opacity:0.0; "); + break; + default : + wxASSERT_MSG(false, wxT("wxSVGFileDC::Requested Pen Style not available")); } - else + + return s; +} + +wxString wxBrushString(wxColour c, int style = wxBRUSHSTYLE_SOLID) +{ + float opacity; + wxString s = wxT("fill:") + Col2SVG(c, &opacity) + wxT("; "); + + switch ( style ) { - switch ( style ) - { - case wxBRUSHSTYLE_SOLID: - s += wxT("fill-opacity:1.0; "); - break; - case wxBRUSHSTYLE_TRANSPARENT: - s += wxT("fill-opacity:0.0; "); - break; - default : - wxASSERT_MSG(false, wxT("wxSVGFileDC::Requested Brush Style not available")); - } + case wxBRUSHSTYLE_SOLID: + s += wxString::Format(wxT("fill-opacity:%s; "), NumStr(opacity)); + break; + case wxBRUSHSTYLE_TRANSPARENT: + s += wxT("fill-opacity:0.0; "); + break; + default : + wxASSERT_MSG(false, wxT("wxSVGFileDC::Requested Brush Style not available")); } + return s; }