Add initial line segment when adding arc to wxGraphicsPath with GDI+

For the sake of compatibility with Cairo (and Direct2D) an initial line segment should be added to the path from the current point (if set) to the beginning of the arc.

Closes #17557
This commit is contained in:
Artur Wieczorek
2016-06-05 18:50:54 +02:00
parent cc37031d46
commit edabb01032
3 changed files with 18 additions and 16 deletions

View File

@@ -31,11 +31,15 @@ public:
The angles are measured in radians but, contrary to the usual
mathematical convention, are always @e clockwise from the horizontal
axis.
If for clockwise arc @a endAngle is less than @a startAngle it will be
progressively increased by 2*pi until it is greater than @a startAngle.
If for counter-clockwise arc @a endAngle is greater than @a startAngle
it will be progressively decreased by 2*pi until it is less than
@a startAngle.
If there is a current point set, an initial line segment will be added
to the path to connect the current point to the beginning of the arc.
*/
//@{
virtual void AddArc(wxDouble x, wxDouble y, wxDouble r,

View File

@@ -1295,7 +1295,7 @@ void wxGDIPlusPathData::AddArc( wxDouble x, wxDouble y, wxDouble r, double start
{
double angle;
// For the sake of consistency normalize angles the same way
// For the sake of compatibility normalize angles the same way
// as it is done in Cairo.
if ( clockwise )
{
@@ -1326,22 +1326,17 @@ void wxGDIPlusPathData::AddArc( wxDouble x, wxDouble y, wxDouble r, double start
angle = startAngle - endAngle;
}
// Native GraphicsPath.AddArc() does nothing when sweep
// angle equals 0 (even current point is not updated)
// so we have to handle this case on our own.
// To ensure compatibility with Cairo an initial
// line segment to the beginning of the arc needs
// to be added to the path.
AddLineToPoint(r*cos(startAngle) + x, r*sin(startAngle) + y);
// Native GraphicsPath.AddArc() does nothing
// (even current point is not updated)
// when sweep angle equals 0 so we can skip
// any further actions.
if ( angle == 0 )
{
wxPoint2DDouble start = wxPoint2DDouble(cos(startAngle) * r, sin(startAngle) * r);
if (m_figureOpened)
{
AddLineToPoint(start.m_x + x, start.m_y + y);
}
else
{
MoveToPoint(start.m_x + x, start.m_y + y);
}
return;
}

View File

@@ -1416,7 +1416,7 @@ void wxD2DPathData::AddArc(wxDouble x, wxDouble y, wxDouble r, wxDouble startAng
{
double angle;
// For the sake of consistency normalize angles the same way
// For the sake of compatibility normalize angles the same way
// as it is done in Cairo.
if ( clockwise )
{
@@ -1450,6 +1450,9 @@ void wxD2DPathData::AddArc(wxDouble x, wxDouble y, wxDouble r, wxDouble startAng
wxPoint2DDouble start = wxPoint2DDouble(cos(startAngle) * r, sin(startAngle) * r);
wxPoint2DDouble end = wxPoint2DDouble(cos(endAngle) * r, sin(endAngle) * r);
// To ensure compatibility with Cairo an initial
// line segment to the beginning of the arc needs
// to be added to the path.
if (m_figureOpened)
{
AddLineToPoint(start.m_x + x, start.m_y + y);