示例#1
0
        /// <summary>
        /// Compiles the stroke to the necessary triangles to draw it.
        /// </summary>
        /// <param name="path">The path to be compiled.</param>
        /// <param name="width">The width of the stroke.</param>
        /// <param name="lineCap">The line cap method for the stroke's ends.</param>
        /// <param name="lineJoin">The line join method for the stroke's midpoints</param>
        /// <param name="miterLimit">The miter limit value.</param>
        public static CompiledDrawing CompileStroke(SvgPathSegmentList path, double width,
                                                    SvgStrokeLineCap lineCap   = SvgStrokeLineCap.Butt,
                                                    SvgStrokeLineJoin lineJoin = SvgStrokeLineJoin.Bevel,
                                                    double miterLimit          = double.PositiveInfinity)
        {
            // Return empty if stroke width == 0
            if (width == 0)
            {
                return(CompiledDrawing.Empty);
            }

            // Divide the width by 2 to cope with the SVG documentation
            var halfWidth = width / 2;

            var curves = new List <Curve>();

            // Convert each split path to a fill
            foreach (var data in path.SplitCurves())
            {
                curves.AddRange(StrokeUtils.ConvertToFill(data, halfWidth, lineCap, lineJoin, miterLimit));
            }

            // And compile
            return(CompileCurves(curves, SvgFillRule.NonZero));
        }
示例#2
0
        /// <summary>
        /// Determine the filled simple segments of a path, splitting lines and curves appropriately.
        /// </summary>
        /// <param name="path">The path that is supposed to be compiled.</param>
        /// <param name="fillRule">The fill rule used to determine the filled components</param>
        /// <returns>The set of simple path components.</returns>
        public static CompiledDrawing CompileFill(SvgPathSegmentList path, SvgFillRule fillRule = SvgFillRule.EvenOdd)
        {
            var curveData = path.SplitCurves();
            var curves    = new List <Curve>();

            foreach (var data in curveData)
            {
                // Add all open curves
                curves.AddRange(data.Curves);

                // Force close the open curves
                var p0 = data.Curves[0].At(0);
                var p1 = data.Curves[data.Curves.Length - 1].At(1);
                if (!DoubleUtils.RoughlyEquals(p0, p1))
                {
                    curves.Add(Curve.Line(p1, p0));
                }
            }

            return(CompileCurves(curves, fillRule));
        }
示例#3
0
 public static IEnumerable <Curve> Curves(this SvgPathSegmentList pathSegments)
 => pathSegments.SplitCurves().SelectMany(c => c.Curves);