Type a page name and press Enter. You'll jump to the page if it exists, or you can create it if it doesn't.
To create a page in a module other than Structures, prefix the name with the module name and a period.
LOGFONT (Structures)
.
C# Simple Version:
// if we specify CharSet.Auto instead of CharSet.Ansi, then the string will be unreadable
[StructLayout(LayoutKind.Sequential, CharSet=CharSet.Auto)]
[StructLayout(LayoutKind.Sequential, CharSet=CharSet.Ansi)]
public class LOGFONT
{
public int lfHeight = 0;
public int lfWidth = 0;
public int lfEscapement = 0;
public int lfOrientation = 0;
public int lfWeight = 0;
public byte lfItalic = 0;
public byte lfUnderline = 0;
public byte lfStrikeOut = 0;
public byte lfCharSet = 0;
public byte lfOutPrecision = 0;
public byte lfClipPrecision = 0;
public byte lfQuality = 0;
public byte lfPitchAndFamily = 0;
[MarshalAs(UnmanagedType.ByValTStr, SizeConst=32)]
public string lfFaceName = string.Empty;
}
C# Signature:
// if we specify CharSet.Auto instead of CharSet.Ansi, then the string will be unreadable
[StructLayout(LayoutKind.Sequential, CharSet = CharSet.Auto)]
[StructLayout(LayoutKind.Sequential, CharSet = CharSet.Ansi)]
public class LOGFONT
{
public int lfHeight;
public int lfWidth;
public int lfEscapement;
public int lfOrientation;
public FontWeight lfWeight;
[MarshalAs(UnmanagedType.U1)]
public bool lfItalic;
[MarshalAs(UnmanagedType.U1)]
public bool lfUnderline;
[MarshalAs(UnmanagedType.U1)]
public bool lfStrikeOut;
public FontCharSet lfCharSet;
public FontPrecision lfOutPrecision;
public FontClipPrecision lfClipPrecision;
public FontQuality lfQuality;
public FontPitchAndFamily lfPitchAndFamily;
[MarshalAs(UnmanagedType.ByValTStr, SizeConst = 32)]
public string lfFaceName;
<StructLayout(LayoutKind.Sequential, CharSet:=CharSet.Auto)> _
Public Structure LOGFONT
Public lfHeight As Int32
Public lfWidth As Int32
Public lfEscapement As Int32
Public lfOrientation As Int32
Public lfWeight As Int32
Public lfItalic As Byte
Public lfUnderline As Byte
Public lfStrikeOut As Byte
Public lfCharSet As Byte
Public lfOutPrecision As Byte
Public lfClipPrecision As Byte
Public lfQuality As Byte
Public lfPitchAndFamily As Byte
<MarshalAs(UnmanagedType.ByValTStr, SizeConst:=32)> _
Public lfFaceName As String
End Structure
VB .NET Signature:
<StructLayout(LayoutKind.Sequential, CharSet:=CharSet.Auto)> _
Public Class LOGFONT
Public lfHeight As Integer
Public lfWidth As Integer
Public lfEscapement As Integer
Public lfOrientation As Integer
Public lfWeight As FontWeight
<MarshalAs(UnmanagedType.U1)> _
Public lfItalic As Boolean
<MarshalAs(UnmanagedType.U1)> _
Public lfUnderline As Boolean
<MarshalAs(UnmanagedType.U1)> _
Public lfStrikeOut As Boolean
Public lfCharSet As FontCharSet
Public lfOutPrecision As FontPrecision
Public lfClipPrecision As FontClipPrecision
Public lfQuality As FontQuality
Public lfPitchAndFamily As FontPitchAndFamily
<MarshalAs(UnmanagedType.ByValTStr, SizeConst:=32)> _
Public lfFaceName As String
1) In VB .NET, the CharSet property had to be set to Ansi for it to work with LogFonts embedded in Eastman/Wang style annotation.
2) The FromLogFont method in VB .NET returned "Times New Roman" as the Font.name for many LogFont.lfFaceName that were not "Times New Roman."
Sample Code:
// =========================================================================
// EXAMPLE 1 - Filling a Font object with a LOGFONT.
// [in] LayoutDesign.CtlLayout (ActiveX control)
// [out] fontReceived (System.Drawing.Font)
// An ActiveX control returns a handle to a LOGFONT in unmanaged global mem.
IntPtr hHGlobalLOGFONT = (IntPtr)LayoutDesign.CtlLayout.BorderTextLogfont;
// Stake a claim to the memory and get a pointer to it.
IntPtr pLOGFONT = DLLKernel32.GlobalLock(hHGlobalLOGFONT);
// Instantiate a managed logical font struct (as defined above!)
LOGFONT lf = new LOGFONT();
// Copy the LOGFONT data into managed mem.
Marshal.PtrToStructure(pLOGFONT, lf);
// Create the Font object.
Font fontReceived = Font.FromLogFont(lf);
// Release the claim to the global mem.
DLLKernel32.GlobalUnlock(hHGlobalLOGFONT);
// ... Do whatever with the Font object "fontReceived" ...
// =========================================================================
// EXAMPLE 2 - Reversing the process.
// [in] fontReceived (System.Drawing.Font)
// [out] LayoutDesign.CtlLayout (ActiveX control)
// Use the ActiveX's global memory.
IntPtr hHGlobalLOGFONT = (IntPtr)LayoutDesign.CtlLayout.BorderTextLogfont;
// Stake a claim to the memory and get a pointer to it.
IntPtr pLOGFONT = DLLKernel32.GlobalLock(hHGlobalLOGFONT);
// Instantiate a managed logical font struct (as defined above!)
LOGFONT lf = new LOGFONT();
// Load the LOGFONT struct from the managed Font object.
fontReceived.ToLogFont(lf);
// Copy the LOGFONT data into managed mem.
Marshal.StructureToPtr(pLOGFONT, lf, false);
// Release the claim to the global mem.
DLLKernel32.GlobalUnlock(hHGlobalLOGFONT);
// Update the ActiveX control.
(IntPtr)LayoutDesign.CtlLayout.BorderTextLogfont = hHGlobalLOGFONT;
Alternative Managed API:
The .NET Framework class Font, has a method, Font::FromLogfont that takes an Object reference as it's method parameter. You must define a managed LOGFONT class using the same format as the C# signature above. When using the StructLayout attribute on the class definition, you must set the CharSet property to Auto (the default is Ansi, which will not work correctly). The only difficulty encountered is passing the string value (the designated Font Face Name) to the FromLogfont method; apparently, this must have the attribute: [MarshalAs(UnmanagedType::ByValTStr)] enum value for the method to work correctly. Then, when instantiating a new Font in your managed application, you must cast the LOGFONT class (with appropriate member values assigned) to a System::Object for the function to work without generating a runtime exception.
Note that the managed Font class does not support raster fonts.
Note that neither of the C# LOGFONT classes return the proper value for lfPitchAndFamily using Font.ToLogFont, it always returns FF_DONTCARE.
Click to read this page
4/6/2008 7:23:14 AM - anonymous
The LOGFONT structure defines the attributes of a font.
11/3/2015 6:42:15 PM - -194.25.158.132
The LOGFONT structure defines the attributes of a font.
11/3/2015 6:42:15 PM - -194.25.158.132
Click to read this page
4/6/2008 7:23:14 AM - anonymous
Please edit this page!
Do you have...
helpful tips?
corrections to the existing content?
alternate definitions?
additional languages you want to include?
Select "Edit This Page" on the right hand toolbar and edit it! Or add new pages containing any supporting types needed.