Handle colours with alpha channel correctly in wxSVGFileDC.
wxColour::GetAsString(wxC2S_HTML_SYNTAX) doesn't accept colours with alpha channel as alpha is not representable in HTML syntax, so avoid calling this function with such colours, remove the alpha component in the caller before using it instead. Also slightly simplify wxBrushString() and wxPenString() functions code in wxSVGFileDC implementation. Closes #13214. git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@67883 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
@@ -46,21 +46,35 @@ inline wxString NumStr(double f)
|
|||||||
return wxString::FromCDouble(f, 2);
|
return wxString::FromCDouble(f, 2);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 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)
|
||||||
|
{
|
||||||
|
if ( c.Alpha() != wxALPHA_OPAQUE )
|
||||||
|
{
|
||||||
|
*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 // No alpha.
|
||||||
|
{
|
||||||
|
*opacity = 1.;
|
||||||
|
}
|
||||||
|
|
||||||
|
return c.GetAsString(wxC2S_HTML_SYNTAX);
|
||||||
|
}
|
||||||
|
|
||||||
wxString wxPenString(wxColour c, int style = wxPENSTYLE_SOLID)
|
wxString wxPenString(wxColour c, int style = wxPENSTYLE_SOLID)
|
||||||
{
|
{
|
||||||
wxString s = wxT("stroke:") + c.GetAsString(wxC2S_HTML_SYNTAX) + wxT("; ");
|
float opacity;
|
||||||
// Use the color's alpha value (if not opaque) for the opacity.
|
wxString s = wxT("stroke:") + Col2SVG(c, &opacity) + wxT("; ");
|
||||||
// Note that a transparent pen will override the alpha value.
|
|
||||||
if (c.Alpha() != wxALPHA_OPAQUE && style != wxPENSTYLE_TRANSPARENT)
|
|
||||||
{
|
|
||||||
s += wxString::Format(wxT("stroke-opacity:%s; "), NumStr(c.Alpha()/255.));
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
switch ( style )
|
switch ( style )
|
||||||
{
|
{
|
||||||
case wxPENSTYLE_SOLID:
|
case wxPENSTYLE_SOLID:
|
||||||
s += wxT("stroke-opacity:1.0; ");
|
s += wxString::Format(wxT("stroke-opacity:%s; "), NumStr(opacity));
|
||||||
break;
|
break;
|
||||||
case wxPENSTYLE_TRANSPARENT:
|
case wxPENSTYLE_TRANSPARENT:
|
||||||
s += wxT("stroke-opacity:0.0; ");
|
s += wxT("stroke-opacity:0.0; ");
|
||||||
@@ -68,25 +82,19 @@ wxString wxPenString(wxColour c, int style = wxPENSTYLE_SOLID)
|
|||||||
default :
|
default :
|
||||||
wxASSERT_MSG(false, wxT("wxSVGFileDC::Requested Pen Style not available"));
|
wxASSERT_MSG(false, wxT("wxSVGFileDC::Requested Pen Style not available"));
|
||||||
}
|
}
|
||||||
}
|
|
||||||
return s;
|
return s;
|
||||||
}
|
}
|
||||||
|
|
||||||
wxString wxBrushString(wxColour c, int style = wxBRUSHSTYLE_SOLID)
|
wxString wxBrushString(wxColour c, int style = wxBRUSHSTYLE_SOLID)
|
||||||
{
|
{
|
||||||
wxString s = wxT("fill:") + c.GetAsString(wxC2S_HTML_SYNTAX) + wxT("; ");
|
float opacity;
|
||||||
// Use the color's alpha value (if not opaque) for the opacity.
|
wxString s = wxT("fill:") + Col2SVG(c, &opacity) + wxT("; ");
|
||||||
// Note that a transparent brush will override the alpha value.
|
|
||||||
if (c.Alpha() != wxALPHA_OPAQUE && style != wxBRUSHSTYLE_TRANSPARENT)
|
|
||||||
{
|
|
||||||
s += wxString::Format(wxT("fill-opacity:%s; "), NumStr(c.Alpha()/255.));
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
switch ( style )
|
switch ( style )
|
||||||
{
|
{
|
||||||
case wxBRUSHSTYLE_SOLID:
|
case wxBRUSHSTYLE_SOLID:
|
||||||
s += wxT("fill-opacity:1.0; ");
|
s += wxString::Format(wxT("fill-opacity:%s; "), NumStr(opacity));
|
||||||
break;
|
break;
|
||||||
case wxBRUSHSTYLE_TRANSPARENT:
|
case wxBRUSHSTYLE_TRANSPARENT:
|
||||||
s += wxT("fill-opacity:0.0; ");
|
s += wxT("fill-opacity:0.0; ");
|
||||||
@@ -94,7 +102,7 @@ wxString wxBrushString(wxColour c, int style = wxBRUSHSTYLE_SOLID)
|
|||||||
default :
|
default :
|
||||||
wxASSERT_MSG(false, wxT("wxSVGFileDC::Requested Brush Style not available"));
|
wxASSERT_MSG(false, wxT("wxSVGFileDC::Requested Brush Style not available"));
|
||||||
}
|
}
|
||||||
}
|
|
||||||
return s;
|
return s;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user