public static void PaintResults(Graphics aAreaForPainting, ResultGraphics aResultGraphics) { if (aResultGraphics != null && aResultGraphics.m_Polygons != null && aResultGraphics.m_Polygons.Count > 0) { Pen LinePen = new Pen(aResultGraphics.m_Polygons[0].m_Color); foreach (ResultPolygon Poly in aResultGraphics.m_Polygons) { if (!LinePen.Color.Equals(Poly.m_Color)) { LinePen.Color = Poly.m_Color; } aAreaForPainting.DrawLines(LinePen, Poly.m_Points); } } }
public static ResultGraphics Parse(string aSvgData, Rectangle aDisplayControlRect) { ResultGraphics G = new ResultGraphics(); G.m_OrigSvgData = aSvgData; // Parsing ViewBox size from the following node: viewBox="0 0 1280 1024" int viewBoxIndex = aSvgData.IndexOf("viewBox=\""); if (viewBoxIndex > 0) { Match VBM = m_RegexpViewBox.Match(aSvgData, viewBoxIndex); if (VBM.Groups.Count > 4) { G.m_ViewBoxSize = new Size(Int32.Parse(VBM.Groups[3].Value), Int32.Parse(VBM.Groups[4].Value)); } } double Zoom; Rectangle GraphicRect = Gui.FitImageInControl(G.m_ViewBoxSize, aDisplayControlRect, out Zoom); Point GraphicShift = new Point((aDisplayControlRect.Width - GraphicRect.Width) / 2, (aDisplayControlRect.Height - GraphicRect.Height) / 2); //If there is only image but no decoded result we don't want to parse out the coordinates int dataLength = aSvgData.Length; int pointsIndex = aSvgData.IndexOf("points", 0, dataLength); int colorIndex = aSvgData.IndexOf("stroke=\"#", 0, dataLength); int startIndex; int endIndex; string coordsString; string[] coordsArray; //parsing one or more polygons while (pointsIndex != -1) { ResultPolygon Polygon = new ResultPolygon(); //parsing polygon color colorIndex = aSvgData.IndexOf("stroke=\"#", colorIndex, dataLength - colorIndex); if (colorIndex >= 0) { try { uint ColorValue = UInt32.Parse(aSvgData.Substring(colorIndex + 9, 6), System.Globalization.NumberStyles.HexNumber); Polygon.m_Color = UIntToColor(ColorValue); colorIndex += 9; } catch { } } //parsing polygon points List <Point> Points = new List <Point>(); startIndex = aSvgData.IndexOf("points", pointsIndex, dataLength - pointsIndex) + 8; endIndex = aSvgData.IndexOf('"', startIndex, dataLength - startIndex) - 1; coordsString = aSvgData.Substring(startIndex, endIndex - startIndex); coordsArray = coordsString.Split(' ', ','); Point LastPoint = new Point(); for (int i = 0; i < coordsArray.Length; i += 2) { int PointX = (int)Math.Round(Convert.ToInt32(coordsArray[i + 0]) * Zoom) + GraphicShift.X; int PointY = (int)Math.Round(Convert.ToInt32(coordsArray[i + 1]) * Zoom) + GraphicShift.Y; LastPoint = new Point(PointX, PointY); Points.Add(LastPoint); } //Adding the first point twice makes drawing easier (see: Graphics.DrawLines) if (Points.Count > 0) { Points.Add(Points[0]); } Polygon.Set(Points.ToArray()); G.m_Polygons.Add(Polygon); pointsIndex = aSvgData.IndexOf("points", pointsIndex + 1, dataLength - pointsIndex - 1); } return(G); }