// ----------------------------------------------------------
// Global utilities
// ----------------------------------------------------------
// ----------------------------------------------------------
// Global utilities
// ----------------------------------------------------------
-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 = 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());
- switch ( style )
- {
- case wxPENSTYLE_SOLID:
- s = s + wxT("stroke-opacity:1.0; ");
- break;
- case wxPENSTYLE_TRANSPARENT:
- s = s + wxT("stroke-opacity:0.0; ");
- break;
- default :
- wxASSERT_MSG(false, wxT("wxSVGFileDC::Requested Pen Style not available"));
- }
- 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 = 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"));
- switch ( style )
- {
- case wxBRUSHSTYLE_SOLID:
- s = s + wxT("fill-opacity:1.0; ");
- break;
- case wxBRUSHSTYLE_TRANSPARENT:
- s = 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"));
void wxSVGFileDCImpl::DoDrawLine (wxCoord x1, wxCoord y1, wxCoord x2, wxCoord y2)
{
void wxSVGFileDCImpl::DoDrawLine (wxCoord x1, wxCoord y1, wxCoord x2, wxCoord y2)
{
wxString s;
s.Printf ( wxT("<path d=\"M%d %d L%d %d\" /> \n"), x1,y1,x2,y2 );
if (m_OK)
{
write(s);
}
wxString s;
s.Printf ( wxT("<path d=\"M%d %d L%d %d\" /> \n"), x1,y1,x2,y2 );
if (m_OK)
{
write(s);
}
}
void wxSVGFileDCImpl::DoDrawLines(int n, wxPoint points[], wxCoord xoffset , wxCoord yoffset )
}
void wxSVGFileDCImpl::DoDrawLines(int n, wxPoint points[], wxCoord xoffset , wxCoord yoffset )
s = wxT("<g style = \"stroke-linecap:round;\" > ") + wxString(wxT("\n"));
write(s);
DoDrawLine ( x1,y1,x1,y1 );
s = wxT("<g style = \"stroke-linecap:round;\" > ") + wxString(wxT("\n"));
write(s);
DoDrawLine ( x1,y1,x1,y1 );
void wxSVGFileDCImpl::DoDrawText(const wxString& text, wxCoord x1, wxCoord y1)
{
DoDrawRotatedText(text, x1,y1,0.0);
void wxSVGFileDCImpl::DoDrawText(const wxString& text, wxCoord x1, wxCoord y1)
{
DoDrawRotatedText(text, x1,y1,0.0);
}
void wxSVGFileDCImpl::DoDrawRotatedText(const wxString& sText, wxCoord x, wxCoord y, double angle)
{
//known bug; if the font is drawn in a scaled DC, it will not behave exactly as wxMSW
}
void wxSVGFileDCImpl::DoDrawRotatedText(const wxString& sText, wxCoord x, wxCoord y, double angle)
{
//known bug; if the font is drawn in a scaled DC, it will not behave exactly as wxMSW
sTmp.Printf ( wxT(" <rect x=\"%d\" y=\"%d\" width=\"%d\" height=\"%d\" "), x,y+desc-h, w, h );
s = sTmp + wxT("style=\"") + wxBrushString(m_textBackgroundColour);
sTmp.Printf ( wxT(" <rect x=\"%d\" y=\"%d\" width=\"%d\" height=\"%d\" "), x,y+desc-h, w, h );
s = sTmp + wxT("style=\"") + wxBrushString(m_textBackgroundColour);
sTmp.Printf ( wxT("\" transform=\"rotate( %s %d %d ) \" />"), NumStr(-angle), x,y );
sTmp.Printf ( wxT("\" transform=\"rotate( %s %d %d ) \" />"), NumStr(-angle), x,y );
- sTmp = m_font.GetFaceName ();
- if (sTmp.Len () > 0) s = s + wxT("style=\"font-family:") + sTmp + wxT("; ");
- else s = s + wxT("style=\" ");
+ sTmp = m_font.GetFaceName();
+ if (sTmp.Len() > 0) s += wxT("style=\"font-family:") + sTmp + wxT("; ");
+ else s += wxT("style=\" ");
wxString fontstyles [5] = { wxT("normal"), wxT("style error"), wxT("style error"), wxT("italic"), wxT("oblique") };
wxString fontstyles [5] = { wxT("normal"), wxT("style error"), wxT("style error"), wxT("italic"), wxT("oblique") };
sTmp.Printf ( wxT("stroke-width:0;\" transform=\"rotate( %s %d %d ) \" >"), NumStr(-angle), x,y );
sTmp.Printf ( wxT("stroke-width:0;\" transform=\"rotate( %s %d %d ) \" >"), NumStr(-angle), x,y );
}
void wxSVGFileDCImpl::DoDrawRectangle(wxCoord x, wxCoord y, wxCoord width, wxCoord height)
}
void wxSVGFileDCImpl::DoDrawRectangle(wxCoord x, wxCoord y, wxCoord width, wxCoord height)
void wxSVGFileDCImpl::DoDrawRoundedRectangle(wxCoord x, wxCoord y, wxCoord width, wxCoord height, double radius )
{
void wxSVGFileDCImpl::DoDrawRoundedRectangle(wxCoord x, wxCoord y, wxCoord width, wxCoord height, double radius )
{
wxString s;
s.Printf ( wxT(" <rect x=\"%d\" y=\"%d\" width=\"%d\" height=\"%d\" rx=\"%s\" "),
x, y, width, height, NumStr(radius) );
wxString s;
s.Printf ( wxT(" <rect x=\"%d\" y=\"%d\" width=\"%d\" height=\"%d\" rx=\"%s\" "),
x, y, width, height, NumStr(radius) );
wxCoord xoffset, wxCoord yoffset,
wxPolygonFillMode fillStyle)
{
wxCoord xoffset, wxCoord yoffset,
wxPolygonFillMode fillStyle)
{
for (int i = 0; i < n; i++)
{
sTmp.Printf ( wxT("%d,%d"), points [i].x+xoffset, points[i].y+yoffset );
for (int i = 0; i < n; i++)
{
sTmp.Printf ( wxT("%d,%d"), points [i].x+xoffset, points[i].y+yoffset );
}
void wxSVGFileDCImpl::DoDrawEllipse (wxCoord x, wxCoord y, wxCoord width, wxCoord height)
{
}
void wxSVGFileDCImpl::DoDrawEllipse (wxCoord x, wxCoord y, wxCoord width, wxCoord height)
{
int rh = height /2;
int rw = width /2;
wxString s;
s.Printf ( wxT("<ellipse cx=\"%d\" cy=\"%d\" rx=\"%d\" ry=\"%d\" "), x+rw,y+rh, rw, rh );
int rh = height /2;
int rw = width /2;
wxString s;
s.Printf ( wxT("<ellipse cx=\"%d\" cy=\"%d\" rx=\"%d\" ry=\"%d\" "), x+rw,y+rh, rw, rh );
x1,y1, NumStr(r1), NumStr(r2), fArc, fSweep, x2, y2, xc, yc );
// the z means close the path and fill
x1,y1, NumStr(r1), NumStr(r2), fArc, fSweep, x2, y2, xc, yc );
// the z means close the path and fill
}
void wxSVGFileDCImpl::DoDrawEllipticArc(wxCoord x,wxCoord y,wxCoord w,wxCoord h,double sa,double ea)
}
void wxSVGFileDCImpl::DoDrawEllipticArc(wxCoord x,wxCoord y,wxCoord w,wxCoord h,double sa,double ea)
int(xs), int(ys), int(rx), int(ry),
fArc, fSweep, int(xe), int(ye), int(xc), int(yc) );
int(xs), int(ys), int(rx), int(ry),
fArc, fSweep, int(xe), int(ye), int(xc), int(yc) );
}
void wxSVGFileDCImpl::DoGetTextExtent(const wxString& string, wxCoord *w, wxCoord *h, wxCoord *descent , wxCoord *externalLeading , const wxFont *font) const
}
void wxSVGFileDCImpl::DoGetTextExtent(const wxString& string, wxCoord *w, wxCoord *h, wxCoord *descent , wxCoord *externalLeading , const wxFont *font) const
sDC.SetFont (m_font);
if ( font != NULL ) sDC.SetFont ( *font );
sDC.GetTextExtent(string, w, h, descent, externalLeading );
sDC.SetFont (m_font);
if ( font != NULL ) sDC.SetFont ( *font );
sDC.GetTextExtent(string, w, h, descent, externalLeading );
{
wxString s, sBrush, sPenCap, sPenJoin, sPenStyle, sLast, sWarn;
{
wxString s, sBrush, sPenCap, sPenJoin, sPenStyle, sLast, sWarn;
sLast.Printf( wxT("stroke-width:%d\" \n transform=\"translate(%s %s) scale(%s %s)\">"),
m_pen.GetWidth(), NumStr(m_logicalOriginX), NumStr(m_logicalOriginY), NumStr(m_scaleX), NumStr(m_scaleY) );
sLast.Printf( wxT("stroke-width:%d\" \n transform=\"translate(%s %s) scale(%s %s)\">"),
m_pen.GetWidth(), NumStr(m_logicalOriginX), NumStr(m_logicalOriginY), NumStr(m_scaleX), NumStr(m_scaleY) );
memDC.Blit(0, 0, width, height, source, xsrc, ysrc);
memDC.SelectObject( wxNullBitmap );
DoDrawBitmap(myBitmap, xdest, ydest);
memDC.Blit(0, 0, width, height, source, xsrc, ysrc);
memDC.SelectObject( wxNullBitmap );
DoDrawBitmap(myBitmap, xdest, ydest);
memDC.DrawIcon(myIcon,0,0);
memDC.SelectObject( wxNullBitmap );
DoDrawBitmap(myBitmap, x, y);
memDC.DrawIcon(myIcon,0,0);
memDC.SelectObject( wxNullBitmap );
DoDrawBitmap(myBitmap, x, y);
}
void wxSVGFileDCImpl::DoDrawBitmap(const class wxBitmap & bmp, wxCoord x, wxCoord y , bool WXUNUSED(bTransparent) /*=0*/ )
{
}
void wxSVGFileDCImpl::DoDrawBitmap(const class wxBitmap & bmp, wxCoord x, wxCoord y , bool WXUNUSED(bTransparent) /*=0*/ )
{
int w = myBitmap.GetWidth();
int h = myBitmap.GetHeight();
sTmp.Printf ( wxT(" <image x=\"%d\" y=\"%d\" width=\"%dpx\" height=\"%dpx\" "), x,y,w,h );
int w = myBitmap.GetWidth();
int h = myBitmap.GetHeight();
sTmp.Printf ( wxT(" <image x=\"%d\" y=\"%d\" width=\"%dpx\" height=\"%dpx\" "), x,y,w,h );
}
void wxSVGFileDCImpl::write(const wxString &s)
{
const wxCharBuffer buf = s.utf8_str();
m_outfile->Write(buf, strlen((const char *)buf));
}
void wxSVGFileDCImpl::write(const wxString &s)
{
const wxCharBuffer buf = s.utf8_str();
m_outfile->Write(buf, strlen((const char *)buf));