微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

如何在Windows中获取所有等宽字体?

我见过如何获得所有安装的固定宽度的字体? ,但我不能让它工作:

internal class NativeMethods { public const Int32 LF_FACESIZE = 32; public const Int32 FIXED_PITCH = 1; [StructLayout(LayoutKind.Sequential,CharSet = CharSet.Auto)] public class LOGFONT { public Int32 lfheight = 0; public Int32 lfWidth = 0; public Int32 lfEscapement = 0; public Int32 lfOrientation = 0; public Int32 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 = LF_FACESIZE)] public String lfFaceName = string.Empty; } } public partial class MainForm : Form { private string font_names = null; public MainForm() { InitializeComponent(); StringBuilder sb = new StringBuilder(); foreach (var font_family in FontFamily.Families) { if (font_family.IsstyleAvailable(FontStyle.Regular)) { var lf = new NativeMethods.LOGFONT(); Font font = new Font(font_family,9.0f); font.ToLogFont(lf); if ((lf.lfPitchAndFamily & 0x3) == NativeMethods.FIXED_PITCH) { sb.AppendLine(font_family.Name); } } } font_names = sb.ToString(); } private void MainForm_Paint(object sender,PaintEventArgs e) { e.Graphics.DrawString(font_names,SystemFonts.MessageBoxFont,SystemBrushes.WindowText,10.0f,10.0f); } }

看起来不pipe它是什么字体, lfPitchAndFamily总是为零。

那么如何获得所有等宽字体?

添加了AddFontResourceEx的字体在GDI +中不起作用

在Linux中获取文件元数据

我可以在我的Windows应用程序中embedded几乎任何字体,只要在应用程序执行期间安装它?

是否有可用于Windows的Unicode字体,与Arial Unicode MS一样完整,但是免费,甚至用于商业用途?

设置字体无效的过期标题

字体真棒和i3bar

查看其他应用程序的字体

所有Windows浏览器上的Typekit和@fontface问题都使用Ruby on Rails应用程序,尤其是Chrome

所有浏览器的字体重量的外观?

Java自动调整到Windows 7的字体大小调整

我想我只是使用P / Invoke来做到这一点:

internal class NativeMethods { public const Int32 LF_FACESIZE = 32; public const Int32 LF_FULLFACESIZE = 64; public const Int32 DEFAULT_CHARSET = 1; public const Int32 FIXED_PITCH = 1; public const Int32 TRUETYPE_FONTTYPE = 0x0004; public delegate Int32 FONTENUMPROC(ref ENUMLOGFONT lpelf,ref NEWTEXTMETRIC lpntm,UInt32 FontType,IntPtr lParam); [StructLayout(LayoutKind.Sequential,CharSet = CharSet.Auto)] public struct LOGFONT { public Int32 lfheight; public Int32 lfWidth; public Int32 lfEscapement; public Int32 lfOrientation; public Int32 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; } [StructLayout(LayoutKind.Sequential,CharSet = CharSet.Auto)] public struct TEXTMETRIC { public Int32 tmHeight; public Int32 tmAscent; public Int32 tmDescent; public Int32 tmInternalLeading; public Int32 tmExternalLeading; public Int32 tmAveCharWidth; public Int32 tmMaxCharWidth; public Int32 tmWeight; public Int32 tmOverhang; public Int32 tmDigitizedAspectX; public Int32 tmDigitizedAspectY; public Char tmFirstChar; public Char tmLastChar; public Char tmDefaultChar; public Char tmBreakChar; public Byte tmItalic; public Byte tmUnderlined; public Byte tmStruckOut; public Byte tmPitchAndFamily; public Byte tmCharSet; } [StructLayout(LayoutKind.Sequential,CharSet = CharSet.Auto)] public struct ENUMLOGFONT { public LOGFONT elfLogFont; [MarshalAs(UnmanagedType.ByValTStr,SizeConst = LF_FULLFACESIZE)] public String elfFullName; [MarshalAs(UnmanagedType.ByValTStr,SizeConst = LF_FACESIZE)] public String elfStyle; } [StructLayout(LayoutKind.Sequential,CharSet = CharSet.Auto)] public struct NEWTEXTMETRIC { public Int32 tmHeight; public Int32 tmAscent; public Int32 tmDescent; public Int32 tmInternalLeading; public Int32 tmExternalLeading; public Int32 tmAveCharWidth; public Int32 tmMaxCharWidth; public Int32 tmWeight; public Int32 tmOverhang; public Int32 tmDigitizedAspectX; public Int32 tmDigitizedAspectY; public Char tmFirstChar; public Char tmLastChar; public Char tmDefaultChar; public Char tmBreakChar; public Byte tmItalic; public Byte tmUnderlined; public Byte tmStruckOut; public Byte tmPitchAndFamily; public Byte tmCharSet; public UInt32 ntmFlags; public UInt32 ntmSizeEM; public UInt32 ntmCellHeight; public UInt32 ntmAvgWidth; } [DllImport("gdi32.dll",CharSet = CharSet.Auto)] public extern static Int32 EnumFontFamiliesEx(IntPtr hdc,ref LOGFONT lpLogfont,FONTENUMPROC lpEnumFontFamExProc,IntPtr lParam,UInt32 dwFlags); } internal static class Program { private static void Main() { Graphics graphics = Graphics.FromHwnd(IntPtr.Zero); IntPtr hdc = graphics.GetHdc(); var logfont = new NativeMethods.LOGFONT() { lfCharSet = NativeMethods.DEFAULT_CHARSET }; NativeMethods.EnumFontFamiliesEx(hdc,ref logfont,new NativeMethods.FONTENUMPROC(EnumFontFamExProc),IntPtr.Zero,0); graphics.ReleaseHdc(); } private static int EnumFontFamExProc(ref NativeMethods.ENUMLOGFONT lpelf,ref NativeMethods.NEWTEXTMETRIC lpntm,uint FontType,IntPtr lParam) { if ((lpelf.elfLogFont.lfPitchAndFamily & 0x3) == NativeMethods.FIXED_PITCH) { Console.WriteLine(lpelf.elfLogFont.lfFaceName); } return 1; } }

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 [email protected] 举报,一经查实,本站将立刻删除。

相关推荐