예제 #1
0
        //--------------------------------------------------------------------------------------------------

        void _ImportQuadraticCurveSegment(SvgPathSegCurvetoQuadratic svgSegment, ref int startPoint)
        {
            var endPoint     = _AddPoint(svgSegment.End);
            var controlPoint = _AddPoint(svgSegment.C1);

            _Segments.Add(new SketchSegmentBezier(startPoint, controlPoint, endPoint));
            startPoint = endPoint;
        }
예제 #2
0
        public static IEnumerable <SvgPathSegment> Create(SvgPathSegment lastSegment, string commandString, SvgConverter conv)
        {
            if (!conv.TrySplitValues(commandString.Substring(1), out var values, true))
            {
                yield break;
            }

            int valuePos = 0;

            while (valuePos < values.Length)
            {
                var start = lastSegment?.End ?? Pnt2d.Origin;

                Pnt2d c1;
                Pnt2d end;
                if (char.ToLower(commandString[0]) == 'q')
                {
                    c1        = new Pnt2d(values[valuePos], values[valuePos + 1]);
                    end       = new Pnt2d(values[valuePos + 2], values[valuePos + 3]);
                    valuePos += 4;

                    if (char.IsLower(commandString[0]))
                    {
                        c1  += start;
                        end += start;
                    }
                    lastSegment = new SvgPathSegCurvetoQuadratic(start, c1, end);
                    yield return(lastSegment);
                }
                else if (char.ToLower(commandString[0]) == 't')
                {
                    end       = new Pnt2d(values[valuePos], values[valuePos + 1]);
                    valuePos += 2;

                    if (char.IsLower(commandString[0]))
                    {
                        end += start;
                    }

                    if (lastSegment is SvgPathSegCurvetoQuadratic lastSeg)
                    {
                        c1 = lastSeg.C1;
                    }
                    else
                    {
                        c1 = start;
                    }
                    lastSegment = new SvgPathSegCurvetoQuadratic(start, c1, end);
                    yield return(lastSegment);
                }
            }
        }
예제 #3
0
        //--------------------------------------------------------------------------------------------------

        internal static IEnumerable <SvgPathSegment> Create(string pathString, SvgConverter conv)
        {
            SvgPathSegment lastSegment  = null;
            SvgPathSegment firstSegment = null;
            int            next         = 0;

            while (next < pathString.Length)
            {
                int start = next;
                next = pathString.IndexOfAny(_PathCommands, start + 1);
                if (next == -1)
                {
                    next = pathString.Length;
                }

                IEnumerable <SvgPathSegment> newSegments = null;
                var commandString = pathString.Substring(start, next - start);
                switch (char.ToLower(commandString[0]))
                {
                case 'm':
                    newSegments = SvgPathSegMoveto.Create(lastSegment, commandString, conv);
                    break;

                case 'l':
                case 'h':
                case 'v':
                    newSegments = SvgPathSegLineto.Create(lastSegment, commandString, conv);
                    break;

                case 'c':
                case 's':
                    newSegments = SvgPathSegCurvetoCubic.Create(lastSegment, commandString, conv);
                    break;

                case 'q':
                case 't':
                    newSegments = SvgPathSegCurvetoQuadratic.Create(lastSegment, commandString, conv);
                    break;

                case 'a':
                    newSegments = SvgPathSegArc.Create(lastSegment, commandString, conv);
                    break;

                case 'z':
                    lastSegment = SvgPathSegClosePath.Create(firstSegment, lastSegment);
                    yield return(lastSegment);

                    firstSegment = null;
                    continue;
                }

                if (newSegments == null)
                {
                    continue;
                }

                foreach (var segment in newSegments)
                {
                    if (firstSegment == null)
                    {
                        firstSegment = segment;
                    }
                    lastSegment = segment;
                    yield return(segment);
                }
            }
        }