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


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

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


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

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