static Msdfgen.Shape CreateMsdfShape(List <GlyphContour> contours) { var shape = new Msdfgen.Shape(); int j = contours.Count; for (int i = 0; i < j; ++i) { var cnt = new Msdfgen.Contour(); shape.contours.Add(cnt); GlyphContour contour = contours[i]; List <GlyphPart> parts = contour.parts; int m = parts.Count; for (int n = 0; n < m; ++n) { GlyphPart p = parts[n]; switch (p.Kind) { default: throw new NotSupportedException(); case GlyphPartKind.Curve3: { GlyphCurve3 curve3 = (GlyphCurve3)p; cnt.AddQuadraticSegment( curve3.FirstPoint.X, curve3.FirstPoint.Y, curve3.x1, curve3.y1, curve3.x2, curve3.y2 ); } break; case GlyphPartKind.Curve4: { GlyphCurve4 curve4 = (GlyphCurve4)p; cnt.AddCubicSegment( curve4.FirstPoint.X, curve4.FirstPoint.Y, curve4.x1, curve4.y1, curve4.x2, curve4.y2, curve4.x3, curve4.y3); } break; case GlyphPartKind.Line: { GlyphLine line = (GlyphLine)p; cnt.AddLine( line.FirstPoint.X, line.FirstPoint.Y, line.x1, line.y1); } break; } } } return(shape); }
private void button10_Click(object sender, EventArgs e) { //-------------------------------------------- Msdfgen.Shape shape = new Msdfgen.Shape(); Msdfgen.Contour contour = new Msdfgen.Contour(); //contour.AddLine(10, 10, 25, 25); //contour.AddLine(25, 25, 15, 10); //contour.AddLine(15, 10, 10, 10); contour.AddLine(10, 10, 25, 25); contour.AddQuadraticSegment(25, 25, 15, 30, 10, 15); contour.AddLine(10, 15, 10, 10); shape.contours.Add(contour); //-+--------------------------- double left, bottom, right, top; shape.findBounds(out left, out bottom, out right, out top); Msdfgen.FloatRGBBmp frgbBmp = new Msdfgen.FloatRGBBmp((int)Math.Ceiling((right - left)), (int)Math.Ceiling((top - bottom))); double edgeThreshold = 1.00000001;//use default double angleThreshold = 1; shape.InverseYAxis = true; Msdfgen.EdgeColoring.edgeColoringSimple(shape, 3); Msdfgen.MsdfGenerator.generateMSDF(frgbBmp, shape, 4, new Msdfgen.Vector2(1, 1), new Msdfgen.Vector2(), -1); int[] buffer = Msdfgen.MsdfGenerator.ConvertToIntBmp(frgbBmp); //MsdfGen.SwapColorComponentFromBigEndianToWinGdi(buffer); using (Bitmap bmp = new Bitmap(frgbBmp.Width, frgbBmp.Height, System.Drawing.Imaging.PixelFormat.Format32bppArgb)) { var bmpdata = bmp.LockBits(new System.Drawing.Rectangle(0, 0, frgbBmp.Width, frgbBmp.Height), System.Drawing.Imaging.ImageLockMode.ReadWrite, bmp.PixelFormat); System.Runtime.InteropServices.Marshal.Copy(buffer, 0, bmpdata.Scan0, buffer.Length); bmp.UnlockBits(bmpdata); bmp.Save("d:\\WImageTest\\a001_xn2_.png"); } }
private void button1_Click(object sender, EventArgs e) { //1. MsdfGenParams msdfGenParams = new MsdfGenParams(); //GlyphImage glyphImg = MsdfGlyphGen.CreateMsdfImage(tx, msdfGenParams); Msdfgen.Shape shape1 = new Msdfgen.Shape(); // Msdfgen.Contour cnt = new Msdfgen.Contour(); //cnt.AddLine(0, 0, 50, 0); //cnt.AddLine(50, 0, 50, 50); //cnt.AddLine(50, 50, 0, 50); //cnt.AddLine(0, 50, 0, 0); //cnt.AddLine(10, 20, 50, 0); //cnt.AddLine(50, 0, 80, 20); //cnt.AddLine(80, 20, 50, 60); //cnt.AddLine(50, 60, 10, 20); //for msdf we draw shape clock-wise cnt.AddLine(10, 20, 50, 60); cnt.AddLine(50, 60, 80, 20); cnt.AddLine(80, 20, 50, 0); cnt.AddLine(50, 0, 10, 20); shape1.contours.Add(cnt); // // var genParams = new MsdfGenParams(); GlyphImage glyphImg = MsdfGlyphGen.CreateMsdfImage(shape1, genParams); using (Bitmap bmp = new Bitmap(glyphImg.Width, glyphImg.Height, System.Drawing.Imaging.PixelFormat.Format32bppArgb)) { int[] buffer = glyphImg.GetImageBuffer(); var bmpdata = bmp.LockBits(new System.Drawing.Rectangle(0, 0, glyphImg.Width, glyphImg.Height), System.Drawing.Imaging.ImageLockMode.ReadWrite, bmp.PixelFormat); System.Runtime.InteropServices.Marshal.Copy(buffer, 0, bmpdata.Scan0, buffer.Length); bmp.UnlockBits(bmpdata); bmp.Save("d:\\WImageTest\\msdf_shape.png"); // } }