public void DrawStep(Graphics graphics, Font font, string word, int[] order) { var isClosed = false; var pen = new Pen(Color.Red); var brush = new SolidBrush(Color.Black); var path = new GraphicsPath(); var subPath = new GraphicsPath(); path.AddString(word, font.FontFamily, (int)font.Style, font.Size, new PointF(0, 0), StringFormat.GenericDefault); var iterator = new GraphicsPathIterator(path); var rect = path.GetBounds(); graphics.PageUnit = font.Unit; graphics.SmoothingMode = SmoothingMode.HighQuality; DrawGrid(graphics, rect); graphics.DrawPath(pen, path); for (var i = 0; i < iterator.SubpathCount; i++) { Thread.Sleep(1000); iterator.Rewind(); for (var j = 0; j < order[i]; j++) { iterator.NextSubpath(subPath, out isClosed); } graphics.FillPath(brush, subPath); } }
public static List <List <IntPoint> > ConvertToClipperPolygons(GraphicsPath path) { var Polygon = new List <IntPoint>(); var Polygons = new List <List <IntPoint> >(); var it = new GraphicsPathIterator(path); it.Rewind(); for (int i = 0; i < it.SubpathCount; i++) { bool isClosed; int startIndex; int endIndex; it.NextSubpath(out startIndex, out endIndex, out isClosed); Polygon.AddRange( path.PathPoints .Skip(startIndex) .Take((endIndex - startIndex) + 1) .Select(x => new IntPoint(Convert.ToInt64(x.X * Scale), Convert.ToInt64(x.Y * Scale))) ); Polygons.Add(new List <IntPoint>(Polygon)); Polygon.Clear(); } it.Dispose(); return(Polygons); }
public virtual void Rewind() { GraphicsPath path = new GraphicsPath(); path.AddLine(new Point(100, 100), new Point(400, 100)); path.AddLine(new Point(400, 200), new Point(10, 100)); path.StartFigure(); path.SetMarkers(); path.AddBezier(10, 10, 50, 250, 100, 5, 200, 280); path.StartFigure(); path.SetMarkers(); path.AddRectangle(new Rectangle(10, 20, 300, 400)); path.StartFigure(); path.SetMarkers(); path.AddLine(new Point(400, 400), new Point(400, 10)); GraphicsPathIterator iterator = new GraphicsPathIterator(path); int i; int j; iterator.NextMarker(out i, out j); iterator.NextMarker(out i, out j); iterator.Rewind(); iterator.NextMarker(out i, out j); Assert.AreEqual(0, i); Assert.AreEqual(3, j); }
public static void DrawStep(Graphics graphics, Font font, string word, int[] order) { var isClosed = false; var pen = new Pen(Color.Red); var brush = new SolidBrush(Color.Black); var subPath = new GraphicsPath(); var path = GetPath(font, word); var rect = path.GetBounds(); graphics.PageUnit = font.Unit; graphics.SmoothingMode = SmoothingMode.HighQuality; DrawGrid(graphics, rect); graphics.DrawPath(pen, path); var iterator = new GraphicsPathIterator(path); for (var i = 0; i < iterator.SubpathCount; i++) { Thread.Sleep(1000); iterator.Rewind(); for (var j = 0; j < order[i]; j++) { iterator.NextSubpath(subPath, out isClosed); } graphics.FillPath(brush, subPath); } }
// </snippet5> // Snippet for: M:System.Drawing.Drawing2D.GraphicsPathIterator.NextPathType(System.Byte@,System.Int32@,System.Int32@) // <snippet6> public void NextPathTypeExample(PaintEventArgs e) { // Create the GraphicsPath. GraphicsPath myPath = new GraphicsPath(); Point[] myPoints = { new Point(20, 20), new Point(120, 120), new Point(20, 120), new Point(20, 20) }; Rectangle myRect = new Rectangle(120, 120, 100, 100); // Add 3 lines, a rectangle, and an ellipse. myPath.AddLines(myPoints); myPath.AddRectangle(myRect); myPath.AddEllipse(220, 220, 100, 100); // List all of the path points to the screen. ListPathPoints(e, myPath, null, 20, 1); // Create a GraphicsPathIterator. GraphicsPathIterator myPathIterator = new GraphicsPathIterator(myPath); // Rewind the Iterator. myPathIterator.Rewind(); // Iterate the subpaths and types, and list the results to // the screen. int i, j = 20; int mySubPaths, subPathStartIndex, subPathEndIndex; Boolean IsClosed; byte subPathPointType; int pointTypeStartIndex, pointTypeEndIndex, numPointsFound; Font myFont = new Font("Arial", 8); SolidBrush myBrush = new SolidBrush(Color.Black); j = 20; for (i = 0; i < 3; i++) { mySubPaths = myPathIterator.NextSubpath( out subPathStartIndex, out subPathEndIndex, out IsClosed); numPointsFound = myPathIterator.NextPathType( out subPathPointType, out pointTypeStartIndex, out pointTypeEndIndex); e.Graphics.DrawString( "SubPath: " + i + " Points Found: " + numPointsFound.ToString() + " Type of Points: " + subPathPointType.ToString(), myFont, myBrush, 200, j); j += 20; } // List the total number of path points to the screen. ListPathPoints(e, myPath, myPathIterator, 200, 2); }
private GraphicsPath GetPathForIndex(int index) { var path = new GraphicsPath(); GraphicsPathIterator iterator = new GraphicsPathIterator(_OriginalPath); iterator.Rewind(); for (int i = 0; i <= index; i++) { iterator.NextMarker(path); } return(path); }
public virtual void CopyData() { GraphicsPath path = new GraphicsPath(); path.AddLine(new Point(100, 100), new Point(400, 100)); path.AddLine(new Point(400, 200), new Point(10, 100)); path.StartFigure(); path.SetMarkers(); path.AddRectangle(new Rectangle(10, 20, 300, 400)); path.StartFigure(); path.SetMarkers(); path.AddLine(new Point(400, 400), new Point(400, 10)); GraphicsPathIterator pathIterator = new GraphicsPathIterator(path); pathIterator.Rewind(); PointF [] actualPoints = new PointF [10]; byte [] actualTypes = new byte [10]; pathIterator.CopyData(ref actualPoints, ref actualTypes, 0, 9); PointF [] expectedPoints = new PointF [] { new PointF(100f, 100f), new PointF(400f, 100f), new PointF(400f, 200f), new PointF(10f, 100f), new PointF(10f, 20f), new PointF(310f, 20f), new PointF(310f, 420f), new PointF(10f, 420f), new PointF(400f, 400f), new PointF(400f, 10f) }; for (int i = 0; i < expectedPoints.Length; i++) { DrawingTest.AssertAlmostEqual(expectedPoints [i], actualPoints [i]); } byte [] expectedTypes = new byte [] { (byte)PathPointType.Start, (byte)PathPointType.Line, (byte)PathPointType.Line, (byte)(PathPointType.Line | PathPointType.PathMarker), (byte)PathPointType.Start, (byte)PathPointType.Line, (byte)PathPointType.Line, (byte)(PathPointType.Line | PathPointType.CloseSubpath | PathPointType.PathMarker), (byte)PathPointType.Start, (byte)PathPointType.Line }; for (int i = 0; i < expectedTypes.Length; i++) { Assert.AreEqual(expectedTypes [i], actualTypes [i]); } }
private void GraphicsPathIterator_Paint(object sender, System.Windows.Forms.PaintEventArgs e) { // Get the Graphics object Graphics g = e.Graphics; // Create a Rectangle Rectangle rect = new Rectangle(50, 50, 100, 50); // Create a Graphics path GraphicsPath path = new GraphicsPath(); PointF[] ptsArray = { new PointF(20, 20), new PointF(60, 12), new PointF(100, 20) }; // Add a curve, rectangle, ellipse, and a line path.AddCurve(ptsArray); path.AddRectangle(rect); rect.Y += 60; path.AddEllipse(rect); path.AddLine(120, 50, 220, 100); // Draw path g.DrawPath(Pens.Blue, path); // Create a Graphics path iterator GraphicsPathIterator pathIterator = new GraphicsPathIterator(path); // Display total points and sub paths string str = "Total points = " + pathIterator.Count.ToString(); str += ", Sub paths = " + pathIterator.SubpathCount.ToString(); MessageBox.Show(str); // rewind pathIterator.Rewind(); // Read all subpaths and their properties for (int i = 0; i < pathIterator.SubpathCount; i++) { int strtIdx, endIdx; bool bClosedCurve; pathIterator.NextSubpath(out strtIdx, out endIdx, out bClosedCurve); str = "Start Index = " + strtIdx.ToString() + ", End Index = " + endIdx.ToString() + ", IsClosed = " + bClosedCurve.ToString(); MessageBox.Show(str); } }
private void btnSave_Click(object sender, EventArgs e) { SaveFileDialog sfd = new SaveFileDialog(); sfd.InitialDirectory = Application.StartupPath + datapath.jogpath; sfd.Filter = "Jog paths (*.xml)|*.xml"; sfd.FileName = "JogPath.xml"; if (sfd.ShowDialog() == DialogResult.OK) { if (File.Exists(sfd.FileName)) { File.Delete(sfd.FileName); } XmlWriterSettings set = new XmlWriterSettings(); set.Indent = true; XmlWriter w = XmlWriter.Create(sfd.FileName, set); w.WriteStartDocument(); w.WriteStartElement("view"); w.WriteAttributeString("raster", nUDRaster.Value.ToString()); GraphicsPathIterator pathIterator = new GraphicsPathIterator(jogPath); pathIterator.Rewind(); // https://www.c-sharpcorner.com/UploadFile/mahesh/understanding-and-using-graphics-paths-in-gdi/ for (int i = 0; i < pathIterator.SubpathCount; i++) { int strIdx, endIdx; bool bClosedCurve; pathIterator.NextSubpath(out strIdx, out endIdx, out bClosedCurve); w.WriteStartElement("path"); w.WriteAttributeString("id", i.ToString()); for (int k = strIdx; k <= endIdx; k++) { w.WriteStartElement("pos"); w.WriteAttributeString("X", jogPath.PathPoints[k].X.ToString().Replace(',', '.')); w.WriteAttributeString("Y", jogPath.PathPoints[k].Y.ToString().Replace(',', '.')); w.WriteEndElement(); } w.WriteEndElement(); } w.WriteEndElement(); w.Close(); } }
/// <summary> /// Gets the key associated with the region at the given point. /// </summary> /// <param name="point">The Point to look for a region.</param> /// <returns>The object tag if point is within a region, otherwise null.</returns> public object GetRegionTag(Point point) { GraphicsPath pathTemp = new GraphicsPath(); GraphicsPathIterator pathIterator = new GraphicsPathIterator(paths); pathIterator.Rewind(); for (int i = 0; i < pathIterator.SubpathCount; i++) { pathIterator.NextMarker(pathTemp); if (pathTemp.IsVisible(point)) { return(pathTags[i]); } } return(null); // not found }
private int getActiveIndexAtPoint(Point point, out GraphicsPath origpath) { var path = new GraphicsPath(); origpath = new GraphicsPath(); GraphicsPathIterator iterator = new GraphicsPathIterator(_ScaledPath); GraphicsPathIterator iteratororig = new GraphicsPathIterator(_OriginalPath); iterator.Rewind(); iteratororig.Rewind(); for (int current = 0; current < iterator.SubpathCount; current++) { iterator.NextMarker(path); iteratororig.NextMarker(origpath); if (path.IsVisible(point, _Graphics)) { return(current); } } return(-1); }
public void GeneratePath(ref List pathlist, string str) { FontFamily fontFamily = new FontFamily(@"楷体_GB2312"); int fontSize = 512; GraphicsPath charPath = new GraphicsPath(); charPath.AddString(str, fontFamily, 0, fontSize, new PointF(0, 0), null); GraphicsPathIterator iterator; iterator = new GraphicsPathIterator(charPath); int count = iterator.SubpathCount; iterator.Rewind(); bool iscolse; for (int i = 0; i < count; i++) { GraphicsPath subpath = new GraphicsPath(); iterator.NextSubpath(subpath, out iscolse); pathlist.Add(subpath); } }
public void Rewind_Success() { using (GraphicsPath gp = new GraphicsPath()) using (GraphicsPath inner = new GraphicsPath()) { gp.AddLine(0, 1, 2, 3); gp.SetMarkers(); gp.StartFigure(); gp.AddLine(20, 21, 22, 23); gp.AddBezier(5, 6, 7, 8, 9, 10, 11, 12); using (GraphicsPathIterator gpi = new GraphicsPathIterator(gp)) { Assert.Equal(2, gpi.SubpathCount); Assert.Equal(2, gpi.NextMarker(gp)); Assert.Equal(6, gpi.NextMarker(gp)); Assert.Equal(0, gpi.NextMarker(gp)); gpi.Rewind(); Assert.Equal(8, gpi.NextMarker(gp)); Assert.Equal(0, gpi.NextMarker(gp)); } } }
/// <summary> /// returns a newly created graphics path with points distorted /// </summary> /// <returns>The distorted Graphics Path</returns> public GraphicsPath ApplyDistortion() { var it = new GraphicsPathIterator(_source); it.Rewind(); var Gp = new GraphicsPath(FillMode.Winding); var ReturnPath = new GraphicsPath(FillMode.Winding); for (var i = 0; i < it.SubpathCount; i++) { bool result; it.NextSubpath(Gp, out result); InjectPrecisionPoints(Gp); ReturnPath.AddPolygon(Gp.PathPoints.Select(p => _distortion.Distort(_source, p)).ToArray()); Gp.Reset(); } it.Dispose(); Gp.Dispose(); return(ReturnPath); }
private void btnExport_Click(object sender, EventArgs e) { Graphic.Init(Graphic.SourceTypes.CSV, "", null, null); Graphic.SetHeaderInfo("From Jog path creator"); Graphic.SetGeometry("Line"); GraphicsPathIterator pathIterator = new GraphicsPathIterator(jogPath); pathIterator.Rewind(); int pointcnt = 0; for (int i = 0; i < pathIterator.SubpathCount; i++) { int strIdx, endIdx; bool bClosedCurve; pathIterator.NextSubpath(out strIdx, out endIdx, out bClosedCurve); lastSet = jogPath.PathPoints[endIdx]; Graphic.SetPathId(i.ToString()); pointcnt = 0; for (int k = strIdx; k <= endIdx; k++) { if (pointcnt++ == 0) { Graphic.StartPath(new System.Windows.Point(jogPath.PathPoints[k].X, jogPath.PathPoints[k].Y)); } else { Graphic.AddLine(new System.Windows.Point(jogPath.PathPoints[k].X, jogPath.PathPoints[k].Y)); } } Graphic.StopPath(); } Graphic.CreateGCode(); joggcode = Graphic.GCode.ToString(); }
/// <summary> /// Given the points on this line decoration, this will cycle through and handle /// the drawing as dictated by this decoration. /// </summary> /// <param name="g"></param> /// <param name="path"></param> /// <param name="scaleWidth">The double scale width for controling markers</param> public void Draw(Graphics g, GraphicsPath path, double scaleWidth) { if (NumSymbols == 0) { return; } GraphicsPathIterator myIterator = new GraphicsPathIterator(path); myIterator.Rewind(); int start, end; bool isClosed; Size2D symbolSize = _symbol.GetSize(); Bitmap symbol = new Bitmap((int)symbolSize.Width, (int)symbolSize.Height); Graphics sg = Graphics.FromImage(symbol); _symbol.Draw(sg, new Rectangle(0, 0, (int)symbolSize.Width, (int)symbolSize.Height)); sg.Dispose(); Matrix oldMat = g.Transform; PointF[] points; if (path.PointCount == 0) { return; } try { points = path.PathPoints; } catch { return; } PointF offset; int count = 0; while (myIterator.NextSubpath(out start, out end, out isClosed) > 0) { count = count + 1; // First marker PointF startPoint = points[start]; PointF stopPoint = points[start + 1]; float angle = 0F; if (_rotateWithLine) { angle = GetAngle(startPoint, stopPoint); } if (FlipFirst && !FlipAll) { FlipAngle(ref angle); } offset = GetOffset(startPoint, stopPoint); startPoint = new PointF(startPoint.X + offset.X, startPoint.Y + offset.Y); Matrix rotated = g.Transform; rotated.RotateAt(angle, startPoint); g.Transform = rotated; DrawImage(g, startPoint, symbol); g.Transform = oldMat; // Second marker if (NumSymbols > 1) { angle = 0F; if (_rotateWithLine) { angle = GetAngle(points[end - 1], points[end]); } if (FlipAll) { FlipAngle(ref angle); } offset = GetOffset(points[end - 1], points[end]); PointF endPoint = new PointF(points[end].X + offset.X, points[end].Y + offset.Y); rotated = g.Transform; rotated.RotateAt(angle, endPoint); g.Transform = rotated; DrawImage(g, endPoint, symbol); g.Transform = oldMat; } if (NumSymbols > 2) { double totalLength = GetLength(points, start, end); double span = totalLength / (NumSymbols - 1); for (int i = 1; i < NumSymbols - 1; i++) { DecorationSpot spot = GetPosition(points, span * i, start, end); angle = 0F; if (_rotateWithLine) { angle = GetAngle(spot.Before, spot.After); } offset = GetOffset(spot.Before, spot.After); PointF location = new PointF(spot.Position.X + offset.X, spot.Position.Y + offset.Y); if (FlipAll) { FlipAngle(ref angle); } rotated = g.Transform; rotated.RotateAt(angle, location); g.Transform = rotated; DrawImage(g, location, symbol); g.Transform = oldMat; } } } }
private void DrawMarker(Graphics g, GraphicsPath path, double scaleWidth) { if (Marker == null) { return; } if (DashButtons == null || DashButtons.Length <= 1) { return; } GraphicsPathIterator myIterator = new GraphicsPathIterator(path); myIterator.Rewind(); int start, end; bool isClosed; Size2D symbolSize = Marker.GetSize(); Bitmap symbol = new Bitmap((int)symbolSize.Width, (int)symbolSize.Height); using (Graphics sg = Graphics.FromImage(symbol)) { Marker.Draw(sg, new Rectangle(0, 0, symbol.Width, symbol.Height)); } Matrix oldMat = g.Transform; PointF[] points; if (path.PointCount == 0) { return; } try { points = path.PathPoints; } catch { return; } while (myIterator.NextSubpath(out start, out end, out isClosed) > 0) { double totalLength = GetLength(points, start, end); PointF startPoint = points[start]; PointF endPoint = points[end]; double totalUsedLength = 0; if (DashButtons.Length == 2) { bool dash = DashButtons[0]; if (!dash) { totalUsedLength = (float)(totalLength / 2); double usedLength = 0; for (int i = start; i < end; i++) { startPoint = points[i]; endPoint = points[i + 1]; double segmentLength = Math.Sqrt(Math.Pow(endPoint.X - startPoint.X, 2) + Math.Pow(endPoint.Y - startPoint.Y, 2)); if (usedLength + segmentLength > totalUsedLength) { if (segmentLength >= symbol.Width / 2) // 线长度大于点符号宽度的一半才绘制 { double length = totalUsedLength - usedLength; PointF location = GetPoint(startPoint, endPoint, length); DrawImage(g, startPoint, endPoint, location, symbol); } break; } usedLength += segmentLength; } } } else { int k = 0; for (int i = start; i < end; i++) { startPoint = points[i]; endPoint = points[i + 1]; double segmentLength = Math.Sqrt(Math.Pow(endPoint.X - startPoint.X, 2) + Math.Pow(endPoint.Y - startPoint.Y, 2)); double usedLength = 0; while (totalUsedLength < totalLength && usedLength < segmentLength) { if (k == DashButtons.Length) { k = 0; } bool dash = DashButtons[k]; if (!dash) { PointF location = GetPoint(startPoint, endPoint, usedLength); DrawImage(g, startPoint, endPoint, location, symbol); } totalUsedLength++; usedLength++; k++; } } } } }
// </snippet1> // Snippet for: M:System.Drawing.Drawing2D.GraphicsPathIterator.Enumerate(System.Drawing.PointF[]@,System.Byte[]@) // <snippet2> public void EnumerateExample(PaintEventArgs e) { GraphicsPath myPath = new GraphicsPath(); Point[] myPoints = { new Point(20, 20), new Point(120, 120), new Point(20, 120), new Point(20, 20) }; Rectangle myRect = new Rectangle(120, 120, 100, 100); myPath.AddLines(myPoints); myPath.AddRectangle(myRect); myPath.AddEllipse(220, 220, 100, 100); // Get the total number of points for the path, and arrays of // the points and types. int myPathPointCount = myPath.PointCount; PointF[] myPathPoints = myPath.PathPoints; byte[] myPathTypes = myPath.PathTypes; // Set up variables for listing the array of points on the left // side of the screen. int i; float j = 20; Font myFont = new Font("Arial", 8); SolidBrush myBrush = new SolidBrush(Color.Black); // List the set of points and types and types to the left side // of the screen. e.Graphics.DrawString("Original Data", myFont, myBrush, 20, j); j += 20; for (i = 0; i < myPathPointCount; i++) { e.Graphics.DrawString(myPathPoints[i].X.ToString() + ", " + myPathPoints[i].Y.ToString() + ", " + myPathTypes[i].ToString(), myFont, myBrush, 20, j); j += 20; } // Create a GraphicsPathIterator for myPath. GraphicsPathIterator myPathIterator = new GraphicsPathIterator(myPath); myPathIterator.Rewind(); PointF[] points = new PointF[myPathIterator.Count]; byte[] types = new byte[myPathIterator.Count]; int numPoints = myPathIterator.Enumerate(ref points, ref types); // Draw the set of copied points and types to the screen. j = 20; e.Graphics.DrawString("Copied Data", myFont, myBrush, 200, j); j += 20; for (i = 0; i < points.Length; i++) { e.Graphics.DrawString("Point: " + i + ", " + "Value: " + points[i].ToString() + ", " + "Type: " + types[i].ToString(), myFont, myBrush, 200, j); j += 20; } }
public List <Polygon <Vector3> > GetTextPolygons(string text) { Dictionary <int, Polygon <Vector3> > letterPolygons = new Dictionary <int, Polygon <Vector3> >(); using (Bitmap bmp = new Bitmap(400, 400)) using (GraphicsPath gp = new GraphicsPath()) using (Graphics g = Graphics.FromImage(bmp)) using (Font f = new Font("Calibri", 40f)) { //g.ScaleTransform(4, 4); gp.AddString(text, f.FontFamily, 0, 40f, new Point(0, 0), StringFormat.GenericDefault); g.DrawPath(Pens.Gray, gp); gp.Flatten(new Matrix(), 0.1f); // <<== * //g.DrawPath(Pens.DarkSlateBlue, gp); //gp.SetMarkers(); using (GraphicsPathIterator gpi = new GraphicsPathIterator(gp)) { gpi.Rewind(); var triangulation = new TriangulationList <Vector3>(); using (GraphicsPath gsubPath = new GraphicsPath()) { // Read all subpaths and their properties for (int i = 0; i < gpi.SubpathCount; i++) { gpi.NextSubpath(gsubPath, out bool bClosedCurve); if (!bClosedCurve) { _logger.LogWarning("Unclosed text shape. Skipping."); continue; } //Debug.Assert(bClosedCurve, "Unclosed character. That's not possible"); var currentRing = gsubPath.PathPoints.Select(p => new Vector3(p.X, p.Y, 0)).ToList(); List <int> childs = GetIncludedPolygons(currentRing, letterPolygons); List <int> parents = GetContainerPolygons(currentRing, letterPolygons); // contains other polygon ? if (childs.Any()) { Polygon <Vector3> newPoly = new Polygon <Vector3>(currentRing); foreach (var key in childs) { var child = letterPolygons[key]; letterPolygons.Remove(key); newPoly.InteriorRings.Add(child.ExteriorRing); } letterPolygons.Add(i, newPoly); } else if (parents.Any()) { Debug.Assert(parents.Count == 1); letterPolygons[parents.First()].InteriorRings.Add(currentRing); } else { letterPolygons.Add(i, new Polygon <Vector3>(currentRing)); } // triangulation += _meshService.Tesselate(currentLetterPoints, currentLetterPointsInt); gsubPath.Reset(); } } } } return(letterPolygons.Values.ToList()); }
public void NextSubpathExample2(PaintEventArgs e) { // Create a graphics path. GraphicsPath myPath = new GraphicsPath(); // Set up primitives to add to myPath. Point[] myPoints = { new Point(20, 20), new Point(120, 120), new Point(20, 120), new Point(20, 20) }; Rectangle myRect = new Rectangle(120, 120, 100, 100); // Add 3 lines, a rectangle, an ellipse, and 2 markers. myPath.AddLines(myPoints); //myPath.SetMarkers(); myPath.AddRectangle(myRect); myPath.SetMarkers(); myPath.AddEllipse(220, 220, 100, 100); // Get the total number of points for the path, // and the arrays of the points and types. int myPathPointCount = myPath.PointCount; PointF[] myPathPoints = myPath.PathPoints; byte[] myPathTypes = myPath.PathTypes; // Set up variables for listing all of the path's // points to the screen. int i; float j = 20; Font myFont = new Font("Arial", 8); SolidBrush myBrush = new SolidBrush(Color.Black); // List the values of all the path points and types to the screen. for (i = 0; i < myPathPointCount; i++) { e.Graphics.DrawString(myPathPoints[i].X.ToString() + ", " + myPathPoints[i].Y.ToString() + ", " + myPathTypes[i].ToString(), myFont, myBrush, 20, j); j += 20; } // Create a GraphicsPathIterator for myPath. GraphicsPathIterator myPathIterator = new GraphicsPathIterator(myPath); // Rewind the iterator. myPathIterator.Rewind(); // Create the GraphicsPath section. GraphicsPath myPathSection = new GraphicsPath(); // Iterate to the 3rd subpath and list the number of points therein // to the screen. int subpathPoints; bool IsClosed2; // Iterate to the third subpath. subpathPoints = myPathIterator.NextSubpath( myPathSection, out IsClosed2); subpathPoints = myPathIterator.NextSubpath( myPathSection, out IsClosed2); subpathPoints = myPathIterator.NextSubpath( myPathSection, out IsClosed2); // Write the number of subpath points to the screen. e.Graphics.DrawString("Subpath: 3" + " Num Points: " + subpathPoints.ToString(), myFont, myBrush, 200, 20); }
//public override void Draw(Graphics g, ToControlPositionDelegate angleOf) //{ // if (!IsVisible) return; // SizeF labelSize = g.MeasureString(Label, LabelFont); // float shift = (float)(0.5 * Math.Max(Math.Abs(labelSize.Width * COS(Rotation)), Math.Abs(labelSize.Height * SIN(Rotation)))); // PointF displayCenter = angleOf(Distance, Angle, shift); // RectangleF rect = new RectangleF(displayCenter.X - labelSize.Width / 2f, displayCenter.Y - labelSize.Height / 2f, labelSize.Width, labelSize.Height); // if (Rotation == 0) // { // if (IsFilled) // g.FillRectangle(TheBrush, rect); // if (IsBordered) // g.DrawRectangle(ThePen, new Rectangle((int)(rect.X), (int)rect.Y, (int)rect.Width, (int)rect.Height)); // g.DrawString(Label, LabelFont, FontBrush, rect); // } // else // { // GraphicsPath path = new GraphicsPath(); // if (IsFilled || IsBordered) // { // path.AddRectangle(rect); // path.SetMarkers(); // } // path.AddString(Label, LabelFont.FontFamily, (int)LabelFont.Style, 26, rect, StringFormat.GenericDefault); // Matrix translateMatrix = new Matrix(); // float rotation = Container.IsXReversed ? Rotation : 180 + Rotation; // translateMatrix.RotateAt((Container.IsClockwise ? Angle : -Angle) + rotation, displayCenter); // path.Transform(translateMatrix); // if (!IsBordered && !IsFilled) // { // g.FillPath(FontBrush, path); // } // else // { // // Create a GraphicsPathIterator for handPath. // GraphicsPathIterator pathIterator = new // GraphicsPathIterator(path); // // Rewind the iterator. // pathIterator.Rewind(); // // Create the GraphicsPath section. // GraphicsPath pathSection = new GraphicsPath(); // // to the screen. // int subpathPoints = pathIterator.NextMarker(pathSection); // drawPath(g, pathSection); // subpathPoints = pathIterator.NextMarker(pathSection); // g.FillPath(FontBrush, pathSection); // } // } //} public override void Draw(Graphics g, ToPhysicalAngleDelegate angleOf) { if (!IsVisible) { return; } SizeF labelSize = g.MeasureString(Label, LabelFont); //float shift = (float)(0.5 * Math.Max(Math.Abs(labelSize.Width * COS(Rotation)), Math.Abs(labelSize.Height * SIN(Rotation)))); float actualDistance = Distance * Container.UnitSize; float actualAngle = angleOf(Angle); float x = (float)Math.Round(actualDistance * COS(actualAngle), 4); float y = (float)Math.Round(actualDistance * SIN(actualAngle), 4); RectangleF rect = new RectangleF(x, y, labelSize.Width, labelSize.Height); if (Rotation == 0) { rect.X -= labelSize.Width / 2f; rect.Y -= labelSize.Height / 2f; if (IsFilled) { g.FillRectangle(TheBrush, rect); } if (IsBordered) { g.DrawRectangle(ThePen, new Rectangle((int)(rect.X), (int)rect.Y, (int)rect.Width, (int)rect.Height)); } g.DrawString(Label, LabelFont, FontBrush, rect); } else { rect.X -= labelSize.Width / 2f; rect.Y -= labelSize.Height / 2f; //float cos = COS(actualAngle); //float sin = SIN(actualAngle); //rect.X -= (cos >= 0 ? cos : -cos) * labelSize.Width / 2f; //rect.Y -= (sin >= 0 ? sin : -sin) * labelSize.Height / 2f; float rotation = actualAngle - Rotation; GraphicsPath path = new GraphicsPath(); if (IsFilled || IsBordered) { path.AddRectangle(rect); path.SetMarkers(); } path.AddString(Label, LabelFont.FontFamily, (int)LabelFont.Style, LabelFont.Size, rect, StringFormat.GenericDefault); Matrix translateMatrix = new Matrix(); translateMatrix.RotateAt(rotation, new PointF(x, y)); path.Transform(translateMatrix); if (!IsBordered && !IsFilled) { g.FillPath(FontBrush, path); } else { // Create a GraphicsPathIterator for handPath. GraphicsPathIterator pathIterator = new GraphicsPathIterator(path); // Rewind the iterator. pathIterator.Rewind(); // Create the GraphicsPath section. GraphicsPath pathSection = new GraphicsPath(); // to the screen. int subpathPoints = pathIterator.NextMarker(pathSection); drawPath(g, pathSection); subpathPoints = pathIterator.NextMarker(pathSection); g.FillPath(FontBrush, pathSection); } } /*/ * SizeF labelSize = g.MeasureString(Label, LabelFont); * float shift = (float)(0.5 * Math.Max(Math.Abs(labelSize.Width * COS(Rotation)), Math.Abs(labelSize.Height * SIN(Rotation)))); * * float actualDistance = Distance * Container.UnitSize + shift; * float actualAngle = angleOf(Angle); * float x = (float)Math.Round(actualDistance * COS(actualAngle), 4); * float y = (float)Math.Round(actualDistance * SIN(actualAngle), 4); * PointF displayCenter = new PointF(x, y); * * RectangleF rect = new RectangleF(displayCenter.X - labelSize.Width / 2f, displayCenter.Y - labelSize.Height / 2f, labelSize.Width, labelSize.Height); * * if (Rotation == 0) * { * if (IsFilled) * g.FillRectangle(TheBrush, rect); * * if (IsBordered) * g.DrawRectangle(ThePen, new Rectangle((int)(rect.X), (int)rect.Y, (int)rect.Width, (int)rect.Height)); * * g.DrawString(Label, LabelFont, FontBrush, rect); * } * else * { * GraphicsPath path = new GraphicsPath(); * * if (IsFilled || IsBordered) * { * path.AddRectangle(rect); * path.SetMarkers(); * } * * path.AddString(Label, LabelFont.FontFamily, (int)LabelFont.Style, 26, rect, StringFormat.GenericDefault); * * Matrix translateMatrix = new Matrix(); * * //float rotation = Container.IsXReversed ? Rotation : 180 + Rotation; * //translateMatrix.RotateAt((Container.IsClockwise ? Angle : -Angle) + rotation, displayCenter); * float rotation = actualAngle + Rotation; * translateMatrix.RotateAt(rotation, displayCenter); * * path.Transform(translateMatrix); * * if (!IsBordered && !IsFilled) * { * g.FillPath(FontBrush, path); * } * else * { * // Create a GraphicsPathIterator for handPath. * GraphicsPathIterator pathIterator = new * GraphicsPathIterator(path); * * // Rewind the iterator. * pathIterator.Rewind(); * * // Create the GraphicsPath section. * GraphicsPath pathSection = new GraphicsPath(); * * // to the screen. * int subpathPoints = pathIterator.NextMarker(pathSection); * * drawPath(g, pathSection); * * subpathPoints = pathIterator.NextMarker(pathSection); * * g.FillPath(FontBrush, pathSection); * } * } * //*/ }
/// <summary> /// Given the points on this line decoration, this will cycle through and handle /// the drawing as dictated by this decoration. /// </summary> /// <param name="g">The graphics object used for drawing.</param> /// <param name="path">The path of the line.</param> /// <param name="scaleWidth">The double scale width for controling markers</param> public void Draw(Graphics g, GraphicsPath path, double scaleWidth) { if (NumSymbols == 0) { return; } GraphicsPathIterator myIterator = new GraphicsPathIterator(path); myIterator.Rewind(); int start, end; bool isClosed; Size2D symbolSize = _symbol.GetSize(); Bitmap symbol = new Bitmap((int)symbolSize.Width, (int)symbolSize.Height); Graphics sg = Graphics.FromImage(symbol); _symbol.Draw(sg, new Rectangle(0, 0, (int)symbolSize.Width, (int)symbolSize.Height)); sg.Dispose(); Matrix oldMat = g.Transform; PointF[] points; if (path.PointCount == 0) { return; } try { points = path.PathPoints; } catch { return; } while (myIterator.NextSubpath(out start, out end, out isClosed) > 0) { if (NumSymbols == 1) { // single decoration spot if (_percentualPosition == 0) { // at start of the line DrawImage(g, points[start], points[start + 1], points[start], FlipFirst ^ FlipAll, symbol, oldMat); } else if (_percentualPosition == 100) { // at end of the line DrawImage(g, points[end - 1], points[end], points[end], FlipFirst ^ FlipAll, symbol, oldMat); } else { // somewhere in between start and end double totalLength = GetLength(points, start, end); double span = totalLength * _percentualPosition / 100; List <DecorationSpot> spot = GetPosition(points, span, start, end); if (spot.Count > 1) { DrawImage(g, spot[1].Before, spot[1].After, spot[1].Position, FlipFirst ^ FlipAll, symbol, oldMat); } } } else { // more than one decoration spot double totalLength = GetLength(points, start, end); double span = Math.Round(totalLength / (NumSymbols - 1), 4); List <DecorationSpot> spots = GetPosition(points, span, start, end); spots.Add(new DecorationSpot(points[end - 1], points[end], points[end])); // add the missing end point for (int i = 0; i < spots.Count; i++) { DrawImage(g, spots[i].Before, spots[i].After, spots[i].Position, i == 0 ? (FlipFirst ^ FlipAll) : FlipAll, symbol, oldMat); } } } }
// </snippet3> // Snippet for: M:System.Drawing.Drawing2D.GraphicsPathIterator.NextMarker(System.Drawing.Drawing2D.GraphicsPath) // <snippet4> public void NextMarkerExample2(PaintEventArgs e) { // Create a graphics path. GraphicsPath myPath = new GraphicsPath(); // Set up primitives to add to myPath. Point[] myPoints = { new Point(20, 20), new Point(120, 120), new Point(20, 120), new Point(20, 20) }; Rectangle myRect = new Rectangle(120, 120, 100, 100); // Add 3 lines, a rectangle, an ellipse, and 2 markers. myPath.AddLines(myPoints); myPath.SetMarkers(); myPath.AddRectangle(myRect); myPath.SetMarkers(); myPath.AddEllipse(220, 220, 100, 100); // Get the total number of points for the path, // and the arrays of the points and types. int myPathPointCount = myPath.PointCount; PointF[] myPathPoints = myPath.PathPoints; byte[] myPathTypes = myPath.PathTypes; // Set up variables for listing all the values of the path's // points to the screen. int i; float j = 20; Font myFont = new Font("Arial", 8); SolidBrush myBrush = new SolidBrush(Color.Black); // List the values for all of path points and types to // the left side of the screen. for (i = 0; i < myPathPointCount; i++) { e.Graphics.DrawString(myPathPoints[i].X.ToString() + ", " + myPathPoints[i].Y.ToString() + ", " + myPathTypes[i].ToString(), myFont, myBrush, 20, j); j += 20; } // Create a GraphicsPathIterator. GraphicsPathIterator myPathIterator = new GraphicsPathIterator(myPath); // Rewind the iterator. myPathIterator.Rewind(); // Create a GraphicsPath to receive a section of myPath. GraphicsPath myPathSection = new GraphicsPath(); // Retrieve and list the number of points contained in // the first marker to the right side of the screen. int markerPoints; markerPoints = myPathIterator.NextMarker(myPathSection); e.Graphics.DrawString("Marker: 1" + " Num Points: " + markerPoints.ToString(), myFont, myBrush, 200, 20); }
// </snippet7> // Snippet for: M:System.Drawing.Drawing2D.GraphicsPathIterator.NextSubpath(System.Int32@,System.Int32@,System.Boolean@) // <snippet8> private void NextSubpathExample(PaintEventArgs e) { // Create the GraphicsPath. GraphicsPath myPath = new GraphicsPath(); Point[] myPoints = { new Point(20, 20), new Point(120, 120), new Point(20, 120), new Point(20, 20) }; Rectangle myRect = new Rectangle(120, 120, 100, 100); // Add 3 lines, a rectangle, an ellipse, and 2 markers. myPath.AddLines(myPoints); myPath.AddRectangle(myRect); myPath.AddEllipse(220, 220, 100, 100); // Get the total number of points for the path, // and the arrays of the points and types. int myPathPointCount = myPath.PointCount; PointF[] myPathPoints = myPath.PathPoints; byte[] myPathTypes = myPath.PathTypes; // Set up variables for drawing the array of // points to the screen. int i; float j = 20; Font myFont = new Font("Arial", 8); SolidBrush myBrush = new SolidBrush(Color.Black); // Draw the set of path points and types to the screen. for (i = 0; i < myPathPointCount; i++) { e.Graphics.DrawString(myPathPoints[i].X.ToString() + ", " + myPathPoints[i].Y.ToString() + ", " + myPathTypes[i].ToString(), myFont, myBrush, 20, j); j += 20; } // Create a GraphicsPathIterator. GraphicsPathIterator myPathIterator = new GraphicsPathIterator(myPath); int myStartIndex; int myEndIndex; bool myIsClosed; // get the number of Subpaths. int numSubpaths = myPathIterator.NextSubpath(myPath, out myIsClosed); numSubpaths -= 1; // Rewind the Iterator. myPathIterator.Rewind(); // List the Subpaths to the screen. j = 20; for (i = 0; i < numSubpaths; i++) { myPathIterator.NextSubpath(out myStartIndex, out myEndIndex, out myIsClosed); e.Graphics.DrawString("Subpath " + i.ToString() + ": Start: " + myStartIndex.ToString() + " End: " + myEndIndex.ToString() + " IsClosed: " + myIsClosed.ToString(), myFont, myBrush, 200, j); j += 20; } // Draw the total number of Subpaths to the screen. j += 20; e.Graphics.DrawString("Number Subpaths = " + numSubpaths.ToString(), myFont, myBrush, 200, j); }
/// <summary> /// The main entry point for the application. /// </summary> /// // Snippet for: M:System.Drawing.Drawing2D.GraphicsPathIterator.CopyData(System.Drawing.PointF[]@,System.Byte[]@,System.Int32,System.Int32) // <snippet1> public void CopyDataExample(PaintEventArgs e) { // Create a graphics path. GraphicsPath myPath = new GraphicsPath(); // Set up a points array. Point[] myPoints = { new Point(20, 20), new Point(120, 120), new Point(20, 120), new Point(20, 20) }; // Create a rectangle. Rectangle myRect = new Rectangle(120, 120, 100, 100); // Add the points, rectangle, and an ellipse to the path. myPath.AddLines(myPoints); myPath.SetMarkers(); myPath.AddRectangle(myRect); myPath.SetMarkers(); myPath.AddEllipse(220, 220, 100, 100); // Get the total number of points for the path, and arrays of // the points and types. int myPathPointCount = myPath.PointCount; PointF[] myPathPoints = myPath.PathPoints; byte[] myPathTypes = myPath.PathTypes; // Set up variables for listing the array of points on the left // side of the screen. int i; float j = 20; Font myFont = new Font("Arial", 8); SolidBrush myBrush = new SolidBrush(Color.Black); // List the set of points and types and types to the left side // of the screen. for (i = 0; i < myPathPointCount; i++) { e.Graphics.DrawString(myPathPoints[i].X.ToString() + ", " + myPathPoints[i].Y.ToString() + ", " + myPathTypes[i].ToString(), myFont, myBrush, 20, j); j += 20; } // Create a GraphicsPathIterator for myPath and rewind it. GraphicsPathIterator myPathIterator = new GraphicsPathIterator(myPath); myPathIterator.Rewind(); // Set up the arrays to receive the copied data. PointF[] points = new PointF[myPathIterator.Count]; byte[] types = new byte[myPathIterator.Count]; int myStartIndex; int myEndIndex; // Increment the starting index to the second marker in the // path. myPathIterator.NextMarker(out myStartIndex, out myEndIndex); myPathIterator.NextMarker(out myStartIndex, out myEndIndex); // Copy all the points and types from the starting index to the // ending index to the points array and the types array // respectively. int numPointsCopied = myPathIterator.CopyData( ref points, ref types, myStartIndex, myEndIndex); // List the copied points to the right side of the screen. j = 20; int copiedStartIndex = 0; for (i = 0; i < numPointsCopied; i++) { copiedStartIndex = myStartIndex + i; e.Graphics.DrawString( "Point: " + copiedStartIndex.ToString() + ", Value: " + points[i].ToString() + ", Type: " + types[i].ToString(), myFont, myBrush, 200, j); j += 20; } }
public void PreCalc32Strokes() { if (m_32BasicStrokenBounds.Count > 0) { return; } // FontFamily fontFamily = new FontFamily(@"楷体_GB2312"); int fontSize = 512; bool iscolse = false; for (int i = 0; i < MAX_BASIC_STROKE; i++) { GraphicsPath charPath = new GraphicsPath(); charPath.AddString(StrokeInChinese[i], fontFamily, 0, fontSize, new PointF(0, 0), null); GraphicsPathIterator iterator; iterator = new GraphicsPathIterator(charPath); int count = iterator.SubpathCount; iterator.Rewind(); GraphicsPath bihua = new GraphicsPath(); for (int j = 0; j < count; j++) { GraphicsPath subpath = new GraphicsPath(); iterator.NextSubpath(subpath, out iscolse); if (StrokeIndexInKaitiGB2312_a[i] == j || StrokeIndexInKaitiGB2312_b[i] == j) { bihua.AddPath(subpath, false); } if (j == StrokeIndexInKaitiGB2312_b[i]) { break; } } //Compute Bounds of Path RectangleF b; b = bihua.GetBounds(); //Transform to 64x64 Matrix translateMatrix = new Matrix(); float scale = 64.0f / Math.Max(b.Width, b.Height); //Translate by Top Left translateMatrix.Translate(-b.X * scale, -b.Y * scale); //Scale by MAX (W/h) translateMatrix.Scale(scale, scale); bihua.Transform(translateMatrix); b = bihua.GetBounds(); //Create Region Region r = new Region(bihua); //translateMatrix.Reset(); //RegionData myRegionData = r.GetRegionData(); int area = 0; for (int x = 0; x < 64; x++) { for (int y = 0; y < 64; y++) { if (r.IsVisible(x, y)) { area++; } } } m_32BasicStrokes.Add(bihua); m_32BasicStrokenBounds.Add(b); m_32BasicStroken_Area.Add(area); iterator.Dispose(); charPath.Dispose(); } }
/// <summary> /// Given the points on this line decoration, this will cycle through and handle /// the drawing as dictated by this decoration. /// </summary> /// <param name="g">The graphics object used for drawing.</param> /// <param name="path">The path of the line.</param> /// <param name="scaleWidth">The double scale width for controling markers</param> public void Draw(Graphics g, GraphicsPath path, double scaleWidth) { // CGX TRY CATCH try { if (NumSymbols == 0) { return; } GraphicsPathIterator myIterator = new GraphicsPathIterator(path); myIterator.Rewind(); bool isClosed; Size2D symbolSize = _symbol.GetSize(); symbolSize.Height = Math.Ceiling(symbolSize.Height * scaleWidth); symbolSize.Width = Math.Ceiling(symbolSize.Width * scaleWidth); Bitmap symbol = new Bitmap((int)symbolSize.Width, (int)symbolSize.Height); Graphics sg = Graphics.FromImage(symbol); _symbol.Draw(sg, new Rectangle(0, 0, (int)symbolSize.Width, (int)symbolSize.Height)); sg.Dispose(); Matrix oldMat = g.Transform; GraphicsPath gp = new GraphicsPath(); GraphicsPath pastGP = new GraphicsPath(); while (myIterator.NextSubpath(gp, out isClosed) > 0) { PointF[] points = gp.PathPoints; int start = 0, end = points.Length - 1; if (NumSymbols == 1) { // single decoration spot if (_percentualPosition == 0) { // at start of the line DrawImage(g, points[start], points[start + 1], points[start], FlipFirst ^ FlipAll, symbol, oldMat, scaleWidth); } else if (_percentualPosition == 100) { // at end of the line DrawImage(g, points[end - 1], points[end], points[end], FlipFirst ^ FlipAll, symbol, oldMat, scaleWidth); } else { // somewhere in between start and end double totalLength = GetLength(points, start, end); double span = totalLength * _percentualPosition / 100; List <DecorationSpot> spot = GetPosition(points, span, start, end); if (spot.Count > 1) { DrawImage(g, spot[1].Before, spot[1].After, spot[1].Position, FlipFirst ^ FlipAll, symbol, oldMat, scaleWidth); } } } else { // more than one decoration spot double totalLength = GetLength(points, start, end); List <DecorationSpot> spots = new List <DecorationSpot>(); double span = 0.0; if (_useSpacing) { var dpi = g.DpiX; var mm = GetSpacingValue_mm(); span = ((mm * dpi) / 25.4) * scaleWidth; if (DotSpatial.Symbology.Core.Constants.IsPrinting) { float fRes = (float)g.DpiX; span = span * 97.0F / fRes; } } else { span = Math.Round(totalLength / (NumSymbols - 1), 4); } if (span > 0) { spots = GetPosition(points, span, start, end); } for (int i = 0; i < spots.Count; i++) { using (var pen = new Pen(Color.Black, 2)) { if (!pastGP.IsOutlineVisible(spots[i].Position, pen)) { DrawImage(g, spots[i].Before, spots[i].After, spots[i].Position, i == 0 ? (FlipFirst ^ FlipAll) : FlipAll, oldMat, scaleWidth); } } } } pastGP.AddPath(gp, false); } } catch (Exception) { } }