public FontContainer() { this.mCharBitmaps = new Dictionary <char, Bitmap>(); //this.mFontFamily = "Arial"; //this.mSize = 14; //this.mStyle = FontStyle.Regular; this.mWidthMode = FontWidthMode.None; this.mFont = new Font("Arial", 14, FontStyle.Regular, GraphicsUnit.Pixel); this.mEdge = 5; }
public static Bitmap GetCharacterBitmap(char c, Font font, FontWidthMode widthMode, int width, float edge) { bool setByDef = SavedContainer <Options> .Instance.SetBitsByDefault; Size sz = TextRenderer.MeasureText(new string(c, 1), font); Bitmap bmp; if (widthMode == FontWidthMode.Monospaced) { bmp = new Bitmap(width, sz.Height); } else { bmp = new Bitmap(sz.Width, sz.Height); } Graphics gr = Graphics.FromImage(bmp); gr.FillRectangle((setByDef ? Brushes.White : Brushes.Black), 0, 0, bmp.Width, bmp.Height); gr.InterpolationMode = System.Drawing.Drawing2D.InterpolationMode.Low; gr.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.None; gr.DrawString(new string(c, 1), font, (setByDef ? Brushes.Black : Brushes.White), 0, 0); bmp = GetMonochrome(bmp, edge); if (widthMode == FontWidthMode.Proportional) { Rectangle shrink = BitmapHelper.CalcShrink(bmp); int left = -shrink.X; int top = -shrink.Y; int right = -(bmp.Width - shrink.Width - shrink.X); int bottom = -(bmp.Height - shrink.Height - shrink.Y); left++; right++; bmp = BitmapHelper.Resize(bmp, left, 0, right, 0); } return(bmp); }