PDFsharp & MigraDoc Foundation
https://forum.pdfsharp.net/

XGraphicsPath - Path w/ open and closed figures causes issue
https://forum.pdfsharp.net/viewtopic.php?f=3&t=2360
Page 1 of 1

Author:  no-op [ Mon Mar 11, 2013 7:59 pm ]
Post subject:  XGraphicsPath - Path w/ open and closed figures causes issue

A path containing several open figures with a closed figure in the middle will not close correctly. It will treat the entire path as a single closed figure. Issue was fixed by updating get accessor in the XGraphicsPath.CurrentPathFigure property.

The code originally read:

Code:
        /// <summary>
        /// Gets the current path figure.
        /// </summary>
        private PathFigure CurrentPathFigure
        {
            get
            {
                int count = this.pathGeometry.Figures.Count;
                if (count == 0)
                {
                    this.pathGeometry.Figures.Add(new PathFigure());
                    count++;
                }
                else if (this.startNewFigure && this.pathGeometry.Figures[count - 1].Segments.Count == 0)
                {
                    this.pathGeometry.Figures.Add(new PathFigure());
                    count++;
                }
                return this.pathGeometry.Figures[count - 1];
            }
        }

The apparent logic error is the '==' conditional in the else if statement. With fix, the code reads:

Code:
        /// <summary>
        /// Gets the current path figure.
        /// </summary>
        private PathFigure CurrentPathFigure
        {
            get
            {
                int count = this.pathGeometry.Figures.Count;
                if (count == 0)
                {
                    this.pathGeometry.Figures.Add(new PathFigure());
                    count++;
                }
                else if (this.startNewFigure && this.pathGeometry.Figures[count - 1].Segments.Count > 0)
                {
                    this.pathGeometry.Figures.Add(new PathFigure());
                    count++;
                }
                return this.pathGeometry.Figures[count - 1];
            }
        }


With fix, only the closed figure is closed and other figures remain open.

Author:  Thomas Hoevel [ Tue Mar 12, 2013 9:13 am ]
Post subject:  Re: XGraphicsPath - Path w/ open and closed figures causes i

Thank you very much for the feedback.

Page 1 of 1 All times are UTC
Powered by phpBB® Forum Software © phpBB Group
https://www.phpbb.com/