static SimpleFontAtlasBuilder CreateSampleMsdfTextureFont(string fontfile, float sizeInPoint, ushort startGlyphIndex, ushort endGlyphIndex) { //read type face from file Typeface typeface; using (var fs = new FileStream(fontfile, FileMode.Open, FileAccess.Read)) { var reader = new OpenFontReader(); //1. read typeface from font file typeface = reader.Read(fs); } //sample: create sample msdf texture //------------------------------------------------------------- var builder = new MyGlyphPathBuilder(typeface); //builder.UseTrueTypeInterpreter = this.chkTrueTypeHint.Checked; //builder.UseVerticalHinting = this.chkVerticalHinting.Checked; //------------------------------------------------------------- var atlasBuilder = new SimpleFontAtlasBuilder(); var msdfBuilder = new MsdfGlyphGen(); for (ushort n = startGlyphIndex; n <= endGlyphIndex; ++n) { //build glyph builder.BuildFromGlyphIndex(n, sizeInPoint); var msdfGlyphGen = new MsdfGlyphGen(); var actualImg = msdfGlyphGen.CreateMsdfImage( builder.GetOutputPoints(), builder.GetOutputContours(), builder.GetPixelScale()); atlasBuilder.AddGlyph((int)n, actualImg); //using (Bitmap bmp = new Bitmap(w, h, System.Drawing.Imaging.PixelFormat.Format32bppArgb)) //{ // var bmpdata = bmp.LockBits(new Rectangle(0, 0, w, h), 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_" + n + ".png"); //} } return(atlasBuilder); //var glyphImg2 = atlasBuilder.BuildSingleImage(); //using (Bitmap bmp = new Bitmap(glyphImg2.Width, glyphImg2.Height, System.Drawing.Imaging.PixelFormat.Format32bppArgb)) //{ // var bmpdata = bmp.LockBits(new System.Drawing.Rectangle(0, 0, glyphImg2.Width, glyphImg2.Height), // System.Drawing.Imaging.ImageLockMode.ReadWrite, bmp.PixelFormat); // int[] intBuffer = glyphImg2.GetImageBuffer(); // System.Runtime.InteropServices.Marshal.Copy(intBuffer, 0, bmpdata.Scan0, intBuffer.Length); // bmp.UnlockBits(bmpdata); // bmp.Save("d:\\WImageTest\\a_total.png"); //} //atlasBuilder.SaveFontInfo("d:\\WImageTest\\a_info.xml"); }
List <ushort> inputGlyphs = new List <ushort>(); //not thread safe*** void Print(Typeface typeface, float size, char[] str, List <GlyphPlan> glyphPlanBuffer) { //1. layout _glyphLayout.Layout(typeface, size, str, glyphPlanBuffer); var glyphPathBuilder = new MyGlyphPathBuilder(typeface); int j = glyphPlanBuffer.Count; float pxScale = typeface.CalculateFromPointToPixelScale(size); for (int i = 0; i < j; ++i) { GlyphPlan glyphPlan = glyphPlanBuffer[i]; //----------------------------------- //check if we static vxs/bmp for this glyph //if not, create and cache //----------------------------------- glyphPathBuilder.BuildFromGlyphIndex(glyphPlan.glyphIndex, size); //----------------------------------- var vxsBuilder = new GlyphPathBuilderVxs(); glyphPathBuilder.ReadShapes(vxsBuilder); glyphPlan.vxs = vxsBuilder.GetVxs(pxScale); } }