当前位置: 首页>>代码示例>>C#>>正文


C# System.Drawing.Font.ToHfont方法代码示例

本文整理汇总了C#中System.Drawing.Font.ToHfont方法的典型用法代码示例。如果您正苦于以下问题:C# System.Drawing.Font.ToHfont方法的具体用法?C# System.Drawing.Font.ToHfont怎么用?C# System.Drawing.Font.ToHfont使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在System.Drawing.Font的用法示例。


在下文中一共展示了System.Drawing.Font.ToHfont方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: font

        public static void CreateBitmapFont
        (
            GraphicsInterface gr,
            IntPtr hdc,  // [in]
            String fontName, // [in] "Verdana", "Arial", "Courier New", "Symbol", "Wingdings", "Wingdings 3"
            int fontCellHeightInPoints, // [in] Cell height of font (in points)
            ref uint bitmapFontOpenGLDisplayListBase  // [in]
        )
        {
            bitmapFontOpenGLDisplayListBase = gl.glGenLists(256);

            // IT IT AN ABSOLUTE NECESSITY TO SELECT A FONT IN TO THE DC FOR THE 
            // wglUseFontOutlines() METHOD TO SUCCEED WITHOUT A MYSTERIOUS 
            // ERROR 126: ERROR_MOD_NOT_FOUND : The specified module could not be found.
            // THAT ERROR CODE, OF COURSE, IS MISLEADING.

            IntPtr hfont;
            System.Drawing.Font font = null;

            bool useGDICreateFontDirectly = false;

            if (useGDICreateFontDirectly)
            {
                // height ; negative means CHARACTER height; positive means CELL height
                hfont = TOAPI.GDI32.GDI32.CreateFont((short)fontCellHeightInPoints,
                  0, 0, 0,
                  GDI32.FW_NORMAL, // weight 
                  0, 0, 0,
                  GDI32.ANSI_CHARSET, // char set 
                  GDI32.OUT_TT_PRECIS, // output precision 
                  GDI32.CLIP_DEFAULT_PRECIS, // clip precision 
                  GDI32.ANTIALIASED_QUALITY, // quality
                  GDI32.FF_DONTCARE | GDI32.DEFAULT_PITCH, // pitch and family 
                  fontName);
            }
            else
            {
                font =
                  new System.Drawing.Font(
                    fontName, // family: "Verdana", "Arial", "Courier New", "Symbol", "Wingdings", "Wingdings 3"
                    (float)fontCellHeightInPoints,            // emSize: Font size (see 4th parameter for units)
                    System.Drawing.FontStyle.Regular, // style
                    System.Drawing.GraphicsUnit.Point, // unit
                    ((System.Byte)(0)) // GDI character set
                    );

                hfont = font.ToHfont();
            }

            GDI32.SelectObject(hdc, hfont);


            bool result;

            // Use wglUseFontBitmapsW() instead if this doesn't work!!!
            result = wgl.wglUseFontBitmapsW(hdc, 0, 255, bitmapFontOpenGLDisplayListBase);

            if (!result)
            {
                String message = "wglUseFontBitmaps() error";
                Console.WriteLine(message);
                //MessageBox.Show(null, message, "Error", MessageBoxButtons.OK);
            }
        }
开发者ID:Wiladams,项目名称:NewTOAPIA,代码行数:64,代码来源:GLTextHelper.cs

示例2: ReadFontBytesFromGdi

        static byte[] ReadFontBytesFromGdi(GdiFont gdiFont)
        {
            // Weird: LastError is always 123 or 127. Comment out Debug.Assert.
            int error = Marshal.GetLastWin32Error();
            //Debug.Assert(error == 0);
            error = Marshal.GetLastWin32Error();
            //Debug.Assert(error == 0);

            IntPtr hfont = gdiFont.ToHfont();
#if true
            IntPtr hdc = NativeMethods.GetDC(IntPtr.Zero);
#else
            NativeMethods.LOGFONT logFont = new NativeMethods.LOGFONT();
            logFont.lfHeight = 30;
            logFont.lfWidth = 0;
            logFont.lfEscapement = 0;
            logFont.lfOrientation = 0;
            logFont.lfWeight = 400;
            logFont.lfItalic = 0;
            logFont.lfUnderline = 0;
            logFont.lfStrikeOut = 0;
            logFont.lfCharSet = 0;
            logFont.lfOutPrecision = 0;
            logFont.lfClipPrecision = 0;
            logFont.lfQuality = 0;
            logFont.lfPitchAndFamily = 0;
            logFont.lfFaceName = "Arial";

            gdiFont.ToLogFont(logFont);

            hfont = NativeMethods.CreateFontIndirect(logFont);


            // IntPtr hdc = NativeMethods.CreateDC("DISPLAY", null, null, IntPtr.Zero);
            IntPtr hdc = NativeMethods.CreateCompatibleDC(IntPtr.Zero);
#endif
            error = Marshal.GetLastWin32Error();
            //Debug.Assert(error == 0);

            IntPtr oldFont = NativeMethods.SelectObject(hdc, hfont);
            error = Marshal.GetLastWin32Error();
            //Debug.Assert(error == 0);

            // Get size of the font file.
            bool isTtcf = false;
            // In Azure I get 0xc0000022
            int size = NativeMethods.GetFontData(hdc, 0, 0, null, 0);

            // Check for ntstatus.h: #define STATUS_ACCESS_DENIED             ((NTSTATUS)0xC0000022L)
            if ((uint)size == 0xc0000022)
                throw new InvalidOperationException("Microsoft Azure returns STATUS_ACCESS_DENIED ((NTSTATUS)0xC0000022L) from GetFontData. This is a bug in Azure. You must implement a FontResolver to circumvent this issue.");

            if (size == NativeMethods.GDI_ERROR)
            {
                // Assume that the font file is a true type collection.
                size = NativeMethods.GetFontData(hdc, ttcf, 0, null, 0);
                isTtcf = true;
            }
            error = Marshal.GetLastWin32Error();
            //Debug.Assert(error == 0);

            if (size == 0)
                throw new InvalidOperationException("Cannot retrieve font data.");

            byte[] bytes = new byte[size];
            int effectiveSize = NativeMethods.GetFontData(hdc, isTtcf ? ttcf : 0, 0, bytes, size);
            Debug.Assert(size == effectiveSize);
            // Clean up.
            NativeMethods.SelectObject(hdc, oldFont);
            NativeMethods.ReleaseDC(IntPtr.Zero, hdc);

            return bytes;
        }
开发者ID:Sl0vi,项目名称:PDFsharp,代码行数:73,代码来源:XFontSource.cs


注:本文中的System.Drawing.Font.ToHfont方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。