CreateFontIndirect() private method

private CreateFontIndirect ( Win32.LOGFONT &logFont ) : IntPtr
logFont Win32.LOGFONT
return System.IntPtr
Beispiel #1
0
        static IntPtr InitFont(string fontName, float emHeight, FontStyle style)
        {
            //see: MSDN, LOGFONT structure
            //https://msdn.microsoft.com/en-us/library/windows/desktop/dd145037(v=vs.85).aspx
            MyWin32.LOGFONT logFont = new MyWin32.LOGFONT();
            MyWin32.SetFontName(ref logFont, fontName);
            logFont.lfHeight  = -(int)ConvEmSizeInPointsToPixels(emHeight); //minus **
            logFont.lfCharSet = 1;                                          //default
            logFont.lfQuality = 0;                                          //default

            MyWin32.LOGFONT_FontWeight weight =
                ((style & FontStyle.Bold) == FontStyle.Bold) ?
                MyWin32.LOGFONT_FontWeight.FW_BOLD :
                MyWin32.LOGFONT_FontWeight.FW_REGULAR;
            logFont.lfWeight = (int)weight;
            //
            logFont.lfItalic = (byte)(((style & FontStyle.Italic) == FontStyle.Italic) ? 1 : 0);
            return(MyWin32.CreateFontIndirect(ref logFont));
        }
        public static Win32Font CreateWin32Font(string fontName, float emHeight, bool bold, bool italic, float pixels_per_inch = 96)
        {
            //see: MSDN, LOGFONT structure
            //https://msdn.microsoft.com/en-us/library/windows/desktop/dd145037(v=vs.85).aspx
            MyWin32.LOGFONT logFont = new MyWin32.LOGFONT();
            MyWin32.SetFontName(ref logFont, fontName);
            logFont.lfHeight  = -(int)MyWin32.ConvEmSizeInPointsToPixels(emHeight, pixels_per_inch); //minus **
            logFont.lfCharSet = 1;                                                                   //default
            logFont.lfQuality = 0;                                                                   //default

            //
            MyWin32.LOGFONT_FontWeight weight =
                bold ?
                MyWin32.LOGFONT_FontWeight.FW_BOLD :
                MyWin32.LOGFONT_FontWeight.FW_REGULAR;
            logFont.lfWeight = (int)weight;
            //
            logFont.lfItalic = (byte)(italic ? 1 : 0);
            return(new Win32Font(MyWin32.CreateFontIndirect(ref logFont)));
        }