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