本文整理汇总了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;
}