private void SetFontSize(int size) { _size = size; //////_fontFace.SetCharSize(size, size, 0, 0); _fontFace.SetPixelSizes((uint)size, (uint)size); GenerateTextures(); }
/* * private void DrawChar(Char c) * { * var g = this.CreateGraphics(); * g.ResetTransform(); * g.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.None; * g.TextRenderingHint = System.Drawing.Text.TextRenderingHint.SingleBitPerPixel; * //g. * var charWidth = Int32.Parse(textBoxCharWidth.Text); * var charHeight = Int32.Parse(textBoxCharHeight.Text); * //Console.WriteLine(textBoxFontPreview.Font); * var size = GetCharSize(c, g); * Bitmap bm = new Bitmap(size.Width, size.Height); * Brush br = new SolidBrush(Color.White); * //Graphics g = Graphics.FromImage(bm); * //String s = ""; * //s += c; * StringFormat sf = new StringFormat(); * //sf.Alignment = StringAlignment.Center; * //sf.LineAlignment = StringAlignment.Center; * //g.ResetTransform(); * //g.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.None; * //g.TextRenderingHint = System.Drawing.Text.TextRenderingHint.SingleBitPerPixel; * g.Clear(Color.Black); * //g.DrawString(s, fontDialog1.Font, br, 1, 1, sf); * TextRenderer.DrawText(g, c.ToString(), fontDialog1.Font, new Point(0, 0), Color.White); * // * var bmf = String.Format("{0}\\pcf_{1}.bmp", textBoxOutputDir.Text, (Int32)c); * bm.Save(bmf); * // * g.Dispose(); * } */ private bool DrawChar(Char c) { try { //ftFace.SetCharSize(appSettings.CharSize.Width, appSettings.CharSize.Height, (uint)appSettings.DPI.Width, (uint)appSettings.DPI.Height); ftFace.SetPixelSizes((uint)appSettings.CharSize.Width, (uint)appSettings.CharSize.Height); var glyphIndex = ftFace.GetCharIndex((uint)c); ftFace.LoadGlyph(glyphIndex, SharpFont.LoadFlags.Default | SharpFont.LoadFlags.NoHinting, SharpFont.LoadTarget.Mono); ftFace.Glyph.RenderGlyph(SharpFont.RenderMode.Mono); var penX = ftFace.Glyph.BitmapLeft; var penY = (int)ftFace.Size.Metrics.Ascender - ftFace.Glyph.BitmapTop; while (penY > 0 && penY + ftFace.Glyph.Metrics.Height > appSettings.CharSize.Height) { penY--; } Console.WriteLine("X {0} Y {1} L {2} T {3}", ftFace.Glyph.Advance.X, ftFace.Glyph.Advance.Y, ftFace.Glyph.BitmapLeft, ftFace.Glyph.BitmapTop); Console.WriteLine("{0} {1} {2}", ftFace.Size.Metrics.Ascender, ftFace.Size.Metrics.Descender, ftFace.Glyph.Metrics.Height); Bitmap bm = ftFace.Glyph.Bitmap.ToGdipBitmap(Color.Black); var nbm = new Bitmap(appSettings.CharSize.Width, appSettings.CharSize.Height); var g = Graphics.FromImage(nbm); g.Clear(Color.White); g.DrawImageUnscaled(bm, penX, penY); //nbm.SetPixel() // byte[] mbc; if (c > 127) { mbc = Encoding.GetEncoding(appSettings.CharEncoding).GetBytes(c.ToString().ToCharArray()); } else { mbc = new byte[] { 0, (byte)c } }; outputWriter.WriteLine(@"0x{0:x2},0x{1:x2}, // {2}", mbc[0], mbc[1], c); Console.WriteLine("W {0} H {1}", nbm.Width, nbm.Height); BitArray ba = new BitArray(nbm.Width * nbm.Height); for (var y = 0; y < nbm.Height; y++) { for (var x = 0; x < nbm.Width; x++) { var a = nbm.GetPixel(x, y); ba.Set(y * nbm.Width + x, a.B == 0); } } byte[] bba = new byte[nbm.Width * nbm.Height / 8]; ba.CopyTo(bba, 0); for (var i = 0; i < bba.Length; i++) { if (i > 0 && i % 16 == 0) { outputWriter.WriteLine(); } outputWriter.Write(@"0x{0:x2},", bba[i]); } outputWriter.WriteLine(); outputWriter.WriteLine(); Console.WriteLine(bba.Length); if (appSettings.SaveBitmap) { var nbmf = String.Format("{0}\\pcf_{1:x2}{2:x2}.bmp", appSettings.OutputDir, mbc[0], mbc[1]); nbm.Save(nbmf); } ShowBitmap(nbm); } catch (Exception ex) { Console.WriteLine(ex); return(false); } return(true); }