public void ClosePath_Test()
        {
            PDFGraphicsPath target = new PDFGraphicsPath();

            Assert.IsTrue(target.Paths.Count == 1);
            Assert.IsTrue(target.HasCurrentPath);

            bool end = false;

            target.ClosePath(end);
            Assert.IsTrue(target.Paths.Count == 1, "Paths count after close was not 1");
            Assert.IsTrue(target.Paths[0].Count == 1, "First path does not have one entry");
            Assert.IsTrue(target.Paths[0].Operations.Count == 1, "First path operations count was not 1");
            Assert.IsInstanceOfType(target.Paths[0].Operations[0], typeof(PathCloseData), "Opertation type was not a PathClose");

            //should still have a current path.
            Assert.IsTrue(target.HasCurrentPath, "There is no current path");
            Assert.IsNotNull(target.CurrentPath);


            end    = true;
            target = new PDFGraphicsPath();
            Assert.IsTrue(target.Paths.Count == 1);
            Assert.IsTrue(target.HasCurrentPath);

            target.ClosePath(true);
            Assert.IsTrue(target.Paths.Count == 1, "Paths count after close was not 1");
            Assert.IsTrue(target.Paths[0].Count == 1, "First path does not have one entry");
            Assert.IsTrue(target.Paths[0].Operations.Count == 1, "First path operations count was not 1");
            Assert.IsInstanceOfType(target.Paths[0].Operations[0], typeof(PathCloseData), "Opertation type was not a PathClose");

            //should NOT have a current path.
            Assert.IsFalse(target.HasCurrentPath, "There is a current path after ending it");
            Assert.IsNull(target.CurrentPath, "Current path is not null after ending path");
        }
        //
        // helper methods
        //


        #region protected virtual void BuildPath(PDFGraphicsPath path, PDFPoint[] points, PDFStyle style, bool end)

        /// <summary>
        /// Adds a series of lines to the path based on the points. Moving to the first in the array, adding lines after, and optionally closing and ending the path.
        /// </summary>
        /// <param name="path">The path to build the lines in</param>
        /// <param name="points">The points to add lines between</param>
        /// <param name="close">Closes the path (adds an extra line back to the starting point</param>
        /// <param name="end">If true then ends the path so no more points can be added to it</param>
        protected virtual void BuildPath(PDFGraphicsPath path, PDFPoint[] points, Style style, bool end)
        {
            if (path.HasCurrentPath == false)
            {
                path.BeginPath();
            }

            for (int i = 0; i < points.Length; i++)
            {
                if (i == 0)
                {
                    path.MoveTo(points[i]);
                }
                else
                {
                    path.LineTo(points[i]);
                }
            }

            bool closed = style.GetValue(StyleKeys.ShapeClosedKey, true);

            if (closed)
            {
                path.ClosePath(end);
            }
            else if (end)
            {
                path.EndPath();
            }
        }
        protected override PDFGraphicsPath CreatePath(PDFSize available, Style fullstyle)
        {
            PDFGraphicsPath path = base.CreatePath(available, fullstyle);

            path.ClosePath(true);

            return(path);
        }
