Example #1
0
        bool IsSamAsLast(VectorSegment seg)
        {
            if (lastSegment == null)
            {
                return(false);
            }

            if (lastSegment is VectorMoveSegment && seg is VectorLineSegment)
            {
                return(true);
            }

            return(lastSegment.GetType().Equals(seg.GetType()));
        }
Example #2
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;
        }
Example #3
0
 void AddSegment(VectorSegment seg)
 {
     segments.Add(seg);
 }