コード例 #1
0
ファイル: Win32Api2.cs プロジェクト: luislasonbra/PixelFarm
        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));
        }
コード例 #2
0
        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)));
        }
コード例 #3
0
ファイル: MyWin32.cs プロジェクト: prepare/HTML-Renderer
 public static IntPtr CreateFontHelper(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)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 MyWin32.CreateFontIndirect(ref logFont);
 }
コード例 #4
0
ファイル: WinGdiFont.cs プロジェクト: prepare/HTML-Renderer
 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)PixelFarm.Drawing.RequestFont.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);
 }