Example #1
0
        public static IVertexSource CreatePath(String DFromSVGFile, double xOffset, double yOffset)
        {
            VertexStorage path = new VertexStorage();

            string[] splitOnSpace = DFromSVGFile.Split(' ');
            string[] splitOnComma;
            double   xc1, yc1, xc2, yc2, x, y;

            for (int i = 0; i < splitOnSpace.Length; i++)
            {
                switch (splitOnSpace[i++])
                {
                case "M":
                {
                    splitOnComma = splitOnSpace[i].Split(',');
                    double.TryParse(splitOnComma[0], NumberStyles.Number, null, out x);
                    double.TryParse(splitOnComma[1], NumberStyles.Number, null, out y);
                    path.MoveTo(x, y + yOffset);
                }
                break;

                case "L":
                {
                    splitOnComma = splitOnSpace[i].Split(',');
                    double.TryParse(splitOnComma[0], NumberStyles.Number, null, out x);
                    double.TryParse(splitOnComma[1], NumberStyles.Number, null, out y);
                    path.LineTo(x, y + yOffset);
                }
                break;

                case "C":
                {
                    splitOnComma = splitOnSpace[i++].Split(',');
                    double.TryParse(splitOnComma[0], NumberStyles.Number, null, out xc1);
                    double.TryParse(splitOnComma[1], NumberStyles.Number, null, out yc1);

                    splitOnComma = splitOnSpace[i++].Split(',');
                    double.TryParse(splitOnComma[0], NumberStyles.Number, null, out xc2);
                    double.TryParse(splitOnComma[1], NumberStyles.Number, null, out yc2);

                    splitOnComma = splitOnSpace[i].Split(',');
                    double.TryParse(splitOnComma[0], NumberStyles.Number, null, out x);
                    double.TryParse(splitOnComma[1], NumberStyles.Number, null, out y);
                    path.curve4(xc1, yc1 + yOffset, xc2, yc2 + yOffset, x, y + yOffset);
                }
                break;

                case "z":
                    if (i < splitOnSpace.Length)
                    {
                        throw new Exception();
                    }
                    break;

                default:
                    throw new NotImplementedException();
                }
            }

            path.arrange_orientations_all_paths(MatterHackers.Agg.ShapePath.FlagsAndCommand.FlagCW);
            VertexSourceApplyTransform flipped = new VertexSourceApplyTransform(path, Affine.NewScaling(1, -1));

            return(flipped);
        }
Example #2
0
 public void Curve4(float x1, float y1, float x2, float y2, float x3, float y3)
 {
     vertexStorage.curve4(x1, y1, x2, y2, x3, y3);
 }