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); }
protected override void OnReadyForInitGLShaderProgram() { //--------------------- var atlasBuilder = new Typography.Rendering.SimpleFontAtlasBuilder(); using (System.IO.FileStream fs = new System.IO.FileStream(RootDemoPath.Path + @"\a_total.xml", System.IO.FileMode.Open)) { _fontAtlas = atlasBuilder.LoadFontAtlasInfo(fs)[0]; } PixelFarm.CpuBlit.MemBitmap actualImg = null; using (System.IO.FileStream fs = new System.IO.FileStream(RootDemoPath.Path + @"\a_total.png", System.IO.FileMode.Open)) { actualImg = PixelFarm.CpuBlit.MemBitmap.LoadBitmap(fs); } _totalBmp = actualImg; //var bmpdata = totalImg.LockBits(new System.Drawing.Rectangle(0, 0, totalImg.Width, totalImg.Height), System.Drawing.Imaging.ImageLockMode.ReadWrite, totalImg.PixelFormat); //var buffer = new int[totalImg.Width * totalImg.Height]; //System.Runtime.InteropServices.Marshal.Copy(bmpdata.Scan0, buffer, 0, buffer.Length); //totalImg.UnlockBits(bmpdata); var glyph = new Typography.Rendering.GlyphImage(_totalBmp.Width, _totalBmp.Height); glyph.SetImageBuffer(PixelFarm.CpuBlit.MemBitmap.CopyImgBuffer(actualImg), false); _fontAtlas.TotalGlyph = glyph; }
protected override void OnInitGLProgram(object sender, EventArgs args) { int max = Math.Max(this.Width, this.Height); canvas2d = PixelFarm.Drawing.GLES2.GLES2Platform.CreateCanvasGL2d(max, max); painter = new GLCanvasPainter(canvas2d, max, max); //--------------------- string fontfilename = "d:\\WImageTest\\a_total.xml"; var atlasBuilder = new Typography.Rendering.SimpleFontAtlasBuilder(); fontAtlas = atlasBuilder.LoadFontInfo(fontfilename); totalImg = new System.Drawing.Bitmap("d:\\WImageTest\\a_total.png"); var bmpdata = totalImg.LockBits(new System.Drawing.Rectangle(0, 0, totalImg.Width, totalImg.Height), System.Drawing.Imaging.ImageLockMode.ReadWrite, totalImg.PixelFormat); var buffer = new int[totalImg.Width * totalImg.Height]; System.Runtime.InteropServices.Marshal.Copy(bmpdata.Scan0, buffer, 0, buffer.Length); totalImg.UnlockBits(bmpdata); var glyph = new Typography.Rendering.GlyphImage(totalImg.Width, totalImg.Height); glyph.SetImageBuffer(buffer, false); fontAtlas.TotalGlyph = glyph; //--------------------- }
protected override void OnReadyForInitGLShaderProgram() { //--------------------- var atlasBuilder = new Typography.Rendering.SimpleFontAtlasBuilder(); fontAtlas = atlasBuilder.LoadFontInfo(RootDemoPath.Path + @"\a_total.xml"); var actualImg = DemoHelper.LoadImage(RootDemoPath.Path + @"\a_total.png"); //var bmpdata = totalImg.LockBits(new System.Drawing.Rectangle(0, 0, totalImg.Width, totalImg.Height), System.Drawing.Imaging.ImageLockMode.ReadWrite, totalImg.PixelFormat); //var buffer = new int[totalImg.Width * totalImg.Height]; //System.Runtime.InteropServices.Marshal.Copy(bmpdata.Scan0, buffer, 0, buffer.Length); //totalImg.UnlockBits(bmpdata); var glyph = new Typography.Rendering.GlyphImage(totalImg.Width, totalImg.Height); glyph.SetImageBuffer(PixelFarm.Agg.ActualImage.CopyImgBuffer(actualImg), false); fontAtlas.TotalGlyph = glyph; }