From db7af3c2a732ba6b963c254d02ca4a7734c4a3bf Mon Sep 17 00:00:00 2001 From: Vadim Zeitlin Date: Fri, 25 Oct 2013 17:38:37 +0000 Subject: [PATCH] Fix DrawArc() implementation in wxGtkPrinterDC. It didn't count the angles correctly when they were equal to 90 degrees. Also simplify the code by avoiding special cases for 90 degrees anyhow, just call atan2() directly. And also avoid converting the angles to degrees just to convert them back to radians immediately afterwards. See #15609. git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@75064 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775 --- docs/changes.txt | 4 ++++ src/gtk/print.cpp | 43 ++++++++++++++++++------------------------- 2 files changed, 22 insertions(+), 25 deletions(-) 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);