示例#4
0
        public static void BuildElipse(PDFGraphicsPath path, PDFRect rect, bool closed, double angle)
        {
            double width  = rect.Width.PointsValue;
            double height = rect.Height.PointsValue;

            if (width <= 0 || height <= 0)
            {
                return;
            }

            // build the ellipse around the origin
            // rotate each by the required amount
            // then translate into position.

            double centerX = rect.Width.PointsValue / 2.0;
            double centerY = rect.Height.PointsValue / 2.0;

            double radX = width / 2.0;
            double radY = height / 2.0;

            double lengthX = (double)((width * CircularityFactor) / 2.0);
            double lengthY = (double)((height * CircularityFactor) / 2.0);

            double rotation = angle * InRadians;

            //start at left, middle
            PDFPoint start = Rotate(new PDFPoint(-radX, 0), rotation);


            //4 curve definitions with 3 points each.
            PDFPoint[,] curves = new PDFPoint[4, 3];


            //arc to center, top
            curves[0, 0] = Rotate(new PDFPoint(0, -radY), rotation);
            curves[0, 1] = Rotate(new PDFPoint(-radX, -lengthY), rotation);
            curves[0, 2] = Rotate(new PDFPoint(-lengthX, -radY), rotation);



            //arc to right, middle
            curves[1, 0] = Rotate(new PDFPoint(radX, 0), rotation);
            curves[1, 1] = Rotate(new PDFPoint(lengthX, -radY), rotation);
            curves[1, 2] = Rotate(new PDFPoint(radX, -lengthY), rotation);


            //arc to center, bottom
            curves[2, 0] = Rotate(new PDFPoint(0, radY), rotation);
            curves[2, 1] = Rotate(new PDFPoint(radX, lengthY), rotation);
            curves[2, 2] = Rotate(new PDFPoint(lengthX, radY), rotation);


            //arc to left middle
            curves[3, 0] = Rotate(new PDFPoint(-radX, 0), rotation);
            curves[3, 1] = Rotate(new PDFPoint(-lengthX, radY), rotation);
            curves[3, 2] = Rotate(new PDFPoint(-radX, lengthY), rotation);

            //get the minimun x and y values
            PDFUnit minx = start.X;
            PDFUnit miny = start.Y;

            for (int i = 0; i < 4; i++)
            {
                for (int j = 0; j < 3; j++)
                {
                    PDFPoint pt = curves[i, j];
                    minx = PDFUnit.Min(minx, pt.X);
                    miny = PDFUnit.Min(miny, pt.Y);
                }
            }
            PDFUnit offsetx = 0 - minx;
            PDFUnit offsety = 0 - miny;

            //translate the point by the minimum values so the topleft is always 0,0 in the boundary rect.

            start = Translate(start, offsetx, offsety);

            for (int i = 0; i < 4; i++)
            {
                for (int j = 0; j < 3; j++)
                {
                    PDFPoint pt = curves[i, j];
                    pt           = Translate(pt, offsetx, offsety);
                    curves[i, j] = pt;
                }
            }

            path.MoveTo(start);
            path.CubicCurveTo(curves[0, 0], curves[0, 1], curves[0, 2]);
            path.CubicCurveTo(curves[1, 0], curves[1, 1], curves[1, 2]);
            path.CubicCurveTo(curves[2, 0], curves[2, 1], curves[2, 2]);
            path.CubicCurveTo(curves[3, 0], curves[3, 1], curves[3, 2]);



            //close
            if (closed)
            {
                path.ClosePath(true);
            }
            else
            {
                path.EndPath();
            }
        }
 private void ParseSVGCloseCommand(PDFGraphicsPath path, string[] args)
 {
     path.ClosePath(false);
 }
示例#6
0
        protected virtual void BuildPolygramPath(PDFGraphicsPath path, PDFPoint[] points, int step, bool closed, bool end)
        {
            if (points.Length < 5)
            {
                throw new PDFException(Errors.CannotCreatePolygramWithLessThan5Sides, null);
            }

            if (step >= points.Length)
            {
                throw new PDFException(Errors.StepCountCannotBeGreaterThanVertexCount);
            }

            bool[] visited   = new bool[points.Length];
            int    loopcount = 0;
            int    firstFree = 0;

            //checks the integer array of see if everyone has been covered
            Func <bool> visitedAll = delegate()
            {
                for (int i = 0; i < visited.Length; i++)
                {
                    if (visited[i] == false)
                    {
                        firstFree = i;
                        return(false);
                    }
                }
                return(true);
            };

            while (!visitedAll() && loopcount < 10)
            {
                if (path.HasCurrentPath == false)
                {
                    path.BeginPath();
                }

                int      index   = firstFree; //firstFree is set from the visitedAll method
                PDFPoint first   = points[index];
                PDFPoint current = first;

                path.MoveTo(current);
                do
                {
                    index += step;
                    if (index >= points.Length)
                    {
                        index -= points.Length;
                    }

                    current = points[index];

                    visited[index] = true; //mark the point as visited.

                    if (current == first)
                    {
                        if (closed)
                        {
                            path.ClosePath(end);
                        }
                        else if (end)
                        {
                            path.EndPath();
                        }
                    }
                    else
                    {
                        path.LineTo(current);
                    }
                } while (current != first);

                path.EndPath();

                loopcount++;
            }
        }