void wxSVGFileDCImpl::DoDrawLine (wxCoord x1, wxCoord y1, wxCoord x2, wxCoord y2)
{
- if (m_graphics_changed) NewGraphics();
+ NewGraphicsIfNeeded();
wxString s;
s.Printf ( wxT("<path d=\"M%d %d L%d %d\" /> \n"), x1,y1,x2,y2 );
if (m_OK)
void wxSVGFileDCImpl::DoDrawPoint (wxCoord x1, wxCoord y1)
{
wxString s;
- if (m_graphics_changed) NewGraphics();
+ NewGraphicsIfNeeded();
s = wxT("<g style = \"stroke-linecap:round;\" > ") + wxString(wxT("\n"));
write(s);
DoDrawLine ( x1,y1,x1,y1 );
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
- if (m_graphics_changed) NewGraphics();
+ NewGraphicsIfNeeded();
wxString s, sTmp;
// calculate bounding box
CalcBoundingBox((wxCoord)(x + w*cos(rad)), (wxCoord)(y - h*sin(rad)));
// wxT("bottom left") and wxT("bottom right")
- x += (wxCoord)(h*sin(rad));
- y += (wxCoord)(h*cos(rad));
- CalcBoundingBox(x, y);
CalcBoundingBox((wxCoord)(x + h*sin(rad)), (wxCoord)(y + h*cos(rad)));
+ CalcBoundingBox((wxCoord)(x + h*sin(rad) + w*cos(rad)), (wxCoord)(y + h*cos(rad) - w*sin(rad)));
if (m_backgroundMode == wxBRUSHSTYLE_SOLID)
{
// draw background first
// just like DoDrawRectangle except we pass the text color to it and set the border to a 1 pixel wide text background
- sTmp.Printf ( wxT(" <rect x=\"%d\" y=\"%d\" width=\"%d\" height=\"%d\" "), x,y+desc-h, w, h );
+ sTmp.Printf ( wxT(" <rect x=\"%d\" y=\"%d\" width=\"%d\" height=\"%d\" "), x, y, w, h );
s = sTmp + wxT("style=\"") + wxBrushString(m_textBackgroundColour);
s += wxT("stroke-width:1; ") + wxPenString(m_textBackgroundColour);
sTmp.Printf ( wxT("\" transform=\"rotate( %s %d %d ) \" />"), NumStr(-angle), x,y );
s += sTmp + wxT("\n");
write(s);
}
+
+ // convert x,y to SVG text x,y (the coordinates of the text baseline)
+ x = (wxCoord)(x + (h-desc)*sin(rad));
+ y = (wxCoord)(y + (h-desc)*cos(rad));
+
//now do the text itself
s.Printf (wxT(" <text x=\"%d\" y=\"%d\" "),x,y );
void wxSVGFileDCImpl::DoDrawRoundedRectangle(wxCoord x, wxCoord y, wxCoord width, wxCoord height, double radius )
{
- if (m_graphics_changed) NewGraphics();
+ NewGraphicsIfNeeded();
wxString s;
s.Printf ( wxT(" <rect x=\"%d\" y=\"%d\" width=\"%d\" height=\"%d\" rx=\"%s\" "),
wxCoord xoffset, wxCoord yoffset,
wxPolygonFillMode fillStyle)
{
- if (m_graphics_changed) NewGraphics();
+ NewGraphicsIfNeeded();
wxString s, sTmp;
s = wxT("<polygon style=\"");
if ( fillStyle == wxODDEVEN_RULE )
void wxSVGFileDCImpl::DoDrawEllipse (wxCoord x, wxCoord y, wxCoord width, wxCoord height)
{
- if (m_graphics_changed) NewGraphics();
+ NewGraphicsIfNeeded();
int rh = height /2;
int rw = width /2;
Might be better described as Pie drawing */
- if (m_graphics_changed) NewGraphics();
+ NewGraphicsIfNeeded();
wxString s;
// we need the radius of the circle which has two estimates
//known bug: SVG draws with the current pen along the radii, but this does not happen in wxMSW
- if (m_graphics_changed) NewGraphics();
+ NewGraphicsIfNeeded();
wxString s;
//radius
void wxSVGFileDCImpl::SetBrush(const wxBrush& brush)
-
{
m_brush = brush;
m_graphics_changed = true;
}
-void wxSVGFileDCImpl::NewGraphics()
+void wxSVGFileDCImpl::NewGraphicsIfNeeded()
{
+ if ( !m_graphics_changed )
+ return;
+
+ m_graphics_changed = false;
+
wxString s, sBrush, sPenCap, sPenJoin, sPenStyle, sLast, sWarn;
sBrush = wxT("</g>\n<g style=\"") + wxBrushString ( m_brush.GetColour(), m_brush.GetStyle() )
s = sBrush + sPenCap + sPenJoin + sPenStyle + sLast + wxT("\n") + sWarn;
write(s);
- m_graphics_changed = false;
}
void wxSVGFileDCImpl::DoDrawBitmap(const class wxBitmap & bmp, wxCoord x, wxCoord y , bool WXUNUSED(bTransparent) /*=0*/ )
{
- if (m_graphics_changed) NewGraphics();
+ NewGraphicsIfNeeded();
wxString sTmp, s, sPNG;
if ( wxImage::FindHandler(wxBITMAP_TYPE_PNG) == NULL )