From f49528cc2fd4676526979900b4444dee926ebcc7 Mon Sep 17 00:00:00 2001 From: Artur Wieczorek Date: Wed, 22 Feb 2017 21:09:16 +0100 Subject: [PATCH] Fix DrawArc() implementation in wxPostScriptDC Draw pie, not arc, if current brush is not transparent. Also simplify the code by invoking PostScript 'arc' operator only once if pie is drawn. Closes #17805. --- docs/changes.txt | 1 + src/generic/dcpsg.cpp | 69 +++++++++++++++++++++++-------------------- 2 files changed, 38 insertions(+), 32 deletions(-) diff --git a/docs/changes.txt b/docs/changes.txt index 911bf19aec..74dfa7d4b2 100644 --- a/docs/changes.txt +++ b/docs/changes.txt @@ -127,6 +127,7 @@ All (GUI): - Support multiline strings in wxPostScriptDC::DrawText(), DrawRotatedText(). - Deprecate wxEVT_STC_KEY and wxEVT_STC_URIDROPPED events (NewPagodi). - Optimize font registration in PostScript code emitted by wxPostScriptDC. +- Fix drawing filled arc with wxPostScriptDC::DrawArc(). wxGTK: diff --git a/src/generic/dcpsg.cpp b/src/generic/dcpsg.cpp index 95a5fbe87b..b6e290e441 100644 --- a/src/generic/dcpsg.cpp +++ b/src/generic/dcpsg.cpp @@ -483,51 +483,56 @@ void wxPostScriptDCImpl::DoDrawArc (wxCoord x1, wxCoord y1, wxCoord x2, wxCoord (y2 - yc < 0) ? 90.0 : -90.0 : wxRadToDeg(-atan2(double(y2-yc), double(x2-xc))); } - while (alpha1 <= 0) alpha1 += 360; - while (alpha2 <= 0) alpha2 += 360; // adjust angles to be between + 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; int i_radius = wxRound( radius ); - if ( m_brush.IsNonTransparent() ) + // Draw the arc (open) + wxString buffer; + if ( m_brush.IsNonTransparent() || m_pen.IsNonTransparent() ) { - SetBrush( m_brush ); - - wxString buffer; buffer.Printf( "newpath\n" - "%f %f %f %f %f %f ellipse\n" - "%f %f lineto\n" - "closepath\n" - "fill\n", - XLOG2DEV(xc), YLOG2DEV(yc), - XLOG2DEVREL(i_radius), YLOG2DEVREL(i_radius), - alpha1, alpha2, - XLOG2DEV(xc), YLOG2DEV(yc) ); - buffer.Replace( ",", "." ); - PsPrint( buffer ); - - CalcBoundingBox( xc-i_radius, yc-i_radius ); - CalcBoundingBox( xc+i_radius, yc+i_radius ); - } - - if ( m_pen.IsNonTransparent() ) - { - SetPen( m_pen ); - - wxString buffer; - buffer.Printf( "newpath\n" - "%f %f %f %f %f %f ellipse\n" - "stroke\n", + "%f %f %f %f %f %f ellipse\n", XLOG2DEV(xc), YLOG2DEV(yc), XLOG2DEVREL(i_radius), YLOG2DEVREL(i_radius), alpha1, alpha2 ); buffer.Replace( ",", "." ); PsPrint( buffer ); - - CalcBoundingBox( xc-i_radius, yc-i_radius ); - CalcBoundingBox( xc+i_radius, yc+i_radius ); } + + // Close and fill the arc if brush is not transparent. + if ( m_brush.IsNonTransparent() ) + { + // Lines connecting the centre with endpoints + // shouldn't be drawn if arc is full. + if ( x1 != x2 || y1 != y2 ) + { + buffer.Printf( "%f %f lineto\n", + XLOG2DEV(xc), YLOG2DEV(yc) ); + buffer.Replace( ",", "." ); + PsPrint( buffer ); + } + PsPrint( "closepath\n" ); + + SetBrush(m_brush); + // We need to preserve current path to draw the contour int the next step. + if ( m_pen.IsNonTransparent() ) + PsPrint( "gsave fill grestore\n" ); + else + PsPrint( "fill\n" ); + } + + if ( m_pen.IsNonTransparent() ) + { + SetPen(m_pen); + PsPrint( "stroke\n" ); + } + + CalcBoundingBox( xc-i_radius, yc-i_radius ); + CalcBoundingBox( xc+i_radius, yc+i_radius ); } void wxPostScriptDCImpl::DoDrawEllipticArc(wxCoord x,wxCoord y,wxCoord w,wxCoord h,double sa,double ea)