private void CreateFont() { lock (this) { if (_hFont == IntPtr.Zero) { if (_clearType) { Win32.LOGFONT lf = new Win32.LOGFONT(); _font.ToLogFont(lf); Version osVer = Environment.OSVersion.Version; int major = osVer.Major; int minor = osVer.Minor; if (major > 5 || (major == 5 && minor >= 1)) { lf.lfQuality = Win32.CLEARTYPE_NATURAL_QUALITY; } else { lf.lfQuality = Win32.CLEARTYPE_QUALITY; } _hFont = Win32.CreateFontIndirect(lf); } else { _hFont = _font.ToHfont(); } } } }
public static FontGdi CreateFont(string Family, float Size, FontStyle Style, bool forceClearType) { IntPtr hFont = m_cache[Family][Size][Style]; if (hFont != IntPtr.Zero) { return(new FontGdi(hFont)); } // // ClearType: Check to see if this computer has ClearType turned on so we can // display with ClearType fonts if it does. // bool useCleartype = forceClearType; if (!forceClearType) { object clearType = Registry.GetValue(@"HKEY_CURRENT_USER\Software\Microsoft\Shell", "ClearType", null); useCleartype = (clearType is int && (int)clearType == 1); } Win32.LOGFONT lf = new Win32.LOGFONT(); lf.lfCharSet = Win32.ANSI_CHARSET; lf.lfClipPrecision = 0; lf.lfEscapement = 0; //lf.lfFaceName = Family.PadRight(32, ' ').ToCharArray(); lf.lfHeight = UISettings.CalcPix((int)Size);// (Size / 8 * 13); lf.lfItalic = (Style & FontStyle.Italic) == FontStyle.Italic? (byte)1: (byte)0; lf.lfOrientation = 0; lf.lfOutPrecision = 0; lf.lfPitchAndFamily = Win32.FF_DONTCARE; if (useCleartype) { lf.lfQuality = Win32.CLEARTYPE_QUALITY; } else { lf.lfQuality = Win32.DEFAULT_QUALITY; } lf.lfStrikeOut = (Style & FontStyle.Strikeout) == FontStyle.Strikeout? (byte)1: (byte)0; lf.lfUnderline = (Style & FontStyle.Underline) == FontStyle.Underline? (byte)1: (byte)0; lf.lfWeight = (Style & FontStyle.Bold) == FontStyle.Bold? Win32.FW_BOLD: Win32.FW_NORMAL; lf.lfWidth = 0; IntPtr pLF = Win32.LocalAlloc(Win32.LocalAllocFlags.LPTR, 92); Marshal.StructureToPtr(lf, pLF, false); if (Family.Length > 32) { Family = Family.Substring(0, 32); } Marshal.Copy(Family.ToCharArray(), 0, (IntPtr)((int)pLF + 28), Family.Length); hFont = Win32.CreateFontIndirect(pLF); Marshal.PtrToStructure(pLF, lf); Win32.LocalFree(pLF); m_cache[Family][Size][Style] = hFont; return(new FontGdi(hFont)); }
//IMEの位置合わせなど。日本語入力開始時、現在のキャレット位置からIMEをスタートさせる。 private void AdjustIMEComposition() { TerminalDocument document = GetDocument(); IntPtr hIMC = Win32.ImmGetContext(this.Handle); RenderProfile prof = GetRenderProfile(); //フォントのセットは1回やればよいのか? Win32.LOGFONT lf = new Win32.LOGFONT(); prof.CalcFont(null, CharGroup.Zenkaku).ToLogFont(lf); Win32.ImmSetCompositionFont(hIMC, lf); Win32.COMPOSITIONFORM form = new Win32.COMPOSITIONFORM(); form.dwStyle = Win32.CFS_POINT; Win32.SystemMetrics sm = GEnv.SystemMetrics; //Debug.WriteLine(String.Format("{0} {1} {2}", document.CaretColumn, charwidth, document.CurrentLine.CharPosToDisplayPos(document.CaretColumn))); form.ptCurrentPos.x = sm.ControlBorderWidth + (int)(prof.Pitch.Width * (document.CaretColumn)); form.ptCurrentPos.y = sm.ControlBorderHeight + (int)((prof.Pitch.Height + prof.LineSpacing) * (document.CurrentLineNumber - document.TopLineNumber)); bool r = Win32.ImmSetCompositionWindow(hIMC, ref form); Debug.Assert(r); Win32.ImmReleaseContext(this.Handle, hIMC); }
//IME�̈ʒu���킹�ȂǁB���{����͊J�n���A���݂̃L�����b�g�ʒu����IME��X�^�[�g������B private void AdjustIMEComposition() { TerminalDocument document = GetDocument(); IntPtr hIMC = Win32.ImmGetContext(this.Handle); RenderProfile prof = GetRenderProfile(); //�t�H���g�̃Z�b�g�͂P����悢�̂��H Win32.LOGFONT lf = new Win32.LOGFONT(); prof.CalcFont(null, CharGroup.CJKZenkaku).ToLogFont(lf); Win32.ImmSetCompositionFont(hIMC, lf); Win32.COMPOSITIONFORM form = new Win32.COMPOSITIONFORM(); form.dwStyle = Win32.CFS_POINT; Win32.SystemMetrics sm = GEnv.SystemMetrics; //Debug.WriteLine(String.Format("{0} {1} {2}", document.CaretColumn, charwidth, document.CurrentLine.CharPosToDisplayPos(document.CaretColumn))); form.ptCurrentPos.x = sm.ControlBorderWidth + (int)(prof.Pitch.Width * (document.CaretColumn)); form.ptCurrentPos.y = sm.ControlBorderHeight + (int)((prof.Pitch.Height + prof.LineSpacing) * (document.CurrentLineNumber - document.TopLineNumber)); bool r = Win32.ImmSetCompositionWindow(hIMC, ref form); Debug.Assert(r); Win32.ImmReleaseContext(this.Handle, hIMC); }
private void CreateFont() { lock (this) { if (_hFont == IntPtr.Zero) { if (_clearType) { Win32.LOGFONT lf = new Win32.LOGFONT(); _font.ToLogFont(lf); Version osVer = Environment.OSVersion.Version; int major = osVer.Major; int minor = osVer.Minor; if (major > 5 || (major == 5 && minor >= 1)) lf.lfQuality = Win32.CLEARTYPE_NATURAL_QUALITY; else lf.lfQuality = Win32.CLEARTYPE_QUALITY; _hFont = Win32.CreateFontIndirect(lf); } else { _hFont = _font.ToHfont(); } } } }
protected override void OnPaint( PaintEventArgs e) { // calculate rectangles Rectangle ic, ip, cc, cp, border; CalcRects(ClientRectangle, out ic, out ip, out cc, out cp, out border); // caption if (_showCaptions) { // background using (Brush b = new SolidBrush(BackColor)) { e.Graphics.FillRectangle(b, ic); e.Graphics.FillRectangle(b, cc); } // text, create Win32 font var lf = new Win32.LOGFONT(); Font.ToLogFont(lf); if (_orientation == PreviewOrientation.Horizontal) { // text rotated at 90 lf.lfOrientation = 900; lf.lfEscapement = 900; } IntPtr dc = e.Graphics.GetHdc(); IntPtr nf = Win32.CreateFontIndirect(lf); IntPtr of = Win32.SelectObject(dc, nf); int oc = Win32.SetTextColor(dc, ColorTranslator.ToWin32(ForeColor)); int om = Win32.SetBkMode(dc, Win32.SetBkModeConsts.TRANSPARENT); DrawText(dc, _initial, ic, _orientation == PreviewOrientation.Vertical); DrawText(dc, _current, cc, _orientation == PreviewOrientation.Vertical); Win32.SetBkMode(dc, om); Win32.SetTextColor(dc, oc); Win32.SelectObject(dc, of); Win32.DeleteObject(nf); e.Graphics.ReleaseHdc(); } // border using (var p = new Pen(_borderColor, 1)) e.Graphics.DrawRectangle(p, border.Left, border.Top, border.Width - 1, border.Height - 1); // if (_showInitial) { OnDrawInitial(e.Graphics, ip); OnDrawCurrent(e.Graphics, cp); } else { OnDrawCurrent(e.Graphics, cp); } base.OnPaint(e); }