]> git.saurik.com Git - wxWidgets.git/blobdiff - src/common/dcsvg.cpp
Fix compilation errors under OSX.
[wxWidgets.git] / src / common / dcsvg.cpp
index 449ad4791aaf04e290ad151d6b9e44425864ccb8..9aeb7e953085ed759b688327bde55add560ea4af 100644 (file)
@@ -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;
 }