Пример #1
0
    // Make a tree of splitters, controlled by the string in sp

    static public SplitContainer SplitterTreeMakeFromCtrlString(BaseUtils.StringParser sp,
                                                                Func <Orientation, int, SplitContainer> MakeSC,
                                                                Func <string, Control> MakeNode, int lvl)
    {
        char tomake;

        if (sp.SkipUntil(new char[] { 'H', 'V', 'U' }) && (tomake = sp.GetChar()) != 'U')
        {
            sp.IsCharMoveOn('(');   // ignore (

            SplitContainer sc = MakeSC(tomake == 'H' ? Orientation.Horizontal : Orientation.Vertical, lvl);

            double percent = sp.NextDouble(",") ?? 0.5;
            sc.SplitterDistance(percent);

            SplitContainer one = SplitterTreeMakeFromCtrlString(sp, MakeSC, MakeNode, lvl + 1);

            if (one == null)
            {
                string para = sp.PeekChar() == '\'' ? sp.NextQuotedWord() : "";
                sc.Panel1.Controls.Add(MakeNode(para));
            }
            else
            {
                sc.Panel1.Controls.Add(one);
            }

            SplitContainer two = SplitterTreeMakeFromCtrlString(sp, MakeSC, MakeNode, lvl + 1);

            if (two == null)
            {
                string para = sp.PeekChar() == '\'' ? sp.NextQuotedWord() : "";
                sc.Panel2.Controls.Add(MakeNode(para));
            }
            else
            {
                sc.Panel2.Controls.Add(two);
            }

            return(sc);
        }
        else
        {
            return(null);
        }
    }
Пример #2
0
        static public List <PointF> ReadSVGPath(string s)              // simple L,M,Z path only
        {
            StringParser  sp     = new StringParser(s);
            List <PointF> points = new List <PointF>();

            while (!sp.IsEOL)
            {
                char ctrl = sp.GetChar(true);
                ctrl = char.ToLower(ctrl);
                if (ctrl == 'z')
                {
                    if (points.Count > 0)
                    {
                        points.Add(points[0]);
                    }
                    else
                    {
                        return(null);
                    }
                }
                else if (ctrl == 'm' || ctrl == 'l')
                {
                    if ((ctrl == 'm' && points.Count == 0) || (ctrl == 'l'))
                    {
                        double?x = sp.NextDoubleComma(", ");
                        double?y = sp.NextDouble();

                        if (x.HasValue && y.HasValue)
                        {
                            points.Add(new PointF((float)x, (float)y));
                        }
                        else
                        {
                            return(null);
                        }
                    }
                }
                else
                {
                    return(null);
                }
            }

            return(points);
        }