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;
}
////////////////////code here
m_outfile = new wxFileOutputStream(filename);
- m_OK = m_outfile->Ok();
+ m_OK = m_outfile->IsOk();
if (m_OK)
{
m_filename = filename;
{
write(s);
}
- m_OK = m_outfile->Ok() && bPNG_OK;
+ m_OK = m_outfile->IsOk() && bPNG_OK;
}
void wxSVGFileDCImpl::write(const wxString &s)
{
const wxCharBuffer buf = s.utf8_str();
m_outfile->Write(buf, strlen((const char *)buf));
- m_OK = m_outfile->Ok();
+ m_OK = m_outfile->IsOk();
}