I'm trying to create a System.Drawing.Font from a LOGFONT using P/Invoke and Font.FromLogFont. The requested font have been created, however it always have the same rendering quality - no matter which value I have assigned to the lfQuality member of the LOGFONT struct.
here is relevant code:
//LOGFONT struct
[StructLayout(LayoutKind.Sequential, CharSet = CharSet.Auto)]
public class LOGFONT
{
public const int LF_FACESIZE = 32;
public int lfHeight;
public int lfWidth;
public int lfEscapement;
public int lfOrientation;
public int lfWeight;
public byte lfItalic;
public byte lfUnderline;
public byte lfStrikeOut;
public byte lfCharSet;
public byte lfOutPrecision;
public byte lfClipPrecision;
public byte lfQuality;
public byte lfPitchAndFamily;
[MarshalAs(UnmanagedType.ByValTStr, SizeConst = LF_FACESIZE)]
public string lfFaceName;
}
Then import for CreateFontIndirect:
[DllImport("gdi32.dll", CharSet=CharSet.Auto)]
public static extern IntPtr CreateFontIndirect(
[In, MarshalAs(UnmanagedType.LPStruct)]
LOGFONT lplf // characteristics
);
Now create the font:
LOGFONT lf = new LOGFONT();
lf.lfFaceName = "DejaVu Sans";
lf.lfHeight = 36;
lf.lfQuality = 5;
IntPtr handle = CreateFontIndirect(lf);
Font f = Font.FromLogFont(lf);
So it seems that the managed code ignores the lfQuality member. Any way fixing that? I would like to control the way some fonts are being rendered, ignoring the system global settings.