Example #1
0
		static public int parse_lion(PathStorage path, RGBA_Bytes[] 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] = RGBA_Bytes.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;
		}