Fetching Font information ?

G

Guest

I am trying to fetch the font information using following code

private void Form1_Load(object sender, System.EventArgs e)
{


IntPtr hdc = Win32API.GetDC(this.Handle);
try
{
LOGFONT lf = CreateLogFont("");
int ret = 0;
try
{
ret = Win32API.EnumFontFamiliesEx
(hdc, ref lf, new Win32API.EnumFontFamExProc(this.callback), 0, 0);
}
catch
{
System.Diagnostics.Trace.WriteLine("Excetion Happend!");
}
System.Diagnostics.Trace.WriteLine("EnumFontFamiliesEx = " + ret.ToString());
}
finally
{
Win32API.ReleaseDC(IntPtr.Zero, hdc);
}

}

private int cnt = 0;

private int callback(
ref ENUMLOGFONTEXDV lpelfe,
ref NEWTEXTMETRICEX lpntme,
uint FontType,
IntPtr lParam
)
{
try
{
++cnt;
string header = "no." + (cnt).ToString() + "::";
System.Diagnostics.Trace.WriteLine(header + lpelfe.elfEnumLogfontEx.elfLogFont.lfFaceName);
System.Diagnostics.Trace.WriteLine(header + lpelfe.elfEnumLogfontEx.elfLogFont.lfCharSet);
}
catch
{
System.Diagnostics.Trace.WriteLine("What happend?");
}
return cnt;
}

private const byte DEFAULT_CHARSET = 1;
private const byte SHIFTJIS_CHARSET = 128;
private const byte JOHAB_CHARSET = 130;
private const byte EASTEUROPE_CHARSET = 238;

private const byte DEFAULT_PITCH = 0;
private const byte FIXED_PITCH = 1;
private const byte VARIABLE_PITCH = 2;
private const byte FF_DONTCARE = (0 << 4);
private const byte FF_ROMAN = (1 << 4);
private const byte FF_SWISS = (2 << 4);
private const byte FF_MODERN = (3 << 4);
private const byte FF_SCRIPT = (4 << 4);
private const byte FF_DECORATIVE = (5 << 4);


public static LOGFONT CreateLogFont(string fontname)
{
LOGFONT lf = new LOGFONT();
lf.lfHeight = 0;
lf.lfWidth = 0;
lf.lfEscapement = 0;
lf.lfOrientation = 0;
lf.lfWeight = 0;
lf.lfItalic = 0;
lf.lfUnderline = 0;
lf.lfStrikeOut = 0;
lf.lfCharSet = SHIFTJIS_CHARSET;
//lf.lfCharSet = DEFAULT_CHARSET;
lf.lfOutPrecision = 0;
lf.lfClipPrecision = 0;
lf.lfQuality = 0;
lf.lfPitchAndFamily = (?_?) ;
lf.lfFaceName = "";


return lf;
}

it works well, but I am not able to toy with "lfPitchAndFamily", I want to fetch font names according to font family name

and pitch.
Please guide
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top