Esempio n. 1
0
        public int CompareTo(Object o)
        {
            int result = 0;

            if (o is IShapeData)
            {
                IShapeData co = (IShapeData)o;
                if (this.StartPoint != co.StartPoint)
                {
                    result = this.StartPoint.CompareTo(co.StartPoint);
                }
                else if (this.EndPoint != co.EndPoint)
                {
                    result = this.EndPoint.CompareTo(co.EndPoint);
                }
                else if (o is QuadBezier)
                {
                    QuadBezier cb = (QuadBezier)o;
                    if (this.Control != cb.Control)
                    {
                        result = this.Control.CompareTo(cb.Control);
                    }
                }
                else if (this.SegmentType != co.SegmentType)
                {
                    result = ((int)this.SegmentType) > ((int)co.SegmentType) ? 1 : -1;
                }
            }
            else
            {
                throw new ArgumentException("Objects being compared are not of the same type");
            }
            return(result);
        }
Esempio n. 2
0
        public static string GetSvgString(List <IShapeData> sh)
        {
            StringBuilder sb = new StringBuilder();

            sb.Append("M" + sh[0].StartPoint.GetSVG() + " ");

            Point  lastPoint = sh[0].StartPoint;
            String spc       = "";

            for (int i = 0; i < sh.Count; i++)
            {
                IShapeData sd = sh[i];
                if (lastPoint != sd.StartPoint)
                {
                    sb.Append(spc + "M" + sd.StartPoint.GetSVG());
                }
                switch (sd.SegmentType)
                {
                case SegmentType.Line:
                    sb.Append(spc + "L" + sd.EndPoint.GetSVG());
                    lastPoint = sd.EndPoint;
                    break;

                case SegmentType.CubicBezier:
                    CubicBezier cb = (CubicBezier)sd;
                    sb.Append(spc + "C" + cb.Control0.GetSVG() + "," + cb.Control1.GetSVG() + "," + cb.Anchor1.GetSVG());
                    lastPoint = cb.EndPoint;
                    break;

                case SegmentType.QuadraticBezier:
                    QuadBezier qb = (QuadBezier)sd;
                    sb.Append(spc + "Q" + qb.Control.GetSVG() + "," + qb.Anchor1.GetSVG());
                    lastPoint = qb.EndPoint;
                    break;
                }

                spc = " ";
            }

            return(sb.ToString());
        }
Esempio n. 3
0
        public static void ParseSerializedShapeString(string s, List <IShapeData> data)
        {
            string[] ar = s.Split(spc, StringSplitOptions.RemoveEmptyEntries);

            for (int i = 0; i < ar.Length; i++)
            {
                switch (ar[i][0])
                {
                case 'L':
                    data.Add(Line.Deserialize(ar[i]));
                    break;

                case 'C':
                    data.Add(QuadBezier.Deserialize(ar[i]));
                    break;

                case 'Q':
                    data.Add(QuadBezier.Deserialize(ar[i]));
                    break;
                }
            }
        }
Esempio n. 4
0
        private List <GraphicsPath> GetPath(List <Vex.IShapeData> shapes, bool isFilled)
        {
            List <GraphicsPath> result = new List <GraphicsPath>();

            if (shapes.Count == 0)
            {
                return(result);
            }
            DDW.Vex.Point endPoint = shapes[0].EndPoint;
            GraphicsPath  gp       = new GraphicsPath();

            gp.FillMode = FillMode.Alternate;
            result.Add(gp);

            for (int i = 0; i < shapes.Count; i++)
            {
                Vex.IShapeData sd = shapes[i];

                if (sd.StartPoint != endPoint)
                {
                    if (isFilled)
                    {
                        gp.CloseFigure();
                    }
                    else
                    {
                        gp          = new GraphicsPath();
                        gp.FillMode = FillMode.Alternate;
                        result.Add(gp);
                    }
                }
                switch (sd.SegmentType)
                {
                case Vex.SegmentType.Line:
                    Vex.Line l = (Vex.Line)sd;
                    gp.AddLine(l.Anchor0.X, l.Anchor0.Y, l.Anchor1.X, l.Anchor1.Y);
                    break;

                case Vex.SegmentType.CubicBezier:
                    Vex.CubicBezier cb = (Vex.CubicBezier)sd;
                    gp.AddBezier(
                        cb.Anchor0.X, cb.Anchor0.Y,
                        cb.Control0.X, cb.Control0.Y,
                        cb.Control1.X, cb.Control1.Y,
                        cb.Anchor1.X, cb.Anchor1.Y);
                    break;

                case Vex.SegmentType.QuadraticBezier:
                    Vex.QuadBezier  qb  = (Vex.QuadBezier)sd;
                    Vex.CubicBezier qtc = qb.GetCubicBezier();
                    gp.AddBezier(
                        qtc.Anchor0.X, qtc.Anchor0.Y,
                        qtc.Control0.X, qtc.Control0.Y,
                        qtc.Control1.X, qtc.Control1.Y,
                        qtc.Anchor1.X, qtc.Anchor1.Y);
                    break;
                }
                endPoint = sd.EndPoint;
            }
            if (isFilled)
            {
                gp.CloseFigure();
            }
            return(result);
        }
