public OpenTypeFontStyle(FastColoredTextBox fctb, LOGFONT font) : base(null, null, FontStyle.Regular) { this.font = font; //measure font using (var gr = fctb.CreateGraphics()) { var HDC = gr.GetHdc(); var fontHandle = CreateFontIndirect(font); var f = SelectObject(HDC, fontHandle); var measureSize = new Size(0, 0); try { GetTextExtentPoint(HDC, "M", 1, ref measureSize); } finally { DeleteObject(SelectObject(HDC, f)); gr.ReleaseHdc(HDC); } fctb.CharWidth = measureSize.Width; fctb.CharHeight = measureSize.Height + fctb.LineInterval; fctb.NeedRecalc(true, true); } }
public OpenTypeFontStyle(FastColoredTextBox fctb, LOGFONT font) : base(null, null, FontStyle.Regular) { this.font = font; //measure font using (var gr = fctb.CreateGraphics()) { var HDC = gr.GetHdc(); var fontHandle = CreateFontIndirect(font); var f = SelectObject(HDC, fontHandle); var measureSize = new Size(0, 0); try { GetTextExtentPoint(HDC, "M", 1, ref measureSize); } finally { DeleteObject(SelectObject(HDC, f)); gr.ReleaseHdc(HDC); } fctb.CharWidth = measureSize.Width; fctb.CharHeight = measureSize.Height + fctb.LineInterval; fctb.NeedRecalc(true, true); } }