From 2dcaa43f0b2bd8afcf1319b3c216c828745cd304 Mon Sep 17 00:00:00 2001 From: Maarten Bent Date: Sat, 4 Jun 2016 14:20:18 +0200 Subject: [PATCH] Fixed drawing ellipses and arcs in wxSVGFileDC. Ellipses with the same start and end point (circles) where not drawn because the angle becomes 0 degrees. Fixed by drawing two half circles. Do not close ellipses if a transparent brush is used (to match wxDC behavior). See issue #17557. --- src/common/dcsvg.cpp | 60 +++++++++++++++++++++++++++----------------- 1 file changed, 37 insertions(+), 23 deletions(-) diff --git a/src/common/dcsvg.cpp b/src/common/dcsvg.cpp index f93396065f..fbc93b1802 100644 --- a/src/common/dcsvg.cpp +++ b/src/common/dcsvg.cpp @@ -731,17 +731,16 @@ void wxSVGFileDCImpl::DoDrawPolyPolygon(int n, const int count[], const wxPoint } } -void wxSVGFileDCImpl::DoDrawEllipse (wxCoord x, wxCoord y, wxCoord width, wxCoord height) - +void wxSVGFileDCImpl::DoDrawEllipse(wxCoord x, wxCoord y, wxCoord width, wxCoord height) { NewGraphicsIfNeeded(); - int rh = height /2; - int rw = width /2; + int rh = height / 2; + int rw = width / 2; wxString s; - s.Printf ( wxT(" \n"); + s = wxString::Format(wxS(" \n"); write(s); @@ -767,35 +766,50 @@ void wxSVGFileDCImpl::DoDrawArc(wxCoord x1, wxCoord y1, wxCoord x2, wxCoord y2, double r1 = sqrt ( double( (x1-xc)*(x1-xc) ) + double( (y1-yc)*(y1-yc) ) ); double r2 = sqrt ( double( (x2-xc)*(x2-xc) ) + double( (y2-yc)*(y2-yc) ) ); - wxASSERT_MSG( (fabs ( r2-r1 ) <= 3), wxT("wxSVGFileDC::DoDrawArc Error in getting radii of circle")); + wxASSERT_MSG( (fabs ( r2-r1 ) <= 3), wxS("wxSVGFileDC::DoDrawArc Error in getting radii of circle")); if ( fabs ( r2-r1 ) > 3 ) //pixels { - s = wxT(" \n"); + s = wxS("\n"); write(s); } - double theta1 = atan2((double)(yc-y1),(double)(x1-xc)); - if ( theta1 < 0 ) theta1 = theta1 + M_PI * 2; - double theta2 = atan2((double)(yc-y2), (double)(x2-xc)); - if ( theta2 < 0 ) theta2 = theta2 + M_PI * 2; - if ( theta2 < theta1 ) theta2 = theta2 + M_PI *2; + double theta1 = atan2((double)(yc - y1), (double)(x1 - xc)); + if (theta1 < 0) + theta1 = theta1 + M_PI * 2; + + double theta2 = atan2((double)(yc - y2), (double)(x2 - xc)); + if (theta2 < 0) + theta2 = theta2 + M_PI * 2; + if (theta2 < theta1) theta2 = theta2 + M_PI * 2; int fArc; // flag for large or small arc 0 means less than 180 degrees - if ( fabs(theta2 - theta1) > M_PI ) fArc = 1; else fArc = 0; + if (fabs(theta2 - theta1) > M_PI) + fArc = 1; else fArc = 0; int fSweep = 0; // flag for sweep always 0 - s.Printf ( wxT(" \n"); - - - if (m_OK) + if (x1 == x2 && y1 == y2) { - write(s); + // drawing full circle fails with default arc. Draw two half arcs instead. + s = wxString::Format(wxS(" \n"); + + write(s); } void wxSVGFileDCImpl::DoDrawEllipticArc(wxCoord x,wxCoord y,wxCoord w,wxCoord h,double sa,double ea)