Exemple #1
0
        internal void ImportPath(VectorPath p)
        {
            segments.Clear();
            polygons = null;

            BeginPath();

            Marca    = p.Document.Marca;
            Modelo   = p.Document.Modelo;
            Ano      = p.Document.Ano;
            NomePeca = p.NomePeca;

            foreach (VectorSegment s in p.segments)
            {
                if (s is VectorMoveSegment)
                {
                    MoveTo(s.End.X, s.End.Y);
                }

                if (s is VectorLineSegment)
                {
                    LineTo(s.End.X, s.End.Y);
                }

                if (s is VectorCubicSegment)
                {
                    VectorCubicSegment c = (VectorCubicSegment)s;
                    CurveTo(c.End.X, c.End.Y, c.Control1.X, c.Control1.Y, c.Control2.X, c.Control2.Y);
                }

                if (s is VectorQuadraticSegment)
                {
                    VectorQuadraticSegment q = (VectorQuadraticSegment)s;
                    QCurveTo(q.End.X, q.End.Y, q.Control.X, q.Control.Y);
                }

                if (s is VectorCloseSegment)
                {
                    ClosePolygon();
                }
            }

            ClosePath();

            p.importCount++;

            source     = p;
            p.Imported = true;

            posx = p.posx + 100;
            posy = p.posy + 100;
            id   = p.Id;
        }
Exemple #2
0
        public void QCurveTo(float x, float y, float cx, float cy)
        {
            VectorQuadraticSegment c = new VectorQuadraticSegment();

            c.Start = new PointF(curX, curY);
            c.End   = new PointF(x, y);

            curX = x;
            curY = y;

            c.Control = new PointF(cx, cy);

            AddSegment(c);
        }
Exemple #3
0
        void WriteSvgSegment(StringBuilder sb, VectorSegment seg, float ppmx, float ppmy)
        {
            int sx, sy, ex, ey;

            Matrix mt = new Matrix();

            mt.Translate(posx, posy);
            mt.Rotate(angle);

            PointF[] pts = new PointF[] { seg.Start, seg.End };

            mt.TransformPoints(pts);

            sx = (int)Math.Round(pts[0].X * ppmx);
            sy = (int)Math.Round(pts[0].Y * ppmy);
            ex = (int)Math.Round(pts[1].X * ppmx);
            ey = (int)Math.Round(pts[1].Y * ppmy);

            if (seg is VectorMoveSegment)
            {
                sb.Append(" M");
                sb.AppendFormat("{0},{1}", ex, ey);
            }

            if (seg is VectorLineSegment)
            {
                if (!IsSamAsLast(seg))
                {
                    sb.Append(" L");
                }
                else
                {
                    sb.Append(" ");
                }

                sb.AppendFormat("{0},{1}", ex, ey);
            }

            if (seg is VectorCubicSegment)
            {
                if (!IsSamAsLast(seg))
                {
                    sb.Append(" C");
                }
                else
                {
                    sb.Append(" ");
                }

                VectorCubicSegment vc = (VectorCubicSegment)seg;
                int c1x, c1y, c2x, c2y;

                pts = new PointF[] { vc.Control1, vc.Control2 };

                mt.TransformPoints(pts);

                c1x = (int)Math.Round(pts[0].X * ppmx);
                c1y = (int)Math.Round(pts[0].Y * ppmy);
                c2x = (int)Math.Round(pts[1].X * ppmx);
                c2y = (int)Math.Round(pts[1].Y * ppmy);

                sb.AppendFormat("{0},{1} {2},{3} {4},{5}", c1x, c1y, c2x, c2y, ex, ey);
            }

            if (seg is VectorQuadraticSegment)
            {
                if (!IsSamAsLast(seg))
                {
                    sb.Append(" Q");
                }
                else
                {
                    sb.Append(" ");
                }

                VectorQuadraticSegment qc = (VectorQuadraticSegment)seg;
                int cx, cy;

                pts = new PointF[] { qc.Control };

                cx = (int)Math.Round(pts[0].X * ppmx);
                cy = (int)Math.Round(pts[0].Y * ppmy);

                sb.AppendFormat("{0},{1} {2},{3}", cx, cy, ex, ey);
            }

            if (seg is VectorCloseSegment)
            {
                sb.Append(" Z");
            }

            lastSegment = seg;
        }