Esempio n. 5
0
		private void ParseShapeWithStyle(ShapeWithStyle tag)
		{
			List<FillStyle> curFillStyles = ParseFillStyleArray(tag.FillStyles);
			List<StrokeStyle> curStrokeStyles = ParseLineStyleArray(tag.LineStyles);
			int curX = 0;
			int curY = 0;
			int curFill0 = 0;
			int curFill1 = 0;
			int curStroke = 0;

			List<FillPath> fillPaths = new List<FillPath>();
			List<StrokePath> strokePaths = new List<StrokePath>();

			foreach (IShapeRecord o in tag.ShapeRecords)
			{
				if (o is StraightEdgeRecord)
				{
					StraightEdgeRecord r = (StraightEdgeRecord)o;
					Line line = new Line(
						new Point(curX / twips, curY / twips),
						new Point((curX + r.DeltaX) / twips, (curY + r.DeltaY) / twips));

					if (curFill0 > 0)
					{
						if (curFill0 > curFillStyles.Count)
						{
							fillPaths.Add(new FillPath(new DDW.Vex.SolidFill(new Color(255, 0, 0)), line));
						}
						else
						{
							fillPaths.Add(new FillPath(curFillStyles[curFill0 - 1], line));
						}
					}
					if (curFill1 > 0)
					{
						if (curFill1 > curFillStyles.Count)
						{
							fillPaths.Add(new FillPath(new DDW.Vex.SolidFill(new Color(255, 0, 0)), line));
						}
						else
						{
							fillPaths.Add(new FillPath(curFillStyles[curFill1 - 1], line));
						}
					}
					if (curStroke > 0)
					{
						strokePaths.Add(new StrokePath(curStrokeStyles[curStroke - 1], line));
					}

					curX += r.DeltaX;
					curY += r.DeltaY;
				}
				else if (o is CurvedEdgeRecord)
				{
					CurvedEdgeRecord r = (CurvedEdgeRecord)o;
					Point a0 = new Point(curX / twips, curY / twips);
					Point c0 = new Point((curX + r.ControlX) / twips, (curY + r.ControlY) / twips);
					curX += r.ControlX;
					curY += r.ControlY;
					Point a1 = new Point((curX + r.AnchorX) / twips, (curY + r.AnchorY) / twips);
					curX += r.AnchorX;
					curY += r.AnchorY;
					QuadBezier bez = new QuadBezier(a0, c0, a1);

					if (curFill0 > 0)
					{
						if (curFill1 > curFillStyles.Count)
						{
							fillPaths.Add(new FillPath(new DDW.Vex.SolidFill(new Color(255, 0, 0)), bez));
						}
						else
						{
							fillPaths.Add(new FillPath(curFillStyles[curFill0 - 1], bez));
						}
					}
					if (curFill1 > 0)
					{
						if (curFill1 > curFillStyles.Count)
						{
							fillPaths.Add( new FillPath( new DDW.Vex.SolidFill(new Color(255,0,0)), bez) );
						}
						else
						{
							fillPaths.Add(new FillPath(curFillStyles[curFill1 - 1], bez));
						}
					}
					if (curStroke > 0)
					{
						strokePaths.Add(new StrokePath(curStrokeStyles[curStroke - 1], bez)); 
					}
				}
				else if (o is StyleChangedRecord)
				{
					StyleChangedRecord scr = (StyleChangedRecord)o;
					if (scr.HasMove)
					{
						curX = scr.MoveDeltaX;
						curY = scr.MoveDeltaY;
					}

					if (scr.HasFillStyle0)
					{
						curFill0 = (int)scr.FillStyle0;
					}
					if (scr.HasFillStyle1)
					{
						curFill1 = (int)scr.FillStyle1;
					}
					if (scr.HasLineStyle)
					{

						curStroke = (int)scr.LineStyle;
					}
					if (scr.HasNewStyles)
					{
						ProcessPaths(fillPaths, strokePaths);
						fillPaths.Clear();
						strokePaths.Clear();

						curFillStyles = ParseFillStyleArray(scr.FillStyles);
						curStrokeStyles = ParseLineStyleArray(scr.LineStyles);
					}
				}
				else if (o is EndShapeRecord)
				{
					// end
				}
			}
			ProcessPaths(fillPaths, strokePaths);
		}