static public int parse_lion(VertexStorage path, Color[] colors, int[] path_idx) { // Parse the lion and then detect its bounding // box and arrange polygons orientations (make all polygons // oriented clockwise or counterclockwise) int npaths = 0; string[] splitOnNL = g_lion.Split('\n'); foreach (string LineString in splitOnNL) { int c; if (LineString.Length > 0 && LineString[0] != 'M' && Int32.TryParse(LineString, NumberStyles.HexNumber, null, out c)) { // New color. Every new color creates new path in the path object. path.ClosePolygon(); colors[npaths] = Color.rgb8_packed((int)c); path_idx[npaths] = path.start_new_path(); npaths++; } else { bool startedPoly = false; string[] splitOnSpace = LineString.Split(' '); for (int i = 0; i < splitOnSpace.Length; i++) { string[] splitOnComma = splitOnSpace[i].Split(','); if (splitOnComma.Length > 1) { double x = 0.0; double y = 0.0; double.TryParse(splitOnComma[0], NumberStyles.Number, null, out x); double.TryParse(splitOnComma[1], NumberStyles.Number, null, out y); if (!startedPoly) { startedPoly = true; path.ClosePolygon(); path.MoveTo(x, y); } else { path.LineTo(x, y); } } } } } path.arrange_orientations_all_paths(ShapePath.FlagsAndCommand.FlagCW); return(npaths); }
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); }