public static GlyphImage CreateMsdfImage( this MsdfGlyphGen msdfGlyphGen, GlyphPointF[] glyphPoints, ushort[] contourEndPoints, float pxScale = 1) { // create msdf shape , then convert to actual image Msdfgen.Shape shape = msdfGlyphGen.CreateMsdfShape(glyphPoints, contourEndPoints, pxScale); double left, bottom, right, top; shape.findBounds(out left, out bottom, out right, out top); int w = (int)Math.Ceiling((right - left)); int h = (int)Math.Ceiling((top - bottom)); if (w < 5) { w = 5; } if (h < 5) { h = 5; } Msdfgen.FloatRGBBmp frgbBmp = new Msdfgen.FloatRGBBmp(w, h); 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); GlyphImage img = new Typography.Rendering.GlyphImage(w, h); img.SetImageBuffer(buffer, false); return(img); }
public static BitmapAtlasItemSource CreateMsdfImageV1(Msdfgen.Shape shape, Msdfgen.MsdfGenParams genParams) { //output is msdf v1, //int w, int h, Vector2 translate Msdfgen.MsdfGen3.PreviewSizeAndLocation(shape, genParams, out int imgW, out int imgH, out Msdfgen.Vector2 translate); //output is msdf v1 return(Msdfgen.MsdfGen3.CreateMsdfImage(shape, genParams, imgW, imgH, translate, null));//output is msdf v1, since we set lut=null }
public static BitmapAtlasItemSource CreateMsdfImageV1(ContourBuilder contourBuilder, Msdfgen.MsdfGenParams genParams) { // create msdf shape , then convert to actual image Msdfgen.Shape shape = CreateMsdfShape(contourBuilder, genParams.shapeScale); //int w, int h, Vector2 translate Msdfgen.MsdfGen3.PreviewSizeAndLocation(shape, genParams, out int imgW, out int imgH, out Msdfgen.Vector2 translate); return(Msdfgen.MsdfGen3.CreateMsdfImage(shape, genParams, imgW, imgH, translate, null)); }
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); }
public static GlyphImage CreateMsdfImage(Msdfgen.Shape shape) { double left, bottom, right, top; shape.findBounds(out left, out bottom, out right, out top); int w = (int)Math.Ceiling((right - left)); int h = (int)Math.Ceiling((top - bottom)); if (w < 5) { w = 5; } if (h < 5) { h = 5; } int borderW = (int)((float)w / 5f); var translate = new Msdfgen.Vector2(left < 0 ? -left + borderW : borderW, bottom < 0 ? -bottom + borderW : borderW); w += borderW * 2; //borders,left- right h += borderW * 2; //borders, top- bottom Msdfgen.FloatRGBBmp frgbBmp = new Msdfgen.FloatRGBBmp(w, h); Msdfgen.EdgeColoring.edgeColoringSimple(shape, 3); Msdfgen.MsdfGenerator.generateMSDF(frgbBmp, shape, 4, new Msdfgen.Vector2(1, 1), //scale translate, //translate to positive quadrant -1); //----------------------------------- int[] buffer = Msdfgen.MsdfGenerator.ConvertToIntBmp(frgbBmp); GlyphImage img = new GlyphImage(w, h); img.TextureOffsetX = translate.x; img.TextureOffsetY = translate.y; img.SetImageBuffer(buffer, false); return(img); }
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"); // } }
public static GlyphImage CreateMsdfImage(Msdfgen.Shape shape, MsdfGenParams genParams) { double left, bottom, right, top; shape.findBounds(out left, out bottom, out right, out top); int w = (int)Math.Ceiling((right - left)); int h = (int)Math.Ceiling((top - bottom)); if (w < genParams.minImgWidth) { w = genParams.minImgWidth; } if (h < genParams.minImgHeight) { h = genParams.minImgHeight; } //temp, for debug with glyph 'I', tahoma font //double edgeThreshold = 1.00000001;//default, if edgeThreshold < 0 then set edgeThreshold=1 //Msdfgen.Vector2 scale = new Msdfgen.Vector2(0.98714652956298199, 0.98714652956298199); //double pxRange = 4; //translate = new Msdfgen.Vector2(12.552083333333332, 4.0520833333333330); //double range = pxRange / Math.Min(scale.x, scale.y); int borderW = (int)((float)w / 5f); var translate = new Msdfgen.Vector2(left < 0 ? -left + borderW : borderW, bottom < 0 ? -bottom + borderW : borderW); w += borderW * 2; //borders,left- right h += borderW * 2; //borders, top- bottom double edgeThreshold = genParams.edgeThreshold; if (edgeThreshold < 0) { edgeThreshold = 1.00000001; //use default if edgeThreshold <0 } var scale = new Msdfgen.Vector2(genParams.scaleX, genParams.scaleY); //scale double range = genParams.pxRange / Math.Min(scale.x, scale.y); //--------- Msdfgen.FloatRGBBmp frgbBmp = new Msdfgen.FloatRGBBmp(w, h); Msdfgen.EdgeColoring.edgeColoringSimple(shape, genParams.angleThreshold); Msdfgen.MsdfGenerator.generateMSDF(frgbBmp, shape, range, scale, translate,//translate to positive quadrant edgeThreshold); //----------------------------------- int[] buffer = Msdfgen.MsdfGenerator.ConvertToIntBmp(frgbBmp); GlyphImage img = new GlyphImage(w, h); img.TextureOffsetX = (short)translate.x; img.TextureOffsetY = (short)translate.y; img.SetImageBuffer(buffer, false); return(img); }