diff --git a/docs/changes.txt b/docs/changes.txt index d38cd3a562..c3c09fb10c 100644 --- a/docs/changes.txt +++ b/docs/changes.txt @@ -573,6 +573,10 @@ All (GUI): - Fix wxListEvent::GetData() in LLP64 builds. +wxGTK: + +- Fix DrawArc() when printing. + wxMSW: - Optional better handling of SAFEARRAYs in wxAutomationObject (PB). diff --git a/src/gtk/print.cpp b/src/gtk/print.cpp index d776a88b52..997c95a540 100644 --- a/src/gtk/print.cpp +++ b/src/gtk/print.cpp @@ -1357,42 +1357,35 @@ void wxGtkPrinterDCImpl::DoCrossHair(wxCoord x, wxCoord y) void wxGtkPrinterDCImpl::DoDrawArc(wxCoord x1,wxCoord y1,wxCoord x2,wxCoord y2,wxCoord xc,wxCoord yc) { - double dx = x1 - xc; - double dy = y1 - yc; - double radius = sqrt((double)(dx*dx+dy*dy)); + const double dx1 = x1 - xc; + const double dy1 = y1 - yc; + const double radius = sqrt(dx1*dx1 + dy1*dy1); + + if ( radius == 0.0 ) + return; double alpha1, alpha2; - if (x1 == x2 && y1 == y2) + if ( x1 == x2 && y1 == y2 ) { alpha1 = 0.0; - alpha2 = 360.0; - } - else - if (radius == 0.0) - { - alpha1 = alpha2 = 0.0; + alpha2 = 2*M_PI; + } else { - alpha1 = (x1 - xc == 0) ? - (y1 - yc < 0) ? 90.0 : -90.0 : - atan2(double(y1-yc), double(x1-xc)) * RAD2DEG; - alpha2 = (x2 - xc == 0) ? - (y2 - yc < 0) ? 90.0 : -90.0 : - atan2(double(y2-yc), double(x2-xc)) * RAD2DEG; - - while (alpha1 <= 0) alpha1 += 360; - while (alpha2 <= 0) alpha2 += 360; // adjust angles to be between. - while (alpha1 > 360) alpha1 -= 360; // 0 and 360 degree. - while (alpha2 > 360) alpha2 -= 360; + alpha1 = atan2(dy1, dx1); + alpha2 = atan2(double(y2-yc), double(x2-xc)); } - alpha1 *= DEG2RAD; - alpha2 *= DEG2RAD; - cairo_new_path(m_cairo); - cairo_arc_negative ( m_cairo, XLOG2DEV(xc), YLOG2DEV(yc), XLOG2DEVREL((int)radius), alpha1, alpha2); + // We use the "negative" variant because the arc should go counterclockwise + // while in the default coordinate system, with Y axis going down, Cairo + // counts angles in the direction from positive X axis direction to + // positive Y axis direction, i.e. clockwise. + cairo_arc_negative(m_cairo, XLOG2DEV(xc), YLOG2DEV(yc), + XLOG2DEVREL(wxRound(radius)), alpha1, alpha2); + cairo_line_to(m_cairo, XLOG2DEV(xc), YLOG2DEV(yc)); cairo_close_path (m_cairo);